@@ -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
0 commit comments