Showing
4 changed files
with
143 additions
and
8 deletions
... | @@ -17,17 +17,20 @@ import androidx.recyclerview.widget.RecyclerView; | ... | @@ -17,17 +17,20 @@ import androidx.recyclerview.widget.RecyclerView; |
17 | import org.json.JSONException; | 17 | import org.json.JSONException; |
18 | 18 | ||
19 | import ly.warp.sdk.R; | 19 | import ly.warp.sdk.R; |
20 | +import ly.warp.sdk.views.adapters.HomeCampaignAdapter; | ||
20 | import ly.warp.sdk.views.adapters.HomeCouponAdapter; | 21 | import ly.warp.sdk.views.adapters.HomeCouponAdapter; |
21 | import ly.warp.sdk.activities.WarpViewActivity; | 22 | import ly.warp.sdk.activities.WarpViewActivity; |
22 | import ly.warp.sdk.io.models.Coupon; | 23 | import ly.warp.sdk.io.models.Coupon; |
23 | import ly.warp.sdk.io.models.CouponList; | 24 | import ly.warp.sdk.io.models.CouponList; |
24 | -import ly.warp.sdk.views.adapters.ProfileCampaignAdapter; | 25 | +import ly.warp.sdk.io.models.Campaign; |
26 | +import ly.warp.sdk.io.models.CampaignList; | ||
25 | 27 | ||
26 | public class HomeFragment extends Fragment { | 28 | public class HomeFragment extends Fragment { |
27 | 29 | ||
28 | private RelativeLayout mOptionOne, mOptionTwo, mOptionThree; | 30 | private RelativeLayout mOptionOne, mOptionTwo, mOptionThree; |
29 | - private RecyclerView mRecyclerCoupons; | 31 | + private RecyclerView mRecyclerCampaigns, mRecyclerCoupons; |
30 | private HomeCouponAdapter mAdapterCoupons; | 32 | private HomeCouponAdapter mAdapterCoupons; |
33 | + private HomeCampaignAdapter mAdapterCampaigns; | ||
31 | 34 | ||
32 | @Override | 35 | @Override |
33 | public View onCreateView( | 36 | public View onCreateView( |
... | @@ -73,7 +76,32 @@ public class HomeFragment extends Fragment { | ... | @@ -73,7 +76,32 @@ public class HomeFragment extends Fragment { |
73 | mOptionThreeText.setText("1"); | 76 | mOptionThreeText.setText("1"); |
74 | mOptionThreeImage.setImageResource(R.drawable.tv_option); | 77 | mOptionThreeImage.setImageResource(R.drawable.tv_option); |
75 | 78 | ||
76 | - /********* TEST DATA **********/ | 79 | + /********* TEST CAMPAIGNS DATA **********/ |
80 | + CampaignList clistCampaigns = new CampaignList(); | ||
81 | + try { | ||
82 | + clistCampaigns.add(new Campaign("{\"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\"}")); | ||
83 | + clistCampaigns.add(new Campaign("{\"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\"}")); | ||
84 | + } catch (JSONException e) { | ||
85 | + e.printStackTrace(); | ||
86 | + } | ||
87 | + /********* TEST CAMPAIGNS DATA **********/ | ||
88 | + | ||
89 | + mRecyclerCampaigns = view.findViewById(R.id.rv_home_campaigns); | ||
90 | + mRecyclerCampaigns.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | ||
91 | + mAdapterCampaigns = new HomeCampaignAdapter(getContext(), clistCampaigns); | ||
92 | + mRecyclerCampaigns.setAdapter(mAdapterCampaigns); | ||
93 | + mAdapterCampaigns.getPositionClicks() | ||
94 | + .doOnNext(campaign -> { | ||
95 | + getContext().startActivity( | ||
96 | + WarpViewActivity.createIntentFromSessionUUID(getContext(), | ||
97 | + campaign.getSessionUUID())); | ||
98 | + }) | ||
99 | + .doOnError(error -> { | ||
100 | + }) | ||
101 | + .subscribe(); | ||
102 | + | ||
103 | + | ||
104 | + /********* TEST COUPONS DATA **********/ | ||
77 | CouponList clist = new CouponList(); | 105 | CouponList clist = new CouponList(); |
78 | try { | 106 | try { |
79 | clist.add(new Coupon("{\"barcode\": \"a724e911a71a42408b6ba50ae6c08dbb\", \"coupon\": \"123456789\", \"name\": \"\\u039a\\u03ac\\u03bd\\u03b5 strike\", \"description\": \"\\u03ba\\u03b1\\u03b9 \\u03ba\\u03ad\\u03c1\\u03b4\\u03b9\\u03c3\\u03b5!\", \"image\": \"https://warply.s3.amazonaws.com/artworks/034fba10ceac4e0f9338bd8e60086292/index.html\"}")); | 107 | clist.add(new Coupon("{\"barcode\": \"a724e911a71a42408b6ba50ae6c08dbb\", \"coupon\": \"123456789\", \"name\": \"\\u039a\\u03ac\\u03bd\\u03b5 strike\", \"description\": \"\\u03ba\\u03b1\\u03b9 \\u03ba\\u03ad\\u03c1\\u03b4\\u03b9\\u03c3\\u03b5!\", \"image\": \"https://warply.s3.amazonaws.com/artworks/034fba10ceac4e0f9338bd8e60086292/index.html\"}")); |
... | @@ -81,7 +109,7 @@ public class HomeFragment extends Fragment { | ... | @@ -81,7 +109,7 @@ public class HomeFragment extends Fragment { |
81 | } catch (JSONException e) { | 109 | } catch (JSONException e) { |
82 | e.printStackTrace(); | 110 | e.printStackTrace(); |
83 | } | 111 | } |
84 | - /********* TEST DATA **********/ | 112 | + /********* TEST COUPONS DATA **********/ |
85 | 113 | ||
86 | mRecyclerCoupons = view.findViewById(R.id.rv_home_coupons); | 114 | mRecyclerCoupons = view.findViewById(R.id.rv_home_coupons); |
87 | mRecyclerCoupons.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | 115 | mRecyclerCoupons.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | ... | ... |
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.Campaign; | ||
20 | +import ly.warp.sdk.io.models.CampaignList; | ||
21 | + | ||
22 | + | ||
23 | +public class HomeCampaignAdapter extends RecyclerView.Adapter<HomeCampaignAdapter.HomeCampaignViewHolder> { | ||
24 | + | ||
25 | + private Context mContext; | ||
26 | + private CampaignList mCampaigns; | ||
27 | + private final PublishSubject<Campaign> onClickSubject = PublishSubject.create(); | ||
28 | + | ||
29 | + public HomeCampaignAdapter(Context mContext, CampaignList campaignList) { | ||
30 | + this.mContext = mContext; | ||
31 | + this.mCampaigns = campaignList; | ||
32 | + } | ||
33 | + | ||
34 | + public class HomeCampaignViewHolder extends RecyclerView.ViewHolder { | ||
35 | + private ImageView ivCampaignTitle; | ||
36 | + private TextView tvCampaignTitle; | ||
37 | + | ||
38 | + public HomeCampaignViewHolder(View view) { | ||
39 | + super(view); | ||
40 | + ivCampaignTitle = view.findViewById(R.id.iv_campaign_logo); | ||
41 | + tvCampaignTitle = view.findViewById(R.id.tv_campaign_title); | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public int getItemCount() { | ||
47 | + if (mCampaigns == null) | ||
48 | + return 0; | ||
49 | + else | ||
50 | + return mCampaigns.size(); | ||
51 | + } | ||
52 | + | ||
53 | + | ||
54 | + public Campaign getItem(int id) { | ||
55 | + return mCampaigns.get(id); | ||
56 | + } | ||
57 | + | ||
58 | + public void updateData(CampaignList campaignList) { | ||
59 | + mCampaigns.clear(); | ||
60 | + mCampaigns.addAll(campaignList); | ||
61 | + notifyDataSetChanged(); | ||
62 | + } | ||
63 | + | ||
64 | + | ||
65 | + @Override | ||
66 | + public HomeCampaignViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
67 | + View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.carousel_item, parent, false); | ||
68 | + return new HomeCampaignViewHolder(itemView); | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public void onBindViewHolder(final HomeCampaignViewHolder holder, int position) { | ||
73 | + Campaign campaignItem = mCampaigns.get(position); | ||
74 | + | ||
75 | +// if (campaignItem != null) { | ||
76 | +// if (!TextUtils.isEmpty(campaignItem.getLogoUrl())) { | ||
77 | +// Glide.with(mContext) | ||
78 | +//// .setDefaultRequestOptions( | ||
79 | +//// RequestOptions | ||
80 | +//// .placeholderOf(R.drawable.ic_default_contact_photo) | ||
81 | +//// .error(R.drawable.ic_default_contact_photo)) | ||
82 | +// .load(campaignItem.getLogoUrl()) | ||
83 | +// .diskCacheStrategy(DiskCacheStrategy.DATA) | ||
84 | +// .into(holder.ivCampaignTitle); | ||
85 | +// } else { | ||
86 | +// Glide.with(mContext) | ||
87 | +// .load(R.drawable.ic_cosmote_logo_horizontal_grey) | ||
88 | +// .into(holder.ivCampaignTitle); | ||
89 | +// } | ||
90 | +// | ||
91 | +// holder.tvCampaignTitle.setText(campaignItem.getTitle()); | ||
92 | +// | ||
93 | +// holder.itemView.setOnClickListener(v -> onClickSubject.onNext(campaignItem)); | ||
94 | +// } | ||
95 | + } | ||
96 | + | ||
97 | + public Observable<Campaign> getPositionClicks() { | ||
98 | + return onClickSubject.cache(); | ||
99 | + } | ||
100 | + | ||
101 | +} |
... | @@ -4,6 +4,7 @@ | ... | @@ -4,6 +4,7 @@ |
4 | xmlns:tools="http://schemas.android.com/tools" | 4 | xmlns:tools="http://schemas.android.com/tools" |
5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
6 | android:layout_height="240dp" | 6 | android:layout_height="240dp" |
7 | + android:layout_marginLeft="10dp" | ||
7 | android:background="@drawable/bottom_border"> | 8 | android:background="@drawable/bottom_border"> |
8 | 9 | ||
9 | <LinearLayout | 10 | <LinearLayout | ... | ... |
... | @@ -92,10 +92,15 @@ | ... | @@ -92,10 +92,15 @@ |
92 | android:layout_width="match_parent" | 92 | android:layout_width="match_parent" |
93 | android:layout_height="wrap_content" | 93 | android:layout_height="wrap_content" |
94 | android:layout_below="@id/rl_header" | 94 | android:layout_below="@id/rl_header" |
95 | - android:layout_marginTop="16dp" | 95 | + android:layout_marginTop="16dp"> |
96 | - android:paddingHorizontal="16dp"> | 96 | + <androidx.recyclerview.widget.RecyclerView |
97 | - | 97 | + android:id="@+id/rv_home_campaigns" |
98 | - <include layout="@layout/carousel_item" /> | 98 | + android:layout_width="match_parent" |
99 | + android:layout_height="wrap_content" | ||
100 | + android:layout_marginBottom="8dp" | ||
101 | + android:clipToPadding="false" | ||
102 | + android:orientation="horizontal" | ||
103 | + android:paddingEnd="10dp"/> | ||
99 | </RelativeLayout> | 104 | </RelativeLayout> |
100 | 105 | ||
101 | <LinearLayout | 106 | <LinearLayout | ... | ... |
-
Please register or login to post a comment