mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Add an option to not show the sign-in reminder
This is done via another preference in the settings screen and an action button attached to the notification itself
This commit is contained in:
@@ -163,6 +163,7 @@ public class AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
SharedPreferences provideSharedPreferences(Application app) {
|
SharedPreferences provideSharedPreferences(Application app) {
|
||||||
|
// FIXME unify this with getDefaultSharedPreferences()
|
||||||
return app.getSharedPreferences("db", MODE_PRIVATE);
|
return app.getSharedPreferences("db", MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import android.app.PendingIntent;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||||
|
import org.briarproject.briar.android.settings.SettingsActivity;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -24,6 +26,8 @@ import static android.os.Build.VERSION.SDK_INT;
|
|||||||
import static android.support.v4.app.NotificationCompat.PRIORITY_LOW;
|
import static android.support.v4.app.NotificationCompat.PRIORITY_LOW;
|
||||||
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_SIGN_IN_REMINDER;
|
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_SIGN_IN_REMINDER;
|
||||||
|
import static org.briarproject.briar.android.settings.SettingsActivity.NO_NOTIFY_SIGN_IN;
|
||||||
|
import static org.briarproject.briar.android.settings.SettingsFragment.NOTIFY_SIGN_IN;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_CHANNEL_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
|
||||||
|
|
||||||
@@ -36,15 +40,17 @@ public class BootReceiver extends BroadcastReceiver {
|
|||||||
public void onReceive(Context ctx, Intent intent) {
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
if (!FEATURE_FLAG_SIGN_IN_REMINDER) return;
|
if (!FEATURE_FLAG_SIGN_IN_REMINDER) return;
|
||||||
|
|
||||||
AndroidComponent applicationComponent =
|
BriarApplication app = (BriarApplication) ctx.getApplicationContext();
|
||||||
((BriarApplication) ctx.getApplicationContext())
|
AndroidComponent applicationComponent = app.getApplicationComponent();
|
||||||
.getApplicationComponent();
|
|
||||||
applicationComponent.inject(this);
|
applicationComponent.inject(this);
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (action != null && action.equals(ACTION_BOOT_COMPLETED)) {
|
if (action != null && action.equals(ACTION_BOOT_COMPLETED)) {
|
||||||
if (databaseConfig.databaseExists()) {
|
if (databaseConfig.databaseExists()) {
|
||||||
showSignInNotification(ctx);
|
SharedPreferences prefs = app.getDefaultSharedPreferences();
|
||||||
|
if (prefs.getBoolean(NOTIFY_SIGN_IN, true)) {
|
||||||
|
showSignInNotification(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,6 +79,14 @@ public class BootReceiver extends BroadcastReceiver {
|
|||||||
b.setWhen(0); // Don't show the time
|
b.setWhen(0); // Don't show the time
|
||||||
b.setPriority(PRIORITY_LOW);
|
b.setPriority(PRIORITY_LOW);
|
||||||
|
|
||||||
|
// Add a 'Do not show sign-in reminder' action
|
||||||
|
String actionTitle =
|
||||||
|
ctx.getString(R.string.reminder_notification_do_not_show_again);
|
||||||
|
Intent i1 = new Intent(ctx, SettingsActivity.class);
|
||||||
|
i1.setAction(NO_NOTIFY_SIGN_IN);
|
||||||
|
PendingIntent actionIntent = PendingIntent.getActivity(ctx, 0, i1, 0);
|
||||||
|
b.addAction(0, actionTitle, actionIntent);
|
||||||
|
|
||||||
Intent i = new Intent(ctx, NavDrawerActivity.class);
|
Intent i = new Intent(ctx, NavDrawerActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
|
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
b.setContentIntent(PendingIntent.getActivity(ctx, 0, i, 0));
|
b.setContentIntent(PendingIntent.getActivity(ctx, 0, i, 0));
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.briarproject.briar.android;
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
@@ -12,4 +14,6 @@ public interface BriarApplication {
|
|||||||
Collection<LogRecord> getRecentLogRecords();
|
Collection<LogRecord> getRecentLogRecords();
|
||||||
|
|
||||||
AndroidComponent getApplicationComponent();
|
AndroidComponent getApplicationComponent();
|
||||||
|
|
||||||
|
SharedPreferences getDefaultSharedPreferences();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,11 +77,12 @@ public class BriarApplicationImpl extends Application
|
|||||||
private final CachingLogHandler logHandler = new CachingLogHandler();
|
private final CachingLogHandler logHandler = new CachingLogHandler();
|
||||||
|
|
||||||
private AndroidComponent applicationComponent;
|
private AndroidComponent applicationComponent;
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
SharedPreferences prefs =
|
if (prefs == null)
|
||||||
PreferenceManager.getDefaultSharedPreferences(base);
|
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
||||||
// Loading the language needs to be done here.
|
// Loading the language needs to be done here.
|
||||||
Localizer.initialize(prefs);
|
Localizer.initialize(prefs);
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
@@ -156,4 +157,9 @@ public class BriarApplicationImpl extends Application
|
|||||||
public AndroidComponent getApplicationComponent() {
|
public AndroidComponent getApplicationComponent() {
|
||||||
return applicationComponent;
|
return applicationComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SharedPreferences getDefaultSharedPreferences() {
|
||||||
|
return prefs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,43 @@
|
|||||||
package org.briarproject.briar.android.settings;
|
package org.briarproject.briar.android.settings;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.BriarApplication;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.android.settings.SettingsFragment.NOTIFY_SIGN_IN;
|
||||||
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
|
||||||
|
|
||||||
public class SettingsActivity extends BriarActivity {
|
public class SettingsActivity extends BriarActivity {
|
||||||
|
|
||||||
|
public static final String NO_NOTIFY_SIGN_IN = "noNotifySignIn";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle bundle) {
|
public void onCreate(Bundle bundle) {
|
||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
|
|
||||||
|
// Maybe turn off sign-in reminder
|
||||||
|
Intent intent = getIntent();
|
||||||
|
if (intent != null && NO_NOTIFY_SIGN_IN.equals(intent.getAction())) {
|
||||||
|
// Turn it off
|
||||||
|
BriarApplication app = (BriarApplication) getApplication();
|
||||||
|
SharedPreferences prefs = app.getDefaultSharedPreferences();
|
||||||
|
prefs.edit().putBoolean(NOTIFY_SIGN_IN, false).apply();
|
||||||
|
// Remove sign-in reminder notification
|
||||||
|
NotificationManager nm = (NotificationManager)
|
||||||
|
getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
if (nm != null) nm.cancel(REMINDER_NOTIFICATION_ID);
|
||||||
|
// Finish this activity again
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setHomeButtonEnabled(true);
|
actionBar.setHomeButtonEnabled(true);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ import static org.briarproject.bramble.util.LogUtils.logDuration;
|
|||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_DARK_THEME;
|
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_DARK_THEME;
|
||||||
|
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_SIGN_IN_REMINDER;
|
||||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
||||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_SIGN_OUT;
|
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_SIGN_OUT;
|
||||||
@@ -97,6 +98,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
public static final String BT_NAMESPACE = BluetoothConstants.ID.getString();
|
public static final String BT_NAMESPACE = BluetoothConstants.ID.getString();
|
||||||
public static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
public static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
||||||
public static final String LANGUAGE = "pref_key_language";
|
public static final String LANGUAGE = "pref_key_language";
|
||||||
|
public static final String NOTIFY_SIGN_IN = "pref_key_notify_sign_in";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(SettingsFragment.class.getName());
|
Logger.getLogger(SettingsFragment.class.getName());
|
||||||
@@ -143,6 +145,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
(ListPreference) findPreference("pref_key_theme");
|
(ListPreference) findPreference("pref_key_theme");
|
||||||
enableBluetooth = (ListPreference) findPreference("pref_key_bluetooth");
|
enableBluetooth = (ListPreference) findPreference("pref_key_bluetooth");
|
||||||
torNetwork = (ListPreference) findPreference("pref_key_tor_network");
|
torNetwork = (ListPreference) findPreference("pref_key_tor_network");
|
||||||
|
CheckBoxPreference notifySignIn =
|
||||||
|
(CheckBoxPreference) findPreference(NOTIFY_SIGN_IN);
|
||||||
notifyPrivateMessages = (CheckBoxPreference) findPreference(
|
notifyPrivateMessages = (CheckBoxPreference) findPreference(
|
||||||
"pref_key_notify_private_messages");
|
"pref_key_notify_private_messages");
|
||||||
notifyGroupMessages = (CheckBoxPreference) findPreference(
|
notifyGroupMessages = (CheckBoxPreference) findPreference(
|
||||||
@@ -199,6 +203,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
theme.setVisible(FEATURE_FLAG_DARK_THEME);
|
theme.setVisible(FEATURE_FLAG_DARK_THEME);
|
||||||
|
notifySignIn.setVisible(FEATURE_FLAG_SIGN_IN_REMINDER);
|
||||||
|
|
||||||
findPreference("pref_key_explode").setVisible(false);
|
findPreference("pref_key_explode").setVisible(false);
|
||||||
findPreference("pref_key_test_data").setVisible(false);
|
findPreference("pref_key_test_data").setVisible(false);
|
||||||
@@ -346,7 +351,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSettingsEnabled(boolean enabled) {
|
private void setSettingsEnabled(boolean enabled) {
|
||||||
// theme not needed here, because handled by SharedPreferences
|
// preferences not needed here, because handled by SharedPreferences:
|
||||||
|
// - pref_key_theme
|
||||||
|
// - pref_key_notify_sign_in
|
||||||
enableBluetooth.setEnabled(enabled);
|
enableBluetooth.setEnabled(enabled);
|
||||||
torNetwork.setEnabled(enabled);
|
torNetwork.setEnabled(enabled);
|
||||||
notifyPrivateMessages.setEnabled(enabled);
|
notifyPrivateMessages.setEnabled(enabled);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
<string name="reminder_notification_title">Signed out of Briar</string>
|
<string name="reminder_notification_title">Signed out of Briar</string>
|
||||||
<string name="reminder_notification_text">Tap to sign back in or swipe to dismiss.</string>
|
<string name="reminder_notification_text">Tap to sign back in or swipe to dismiss.</string>
|
||||||
<string name="reminder_notification_channel_title">Briar Sign-in Reminder</string>
|
<string name="reminder_notification_channel_title">Briar Sign-in Reminder</string>
|
||||||
|
<string name="reminder_notification_do_not_show_again">Don\'t show again</string>
|
||||||
<string name="ongoing_notification_title">Signed into Briar</string>
|
<string name="ongoing_notification_title">Signed into Briar</string>
|
||||||
<string name="ongoing_notification_text">Touch to open Briar.</string>
|
<string name="ongoing_notification_text">Touch to open Briar.</string>
|
||||||
<plurals name="private_message_notification_text">
|
<plurals name="private_message_notification_text">
|
||||||
@@ -373,6 +374,8 @@
|
|||||||
|
|
||||||
<!-- Settings Notifications -->
|
<!-- Settings Notifications -->
|
||||||
<string name="notification_settings_title">Notifications</string>
|
<string name="notification_settings_title">Notifications</string>
|
||||||
|
<string name="notify_sign_in_title">Remind me to sign in</string>
|
||||||
|
<string name="notify_sign_in_summary">Shows a reminder when the phone starts</string>
|
||||||
<string name="notify_private_messages_setting_title">Private messages</string>
|
<string name="notify_private_messages_setting_title">Private messages</string>
|
||||||
<string name="notify_private_messages_setting_summary">Show alerts for private messages</string>
|
<string name="notify_private_messages_setting_summary">Show alerts for private messages</string>
|
||||||
<string name="notify_private_messages_setting_summary_26">Configure alerts for private messages</string>
|
<string name="notify_private_messages_setting_summary_26">Configure alerts for private messages</string>
|
||||||
|
|||||||
@@ -81,6 +81,12 @@
|
|||||||
android:layout="@layout/preferences_category"
|
android:layout="@layout/preferences_category"
|
||||||
android:title="@string/notification_settings_title">
|
android:title="@string/notification_settings_title">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="pref_key_notify_sign_in"
|
||||||
|
android:summary="@string/notify_sign_in_summary"
|
||||||
|
android:title="@string/notify_sign_in_title"/>
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="pref_key_notify_private_messages"
|
android:key="pref_key_notify_private_messages"
|
||||||
|
|||||||
@@ -23,13 +23,14 @@ public class TestBriarApplication extends Application
|
|||||||
Logger.getLogger(TestBriarApplication.class.getName());
|
Logger.getLogger(TestBriarApplication.class.getName());
|
||||||
|
|
||||||
private AndroidComponent applicationComponent;
|
private AndroidComponent applicationComponent;
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
LOG.info("Created");
|
LOG.info("Created");
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
Localizer.initialize(prefs);
|
Localizer.initialize(prefs);
|
||||||
applicationComponent = DaggerAndroidComponent.builder()
|
applicationComponent = DaggerAndroidComponent.builder()
|
||||||
.appModule(new AppModule(this))
|
.appModule(new AppModule(this))
|
||||||
@@ -51,4 +52,9 @@ public class TestBriarApplication extends Application
|
|||||||
public AndroidComponent getApplicationComponent() {
|
public AndroidComponent getApplicationComponent() {
|
||||||
return applicationComponent;
|
return applicationComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SharedPreferences getDefaultSharedPreferences() {
|
||||||
|
return prefs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user