Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 812d84b

Browse files
committed
added discount-codes feature
1 parent f5175c0 commit 812d84b

File tree

8 files changed

+237
-1
lines changed

8 files changed

+237
-1
lines changed

Diff for: android/app/src/main/assets/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"email": "[email protected]",
33
"app-name": "Open Event",
4-
"api-link": "https://open-event-api.herokuapp.com/v1/events/173",
4+
"api-link": "https://open-event-api.herokuapp.com/v1/events/198",
55
"is-auth-enabled": true
66
}

Diff for: android/app/src/main/java/org/fossasia/openevent/common/api/processor/EventListResponseProcessor.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected void onSuccess(Event event) {
3636
download.downloadMicrolocations();
3737
download.downloadSponsors();
3838
download.downloadSessionTypes();
39+
download.downloadDiscountCodes();
3940
}
4041

4142
@Override

Diff for: android/app/src/main/java/org/fossasia/openevent/core/about/AboutFragment.java

+35
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
import org.fossasia.openevent.common.utils.Utils;
4949
import org.fossasia.openevent.core.bookmark.BookmarkStatus;
5050
import org.fossasia.openevent.core.bookmark.OnBookmarkSelectedListener;
51+
import org.fossasia.openevent.core.discount.DiscountCodesListAdapter;
5152
import org.fossasia.openevent.core.main.MainActivity;
5253
import org.fossasia.openevent.core.search.GlobalSearchAdapter;
5354
import org.fossasia.openevent.core.search.SearchActivity;
5455
import org.fossasia.openevent.core.track.session.SessionSpeakerListAdapter;
56+
import org.fossasia.openevent.data.DiscountCode;
5557
import org.fossasia.openevent.data.Event;
5658
import org.fossasia.openevent.data.Speaker;
5759
import org.fossasia.openevent.data.extras.Copyright;
@@ -104,16 +106,22 @@ public class AboutFragment extends BaseFragment implements OnBookmarkSelectedLis
104106
protected RecyclerView featuresSpeakersRecyclerView;
105107
@BindView(R.id.logo)
106108
protected ImageView eventLogo;
109+
@BindView(R.id.discount_code_header)
110+
protected TextView discountCodeHeader;
111+
@BindView(R.id.list_discount_codes)
112+
protected RecyclerView discountCodesRecyclerView;
107113

108114
private Context context;
109115
private View root;
110116
private GlobalSearchAdapter bookMarksListAdapter;
111117
private SocialLinksListAdapter socialLinksListAdapter;
112118
private SessionSpeakerListAdapter featuredSpeakersListAdapter;
119+
private DiscountCodesListAdapter discountCodeListAdapter;
113120

114121
private final List<Object> sessions = new ArrayList<>();
115122
private final List<SocialLink> socialLinks = new ArrayList<>();
116123
private final List<Speaker> featuredSpeakers = new ArrayList<>();
124+
private final List<DiscountCode> discountCodes = new ArrayList<>();
117125
private static final String MAP_FRAGMENT_TAG = "mapFragment";
118126

119127
private Event event;
@@ -134,6 +142,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
134142
setUpBookmarksRecyclerView();
135143
setUpSocialLinksRecyclerView();
136144
setUpFeaturedSpeakersRecyclerView();
145+
setUpDiscountCodesRecyclerView();
137146

138147
eventLoc.setOnClickListener(v -> {
139148
if (event.isValid()) {
@@ -216,6 +225,16 @@ private void setUpFeaturedSpeakersRecyclerView() {
216225
featuresSpeakersRecyclerView.setItemAnimator(new DefaultItemAnimator());
217226
}
218227

228+
private void setUpDiscountCodesRecyclerView() {
229+
discountCodesRecyclerView.setVisibility(View.VISIBLE);
230+
discountCodeListAdapter = new DiscountCodesListAdapter(discountCodes);
231+
discountCodesRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(),
232+
LinearLayoutManager.HORIZONTAL, false));
233+
discountCodesRecyclerView.setNestedScrollingEnabled(false);
234+
discountCodesRecyclerView.setAdapter(discountCodeListAdapter);
235+
discountCodesRecyclerView.setItemAnimator(new DefaultItemAnimator());
236+
}
237+
219238
private void loadEvent(Event event) {
220239
if (event == null || !event.isValid())
221240
return;
@@ -419,6 +438,14 @@ private void handleVisibility() {
419438
featuredSpeakersHeader.setVisibility(View.GONE);
420439
featuresSpeakersRecyclerView.setVisibility(View.GONE);
421440
}
441+
442+
if (!discountCodes.isEmpty()) {
443+
discountCodeHeader.setVisibility(View.VISIBLE);
444+
discountCodesRecyclerView.setVisibility(View.VISIBLE);
445+
} else {
446+
discountCodeHeader.setVisibility(View.GONE);
447+
discountCodesRecyclerView.setVisibility(View.GONE);
448+
}
422449
}
423450

424451
private void loadData() {
@@ -437,6 +464,14 @@ private void loadData() {
437464
featuredSpeakersListAdapter.notifyDataSetChanged();
438465
handleVisibility();
439466
});
467+
468+
aboutFragmentViewModel.getDiscountCodes().observe(this, discountCodes -> {
469+
this.discountCodes.clear();
470+
this.discountCodes.addAll(discountCodes);
471+
discountCodeListAdapter.notifyDataSetChanged();
472+
handleVisibility();
473+
Timber.d("Discount Codes are + "+discountCodes.size());
474+
});
440475
}
441476

