Panagiotis Triantafyllou

my coupons filtering

...@@ -32,10 +32,11 @@ public class CouponsActivity extends Activity implements View.OnClickListener, ...@@ -32,10 +32,11 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
32 // =========================================================== 32 // ===========================================================
33 33
34 private ImageView mIvBack; 34 private ImageView mIvBack;
35 - private LinearLayout mLlFilterActive, mLlFilterExpired; 35 + private LinearLayout mLlFilterActive, mLlFilterExpired, mLlActiveCount, mLlExpiredCount;
36 private RecyclerView mRvCoupons; 36 private RecyclerView mRvCoupons;
37 private CouponAdapter mCouponsAdapter; 37 private CouponAdapter mCouponsAdapter;
38 - private TextView mBtnFilterActive, mBtnFilterExpired, mTvHeaderTitle; 38 + private TextView mBtnFilterActive, mBtnFilterExpired, mTvHeaderTitle,
39 + mTvActiveCount, mTvExpiredCount;
39 40
40 // =========================================================== 41 // ===========================================================
41 // Methods for/from SuperClass/Interfaces 42 // Methods for/from SuperClass/Interfaces
...@@ -66,9 +67,9 @@ public class CouponsActivity extends Activity implements View.OnClickListener, ...@@ -66,9 +67,9 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
66 if (id == R.id.iv_back) { 67 if (id == R.id.iv_back) {
67 onBackPressed(); 68 onBackPressed();
68 } else if (id == R.id.ll_filter_active) { 69 } else if (id == R.id.ll_filter_active) {
69 -// filterCoupons(CouponItem.STATUS_ACTIVE); 70 + filterCoupons(1);
70 } else if (id == R.id.ll_filter_redeemed) { 71 } else if (id == R.id.ll_filter_redeemed) {
71 -// filterCoupons(CouponItem.STATUS_REDEEMED); 72 + filterCoupons(-1);
72 } 73 }
73 } 74 }
74 75
...@@ -79,11 +80,6 @@ public class CouponsActivity extends Activity implements View.OnClickListener, ...@@ -79,11 +80,6 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
79 startActivity(myIntent); 80 startActivity(myIntent);
80 } 81 }
81 82
82 - @Override
83 - public void onFavoriteClick(Coupon couponItem, int position) {
84 - // Handle favorite click if needed
85 - }
86 -
87 // =========================================================== 83 // ===========================================================
88 // Methods 84 // Methods
89 // =========================================================== 85 // ===========================================================
...@@ -99,12 +95,16 @@ public class CouponsActivity extends Activity implements View.OnClickListener, ...@@ -99,12 +95,16 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
99 mLlFilterExpired = findViewById(R.id.ll_filter_redeemed); 95 mLlFilterExpired = findViewById(R.id.ll_filter_redeemed);
100 mBtnFilterExpired = findViewById(R.id.btn_filter_redeemed); 96 mBtnFilterExpired = findViewById(R.id.btn_filter_redeemed);
101 mTvHeaderTitle = findViewById(R.id.tv_header_title); 97 mTvHeaderTitle = findViewById(R.id.tv_header_title);
98 + mLlActiveCount = findViewById(R.id.ll_active_count);
99 + mLlExpiredCount = findViewById(R.id.ll_expired_count);
100 + mTvActiveCount = findViewById(R.id.tv_active_count);
101 + mTvExpiredCount = findViewById(R.id.tv_expired_count);
102 // Set click listeners for filter buttons 102 // Set click listeners for filter buttons
103 mLlFilterActive.setOnClickListener(this); 103 mLlFilterActive.setOnClickListener(this);
104 mLlFilterExpired.setOnClickListener(this); 104 mLlFilterExpired.setOnClickListener(this);
105 105
106 WarpUtils.renderCustomFont(this, R.font.ping_lcg_bold, mTvHeaderTitle, 106 WarpUtils.renderCustomFont(this, R.font.ping_lcg_bold, mTvHeaderTitle,
107 - mBtnFilterActive, mBtnFilterExpired); 107 + mBtnFilterActive, mBtnFilterExpired, mTvActiveCount, mTvExpiredCount);
108 } 108 }
109 109
110 private void setupMyCouponsSection() { 110 private void setupMyCouponsSection() {
...@@ -114,34 +114,44 @@ public class CouponsActivity extends Activity implements View.OnClickListener, ...@@ -114,34 +114,44 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
114 114
115 mCouponsAdapter = new CouponAdapter(this, WarplyManagerHelper.getCoupons()); 115 mCouponsAdapter = new CouponAdapter(this, WarplyManagerHelper.getCoupons());
116 mCouponsAdapter.setOnCouponClickListener(this); 116 mCouponsAdapter.setOnCouponClickListener(this);
117 + filterCoupons(1);
117 mRvCoupons.setAdapter(mCouponsAdapter); 118 mRvCoupons.setAdapter(mCouponsAdapter);
118 119
119 int verticalSpacingInPixels = (int) TypedValue.applyDimension( 120 int verticalSpacingInPixels = (int) TypedValue.applyDimension(
120 TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics()); 121 TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
121 mRvCoupons.addItemDecoration(new VerticalSpaceItemDecoration(verticalSpacingInPixels)); 122 mRvCoupons.addItemDecoration(new VerticalSpaceItemDecoration(verticalSpacingInPixels));
122 123
123 -// filterCoupons(CouponItem.STATUS_ACTIVE); 124 + int activeCount = 0, expiredCount = 0;
125 + for (Coupon c : WarplyManagerHelper.getCoupons()) {
126 + if (c.getStatus() == 1) activeCount++;
127 + else if (c.getStatus() == -1) expiredCount++;
128 + }
129 + mTvActiveCount.setText(String.valueOf(activeCount));
130 + mTvExpiredCount.setText(String.valueOf(expiredCount));
124 } 131 }
125 132
126 - private void filterCoupons(String status) { 133 + private void filterCoupons(int status) {
127 - // Reset all filter button styles 134 + mCouponsAdapter.filterByStatus(status);
128 -// mBtnFilterActive.setBackgroundResource(R.drawable.shape_transparent_black_border); 135 +
129 -// mBtnFilterActive.setTextColor(getResources().getColor(R.color.custom_black2)); 136 + if (status == 1) {
130 - 137 + mLlFilterActive.setBackgroundResource(R.drawable.shape_rectangle_rounded_black2);
131 -// mBtnFilterRedeemed.setBackgroundResource(R.drawable.shape_transparent_black_border); 138 + mBtnFilterActive.setTextColor(getColor(R.color.white));
132 -// mBtnFilterRedeemed.setTextColor(getResources().getColor(R.color.custom_black2)); 139 + mLlActiveCount.setBackgroundResource(R.drawable.shape_rounded_transparent_white_border);
133 - 140 + mTvActiveCount.setTextColor(getColor(R.color.white));
134 - // Set selected filter button style 141 + mLlFilterExpired.setBackgroundResource(R.drawable.shape_rectangle_rounded_grey4);
135 -// if (CouponItem.STATUS_ACTIVE.equals(status)) { 142 + mBtnFilterExpired.setTextColor(getColor(R.color.custom_black6));
136 -// mBtnFilterActive.setBackgroundResource(R.drawable.shape_rectangle_rounded_black); 143 + mLlExpiredCount.setBackgroundResource(R.drawable.shape_rounded_transparent_black_border);
137 -// mBtnFilterActive.setTextColor(Color.WHITE); 144 + mTvExpiredCount.setTextColor(getColor(R.color.custom_black6));
138 -// } else if (CouponItem.STATUS_REDEEMED.equals(status)) { 145 + } else {
139 -// mBtnFilterRedeemed.setBackgroundResource(R.drawable.shape_rectangle_rounded_black); 146 + mLlFilterExpired.setBackgroundResource(R.drawable.shape_rectangle_rounded_black2);
140 -// mBtnFilterRedeemed.setTextColor(Color.WHITE); 147 + mBtnFilterExpired.setTextColor(getColor(R.color.white));
141 -// } 148 + mLlExpiredCount.setBackgroundResource(R.drawable.shape_rounded_transparent_white_border);
142 - 149 + mTvExpiredCount.setTextColor(getColor(R.color.white));
143 - // Apply filter to adapter 150 + mLlFilterActive.setBackgroundResource(R.drawable.shape_rectangle_rounded_grey4);
144 -// mCouponsAdapter.filterByStatus(status); 151 + mBtnFilterActive.setTextColor(getColor(R.color.custom_black6));
152 + mLlActiveCount.setBackgroundResource(R.drawable.shape_rounded_transparent_black_border);
153 + mTvActiveCount.setTextColor(getColor(R.color.custom_black6));
154 + }
145 } 155 }
146 156
147 // =========================================================== 157 // ===========================================================
......
...@@ -2,7 +2,6 @@ package ly.warp.sdk.activities; ...@@ -2,7 +2,6 @@ package ly.warp.sdk.activities;
2 2
3 import android.app.Activity; 3 import android.app.Activity;
4 import android.content.Intent; 4 import android.content.Intent;
5 -import android.graphics.Color;
6 import android.os.Bundle; 5 import android.os.Bundle;
7 import android.os.Parcelable; 6 import android.os.Parcelable;
8 import android.util.TypedValue; 7 import android.util.TypedValue;
...@@ -110,11 +109,6 @@ public class ProfileActivity extends Activity implements View.OnClickListener, O ...@@ -110,11 +109,6 @@ public class ProfileActivity extends Activity implements View.OnClickListener, O
110 startActivity(myIntent); 109 startActivity(myIntent);
111 } 110 }
112 111
113 - @Override
114 - public void onFavoriteClick(Coupon couponItem, int position) {
115 - // Handle favorite click if needed
116 - }
117 -
118 // =========================================================== 112 // ===========================================================
119 // Methods 113 // Methods
120 // =========================================================== 114 // ===========================================================
......
...@@ -43,8 +43,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView ...@@ -43,8 +43,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
43 */ 43 */
44 public interface OnCouponClickListener { 44 public interface OnCouponClickListener {
45 void onCouponClick(Coupon couponItem, int position); 45 void onCouponClick(Coupon couponItem, int position);
46 -
47 - void onFavoriteClick(Coupon couponItem, int position);
48 } 46 }
49 47
50 /** 48 /**
...@@ -56,7 +54,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView ...@@ -56,7 +54,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
56 public CouponAdapter(Context context, ArrayList<Coupon> couponItems) { 54 public CouponAdapter(Context context, ArrayList<Coupon> couponItems) {
57 this.context = context; 55 this.context = context;
58 this.allCouponItems = couponItems; 56 this.allCouponItems = couponItems;
59 - this.filteredCouponItems = couponItems; 57 + this.filteredCouponItems = new ArrayList<>(couponItems);
60 } 58 }
61 59
62 /** 60 /**
......
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<shape xmlns:android="http://schemas.android.com/apk/res/android"
3 + android:shape="rectangle">
4 + <corners android:radius="1000dp" />
5 +
6 + <solid android:color="@android:color/transparent" />
7 +
8 + <stroke
9 + android:width="2dp"
10 + android:color="@color/custom_black6" />
11 +</shape>
...\ No newline at end of file ...\ No newline at end of file
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
97 android:layout_height="wrap_content" 97 android:layout_height="wrap_content"
98 android:layout_marginEnd="8dp" 98 android:layout_marginEnd="8dp"
99 android:background="@drawable/shape_rectangle_rounded_black2" 99 android:background="@drawable/shape_rectangle_rounded_black2"
100 + android:gravity="center"
100 android:paddingHorizontal="20dp" 101 android:paddingHorizontal="20dp"
101 android:paddingVertical="12dp"> 102 android:paddingVertical="12dp">
102 103
...@@ -108,6 +109,28 @@ ...@@ -108,6 +109,28 @@
108 android:text="@string/demo_active" 109 android:text="@string/demo_active"
109 android:textColor="@color/white" 110 android:textColor="@color/white"
110 android:textSize="14sp" /> 111 android:textSize="14sp" />
112 +
113 + <View
114 + android:layout_width="12dp"
115 + android:layout_height="match_parent" />
116 +
117 + <LinearLayout
118 + android:id="@+id/ll_active_count"
119 + android:layout_width="21dp"
120 + android:layout_height="21dp"
121 + android:background="@drawable/shape_rounded_transparent_white_border"
122 + android:gravity="center"
123 + android:orientation="horizontal">
124 +
125 + <TextView
126 + android:id="@+id/tv_active_count"
127 + android:layout_width="wrap_content"
128 + android:layout_height="wrap_content"
129 + android:includeFontPadding="false"
130 + android:text="0"
131 + android:textColor="@color/white"
132 + android:textSize="10sp" />
133 + </LinearLayout>
111 </LinearLayout> 134 </LinearLayout>
112 135
113 <LinearLayout 136 <LinearLayout
...@@ -116,18 +139,41 @@ ...@@ -116,18 +139,41 @@
116 android:layout_height="wrap_content" 139 android:layout_height="wrap_content"
117 android:layout_marginEnd="8dp" 140 android:layout_marginEnd="8dp"
118 android:background="@drawable/shape_rectangle_rounded_grey4" 141 android:background="@drawable/shape_rectangle_rounded_grey4"
142 + android:gravity="center"
119 android:paddingHorizontal="20dp" 143 android:paddingHorizontal="20dp"
120 android:paddingVertical="12dp"> 144 android:paddingVertical="12dp">
121 145
122 <TextView 146 <TextView
123 android:id="@+id/btn_filter_redeemed" 147 android:id="@+id/btn_filter_redeemed"
124 - android:layout_height="wrap_content"
125 android:layout_width="wrap_content" 148 android:layout_width="wrap_content"
149 + android:layout_height="wrap_content"
126 android:gravity="center" 150 android:gravity="center"
127 android:includeFontPadding="false" 151 android:includeFontPadding="false"
128 android:text="@string/demo_expired" 152 android:text="@string/demo_expired"
129 android:textColor="@color/custom_black6" 153 android:textColor="@color/custom_black6"
130 android:textSize="14sp" /> 154 android:textSize="14sp" />
155 +
156 + <View
157 + android:layout_width="12dp"
158 + android:layout_height="match_parent" />
159 +
160 + <LinearLayout
161 + android:id="@+id/ll_expired_count"
162 + android:layout_width="21dp"
163 + android:layout_height="21dp"
164 + android:background="@drawable/shape_rounded_transparent_black_border"
165 + android:gravity="center"
166 + android:orientation="horizontal">
167 +
168 + <TextView
169 + android:id="@+id/tv_expired_count"
170 + android:layout_width="wrap_content"
171 + android:layout_height="wrap_content"
172 + android:includeFontPadding="false"
173 + android:text="0"
174 + android:textColor="@color/custom_black6"
175 + android:textSize="10sp" />
176 + </LinearLayout>
131 </LinearLayout> 177 </LinearLayout>
132 </LinearLayout> 178 </LinearLayout>
133 179
......