Solve bug after sort and prepare recycle bin at the bottom

This commit is contained in:
J-Jamet
2018-02-24 21:38:40 +01:00
parent 0650a6f7db
commit c3954faa3e
6 changed files with 74 additions and 14 deletions

View File

@@ -45,6 +45,7 @@ import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.PwGroupId;
import com.keepassdroid.database.PwNode;
import com.keepassdroid.database.SortNodeEnum;
import com.keepassdroid.database.edit.AddGroup;
import com.keepassdroid.database.edit.DeleteEntry;
import com.keepassdroid.database.edit.DeleteGroup;
@@ -207,7 +208,15 @@ public class GroupActivity extends ListNodesActivity
}
}
protected void setGroupIcon() {
@Override
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
super.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
// Show button if hide after sort
rootView.showButton();
}
protected void setGroupIcon() {
if (mCurrentGroup != null) {
ImageView iv = (ImageView) findViewById(R.id.icon);
App.getDB().drawFactory.assignDrawableTo(iv, getResources(), mCurrentGroup.getIcon());

View File

@@ -147,7 +147,7 @@ public abstract class ListNodesActivity extends LockCloseListActivity
}
@Override
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore) {
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
// Toggle setting
Editor editor = prefs.edit();
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());

View File

@@ -40,6 +40,7 @@ public class SortDialogFragment extends DialogFragment {
private static final String SORT_NODE_ENUM_BUNDLE_KEY = "SORT_NODE_ENUM_BUNDLE_KEY";
private static final String SORT_ASCENDING_BUNDLE_KEY = "SORT_ASCENDING_BUNDLE_KEY";
private static final String SORT_GROUPS_BEFORE_BUNDLE_KEY = "SORT_GROUPS_BEFORE_BUNDLE_KEY";
private static final String SORT_RECYCLE_BIN_BOTTOM_BUNDLE_KEY = "SORT_RECYCLE_BIN_BOTTOM_BUNDLE_KEY";
private SortSelectionListener mListener;
@@ -48,12 +49,33 @@ public class SortDialogFragment extends DialogFragment {
int mCheckedId;
private boolean mGroupsBefore;
private boolean mAscending;
private boolean mRecycleBinBottom;
public static SortDialogFragment getInstance(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore) {
private static Bundle buildBundle(SortNodeEnum sortNodeEnum,
boolean ascending,
boolean groupsBefore) {
Bundle bundle = new Bundle();
bundle.putString(SORT_NODE_ENUM_BUNDLE_KEY, sortNodeEnum.name());
bundle.putBoolean(SORT_ASCENDING_BUNDLE_KEY, ascending);
bundle.putBoolean(SORT_GROUPS_BEFORE_BUNDLE_KEY, groupsBefore);
return bundle;
}
public static SortDialogFragment getInstance(SortNodeEnum sortNodeEnum,
boolean ascending,
boolean groupsBefore) {
Bundle bundle = buildBundle(sortNodeEnum, ascending, groupsBefore);
SortDialogFragment fragment = new SortDialogFragment();
fragment.setArguments(bundle);
return fragment;
}
public static SortDialogFragment getInstance(SortNodeEnum sortNodeEnum,
boolean ascending,
boolean groupsBefore,
boolean recycleBinBottom) {
Bundle bundle = buildBundle(sortNodeEnum, ascending, groupsBefore);
bundle.putBoolean(SORT_RECYCLE_BIN_BOTTOM_BUNDLE_KEY, recycleBinBottom);
SortDialogFragment fragment = new SortDialogFragment();
fragment.setArguments(bundle);
return fragment;
@@ -79,14 +101,20 @@ public class SortDialogFragment extends DialogFragment {
sortNodeEnum = SortNodeEnum.TITLE;
mAscending = true;
mGroupsBefore = true;
boolean recycleBinAllowed = false;
mRecycleBinBottom = true;
if (getArguments() != null
&& getArguments().containsKey(SORT_NODE_ENUM_BUNDLE_KEY)
&& getArguments().containsKey(SORT_ASCENDING_BUNDLE_KEY)
&& getArguments().containsKey(SORT_GROUPS_BEFORE_BUNDLE_KEY)) {
sortNodeEnum = SortNodeEnum.valueOf(getArguments().getString(SORT_NODE_ENUM_BUNDLE_KEY));
mAscending = getArguments().getBoolean(SORT_ASCENDING_BUNDLE_KEY);
mGroupsBefore = getArguments().getBoolean(SORT_GROUPS_BEFORE_BUNDLE_KEY);
if (getArguments() != null) {
if (getArguments().containsKey(SORT_NODE_ENUM_BUNDLE_KEY))
sortNodeEnum = SortNodeEnum.valueOf(getArguments().getString(SORT_NODE_ENUM_BUNDLE_KEY));
if (getArguments().containsKey(SORT_ASCENDING_BUNDLE_KEY))
mAscending = getArguments().getBoolean(SORT_ASCENDING_BUNDLE_KEY);
if (getArguments().containsKey(SORT_GROUPS_BEFORE_BUNDLE_KEY))
mGroupsBefore = getArguments().getBoolean(SORT_GROUPS_BEFORE_BUNDLE_KEY);
if (getArguments().containsKey(SORT_RECYCLE_BIN_BOTTOM_BUNDLE_KEY)) {
recycleBinAllowed = true;
mRecycleBinBottom = getArguments().getBoolean(SORT_RECYCLE_BIN_BOTTOM_BUNDLE_KEY);
}
}
mCheckedId = retrieveViewFromEnum(sortNodeEnum);
@@ -98,7 +126,7 @@ public class SortDialogFragment extends DialogFragment {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
mListener.onSortSelected(sortNodeEnum, mAscending, mGroupsBefore);
mListener.onSortSelected(sortNodeEnum, mAscending, mGroupsBefore, mRecycleBinBottom);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@@ -125,6 +153,20 @@ public class SortDialogFragment extends DialogFragment {
}
});
CompoundButton recycleBinBottomView = (CompoundButton) rootView.findViewById(R.id.sort_selection_recycle_bin_bottom);
if (!recycleBinAllowed) {
recycleBinBottomView.setVisibility(View.GONE);
} else {
// Check if recycle bin at the bottom
recycleBinBottomView.setChecked(mRecycleBinBottom);
recycleBinBottomView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mRecycleBinBottom = isChecked;
}
});
}
RadioGroup sortSelectionRadioGroupView = (RadioGroup) rootView.findViewById(R.id.sort_selection_radio_group);
// Check value by default
sortSelectionRadioGroupView.check(mCheckedId);
@@ -185,6 +227,9 @@ public class SortDialogFragment extends DialogFragment {
}
public interface SortSelectionListener {
void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore);
void onSortSelected(SortNodeEnum sortNodeEnum,
boolean ascending,
boolean groupsBefore,
boolean recycleBinBottom);
}
}

