mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
protect profile deletion
This commit is contained in:
@@ -96,6 +96,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
public static final String CLEAR_NOTIFICATIONS = "clear_notifications";
|
||||
public static final String ACCOUNT_ID_EXTRA = "account_id";
|
||||
public static final String FROM_WELCOME = "from_welcome";
|
||||
private static final int REQUEST_CODE_CONFIRM_CREDENTIALS_DELETE_PROFILE = ScreenLockUtil.REQUEST_CODE_CONFIRM_CREDENTIALS+1;
|
||||
|
||||
private ConversationListFragment conversationListFragment;
|
||||
public TextView title;
|
||||
@@ -109,6 +110,8 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
|
||||
/** used to store temporarily scanned QR to pass it back to QrCodeHandler when ScreenLockUtil is used */
|
||||
private String qrData = null;
|
||||
/** used to store temporarily profile ID to delete after authorization is granted via ScreenLockUtil */
|
||||
private int deleteProfileId = 0;
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
@@ -570,6 +573,30 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.chat_share_with_title)));
|
||||
}
|
||||
|
||||
public void onDeleteProfile(int profileId) {
|
||||
deleteProfileId = profileId;
|
||||
boolean result = ScreenLockUtil.applyScreenLock(this, getString(R.string.delete_account), getString(R.string.enter_system_secret_to_continue), REQUEST_CODE_CONFIRM_CREDENTIALS_DELETE_PROFILE);
|
||||
if (!result) {
|
||||
deleteProfile(profileId);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteProfile(int profileId) {
|
||||
DcAccounts accounts = DcHelper.getAccounts(this);
|
||||
boolean selected = profileId == accounts.getSelectedAccount().getAccountId();
|
||||
DcHelper.getNotificationCenter(this).removeAllNotifications(profileId);
|
||||
accounts.removeAccount(profileId);
|
||||
if (selected) {
|
||||
DcContext selAcc = accounts.getSelectedAccount();
|
||||
AccountManager.getInstance().switchAccountAndStartActivity(this, selAcc.isOk()? selAcc.getAccountId() : 0);
|
||||
} else {
|
||||
AccountManager.getInstance().showSwitchAccountMenu(this);
|
||||
}
|
||||
|
||||
// title update needed to show "Delta Chat" in case there is only one profile left
|
||||
refreshTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@@ -590,6 +617,12 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
qrData = null;
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_CONFIRM_CREDENTIALS_DELETE_PROFILE:
|
||||
if (deleteProfileId != 0) {
|
||||
deleteProfile(deleteProfileId);
|
||||
deleteProfileId = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
+9
-22
@@ -47,9 +47,15 @@ import chat.delta.rpc.RpcException;
|
||||
public class AccountSelectionListFragment extends DialogFragment implements DcEventCenter.DcEventDelegate
|
||||
{
|
||||
private static final String TAG = AccountSelectionListFragment.class.getSimpleName();
|
||||
private final ConversationListActivity activity;
|
||||
private RecyclerView recyclerView;
|
||||
private AccountSelectionListAdapter adapter;
|
||||
|
||||
public AccountSelectionListFragment(ConversationListActivity activity) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
@@ -132,7 +138,7 @@ public class AccountSelectionListFragment extends DialogFragment implements DcEv
|
||||
private void onContextItemSelected(MenuItem item, int accountId) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.delete) {
|
||||
onDeleteAccount(accountId);
|
||||
onDeleteProfile(accountId);
|
||||
} else if (itemId == R.id.menu_mute_notifications) {
|
||||
onToggleMute(accountId);
|
||||
} else if (itemId == R.id.menu_set_tag) {
|
||||
@@ -167,8 +173,6 @@ public class AccountSelectionListFragment extends DialogFragment implements DcEv
|
||||
}
|
||||
|
||||
private void onSetTag(int accountId) {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) return;
|
||||
AccountSelectionListFragment.this.dismiss();
|
||||
|
||||
DcContext dcContext = DcHelper.getAccounts(activity).getAccount(accountId);
|
||||
@@ -190,10 +194,8 @@ public class AccountSelectionListFragment extends DialogFragment implements DcEv
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onDeleteAccount(int accountId) {
|
||||
Activity activity = getActivity();
|
||||
private void onDeleteProfile(int accountId) {
|
||||
AccountSelectionListFragment.this.dismiss();
|
||||
if (activity == null) return;
|
||||
DcAccounts accounts = DcHelper.getAccounts(activity);
|
||||
Rpc rpc = DcHelper.getRpc(activity);
|
||||
|
||||
@@ -229,22 +231,7 @@ public class AccountSelectionListFragment extends DialogFragment implements DcEv
|
||||
.setTitle(R.string.delete_account)
|
||||
.setView(dialogView)
|
||||
.setNegativeButton(R.string.cancel, (d, which) -> AccountManager.getInstance().showSwitchAccountMenu(activity))
|
||||
.setPositiveButton(R.string.delete, (d2, which2) -> {
|
||||
boolean selected = accountId == accounts.getSelectedAccount().getAccountId();
|
||||
DcHelper.getNotificationCenter(activity).removeAllNotifications(accountId);
|
||||
accounts.removeAccount(accountId);
|
||||
if (selected) {
|
||||
DcContext selAcc = accounts.getSelectedAccount();
|
||||
AccountManager.getInstance().switchAccountAndStartActivity(activity, selAcc.isOk()? selAcc.getAccountId() : 0);
|
||||
} else {
|
||||
AccountManager.getInstance().showSwitchAccountMenu(activity);
|
||||
}
|
||||
|
||||
// title update needed to show "Delta Chat" in case there is only one profile left
|
||||
if (activity instanceof ConversationListActivity) {
|
||||
((ConversationListActivity)activity).refreshTitle();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.delete, (d2, w2) -> activity.onDeleteProfile(accountId))
|
||||
.show();
|
||||
Util.redPositiveButton(dialog);
|
||||
}
|
||||
|
||||
@@ -147,8 +147,8 @@ public class AccountManager {
|
||||
|
||||
// ui
|
||||
|
||||
public void showSwitchAccountMenu(Activity activity) {
|
||||
AccountSelectionListFragment dialog = new AccountSelectionListFragment();
|
||||
public void showSwitchAccountMenu(ConversationListActivity activity) {
|
||||
AccountSelectionListFragment dialog = new AccountSelectionListFragment(activity);
|
||||
dialog.show(((FragmentActivity) activity).getSupportFragmentManager(), null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user