resolved non-conflict
This commit is contained in:
commit
e48bf683f7
|
@ -55,11 +55,14 @@
|
||||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
|
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service android:name=".MyFirebaseMessagingService" android:exported="true">
|
<service android:name=".MyFirebaseMessagingService" android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
|
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<receiver android:name=".NotificationClearBroadcastReceiver" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -28,6 +28,7 @@ import android.text.Spanned;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
|
||||||
|
import com.google.firebase.iid.FirebaseInstanceId;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
|
@ -38,6 +39,9 @@ import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
|
|
||||||
|
@ -96,6 +100,11 @@ public class BaseActivity extends AppCompatActivity {
|
||||||
return preferences.getString("accessToken", null);
|
return preferences.getString("accessToken", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean arePushNotificationsEnabled() {
|
||||||
|
SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||||
|
return preferences.getBoolean("notificationsEnabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
protected String getBaseUrl() {
|
protected String getBaseUrl() {
|
||||||
SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||||
return "https://" + preferences.getString("domain", null);
|
return "https://" + preferences.getString("domain", null);
|
||||||
|
@ -161,4 +170,32 @@ public class BaseActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void enablePushNotifications() {
|
||||||
|
tuskyAPI.register(getBaseUrl(), getAccessToken(), FirebaseInstanceId.getInstance().getToken()).enqueue(new Callback<ResponseBody>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void disablePushNotifications() {
|
||||||
|
tuskyAPI.unregister(getBaseUrl(), getAccessToken()).enqueue(new Callback<ResponseBody>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,6 @@ public class LoginActivity extends AppCompatActivity {
|
||||||
@BindView(R.id.button_login) Button button;
|
@BindView(R.id.button_login) Button button;
|
||||||
@BindView(R.id.no_account) TextView noAccount;
|
@BindView(R.id.no_account) TextView noAccount;
|
||||||
|
|
||||||
protected void createMastodonAPI() {
|
|
||||||
// Don't do this in this activity, since we don't know a domain yet
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chain together the key-value pairs into a query string, for either appending to a URL or
|
* Chain together the key-value pairs into a query string, for either appending to a URL or
|
||||||
* as the content of an HTTP request.
|
* as the content of an HTTP request.
|
||||||
|
|
|
@ -39,7 +39,6 @@ import android.widget.TextView;
|
||||||
import com.arlib.floatingsearchview.FloatingSearchView;
|
import com.arlib.floatingsearchview.FloatingSearchView;
|
||||||
import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter;
|
import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter;
|
||||||
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
|
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
|
||||||
import com.google.firebase.iid.FirebaseInstanceId;
|
|
||||||
import com.keylesspalace.tusky.entity.Account;
|
import com.keylesspalace.tusky.entity.Account;
|
||||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||||
import com.mikepenz.materialdrawer.AccountHeader;
|
import com.mikepenz.materialdrawer.AccountHeader;
|
||||||
|
@ -61,7 +60,6 @@ import java.util.Stack;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
@ -175,17 +173,7 @@ public class MainActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup push notifications
|
// Setup push notifications
|
||||||
tuskyAPI.register(getBaseUrl(), getAccessToken(), FirebaseInstanceId.getInstance().getToken()).enqueue(new Callback<ResponseBody>() {
|
if (arePushNotificationsEnabled()) enablePushNotifications();
|
||||||
@Override
|
|
||||||
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
|
||||||
Log.d(TAG, "tusky-api reponse: " + response.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
|
||||||
Log.d(TAG, "tusky-api failure: " + t.getMessage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -277,17 +265,7 @@ public class MainActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logout() {
|
private void logout() {
|
||||||
tuskyAPI.unregister(getBaseUrl(), getAccessToken()).enqueue(new Callback<ResponseBody>() {
|
if (arePushNotificationsEnabled()) disablePushNotifications();
|
||||||
@Override
|
|
||||||
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
|
|
@ -55,6 +55,13 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
||||||
|
|
||||||
Log.d(TAG, notificationId);
|
Log.d(TAG, notificationId);
|
||||||
|
|
||||||
|
SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||||
|
boolean enabled = preferences.getBoolean("notificationsEnabled", true);
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
createMastodonAPI();
|
createMastodonAPI();
|
||||||
|
|
||||||
mastodonAPI.notification(notificationId).enqueue(new Callback<Notification>() {
|
mastodonAPI.notification(notificationId).enqueue(new Callback<Notification>() {
|
||||||
|
@ -152,9 +159,13 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
||||||
stackBuilder.addNextIntent(resultIntent);
|
stackBuilder.addNextIntent(resultIntent);
|
||||||
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
Intent deleteIntent = new Intent(this, NotificationClearBroadcastReceiver.class);
|
||||||
|
PendingIntent deletePendingIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
|
||||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||||
.setSmallIcon(R.drawable.ic_notify)
|
.setSmallIcon(R.drawable.ic_notify)
|
||||||
.setContentIntent(resultPendingIntent)
|
.setContentIntent(resultPendingIntent)
|
||||||
|
.setDeleteIntent(deletePendingIntent)
|
||||||
.setDefaults(0); // So it doesn't ring twice, notify only in Target callback
|
.setDefaults(0); // So it doesn't ring twice, notify only in Target callback
|
||||||
|
|
||||||
if (currentNotifications.length() == 1) {
|
if (currentNotifications.length() == 1) {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.keylesspalace.tusky;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
public class NotificationClearBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = notificationPreferences.edit();
|
||||||
|
editor.putString("current", "[]");
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
}
|
|
@ -68,6 +68,14 @@ public class PreferencesActivity extends BaseActivity
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||||
|
} else if (key.equals("notificationsEnabled")) {
|
||||||
|
boolean notificationsEnabled = sharedPreferences.getBoolean("notificationsEnabled", true);
|
||||||
|
|
||||||
|
if (notificationsEnabled) {
|
||||||
|
enablePushNotifications();
|
||||||
|
} else {
|
||||||
|
disablePushNotifications();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/status_share"
|
||||||
|
android:title="@string/action_share"/>
|
||||||
<item android:title="@string/action_delete"
|
<item android:title="@string/action_delete"
|
||||||
android:id="@+id/status_delete" />
|
android:id="@+id/status_delete" />
|
||||||
</menu>
|
</menu>
|
|
@ -133,4 +133,5 @@
|
||||||
<string name="notification_summary_medium">%1$s, %2$s, and %3$s</string>
|
<string name="notification_summary_medium">%1$s, %2$s, and %3$s</string>
|
||||||
<string name="notification_summary_small">%1$s and %2$s</string>
|
<string name="notification_summary_small">%1$s and %2$s</string>
|
||||||
<string name="notification_title_summary">%d new interactions</string>
|
<string name="notification_title_summary">%d new interactions</string>
|
||||||
|
<string name="pref_title_notifications_enabled">Push notifications</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,23 +1,28 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:key="@string/preferences_file_key">
|
android:key="@string/preferences_file_key">
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/pref_title_notification_settings">
|
<PreferenceCategory android:title="@string/pref_title_notification_settings">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
android:key="notificationsEnabled"
|
||||||
|
android:title="@string/pref_title_notifications_enabled"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:dependency="notificationsEnabled"
|
||||||
android:key="notificationAlertSound"
|
android:key="notificationAlertSound"
|
||||||
android:title="@string/pref_title_notification_alert_sound"
|
android:title="@string/pref_title_notification_alert_sound"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
android:dependency="notificationsEnabled"
|
||||||
android:key="notificationStyleVibrate"
|
android:key="notificationStyleVibrate"
|
||||||
android:title="@string/pref_title_notification_style_vibrate"
|
android:title="@string/pref_title_notification_style_vibrate"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
android:dependency="notificationsEnabled"
|
||||||
android:key="notificationStyleLight"
|
android:key="notificationStyleLight"
|
||||||
android:title="@string/pref_title_notification_style_light"
|
android:title="@string/pref_title_notification_style_light"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
Loading…
Reference in New Issue