Panagiotis Triantafyllou

questionnaire part2

...@@ -10,13 +10,18 @@ import android.util.TypedValue; ...@@ -10,13 +10,18 @@ import android.util.TypedValue;
10 import android.view.LayoutInflater; 10 import android.view.LayoutInflater;
11 import android.view.View; 11 import android.view.View;
12 import android.view.ViewGroup; 12 import android.view.ViewGroup;
13 +import android.widget.AdapterView;
14 +import android.widget.ArrayAdapter;
13 import android.widget.ImageView; 15 import android.widget.ImageView;
14 import android.widget.LinearLayout; 16 import android.widget.LinearLayout;
17 +import android.widget.ListPopupWindow;
15 import android.widget.RelativeLayout; 18 import android.widget.RelativeLayout;
19 +import android.widget.Spinner;
16 import android.widget.TextView; 20 import android.widget.TextView;
17 import android.widget.Toast; 21 import android.widget.Toast;
18 22
19 import androidx.appcompat.content.res.AppCompatResources; 23 import androidx.appcompat.content.res.AppCompatResources;
24 +import androidx.appcompat.widget.AppCompatSpinner;
20 import androidx.constraintlayout.widget.ConstraintLayout; 25 import androidx.constraintlayout.widget.ConstraintLayout;
21 import androidx.recyclerview.widget.LinearLayoutManager; 26 import androidx.recyclerview.widget.LinearLayoutManager;
22 import androidx.recyclerview.widget.RecyclerView; 27 import androidx.recyclerview.widget.RecyclerView;
...@@ -77,7 +82,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -77,7 +82,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
77 private ConstraintLayout mViewPager; 82 private ConstraintLayout mViewPager;
78 private LinearLayout mSectionsContainer; 83 private LinearLayout mSectionsContainer;
79 private RelativeLayout mSectionsLoading; 84 private RelativeLayout mSectionsLoading;
80 - private int mCurrentQuestionIndex = 1; 85 + private int mCurrentQuestionIndex = 0;
81 private SettableFuture<ArrayList<CarouselItem>> carouselFuture = SettableFuture.create(); 86 private SettableFuture<ArrayList<CarouselItem>> carouselFuture = SettableFuture.create();
82 private SettableFuture<LinkedHashMap<String, ArrayList<Couponset>>> couponsetsFuture = SettableFuture.create(); 87 private SettableFuture<LinkedHashMap<String, ArrayList<Couponset>>> couponsetsFuture = SettableFuture.create();
83 88
...@@ -548,7 +553,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -548,7 +553,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
548 ImageView ivClose = dialogView.findViewById(R.id.iv_back); 553 ImageView ivClose = dialogView.findViewById(R.id.iv_back);
549 ivClose.setOnClickListener(v -> bottomSheetDialog.dismiss()); 554 ivClose.setOnClickListener(v -> bottomSheetDialog.dismiss());
550 555
551 - mCurrentQuestionIndex = 1; 556 + mCurrentQuestionIndex = 0;
552 renderQuestion(questionnaire, dialogView, bottomSheetDialog); 557 renderQuestion(questionnaire, dialogView, bottomSheetDialog);
553 558
554 bottomSheetDialog.setOnShowListener(dialog -> { 559 bottomSheetDialog.setOnShowListener(dialog -> {
...@@ -576,7 +581,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -576,7 +581,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
576 } 581 }
577 582
578 TextView tvQuestionCount = dialogView.findViewById(R.id.tv_question_count); 583 TextView tvQuestionCount = dialogView.findViewById(R.id.tv_question_count);
579 - tvQuestionCount.setText(String.valueOf(mCurrentQuestionIndex) + "/" + String.valueOf(questionnaire.getQuestions().size()-1)); 584 + tvQuestionCount.setText(String.valueOf(mCurrentQuestionIndex + 1) + "/" + String.valueOf(questionnaire.getQuestions().size()));
580 585
581 TextView tvQuestionHeaderTitle = dialogView.findViewById(R.id.tv_question_header_title); 586 TextView tvQuestionHeaderTitle = dialogView.findViewById(R.id.tv_question_header_title);
582 TextView tvQuestionHeaderSubtitle = dialogView.findViewById(R.id.tv_question_subtitle); 587 TextView tvQuestionHeaderSubtitle = dialogView.findViewById(R.id.tv_question_subtitle);
...@@ -600,54 +605,163 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -600,54 +605,163 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
600 605
601 if ("select".equals(type)) { 606 if ("select".equals(type)) {
602 tvQuestionHeaderSubtitle.setVisibility(View.GONE); 607 tvQuestionHeaderSubtitle.setVisibility(View.GONE);
603 - View dropdownHeader = LayoutInflater.from(this).inflate(R.layout.item_questionnaire_option, llOptionsContainer, false); 608 +
604 - LinearLayout llDropdownContainer = dropdownHeader.findViewById(R.id.ll_option_container); 609 + View dropdownHeader = LayoutInflater.from(this).inflate(R.layout.item_questionnaire_list_header, llOptionsContainer, false);
605 - TextView tvDropdownTitle = dropdownHeader.findViewById(R.id.tv_option_title); 610 + TextView tvDropdownTitle = dropdownHeader.findViewById(R.id.tv_dropdown_option_header);
606 - String optionHeaderText = options.optString(0); 611 + ImageView ivArrow = dropdownHeader.findViewById(R.id.iv_terms_arrow);
612 +
613 + String optionHeaderText = options != null && options.length() > 0 ? options.optString(0) : "Επιλέξτε";
607 tvDropdownTitle.setText(optionHeaderText); 614 tvDropdownTitle.setText(optionHeaderText);
608 WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvDropdownTitle); 615 WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvDropdownTitle);
609 - llDropdownContainer.setBackground(AppCompatResources.getDrawable(this, R.drawable.shape_questionnaire_option_unselected));
610 - tvDropdownTitle.setTextColor(getColor(R.color.custom_black2));
611 616
612 - LinearLayout llDropdownList = new LinearLayout(this); 617 + llOptionsContainer.addView(dropdownHeader);
613 - llDropdownList.setOrientation(LinearLayout.VERTICAL);
614 - llDropdownList.setVisibility(View.GONE);
615 618
619 + List<String> popupOptions = new ArrayList<>();
616 if (options != null) { 620 if (options != null) {
617 - for (int i = 1; i < options.length(); i++) { 621 + for (int i = 0; i < options.length(); i++) {
618 - final int position = i; 622 + popupOptions.add(options.optString(i));
619 - String optionText = options.optString(i); 623 + }
620 - View optionView = LayoutInflater.from(this).inflate(R.layout.item_questionnaire_option, llDropdownList, false); 624 + }
621 - TextView tvOptionTitle = optionView.findViewById(R.id.tv_option_title);
622 - tvOptionTitle.setText(optionText);
623 - WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvOptionTitle);
624 - tvOptionTitle.setTextColor(getColor(R.color.custom_grey3));
625 625
626 - optionView.setOnClickListener(v -> { 626 + ArrayAdapter<String> adapter = new ArrayAdapter<String>(
627 + this,
628 + R.layout.item_questionnaire_list_option,
629 + popupOptions
630 + ) {
631 + @Override
632 + public View getView(int position, View convertView, ViewGroup parent) {
633 + if (convertView == null) {
634 + convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_questionnaire_list_option, parent, false);
635 + }
636 + TextView tvOption = convertView.findViewById(R.id.tv_dropdown_option_title);
637 + if (tvOption != null) {
638 + tvOption.setText(getItem(position));
639 + WarpUtils.renderCustomFont(HomeActivity.this, R.font.ping_lcg_regular, tvOption);
640 + }
641 + return convertView;
642 + }
643 + };
644 +
645 + ListPopupWindow listPopupWindow = new ListPopupWindow(this);
646 + listPopupWindow.setAdapter(adapter);
647 + listPopupWindow.setAnchorView(dropdownHeader);
648 + listPopupWindow.setModal(true);
649 + listPopupWindow.setHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55 * 5, getResources().getDisplayMetrics()));
650 +
651 + dropdownHeader.setOnClickListener(v -> {
652 + ivArrow.animate().rotation(180f).setDuration(200).start();
653 + listPopupWindow.setWidth(dropdownHeader.getWidth());
654 + listPopupWindow.show();
655 + });
656 +
657 + listPopupWindow.setOnDismissListener(() -> {
658 + ivArrow.animate().rotation(0f).setDuration(200).start();
659 + });
660 +
661 + listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
627 selectedPositions.clear(); 662 selectedPositions.clear();
628 selectedPositions.add(position); 663 selectedPositions.add(position);
629 - tvDropdownTitle.setText(optionText); 664 + tvDropdownTitle.setText(popupOptions.get(position));
630 - llDropdownList.setVisibility(View.GONE); 665 + listPopupWindow.dismiss();
631 - llDropdownContainer.setBackground(AppCompatResources.getDrawable(this, R.drawable.shape_questionnaire_option_selected));
632 - tvDropdownTitle.setTextColor(getColor(R.color.black));
633 }); 666 });
634 - llDropdownList.addView(optionView); 667 +
668 + } else if ("custom1".equals(type)) {
669 + String[] headers = {"Ενήλικες", "Παιδιά έως 9 ετών", "Παιδιά 10-18 ετών"};
670 +
671 + if (options != null) {
672 + for (int i = 0; i < options.length(); i++) {
673 + Object outerItem = options.opt(i);
674 + if (!(outerItem instanceof JSONArray)) continue;
675 +
676 + JSONArray innerList = (JSONArray) outerItem;
677 + List<String> popupOptions = new ArrayList<>();
678 + for (int j = 0; j < innerList.length(); j++) {
679 + popupOptions.add(innerList.optString(j));
635 } 680 }
681 +
682 + // 1. Inflate header container
683 + View customContainer = LayoutInflater.from(this).inflate(R.layout.item_questionnaire_list_custom, llOptionsContainer, false);
684 + LinearLayout llCustomContainer = customContainer.findViewById(R.id.ll_option_container);
685 + TextView tvHeaderTitle = customContainer.findViewById(R.id.tv_dropdown_option_header);
686 +
687 + // 2. Set header text and font
688 + if (i < headers.length) {
689 + tvHeaderTitle.setText(headers[i]);
636 } 690 }
691 + WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvHeaderTitle);
692 +
693 + // 3. Inflate dropdown button and add it inside the custom container
694 + View dropdownHeader = LayoutInflater.from(this).inflate(R.layout.item_questionnaire_list_header, llCustomContainer, false);
695 + TextView tvDropdownTitle = dropdownHeader.findViewById(R.id.tv_dropdown_option_header);
696 + ImageView ivArrow = dropdownHeader.findViewById(R.id.iv_terms_arrow);
697 +
698 + LinearLayout.LayoutParams dropdownParams = new LinearLayout.LayoutParams(
699 + LinearLayout.LayoutParams.MATCH_PARENT,
700 + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, getResources().getDisplayMetrics())
701 + );
702 + dropdownHeader.setLayoutParams(dropdownParams);
703 +
704 + tvDropdownTitle.setText("Επιλέξτε");
705 + WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvDropdownTitle);
706 +
707 + llCustomContainer.addView(dropdownHeader);
708 +
709 + // 4. Create ArrayAdapter for popup rows
710 + ArrayAdapter<String> adapter = new ArrayAdapter<String>(
711 + this,
712 + R.layout.item_questionnaire_list_option,
713 + popupOptions
714 + ) {
715 + @Override
716 + public View getView(int position, View convertView, ViewGroup parent) {
717 + if (convertView == null) {
718 + convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_questionnaire_list_option, parent, false);
719 + }
720 + TextView tvOption = convertView.findViewById(R.id.tv_dropdown_option_title);
721 + if (tvOption != null) {
722 + tvOption.setText(getItem(position));
723 + WarpUtils.renderCustomFont(HomeActivity.this, R.font.ping_lcg_regular, tvOption);
724 + }
725 + return convertView;
726 + }
727 + };
728 +
729 + // 5. Create ListPopupWindow
730 + ListPopupWindow listPopupWindow = new ListPopupWindow(this);
731 + listPopupWindow.setAdapter(adapter);
732 + listPopupWindow.setAnchorView(dropdownHeader);
733 + listPopupWindow.setModal(true);
734 + listPopupWindow.setHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, getResources().getDisplayMetrics()));
637 735
638 dropdownHeader.setOnClickListener(v -> { 736 dropdownHeader.setOnClickListener(v -> {
639 - boolean isExpanded = llDropdownList.getVisibility() == View.VISIBLE; 737 + ivArrow.animate().rotation(180f).setDuration(200).start();
640 - llDropdownList.setVisibility(isExpanded ? View.GONE : View.VISIBLE); 738 + listPopupWindow.setWidth(dropdownHeader.getWidth());
739 + listPopupWindow.show();
641 }); 740 });
642 741
643 - llOptionsContainer.addView(dropdownHeader); 742 + listPopupWindow.setOnDismissListener(() -> {
644 - llOptionsContainer.addView(llDropdownList); 743 + ivArrow.animate().rotation(0f).setDuration(200).start();
645 - } else { 744 + });
745 +
746 + final int headerIndex = i;
747 + listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
748 + selectedPositions.clear();
749 + selectedPositions.add(headerIndex * 100 + position);
750 + tvDropdownTitle.setText(popupOptions.get(position));
751 + listPopupWindow.dismiss();
752 + });
753 +
754 + llOptionsContainer.addView(customContainer);
755 + }
756 + }
757 +
758 + } else if ("multi".equals(type) || "string".equals(type)) {
646 if ("string".equals(type)) { 759 if ("string".equals(type)) {
647 tvQuestionHeaderSubtitle.setVisibility(View.GONE); 760 tvQuestionHeaderSubtitle.setVisibility(View.GONE);
648 } else if ("multi".equals(type)) { 761 } else if ("multi".equals(type)) {
649 tvQuestionHeaderSubtitle.setVisibility(View.VISIBLE); 762 tvQuestionHeaderSubtitle.setVisibility(View.VISIBLE);
650 } 763 }
764 +
651 if (options != null) { 765 if (options != null) {
652 for (int i = 0; i < options.length(); i++) { 766 for (int i = 0; i < options.length(); i++) {
653 final int position = i; 767 final int position = i;
......
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="14dp" />
5 +
6 + <solid android:color="@color/white" />
7 +</shape>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:tools="http://schemas.android.com/tools"
4 + android:id="@+id/ll_option_container"
5 + android:layout_width="match_parent"
6 + android:layout_height="wrap_content"
7 + android:background="@color/white"
8 + android:gravity="center_vertical"
9 + android:orientation="vertical"
10 + android:layout_marginTop="40dp">
11 +
12 + <TextView
13 + android:id="@+id/tv_dropdown_option_header"
14 + android:layout_width="wrap_content"
15 + android:layout_height="wrap_content"
16 + android:includeFontPadding="false"
17 + android:layout_marginBottom="12dp"
18 + android:paddingHorizontal="16dp"
19 + android:textColor="@color/black"
20 + android:textSize="15sp"
21 + tools:text="Option Title" />
22 +</LinearLayout>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:tools="http://schemas.android.com/tools"
4 + android:id="@+id/ll_option_container"
5 + android:layout_width="match_parent"
6 + android:layout_height="55dp"
7 + android:background="@drawable/shape_questionnaire_option_unselected"
8 + android:gravity="center_vertical"
9 + android:orientation="horizontal"
10 + android:paddingHorizontal="16dp">
11 +
12 + <TextView
13 + android:id="@+id/tv_dropdown_option_header"
14 + android:layout_width="0dp"
15 + android:layout_height="wrap_content"
16 + android:layout_weight="1"
17 + android:includeFontPadding="false"
18 + tools:text="Option Title"
19 + android:textColor="@color/black"
20 + android:textSize="15sp" />
21 +
22 + <ImageView
23 + android:id="@+id/iv_terms_arrow"
24 + android:layout_width="10dp"
25 + android:layout_height="10dp"
26 + android:src="@drawable/ic_arrow_down" />
27 +</LinearLayout>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:tools="http://schemas.android.com/tools"
4 + android:id="@+id/ll_option_container"
5 + android:layout_width="match_parent"
6 + android:layout_height="55dp"
7 + android:layout_marginBottom="8dp"
8 + android:background="@color/white"
9 + android:gravity="center"
10 + android:orientation="horizontal">
11 +
12 + <TextView
13 + android:id="@+id/tv_dropdown_option_title"
14 + android:layout_width="wrap_content"
15 + android:layout_height="wrap_content"
16 + android:includeFontPadding="false"
17 + tools:text="Option Title"
18 + android:textColor="@color/black"
19 + android:textSize="15sp" />
20 +</LinearLayout>
...\ No newline at end of file ...\ No newline at end of file