Showing
3 changed files
with
148 additions
and
7 deletions
... | @@ -11,14 +11,23 @@ import android.widget.TextView; | ... | @@ -11,14 +11,23 @@ import android.widget.TextView; |
11 | 11 | ||
12 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
13 | import androidx.fragment.app.Fragment; | 13 | import androidx.fragment.app.Fragment; |
14 | +import androidx.recyclerview.widget.LinearLayoutManager; | ||
15 | +import androidx.recyclerview.widget.RecyclerView; | ||
16 | + | ||
17 | +import org.json.JSONException; | ||
14 | 18 | ||
15 | import ly.warp.sdk.R; | 19 | import ly.warp.sdk.R; |
20 | +import ly.warp.sdk.views.adapters.HomeCouponAdapter; | ||
21 | +import ly.warp.sdk.activities.WarpViewActivity; | ||
22 | +import ly.warp.sdk.io.models.Coupon; | ||
23 | +import ly.warp.sdk.io.models.CouponList; | ||
24 | +import ly.warp.sdk.views.adapters.ProfileCampaignAdapter; | ||
16 | 25 | ||
17 | public class HomeFragment extends Fragment { | 26 | public class HomeFragment extends Fragment { |
18 | 27 | ||
19 | - private RelativeLayout mOptionOne; | 28 | + private RelativeLayout mOptionOne, mOptionTwo, mOptionThree; |
20 | - private RelativeLayout mOptionTwo; | 29 | + private RecyclerView mRecyclerCoupons; |
21 | - private RelativeLayout mOptionThree; | 30 | + private HomeCouponAdapter mAdapterCoupons; |
22 | 31 | ||
23 | @Override | 32 | @Override |
24 | public View onCreateView( | 33 | public View onCreateView( |
... | @@ -63,6 +72,30 @@ public class HomeFragment extends Fragment { | ... | @@ -63,6 +72,30 @@ public class HomeFragment extends Fragment { |
63 | ImageView mOptionThreeImage = (ImageView) mOptionThree.findViewById(R.id.option_icon); | 72 | ImageView mOptionThreeImage = (ImageView) mOptionThree.findViewById(R.id.option_icon); |
64 | mOptionThreeText.setText("1"); | 73 | mOptionThreeText.setText("1"); |
65 | mOptionThreeImage.setImageResource(R.drawable.tv_option); | 74 | mOptionThreeImage.setImageResource(R.drawable.tv_option); |
75 | + | ||
76 | + /********* TEST DATA **********/ | ||
77 | + CouponList clist = new CouponList(); | ||
78 | + try { | ||
79 | + clist.add(new Coupon("{\"session_uuid\": \"a724e911a71a42408b6ba50ae6c08dbb\", \"title\": \"\\u039a\\u03ac\\u03bd\\u03b5 strike\", \"subtitle\": \"\\u03ba\\u03b1\\u03b9 \\u03ba\\u03ad\\u03c1\\u03b4\\u03b9\\u03c3\\u03b5!\", \"offer_message\": null, \"message\": null, \"index_url\": \"https://warply.s3.amazonaws.com/artworks/034fba10ceac4e0f9338bd8e60086292/index.html\", \"logo_url\": \"https://warply.s3.amazonaws.com/temp/96322898cc824981aece923d8b5afc88/drggtdr.jpg\", \"starts\": 1644494400, \"expires\": 1881522000, \"delivered\": 1644607293, \"action\": 0, \"opened\": 1, \"offer_category\": \"standard-offer\", \"sorting\": 0, \"is_new\": true, \"session_metadata\": \"\\\"\\\"\", \"display_type\": null, \"delivery_method\": 2, \"extra_fields\": \"{}\", \"campaign_type\": null, \"campaign_type_settings\": null, \"actions\": null, \"show\": true, \"expired\": false, \"audience\": \"all\"}")); | ||
80 | + clist.add(new Coupon("{\"session_uuid\": \"a724e911a71a42408b6ba50ae6c08dbb\", \"title\": \"\\u039a\\u03ac\\u03bd\\u03b5 strike\", \"subtitle\": \"\\u03ba\\u03b1\\u03b9 \\u03ba\\u03ad\\u03c1\\u03b4\\u03b9\\u03c3\\u03b5!\", \"offer_message\": null, \"message\": null, \"index_url\": \"https://warply.s3.amazonaws.com/artworks/034fba10ceac4e0f9338bd8e60086292/index.html\", \"logo_url\": \"https://warply.s3.amazonaws.com/temp/96322898cc824981aece923d8b5afc88/drggtdr.jpg\", \"starts\": 1644494400, \"expires\": 1881522000, \"delivered\": 1644607293, \"action\": 0, \"opened\": 1, \"offer_category\": \"standard-offer\", \"sorting\": 0, \"is_new\": true, \"session_metadata\": \"\\\"\\\"\", \"display_type\": null, \"delivery_method\": 2, \"extra_fields\": \"{}\", \"campaign_type\": null, \"campaign_type_settings\": null, \"actions\": null, \"show\": true, \"expired\": false, \"audience\": \"all\"}")); | ||
81 | + } catch (JSONException e) { | ||
82 | + e.printStackTrace(); | ||
83 | + } | ||
84 | + /********* TEST DATA **********/ | ||
85 | + | ||
86 | + mRecyclerCoupons = view.findViewById(R.id.rv_home_coupons); | ||
87 | + mRecyclerCoupons.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | ||
88 | + mAdapterCoupons = new HomeCouponAdapter(getContext(), clist); | ||
89 | + mRecyclerCoupons.setAdapter(mAdapterCoupons); | ||
90 | + mAdapterCoupons.getPositionClicks() | ||
91 | + .doOnNext(coupon -> { | ||
92 | + getContext().startActivity( | ||
93 | + WarpViewActivity.createIntentFromSessionUUID(getContext(), | ||
94 | + coupon.getSessionUUID())); | ||
95 | + }) | ||
96 | + .doOnError(error -> { | ||
97 | + }) | ||
98 | + .subscribe(); | ||
66 | } | 99 | } |
67 | 100 | ||
68 | @Override | 101 | @Override | ... | ... |
1 | +package ly.warp.sdk.views.adapters; | ||
2 | + | ||
3 | +import android.content.Context; | ||
4 | +import android.text.TextUtils; | ||
5 | +import android.view.LayoutInflater; | ||
6 | +import android.view.View; | ||
7 | +import android.view.ViewGroup; | ||
8 | +import android.widget.ImageView; | ||
9 | +import android.widget.TextView; | ||
10 | + | ||
11 | +import androidx.recyclerview.widget.RecyclerView; | ||
12 | + | ||
13 | +import com.bumptech.glide.Glide; | ||
14 | +import com.bumptech.glide.load.engine.DiskCacheStrategy; | ||
15 | + | ||
16 | +import io.reactivex.Observable; | ||
17 | +import io.reactivex.subjects.PublishSubject; | ||
18 | +import ly.warp.sdk.R; | ||
19 | +import ly.warp.sdk.io.models.Coupon; | ||
20 | +import ly.warp.sdk.io.models.CouponList; | ||
21 | + | ||
22 | +public class HomeCouponAdapter extends RecyclerView.Adapter<HomeCouponAdapter.HomeCouponViewHolder> { | ||
23 | + | ||
24 | + private Context mContext; | ||
25 | + private CouponList mCoupons; | ||
26 | + private final PublishSubject<Coupon> onClickSubject = PublishSubject.create(); | ||
27 | + | ||
28 | + public HomeCouponAdapter(Context mContext, CouponList campaignList) { | ||
29 | + this.mContext = mContext; | ||
30 | + this.mCoupons = campaignList; | ||
31 | + } | ||
32 | + | ||
33 | + public class HomeCouponViewHolder extends RecyclerView.ViewHolder { | ||
34 | + private ImageView ivCampaignTitle; | ||
35 | + private TextView tvCampaignTitle; | ||
36 | + | ||
37 | + public HomeCouponViewHolder(View view) { | ||
38 | + super(view); | ||
39 | + ivCampaignTitle = view.findViewById(R.id.iv_campaign_logo); | ||
40 | + tvCampaignTitle = view.findViewById(R.id.tv_campaign_title); | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public int getItemCount() { | ||
46 | + if (mCoupons == null) | ||
47 | + return 0; | ||
48 | + else | ||
49 | + return mCoupons.size(); | ||
50 | + } | ||
51 | + | ||
52 | + | ||
53 | + public Coupon getItem(int id) { | ||
54 | + return mCoupons.get(id); | ||
55 | + } | ||
56 | + | ||
57 | + public void updateData(CouponList couponList) { | ||
58 | + mCoupons.clear(); | ||
59 | + mCoupons.addAll(couponList); | ||
60 | + notifyDataSetChanged(); | ||
61 | + } | ||
62 | + | ||
63 | + | ||
64 | + @Override | ||
65 | + public HomeCouponViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
66 | + View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.coupon_layout, parent, false); | ||
67 | + return new HomeCouponViewHolder(itemView); | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public void onBindViewHolder(final HomeCouponViewHolder holder, int position) { | ||
72 | + Coupon couponItem = mCoupons.get(position); | ||
73 | + | ||
74 | + if (couponItem != null) { | ||
75 | + if (!TextUtils.isEmpty(couponItem.getLogoUrl())) { | ||
76 | + Glide.with(mContext) | ||
77 | +// .setDefaultRequestOptions( | ||
78 | +// RequestOptions | ||
79 | +// .placeholderOf(R.drawable.ic_default_contact_photo) | ||
80 | +// .error(R.drawable.ic_default_contact_photo)) | ||
81 | + .load(couponItem.getLogoUrl()) | ||
82 | + .diskCacheStrategy(DiskCacheStrategy.DATA) | ||
83 | + .into(holder.ivCampaignTitle); | ||
84 | + } else { | ||
85 | + Glide.with(mContext) | ||
86 | + .load(R.drawable.ic_cosmote_logo_horizontal_grey) | ||
87 | + .into(holder.ivCampaignTitle); | ||
88 | + } | ||
89 | + | ||
90 | + holder.tvCampaignTitle.setText(couponItem.getTitle()); | ||
91 | + | ||
92 | + holder.itemView.setOnClickListener(v -> onClickSubject.onNext(couponItem)); | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + public Observable<Coupon> getPositionClicks() { | ||
97 | + return onClickSubject.cache(); | ||
98 | + } | ||
99 | +} |
... | @@ -101,15 +101,24 @@ | ... | @@ -101,15 +101,24 @@ |
101 | <include layout="@layout/carousel_item" /> | 101 | <include layout="@layout/carousel_item" /> |
102 | </RelativeLayout> | 102 | </RelativeLayout> |
103 | 103 | ||
104 | - <RelativeLayout | 104 | + <LinearLayout |
105 | android:id="@+id/rl_home_coupons" | 105 | android:id="@+id/rl_home_coupons" |
106 | android:layout_width="match_parent" | 106 | android:layout_width="match_parent" |
107 | android:layout_height="wrap_content" | 107 | android:layout_height="wrap_content" |
108 | android:layout_below="@id/rl_home_campaigns" | 108 | android:layout_below="@id/rl_home_campaigns" |
109 | + android:layout_marginVertical="25dp" | ||
109 | android:paddingHorizontal="15dp"> | 110 | android:paddingHorizontal="15dp"> |
110 | - | 111 | +<!-- <androidx.recyclerview.widget.RecyclerView--> |
111 | - <include layout="@layout/coupon_layout"/> | 112 | +<!-- android:id="@+id/rv_home_coupons"--> |
112 | - </RelativeLayout> | 113 | +<!-- android:layout_width="match_parent"--> |
114 | +<!-- android:layout_height="wrap_content"--> | ||
115 | +<!-- android:layout_marginBottom="8dp"--> | ||
116 | +<!-- android:clipToPadding="false"--> | ||
117 | +<!-- android:orientation="horizontal"--> | ||
118 | +<!-- android:paddingEnd="10dp"--> | ||
119 | +<!-- />--> | ||
120 | + <include layout="@layout/coupon_layout" /> | ||
121 | + </LinearLayout> | ||
113 | 122 | ||
114 | <androidx.constraintlayout.widget.ConstraintLayout | 123 | <androidx.constraintlayout.widget.ConstraintLayout |
115 | android:id="@+id/rl_home_info_widget" | 124 | android:id="@+id/rl_home_info_widget" | ... | ... |
-
Please register or login to post a comment