View File

@@ -47,4 +47,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sort_groups_before"/>
<CheckBox android:id="@+id/sort_selection_recycle_bin_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sort_recycle_bin_bottom"/>
</LinearLayout>

View File

@@ -181,8 +181,9 @@
<string name="search_label">Rechercher</string>
<string name="show_password">Afficher le mot de passe</string>
<string name="sort_menu">Trier</string>
<string name="sort_groups_before">Groupes avant</string>
<string name="sort_ascending">Ascendant</string>
<string name="sort_groups_before">Groupes avant</string>
<string name="sort_recycle_bin_bottom">Corbeille à la fin</string>
<string name="sort_db">Tri par défaut (base de données)</string>
<string name="sort_title">Tri par Titre</string>
<string name="sort_name">Tri par nom</string>

View File

@@ -181,8 +181,9 @@
<string name="search_label">Search</string>
<string name="show_password">Show password</string>
<string name="sort_menu">Sort</string>
<string name="sort_groups_before">Groups before</string>
<string name="sort_ascending">Ascending</string>
<string name="sort_groups_before">Groups before</string>
<string name="sort_recycle_bin_bottom">Recycle bin at the bottom</string>
<string name="sort_db">DB sort order</string>
<string name="sort_title">Sort by Title</string>
<string name="sort_name">Sort by Name</string>