[android] Implemented introduction screen fragment for deffered deep link first launch.

[android] Applied introduction screen logic to existing catalogue deep link
This commit is contained in:
Александр Зацепин 2019-04-17 17:09:10 +03:00 committed by yoksnod
parent 78d3493cd7
commit db1e5879df
6 changed files with 178 additions and 2 deletions

View file

@ -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

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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();
}

View file

@ -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);
}