mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Added callback when removing accounts on logout to ensure that post logout screen transition happens only after complete logout procedure is complete.
This commit is contained in:
parent
9048842c72
commit
16487556dc
2 changed files with 56 additions and 20 deletions
|
|
@ -2,6 +2,8 @@ package fr.free.nrw.commons;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
|
import android.accounts.AccountManagerCallback;
|
||||||
|
import android.accounts.AccountManagerFuture;
|
||||||
import android.accounts.AuthenticatorException;
|
import android.accounts.AuthenticatorException;
|
||||||
import android.accounts.OperationCanceledException;
|
import android.accounts.OperationCanceledException;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
@ -11,6 +13,7 @@ import android.content.pm.PackageManager;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.util.LruCache;
|
import android.support.v4.util.LruCache;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||||
import com.facebook.stetho.Stetho;
|
import com.facebook.stetho.Stetho;
|
||||||
|
|
@ -32,6 +35,7 @@ import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||||
import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi;
|
import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi;
|
||||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||||
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
||||||
|
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
||||||
import fr.free.nrw.commons.utils.FileUtils;
|
import fr.free.nrw.commons.utils.FileUtils;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -190,7 +194,7 @@ public class CommonsApplication extends Application {
|
||||||
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
|
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearApplicationData(Context context) {
|
public void clearApplicationData(Context context, NavigationBaseActivity.LogoutCompleteListener logoutCompleteListener) {
|
||||||
File cacheDirectory = context.getCacheDir();
|
File cacheDirectory = context.getCacheDir();
|
||||||
File applicationDirectory = new File(cacheDirectory.getParent());
|
File applicationDirectory = new File(cacheDirectory.getParent());
|
||||||
if (applicationDirectory.exists()) {
|
if (applicationDirectory.exists()) {
|
||||||
|
|
@ -204,10 +208,26 @@ public class CommonsApplication extends Application {
|
||||||
|
|
||||||
AccountManager accountManager = AccountManager.get(this);
|
AccountManager accountManager = AccountManager.get(this);
|
||||||
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
|
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
|
||||||
for (Account allAccount : allAccounts) {
|
|
||||||
accountManager.removeAccount(allAccount, null, null);
|
AccountManagerCallback<Boolean> accountManagerCallback = new AccountManagerCallback<Boolean>() {
|
||||||
|
int index = 0;
|
||||||
|
@Override
|
||||||
|
public void run(AccountManagerFuture<Boolean> accountManagerFuture) {
|
||||||
|
index++;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(accountManagerFuture.getResult())
|
||||||
|
{
|
||||||
|
Timber.d("Account removed successfully.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(index == allAccounts.length)
|
||||||
|
{
|
||||||
|
Timber.d("All accounts have been removed");
|
||||||
//TODO: fix preference manager
|
//TODO: fix preference manager
|
||||||
PreferenceManager.getDefaultSharedPreferences(getInstance()).edit().clear().commit();
|
PreferenceManager.getDefaultSharedPreferences(getInstance()).edit().clear().commit();
|
||||||
SharedPreferences preferences = context
|
SharedPreferences preferences = context
|
||||||
|
|
@ -217,6 +237,15 @@ public class CommonsApplication extends Application {
|
||||||
preferences.edit().putBoolean("firstrun", false).apply();
|
preferences.edit().putBoolean("firstrun", false).apply();
|
||||||
updateAllDatabases();
|
updateAllDatabases();
|
||||||
currentAccount = null;
|
currentAccount = null;
|
||||||
|
|
||||||
|
logoutCompleteListener.onLogoutComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Account account : allAccounts) {
|
||||||
|
accountManager.removeAccount(account, accountManagerCallback, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import fr.free.nrw.commons.auth.LoginActivity;
|
||||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||||
import fr.free.nrw.commons.nearby.NearbyActivity;
|
import fr.free.nrw.commons.nearby.NearbyActivity;
|
||||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class NavigationBaseActivity extends BaseActivity
|
public class NavigationBaseActivity extends BaseActivity
|
||||||
implements NavigationView.OnNavigationItemSelectedListener {
|
implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
@ -132,13 +133,15 @@ public class NavigationBaseActivity extends BaseActivity
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||||
((CommonsApplication) getApplicationContext())
|
((CommonsApplication) getApplicationContext())
|
||||||
.clearApplicationData(NavigationBaseActivity.this);
|
.clearApplicationData(NavigationBaseActivity.this, () -> {
|
||||||
|
Timber.d("Logout complete callback received.");
|
||||||
Intent nearbyIntent = new Intent(
|
Intent nearbyIntent = new Intent(
|
||||||
NavigationBaseActivity.this, LoginActivity.class);
|
NavigationBaseActivity.this, LoginActivity.class);
|
||||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startActivity(nearbyIntent);
|
startActivity(nearbyIntent);
|
||||||
finish();
|
finish();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
|
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
|
||||||
.show();
|
.show();
|
||||||
|
|
@ -147,4 +150,8 @@ public class NavigationBaseActivity extends BaseActivity
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface LogoutCompleteListener {
|
||||||
|
void onLogoutComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue