Skip to content

Commit 8763789

Browse files
committed
add credit card icon to payment credentials list and fix payment options view not updating when adding a creditcard via datatrans
1 parent f0d275e commit 8763789

File tree

11 files changed

+84
-79
lines changed

11 files changed

+84
-79
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.43.2]
5+
6+
### Added
7+
- Added an icon to the payment credentials list empty state
8+
9+
### Fixed
10+
- PaymentOptionsView not updating when adding a credit card via datatrans
11+
412
## [0.43.1]
513

614
### Fixed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
}
3232

3333
project.ext {
34-
sdkVersion='0.43.1'
34+
sdkVersion='0.43.2'
3535
versionCode=1
3636

3737
compileSdkVersion=30

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

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class PaymentCredentialsListView extends FrameLayout implements PaymentCr
4646
private RecyclerView recyclerView;
4747
private List<PaymentCredentials.Type> types;
4848
private Project project;
49+
private View emptyState;
4950

5051
public PaymentCredentialsListView(Context context) {
5152
super(context);
@@ -117,6 +118,8 @@ public void click() {
117118
}
118119
}
119120
});
121+
122+
emptyState = findViewById(R.id.empty_state);
120123
}
121124

122125
public void show(List<PaymentCredentials.Type> types, Project project) {
@@ -202,6 +205,14 @@ public void onChanged() {
202205
}
203206

204207
recyclerView.getAdapter().notifyDataSetChanged();
208+
209+
if (entries.size() == 0) {
210+
emptyState.setVisibility(View.VISIBLE);
211+
recyclerView.setVisibility(View.GONE);
212+
} else {
213+
emptyState.setVisibility(View.GONE);
214+
recyclerView.setVisibility(View.VISIBLE);
215+
}
205216
}
206217

207218
private int getDrawableForBrand(PaymentCredentials.Brand brand) {
@@ -229,74 +240,52 @@ private int getDrawableForBrand(PaymentCredentials.Brand brand) {
229240
return drawableResId;
230241
}
231242

232-
private class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
233-
private final static int TYPE_EMPTYSTATE = 0;
234-
private final static int TYPE_ENTRY = 1;
235-
236-
@Override
237-
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
238-
if (viewType == TYPE_EMPTYSTATE) {
239-
View v = LayoutInflater.from(getContext()).inflate(R.layout.snabble_item_payment_credentials_list_emptystate, parent, false);
240-
return new EmptyStateViewHolder(v);
241-
} else {
242-
View v = LayoutInflater.from(getContext()).inflate(R.layout.snabble_item_payment_credentials_list_entry, parent, false);
243-
return new EntryViewHolder(v);
244-
}
245-
}
246-
243+
private class Adapter extends RecyclerView.Adapter<EntryViewHolder> {
247244
@Override
248-
public int getItemViewType(int position) {
249-
if (entries.size() == 0) {
250-
return TYPE_EMPTYSTATE;
251-
}
252-
253-
return TYPE_ENTRY;
245+
public EntryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
246+
View v = LayoutInflater.from(getContext()).inflate(R.layout.snabble_item_payment_credentials_list_entry, parent, false);
247+
return new EntryViewHolder(v);
254248
}
255249

256250
@Override
257-
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
258-
int type = getItemViewType(position);
259-
260-
if (type == TYPE_ENTRY) {
261-
EntryViewHolder vh = (EntryViewHolder) holder;
262-
final Entry e = entries.get(position);
251+
public void onBindViewHolder(final EntryViewHolder vh, final int position) {
252+
final Entry e = entries.get(position);
263253

264-
if (e.drawableRes != 0) {
265-
vh.icon.setImageResource(e.drawableRes);
266-
vh.icon.setVisibility(View.VISIBLE);
267-
} else {
268-
vh.icon.setVisibility(View.INVISIBLE);
269-
}
270-
271-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yyyy");
272-
String validTo = simpleDateFormat.format(e.paymentCredentials.getValidTo());
273-
274-
if (e.paymentCredentials.getValidTo() != 0) {
275-
vh.validTo.setText(getResources().getString(R.string.Snabble_Payment_CreditCard_expireDate, validTo));
276-
vh.validTo.setVisibility(View.VISIBLE);
277-
} else {
278-
vh.validTo.setVisibility(View.GONE);
279-
}
254+
if (e.drawableRes != 0) {
255+
vh.icon.setImageResource(e.drawableRes);
256+
vh.icon.setVisibility(View.VISIBLE);
257+
} else {
258+
vh.icon.setVisibility(View.INVISIBLE);
259+
}
280260

281-
vh.text.setText(e.text);
282-
vh.delete.setOnClickListener(view -> {
283-
new AlertDialog.Builder(getContext())
284-
.setMessage(R.string.Snabble_Payment_delete_message)
285-
.setPositiveButton(R.string.Snabble_Yes, (dialog, which) -> {
286-
paymentCredentialsStore.remove(e.paymentCredentials);
287-
})
288-
.setNegativeButton(R.string.Snabble_No, null)
289-
.create()
290-
.show();
261+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yyyy");
262+
String validTo = simpleDateFormat.format(e.paymentCredentials.getValidTo());
291263

292-
Telemetry.event(Telemetry.Event.PaymentMethodDeleted, e.paymentCredentials.getType());
293-
});
264+
if (e.paymentCredentials.getValidTo() != 0) {
265+
vh.validTo.setText(getResources().getString(R.string.Snabble_Payment_CreditCard_expireDate, validTo));
266+
vh.validTo.setVisibility(View.VISIBLE);
267+
} else {
268+
vh.validTo.setVisibility(View.GONE);
294269
}
270+
271+
vh.text.setText(e.text);
272+
vh.delete.setOnClickListener(view -> {
273+
new AlertDialog.Builder(getContext())
274+
.setMessage(R.string.Snabble_Payment_delete_message)
275+
.setPositiveButton(R.string.Snabble_Yes, (dialog, which) -> {
276+
paymentCredentialsStore.remove(e.paymentCredentials);
277+
})
278+
.setNegativeButton(R.string.Snabble_No, null)
279+
.create()
280+
.show();
281+
282+
Telemetry.event(Telemetry.Event.PaymentMethodDeleted, e.paymentCredentials.getType());
283+
});
295284
}
296285

297286
@Override
298287
public int getItemCount() {
299-
return Math.max(1, entries.size());
288+
return entries.size();
300289
}
301290
}
302291

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ open class PaymentOptionsView @JvmOverloads constructor(
4343
adapter.submitList(getEntries())
4444

4545
val listener = PaymentCredentialsStore.Callback {
46-
adapter.notifyDataSetChanged()
46+
adapter.submitList(getEntries())
4747
}
4848

4949
Snabble.getInstance().paymentCredentialsStore.addCallback(listener)
500 Bytes
Loading
276 Bytes
Loading
736 Bytes
Loading
1.12 KB
Loading
1.49 KB
Loading

ui/src/main/res/layout/snabble_item_payment_credentials_list_emptystate.xml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)