From 7fca6db35e1d2a5ca242a1f8388be19c941a4454 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Wed, 8 Dec 2021 00:31:53 +0100 Subject: [PATCH 01/40] Add code 93 --- app/src/main/java/protect/card_locker/CatimaBarcode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/protect/card_locker/CatimaBarcode.java b/app/src/main/java/protect/card_locker/CatimaBarcode.java index c402f7991d..2b1a5c488a 100644 --- a/app/src/main/java/protect/card_locker/CatimaBarcode.java +++ b/app/src/main/java/protect/card_locker/CatimaBarcode.java @@ -10,6 +10,7 @@ public class CatimaBarcode { public static final List barcodeFormats = Collections.unmodifiableList(Arrays.asList( BarcodeFormat.AZTEC, BarcodeFormat.CODE_39, + BarcodeFormat.CODE_93, BarcodeFormat.CODE_128, BarcodeFormat.CODABAR, BarcodeFormat.DATA_MATRIX, @@ -25,6 +26,7 @@ public class CatimaBarcode { public static final List barcodePrettyNames = Collections.unmodifiableList(Arrays.asList( "Aztec", "Code 39", + "Code 93", "Code 128", "Codabar", "Data Matrix", From 8c86fa838c06a419f705e9b3cb3504ded82f357a Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Thu, 9 Dec 2021 19:20:23 +0100 Subject: [PATCH 02/40] Fix long press to add card to group --- app/src/main/java/protect/card_locker/ManageGroupActivity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/protect/card_locker/ManageGroupActivity.java b/app/src/main/java/protect/card_locker/ManageGroupActivity.java index 19482bce01..45fe93fc3a 100644 --- a/app/src/main/java/protect/card_locker/ManageGroupActivity.java +++ b/app/src/main/java/protect/card_locker/ManageGroupActivity.java @@ -205,12 +205,11 @@ private boolean hasChanged() { @Override public void onRowLongClicked(int inputPosition) { - // do nothing for now + mAdapter.toggleSelection(inputPosition); } @Override public void onRowClicked(int inputPosition) { mAdapter.toggleSelection(inputPosition); - } } From 7cf8d89537d17aafebb28031dc75e0663eba84f3 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Thu, 9 Dec 2021 21:35:37 +0100 Subject: [PATCH 03/40] First step to implement group widget --- app/src/main/AndroidManifest.xml | 11 +++ .../card_locker/GroupShortcutConfigure.java | 89 +++++++++++++++++++ .../protect/card_locker/MainActivity.java | 19 +++- .../protect/card_locker/ShortcutHelper.java | 22 +++++ .../main/java/protect/card_locker/Utils.java | 4 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/protect/card_locker/GroupShortcutConfigure.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 848cc08bc5..93d615e18d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -114,6 +114,17 @@ + + + + + + + mBarcodeScannerLauncher; private ActionMode.Callback mCurrentActionModeCallback = new ActionMode.Callback() { @@ -171,9 +172,17 @@ public void onDestroyActionMode(ActionMode inputMode) { } }; + private void extractIntentFields(Intent intent) + { + final Bundle b = intent.getExtras(); + groupId = b != null ? b.getString("id") : ""; + Log.d(TAG, "View activity: id=" + groupId); + } + @Override protected void onCreate(Bundle inputSavedInstanceState) { super.onCreate(inputSavedInstanceState); + extractIntentFields(getIntent()); SplashScreen.installSplashScreen(this); setTitle(R.string.app_name); setContentView(R.layout.main_activity); @@ -703,4 +712,12 @@ public void onRowClicked(int inputPosition) { startActivity(i); } } + + @Override + public void onNewIntent(Intent intent) { + super.onNewIntent(intent); + + Log.i(TAG, "Received new intent"); + extractIntentFields(intent); + } } diff --git a/app/src/main/java/protect/card_locker/ShortcutHelper.java b/app/src/main/java/protect/card_locker/ShortcutHelper.java index 426983cf1f..3289eb02a2 100644 --- a/app/src/main/java/protect/card_locker/ShortcutHelper.java +++ b/app/src/main/java/protect/card_locker/ShortcutHelper.java @@ -155,4 +155,26 @@ static ShortcutInfoCompat.Builder createShortcutBuilder(Context context, Loyalty .setIntent(intent) .setIcon(icon); } + static ShortcutInfoCompat.Builder createGroupShortcutBuilder(Context context, Group group) { + Intent intent = new Intent(context, MainActivity.class); + intent.setAction(Intent.ACTION_MAIN); + // Prevent instances of the view activity from piling up; if one exists let this + // one replace it. + intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP); + final Bundle bundle = new Bundle(); + // Done like with the cards but with group._id (a string) + bundle.putString("id", group._id); + bundle.putBoolean("view", true); + intent.putExtras(bundle); + + Bitmap iconBitmap = Utils.generateIcon(context, group, true).getLetterTile(); + + IconCompat icon = IconCompat.createWithAdaptiveBitmap(iconBitmap); + + return new ShortcutInfoCompat.Builder(context, group._id) + .setShortLabel(group._id) + .setLongLabel(group._id) + .setIntent(intent) + .setIcon(icon); + } } diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index 0094bddd07..aa0885aca5 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -67,6 +67,10 @@ public class Utils { static public LetterBitmap generateIcon(Context context, LoyaltyCard loyaltyCard, boolean forShortcut) { return generateIcon(context, loyaltyCard.store, loyaltyCard.headerColor, forShortcut); } + static public LetterBitmap generateIcon(Context context, Group group, boolean forShortcut) { + // Temporary color for group + return generateIcon(context, group._id, 0, forShortcut); + } static public LetterBitmap generateIcon(Context context, String store, Integer backgroundColor) { return generateIcon(context, store, backgroundColor, false); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 472769903d..f7c5a884f3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -258,4 +258,5 @@ Show details Hide details on Weblate + Group Shortcut From 2504a24f5a3f2e67a9a5181c3d4f0c3f9b9c83c8 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Thu, 9 Dec 2021 22:09:21 +0100 Subject: [PATCH 04/40] Try to fix (try with a standard list view) --- .../main/java/protect/card_locker/GroupShortcutConfigure.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java index 51825b51cd..9efdd1e463 100644 --- a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java +++ b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java @@ -48,7 +48,7 @@ public void onCreate(Bundle bundle) { } - final RecyclerView groupList = findViewById(R.id.groups); + final RecyclerView groupList = findViewById(R.id.list); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); groupList.setLayoutManager(mLayoutManager); From 4a5f517e04d0f1f0140e4bed9efc7a0a5a3b0596 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Thu, 9 Dec 2021 22:38:41 +0100 Subject: [PATCH 05/40] Try to fix with group cursors --- .../java/protect/card_locker/GroupShortcutConfigure.java | 9 +++++---- app/src/main/res/layout/group_main.xml | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java index 9efdd1e463..c7e99550a6 100644 --- a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java +++ b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java @@ -56,14 +56,15 @@ public void onCreate(Bundle bundle) { groupList.setVisibility(View.VISIBLE); - Cursor groupCursor = db.getLoyaltyCardCursor(); + Cursor groupCursor = db.getGroupCursor(); - final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, groupCursor, this); - groupList.setAdapter(adapter); + // Test to comment these lines out + // final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, groupCursor, this); + // groupList.setAdapter(adapter); } private void onClickAction(int position) { - Cursor selected = mDb.getLoyaltyCardCursor(); + Cursor selected = mDb.getGroupCursor(); selected.moveToPosition(position); Group group = Group.toGroup(selected); diff --git a/app/src/main/res/layout/group_main.xml b/app/src/main/res/layout/group_main.xml index 49f51c27ce..2a2d19c046 100644 --- a/app/src/main/res/layout/group_main.xml +++ b/app/src/main/res/layout/group_main.xml @@ -23,4 +23,5 @@ android:layout_height="match_parent" android:scrollbars="vertical" android:visibility="gone" /> + From 1bfff053164e8469538f74d06fee63281ea86198 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Thu, 9 Dec 2021 22:46:47 +0100 Subject: [PATCH 06/40] Blank list, fix with GroupCursorAdapter --- .../java/protect/card_locker/GroupShortcutConfigure.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java index c7e99550a6..b8688ca440 100644 --- a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java +++ b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java @@ -58,9 +58,8 @@ public void onCreate(Bundle bundle) { Cursor groupCursor = db.getGroupCursor(); - // Test to comment these lines out - // final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, groupCursor, this); - // groupList.setAdapter(adapter); + final GroupCursorAdapter adapter = new GroupCursorAdapter(this, groupCursor, (GroupCursorAdapter.GroupAdapterListener) this); + groupList.setAdapter(adapter); } private void onClickAction(int position) { From a8f9bafc82521a9aba532e15eb9f7ba93a6d421f Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Thu, 9 Dec 2021 22:58:33 +0100 Subject: [PATCH 07/40] implement GroupCursorAdapter --- .../card_locker/GroupShortcutConfigure.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java index b8688ca440..77735dc91e 100644 --- a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java +++ b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java @@ -19,7 +19,7 @@ /** * The configuration screen for creating a shortcut. */ -public class GroupShortcutConfigure extends AppCompatActivity implements LoyaltyCardCursorAdapter.CardAdapterListener { +public class GroupShortcutConfigure extends AppCompatActivity implements GroupCursorAdapter.GroupAdapterListener { static final String TAG = "Catima"; final DBHelper mDb = new DBHelper(this); @@ -58,7 +58,7 @@ public void onCreate(Bundle bundle) { Cursor groupCursor = db.getGroupCursor(); - final GroupCursorAdapter adapter = new GroupCursorAdapter(this, groupCursor, (GroupCursorAdapter.GroupAdapterListener) this); + final GroupCursorAdapter adapter = new GroupCursorAdapter(this, groupCursor,this); groupList.setAdapter(adapter); } @@ -76,14 +76,23 @@ private void onClickAction(int position) { finish(); } + @Override + public void onMoveDownButtonClicked(View view) { + // do nothing + } + + @Override + public void onMoveUpButtonClicked(View view) { + // do nothing + } @Override - public void onRowClicked(int inputPosition) { - onClickAction(inputPosition); + public void onEditButtonClicked(View view) { + // do nothing } @Override - public void onRowLongClicked(int inputPosition) { + public void onDeleteButtonClicked(View view) { // do nothing } } From a6aa6f67a41abdf59bc7516c6435058f128a7adf Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 11:29:23 +0100 Subject: [PATCH 08/40] implement click action --- .../card_locker/GroupShortcutConfigure.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java index 77735dc91e..dc01555494 100644 --- a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java +++ b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -62,10 +63,21 @@ public void onCreate(Bundle bundle) { groupList.setAdapter(adapter); } - private void onClickAction(int position) { - Cursor selected = mDb.getGroupCursor(); - selected.moveToPosition(position); - Group group = Group.toGroup(selected); + private String getGroupName(View view) { + TextView groupNameTextView = view.findViewById(R.id.name); + return (String) groupNameTextView.getText(); + } + + private void onClickAction(View view) { + String groupId = getGroupName(view); + if (groupId == null) { + throw (new IllegalArgumentException("The widget expects a group")); + } + Log.d("groupId", "groupId: " + groupId); + Group group = mDb.getGroup(groupId); + if (group == null) { + throw (new IllegalArgumentException("cannot load group " + groupId + " from database")); + } Log.d(TAG, "Creating shortcut for group " + group._id + "," + group._id); @@ -93,6 +105,6 @@ public void onEditButtonClicked(View view) { @Override public void onDeleteButtonClicked(View view) { - // do nothing + onClickAction(view); } } From 10da2a75ac5e7ce36ea24666da31923e572aa1b2 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 13:22:08 +0100 Subject: [PATCH 09/40] try fixes with renaming groupListListItemViewHolder --- app/src/main/java/protect/card_locker/MainActivity.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 7a477a5a96..6c64057d4d 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -54,8 +54,6 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard private View mNoMatchingCardsText; private View mNoGroupCardsText; - String groupId; - private ActivityResultLauncher mBarcodeScannerLauncher; private ActionMode.Callback mCurrentActionModeCallback = new ActionMode.Callback() { @@ -175,8 +173,8 @@ public void onDestroyActionMode(ActionMode inputMode) { private void extractIntentFields(Intent intent) { final Bundle b = intent.getExtras(); - groupId = b != null ? b.getString("id") : ""; - Log.d(TAG, "View activity: id=" + groupId); + mGroup = b != null ? b.getString("id") : ""; + Log.d(TAG, "View activity: id=" + mGroup); } @Override From 5a074dbfceeedfe14bf4c28f8966dcb19b9c07e8 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 13:49:36 +0100 Subject: [PATCH 10/40] try fixes with onResume group view --- app/src/main/java/protect/card_locker/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 6c64057d4d..54b4fc4fed 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -290,6 +290,8 @@ public void onClick(DialogInterface dialog, int whichButton) { protected void onResume() { super.onResume(); + extractIntentFields(getIntent()); + if (mCurrentActionMode != null) { mAdapter.clearSelections(); mCurrentActionMode.finish(); From 8078f0c825aa61371e2a84276d98e120cb618d0a Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 14:17:23 +0100 Subject: [PATCH 11/40] try fixes with updateLoyaltyCardList() --- app/src/main/java/protect/card_locker/MainActivity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 54b4fc4fed..ca3f894f2e 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -175,6 +175,7 @@ private void extractIntentFields(Intent intent) final Bundle b = intent.getExtras(); mGroup = b != null ? b.getString("id") : ""; Log.d(TAG, "View activity: id=" + mGroup); + updateLoyaltyCardList(); } @Override @@ -290,8 +291,6 @@ public void onClick(DialogInterface dialog, int whichButton) { protected void onResume() { super.onResume(); - extractIntentFields(getIntent()); - if (mCurrentActionMode != null) { mAdapter.clearSelections(); mCurrentActionMode.finish(); From d57f26e0edb51a1574b86161e0692cceaba70d89 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 15:07:18 +0100 Subject: [PATCH 12/40] try fixes with groupTabs selectTab --- app/src/main/java/protect/card_locker/MainActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index ca3f894f2e..2601629606 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -173,9 +173,11 @@ public void onDestroyActionMode(ActionMode inputMode) { private void extractIntentFields(Intent intent) { final Bundle b = intent.getExtras(); - mGroup = b != null ? b.getString("id") : ""; + String groupName = b != null ? b.getString("id") : ""; Log.d(TAG, "View activity: id=" + mGroup); - updateLoyaltyCardList(); + TabLayout groupTabs = findViewById(R.id.groups); + Group group = mDB.getGroup(groupName); + groupTabs.selectTab(groupTabs.getTabAt(group.order)); } @Override From d3c2412aa06cc24099ad712575368b2ed7cf2cfb Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 15:42:50 +0100 Subject: [PATCH 13/40] fix, just set selectedTab --- app/src/main/java/protect/card_locker/MainActivity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 2601629606..f89e13745e 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -174,10 +174,9 @@ private void extractIntentFields(Intent intent) { final Bundle b = intent.getExtras(); String groupName = b != null ? b.getString("id") : ""; - Log.d(TAG, "View activity: id=" + mGroup); - TabLayout groupTabs = findViewById(R.id.groups); + Log.d(TAG, "View activity: id=" + groupName); Group group = mDB.getGroup(groupName); - groupTabs.selectTab(groupTabs.getTabAt(group.order)); + selectedTab = group.order; } @Override From 30f13814aad8ab2f812d4a42fc6668586131fc85 Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 17:18:16 +0100 Subject: [PATCH 14/40] Revert some changes to see if the app starts again correctly :/ --- app/src/main/java/protect/card_locker/MainActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index f89e13745e..3dcd538f2e 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -175,8 +175,8 @@ private void extractIntentFields(Intent intent) final Bundle b = intent.getExtras(); String groupName = b != null ? b.getString("id") : ""; Log.d(TAG, "View activity: id=" + groupName); - Group group = mDB.getGroup(groupName); - selectedTab = group.order; + // Group group = mDB.getGroup(groupName); + // selectedTab = group.order; } @Override From 36cdbd13b214a1ac2a1d93eeee5c611ea399f16a Mon Sep 17 00:00:00 2001 From: Altonss <_> Date: Fri, 10 Dec 2021 17:31:46 +0100 Subject: [PATCH 15/40] Select group for widget --- .../card_locker/GroupSelectCursorAdapter.java | 73 +++++++++++++++++++ .../card_locker/GroupShortcutConfigure.java | 22 +----- .../main/res/layout/group_select_layout.xml | 50 +++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/protect/card_locker/GroupSelectCursorAdapter.java create mode 100644 app/src/main/res/layout/group_select_layout.xml diff --git a/app/src/main/java/protect/card_locker/GroupSelectCursorAdapter.java b/app/src/main/java/protect/card_locker/GroupSelectCursorAdapter.java new file mode 100644 index 0000000000..9e21638eae --- /dev/null +++ b/app/src/main/java/protect/card_locker/GroupSelectCursorAdapter.java @@ -0,0 +1,73 @@ +package protect.card_locker; + +import android.content.Context; +import android.database.Cursor; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.RecyclerView; + +import protect.card_locker.preferences.Settings; + +public class GroupSelectCursorAdapter extends BaseCursorAdapter { + Settings mSettings; + private final Context mContext; + private final GroupAdapterListener mListener; + DBHelper mDb; + + public GroupSelectCursorAdapter(Context inputContext, Cursor inputCursor, GroupAdapterListener inputListener) { + super(inputCursor, DBHelper.LoyaltyCardDbGroups.ORDER); + setHasStableIds(true); + mSettings = new Settings(inputContext); + mContext = inputContext.getApplicationContext(); + mListener = inputListener; + mDb = new DBHelper(inputContext); + + swapCursor(inputCursor); + } + + @NonNull + @Override + public GroupSelectCursorAdapter.GroupListItemViewHolder onCreateViewHolder(ViewGroup inputParent, int inputViewType) { + View itemView = LayoutInflater.from(inputParent.getContext()).inflate(R.layout.group_select_layout, inputParent, false); + return new GroupListItemViewHolder(itemView); + } + + public void onBindViewHolder(GroupListItemViewHolder inputHolder, Cursor inputCursor) { + Group group = Group.toGroup(inputCursor); + + inputHolder.mName.setText(group._id); + + int groupCardCount = mDb.getGroupCardCount(group._id); + inputHolder.mCardCount.setText(mContext.getResources().getQuantityString(R.plurals.groupCardCount, groupCardCount, groupCardCount)); + + inputHolder.mName.setTextSize(mSettings.getFontSizeMax(mSettings.getMediumFont())); + inputHolder.mCardCount.setTextSize(mSettings.getFontSizeMax(mSettings.getSmallFont())); + + applyClickEvents(inputHolder); + } + + private void applyClickEvents(GroupListItemViewHolder inputHolder) { + inputHolder.mSelect.setOnClickListener(view -> mListener.onSelectButtonClicked(inputHolder.itemView)); + } + + public interface GroupAdapterListener { + void onSelectButtonClicked(View view); + } + + public static class GroupListItemViewHolder extends RecyclerView.ViewHolder { + public TextView mName, mCardCount; + public AppCompatImageButton mSelect; + + public GroupListItemViewHolder(View inputView) { + super(inputView); + mName = inputView.findViewById(R.id.name); + mCardCount = inputView.findViewById(R.id.cardCount); + mSelect = inputView.findViewById(R.id.select); + } + } +} diff --git a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java index dc01555494..4afacb4831 100644 --- a/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java +++ b/app/src/main/java/protect/card_locker/GroupShortcutConfigure.java @@ -20,7 +20,7 @@ /** * The configuration screen for creating a shortcut. */ -public class GroupShortcutConfigure extends AppCompatActivity implements GroupCursorAdapter.GroupAdapterListener { +public class GroupShortcutConfigure extends AppCompatActivity implements GroupSelectCursorAdapter.GroupAdapterListener { static final String TAG = "Catima"; final DBHelper mDb = new DBHelper(this); @@ -59,7 +59,7 @@ public void onCreate(Bundle bundle) { Cursor groupCursor = db.getGroupCursor(); - final GroupCursorAdapter adapter = new GroupCursorAdapter(this, groupCursor,this); + final GroupSelectCursorAdapter adapter = new GroupSelectCursorAdapter(this, groupCursor,this); groupList.setAdapter(adapter); } @@ -89,22 +89,8 @@ private void onClickAction(View view) { } @Override - public void onMoveDownButtonClicked(View view) { - // do nothing - } - - @Override - public void onMoveUpButtonClicked(View view) { - // do nothing - } - - @Override - public void onEditButtonClicked(View view) { - // do nothing - } - - @Override - public void onDeleteButtonClicked(View view) { + public void onSelectButtonClicked(View view) { onClickAction(view); } + } diff --git a/app/src/main/res/layout/group_select_layout.xml b/app/src/main/res/layout/group_select_layout.xml new file mode 100644 index 0000000000..414c562f2c --- /dev/null +++ b/app/src/main/res/layout/group_select_layout.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + +