From 8e44348f461b4b3d9f5e33878eb7adb1804a9e90 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Sat, 21 Oct 2017 21:28:05 +0200 Subject: [PATCH] create notification channels ahead of time so users can edit the settings before a notification was issued --- .../com/keylesspalace/tusky/LoginActivity.java | 15 ++++++++++----- .../tusky/fragment/PreferencesFragment.java | 2 ++ .../tusky/util/NotificationMaker.java | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 91ed0750d..b771582a0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -40,6 +40,7 @@ import com.keylesspalace.tusky.entity.AccessToken; import com.keylesspalace.tusky.entity.AppCredentials; import com.keylesspalace.tusky.network.MastodonApi; import com.keylesspalace.tusky.util.CustomTabsHelper; +import com.keylesspalace.tusky.util.NotificationMaker; import com.keylesspalace.tusky.util.OkHttpUtils; import java.util.HashMap; @@ -179,8 +180,8 @@ public class LoginActivity extends AppCompatActivity { } else { Callback callback = new Callback() { @Override - public void onResponse(Call call, - Response response) { + public void onResponse(@NonNull Call call, + @NonNull Response response) { if (!response.isSuccessful()) { editText.setError(getString(R.string.error_failed_app_registration)); Log.e(TAG, "App authentication failed. " + response.message()); @@ -197,7 +198,7 @@ public class LoginActivity extends AppCompatActivity { } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { editText.setError(getString(R.string.error_failed_app_registration)); Log.e(TAG, Log.getStackTraceString(t)); } @@ -334,7 +335,7 @@ public class LoginActivity extends AppCompatActivity { * the authorization code for an access token. */ Callback callback = new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { onLoginSuccess(response.body().accessToken); } else { @@ -348,7 +349,7 @@ public class LoginActivity extends AppCompatActivity { } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { setLoading(false); editText.setError(getString(R.string.error_retrieving_oauth_token)); Log.e(TAG, String.format("%s %s", @@ -393,6 +394,10 @@ public class LoginActivity extends AppCompatActivity { editText.setError(getString(R.string.error_retrieving_oauth_token)); return; } + + //create notification channels ahead of time so users can edit the settings + NotificationMaker.createNotificationChannels(this); + Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java index 7b2bbe398..5d8560792 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/PreferencesFragment.java @@ -24,6 +24,7 @@ import android.preference.PreferenceScreen; import com.keylesspalace.tusky.BuildConfig; import com.keylesspalace.tusky.R; +import com.keylesspalace.tusky.util.NotificationMaker; public class PreferencesFragment extends PreferenceFragment { @Override @@ -34,6 +35,7 @@ public class PreferencesFragment extends PreferenceFragment { //on Android O and newer, launch the system notification settings instead of the app settings if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationMaker.createNotificationChannels(getContext()); PreferenceScreen notificationPreferences = (PreferenceScreen) findPreference("notificationSettings"); notificationPreferences.removeAll(); notificationPreferences.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { diff --git a/app/src/main/java/com/keylesspalace/tusky/util/NotificationMaker.java b/app/src/main/java/com/keylesspalace/tusky/util/NotificationMaker.java index 97555013d..5322cd48d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/NotificationMaker.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/NotificationMaker.java @@ -173,7 +173,7 @@ public class NotificationMaker { notificationManager.notify(notifyId, builder.build()); } - private static void createNotificationChannels(Context context) { + public static void createNotificationChannels(Context context) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mNotificationManager =