Move Archive back into overflow menu

While I much prefer the design introduced in
https://github.com/CatimaLoyalty/Android/pull/1009, it sadly caused a
serious performance regression
(https://github.com/CatimaLoyalty/Android/issues/1026).

This commit restores the old behaviour so that a new release isn't
blocked while this is figured out.
This commit is contained in:
Sylvia van Os
2022-09-18 22:35:32 +02:00
parent 0017e767c9
commit 1a22c27326
5 changed files with 74 additions and 80 deletions

View File

@@ -4,7 +4,6 @@
- Add Monochrome icon for Android 13
- Improve first launch screen
- Move archive info from overflow menu to bottom of card list
- Fidme import fixes
## v2.19.0 - 113

View File

@@ -68,7 +68,6 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
private View mHelpSection;
private View mNoMatchingCardsText;
private View mNoGroupCardsText;
private TextView mOpenArchiveText;
private boolean mArchiveMode;
public static final String BUNDLE_ARCHIVE_MODE = "archiveMode";
@@ -287,22 +286,12 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
mHelpSection = findViewById(R.id.helpSection);
mNoMatchingCardsText = findViewById(R.id.noMatchingCardsText);
mNoGroupCardsText = findViewById(R.id.noGroupCardsText);
mOpenArchiveText = findViewById(R.id.openArchiveLinkText);
mCardList = findViewById(R.id.list);
mNoMatchingCardsText.setOnTouchListener(gestureTouchListener);
mCardList.setOnTouchListener(gestureTouchListener);
mNoGroupCardsText.setOnTouchListener(gestureTouchListener);
// Open archive on archive text click
mOpenArchiveText.setOnClickListener(view -> {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
Bundle bundle = new Bundle();
bundle.putBoolean("archiveMode", true);
i.putExtras(bundle);
startActivity(i);
});
mAdapter = new LoyaltyCardCursorAdapter(this, null, this);
mCardList.setAdapter(mAdapter);
registerForContextMenu(mCardList);
@@ -475,11 +464,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
mHelpSection.setVisibility(View.GONE);
mNoGroupCardsText.setVisibility(View.GONE);
int archiveCount =
mArchiveMode ? 0 :
group != null ? DBHelper.getArchivedCardsCount(mDatabase, group._id) : DBHelper.getArchivedCardsCount(mDatabase);
if (mAdapter.getItemCount() + archiveCount > 0) {
if (mAdapter.getItemCount() > 0) {
mCardList.setVisibility(View.VISIBLE);
mNoMatchingCardsText.setVisibility(View.GONE);
} else {
@@ -494,10 +479,13 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
mNoGroupCardsText.setVisibility(View.VISIBLE);
}
}
mOpenArchiveText.setText(getResources().getQuantityString(R.plurals.viewArchivedCardsWithCount, archiveCount, archiveCount));
mOpenArchiveText.setVisibility(archiveCount > 0 ? View.VISIBLE : View.GONE);
} else {
if (mArchiveMode) {
// If an user deletes the last card in archive mode, we should close the activity
// This will move us back to the main view
finish();
}
mCardList.setVisibility(View.GONE);
mHelpSection.setVisibility(View.VISIBLE);
@@ -585,6 +573,14 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
});
}
if(!mArchiveMode) {
if (DBHelper.getArchivedCardsCount(mDatabase) == 0) {
inputMenu.findItem(R.id.action_archived).setVisible(false);
} else {
inputMenu.findItem(R.id.action_archived).setVisible(true);
}
}
return super.onCreateOptionsMenu(inputMenu);
}
@@ -651,6 +647,15 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
return true;
}
if (id == R.id.action_archived) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
Bundle bundle = new Bundle();
bundle.putBoolean("archiveMode", true);
i.putExtras(bundle);
startActivity(i);
return true;
}
if (id == R.id.action_import_export) {
Intent i = new Intent(getApplicationContext(), ImportExportActivity.class);
startActivity(i);

View File

@@ -1,84 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="protect.card_locker.MainActivity"
tools:showIn="@layout/main_activity">
<LinearLayout
android:id="@+id/helpSection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="@+id/helpSection"
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="match_parent"
android:layout_height="184dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher_foreground" />
<TextView
style="@style/TextAppearance.Material3.HeadlineLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/welcome" />
<TextView
style="@style/AppTheme.TextView.NoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/noGiftCards"/>
</LinearLayout>
android:layout_height="184dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher_foreground" />
<TextView
style="@style/AppTheme.TextView.NoData"
android:id="@+id/noMatchingCardsText"
style="@style/TextAppearance.Material3.HeadlineLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/noMatchingGiftCards"
android:visibility="gone"/>
android:text="@string/welcome" />
<TextView
style="@style/AppTheme.TextView.NoData"
android:id="@+id/noGroupCardsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/noGroupCards"
android:visibility="gone"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="@integer/main_view_card_columns"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:visibility="gone"/>
<TextView
style="@style/AppTheme.TextView.NoData"
android:id="@+id/openArchiveLinkText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:visibility="gone"/>
<View
android:id="@+id/bottomPadding"
android:layout_width="match_parent"
android:layout_height="80dp" />
android:text="@string/noGiftCards"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<TextView
style="@style/AppTheme.TextView.NoData"
android:id="@+id/noMatchingCardsText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/noMatchingGiftCards"
android:visibility="gone"/>
<TextView
style="@style/AppTheme.TextView.NoData"
android:id="@+id/noGroupCardsText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/noGroupCards"
android:visibility="gone"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="@integer/main_view_card_columns"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="80dp"
android:clipToPadding="false"
android:scrollbars="vertical"
android:visibility="gone"/>
</RelativeLayout>

View File

@@ -26,6 +26,10 @@
android:icon="@drawable/ic_folder_white"
android:title="@string/groups"
app:showAsAction="never"/>
<item
android:id="@+id/action_archived"
android:title="@string/archiveList"
app:showAsAction="never"/>
<item
android:id="@+id/action_import_export"
android:icon="@drawable/ic_import_export_white_24dp"

View File

@@ -60,11 +60,12 @@ public class MainActivityTest {
assertNotNull(menu);
// The settings, import/export, groups, search and add button should be present
assertEquals(menu.size(), 7);
assertEquals(menu.size(), 8);
assertEquals("Search", menu.findItem(R.id.action_search).getTitle().toString());
assertEquals("Sort", menu.findItem(R.id.action_sort).getTitle().toString());
assertEquals("Hide details", menu.findItem(R.id.action_unfold).getTitle().toString());
assertEquals("Groups", menu.findItem(R.id.action_manage_groups).getTitle().toString());
assertEquals("Archive", menu.findItem(R.id.action_archived).getTitle().toString());
assertEquals("Import/Export", menu.findItem(R.id.action_import_export).getTitle().toString());
assertEquals("About", menu.findItem(R.id.action_about).getTitle().toString());
assertEquals("Settings", menu.findItem(R.id.action_settings).getTitle().toString());