forked from organicmaps/organicmaps
[android] Tips and tricks supported
This commit is contained in:
parent
08c6b64201
commit
18840f8b67
10 changed files with 586 additions and 90 deletions
|
@ -109,6 +109,7 @@ dependencies {
|
|||
}
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
||||
implementation 'com.android.billingclient:billing:1.1'
|
||||
implementation 'uk.co.samuelwall:material-tap-target-prompt:2.12.1'
|
||||
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
|
||||
}
|
||||
|
||||
|
|
|
@ -1769,6 +1769,13 @@ Java_com_mapswithme_maps_Framework_nativeSetSubscriptionValidationListener(JNIEn
|
|||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeGetCurrentTipsApi(JNIEnv * env, jclass)
|
||||
{
|
||||
auto const & tipsApi = frm()->GetTipsApi();
|
||||
return tipsApi.GetTip().is_initialized() ? static_cast<jint>(tipsApi.GetTip().get()) : -1;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeHasActiveSubscription(JNIEnv *, jclass)
|
||||
{
|
||||
|
|
|
@ -184,4 +184,11 @@
|
|||
<color name="rating_horrible">#E53935</color>
|
||||
<color name="rating_none">#FF888A82</color>
|
||||
<color name="rating_coming_soon">#FF1E96F0</color>
|
||||
|
||||
<color name="tips_and_triks_bg_dark">#b8000000</color>
|
||||
<color name="tips_and_triks_bg_light">#b8ffffff</color>
|
||||
<color name="tips_and_triks_primary_text_dark">#000000</color>
|
||||
<color name="tips_and_triks_primary_text_light">#ffffff</color>
|
||||
<color name="tips_and_triks_secondary_text_dark">#b8000000</color>
|
||||
<color name="tips_and_triks_secondary_text_light">#b3ffffff</color>
|
||||
</resources>
|
||||
|
|
|
@ -105,6 +105,9 @@
|
|||
<attr name="adChoicesIcon" format="reference"/>
|
||||
<attr name="saleIcon" format="reference"/>
|
||||
<attr name="toggleMapLayerBtnBg" format="reference"/>
|
||||
<attr name="tipsBgColor" format="color"/>
|
||||
<attr name="tipsPrimaryTextColor" format="color"/>
|
||||
<attr name="tipsSecondaryTextColor" format="color"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="ThemeAttrs.NavButtons">
|
||||
|
|
|
@ -133,6 +133,9 @@
|
|||
<item name="subwayMenuDisabled">@drawable/ic_subway_menu_light_off</item>
|
||||
<item name="toggleMapLayerBtnBg">@drawable/bg_toggle_map_layer_btn</item>
|
||||
<item name="accentTextColorSelector">@color/tab_text</item>
|
||||
<item name="tipsBgColor">@color/tips_and_triks_bg_dark</item>
|
||||
<item name="tipsPrimaryTextColor">@color/tips_and_triks_primary_text_light</item>
|
||||
<item name="tipsSecondaryTextColor">@color/tips_and_triks_secondary_text_light</item>
|
||||
</style>
|
||||
|
||||
<!-- Night theme -->
|
||||
|
@ -269,5 +272,8 @@
|
|||
<item name="subwayMenuDisabled">@drawable/ic_subway_menu_dark_off</item>
|
||||
<item name="toggleMapLayerBtnBg">@drawable/bg_toggle_map_layer_btn_dark</item>
|
||||
<item name="accentTextColorSelector">@color/tab_text_night</item>
|
||||
<item name="tipsBgColor">@color/tips_and_triks_bg_light</item>
|
||||
<item name="tipsPrimaryTextColor">@color/tips_and_triks_primary_text_dark</item>
|
||||
<item name="tipsSecondaryTextColor">@color/tips_and_triks_secondary_text_dark</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -474,4 +474,6 @@ public class Framework
|
|||
public static native void nativeSetSubscriptionValidationListener(
|
||||
@Nullable SubscriptionValidationListener listener);
|
||||
public static native boolean nativeHasActiveSubscription();
|
||||
|
||||
public static native int nativeGetCurrentTipsApi();
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ import com.mapswithme.maps.location.CompassData;
|
|||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.maplayer.MapLayerCompositeController;
|
||||
import com.mapswithme.maps.maplayer.Mode;
|
||||
import com.mapswithme.maps.tips.TipsProvider;
|
||||
import com.mapswithme.maps.maplayer.subway.OnSubwayLayerToggleListener;
|
||||
import com.mapswithme.maps.maplayer.subway.SubwayManager;
|
||||
import com.mapswithme.maps.maplayer.traffic.OnTrafficLayerToggleListener;
|
||||
|
@ -577,7 +578,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
initMap();
|
||||
initNavigationButtons();
|
||||
|
||||
mPlacePage = (PlacePageView) findViewById(R.id.info_box);
|
||||
mPlacePage = findViewById(R.id.info_box);
|
||||
mPlacePage.setOnVisibilityChangedListener(this);
|
||||
mPlacePage.setOnAnimationListener(this);
|
||||
mPlacePageTracker = new PlacePageTracker(mPlacePage);
|
||||
|
@ -593,6 +594,16 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
initOnmapDownloader();
|
||||
initPositionChooser();
|
||||
initFilterViews();
|
||||
initTips();
|
||||
}
|
||||
|
||||
private void initTips()
|
||||
{
|
||||
TipsProvider api = TipsProvider.requestCurrent(getClass());
|
||||
if (api == TipsProvider.STUB)
|
||||
return;
|
||||
|
||||
api.showTutorial(getActivity());
|
||||
}
|
||||
|
||||
private void initFilterViews()
|
||||
|
@ -651,7 +662,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
if (mPositionChooser == null)
|
||||
return;
|
||||
|
||||
final Toolbar toolbar = (Toolbar) mPositionChooser.findViewById(R.id.toolbar_position_chooser);
|
||||
final Toolbar toolbar = mPositionChooser.findViewById(R.id.toolbar_position_chooser);
|
||||
UiUtils.extendViewWithStatusBar(toolbar);
|
||||
UiUtils.showHomeUpButton(toolbar);
|
||||
toolbar.setNavigationOnClickListener(v -> hidePositionChooser());
|
||||
|
@ -686,7 +697,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
private void initMap()
|
||||
{
|
||||
mFadeView = (FadeView) findViewById(R.id.fade_view);
|
||||
mFadeView = findViewById(R.id.fade_view);
|
||||
mFadeView.setListener(new FadeView.Listener()
|
||||
{
|
||||
@Override
|
||||
|
@ -789,7 +800,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
mFadeView.fadeOut();
|
||||
mMainMenu.close(true, procAfterClose);
|
||||
}
|
||||
|
||||
private boolean closePositionChooser()
|
||||
{
|
||||
if (UiUtils.isVisible(mPositionChooser))
|
||||
|
@ -828,80 +838,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
private void initMainMenu()
|
||||
{
|
||||
mMainMenu = new MainMenu(findViewById(R.id.menu_frame), item -> {
|
||||
if (mIsFullscreenAnimating)
|
||||
return;
|
||||
|
||||
switch (item)
|
||||
{
|
||||
case MENU:
|
||||
if (!mMainMenu.isOpen())
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarClick(item);
|
||||
if (mPlacePage == null || (mPlacePage.isDocked() && closePlacePage()))
|
||||
return;
|
||||
|
||||
if (closeSidePanel())
|
||||
return;
|
||||
}
|
||||
toggleMenu();
|
||||
break;
|
||||
|
||||
case ADD_PLACE:
|
||||
Statistics.INSTANCE.trackToolbarMenu(item);
|
||||
closePlacePage();
|
||||
if (mIsTabletLayout)
|
||||
closeSidePanel();
|
||||
closeMenu(() -> {
|
||||
showPositionChooser(false, false);
|
||||
});
|
||||
break;
|
||||
|
||||
case SEARCH:
|
||||
Statistics.INSTANCE.trackToolbarClick(item);
|
||||
RoutingController.get().cancel();
|
||||
closeMenu(() -> showSearch(mSearchController.getQuery()));
|
||||
break;
|
||||
|
||||
case POINT_TO_POINT:
|
||||
Statistics.INSTANCE.trackToolbarClick(item);
|
||||
startLocationToPoint(null, false);
|
||||
break;
|
||||
|
||||
case DISCOVERY:
|
||||
Statistics.INSTANCE.trackToolbarClick(item);
|
||||
showDiscovery();
|
||||
break;
|
||||
|
||||
case BOOKMARKS:
|
||||
Statistics.INSTANCE.trackToolbarClick(item);
|
||||
closeMenu(this::showBookmarks);
|
||||
break;
|
||||
|
||||
case SHARE_MY_LOCATION:
|
||||
Statistics.INSTANCE.trackToolbarMenu(item);
|
||||
closeMenu(this::shareMyLocation);
|
||||
break;
|
||||
|
||||
case DOWNLOAD_MAPS:
|
||||
Statistics.INSTANCE.trackToolbarMenu(item);
|
||||
RoutingController.get().cancel();
|
||||
closeMenu(() -> showDownloader(false));
|
||||
break;
|
||||
|
||||
case SETTINGS:
|
||||
Statistics.INSTANCE.trackToolbarMenu(item);
|
||||
Intent intent = new Intent(MwmActivity.this, SettingsActivity.class);
|
||||
closeMenu(() -> startActivity(intent));
|
||||
break;
|
||||
|
||||
case DOWNLOAD_GUIDES:
|
||||
Statistics.INSTANCE.trackToolbarMenu(item);
|
||||
int requestCode = BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY;
|
||||
closeMenu(() -> BookmarksCatalogActivity.startForResult(getActivity(), requestCode));
|
||||
break;
|
||||
}
|
||||
});
|
||||
mMainMenu = new MainMenu(findViewById(R.id.menu_frame), this::onItemClickOrSkipAnim);
|
||||
|
||||
if (mIsTabletLayout)
|
||||
{
|
||||
|
@ -914,7 +851,15 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
mPlacePage.setLeftAnimationTrackListener(mMainMenu.getLeftAnimationTrackListener());
|
||||
}
|
||||
|
||||
private void showDiscovery()
|
||||
private void onItemClickOrSkipAnim(@NonNull MainMenu.Item item)
|
||||
{
|
||||
if (mIsFullscreenAnimating)
|
||||
return;
|
||||
|
||||
item.onClicked(this, item);
|
||||
}
|
||||
|
||||
public void showDiscovery()
|
||||
{
|
||||
if (mIsTabletLayout)
|
||||
{
|
||||
|
@ -988,7 +933,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
if (state != State.HIDDEN)
|
||||
{
|
||||
mPlacePageRestored = true;
|
||||
MapObject mapObject = (MapObject) savedInstanceState.getParcelable(STATE_MAP_OBJECT);
|
||||
MapObject mapObject = savedInstanceState.getParcelable(STATE_MAP_OBJECT);
|
||||
mPlacePage.setMapObject(mapObject, true,
|
||||
new PlacePageView.SetMapObjectListener()
|
||||
{
|
||||
|
@ -2704,4 +2649,212 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
myPositionClick();
|
||||
}
|
||||
}
|
||||
|
||||
public interface ClickMenuDelegate
|
||||
{
|
||||
void onMenuItemClick();
|
||||
|
||||
abstract class AbstractClickMenuDelegate implements ClickMenuDelegate
|
||||
{
|
||||
@NonNull
|
||||
private final MwmActivity mActivity;
|
||||
@NonNull
|
||||
private final MainMenu.Item mItem;
|
||||
|
||||
AbstractClickMenuDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
mActivity = activity;
|
||||
mItem = item;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MwmActivity getActivity()
|
||||
{
|
||||
return mActivity;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MainMenu.Item getItem()
|
||||
{
|
||||
return mItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onMenuItemClick()
|
||||
{
|
||||
TipsProvider api = TipsProvider.requestCurrent(getActivity().getClass());
|
||||
if (api == TipsProvider.STUB || getItem() != api.getSiblingMenuItem())
|
||||
onMenuItemClickInternal();
|
||||
else
|
||||
api.createClickInterceptor().onInterceptClick(getActivity());
|
||||
}
|
||||
|
||||
public abstract void onMenuItemClickInternal();
|
||||
}
|
||||
|
||||
class MenuClickDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public MenuClickDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
if (!getActivity().mMainMenu.isOpen())
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarClick(getItem());
|
||||
if (getActivity().mPlacePage.isDocked() && getActivity().closePlacePage())
|
||||
return;
|
||||
|
||||
if (getActivity().closeSidePanel())
|
||||
return;
|
||||
}
|
||||
getActivity().toggleMenu();
|
||||
}
|
||||
}
|
||||
|
||||
class AddPlaceDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public AddPlaceDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarMenu(getItem());
|
||||
getActivity().closePlacePage();
|
||||
if (getActivity().mIsTabletLayout)
|
||||
getActivity().closeSidePanel();
|
||||
getActivity().closeMenu(() -> getActivity().showPositionChooser(false, false));
|
||||
}
|
||||
}
|
||||
|
||||
class SearchClickDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public SearchClickDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarClick(getItem());
|
||||
RoutingController.get().cancel();
|
||||
getActivity().closeMenu(() -> getActivity().showSearch(getActivity().mSearchController.getQuery()));
|
||||
}
|
||||
}
|
||||
|
||||
class PointToPointDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public PointToPointDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarClick(getItem());
|
||||
getActivity().startLocationToPoint(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
class DiscoveryDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public DiscoveryDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarClick(getItem());
|
||||
getActivity().showDiscovery();
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarksDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public BookmarksDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarClick(getItem());
|
||||
getActivity().closeMenu(getActivity()::showBookmarks);
|
||||
}
|
||||
}
|
||||
|
||||
class ShareMyLocationDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public ShareMyLocationDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarMenu(getItem());
|
||||
getActivity().closeMenu(getActivity()::shareMyLocation);
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadMapsDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public DownloadMapsDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarMenu(getItem());
|
||||
RoutingController.get().cancel();
|
||||
getActivity().closeMenu(() -> getActivity().showDownloader(false));
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public SettingsDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarMenu(getItem());
|
||||
Intent intent = new Intent(getActivity(), SettingsActivity.class);
|
||||
getActivity().closeMenu(() -> getActivity().startActivity(intent));
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadGuidesDelegate extends AbstractClickMenuDelegate
|
||||
{
|
||||
public DownloadGuidesDelegate(@NonNull MwmActivity activity, @NonNull MainMenu.Item item)
|
||||
{
|
||||
super(activity, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClickInternal()
|
||||
{
|
||||
Statistics.INSTANCE.trackToolbarMenu(getItem());
|
||||
int requestCode = BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY;
|
||||
getActivity().closeMenu(() -> BookmarksCatalogActivity.startForResult(getActivity(), requestCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import android.support.annotation.NonNull;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.maplayer.subway.SubwayMapLayerController;
|
||||
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton;
|
||||
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButtonController;
|
||||
import com.mapswithme.maps.tips.TipsProvider;
|
||||
import com.mapswithme.util.InputUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -266,6 +268,15 @@ public class MapLayerCompositeController implements MapLayerController
|
|||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
TipsProvider api;
|
||||
if ((api = TipsProvider.requestCurrent(mActivity.getClass())) == TipsProvider.MAP_LAYERS)
|
||||
{
|
||||
MwmActivity mwmActivity = (MwmActivity) mActivity;
|
||||
TipsProvider.ClickInterceptor interceptor = api.createClickInterceptor();
|
||||
interceptor.onInterceptClick(mwmActivity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mMasterEntry.getMode().isEnabled(mActivity))
|
||||
{
|
||||
turnOff();
|
||||
|
|
206
android/src/com/mapswithme/maps/tips/TipsProvider.java
Normal file
206
android/src/com/mapswithme/maps/tips/TipsProvider.java
Normal file
|
@ -0,0 +1,206 @@
|
|||
package com.mapswithme.maps.tips;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity;
|
||||
import com.mapswithme.maps.maplayer.Mode;
|
||||
import com.mapswithme.maps.widget.menu.MainMenu;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||
import uk.co.samuelwall.materialtaptargetprompt.extras.backgrounds.FullscreenPromptBackground;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public enum TipsProvider
|
||||
{
|
||||
BOOKMARKS(R.string.tips_bookmarks_catalog_title,
|
||||
R.string.tips_bookmarks_catalog_message,
|
||||
R.id.bookmarks, MainMenu.Item.BOOKMARKS, MwmActivity.class)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public ClickInterceptor createClickInterceptor()
|
||||
{
|
||||
return new ClickInterceptor.OpenBookmarksCatalog();
|
||||
}
|
||||
},
|
||||
|
||||
SEARCH(R.string.tips_book_hotel_title,
|
||||
R.string.tips_book_hotel_message,
|
||||
R.id.search, MainMenu.Item.SEARCH, MwmActivity.class)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public ClickInterceptor createClickInterceptor()
|
||||
{
|
||||
return new ClickInterceptor.SearchHotels();
|
||||
}
|
||||
},
|
||||
|
||||
DISCOVERY(R.string.tips_discover_button_title,
|
||||
R.string.tips_discover_button_message,
|
||||
R.id.discovery, MainMenu.Item.DISCOVERY, MwmActivity.class)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public ClickInterceptor createClickInterceptor()
|
||||
{
|
||||
return new ClickInterceptor.OpenDiscoveryScreen();
|
||||
}
|
||||
},
|
||||
|
||||
MAP_LAYERS(R.string.tips_map_layers_title,
|
||||
R.string.tips_map_layers_message,
|
||||
R.id.subway, null, MwmActivity.class)
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ClickInterceptor createClickInterceptor()
|
||||
{
|
||||
return new ClickInterceptor.ActivateSubwayLayer();
|
||||
}
|
||||
},
|
||||
|
||||
STUB
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public ClickInterceptor createClickInterceptor()
|
||||
{
|
||||
return params -> {};
|
||||
}
|
||||
};
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
private static final String TAG = TipsProvider.class.getSimpleName();
|
||||
|
||||
@StringRes
|
||||
private final int mPrimaryText;
|
||||
@StringRes
|
||||
private final int mSecondaryText;
|
||||
@IdRes
|
||||
private final int mAnchorViewId;
|
||||
@NonNull
|
||||
private final List<Class<?>> mAllowedScreens;
|
||||
@Nullable
|
||||
private final MainMenu.Item mSiblingMenuItem;
|
||||
|
||||
TipsProvider(@StringRes int primaryText, @StringRes int secondaryText, @IdRes int anchorViewId,
|
||||
@Nullable MainMenu.Item siblingMenuItem, @NonNull Class<?>... allowedScreens)
|
||||
{
|
||||
mPrimaryText = primaryText;
|
||||
mSecondaryText = secondaryText;
|
||||
mAnchorViewId = anchorViewId;
|
||||
mSiblingMenuItem = siblingMenuItem;
|
||||
mAllowedScreens = Arrays.asList(allowedScreens);
|
||||
}
|
||||
|
||||
TipsProvider()
|
||||
{
|
||||
this(UiUtils.NO_ID, UiUtils.NO_ID, UiUtils.NO_ID, null);
|
||||
}
|
||||
|
||||
private boolean isScreenAllowed(@NonNull Class<?> screenClass)
|
||||
{
|
||||
return mAllowedScreens.contains(screenClass);
|
||||
}
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
@Nullable
|
||||
public MaterialTapTargetPrompt showTutorial(@NonNull Activity activity)
|
||||
{
|
||||
View target = activity.findViewById(mAnchorViewId);
|
||||
return new MaterialTapTargetPrompt.Builder(activity)
|
||||
.setTarget(target)
|
||||
.setFocalRadius(R.dimen.nav_street_height)
|
||||
.setPrimaryText(mPrimaryText)
|
||||
.setPrimaryTextSize(R.dimen.text_size_toolbar)
|
||||
.setPrimaryTextColour(ThemeUtils.getColor(activity, R.attr.tipsPrimaryTextColor))
|
||||
.setPrimaryTextTypeface(Typeface.DEFAULT_BOLD)
|
||||
.setSecondaryText(mSecondaryText)
|
||||
.setSecondaryTextColour(ThemeUtils.getColor(activity, R.attr.tipsSecondaryTextColor))
|
||||
.setSecondaryTextSize(R.dimen.text_size_body_3)
|
||||
.setSecondaryTextTypeface(Typeface.DEFAULT)
|
||||
.setBackgroundColour(ThemeUtils.getColor(activity, R.attr.tipsBgColor))
|
||||
.setFocalColour(activity.getResources().getColor(android.R.color.transparent))
|
||||
.setPromptBackground(new FullscreenPromptBackground())
|
||||
.show();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MainMenu.Item getSiblingMenuItem()
|
||||
{
|
||||
return mSiblingMenuItem;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public abstract ClickInterceptor createClickInterceptor();
|
||||
|
||||
@NonNull
|
||||
public static <T> TipsProvider requestCurrent(@NonNull Class<T> requiredScreenClass)
|
||||
{
|
||||
int index = Framework.nativeGetCurrentTipsApi();
|
||||
TipsProvider value = index >= 0 ? values()[index] : STUB;
|
||||
TipsProvider tipsProvider = value != STUB && value.isScreenAllowed(requiredScreenClass) ? value
|
||||
: STUB;
|
||||
LOGGER.d(TAG, "tipsProvider = " + tipsProvider);
|
||||
return tipsProvider;
|
||||
}
|
||||
|
||||
public interface ClickInterceptor
|
||||
{
|
||||
void onInterceptClick(@NonNull MwmActivity params);
|
||||
|
||||
class OpenBookmarksCatalog implements ClickInterceptor
|
||||
{
|
||||
@Override
|
||||
public void onInterceptClick(@NonNull MwmActivity params)
|
||||
{
|
||||
BookmarksCatalogActivity.startForResult(params,
|
||||
BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY);
|
||||
}
|
||||
}
|
||||
|
||||
class ActivateSubwayLayer implements ClickInterceptor
|
||||
{
|
||||
@Override
|
||||
public void onInterceptClick(@NonNull MwmActivity params)
|
||||
{
|
||||
Mode.SUBWAY.setEnabled(params, true);
|
||||
params.onSubwayLayerSelected();
|
||||
}
|
||||
}
|
||||
|
||||
class SearchHotels implements ClickInterceptor
|
||||
{
|
||||
@Override
|
||||
public void onInterceptClick(@NonNull MwmActivity params)
|
||||
{
|
||||
params.showSearch(params.getString(R.string.hotel));
|
||||
}
|
||||
}
|
||||
|
||||
class OpenDiscoveryScreen implements ClickInterceptor
|
||||
{
|
||||
@Override
|
||||
public void onInterceptClick(@NonNull MwmActivity params)
|
||||
{
|
||||
params.showDiscovery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -122,16 +122,106 @@ public class MainMenu extends BaseMenu
|
|||
|
||||
public enum Item implements BaseMenu.Item
|
||||
{
|
||||
MENU(R.id.toggle),
|
||||
ADD_PLACE(R.id.add_place),
|
||||
DOWNLOAD_GUIDES(R.id.download_guides),
|
||||
SEARCH(R.id.search),
|
||||
POINT_TO_POINT(R.id.p2p),
|
||||
DISCOVERY(R.id.discovery),
|
||||
BOOKMARKS(R.id.bookmarks),
|
||||
SHARE_MY_LOCATION(R.id.share),
|
||||
DOWNLOAD_MAPS(R.id.download_maps),
|
||||
SETTINGS(R.id.settings);
|
||||
MENU(R.id.toggle)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.MenuClickDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
ADD_PLACE(R.id.add_place)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.AddPlaceDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
DOWNLOAD_GUIDES(R.id.download_guides)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.DownloadGuidesDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
SEARCH(R.id.search)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.SearchClickDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
POINT_TO_POINT(R.id.p2p)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.PointToPointDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
DISCOVERY(R.id.discovery)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.DiscoveryDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
BOOKMARKS(R.id.bookmarks)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.BookmarksDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
SHARE_MY_LOCATION(R.id.share)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.ShareMyLocationDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
DOWNLOAD_MAPS(R.id.download_maps)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.DownloadMapsDelegate(activity, item);
|
||||
}
|
||||
},
|
||||
SETTINGS(R.id.settings)
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
public MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item)
|
||||
{
|
||||
return new MwmActivity.ClickMenuDelegate.SettingsDelegate(activity, item);
|
||||
}
|
||||
};
|
||||
|
||||
private final int mViewId;
|
||||
|
||||
|
@ -145,6 +235,16 @@ public class MainMenu extends BaseMenu
|
|||
{
|
||||
return mViewId;
|
||||
}
|
||||
|
||||
public void onClicked(@NonNull MwmActivity activity, @NonNull Item item)
|
||||
{
|
||||
MwmActivity.ClickMenuDelegate delegate = createClickDelegate(activity, item);
|
||||
delegate.onMenuItemClick();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public abstract MwmActivity.ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity,
|
||||
@NonNull Item item);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue