avoid multiple warnings when no push app
This commit is contained in:
parent
a7858b6857
commit
a5044c2d6d
|
@ -44,8 +44,34 @@ public class PushHelper {
|
|||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
|
||||
((Activity) context).runOnUiThread(() -> {
|
||||
for (Account account : accounts) {
|
||||
registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
|
||||
Registration registration = new Registration();
|
||||
List<String> distributors = registration.getDistributors(context);
|
||||
if (distributors.size() == 0) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
int style;
|
||||
if (theme == Helper.THEME_DARK) {
|
||||
style = R.style.DialogDark;
|
||||
} else if (theme == Helper.THEME_BLACK) {
|
||||
style = R.style.DialogBlack;
|
||||
} else {
|
||||
style = R.style.Dialog;
|
||||
}
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(context, style);
|
||||
alert.setTitle(R.string.no_distributors_found);
|
||||
final TextView message = new TextView(context);
|
||||
String link = "https://fedilab.app/wiki/features/push-notifications/";
|
||||
final SpannableString s =
|
||||
new SpannableString(context.getString(R.string.no_distributors_explanation, link));
|
||||
Linkify.addLinks(s, Linkify.WEB_URLS);
|
||||
message.setText(s);
|
||||
message.setPadding(30, 20, 30, 10);
|
||||
message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
alert.setView(message);
|
||||
alert.setPositiveButton(R.string.close, (dialog, whichButton) -> dialog.dismiss());
|
||||
alert.show();
|
||||
} else {
|
||||
registerAppWithDialog(context, accounts);
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
|
@ -73,7 +99,7 @@ public class PushHelper {
|
|||
}
|
||||
|
||||
|
||||
private static void registerAppWithDialog(Context context, String slug) {
|
||||
private static void registerAppWithDialog(Context context, List<Account> accounts) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
int style;
|
||||
|
@ -91,32 +117,23 @@ public class PushHelper {
|
|||
if (distributors.size() == 1) {
|
||||
registration.saveDistributor(context, distributors.get(0));
|
||||
}
|
||||
registration.registerApp(context, slug);
|
||||
for (Account account : accounts) {
|
||||
registration.registerApp(context, account.getUsername() + "@" + account.getInstance());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(context, style);
|
||||
if (distributors.size() == 0) {
|
||||
alert.setTitle(R.string.no_distributors_found);
|
||||
final TextView message = new TextView(context);
|
||||
String link = "https://fedilab.app/wiki/features/push-notifications/";
|
||||
final SpannableString s =
|
||||
new SpannableString(context.getString(R.string.no_distributors_explanation, link));
|
||||
Linkify.addLinks(s, Linkify.WEB_URLS);
|
||||
message.setText(s);
|
||||
message.setPadding(30, 20, 30, 10);
|
||||
message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
alert.setView(message);
|
||||
alert.setPositiveButton(R.string.close, (dialog, whichButton) -> dialog.dismiss());
|
||||
} else {
|
||||
alert.setTitle(R.string.select_distributors);
|
||||
String[] distributorsStr = distributors.toArray(new String[0]);
|
||||
alert.setSingleChoiceItems(distributorsStr, -1, (dialog, item) -> {
|
||||
String distributor = distributorsStr[item];
|
||||
registration.saveDistributor(context, distributor);
|
||||
registration.registerApp(context, slug);
|
||||
dialog.dismiss();
|
||||
});
|
||||
}
|
||||
alert.setTitle(R.string.select_distributors);
|
||||
String[] distributorsStr = distributors.toArray(new String[0]);
|
||||
alert.setSingleChoiceItems(distributorsStr, -1, (dialog, item) -> {
|
||||
String distributor = distributorsStr[item];
|
||||
registration.saveDistributor(context, distributor);
|
||||
for (Account account : accounts) {
|
||||
registration.registerApp(context, account.getUsername() + "@" + account.getInstance());
|
||||
}
|
||||
dialog.dismiss();
|
||||
});
|
||||
alert.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ class handler implements MessagingReceiverHandler {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRegistrationFailed(@Nullable Context context, @NotNull String s) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue