forked from mirrors/Fedilab
comment #11 - Cross-Account actions: Put the confirmation dialog after selecting an account
This commit is contained in:
parent
b15fdabc90
commit
4fb0f168c8
2 changed files with 24 additions and 29 deletions
|
@ -15,6 +15,7 @@ package app.fedilab.android.helper;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.lifecycle.ViewModelStoreOwner;
|
import androidx.lifecycle.ViewModelStoreOwner;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -50,7 +52,7 @@ public class CrossActionHelper {
|
||||||
* @param targetedStatus status that is targeted
|
* @param targetedStatus status that is targeted
|
||||||
*/
|
*/
|
||||||
public static void doCrossAction(@NonNull Context context, @NonNull TypeOfCrossAction actionType, app.fedilab.android.client.mastodon.entities.Account targetedAccount, Status targetedStatus) {
|
public static void doCrossAction(@NonNull Context context, @NonNull TypeOfCrossAction actionType, app.fedilab.android.client.mastodon.entities.Account targetedAccount, Status targetedStatus) {
|
||||||
|
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
List<Account> accounts = new Account(context).getCrossAccounts();
|
List<Account> accounts = new Account(context).getCrossAccounts();
|
||||||
|
@ -76,8 +78,26 @@ public class CrossActionHelper {
|
||||||
}
|
}
|
||||||
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||||
builderSingle.setAdapter(accountsSearchAdapter, (dialog, which) -> {
|
builderSingle.setAdapter(accountsSearchAdapter, (dialog, which) -> {
|
||||||
|
boolean confirmFav = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION_FAV), false);
|
||||||
|
boolean confirmBoost = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION), true);
|
||||||
Account selectedAccount = accountArray[which];
|
Account selectedAccount = accountArray[which];
|
||||||
fetchRemote(context, actionType, selectedAccount, targetedAccount, targetedStatus);
|
if ((actionType == TypeOfCrossAction.REBLOG_ACTION && confirmBoost) || (actionType == TypeOfCrossAction.FAVOURITE_ACTION && confirmFav)) {
|
||||||
|
AlertDialog.Builder alt_bld = new AlertDialog.Builder(context, Helper.dialogStyle());
|
||||||
|
if (actionType == TypeOfCrossAction.REBLOG_ACTION) {
|
||||||
|
alt_bld.setMessage(context.getString(R.string.reblog_add));
|
||||||
|
} else {
|
||||||
|
alt_bld.setMessage(context.getString(R.string.favourite_add));
|
||||||
|
}
|
||||||
|
alt_bld.setPositiveButton(R.string.yes, (dia, id) -> {
|
||||||
|
fetchRemote(context, actionType, selectedAccount, targetedAccount, targetedStatus);
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
alt_bld.setNegativeButton(R.string.cancel, (dia, id) -> dialog.dismiss());
|
||||||
|
AlertDialog alert = alt_bld.create();
|
||||||
|
alert.show();
|
||||||
|
} else {
|
||||||
|
fetchRemote(context, actionType, selectedAccount, targetedAccount, targetedStatus);
|
||||||
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
});
|
});
|
||||||
builderSingle.show();
|
builderSingle.show();
|
||||||
|
|
|
@ -427,23 +427,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
if (statusToDeal.visibility.equals("direct") || (statusToDeal.visibility.equals("private"))) {
|
if (statusToDeal.visibility.equals("direct") || (statusToDeal.visibility.equals("private"))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (confirmBoost) {
|
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, null, statusToDeal);
|
||||||
AlertDialog.Builder alt_bld = new AlertDialog.Builder(context, Helper.dialogStyle());
|
|
||||||
if (statusToDeal.reblogged) {
|
|
||||||
alt_bld.setMessage(context.getString(R.string.reblog_remove));
|
|
||||||
} else {
|
|
||||||
alt_bld.setMessage(context.getString(R.string.reblog_add));
|
|
||||||
}
|
|
||||||
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
|
|
||||||
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, null, statusToDeal);
|
|
||||||
dialog.dismiss();
|
|
||||||
});
|
|
||||||
alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
||||||
AlertDialog alert = alt_bld.create();
|
|
||||||
alert.show();
|
|
||||||
} else {
|
|
||||||
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, null, statusToDeal);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
holder.binding.actionButtonBoost.setOnClickListener(v -> {
|
holder.binding.actionButtonBoost.setOnClickListener(v -> {
|
||||||
|
@ -541,16 +525,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
if (statusToDeal.visibility.equals("direct") || (statusToDeal.visibility.equals("private"))) {
|
if (statusToDeal.visibility.equals("direct") || (statusToDeal.visibility.equals("private"))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (confirmFav) {
|
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, null, statusToDeal);
|
||||||
AlertDialog.Builder alt_bld = new AlertDialog.Builder(context, Helper.dialogStyle());
|
|
||||||
alt_bld.setMessage(context.getString(R.string.favourite_add));
|
|
||||||
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, null, statusToDeal));
|
|
||||||
alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
||||||
AlertDialog alert = alt_bld.create();
|
|
||||||
alert.show();
|
|
||||||
} else {
|
|
||||||
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, null, statusToDeal);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
holder.binding.actionButtonFavorite.setOnClickListener(v -> {
|
holder.binding.actionButtonFavorite.setOnClickListener(v -> {
|
||||||
|
|
Loading…
Reference in a new issue