Remove login and password in shared preferences when deleting account

This commit is contained in:
Shinokuni 2020-01-15 18:41:33 +01:00
parent aea791ed94
commit 188d2086dd
2 changed files with 29 additions and 15 deletions

View File

@ -26,12 +26,13 @@ import com.readrops.app.R;
import com.readrops.app.ReadropsApp;
import com.readrops.app.activities.AddAccountActivity;
import com.readrops.app.activities.ManageFeedsFoldersActivity;
import com.readrops.readropsdb.entities.account.Account;
import com.readrops.readropsdb.entities.account.AccountType;
import com.readrops.app.utils.PermissionManager;
import com.readrops.app.utils.SharedPreferencesManager;
import com.readrops.app.utils.Utils;
import com.readrops.app.utils.matchers.OPMLMatcher;
import com.readrops.app.viewmodels.AccountViewModel;
import com.readrops.readropsdb.entities.account.Account;
import com.readrops.readropsdb.entities.account.AccountType;
import com.readrops.readropslibrary.opml.OPMLParser;
import com.readrops.readropslibrary.opml.model.OPML;
@ -146,20 +147,25 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
.title(R.string.delete_account_question)
.positiveText(R.string.validate)
.negativeText(R.string.cancel)
.onPositive(((dialog, which) -> viewModel.delete(account)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
getActivity().finish();
}
.onPositive(((dialog, which) -> {
SharedPreferencesManager.remove(getContext(), account.getLoginKey());
SharedPreferencesManager.remove(getContext(), account.getPasswordKey());
@Override
public void onError(Throwable e) {
Utils.showSnackbar(getView(), e.getMessage());
}
})))
viewModel.delete(account)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
getActivity().finish();
}
@Override
public void onError(Throwable e) {
Utils.showSnackbar(getView(), e.getMessage());
}
});
}))
.show();
}

View File

@ -48,6 +48,14 @@ public final class SharedPreferencesManager {
return sharedPreferences.getString(sharedPrefKey.key, sharedPrefKey.getStringDefaultValue());
}
public static void remove(Context context, String key) {
SharedPreferences sharedPreferences = getSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(key);
editor.apply();
}
public enum SharedPrefKey {
SHOW_READ_ARTICLES("show_read_articles", false),
ITEMS_TO_PARSE_MAX_NB("items_to_parse_max_nb", "20"),