forked from upstream-mirrors/quik
Request SMS permission when sending message
This commit is contained in:
@@ -31,11 +31,9 @@ class PermissionManagerImpl @Inject constructor(private val context: Context) :
|
|||||||
return Telephony.Sms.getDefaultSmsPackage(context) == context.packageName
|
return Telephony.Sms.getDefaultSmsPackage(context) == context.packageName
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasSmsAndContacts(): Boolean {
|
override fun hasReadSms(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PERMISSION_GRANTED
|
||||||
return hasSms() && hasContacts()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasSms(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PERMISSION_GRANTED
|
override fun hasSendSms(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS) == PERMISSION_GRANTED
|
||||||
|
|
||||||
override fun hasContacts(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PERMISSION_GRANTED
|
override fun hasContacts(): Boolean = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PERMISSION_GRANTED
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class CursorToConversationImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversationsCursor(lastSync: Long): Cursor? {
|
override fun getConversationsCursor(lastSync: Long): Cursor? {
|
||||||
return when (permissionManager.hasSms()) {
|
return when (permissionManager.hasReadSms()) {
|
||||||
true -> context.contentResolver.query(URI, PROJECTION,
|
true -> context.contentResolver.query(URI, PROJECTION,
|
||||||
"date > $lastSync", null,
|
"date > $lastSync", null,
|
||||||
"date desc")
|
"date desc")
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class CursorToMessageImpl @Inject constructor(
|
|||||||
false -> this.projection
|
false -> this.projection
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (permissionManager.hasSms()) {
|
return when (permissionManager.hasReadSms()) {
|
||||||
true -> SqliteWrapper.query(context, uri, projection, sortOrder = "normalized_date desc")
|
true -> SqliteWrapper.query(context, uri, projection, sortOrder = "normalized_date desc")
|
||||||
false -> null
|
false -> null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class CursorToRecipientImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getRecipientCursor(): Cursor? {
|
override fun getRecipientCursor(): Cursor? {
|
||||||
return when (permissionManager.hasSms()) {
|
return when (permissionManager.hasReadSms()) {
|
||||||
true -> context.contentResolver.query(URI, null, null, null, null)
|
true -> context.contentResolver.query(URI, null, null, null, null)
|
||||||
false -> null
|
false -> null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ interface PermissionManager {
|
|||||||
|
|
||||||
fun isDefaultSms(): Boolean
|
fun isDefaultSms(): Boolean
|
||||||
|
|
||||||
fun hasSmsAndContacts(): Boolean
|
fun hasReadSms(): Boolean
|
||||||
|
|
||||||
fun hasSms(): Boolean
|
fun hasSendSms(): Boolean
|
||||||
|
|
||||||
fun hasContacts(): Boolean
|
fun hasContacts(): Boolean
|
||||||
|
|
||||||
|
|||||||
@@ -248,6 +248,12 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun requestSmsPermission() {
|
||||||
|
ActivityCompat.requestPermissions(this, arrayOf(
|
||||||
|
Manifest.permission.READ_SMS,
|
||||||
|
Manifest.permission.SEND_SMS), 0)
|
||||||
|
}
|
||||||
|
|
||||||
override fun requestDatePicker() {
|
override fun requestDatePicker() {
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
DatePickerDialog(this, DatePickerDialog.OnDateSetListener { _, year, month, day ->
|
DatePickerDialog(this, DatePickerDialog.OnDateSetListener { _, year, month, day ->
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ interface ComposeView : QkView<ComposeState> {
|
|||||||
fun clearSelection()
|
fun clearSelection()
|
||||||
fun showDetails(details: String)
|
fun showDetails(details: String)
|
||||||
fun requestStoragePermission()
|
fun requestStoragePermission()
|
||||||
|
fun requestSmsPermission()
|
||||||
fun requestCamera()
|
fun requestCamera()
|
||||||
fun requestGallery()
|
fun requestGallery()
|
||||||
fun requestDatePicker()
|
fun requestDatePicker()
|
||||||
|
|||||||
@@ -571,6 +571,11 @@ class ComposeViewModel @Inject constructor(
|
|||||||
|
|
||||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||||
view.sendIntent
|
view.sendIntent
|
||||||
|
.filter {
|
||||||
|
val hasPermission = permissionManager.hasSendSms()
|
||||||
|
if (!hasPermission) view.requestSmsPermission()
|
||||||
|
hasPermission
|
||||||
|
}
|
||||||
.withLatestFrom(view.textChangedIntent) { _, body -> body }
|
.withLatestFrom(view.textChangedIntent) { _, body -> body }
|
||||||
.map { body -> body.toString() }
|
.map { body -> body.toString() }
|
||||||
.withLatestFrom(state, attachments, conversation, selectedContacts) { body, state, attachments, conversation, contacts ->
|
.withLatestFrom(state, attachments, conversation, selectedContacts) { body, state, attachments, conversation, contacts ->
|
||||||
|
|||||||
@@ -281,7 +281,10 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun requestPermissions() {
|
override fun requestPermissions() {
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS), 0)
|
ActivityCompat.requestPermissions(this, arrayOf(
|
||||||
|
Manifest.permission.READ_CONTACTS,
|
||||||
|
Manifest.permission.READ_SMS,
|
||||||
|
Manifest.permission.SEND_SMS), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clearSearch() {
|
override fun clearSearch() {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class MainViewModel @Inject constructor(
|
|||||||
// If we have all permissions and we've never run a sync, run a sync. This will be the case
|
// If we have all permissions and we've never run a sync, run a sync. This will be the case
|
||||||
// when upgrading from 2.7.3, or if the app's data was cleared
|
// when upgrading from 2.7.3, or if the app's data was cleared
|
||||||
val lastSync = Realm.getDefaultInstance().use { realm -> realm.where(SyncLog::class.java)?.max("date") ?: 0 }
|
val lastSync = Realm.getDefaultInstance().use { realm -> realm.where(SyncLog::class.java)?.max("date") ?: 0 }
|
||||||
if (lastSync == 0 && permissionManager.isDefaultSms() && permissionManager.hasSmsAndContacts()) {
|
if (lastSync == 0 && permissionManager.isDefaultSms() && permissionManager.hasReadSms() && permissionManager.hasContacts()) {
|
||||||
syncMessages.execute(Unit)
|
syncMessages.execute(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,14 +114,14 @@ class MainViewModel @Inject constructor(
|
|||||||
override fun bindView(view: MainView) {
|
override fun bindView(view: MainView) {
|
||||||
super.bindView(view)
|
super.bindView(view)
|
||||||
|
|
||||||
if (!permissionManager.hasSmsAndContacts()) {
|
if (!permissionManager.hasReadSms() || !permissionManager.hasContacts()) {
|
||||||
view.requestPermissions()
|
view.requestPermissions()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the default SMS state or permission states change, update the ViewState
|
// If the default SMS state or permission states change, update the ViewState
|
||||||
Observables.combineLatest(
|
Observables.combineLatest(
|
||||||
view.activityResumedIntent.map { permissionManager.isDefaultSms() }.distinctUntilChanged(),
|
view.activityResumedIntent.map { permissionManager.isDefaultSms() }.distinctUntilChanged(),
|
||||||
view.activityResumedIntent.map { permissionManager.hasSms() }.distinctUntilChanged(),
|
view.activityResumedIntent.map { permissionManager.hasReadSms() }.distinctUntilChanged(),
|
||||||
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged())
|
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged())
|
||||||
{ defaultSms, smsPermission, contactPermission ->
|
{ defaultSms, smsPermission, contactPermission ->
|
||||||
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
newState { copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||||
@@ -131,7 +131,7 @@ class MainViewModel @Inject constructor(
|
|||||||
|
|
||||||
// If the SMS permission state changes from false to true, sync messages
|
// If the SMS permission state changes from false to true, sync messages
|
||||||
view.activityResumedIntent
|
view.activityResumedIntent
|
||||||
.map { permissionManager.hasSms() }
|
.map { permissionManager.hasReadSms() }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.filter { hasSms -> hasSms }
|
.filter { hasSms -> hasSms }
|
||||||
|
|||||||
@@ -135,6 +135,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="2dp"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@id/snackbarButton"
|
app:layout_constraintEnd_toStartOf="@id/snackbarButton"
|
||||||
|
|||||||
Reference in New Issue
Block a user