Option to disable notifications #7

This commit is contained in:
J-Jamet
2017-11-30 01:32:16 +01:00
parent d14dc22918
commit 4794ccb38a
6 changed files with 48 additions and 26 deletions

View File

@@ -69,6 +69,8 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import static com.keepassdroid.settings.PrefsUtil.isClipboardNotificationsEnable;
public class EntryActivity extends LockCloseHideActivity {
public static final String KEY_ENTRY = "entry";
public static final String KEY_REFRESH_POS = "refresh_pos";
@@ -153,7 +155,6 @@ public class EntryActivity extends LockCloseHideActivity {
Intent i = getIntent();
UUID uuid = Types.bytestoUUID(i.getByteArrayExtra(KEY_ENTRY));
mPos = i.getIntExtra(KEY_REFRESH_POS, -1);
assert(uuid != null);
mEntry = db.pm.entries.get(uuid);
if (mEntry == null) {
@@ -171,37 +172,41 @@ public class EntryActivity extends LockCloseHideActivity {
fillData(false);
setupEditButtons();
// Notification Manager
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if ( mEntry.getPassword().length() > 0 ) {
// only show notification if password is available
Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
mNM.notify(NOTIFY_PASSWORD, password);
}
if ( mEntry.getUsername().length() > 0 ) {
// only show notification if username is available
Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username);
mNM.notify(NOTIFY_USERNAME, username);
}
// If notifications enabled in settings
if (isClipboardNotificationsEnable(getApplicationContext())) {
// Notification Manager
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (mEntry.getPassword().length() > 0) {
// only show notification if password is available
Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
mNM.notify(NOTIFY_PASSWORD, password);
}
if (mEntry.getUsername().length() > 0) {
// only show notification if username is available
Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username);
mNM.notify(NOTIFY_USERNAME, username);
}
}
mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ( action.equals(Intents.COPY_USERNAME) ) {
String username = mEntry.getUsername();
if ( username.length() > 0 ) {
timeoutCopyToClipboard(username);
}
} else if ( action.equals(Intents.COPY_PASSWORD) ) {
String password = new String(mEntry.getPassword());
if ( password.length() > 0 ) {
timeoutCopyToClipboard(new String(mEntry.getPassword()));
if ( action != null) {
if (action.equals(Intents.COPY_USERNAME)) {
String username = mEntry.getUsername();
if (username.length() > 0) {
timeoutCopyToClipboard(username);
}
} else if (action.equals(Intents.COPY_PASSWORD)) {
String password = mEntry.getPassword();
if (password.length() > 0) {
timeoutCopyToClipboard(password);
}
}
}
}

View File

@@ -49,4 +49,10 @@ public class PrefsUtil {
ctx.getResources()
.getStringArray(R.array.list_password_generator_options_default_values))));
}
public static boolean isClipboardNotificationsEnable(Context ctx) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
return prefs.getBoolean(ctx.getString(R.string.clipboard_notifications_key),
ctx.getResources().getBoolean(R.bool.clipboard_notifications_default));
}
}

View File

@@ -206,6 +206,8 @@
<string name="password_size_summary">Définir la taille par défaut du mot de passe généré</string>
<string name="list_password_generator_options_title">Caractères de mot de passe</string>
<string name="list_password_generator_options_summary">Définir les caractères par défaut du générateur de mot de passe</string>
<string name="clipboard_notifications_title">Notifications du presse-papiers</string>
<string name="clipboard_notifications_summary">Activer les notifications du presse-papiers pour copier le nom d\'utilisateur et le mot de passe</string>
<string-array name="clipboard_timeout_options">
<item>30 secondes</item>

View File

@@ -52,6 +52,7 @@
<string name="timeout_key" translatable="false">timeout_key</string>
<string name="saf_key" translatable="false">storage_access_framework_key</string>
<string name="setting_style_key" translatable="false">setting_style_key</string>
<string name="clipboard_notifications_key" translatable="false">clipboard_notifications_key</string>
<bool name="maskpass_default" translatable="false">true</bool>
<bool name="keyfile_default" translatable="false">true</bool>
@@ -59,6 +60,7 @@
<bool name="omitbackup_default" translatable="false">true</bool>
<bool name="recentfile_default" translatable="false">true</bool>
<bool name="saf_default" translatable="false">false</bool>
<bool name="clipboard_notifications_default" translatable="false">true</bool>
<string name="clipboard_timeout_default" translatable="false">300000</string>
<string-array name="clipboard_timeout_values">

View File

@@ -206,6 +206,8 @@
<string name="password_size_summary">Set the default size of the generated password</string>
<string name="list_password_generator_options_title">Password characters</string>
<string name="list_password_generator_options_summary">Set the default password generator characters</string>
<string name="clipboard_notifications_title">Clipboard Notifications</string>
<string name="clipboard_notifications_summary">Enable clipboard notifications to copy username and password</string>
<string-array name="clipboard_timeout_options">
<item>30 seconds</item>

View File

@@ -49,6 +49,11 @@
android:defaultValue="@bool/saf_default"
android:title="@string/use_saf_title"
android:key="@string/saf_key"/>
<SwitchPreference
android:key="@string/clipboard_notifications_key"
android:title="@string/clipboard_notifications_title"
android:defaultValue="@bool/clipboard_notifications_default"
android:summary="@string/clipboard_notifications_summary" />
</PreferenceCategory>