Fix visual elements

This commit is contained in:
J-Jamet
2018-08-01 15:45:49 +02:00
parent ecb0138c90
commit 55dc504f26
18 changed files with 106 additions and 42 deletions

View File

@@ -323,7 +323,7 @@ public class EntryActivity extends LockingHideActivity {
} }
// Assign title text // Assign title text
titleView.setText(mEntry.getDisplayTitle()); titleView.setText(mEntry.getVisualTitle());
// Assign basic fields // Assign basic fields
entryContentsView.assignUserName(mEntry.getUsername()); entryContentsView.assignUserName(mEntry.getUsername());

View File

@@ -542,7 +542,7 @@ public class GroupActivity extends LockingActivity
switch (node.getType()) { switch (node.getType()) {
case GROUP: case GROUP:
oldGroupToUpdate = (PwGroup) node; oldGroupToUpdate = (PwGroup) node;
GroupEditDialogFragment.build(node) GroupEditDialogFragment.build(oldGroupToUpdate)
.show(getSupportFragmentManager(), .show(getSupportFragmentManager(),
GroupEditDialogFragment.TAG_CREATE_GROUP); GroupEditDialogFragment.TAG_CREATE_GROUP);
break; break;
@@ -705,6 +705,8 @@ public class GroupActivity extends LockingActivity
super.onResume(); super.onResume();
// Refresh the elements // Refresh the elements
assignGroupViewElements(); assignGroupViewElements();
// Refresh suggestions to change preferences
searchSuggestionAdapter.reInit(this);
} }
/** /**

View File

@@ -239,7 +239,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
database.getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon()); database.getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon());
} }
// Assign text // Assign text
holder.text.setText(subNode.getDisplayTitle()); holder.text.setText(subNode.getTitle());
// Assign click // Assign click
holder.container.setOnClickListener( holder.container.setOnClickListener(
new OnNodeClickListener(subNode)); new OnNodeClickListener(subNode));
@@ -252,12 +252,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
// Add username // Add username
holder.subText.setText(""); holder.subText.setText("");
holder.subText.setVisibility(View.GONE); holder.subText.setVisibility(View.GONE);
if (showUsernames && subNode.getType().equals(PwNode.Type.ENTRY)) { if (subNode.getType().equals(PwNode.Type.ENTRY)) {
PwEntry entry = (PwEntry) subNode; PwEntry entry = (PwEntry) subNode;
entry.startToManageFieldReferences(database.getPwDatabase()); entry.startToManageFieldReferences(database.getPwDatabase());
holder.text.setText(entry.getVisualTitle());
String username = entry.getUsername(); String username = entry.getUsername();
if (!username.isEmpty()) { if (showUsernames && !username.isEmpty()) {
holder.subText.setVisibility(View.VISIBLE); holder.subText.setVisibility(View.VISIBLE);
holder.subText.setText(username); holder.subText.setText(username);
} }

View File

@@ -37,6 +37,7 @@ import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwIconFactory; import com.kunzisoft.keepass.database.PwIconFactory;
import com.kunzisoft.keepass.database.cursor.EntryCursor; import com.kunzisoft.keepass.database.cursor.EntryCursor;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import java.util.UUID; import java.util.UUID;
@@ -44,6 +45,7 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
private LayoutInflater cursorInflater; private LayoutInflater cursorInflater;
private Database database; private Database database;
private boolean displayUsername;
private int iconColor; private int iconColor;
public SearchEntryCursorAdapter(Context context, Database database) { public SearchEntryCursorAdapter(Context context, Database database) {
@@ -57,6 +59,12 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
TypedArray taTextColor = context.getTheme().obtainStyledAttributes(attrTextColor); TypedArray taTextColor = context.getTheme().obtainStyledAttributes(attrTextColor);
this.iconColor = taTextColor.getColor(0, Color.WHITE); this.iconColor = taTextColor.getColor(0, Color.WHITE);
taTextColor.recycle(); taTextColor.recycle();
reInit(context);
}
public void reInit(Context context) {
this.displayUsername = PreferencesUtil.showUsernamesListEntries(context);
} }
@Override @Override
@@ -66,6 +74,7 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
ViewHolder viewHolder = new ViewHolder(); ViewHolder viewHolder = new ViewHolder();
viewHolder.imageViewIcon = view.findViewById(R.id.entry_icon); viewHolder.imageViewIcon = view.findViewById(R.id.entry_icon);
viewHolder.textViewTitle = view.findViewById(R.id.entry_text); viewHolder.textViewTitle = view.findViewById(R.id.entry_text);
viewHolder.textViewSubTitle = view.findViewById(R.id.entry_subtext);
view.setTag(viewHolder); view.setTag(viewHolder);
return view; return view;
@@ -75,6 +84,8 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {
// Retrieve elements from cursor // Retrieve elements from cursor
UUID uuid = new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS)));
PwIconFactory iconFactory = database.getPwDatabase().getIconFactory(); PwIconFactory iconFactory = database.getPwDatabase().getIconFactory();
PwIcon icon = iconFactory.getIcon( PwIcon icon = iconFactory.getIcon(
new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS)), new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS)),
@@ -85,6 +96,8 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
icon = iconFactory.getKeyIcon(); icon = iconFactory.getKeyIcon();
} }
String title = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_TITLE) ); String title = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_TITLE) );
String username = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_USERNAME) );
String url = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_URL) );
ViewHolder viewHolder = (ViewHolder) view.getTag(); ViewHolder viewHolder = (ViewHolder) view.getTag();
@@ -95,12 +108,17 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
database.getDrawFactory().assignDatabaseIconTo(context, viewHolder.imageViewIcon, icon); database.getDrawFactory().assignDatabaseIconTo(context, viewHolder.imageViewIcon, icon);
} }
// Assign title // Assign title
viewHolder.textViewTitle.setText(title); String showTitle = PwEntry.getVisualTitle(false, title, username, url, uuid);
viewHolder.textViewTitle.setText(showTitle);
if (displayUsername && !username.isEmpty()) {
viewHolder.textViewSubTitle.setText(String.format("(%s)", username));
}
} }
private static class ViewHolder { private static class ViewHolder {
ImageView imageViewIcon; ImageView imageViewIcon;
TextView textViewTitle; TextView textViewTitle;
TextView textViewSubTitle;
} }
@Override @Override

View File

@@ -97,21 +97,31 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
return getTitle().equals(PMS_TAN_ENTRY) && (getUsername().length() > 0); return getTitle().equals(PMS_TAN_ENTRY) && (getUsername().length() > 0);
} }
@Override /**
public String getDisplayTitle() { * {@inheritDoc}
if ( isTan() ) { * Get the display title from an entry, <br />
return PMS_TAN_ENTRY + " " + getUsername(); * {@link #startToManageFieldReferences(PwDatabase)} and {@link #stopToManageFieldReferences()} must be called
} else { * before and after {@link #getVisualTitle()}
if (getTitle().isEmpty()) */
if (getUrl().isEmpty()) public String getVisualTitle() {
return getUUID().toString(); // only used to compare, don't car if it's a reference
else return getVisualTitle(isTan(), getTitle(), getUsername(), getUrl(), getUUID());
return getUrl();
else
return getTitle();
}
} }
public static String getVisualTitle(boolean isTAN, String title, String username, String url, UUID uuid) {
if ( isTAN ) {
return PMS_TAN_ENTRY + " " + username;
} else {
if (title.isEmpty())
if (url.isEmpty())
return uuid.toString();
else
return url;
else
return title;
}
}
// TODO encapsulate extra fields // TODO encapsulate extra fields
/** /**

View File

@@ -130,10 +130,18 @@ public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup
public abstract void setId(PwGroupId id); public abstract void setId(PwGroupId id);
@Override @Override
public String getDisplayTitle() { protected String getVisualTitle() {
return getTitle();
}
@Override
public String getTitle() {
return getName(); return getName();
} }
/**
* The same thing as {@link #getTitle()}
*/
public String getName() { public String getName() {
return name; return name;
} }

