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
titleView.setText(mEntry.getDisplayTitle());
titleView.setText(mEntry.getVisualTitle());
// Assign basic fields
entryContentsView.assignUserName(mEntry.getUsername());

View File

@@ -542,7 +542,7 @@ public class GroupActivity extends LockingActivity
switch (node.getType()) {
case GROUP:
oldGroupToUpdate = (PwGroup) node;
GroupEditDialogFragment.build(node)
GroupEditDialogFragment.build(oldGroupToUpdate)
.show(getSupportFragmentManager(),
GroupEditDialogFragment.TAG_CREATE_GROUP);
break;
@@ -705,6 +705,8 @@ public class GroupActivity extends LockingActivity
super.onResume();
// Refresh the elements
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());
}
// Assign text
holder.text.setText(subNode.getDisplayTitle());
holder.text.setText(subNode.getTitle());
// Assign click
holder.container.setOnClickListener(
new OnNodeClickListener(subNode));
@@ -252,12 +252,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
// Add username
holder.subText.setText("");
holder.subText.setVisibility(View.GONE);
if (showUsernames && subNode.getType().equals(PwNode.Type.ENTRY)) {
if (subNode.getType().equals(PwNode.Type.ENTRY)) {
PwEntry entry = (PwEntry) subNode;
entry.startToManageFieldReferences(database.getPwDatabase());
holder.text.setText(entry.getVisualTitle());
String username = entry.getUsername();
if (!username.isEmpty()) {
if (showUsernames && !username.isEmpty()) {
holder.subText.setVisibility(View.VISIBLE);
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.cursor.EntryCursor;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import java.util.UUID;
@@ -44,6 +45,7 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
private LayoutInflater cursorInflater;
private Database database;
private boolean displayUsername;
private int iconColor;
public SearchEntryCursorAdapter(Context context, Database database) {
@@ -57,6 +59,12 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
TypedArray taTextColor = context.getTheme().obtainStyledAttributes(attrTextColor);
this.iconColor = taTextColor.getColor(0, Color.WHITE);
taTextColor.recycle();
reInit(context);
}
public void reInit(Context context) {
this.displayUsername = PreferencesUtil.showUsernamesListEntries(context);
}
@Override
@@ -66,6 +74,7 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
ViewHolder viewHolder = new ViewHolder();
viewHolder.imageViewIcon = view.findViewById(R.id.entry_icon);
viewHolder.textViewTitle = view.findViewById(R.id.entry_text);
viewHolder.textViewSubTitle = view.findViewById(R.id.entry_subtext);
view.setTag(viewHolder);
return view;
@@ -75,6 +84,8 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
public void bindView(View view, Context context, Cursor 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();
PwIcon icon = iconFactory.getIcon(
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();
}
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();
@@ -95,12 +108,17 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
database.getDrawFactory().assignDatabaseIconTo(context, viewHolder.imageViewIcon, icon);
}
// 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 {
ImageView imageViewIcon;
TextView textViewTitle;
TextView textViewSubTitle;
}
@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);
}
@Override
public String getDisplayTitle() {
if ( isTan() ) {
return PMS_TAN_ENTRY + " " + getUsername();
} else {
if (getTitle().isEmpty())
if (getUrl().isEmpty())
return getUUID().toString();
else
return getUrl();
else
return getTitle();
}
/**
* {@inheritDoc}
* Get the display title from an entry, <br />
* {@link #startToManageFieldReferences(PwDatabase)} and {@link #stopToManageFieldReferences()} must be called
* before and after {@link #getVisualTitle()}
*/
public String getVisualTitle() {
// only used to compare, don't car if it's a reference
return getVisualTitle(isTan(), getTitle(), getUsername(), getUrl(), getUUID());
}
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
/**

View File

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

View File

@@ -119,9 +119,14 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
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
@@ -210,7 +215,7 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
*/
public boolean isContentVisuallyTheSame(PwNode o) {
return getType().equals(o.getType())
&& getDisplayTitle().equals(o.getDisplayTitle())
&& getVisualTitle().equals(o.getVisualTitle())
&& getIcon().equals(o.getIcon());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -42,10 +42,24 @@
android:layout_height="wrap_content"
android:layout_width="wrap_content"
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_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/entry_icon"
android:layout_toEndOf="@+id/entry_icon" />
android:layout_toRightOf="@+id/entry_text"
android:layout_toEndOf="@+id/entry_text" />
</RelativeLayout>

View File

@@ -21,7 +21,7 @@
</style>
<!-- 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>
</style>
</resources>

View File

@@ -201,13 +201,14 @@
<style name="KeepassDXStyle.TextAppearance" parent="android:style/TextAppearance">
<item name="android:textColor">?android:attr/textColor</item>
</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>
</style>
<style name="KeepassDXStyle.TextAppearance.DefaultTextOnPrimary" parent="android:style/TextAppearance">
<item name="android:textColor">?attr/textColorInverse</item>
<style name="KeepassDXStyle.TextAppearance.Secondary.TextOnPrimary" parent="KeepassDXStyle.TextAppearance.Default.TextOnPrimary">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">italic</item>
</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:textStyle">bold</item>
</style>
@@ -266,7 +267,7 @@
</style>
<!-- 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">
<item name="android:textSize">15sp</item>
<item name="android:background">@drawable/button_small_background</item>