mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-10 08:00:57 +00:00
delete all account-links when disabling phonebooksync
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
adc0a91dac
commit
17f3dae165
@ -869,11 +869,13 @@ public class SettingsController extends BaseController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(Boolean newValue) {
|
||||
if (newValue) {
|
||||
public void onChanged(Boolean isEnabled) {
|
||||
if (isEnabled) {
|
||||
if(ContactAddressBookWorker.Companion.checkPermission(controller, context)){
|
||||
checkForPhoneNumber();
|
||||
}
|
||||
} else {
|
||||
ContactAddressBookWorker.Companion.deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,13 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
||||
Log.e(javaClass.simpleName, "No current user!")
|
||||
return Result.failure()
|
||||
}
|
||||
|
||||
val deleteAll = inputData.getBoolean(DELETE_ALL, false)
|
||||
if(deleteAll){
|
||||
deleteAllLinkedAccounts()
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
// Check if run already at the date
|
||||
val force = inputData.getBoolean(KEY_FORCE, false)
|
||||
if (!force) {
|
||||
@ -373,10 +380,22 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
||||
return numbers
|
||||
}
|
||||
|
||||
fun deleteAllLinkedAccounts() {
|
||||
val rawContactUri = ContactsContract.RawContacts.CONTENT_URI
|
||||
.buildUpon()
|
||||
.appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
|
||||
.appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, accountName)
|
||||
.appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType)
|
||||
.build()
|
||||
context.contentResolver.delete(rawContactUri, null, null)
|
||||
Log.d(TAG, "deleted all linked accounts")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "ContactAddressBook"
|
||||
const val REQUEST_PERMISSION = 231
|
||||
const val KEY_FORCE = "KEY_FORCE"
|
||||
const val DELETE_ALL = "DELETE_ALL"
|
||||
|
||||
fun run(context: Context) {
|
||||
if (ContextCompat.checkSelfPermission(context,
|
||||
@ -408,5 +427,13 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
WorkManager
|
||||
.getInstance()
|
||||
.enqueue(OneTimeWorkRequest.Builder(ContactAddressBookWorker::class.java)
|
||||
.setInputData(Data.Builder().putBoolean(DELETE_ALL, true).build())
|
||||
.build())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user