Skip to content

Commit

Permalink
removed viewflipper with manual visibility handling -> dialog resizes…
Browse files Browse the repository at this point in the history
… itself now
  • Loading branch information
MFlisar committed May 22, 2018
1 parent 41762fe commit ff9b098
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<LinearLayout> 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);
Expand Down Expand Up @@ -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
Expand All @@ -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 -> {
Expand All @@ -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()) {
Expand All @@ -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);
});
}

Expand Down Expand Up @@ -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<LinearLayout> 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();
}
Expand Down
11 changes: 8 additions & 3 deletions library/src/main/res/layout/gdpr_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />

<ViewFlipper
android:id="@+id/vfFlipper"
<LinearLayout
android:id="@+id/llPages"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="?dialogPreferredPadding">

<!-- 0 - Info page -->

<LinearLayout
android:id="@+id/llPage0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand Down Expand Up @@ -103,6 +105,7 @@
<!-- 1 - User accepted personal ads page -->

<LinearLayout
android:id="@+id/llPage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand All @@ -126,6 +129,7 @@
<!-- 2 - User did not accept personal ads page -->

<LinearLayout
android:id="@+id/llPage2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand All @@ -149,6 +153,7 @@
<!-- 3 - User did not accept any ads page -->

<LinearLayout
android:id="@+id/llPage3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand All @@ -169,5 +174,5 @@

</LinearLayout>

</ViewFlipper>
</LinearLayout>
</LinearLayout>

0 comments on commit ff9b098

Please sign in to comment.