From 93551215debded6134a9c6967e15f339a9071ece Mon Sep 17 00:00:00 2001 From: Kasun Date: Wed, 4 Sep 2019 04:01:37 +0530 Subject: [PATCH] confirm before unfollow --- .../activities/ShowAccountActivity.java | 36 +++++++++++++++++-- .../fragments/ContentSettingsFragment.java | 13 +++++++ .../app/fedilab/android/helper/Helper.java | 1 + .../res/layout/fragment_settings_reveal.xml | 9 ++++- app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java index 81a02e010..26b168d96 100644 --- a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java @@ -332,6 +332,15 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt }else { changeDrawableColor(getApplicationContext(), R.drawable.ic_lock_outline,R.color.mastodonC3); } + + int style; + if (theme == Helper.THEME_LIGHT) + style = R.style.Dialog; + else if (theme == Helper.THEME_BLACK) + style = R.style.DialogBlack; + else + style = R.style.DialogDark; + String accountIdRelation = accountId; if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { accountIdRelation = account.getAcct(); @@ -839,8 +848,31 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt account_follow.setEnabled(false); new PostActionAsyncTask(getApplicationContext(), API.StatusAction.FOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }else if( doAction == action.UNFOLLOW){ - account_follow.setEnabled(false); - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true); + if (confirm_unfollow) { + AlertDialog.Builder unfollowConfirm = new AlertDialog.Builder(ShowAccountActivity.this, style); + unfollowConfirm.setTitle(getString(R.string.unfollow_confirm)); + unfollowConfirm.setMessage(account.getAcct()); + unfollowConfirm.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + dialog.dismiss(); + } + }); + unfollowConfirm.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + account_follow.setEnabled(false); + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dialog.dismiss(); + } + }); + unfollowConfirm.show(); + } else { + account_follow.setEnabled(false); + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + }else if( doAction == action.UNBLOCK){ account_follow.setEnabled(false); new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNBLOCK, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java index d55c3500b..9dc5dd7db 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java @@ -783,6 +783,19 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable set_display_timeline_in_list_text.setOnClickListener(v -> set_display_timeline_in_list.performClick()); + boolean unfollow_validation = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true); + final CheckBox set_unfollow_validation = rootView.findViewById(R.id.set_unfollow_validation); + set_unfollow_validation.setChecked(unfollow_validation); + + set_unfollow_validation.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_UNFOLLOW_VALIDATION, set_unfollow_validation.isChecked()); + editor.apply(); + } + }); + boolean send_crash_reports = sharedpreferences.getBoolean(Helper.SET_SEND_CRASH_REPORTS, false); final CheckBox set_enable_crash_report = rootView.findViewById(R.id.set_enable_crash_report); diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 505dae451..f17b185fb 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -371,6 +371,7 @@ public class Helper { public static final String SET_BLUR_SENSITIVE = "set_blur_sensitive"; public static final String SET_LONG_PRESS_MEDIA = "set_long_press_media"; public static final String SET_DISPLAY_TIMELINE_IN_LIST = "set_display_timeline_in_list"; + public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation"; public static final String SET_ONION_SCHEME = "set_onion_scheme"; public static final String SET_REMEMBER_POSITION_HOME = "set_remember_position"; public static final String SET_DISPLAY_ADMIN_MENU = "set_display_admin_menu"; diff --git a/app/src/main/res/layout/fragment_settings_reveal.xml b/app/src/main/res/layout/fragment_settings_reveal.xml index c59dc6eea..567350d66 100644 --- a/app/src/main/res/layout/fragment_settings_reveal.xml +++ b/app/src/main/res/layout/fragment_settings_reveal.xml @@ -975,7 +975,14 @@ - + Live notifications will be enabled for this account. Clear cache when leaving The cache (media, cached messages, data from the built-in browser) will be automatically cleared when leaving the application. + Do you want to unfollow this account? + Show confirmation dialog before unfollowing \ No newline at end of file