View File

@@ -119,9 +119,14 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
public abstract Type getType(); public abstract Type getType();
/** /**
* @return Title to display as view * @return Title
*/ */
public abstract String getDisplayTitle(); public abstract String getTitle();
/**
* @return Title to display, typically return alternative title if {@link #getTitle()} is empty
*/
protected abstract String getVisualTitle();
/** /**
* @return Visual icon * @return Visual icon
@@ -210,7 +215,7 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
*/ */
public boolean isContentVisuallyTheSame(PwNode o) { public boolean isContentVisuallyTheSame(PwNode o) {
return getType().equals(o.getType()) return getType().equals(o.getType())
&& getDisplayTitle().equals(o.getDisplayTitle()) && getVisualTitle().equals(o.getVisualTitle())
&& getIcon().equals(o.getIcon()); && getIcon().equals(o.getIcon());
} }

View File

@@ -109,8 +109,8 @@ public enum SortNodeEnum {
new EntryNameComparator(ascending), new EntryNameComparator(ascending),
object1, object1,
object2, object2,
object1.getDisplayTitle() object1.getTitle()
.compareToIgnoreCase(object2.getDisplayTitle())); .compareToIgnoreCase(object2.getTitle()));
} }
} }

View File

@@ -35,8 +35,8 @@ import android.widget.Toast;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwIcon; import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import static com.kunzisoft.keepass.dialogs.GroupEditDialogFragment.EditGroupDialogAction.CREATION; import static com.kunzisoft.keepass.dialogs.GroupEditDialogFragment.EditGroupDialogAction.CREATION;
@@ -76,9 +76,9 @@ public class GroupEditDialogFragment extends DialogFragment
return fragment; return fragment;
} }
public static GroupEditDialogFragment build(PwNode group) { public static GroupEditDialogFragment build(PwGroup group) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(KEY_NAME, group.getDisplayTitle()); bundle.putString(KEY_NAME, group.getName());
bundle.putParcelable(KEY_ICON_ID, group.getIcon()); bundle.putParcelable(KEY_ICON_ID, group.getIcon());
bundle.putInt(KEY_ACTION_ID, UPDATE.ordinal()); bundle.putInt(KEY_ACTION_ID, UPDATE.ordinal());
GroupEditDialogFragment fragment = new GroupEditDialogFragment(); GroupEditDialogFragment fragment = new GroupEditDialogFragment();

View File

@@ -32,6 +32,6 @@
android:layout_marginStart="24dp" android:layout_marginStart="24dp"
android:layout_marginEnd="18dp" android:layout_marginEnd="18dp"
android:layout_toStartOf="@+id/fingerprint_image" android:layout_toStartOf="@+id/fingerprint_image"
style="@style/KeepassDXStyle.TextAppearance.DefaultTextOnPrimary" style="@style/KeepassDXStyle.TextAppearance.Default.TextOnPrimary"
android:gravity="center_vertical|start" /> android:gravity="center_vertical|start" />
</RelativeLayout> </RelativeLayout>

View File

@@ -53,7 +53,7 @@
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
style="@style/KeepassDXStyle.TextAppearance.TitleTextOnPrimary" /> style="@style/KeepassDXStyle.TextAppearance.Title.TextOnPrimary" />
</LinearLayout> </LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>

View File

@@ -52,6 +52,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:lines="1" android:lines="1"
android:singleLine="true"
style="@style/KeepassDXStyle.TextAppearance.Default" /> <!-- style override --> style="@style/KeepassDXStyle.TextAppearance.Default" /> <!-- style override -->
<TextView <TextView
android:id="@+id/entry_subtext" android:id="@+id/entry_subtext"
@@ -59,6 +60,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_marginTop="-4dp" android:layout_marginTop="-4dp"
android:lines="1" android:lines="1"
android:singleLine="true"
style="@style/KeepassDXStyle.TextAppearance.Secondary" /> <!-- style override --> style="@style/KeepassDXStyle.TextAppearance.Secondary" /> <!-- style override -->
</LinearLayout> </LinearLayout>

View File

@@ -64,6 +64,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:lines="1" android:lines="1"
android:singleLine="true"
style="@style/KeepassDXStyle.TextAppearance.Title" /> <!-- style override --> style="@style/KeepassDXStyle.TextAppearance.Title" /> <!-- style override -->
<TextView android:id="@+id/group_subtext" <TextView android:id="@+id/group_subtext"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -71,6 +72,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_marginTop="-4dp" android:layout_marginTop="-4dp"
android:lines="1" android:lines="1"
android:singleLine="true"
style="@style/KeepassDXStyle.TextAppearance.Secondary" /> <!-- style override --> style="@style/KeepassDXStyle.TextAppearance.Secondary" /> <!-- style override -->
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

View File

@@ -69,7 +69,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/search_results" android:text="@string/search_results"
android:visibility="gone" android:visibility="gone"
style="@style/KeepassDXStyle.TextAppearance.DefaultTextOnPrimary" /> style="@style/KeepassDXStyle.TextAppearance.Default.TextOnPrimary" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -90,7 +90,7 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/root" android:text="@string/root"
android:maxLines="1" android:maxLines="1"
style="@style/KeepassDXStyle.TextAppearance.TitleTextOnPrimary" /> style="@style/KeepassDXStyle.TextAppearance.Title.TextOnPrimary" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>

View File

@@ -75,7 +75,7 @@
tools:targetApi="lollipop" > tools:targetApi="lollipop" >
<TextView <TextView
android:id="@+id/filename" android:id="@+id/filename"
style="@style/KeepassDXStyle.TextAppearance.TitleTextOnPrimary" style="@style/KeepassDXStyle.TextAppearance.Title.TextOnPrimary"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"

View File

@@ -42,10 +42,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:lines="1" android:lines="1"
style="@style/KeepassDXStyle.TextAppearance.Inverse" android:singleLine="true"
style="@style/KeepassDXStyle.TextAppearance.Default.TextOnPrimary"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/entry_icon"
android:layout_toEndOf="@+id/entry_icon" />
<TextView
android:id="@+id/entry_subtext"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:lines="1"
android:singleLine="true"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
style="@style/KeepassDXStyle.TextAppearance.Secondary.TextOnPrimary"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/entry_icon" android:layout_toRightOf="@+id/entry_text"
android:layout_toEndOf="@+id/entry_icon" /> android:layout_toEndOf="@+id/entry_text" />
</RelativeLayout> </RelativeLayout>

View File

@@ -21,7 +21,7 @@
</style> </style>
<!-- Menu FAB --> <!-- Menu FAB -->
<style name="KeepassDXStyle.v21.FabMenu" parent="KeepassDXStyle.TextAppearance.DefaultTextOnPrimary"> <style name="KeepassDXStyle.v21.FabMenu" parent="KeepassDXStyle.TextAppearance.Default.TextOnPrimary">
<item name="android:elevation">4dp</item> <item name="android:elevation">4dp</item>
</style> </style>
</resources> </resources>

View File

@@ -201,13 +201,14 @@
<style name="KeepassDXStyle.TextAppearance" parent="android:style/TextAppearance"> <style name="KeepassDXStyle.TextAppearance" parent="android:style/TextAppearance">
<item name="android:textColor">?android:attr/textColor</item> <item name="android:textColor">?android:attr/textColor</item>
</style> </style>
<style name="KeepassDXStyle.TextAppearance.Inverse" parent="android:style/TextAppearance"> <style name="KeepassDXStyle.TextAppearance.Default.TextOnPrimary" parent="android:style/TextAppearance">
<item name="android:textColor">?attr/textColorInverse</item> <item name="android:textColor">?attr/textColorInverse</item>
</style> </style>
<style name="KeepassDXStyle.TextAppearance.DefaultTextOnPrimary" parent="android:style/TextAppearance"> <style name="KeepassDXStyle.TextAppearance.Secondary.TextOnPrimary" parent="KeepassDXStyle.TextAppearance.Default.TextOnPrimary">
<item name="android:textColor">?attr/textColorInverse</item> <item name="android:textSize">14sp</item>
<item name="android:textStyle">italic</item>
</style> </style>
<style name="KeepassDXStyle.TextAppearance.TitleTextOnPrimary" parent="KeepassDXStyle.TextAppearance.DefaultTextOnPrimary"> <style name="KeepassDXStyle.TextAppearance.Title.TextOnPrimary" parent="KeepassDXStyle.TextAppearance.Default.TextOnPrimary">
<item name="android:textSize">18sp</item> <item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
</style> </style>
@@ -266,7 +267,7 @@
</style> </style>
<!-- Menu FAB --> <!-- Menu FAB -->
<style name="KeepassDXStyle.v21.FabMenu" parent="KeepassDXStyle.TextAppearance.DefaultTextOnPrimary" /> <style name="KeepassDXStyle.v21.FabMenu" parent="KeepassDXStyle.TextAppearance.Default.TextOnPrimary" />
<style name="KeepassDXStyle.FabMenu" parent="KeepassDXStyle.v21.FabMenu"> <style name="KeepassDXStyle.FabMenu" parent="KeepassDXStyle.v21.FabMenu">
<item name="android:textSize">15sp</item> <item name="android:textSize">15sp</item>
<item name="android:background">@drawable/button_small_background</item> <item name="android:background">@drawable/button_small_background</item>