create notification channels ahead of time so users can edit the settings before a notification was issued
This commit is contained in:
parent
8b13ce4806
commit
8e44348f46
|
@ -40,6 +40,7 @@ import com.keylesspalace.tusky.entity.AccessToken;
|
||||||
import com.keylesspalace.tusky.entity.AppCredentials;
|
import com.keylesspalace.tusky.entity.AppCredentials;
|
||||||
import com.keylesspalace.tusky.network.MastodonApi;
|
import com.keylesspalace.tusky.network.MastodonApi;
|
||||||
import com.keylesspalace.tusky.util.CustomTabsHelper;
|
import com.keylesspalace.tusky.util.CustomTabsHelper;
|
||||||
|
import com.keylesspalace.tusky.util.NotificationMaker;
|
||||||
import com.keylesspalace.tusky.util.OkHttpUtils;
|
import com.keylesspalace.tusky.util.OkHttpUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -179,8 +180,8 @@ public class LoginActivity extends AppCompatActivity {
|
||||||
} else {
|
} else {
|
||||||
Callback<AppCredentials> callback = new Callback<AppCredentials>() {
|
Callback<AppCredentials> callback = new Callback<AppCredentials>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<AppCredentials> call,
|
public void onResponse(@NonNull Call<AppCredentials> call,
|
||||||
Response<AppCredentials> response) {
|
@NonNull Response<AppCredentials> response) {
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
editText.setError(getString(R.string.error_failed_app_registration));
|
editText.setError(getString(R.string.error_failed_app_registration));
|
||||||
Log.e(TAG, "App authentication failed. " + response.message());
|
Log.e(TAG, "App authentication failed. " + response.message());
|
||||||
|
@ -197,7 +198,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<AppCredentials> call, Throwable t) {
|
public void onFailure(@NonNull Call<AppCredentials> call, @NonNull Throwable t) {
|
||||||
editText.setError(getString(R.string.error_failed_app_registration));
|
editText.setError(getString(R.string.error_failed_app_registration));
|
||||||
Log.e(TAG, Log.getStackTraceString(t));
|
Log.e(TAG, Log.getStackTraceString(t));
|
||||||
}
|
}
|
||||||
|
@ -334,7 +335,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||||
* the authorization code for an access token. */
|
* the authorization code for an access token. */
|
||||||
Callback<AccessToken> callback = new Callback<AccessToken>() {
|
Callback<AccessToken> callback = new Callback<AccessToken>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<AccessToken> call, Response<AccessToken> response) {
|
public void onResponse(@NonNull Call<AccessToken> call, @NonNull Response<AccessToken> response) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
onLoginSuccess(response.body().accessToken);
|
onLoginSuccess(response.body().accessToken);
|
||||||
} else {
|
} else {
|
||||||
|
@ -348,7 +349,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<AccessToken> call, Throwable t) {
|
public void onFailure(@NonNull Call<AccessToken> call, @NonNull Throwable t) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
editText.setError(getString(R.string.error_retrieving_oauth_token));
|
editText.setError(getString(R.string.error_retrieving_oauth_token));
|
||||||
Log.e(TAG, String.format("%s %s",
|
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));
|
editText.setError(getString(R.string.error_retrieving_oauth_token));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//create notification channels ahead of time so users can edit the settings
|
||||||
|
NotificationMaker.createNotificationChannels(this);
|
||||||
|
|
||||||
Intent intent = new Intent(this, MainActivity.class);
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.keylesspalace.tusky.BuildConfig;
|
import com.keylesspalace.tusky.BuildConfig;
|
||||||
import com.keylesspalace.tusky.R;
|
import com.keylesspalace.tusky.R;
|
||||||
|
import com.keylesspalace.tusky.util.NotificationMaker;
|
||||||
|
|
||||||
public class PreferencesFragment extends PreferenceFragment {
|
public class PreferencesFragment extends PreferenceFragment {
|
||||||
@Override
|
@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
|
//on Android O and newer, launch the system notification settings instead of the app settings
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
NotificationMaker.createNotificationChannels(getContext());
|
||||||
PreferenceScreen notificationPreferences = (PreferenceScreen) findPreference("notificationSettings");
|
PreferenceScreen notificationPreferences = (PreferenceScreen) findPreference("notificationSettings");
|
||||||
notificationPreferences.removeAll();
|
notificationPreferences.removeAll();
|
||||||
notificationPreferences.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
notificationPreferences.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class NotificationMaker {
|
||||||
notificationManager.notify(notifyId, builder.build());
|
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) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
|
||||||
NotificationManager mNotificationManager =
|
NotificationManager mNotificationManager =
|
||||||
|
|
Loading…
Reference in New Issue