Panagiotis Triantafyllou

questionnaire part1

......@@ -221,8 +221,8 @@ public class SingleCouponActivity extends Activity implements View.OnClickListen
.into(mIvImage);
}
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getMerchantAdminName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getMerchantAdminName()))
mTvMerchantName.setText(mOfferItem.getCouponsetDetails().getMerchantAdminName());
if (mOfferItem.getMerchantDetails() != null && mOfferItem.getMerchantDetails().getName() != null && !TextUtils.isEmpty(mOfferItem.getMerchantDetails().getName()))
mTvMerchantName.setText(mOfferItem.getMerchantDetails().getName());
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getName() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getName()))
mTvValue.setText(mOfferItem.getCouponsetDetails().getName());
if (mOfferItem.getCouponsetDetails() != null && mOfferItem.getCouponsetDetails().getShort_description() != null && !TextUtils.isEmpty(mOfferItem.getCouponsetDetails().getShort_description()))
......
......@@ -170,7 +170,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
llDateExpired.setVisibility(View.GONE);
}
tvMerchant.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getMerchantAdminName()) ? couponItem.getCouponsetDetails().getMerchantAdminName().trim() : "");
tvMerchant.setText(!TextUtils.isEmpty(couponItem.getMerchantDetails().getName()) ? couponItem.getMerchantDetails().getName().trim() : "");
tvTitle.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getName()) ? couponItem.getCouponsetDetails().getName().trim() : "");
tvDescription.setText(!TextUtils.isEmpty(couponItem.getCouponsetDetails().getShort_description()) ? couponItem.getCouponsetDetails().getShort_description().trim() : "");
if (couponItem.getExpiration() != null && !couponItem.getExpiration().isEmpty()) {
......
......@@ -71,7 +71,7 @@ public class User implements Parcelable, Serializable {
private boolean isEligible = false;
private String msisdn;
private String profileMetadata;
private JSONObject questionnaire;
private Questionnaire questionnaire;
private JSONObject questionnaireAnswers;
private JSONObject userAnswers;
private String userId;
......@@ -127,7 +127,7 @@ public class User implements Parcelable, Serializable {
this.isEligible = json.optBoolean(IS_ELIGIBLE);
this.msisdn = optNullableString(json, MSISDN);
this.profileMetadata = optNullableString(json, PROFILE_METADATA);
this.questionnaire = json.optJSONObject(QUESTIONNAIRE);
this.questionnaire = json.isNull(QUESTIONNAIRE) ? null : new Questionnaire(json.optJSONObject(QUESTIONNAIRE));
this.questionnaireAnswers = json.optJSONObject(QUESTIONNAIRE_ANSWERS);
this.userAnswers = json.optJSONObject(USER_ANSWERS);
this.userId = optNullableString(json, USER_ID);
......@@ -158,7 +158,7 @@ public class User implements Parcelable, Serializable {
}
try {
String questionnaireStr = source.readString();
this.questionnaire = questionnaireStr != null ? new JSONObject(questionnaireStr) : null;
this.questionnaire = questionnaireStr != null ? new Questionnaire(new JSONObject(questionnaireStr)) : null;
} catch (JSONException e) {
this.questionnaire = null;
}
......@@ -214,7 +214,7 @@ public class User implements Parcelable, Serializable {
jObj.putOpt(IS_ELIGIBLE, this.isEligible);
jObj.put(MSISDN, this.msisdn != null ? this.msisdn : JSONObject.NULL);
jObj.put(PROFILE_METADATA, this.profileMetadata != null ? this.profileMetadata : JSONObject.NULL);
jObj.put(QUESTIONNAIRE, this.questionnaire != null ? this.questionnaire : JSONObject.NULL);
jObj.put(QUESTIONNAIRE, this.questionnaire != null ? this.questionnaire.toJSONObject() : JSONObject.NULL);
jObj.put(QUESTIONNAIRE_ANSWERS, this.questionnaireAnswers != null ? this.questionnaireAnswers : JSONObject.NULL);
jObj.put(USER_ANSWERS, this.userAnswers != null ? this.userAnswers : JSONObject.NULL);
jObj.put(USER_ID, this.userId != null ? this.userId : JSONObject.NULL);
......@@ -308,7 +308,7 @@ public class User implements Parcelable, Serializable {
return profileMetadata;
}
public JSONObject getQuestionnaire() {
public Questionnaire getQuestionnaire() {
return questionnaire;
}
......@@ -368,7 +368,7 @@ public class User implements Parcelable, Serializable {
this.profileMetadata = profileMetadata;
}
public void setQuestionnaire(JSONObject questionnaire) {
public void setQuestionnaire(Questionnaire questionnaire) {
this.questionnaire = questionnaire;
}
......@@ -416,4 +416,190 @@ public class User implements Parcelable, Serializable {
}
return listData;
}
public static class Questionnaire implements Parcelable, Serializable {
private String questionnaireId;
private ArrayList<Question> questions;
public Questionnaire() {
this.questionnaireId = null;
this.questions = new ArrayList<>();
}
public Questionnaire(JSONObject json) {
if (json != null) {
this.questionnaireId = json.isNull("questionnaire_id") ? null : json.optString("questionnaire_id");
this.questions = new ArrayList<>();
JSONArray questionsArr = json.optJSONArray("questions");
if (questionsArr != null) {
for (int i = 0; i < questionsArr.length(); i++) {
JSONObject qJson = questionsArr.optJSONObject(i);
if (qJson != null) {
this.questions.add(new Question(qJson));
}
}
}
}
}
protected Questionnaire(Parcel in) {
questionnaireId = in.readString();
questions = in.createTypedArrayList(Question.CREATOR);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(questionnaireId);
dest.writeTypedList(questions);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Questionnaire> CREATOR = new Creator<Questionnaire>() {
@Override
public Questionnaire createFromParcel(Parcel in) {
return new Questionnaire(in);
}
@Override
public Questionnaire[] newArray(int size) {
return new Questionnaire[size];
}
};
public JSONObject toJSONObject() {
JSONObject jObj = new JSONObject();
try {
jObj.put("questionnaire_id", this.questionnaireId != null ? this.questionnaireId : JSONObject.NULL);
JSONArray qArr = new JSONArray();
if (this.questions != null) {
for (Question q : this.questions) {
qArr.put(q.toJSONObject());
}
}
jObj.put("questions", qArr);
} catch (JSONException e) {
if (WarpConstants.DEBUG) e.printStackTrace();
}
return jObj;
}
public String getQuestionnaireId() { return questionnaireId; }
public void setQuestionnaireId(String questionnaireId) { this.questionnaireId = questionnaireId; }
public ArrayList<Question> getQuestions() { return questions; }
public void setQuestions(ArrayList<Question> questions) { this.questions = questions; }
}
public static class Question implements Parcelable, Serializable {
private String adminName;
private int id;
private JSONArray options;
private String question;
private JSONObject settings;
private int sorting;
private String type;
private int version;
public Question() {}
public Question(JSONObject json) {
if (json != null) {
this.adminName = json.isNull("admin_name") ? null : json.optString("admin_name");
this.id = json.optInt("id", -1);
this.options = json.optJSONArray("options");
this.question = json.isNull("question") ? null : json.optString("question");
this.settings = json.optJSONObject("settings");
this.sorting = json.optInt("sorting", 0);
this.type = json.isNull("type") ? null : json.optString("type");
this.version = json.optInt("version", 0);
}
}
protected Question(Parcel in) {
adminName = in.readString();
id = in.readInt();
try {
String optionsStr = in.readString();
options = optionsStr != null ? new JSONArray(optionsStr) : null;
} catch (JSONException e) {
options = null;
}
question = in.readString();
try {
String settingsStr = in.readString();
settings = settingsStr != null ? new JSONObject(settingsStr) : null;
} catch (JSONException e) {
settings = null;
}
sorting = in.readInt();
type = in.readString();
version = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(adminName);
dest.writeInt(id);
dest.writeString(options != null ? options.toString() : null);
dest.writeString(question);
dest.writeString(settings != null ? settings.toString() : null);
dest.writeInt(sorting);
dest.writeString(type);
dest.writeInt(version);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Question> CREATOR = new Creator<Question>() {
@Override
public Question createFromParcel(Parcel in) {
return new Question(in);
}
@Override
public Question[] newArray(int size) {
return new Question[size];
}
};
public JSONObject toJSONObject() {
JSONObject jObj = new JSONObject();
try {
jObj.put("admin_name", this.adminName != null ? this.adminName : JSONObject.NULL);
jObj.put("id", this.id);
jObj.put("options", this.options != null ? this.options : JSONObject.NULL);
jObj.put("question", this.question != null ? this.question : JSONObject.NULL);
jObj.put("settings", this.settings != null ? this.settings : JSONObject.NULL);
jObj.put("sorting", this.sorting);
jObj.put("type", this.type != null ? this.type : JSONObject.NULL);
jObj.put("version", this.version);
} catch (JSONException e) {
if (WarpConstants.DEBUG) e.printStackTrace();
}
return jObj;
}
public String getAdminName() { return adminName; }
public void setAdminName(String adminName) { this.adminName = adminName; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public JSONArray getOptions() { return options; }
public void setOptions(JSONArray options) { this.options = options; }
public String getQuestion() { return question; }
public void setQuestion(String question) { this.question = question; }
public JSONObject getSettings() { return settings; }
public void setSettings(JSONObject settings) { this.settings = settings; }
public int getSorting() { return sorting; }
public void setSorting(int sorting) { this.sorting = sorting; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public int getVersion() { return version; }
public void setVersion(int version) { this.version = version; }
}
}
......
......@@ -192,6 +192,18 @@ public interface ApiService {
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getQuestionnaire(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
// ===========================================================
// Getter & Setter
// ===========================================================
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="14dp" />
<solid android:color="@color/white" />
<stroke android:width="2dp" android:color="@color/custom_black7" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="14dp" />
<solid android:color="@color/white" />
<stroke android:width="1dp" android:color="@color/custom_grey7" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<LinearLayout
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_back"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginEnd="24dp"
android:src="@drawable/ic_back" />
</LinearLayout>
<TextView
android:id="@+id/tv_question_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/custom_black4"
android:textSize="18sp"
tools:text="1/7" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="@id/ll_next_container"
app:layout_constraintTop_toBottomOf="@id/header_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="16dp"
android:paddingBottom="32dp">
<TextView
android:id="@+id/tv_question_header_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="@string/demo_questionnaire_title"
android:textColor="@color/custom_black4"
android:textSize="22sp" />
<TextView
android:id="@+id/tv_question_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:textColor="@color/custom_black4"
android:textSize="18sp"
android:layout_marginTop="40dp"
tools:text="Question Title?" />
<TextView
android:id="@+id/tv_question_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:textColor="@color/custom_black2"
android:textSize="14sp"
android:layout_marginTop="8dp"
android:text="@string/demo_questionnaire_subtitle"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/ll_options_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/ll_next_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:id="@+id/ll_next_button"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@drawable/shape_rectangle_rounded_light_blue_tr"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="Next"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -42,7 +42,8 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:id="@+id/ll_filter_container"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_option_container"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginBottom="8dp"
android:background="@drawable/shape_questionnaire_option_unselected"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_option_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
tools:text="Option Title"
android:textColor="@color/black"
android:textSize="15sp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_option_separator"
android:layout_width="match_parent"
android:layout_height="8dp"
android:orientation="horizontal">
</LinearLayout>
\ No newline at end of file
......@@ -8,6 +8,7 @@
<color name="custom_orange">#FF9933</color>
<color name="custom_skyblue2">#22A9B5</color>
<color name="custom_blue_dark">#3A5266</color>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
<color name="white_tr">#66FFFFFF</color>
<color name="custom_green5">#79BF14</color>
......
......@@ -43,4 +43,7 @@
<string name="demo_search_title">Αναζήτηση</string>
<string name="lbl_directions">Οδηγίες</string>
<string name="lbl_top_offers">Top offers</string>
<string name="demo_questionnaire_title">Questionnaire</string>
<string name="demo_questionnaire_subtitle">(You can select more than one answer)</string>
<string name="demo_region_title">Region</string>
</resources>
......