From db1e5879dfa6b4ade5a99eca2bc0b9db5b0fb18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Wed, 17 Apr 2019 17:09:10 +0300 Subject: [PATCH] [android] Implemented introduction screen fragment for deffered deep link first launch. [android] Applied introduction screen logic to existing catalogue deep link --- .../src/com/mapswithme/maps/MwmActivity.java | 8 +++ .../maps/base/BaseMwmDialogFragment.java | 9 +++ .../com/mapswithme/maps/intent/Factory.java | 23 ++++++- .../maps/news/IntroductionDialogFragment.java | 66 +++++++++++++++++++ .../maps/news/IntroductionScreenFactory.java | 65 ++++++++++++++++++ .../OnIntroductionButtonClickListener.java | 9 +++ 6 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 android/src/com/mapswithme/maps/news/IntroductionDialogFragment.java create mode 100644 android/src/com/mapswithme/maps/news/IntroductionScreenFactory.java create mode 100644 android/src/com/mapswithme/maps/news/OnIntroductionButtonClickListener.java diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 7c8294f737..96c7616632 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -70,6 +70,8 @@ import com.mapswithme.maps.maplayer.subway.SubwayManager; import com.mapswithme.maps.maplayer.traffic.OnTrafficLayerToggleListener; import com.mapswithme.maps.maplayer.traffic.TrafficManager; import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton; +import com.mapswithme.maps.news.IntroductionDialogFragment; +import com.mapswithme.maps.news.IntroductionScreenFactory; import com.mapswithme.maps.purchase.AdsRemovalActivationCallback; import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider; import com.mapswithme.maps.purchase.FailedPurchaseChecker; @@ -2248,6 +2250,12 @@ public class MwmActivity extends BaseMwmFragmentActivity showSearch(query); } + public void showIntroductionScreenForDeeplink(@NonNull String deepLink, + @NonNull IntroductionScreenFactory factory) + { + IntroductionDialogFragment.show(getSupportFragmentManager(), deepLink, factory); + } + private class CurrentPositionClickListener implements OnClickListener { @Override diff --git a/android/src/com/mapswithme/maps/base/BaseMwmDialogFragment.java b/android/src/com/mapswithme/maps/base/BaseMwmDialogFragment.java index 23de6ae816..5167669a8c 100644 --- a/android/src/com/mapswithme/maps/base/BaseMwmDialogFragment.java +++ b/android/src/com/mapswithme/maps/base/BaseMwmDialogFragment.java @@ -86,4 +86,13 @@ public class BaseMwmDialogFragment extends DialogFragment throw new IllegalStateException("Before call this method make sure that the view exists"); return view; } + + @NonNull + protected Bundle getArgumentsOrThrow() + { + Bundle args = getArguments(); + if (args == null) + throw new AssertionError("Arguments must be non-null!"); + return args; + } } diff --git a/android/src/com/mapswithme/maps/intent/Factory.java b/android/src/com/mapswithme/maps/intent/Factory.java index 2e4ae9e1fa..3e7be2f200 100644 --- a/android/src/com/mapswithme/maps/intent/Factory.java +++ b/android/src/com/mapswithme/maps/intent/Factory.java @@ -27,6 +27,7 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.FeatureId; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.location.LocationHelper; +import com.mapswithme.maps.news.IntroductionScreenFactory; import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.maps.search.SearchActivity; import com.mapswithme.maps.search.SearchEngine; @@ -303,8 +304,7 @@ public class Factory @Override MapTask createIntroductionTask(@NonNull String url) { - // TODO: create task to show introduction in deeplink screen. - return null; + return new FreeGuideReadyToDownloadTask(url); } @NonNull @@ -659,6 +659,25 @@ public class Factory } } + public static class FreeGuideReadyToDownloadTask implements MapTask + { + private static final long serialVersionUID = -6851782210156017186L; + @NonNull + private final String mUrl; + + FreeGuideReadyToDownloadTask(@NonNull String url) + { + mUrl = url; + } + + @Override + public boolean run(@NonNull MwmActivity target) + { + target.showIntroductionScreenForDeeplink(mUrl, IntroductionScreenFactory.FREE_GUIDE); + return false; + } + } + public static class OpenUrlTask implements MapTask { private static final long serialVersionUID = -7257820771228127413L; diff --git a/android/src/com/mapswithme/maps/news/IntroductionDialogFragment.java b/android/src/com/mapswithme/maps/news/IntroductionDialogFragment.java new file mode 100644 index 0000000000..bbd6c2b794 --- /dev/null +++ b/android/src/com/mapswithme/maps/news/IntroductionDialogFragment.java @@ -0,0 +1,66 @@ +package com.mapswithme.maps.news; + +import android.app.Dialog; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import com.mapswithme.maps.R; +import com.mapswithme.maps.base.BaseMwmDialogFragment; + +public class IntroductionDialogFragment extends BaseMwmDialogFragment +{ + private static final String ARG_DEEPLINK = "arg_deeplink"; + private static final String ARG_INTRODUCTION_FACTORY = "arg_introduction_factory"; + + public static void show(@NonNull FragmentManager fm, @NonNull String deepLink, + @NonNull IntroductionScreenFactory factory) + { + Bundle args = new Bundle(); + args.putString(IntroductionDialogFragment.ARG_DEEPLINK, deepLink); + args.putInt(IntroductionDialogFragment.ARG_INTRODUCTION_FACTORY, factory.ordinal()); + final IntroductionDialogFragment fragment = new IntroductionDialogFragment(); + fragment.setArguments(args); + fragment.show(fm, IntroductionDialogFragment.class.getName()); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) + { + Dialog res = super.onCreateDialog(savedInstanceState); + + View content = View.inflate(getActivity(), R.layout.fragment_welcome, null); + res.setContentView(content); + Bundle args = getArgumentsOrThrow(); + int dataIndex = args.getInt(ARG_INTRODUCTION_FACTORY); + IntroductionScreenFactory data = IntroductionScreenFactory.values()[dataIndex]; + TextView button = content.findViewById(R.id.btn__continue); + button.setText(data.getAction()); + button.setOnClickListener(v -> { + String deepLink = args.getString(ARG_DEEPLINK); + if (TextUtils.isEmpty(deepLink)) + throw new AssertionError("Deeplink must non-empty within introduction fragment!"); + data.createButtonClickListener().onIntroductionButtonClick(requireActivity(), deepLink); + dismissAllowingStateLoss(); + }); + ImageView image = content.findViewById(R.id.iv__image); + image.setImageResource(data.getImage()); + TextView title = content.findViewById(R.id.tv__title); + title.setText(data.getTitle()); + TextView subtitle = content.findViewById(R.id.tv__subtitle1); + subtitle.setText(data.getSubtitle()); + + return res; + } + + @Override + protected int getCustomTheme() + { + return getFullscreenTheme(); + } +} diff --git a/android/src/com/mapswithme/maps/news/IntroductionScreenFactory.java b/android/src/com/mapswithme/maps/news/IntroductionScreenFactory.java new file mode 100644 index 0000000000..d0b3312699 --- /dev/null +++ b/android/src/com/mapswithme/maps/news/IntroductionScreenFactory.java @@ -0,0 +1,65 @@ +package com.mapswithme.maps.news; + +import android.app.Activity; +import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; +import android.support.annotation.StringRes; + +import com.mapswithme.maps.R; +import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity; +import com.mapswithme.maps.bookmarks.BookmarksPageFactory; + +public enum IntroductionScreenFactory +{ + FREE_GUIDE + { + @Override + public int getTitle() + { + return R.string.onboarding_guide_direct_download_title; + } + + @Override + public int getSubtitle() + { + return R.string.onboarding_guide_direct_download_subtitle; + } + + @Override + public int getAction() + { + return R.string.onboarding_guide_direct_download_button; + } + + @Override + public int getImage() + { + return R.drawable.img_onboarding_guide; + } + + @NonNull + @Override + public OnIntroductionButtonClickListener createButtonClickListener() + { + return new OnIntroductionButtonClickListener() + { + @Override + public void onIntroductionButtonClick(@NonNull Activity activity, @NonNull String deeplink) + { + BookmarkCategoriesActivity.startForResult(activity, BookmarksPageFactory.DOWNLOADED.ordinal(), deeplink); + } + }; + } + }; + + @StringRes + public abstract int getTitle(); + @StringRes + public abstract int getSubtitle(); + @StringRes + public abstract int getAction(); + @DrawableRes + public abstract int getImage(); + @NonNull + public abstract OnIntroductionButtonClickListener createButtonClickListener(); +} diff --git a/android/src/com/mapswithme/maps/news/OnIntroductionButtonClickListener.java b/android/src/com/mapswithme/maps/news/OnIntroductionButtonClickListener.java new file mode 100644 index 0000000000..0d0c9dc435 --- /dev/null +++ b/android/src/com/mapswithme/maps/news/OnIntroductionButtonClickListener.java @@ -0,0 +1,9 @@ +package com.mapswithme.maps.news; + +import android.app.Activity; +import android.support.annotation.NonNull; + +public interface OnIntroductionButtonClickListener +{ + void onIntroductionButtonClick(@NonNull Activity activity, @NonNull String deeplink); +}