Skip to content

Commit 0e4dd8f

Browse files
authored
Merge pull request #54 from snabble/missing_project_edgecase
Fix edge case when in single project apps the client has checked out
2 parents ae56223 + 51e56d9 commit 0e4dd8f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ open class PaymentCredentialsListFragment : BaseFragment(
2929

3030
override fun onActualViewCreated(view: View, savedInstanceState: Bundle?) {
3131
val v = view as PaymentCredentialsListView
32-
type?.let { v.show(it, project) }
32+
type?.let { v.show(it, project) } ?: v.setProject(project)
3333
}
3434
}

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentCredentialsListView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public PaymentCredentialsListView(Context context, AttributeSet attrs, int defSt
6161

6262
private void inflateView() {
6363
inflate(getContext(), R.layout.snabble_view_payment_credentials_list, this);
64+
if (isInEditMode()) return;
6465
paymentCredentialsStore = Snabble.getInstance().getPaymentCredentialsStore();
6566

6667
recyclerView = findViewById(R.id.recycler_view);
@@ -85,6 +86,10 @@ public void click() {
8586
p = Snabble.getInstance().getCheckedInProject().getValue();
8687
}
8788

89+
if (p == null) {
90+
throw new IllegalStateException("Cannot get current project. Did you forget to set the projectId to the PaymentCredentialsListFragment or PaymentCredentialsListView?");
91+
}
92+
8893
bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, p.getId());
8994
dialogFragment.setArguments(bundle);
9095
dialogFragment.show(((FragmentActivity) activity).getSupportFragmentManager(), null);
@@ -104,6 +109,10 @@ public void click() {
104109
emptyState = findViewById(R.id.empty_state);
105110
}
106111

112+
public void setProject(Project project) {
113+
this.project = project;
114+
}
115+
107116
public void show(List<PaymentCredentials.Type> types, Project project) {
108117
this.types = types;
109118
this.project = project;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<io.snabble.sdk.ui.payment.PaymentCredentialsListView xmlns:android="http://schemas.android.com/apk/res/android"
2+
<io.snabble.sdk.ui.payment.PaymentCredentialsListView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
android:id="@+id/user_payment_method_view"
45
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
6-
7-
</io.snabble.sdk.ui.payment.PaymentCredentialsListView>
6+
android:layout_height="match_parent"/>

0 commit comments

Comments
 (0)