Add notification to copy extra field, remove unused string

This commit is contained in:
J-Jamet committed 2018-03-20 14:47:49 +01:00
1 parent 55ee89314f
commit 62f6f02467
29 files changed
+207 -897

No files matched your search

@@ -26,6 +26,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -59,6 +60,8 @@ import java.util.UUID;
import static com.keepassdroid.settings.PreferencesUtil.isClipboardNotificationsEnable;
public class EntryActivity extends LockingHideActivity {
private final static String TAG = EntryActivity.class.getName();
public static final String KEY_ENTRY = "entry";
private ImageView titleIconView;
@@ -165,6 +168,24 @@ public class EntryActivity extends LockingHideActivity {
NotificationField.NotificationFieldId.PASSWORD,
mEntry.getPassword(),
getResources()));
// Add extra fields
if (mEntry.allowExtraFields()) {
try {
int anonymousFieldNumber = 0;
for (Map.Entry<String, String> entry : mEntry.getExtraFields(App.getDB().pm).entrySet()) {
notificationFields.add(
new NotificationField(
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
entry.getValue(),
entry.getKey(),
getResources()));
anonymousFieldNumber++;
}
} catch (ArrayIndexOutOfBoundsException e) {
Log.w(TAG, "Only " + NotificationField.NotificationFieldId.getAnonymousFieldId().length +
" anonymous notifications are available");
}
}
// Add notifications
intent.putParcelableArrayListExtra(NotificationCopyingService.EXTRA_FIELDS, notificationFields);
@@ -52,6 +52,13 @@ public class NotificationField implements Parcelable {
this.copyText = getCopyText(resources);
}
public NotificationField(NotificationFieldId id, String value, String label, Resources resources) {
this.id = id;
this.value = value;
this.label = label;
this.copyText = getCopyText(resources);
}
protected NotificationField(Parcel in) {
id = NotificationFieldId.values()[in.readInt()];
value = in.readString();
@@ -99,6 +106,10 @@ public class NotificationField implements Parcelable {
public enum NotificationFieldId {
USERNAME, PASSWORD, FIELD_A, FIELD_B, FIELD_C;
public static NotificationFieldId[] getAnonymousFieldId() {
return new NotificationFieldId[] {FIELD_A, FIELD_B, FIELD_C};
}
}
private static final String ACTION_COPY_PREFIX = "ACTION_COPY_";
@@ -143,35 +154,18 @@ public class NotificationField implements Parcelable {
return actionKeys;
}
public static List<String> getAllExtraKeys() {
List<String> extraKeys = new ArrayList<>();
for (NotificationFieldId id : NotificationFieldId.values()) {
extraKeys.add(getExtraKey(id));
}
return extraKeys;
}
private String getLabel(Resources resources) {
switch (id) {
case USERNAME:
return resources.getString(R.string.entry_user_name);
case PASSWORD:
return resources.getString(R.string.entry_password);
// TODO default
default:
return "";
return id.name();
}
}
private String getCopyText(Resources resources) {
switch (id) {
case USERNAME:
return resources.getString(R.string.copy_username);
case PASSWORD:
return resources.getString(R.string.copy_password);
// TODO default
default:
return "";
}
return resources.getString(R.string.select_to_copy, label);
}
}