442477
@Override

Diff for: android/app/src/main/java/org/fossasia/openevent/core/about/AboutFragmentViewModel.java

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.fossasia.openevent.OpenEventApp;
1515
import org.fossasia.openevent.common.arch.LiveRealmData;
1616
import org.fossasia.openevent.common.date.DateConverter;
17+
import org.fossasia.openevent.data.DiscountCode;
1718
import org.fossasia.openevent.data.Event;
1819
import org.fossasia.openevent.data.Session;
1920
import org.fossasia.openevent.data.Speaker;
@@ -33,6 +34,7 @@ public class AboutFragmentViewModel extends ViewModel {
3334
private List<String> dateList;
3435
private LiveData<Event> eventLiveData;
3536
private LiveData<List<Speaker>> featuredSpeakers;
37+
private LiveData<List<DiscountCode>> discountCodes;
3638
private MutableLiveData<Bitmap> eventLogo;
3739

3840
public AboutFragmentViewModel() {
@@ -96,6 +98,15 @@ public LiveData<List<Speaker>> getFeaturedSpeakers() {
9698
return featuredSpeakers;
9799
}
98100

101+
public LiveData<List<DiscountCode>> getDiscountCodes() {
102+
if (discountCodes == null) {
103+
LiveRealmData<DiscountCode> discountCodeLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getDiscountCodes());
104+
discountCodes = Transformations.map(discountCodeLiveRealmData, input -> input);
105+
}
106+
return discountCodes;
107+
}
108+
109+
99110
public LiveData<Bitmap> getEventLogo(String url) {
100111
if (eventLogo == null) {
101112
eventLogo = new MutableLiveData<>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.fossasia.openevent.core.discount;
2+
3+
import android.view.LayoutInflater;
4+
import android.view.View;
5+
import android.view.ViewGroup;
6+
7+
import org.fossasia.openevent.R;
8+
import org.fossasia.openevent.common.ui.base.BaseRVAdapter;
9+
import org.fossasia.openevent.data.DiscountCode;
10+
11+
import java.util.List;
12+
13+
public class DiscountCodesListAdapter extends BaseRVAdapter<DiscountCode, DiscountViewHolder> {
14+
15+
public DiscountCodesListAdapter(List<DiscountCode> discountCodes) {
16+
super(discountCodes);
17+
}
18+
19+
@Override
20+
public DiscountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
21+
View view = LayoutInflater.from(parent.getContext())
22+
.inflate(R.layout.item_discount_code, parent, false);
23+
return new DiscountViewHolder(view, parent.getContext());
24+
}
25+
26+
public void onBindViewHolder(DiscountViewHolder holder, int position) {
27+
holder.bindDiscountCode(getItem(position));
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.fossasia.openevent.core.discount;
2+
3+
import android.content.Context;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.text.TextUtils;
7+
import android.view.View;
8+
import android.widget.LinearLayout;
9+
import android.widget.TextView;
10+
11+
import org.fossasia.openevent.R;
12+
import org.fossasia.openevent.common.utils.Utils;
13+
import org.fossasia.openevent.data.DiscountCode;
14+
15+
import butterknife.BindView;
16+
import butterknife.ButterKnife;
17+
18+
public class DiscountViewHolder extends RecyclerView.ViewHolder {
19+
20+
@BindView(R.id.discount_code)
21+
protected TextView discountCodeTextView;
22+
23+
@BindView(R.id.discount_code_value)
24+
protected TextView discountCodeValue;
25+
26+
@BindView(R.id.discount_code_type)
27+
protected TextView discountCodeType;
28+
29+
@Nullable
30+
@BindView(R.id.linear_layout_discount_code_list_info)
31+
protected LinearLayout discountTextualInfo;
32+
33+
private DiscountCode discountCode;
34+
private Context context;
35+
36+
private boolean isImageCircle = true;
37+
38+
public DiscountViewHolder(View itemView, Context context) {
39+
super(itemView);
40+
ButterKnife.bind(this, itemView);
41+
42+
this.context = context;
43+
44+
}
45+
46+
public void bindDiscountCode(DiscountCode discountCode) {
47+
this.discountCode = discountCode;
48+
49+
String code = Utils.checkStringEmpty(discountCode.getCode());
50+
String type = Utils.checkStringEmpty(discountCode.getType());
51+
float value = discountCode.getValue();
52+
53+
54+
setStringField(discountCodeTextView, code);
55+
setStringField(discountCodeType, type);
56+
setStringField(discountCodeValue, "Value:"+value);
57+
}
58+
59+
private void setStringField(TextView textView, String field) {
60+
if (textView == null)
61+
return;
62+
63+
if (!TextUtils.isEmpty(field.trim())) {
64+
textView.setVisibility(View.VISIBLE);
65+
textView.setText(field);
66+
} else {
67+
textView.setVisibility(View.GONE);
68+
}
69+
}
70+
}

Diff for: android/app/src/main/res/layout/content_about_event.xml

+18
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@
222222
android:clipToPadding="false"
223223
tools:listitem="@layout/item_speaker"/>
224224

225+
<TextView
226+
android:id="@+id/discount_code_header"
227+
android:layout_width="match_parent"
228+
android:layout_height="wrap_content"
229+
android:background="@color/color_accent"
230+
android:padding="@dimen/padding_medium"
231+
android:text="Available Discount Codes"
232+
android:textColor="@color/card_title"
233+
android:textSize="@dimen/text_size_extra_large"
234+
android:textStyle="bold" />
235+
236+
<android.support.v7.widget.RecyclerView
237+
android:id="@+id/list_discount_codes"
238+
android:layout_width="match_parent"
239+
android:layout_height="wrap_content"
240+
android:clipToPadding="false"
241+
tools:listitem="@layout/item_discount_code"/>
242+
225243
<LinearLayout
226244
android:id="@+id/images"
227245
android:layout_width="match_parent"
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:background="#ffffff"
8+
android:foreground="?android:attr/selectableItemBackground"
9+
tools:layout_width="@dimen/widget_default_height">
10+
11+
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_margin="@dimen/layout_margin_medium"
15+
card_view:cardCornerRadius="2dp"
16+
card_view:cardElevation="2dp">
17+
18+
<LinearLayout
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:orientation="vertical">
22+
23+
<LinearLayout
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_gravity="bottom"
27+
android:alpha="0.8"
28+
android:background="?colorPrimaryDark"
29+
android:orientation="vertical"
30+
android:padding="@dimen/padding_extra_small"
31+
android:id="@+id/linear_layout_discount_code_list_info">
32+
33+
<TextView
34+
android:id="@+id/discount_code"
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content"
37+
android:gravity="center"
38+
android:maxLines="2"
39+
android:textColor="@android:color/white"
40+
android:textSize="@dimen/text_size_large"
41+
android:textStyle="bold"
42+
tools:ignore="SpUsage"
43+
tools:text="DiscountCode" />
44+
45+
<TextView
46+
android:id="@+id/discount_code_value"
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:gravity="center"
50+
android:maxLines="2"
51+
android:textColor="@android:color/white"
52+
android:textSize="@dimen/text_size_medium"
53+
tools:ignore="SpUsage"
54+
tools:text="Value" />
55+
56+
<TextView
57+
android:id="@+id/discount_code_type"
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
android:gravity="center"
61+
android:maxLines="2"
62+
android:textColor="@android:color/white"
63+
android:textSize="@dimen/text_size_medium"
64+
tools:ignore="SpUsage"
65+
tools:text="Type" />
66+
67+
</LinearLayout>
68+
</LinearLayout>
69+
</android.support.v7.widget.CardView>
70+
71+
</FrameLayout>

0 commit comments

Comments
 (0)