fixed crash for pre-lollipop devices when removing account
This commit is contained in:
parent
8b64005cd0
commit
c0e942e4f2
|
@ -35,8 +35,8 @@ android {
|
|||
applicationId "org.mariotaku.twidere"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 25
|
||||
versionCode 227
|
||||
versionName '3.3.9'
|
||||
versionCode 228
|
||||
versionName '3.3.10'
|
||||
multiDexEnabled true
|
||||
|
||||
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")'
|
||||
|
|
|
@ -10,6 +10,8 @@ import android.app.Activity;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -20,10 +22,11 @@ import java.util.concurrent.TimeUnit;
|
|||
*/
|
||||
|
||||
public class AccountManagerSupport {
|
||||
public static AccountManagerFuture<Bundle> removeAccount(AccountManager am, Account account,
|
||||
Activity activity,
|
||||
final AccountManagerCallback<Bundle> callback,
|
||||
Handler handler) {
|
||||
public static AccountManagerFuture<Bundle> removeAccount(@NonNull AccountManager am,
|
||||
@NonNull Account account,
|
||||
@Nullable Activity activity,
|
||||
@Nullable final AccountManagerCallback<Bundle> callback,
|
||||
@Nullable Handler handler) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
return AccountManagerSupportL.removeAccount(am, account, activity, callback, handler);
|
||||
}
|
||||
|
@ -31,8 +34,10 @@ public class AccountManagerSupport {
|
|||
final AccountManagerFuture<Boolean> future = am.removeAccount(account, new AccountManagerCallback<Boolean>() {
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Boolean> future) {
|
||||
if (callback != null) {
|
||||
callback.run(new BooleanToBundleAccountManagerFuture(future));
|
||||
}
|
||||
}
|
||||
}, handler);
|
||||
return new BooleanToBundleAccountManagerFuture(future);
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
|
|||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
val accountKey = account.getAccountKey(am)
|
||||
AccountManagerSupport.removeAccount(am, account, activity, null, null)
|
||||
AccountManagerSupport.removeAccount(am, account, null, null, null)
|
||||
val where = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY).sql
|
||||
val whereArgs = arrayOf(accountKey.toString())
|
||||
// Also delete tweets related to the account we previously
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
|
@ -122,36 +121,6 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
progressContainer.visibility = if (shown) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_ADD_TAB -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val values = ContentValues()
|
||||
values.put(Tabs.NAME, data!!.getStringExtra(EXTRA_NAME))
|
||||
values.put(Tabs.ICON, data.getStringExtra(EXTRA_ICON))
|
||||
values.put(Tabs.TYPE, data.getStringExtra(EXTRA_TYPE))
|
||||
values.put(Tabs.ARGUMENTS, data.getStringExtra(EXTRA_ARGUMENTS))
|
||||
values.put(Tabs.EXTRAS, data.getStringExtra(EXTRA_EXTRAS))
|
||||
values.put(Tabs.POSITION, adapter.count)
|
||||
contentResolver.insert(Tabs.CONTENT_URI, values)
|
||||
SettingsActivity.setShouldRestart(activity)
|
||||
}
|
||||
}
|
||||
REQUEST_EDIT_TAB -> {
|
||||
if (resultCode == Activity.RESULT_OK && data!!.hasExtra(EXTRA_ID)) {
|
||||
val values = ContentValues()
|
||||
values.put(Tabs.NAME, data.getStringExtra(EXTRA_NAME))
|
||||
values.put(Tabs.ICON, data.getStringExtra(EXTRA_ICON))
|
||||
values.put(Tabs.EXTRAS, data.getStringExtra(EXTRA_EXTRAS))
|
||||
val where = Expression.equals(Tabs._ID, data.getLongExtra(EXTRA_ID, -1)).sql
|
||||
contentResolver.update(Tabs.CONTENT_URI, values, where, null)
|
||||
SettingsActivity.setShouldRestart(activity)
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.action_multi_select_items, menu)
|
||||
return true
|
||||
|
@ -221,16 +190,6 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
setListShown(true)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
when (item!!.itemId) {
|
||||
else -> {
|
||||
val intent = item.intent ?: return false
|
||||
startActivityForResult(intent, REQUEST_ADD_TAB)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
updateTitle(mode)
|
||||
return true
|
||||
|
@ -415,6 +374,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
|||
context.contentResolver.insert(Tabs.CONTENT_URI, TabValuesCreator.create(tab))
|
||||
}
|
||||
}
|
||||
SettingsActivity.setShouldRestart(activity)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue