From 46053cc1447b8051bfe86f95ce494f4912b5adab Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 08:18:58 +0100 Subject: [PATCH 1/7] instead of throwing an exception and crushing the app the fab button does nothing until a project is set --- .../sdk/ui/payment/PaymentCredentialsListView.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java index 0cc0d172a1..774e5626dc 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java +++ b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java @@ -100,14 +100,11 @@ public void click() { if (p == null) { p = Snabble.getInstance().getCheckedInProject().getValue(); } - - if (p == null) { - throw new IllegalStateException("Cannot get current project. Did you forget to set the projectId to the PaymentCredentialsListFragment or PaymentCredentialsListView?"); + if (p != null) { + bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, p.getId()); + dialogFragment.setArguments(bundle); + dialogFragment.show(((FragmentActivity) activity).getSupportFragmentManager(), null); } - - bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, p.getId()); - dialogFragment.setArguments(bundle); - dialogFragment.show(((FragmentActivity) activity).getSupportFragmentManager(), null); } else { throw new RuntimeException("Host activity must be a Fragment Activity"); } From d9680487a84981224e3ad075532c29625f3b535c Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 08:24:17 +0100 Subject: [PATCH 2/7] add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12a7bbdd88..15fb0f9a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Changed ### Removed ### Fixed +* ui: fix crash when adding a payment mehtod (APPS-2155) ## [0.80.5] ### Added From 8a8360c36847ac5f726e7a9344d46fc1f9878888 Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 16:18:55 +0100 Subject: [PATCH 3/7] add circular indicator to show loading state in case a project hasn't been set --- .../layout/snabble_view_payment_credentials_list.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml b/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml index 0d3353f8d0..2a58a3e80e 100644 --- a/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml +++ b/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml @@ -5,6 +5,16 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> + + + From b8f2f6e9b4bccd1e248fb7954470d58bc1bc2175 Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 16:26:29 +0100 Subject: [PATCH 4/7] instead of doin nothing if no project is set the entire view now shows a loading indicator --- .../payment/PaymentCredentialsListView.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java index 774e5626dc..33c4bab8db 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java +++ b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java @@ -23,6 +23,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.progressindicator.CircularProgressIndicator; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -50,6 +51,8 @@ public class PaymentCredentialsListView extends FrameLayout implements PaymentCr private List types; private Project project; private View emptyState; + private FloatingActionButton fab; + private CircularProgressIndicator progressIndicator; public PaymentCredentialsListView(Context context) { super(context); @@ -69,17 +72,19 @@ public PaymentCredentialsListView(Context context, AttributeSet attrs, int defSt private void inflateView() { inflate(getContext(), R.layout.snabble_view_payment_credentials_list, this); if (isInEditMode()) return; + emptyState = findViewById(R.id.empty_state); + recyclerView = findViewById(R.id.recycler_view); + fab = findViewById(R.id.fab); + progressIndicator = findViewById(R.id.circular_indicator); + paymentCredentialsStore = Snabble.getInstance().getPaymentCredentialsStore(); - recyclerView = findViewById(R.id.recycler_view); recyclerView.setAdapter(new PaymentCredentialsListView.Adapter()); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(layoutManager); recyclerView.setItemAnimator(null); - FloatingActionButton fab = findViewById(R.id.fab); - final Project currentProject = Snabble.getInstance().getCheckedInProject().getLatestValue(); final int primaryColor = RemoteThemingHelper.primaryColorForProject(getContext(), currentProject); final int onPrimaryColor = RemoteThemingHelper.onPrimaryColorForProject(getContext(), currentProject); @@ -121,12 +126,12 @@ public void click() { } } }); - - emptyState = findViewById(R.id.empty_state); } public void setProject(Project project) { this.project = project; + progressIndicator.setVisibility(View.GONE); + onChanged(); } public void show(List types, Project project) { @@ -134,6 +139,7 @@ public void show(List types, Project project) { this.project = project; entries.clear(); + progressIndicator.setVisibility(View.GONE); onChanged(); } @@ -181,24 +187,27 @@ public void onChanged() { List paymentCredentials = paymentCredentialsStore.getAll(); for (PaymentCredentials pm : paymentCredentials) { - boolean sameProjectOrNull = true; + boolean sameProject = false; if (project != null) { - sameProjectOrNull = project.getId().equals(pm.getProjectId()); + sameProject = project.getId().equals(pm.getProjectId()); } if (pm.getProjectId() == null && (pm.getType() == Type.SEPA || pm.getType() == Type.PAYONE_SEPA)) { - sameProjectOrNull = true; + sameProject = true; } - boolean sameTypeOrNull = true; + boolean sameType = false; if (types != null) { if (project != null) { - sameTypeOrNull = project.getAvailablePaymentMethods().contains(pm.getPaymentMethod()); + sameType = project.getAvailablePaymentMethods().contains(pm.getPaymentMethod()); } else { - sameTypeOrNull = types.contains(pm.getType()); + sameType = types.contains(pm.getType()); } } - if (pm.isAvailableInCurrentApp() && sameTypeOrNull && sameProjectOrNull) { + + boolean isRetailer = Snabble.getInstance().getProjects().size() == 1; + + if ((pm.isAvailableInCurrentApp() && sameType && sameProject) || isRetailer) { switch (pm.getType()) { case SEPA: case PAYONE_SEPA: @@ -228,11 +237,15 @@ public void onChanged() { } if (entries.size() == 0) { - emptyState.setVisibility(View.VISIBLE); + if (project != null) { + emptyState.setVisibility(View.VISIBLE); + fab.setVisibility(View.VISIBLE); + } recyclerView.setVisibility(View.GONE); } else { emptyState.setVisibility(View.GONE); recyclerView.setVisibility(View.VISIBLE); + fab.setVisibility(View.VISIBLE); } recyclerView.getAdapter().notifyDataSetChanged(); From 46e89ff6918420be55d071aa25d57bea851a6b7d Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 16:29:59 +0100 Subject: [PATCH 5/7] remove fallback since it can lead to pm added in the wrong project --- .../io/snabble/sdk/ui/payment/PaymentCredentialsListView.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java index 33c4bab8db..1ab0de8789 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java +++ b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java @@ -102,9 +102,6 @@ public void click() { Bundle bundle = new Bundle(); Project p = project; - if (p == null) { - p = Snabble.getInstance().getCheckedInProject().getValue(); - } if (p != null) { bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, p.getId()); dialogFragment.setArguments(bundle); From 7027532dcfcc5944a873606207d115a182dc352e Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 17:10:32 +0100 Subject: [PATCH 6/7] rename it --- .../sdk/ui/payment/PaymentCredentialsListView.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java index 1ab0de8789..1ab5e6f2d1 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java +++ b/ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java @@ -52,7 +52,7 @@ public class PaymentCredentialsListView extends FrameLayout implements PaymentCr private Project project; private View emptyState; private FloatingActionButton fab; - private CircularProgressIndicator progressIndicator; + private CircularProgressIndicator circularIndicator; public PaymentCredentialsListView(Context context) { super(context); @@ -75,7 +75,7 @@ private void inflateView() { emptyState = findViewById(R.id.empty_state); recyclerView = findViewById(R.id.recycler_view); fab = findViewById(R.id.fab); - progressIndicator = findViewById(R.id.circular_indicator); + circularIndicator = findViewById(R.id.circular_indicator); paymentCredentialsStore = Snabble.getInstance().getPaymentCredentialsStore(); @@ -127,7 +127,7 @@ public void click() { public void setProject(Project project) { this.project = project; - progressIndicator.setVisibility(View.GONE); + circularIndicator.setVisibility(View.GONE); onChanged(); } @@ -136,7 +136,7 @@ public void show(List types, Project project) { this.project = project; entries.clear(); - progressIndicator.setVisibility(View.GONE); + circularIndicator.setVisibility(View.GONE); onChanged(); } From 75efda6366088a8c59fa3496431712820f1b9f08 Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Mon, 17 Feb 2025 17:12:47 +0100 Subject: [PATCH 7/7] set it to be first visible item --- ui/src/main/res/layout/snabble_view_payment_credentials_list.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml b/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml index 2a58a3e80e..3bf1905c35 100644 --- a/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml +++ b/ui/src/main/res/layout/snabble_view_payment_credentials_list.xml @@ -11,7 +11,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:visibility="gone" app:indicatorSize="48dp" android:indeterminate="true"/>