From ff9b09805edfebe6bf6bcf429d43d44135e1eeac Mon Sep 17 00:00:00 2001 From: MFlisar Date: Tue, 22 May 2018 19:18:40 +0200 Subject: [PATCH] removed viewflipper with manual visibility handling -> dialog resizes itself now --- README.md | 1 - .../gdprdialog/helper/GDPRViewManager.java | 22 +++++++++++-------- library/src/main/res/layout/gdpr_dialog.xml | 11 +++++++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7484671..7337ce5 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,6 @@ Check out the [demo](https://github.com/MFlisar/GDPRDialog/blob/master/app/src/m ### TODO * [ ] better landscape layout -* [ ] resize dialog after each step * [ ] translations * [x] english * [x] german diff --git a/library/src/main/java/com/michaelflisar/gdprdialog/helper/GDPRViewManager.java b/library/src/main/java/com/michaelflisar/gdprdialog/helper/GDPRViewManager.java index 5ef753d..a3df507 100644 --- a/library/src/main/java/com/michaelflisar/gdprdialog/helper/GDPRViewManager.java +++ b/library/src/main/java/com/michaelflisar/gdprdialog/helper/GDPRViewManager.java @@ -10,11 +10,9 @@ import android.view.View; import android.widget.Button; import android.widget.CheckBox; -import android.widget.CompoundButton; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; -import android.widget.ViewFlipper; import com.michaelflisar.gdprdialog.GDPR; import com.michaelflisar.gdprdialog.GDPRConsent; @@ -95,7 +93,11 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene final Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.setVisibility(mSetup.noToolbarTheme() ? View.VISIBLE : View.GONE); toolbar.setTitle(R.string.gdpr_dialog_title); - final ViewFlipper vfFlipper = view.findViewById(R.id.vfFlipper); + final List pages = new ArrayList<>(); + pages.add(view.findViewById(R.id.llPage0)); + pages.add(view.findViewById(R.id.llPage1)); + pages.add(view.findViewById(R.id.llPage2)); + pages.add(view.findViewById(R.id.llPage3)); final Button btDisagree = view.findViewById(R.id.btDisagree); final Button btNoConsentAtAll = view.findViewById(R.id.btNoConsentAtAll); final Button btCloseAfterNoConsentAccepted = view.findViewById(R.id.btCloseAfterNoConsentAccepted); @@ -166,7 +168,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene tvServices.setMovementMethod(LinkMovementMethod.getInstance()); tvTextNonPersonalAccepted.setMovementMethod(LinkMovementMethod.getInstance()); - updateSelectedPage(vfFlipper, view); + updateSelectedPage(pages, view); // ------------------ // Step 0 - Info Page @@ -178,7 +180,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene } mSelectedConsent = GDPRConsent.PERSONAL_CONSENT; mCurrentStep = 1; - updateSelectedPage(vfFlipper, view); + updateSelectedPage(pages, view); }); view.findViewById(R.id.btDisagree).setOnClickListener(v -> { @@ -198,7 +200,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene mSelectedConsent = GDPRConsent.NON_PERSONAL_CONSENT_ONLY; mCurrentStep = 2; } - updateSelectedPage(vfFlipper, view); + updateSelectedPage(pages, view); }); if (!mSetup.allowAnyNoConsent()) { @@ -207,7 +209,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene btNoConsentAtAll.setOnClickListener(v -> { mSelectedConsent = GDPRConsent.NO_CONSENT; mCurrentStep = 3; - updateSelectedPage(vfFlipper, view); + updateSelectedPage(pages, view); }); } @@ -272,8 +274,10 @@ private boolean isAllConsentGiven(Context context, boolean agree) { } } - private void updateSelectedPage(ViewFlipper vfFlipper, View view) { - vfFlipper.setDisplayedChild(mCurrentStep); + private void updateSelectedPage(List pages, View view) { + for (int i = 0; i < pages.size(); i++) { + pages.get(i).setVisibility(i == mCurrentStep ? View.VISIBLE : View.GONE); + } // TODO: resize dialog... // view.requestLayout(); } diff --git a/library/src/main/res/layout/gdpr_dialog.xml b/library/src/main/res/layout/gdpr_dialog.xml index e1f82c4..af46cc6 100644 --- a/library/src/main/res/layout/gdpr_dialog.xml +++ b/library/src/main/res/layout/gdpr_dialog.xml @@ -11,8 +11,9 @@ android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" /> - @@ -20,6 +21,7 @@ @@ -103,6 +105,7 @@ @@ -126,6 +129,7 @@ @@ -149,6 +153,7 @@ @@ -169,5 +174,5 @@ - + \ No newline at end of file