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:
Torsten Grote
2018-06-28 16:34:55 -03:00
parent 0f16ac57f3
commit b28307002e
9 changed files with 79 additions and 8 deletions

View File

@@ -163,6 +163,7 @@ public class AppModule {
@Provides
SharedPreferences provideSharedPreferences(Application app) {
// FIXME unify this with getDefaultSharedPreferences()
return app.getSharedPreferences("db", MODE_PRIVATE);
}

View File

@@ -6,12 +6,14 @@ import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.briar.R;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.briarproject.briar.android.settings.SettingsActivity;
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.VISIBILITY_SECRET;
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_NOTIFICATION_ID;
@@ -36,15 +40,17 @@ public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context ctx, Intent intent) {
if (!FEATURE_FLAG_SIGN_IN_REMINDER) return;
AndroidComponent applicationComponent =
((BriarApplication) ctx.getApplicationContext())
.getApplicationComponent();
BriarApplication app = (BriarApplication) ctx.getApplicationContext();
AndroidComponent applicationComponent = app.getApplicationComponent();
applicationComponent.inject(this);
String action = intent.getAction();
if (action != null && action.equals(ACTION_BOOT_COMPLETED)) {
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.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);
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
b.setContentIntent(PendingIntent.getActivity(ctx, 0, i, 0));

View File

@@ -1,5 +1,7 @@
package org.briarproject.briar.android;
import android.content.SharedPreferences;
import java.util.Collection;
import java.util.logging.LogRecord;
@@ -12,4 +14,6 @@ public interface BriarApplication {
Collection<LogRecord> getRecentLogRecords();
AndroidComponent getApplicationComponent();
SharedPreferences getDefaultSharedPreferences();
}

View File

@@ -77,11 +77,12 @@ public class BriarApplicationImpl extends Application
private final CachingLogHandler logHandler = new CachingLogHandler();
private AndroidComponent applicationComponent;
private SharedPreferences prefs;
@Override
protected void attachBaseContext(Context base) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(base);
if (prefs == null)
prefs = PreferenceManager.getDefaultSharedPreferences(base);
// Loading the language needs to be done here.
Localizer.initialize(prefs);
super.attachBaseContext(
@@ -156,4 +157,9 @@ public class BriarApplicationImpl extends Application
public AndroidComponent getApplicationComponent() {
return applicationComponent;
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return prefs;
}
}

View File

@@ -1,19 +1,43 @@
package org.briarproject.briar.android.settings;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import org.briarproject.briar.R;
import org.briarproject.briar.android.BriarApplication;
import org.briarproject.briar.android.activity.ActivityComponent;
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 static final String NO_NOTIFY_SIGN_IN = "noNotifySignIn";
@Override
public void onCreate(Bundle 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();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);

View File

@@ -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.now;
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.activity.RequestCodes.REQUEST_RINGTONE;
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 TOR_NAMESPACE = TorConstants.ID.getString();
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 =
Logger.getLogger(SettingsFragment.class.getName());
@@ -143,6 +145,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
(ListPreference) findPreference("pref_key_theme");
enableBluetooth = (ListPreference) findPreference("pref_key_bluetooth");
torNetwork = (ListPreference) findPreference("pref_key_tor_network");
CheckBoxPreference notifySignIn =
(CheckBoxPreference) findPreference(NOTIFY_SIGN_IN);
notifyPrivateMessages = (CheckBoxPreference) findPreference(
"pref_key_notify_private_messages");
notifyGroupMessages = (CheckBoxPreference) findPreference(
@@ -199,6 +203,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
);
} else {
theme.setVisible(FEATURE_FLAG_DARK_THEME);
notifySignIn.setVisible(FEATURE_FLAG_SIGN_IN_REMINDER);
findPreference("pref_key_explode").setVisible(false);
findPreference("pref_key_test_data").setVisible(false);
@@ -346,7 +351,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
}
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);
torNetwork.setEnabled(enabled);
notifyPrivateMessages.setEnabled(enabled);

View File

@@ -71,6 +71,7 @@
<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_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_text">Touch to open Briar.</string>
<plurals name="private_message_notification_text">
@@ -373,6 +374,8 @@
<!-- Settings Notifications -->
<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_summary">Show alerts for private messages</string>
<string name="notify_private_messages_setting_summary_26">Configure alerts for private messages</string>

View File

@@ -81,6 +81,12 @@
android:layout="@layout/preferences_category"
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
android:defaultValue="true"
android:key="pref_key_notify_private_messages"

View File

@@ -23,13 +23,14 @@ public class TestBriarApplication extends Application
Logger.getLogger(TestBriarApplication.class.getName());
private AndroidComponent applicationComponent;
private SharedPreferences prefs;
@Override
public void onCreate() {
super.onCreate();
LOG.info("Created");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
Localizer.initialize(prefs);
applicationComponent = DaggerAndroidComponent.builder()
.appModule(new AppModule(this))
@@ -51,4 +52,9 @@ public class TestBriarApplication extends Application
public AndroidComponent getApplicationComponent() {
return applicationComponent;
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return prefs;
}
}