mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01: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
|
@Override
|
||||||
public void onChanged(Boolean newValue) {
|
public void onChanged(Boolean isEnabled) {
|
||||||
if (newValue) {
|
if (isEnabled) {
|
||||||
if(ContactAddressBookWorker.Companion.checkPermission(controller, context)){
|
if(ContactAddressBookWorker.Companion.checkPermission(controller, context)){
|
||||||
checkForPhoneNumber();
|
checkForPhoneNumber();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ContactAddressBookWorker.Companion.deleteAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,13 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
|||||||
Log.e(javaClass.simpleName, "No current user!")
|
Log.e(javaClass.simpleName, "No current user!")
|
||||||
return Result.failure()
|
return Result.failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deleteAll = inputData.getBoolean(DELETE_ALL, false)
|
||||||
|
if(deleteAll){
|
||||||
|
deleteAllLinkedAccounts()
|
||||||
|
return Result.success()
|
||||||
|
}
|
||||||
|
|
||||||
// Check if run already at the date
|
// Check if run already at the date
|
||||||
val force = inputData.getBoolean(KEY_FORCE, false)
|
val force = inputData.getBoolean(KEY_FORCE, false)
|
||||||
if (!force) {
|
if (!force) {
|
||||||
@ -373,10 +380,22 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
|||||||
return numbers
|
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 {
|
companion object {
|
||||||
const val TAG = "ContactAddressBook"
|
const val TAG = "ContactAddressBook"
|
||||||
const val REQUEST_PERMISSION = 231
|
const val REQUEST_PERMISSION = 231
|
||||||
const val KEY_FORCE = "KEY_FORCE"
|
const val KEY_FORCE = "KEY_FORCE"
|
||||||
|
const val DELETE_ALL = "DELETE_ALL"
|
||||||
|
|
||||||
fun run(context: Context) {
|
fun run(context: Context) {
|
||||||
if (ContextCompat.checkSelfPermission(context,
|
if (ContextCompat.checkSelfPermission(context,
|
||||||
@ -408,5 +427,13 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
|||||||
return true
|
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