diff --git a/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java b/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java index b82b250830..1c70fbf182 100644 --- a/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java +++ b/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java @@ -95,9 +95,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity imp Factory.createMapsWithMeIntentProcessor(), Factory.createGoogleMapsIntentProcessor(), Factory.createOldLeadUrlProcessor(), - Factory.createDlinkBookmarkCatalogueProcessor(), Factory.createMapsmeBookmarkCatalogueProcessor(), - Factory.createDlinkBookmarkGuidesPageProcessor(), Factory.createDlinkBookmarksSubscriptionProcessor(), Factory.createOldCoreLinkAdapterProcessor(), Factory.createOpenCountryTaskProcessor(), diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index b51c3e5e76..d1cdf3c592 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -26,7 +26,6 @@ import androidx.annotation.Nullable; import androidx.annotation.StyleRes; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -82,8 +81,6 @@ 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.onboarding.IntroductionDialogFragment; -import com.mapswithme.maps.onboarding.IntroductionScreenFactory; import com.mapswithme.maps.purchase.FailedPurchaseChecker; import com.mapswithme.maps.purchase.PurchaseCallback; import com.mapswithme.maps.purchase.PurchaseController; @@ -117,7 +114,6 @@ import com.mapswithme.maps.sound.TtsPlayer; import com.mapswithme.maps.taxi.TaxiInfo; import com.mapswithme.maps.taxi.TaxiManager; import com.mapswithme.maps.tips.Tutorial; -import com.mapswithme.maps.tips.TutorialAction; import com.mapswithme.maps.widget.FadeView; import com.mapswithme.maps.widget.SearchToolbarController; import com.mapswithme.maps.widget.menu.BaseMenu; @@ -131,9 +127,7 @@ import com.mapswithme.maps.widget.placepage.PlacePageController; import com.mapswithme.maps.widget.placepage.PlacePageData; import com.mapswithme.maps.widget.placepage.PlacePageFactory; import com.mapswithme.maps.widget.placepage.RoutingModeListener; -import com.mapswithme.util.Counters; import com.mapswithme.util.InputUtils; -import com.mapswithme.util.NetworkPolicy; import com.mapswithme.util.PermissionsUtils; import com.mapswithme.util.SharedPropertiesUtils; import com.mapswithme.util.ThemeSwitcher; @@ -2522,12 +2516,6 @@ public class MwmActivity extends BaseMwmFragmentActivity closePlacePage(); } - public void showIntroductionScreenForDeeplink(@NonNull String deepLink, - @NonNull IntroductionScreenFactory factory) - { - IntroductionDialogFragment.show(getSupportFragmentManager(), deepLink, factory); - } - @Override public boolean onKeyUp(int keyCode, KeyEvent event) { diff --git a/android/src/com/mapswithme/maps/SplashActivity.java b/android/src/com/mapswithme/maps/SplashActivity.java index 20acd52df4..6d5763f53b 100644 --- a/android/src/com/mapswithme/maps/SplashActivity.java +++ b/android/src/com/mapswithme/maps/SplashActivity.java @@ -12,14 +12,10 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import com.mapswithme.maps.base.BaseActivity; import com.mapswithme.maps.base.BaseActivityDelegate; -import com.mapswithme.maps.downloader.UpdaterDialogFragment; -import com.mapswithme.maps.editor.ViralFragment; import com.mapswithme.maps.location.LocationHelper; -import com.mapswithme.maps.onboarding.BaseNewsFragment; import com.mapswithme.maps.permissions.PermissionsDialogFragment; import com.mapswithme.util.Config; import com.mapswithme.util.Counters; @@ -30,8 +26,7 @@ import com.mapswithme.util.concurrency.UiThread; import com.mapswithme.util.log.Logger; import com.mapswithme.util.log.LoggerFactory; -public class SplashActivity extends AppCompatActivity - implements BaseNewsFragment.NewsDialogListener, BaseActivity +public class SplashActivity extends AppCompatActivity implements BaseActivity { private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC); private static final String TAG = SplashActivity.class.getSimpleName(); @@ -111,7 +106,6 @@ public class SplashActivity extends AppCompatActivity { super.onCreate(savedInstanceState); mBaseDelegate.onCreate(); - handleUpdateMapsFragmentCorrectly(savedInstanceState); UiThread.cancelDelayedTasks(mPermissionsDelayedTask); UiThread.cancelDelayedTasks(mInitCoreDelayedTask); UiThread.cancelDelayedTasks(mFinalDelayedTask); @@ -126,26 +120,6 @@ public class SplashActivity extends AppCompatActivity mBaseDelegate.onNewIntent(intent); } - private void handleUpdateMapsFragmentCorrectly(@Nullable Bundle savedInstanceState) - { - if (savedInstanceState == null) - return; - - FragmentManager fm = getSupportFragmentManager(); - DialogFragment updaterFragment = (DialogFragment) fm - .findFragmentByTag(UpdaterDialogFragment.class.getName()); - - if (updaterFragment == null) - return; - - // Check platform and core initialization, because we may be in the recovering process, - // i.e. method onResume() may not be invoked in that case. - if (!MwmApplication.from(getApplicationContext()).arePlatformAndCoreInitialized()) - { - init(); - } - } - @Override protected void onStart() { @@ -236,32 +210,7 @@ public class SplashActivity extends AppCompatActivity return; } - boolean showNews = false; - if (!showNews) - { - if (ViralFragment.shouldDisplay(getApplicationContext())) - { - UiUtils.hide(mIvLogo, mAppName); - ViralFragment dialog = new ViralFragment(); - dialog.onDismissListener(new Runnable() - { - @Override - public void run() - { - onDialogDone(); - } - }); - dialog.show(getSupportFragmentManager(), ""); - } - else - { - processNavigation(); - } - } - else - { - UiUtils.hide(mIvLogo, mAppName); - } + processNavigation(); } private void showExternalStorageErrorDialog() @@ -294,12 +243,6 @@ public class SplashActivity extends AppCompatActivity .isLocationGranted(); } - @Override - public void onDialogDone() - { - processNavigation(); - } - private void initView() { UiUtils.setupStatusBar(this); diff --git a/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java b/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java deleted file mode 100644 index bf4dea8232..0000000000 --- a/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java +++ /dev/null @@ -1,543 +0,0 @@ -package com.mapswithme.maps.downloader; - -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentTransaction; -import android.view.View; -import android.view.Window; -import android.widget.TextView; - -import com.mapswithme.maps.Framework; -import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmDialogFragment; -import com.mapswithme.maps.onboarding.BaseNewsFragment; -import com.mapswithme.maps.widget.WheelProgressView; -import com.mapswithme.util.Constants; -import com.mapswithme.util.StringUtils; -import com.mapswithme.util.UiUtils; -import com.mapswithme.util.Utils; -import com.mapswithme.util.log.Logger; -import com.mapswithme.util.log.LoggerFactory; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - - -public class UpdaterDialogFragment extends BaseMwmDialogFragment -{ - private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.DOWNLOADER); - private static final String TAG = UpdaterDialogFragment.class.getSimpleName(); - - private static final String EXTRA_LEFTOVER_MAPS = "extra_leftover_maps"; - private static final String EXTRA_PROCESSED_MAP_ID = "extra_processed_map_id"; - private static final String EXTRA_COMMON_STATUS_RES_ID = "extra_common_status_res_id"; - - private static final String ARG_UPDATE_IMMEDIATELY = "arg_update_immediately"; - private static final String ARG_TOTAL_SIZE = "arg_total_size"; - private static final String ARG_TOTAL_SIZE_BYTES = "arg_total_size_bytes"; - private static final String ARG_OUTDATED_MAPS = "arg_outdated_maps"; - - private TextView mTitle; - private TextView mUpdateBtn; - private WheelProgressView mProgressBar; - private TextView mFinishBtn; - private View mInfo; - private TextView mRelativeStatus; - - @Nullable - private String mTotalSize; - private long mTotalSizeBytes; - private boolean mAutoUpdate; - @Nullable - private String[] mOutdatedMaps; - /** - * Stores maps which are left to finish autoupdating process. - */ - @Nullable - private HashSet mLeftoverMaps; - - @Nullable - private BaseNewsFragment.NewsDialogListener mDoneListener; - - @Nullable - private DetachableStorageCallback mStorageCallback; - - @Nullable - private String mProcessedMapId; - @StringRes - private int mCommonStatusResId = Utils.INVALID_ID; - - private void finish() - { - dismiss(); - if (mDoneListener != null) - mDoneListener.onDialogDone(); - } - - @NonNull - private final View.OnClickListener mFinishClickListener = (View v) -> finish(); - - @NonNull - private final View.OnClickListener mCancelClickListener = (View v) -> - { - MapManager.nativeCancel(CountryItem.getRootId()); - - final UpdateInfo info = MapManager.nativeGetUpdateInfo(CountryItem.getRootId()); - if (info == null) - { - finish(); - return; - } - - updateTotalSizes(info.totalSize); - - mAutoUpdate = false; - mOutdatedMaps = Framework.nativeGetOutdatedCountries(); - - if (mStorageCallback != null) - mStorageCallback.detach(); - - mStorageCallback = new DetachableStorageCallback(this, mLeftoverMaps, mOutdatedMaps); - mStorageCallback.attach(this); - - initViews(); - }; - - @NonNull - private final View.OnClickListener mUpdateClickListener = (View v) -> - MapManager.warnOn3gUpdate(getActivity(), CountryItem.getRootId(), new Runnable() - { - @Override - public void run() - { - mAutoUpdate = true; - mFinishBtn.setText(getString(R.string.downloader_hide_screen)); - mTitle.setText(getString(R.string.whats_new_auto_update_updating_maps)); - setProgress(0, 0, mTotalSizeBytes); - setCommonStatus(mProcessedMapId, mCommonStatusResId); - MapManager.nativeUpdate(CountryItem.getRootId()); - UiUtils.show(mProgressBar, mInfo); - UiUtils.hide(mUpdateBtn); - } - }); - - public static boolean showOn(@NonNull FragmentActivity activity, - @Nullable BaseNewsFragment.NewsDialogListener doneListener) - { - final FragmentManager fm = activity.getSupportFragmentManager(); - if (fm.isDestroyed()) - return false; - - final UpdateInfo info = MapManager.nativeGetUpdateInfo(CountryItem.getRootId()); - if (info == null) - return false; - - @Framework.DoAfterUpdate final int result; - - Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName()); - if (f != null) - { - ((UpdaterDialogFragment) f).mDoneListener = doneListener; - return true; - } - else - { - result = Framework.nativeToDoAfterUpdate(); - if (result == Framework.DO_AFTER_UPDATE_NOTHING) - return false; - } - - final Bundle args = new Bundle(); - args.putBoolean(ARG_UPDATE_IMMEDIATELY, result == Framework.DO_AFTER_UPDATE_AUTO_UPDATE); - args.putString(ARG_TOTAL_SIZE, StringUtils.getFileSizeString(activity.getApplicationContext(), info.totalSize)); - args.putLong(ARG_TOTAL_SIZE_BYTES, info.totalSize); - args.putStringArray(ARG_OUTDATED_MAPS, Framework.nativeGetOutdatedCountries()); - - final UpdaterDialogFragment fragment = new UpdaterDialogFragment(); - fragment.setArguments(args); - fragment.mDoneListener = doneListener; - FragmentTransaction transaction = fm.beginTransaction() - .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); - fragment.show(transaction, UpdaterDialogFragment.class.getName()); - - return true; - } - - @Override - protected int getCustomTheme() - { - return super.getFullscreenTheme(); - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - if (savedInstanceState != null) - { // As long as we use HashSet to store leftover maps this cast is safe. - //noinspection unchecked - mLeftoverMaps = (HashSet) savedInstanceState.getSerializable(EXTRA_LEFTOVER_MAPS); - mProcessedMapId = savedInstanceState.getString(EXTRA_PROCESSED_MAP_ID); - mCommonStatusResId = savedInstanceState.getInt(EXTRA_COMMON_STATUS_RES_ID); - mAutoUpdate = savedInstanceState.getBoolean(ARG_UPDATE_IMMEDIATELY); - mTotalSize = savedInstanceState.getString(ARG_TOTAL_SIZE); - mTotalSizeBytes = savedInstanceState.getLong(ARG_TOTAL_SIZE_BYTES, 0L); - mOutdatedMaps = savedInstanceState.getStringArray(ARG_OUTDATED_MAPS); - } - else - { - readArguments(); - } - mStorageCallback = new DetachableStorageCallback(this, mLeftoverMaps, mOutdatedMaps); - } - - @Override - public void onSaveInstanceState(Bundle outState) - { - super.onSaveInstanceState(outState); - outState.putSerializable(EXTRA_LEFTOVER_MAPS, mLeftoverMaps); - outState.putString(EXTRA_PROCESSED_MAP_ID, mProcessedMapId); - outState.putInt(EXTRA_COMMON_STATUS_RES_ID, mCommonStatusResId); - outState.putBoolean(ARG_UPDATE_IMMEDIATELY, mAutoUpdate); - outState.putString(ARG_TOTAL_SIZE, mTotalSize); - outState.putLong(ARG_TOTAL_SIZE_BYTES, mTotalSizeBytes); - outState.putStringArray(ARG_OUTDATED_MAPS, mOutdatedMaps); - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) - { - Dialog res = super.onCreateDialog(savedInstanceState); - res.requestWindowFeature(Window.FEATURE_NO_TITLE); - - View content = View.inflate(getActivity(), R.layout.fragment_updater, null); - res.setContentView(content); - - mTitle = content.findViewById(R.id.title); - mUpdateBtn = content.findViewById(R.id.update_btn); - mProgressBar = content.findViewById(R.id.progress); - mFinishBtn = content.findViewById(R.id.later_btn); - mInfo = content.findViewById(R.id.info); - mRelativeStatus = content.findViewById(R.id.relative_status); - - initViews(); - - return res; - } - - @Override - public void onResume() - { - super.onResume(); - - // The storage callback must be non-null at this point. - //noinspection ConstantConditions - mStorageCallback.attach(this); - mProgressBar.setOnClickListener(mCancelClickListener); - - if (isAllUpdated() || Framework.nativeGetOutdatedCountries().length == 0) - { - finish(); - return; - } - - if (mAutoUpdate) - { - if (!MapManager.nativeIsDownloading()) - { - MapManager.warnOn3gUpdate(getActivity(), CountryItem.getRootId(), () -> MapManager.nativeUpdate(CountryItem.getRootId())); - } - else - { - CountryItem root = new CountryItem(CountryItem.getRootId()); - MapManager.nativeGetAttributes(root); - - updateTotalSizes(root.bytesToDownload); - setProgress(root.progress, root.downloadedBytes, root.bytesToDownload); - - updateProcessedMapInfo(); - setCommonStatus(mProcessedMapId, mCommonStatusResId); - } - } - } - - @Override - public void onPause() - { - super.onPause(); - - mProgressBar.setOnClickListener(null); - - if (mStorageCallback != null) - mStorageCallback.detach(); - } - - @Override - public void onDestroy() - { - super.onDestroy(); - } - - @Override - public void onCancel(DialogInterface dialog) - { - if (MapManager.nativeIsDownloading()) - MapManager.nativeCancel(CountryItem.getRootId()); - - if (mDoneListener != null) - mDoneListener.onDialogDone(); - - super.onCancel(dialog); - } - - private void readArguments() - { - Bundle args = getArguments(); - if (args == null) - return; - - mAutoUpdate = args.getBoolean(ARG_UPDATE_IMMEDIATELY); - if (!mAutoUpdate && MapManager.nativeIsDownloading()) - mAutoUpdate = true; - - mTotalSize = args.getString(ARG_TOTAL_SIZE); - mTotalSizeBytes = args.getLong(ARG_TOTAL_SIZE_BYTES, 0L); - mOutdatedMaps = args.getStringArray(ARG_OUTDATED_MAPS); - if (mLeftoverMaps == null && mOutdatedMaps != null && mOutdatedMaps.length > 0) - { - mLeftoverMaps = new HashSet<>(Arrays.asList(mOutdatedMaps)); - } - } - - private void initViews() - { - UiUtils.showIf(mAutoUpdate, mProgressBar, mInfo); - UiUtils.showIf(!mAutoUpdate, mUpdateBtn); - - mUpdateBtn.setText(getString(R.string.whats_new_auto_update_button_size, mTotalSize)); - mUpdateBtn.setOnClickListener(mUpdateClickListener); - mFinishBtn.setText(mAutoUpdate ? - getString(R.string.downloader_hide_screen) : - getString(R.string.whats_new_auto_update_button_later)); - mFinishBtn.setOnClickListener(mFinishClickListener); - mProgressBar.post(() -> mProgressBar.setPending(true)); - if (mAutoUpdate) - setCommonStatus(mProcessedMapId, mCommonStatusResId); - else - mTitle.setText(getString(R.string.whats_new_auto_update_title)); - } - - private boolean isAllUpdated() - { - return mOutdatedMaps == null || mLeftoverMaps == null || mLeftoverMaps.isEmpty(); - } - - @NonNull - String getRelativeStatusFormatted(int progress, long localSize, long remoteSize) - { - return getString(R.string.downloader_percent, progress + "%", - localSize / Constants.MB + getString(R.string.mb), - StringUtils.getFileSizeString(requireContext(), remoteSize)); - } - - void setProgress(int progress, long localSize, long remoteSize) - { - if (mProgressBar.isPending()) - mProgressBar.setPending(false); - - mProgressBar.setProgress(progress); - mRelativeStatus.setText(getRelativeStatusFormatted(progress, localSize, remoteSize)); - } - - void setCommonStatus(@Nullable String mwmId, @StringRes int mwmStatusResId) - { - if (mwmId == null || mwmStatusResId == Utils.INVALID_ID) - return; - - mProcessedMapId = mwmId; - mCommonStatusResId = mwmStatusResId; - - String status = getString(mwmStatusResId, MapManager.nativeGetName(mwmId)); - mTitle.setText(status); - } - - void updateTotalSizes(long totalSize) - { - mTotalSize = StringUtils.getFileSizeString(requireContext(), totalSize); - mTotalSizeBytes = totalSize; - } - - void updateProcessedMapInfo() - { - mProcessedMapId = MapManager.nativeGetCurrentDownloadingCountryId(); - - if (mProcessedMapId == null) - return; - - CountryItem processedCountryItem = new CountryItem(mProcessedMapId); - MapManager.nativeGetAttributes(processedCountryItem); - - switch (processedCountryItem.status) - { - case CountryItem.STATUS_PROGRESS: - mCommonStatusResId = R.string.downloader_process; - break; - case CountryItem.STATUS_APPLYING: - mCommonStatusResId = R.string.downloader_applying; - break; - default: - mCommonStatusResId = Utils.INVALID_ID; - break; - } - } - - public long getTotalSizeBytes() - { - return mTotalSizeBytes; - } - - private static class DetachableStorageCallback implements MapManager.StorageCallback - { - @Nullable - private UpdaterDialogFragment mFragment; - @Nullable - private final Set mLeftoverMaps; - @Nullable - private final String[] mOutdatedMaps; - private int mListenerSlot = 0; - - DetachableStorageCallback(@Nullable UpdaterDialogFragment fragment, - @Nullable Set leftoverMaps, - @Nullable String[] outdatedMaps) - { - mFragment = fragment; - mLeftoverMaps = leftoverMaps; - mOutdatedMaps = outdatedMaps; - } - - @Override - public void onStatusChanged(List data) - { - String mwmId = null; - @StringRes - int mwmStatusResId = 0; - for (MapManager.StorageCallbackData item : data) - { - if (!item.isLeafNode) - continue; - - switch (item.newStatus) - { - case CountryItem.STATUS_FAILED: - showErrorDialog(item); - return; - case CountryItem.STATUS_DONE: - LOGGER.i(TAG, "Update finished for: " + item.countryId); - if (mLeftoverMaps != null) - mLeftoverMaps.remove(item.countryId); - break; - case CountryItem.STATUS_PROGRESS: - mwmId = item.countryId; - mwmStatusResId = R.string.downloader_process; - break; - case CountryItem.STATUS_APPLYING: - mwmId = item.countryId; - mwmStatusResId = R.string.downloader_applying; - break; - default: - LOGGER.d(TAG, "Ignored status: " + item.newStatus + - ".For country: " + item.countryId); - break; - } - } - - if (isFragmentAttached()) - { - //noinspection ConstantConditions - mFragment.setCommonStatus(mwmId, mwmStatusResId); - if (mFragment.isAllUpdated()) - mFragment.finish(); - } - } - - private void showErrorDialog(MapManager.StorageCallbackData item) - { - if (!isFragmentAttached()) - return; - - String text; - switch (item.errorCode) - { - case CountryItem.ERROR_NO_INTERNET: - //noinspection ConstantConditions - text = mFragment.getString(R.string.common_check_internet_connection_dialog); - break; - - case CountryItem.ERROR_OOM: - //noinspection ConstantConditions - text = mFragment.getString(R.string.downloader_no_space_title); - break; - - default: - text = String.valueOf(item.errorCode); - } - MapManager.showErrorDialog(mFragment.getActivity(), item, result -> { - if (!isFragmentAttached()) - return; - - if (result) - { - MapManager.warnOn3gUpdate(mFragment.getActivity(), CountryItem.getRootId(), () -> MapManager.nativeUpdate(CountryItem.getRootId())); - } - else - { - MapManager.nativeCancel(CountryItem.getRootId()); - mFragment.finish(); - } - }); - } - - @Override - public void onProgress(String countryId, long localSizeBytes, long remoteSizeBytes) - { - if (!isFragmentAttached()) - return; - - CountryItem root = new CountryItem(CountryItem.getRootId()); - MapManager.nativeGetAttributes(root); - - //noinspection ConstantConditions - mFragment.setProgress(root.progress, root.downloadedBytes, root.bytesToDownload); - } - - void attach(@NonNull UpdaterDialogFragment fragment) - { - mFragment = fragment; - mListenerSlot = MapManager.nativeSubscribe(this); - } - - void detach() - { - if (mFragment == null) - throw new AssertionError("detach() should be called after attach() and only once"); - - mFragment = null; - MapManager.nativeUnsubscribe(mListenerSlot); - } - - private boolean isFragmentAttached() - { - return mFragment != null && mFragment.isAdded(); - } - } -} diff --git a/android/src/com/mapswithme/maps/editor/ViralFragment.java b/android/src/com/mapswithme/maps/editor/ViralFragment.java deleted file mode 100644 index eee7bc0260..0000000000 --- a/android/src/com/mapswithme/maps/editor/ViralFragment.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.mapswithme.maps.editor; - -import android.content.Context; -import android.content.DialogInterface; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import java.util.Random; - -import com.mapswithme.maps.MwmApplication; -import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmDialogFragment; -import com.mapswithme.util.ConnectionState; -import com.mapswithme.util.sharing.SharingHelper; - -public class ViralFragment extends BaseMwmDialogFragment -{ - private static final String EXTRA_CONGRATS_SHOWN = "CongratsShown"; - - @Nullable - private Runnable mDismissListener; - - public static boolean shouldDisplay(@NonNull Context context) - { - return !MwmApplication.prefs(context).contains(EXTRA_CONGRATS_SHOWN) && - Editor.nativeGetStats()[0] == 2 && - ConnectionState.INSTANCE.isConnected(); - } - - @Override - protected int getStyle() - { - return STYLE_NO_TITLE; - } - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) - { - MwmApplication.prefs(requireContext()).edit().putBoolean(EXTRA_CONGRATS_SHOWN, true).apply(); - return inflater.inflate(R.layout.fragment_editor_viral, null); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) - { - super.onViewCreated(view, savedInstanceState); - TextView viralTextView = view.findViewById(R.id.viral); - Context context = requireContext(); - - String viralChangesMsg = context.getString(R.string.editor_done_dialog_1); - String viralRatingMsg = context.getString(R.string.editor_done_dialog_2, getUserEditorRank()); - String viralText = new Random().nextBoolean() ? viralChangesMsg : viralRatingMsg; - viralTextView.setText(viralText); - - view.findViewById(R.id.tell_friend).setOnClickListener(v -> { - share(); - dismiss(); - if (mDismissListener != null) - mDismissListener.run(); - }); - - view.findViewById(R.id.close).setOnClickListener(v -> { - dismiss(); - if (mDismissListener != null) - mDismissListener.run(); - }); - } - - @Override - public void onCancel(@NonNull DialogInterface dialog) - { - super.onCancel(dialog); - if (mDismissListener != null) - mDismissListener.run(); - } - - public void onDismissListener(@Nullable Runnable onDismissListener) - { - mDismissListener = onDismissListener; - } - - private void share() - { - SharingHelper.shareViralEditor(getActivity(), R.string.editor_sharing_title, R.string.whatsnew_editor_message_1); - } - - // Counts fake rank in the rating of editors. - private static int getUserEditorRank() - { - return 1000 + new Random().nextInt(1000); - } -} diff --git a/android/src/com/mapswithme/maps/intent/Factory.java b/android/src/com/mapswithme/maps/intent/Factory.java index 871b34ce2e..9ee72b18cf 100644 --- a/android/src/com/mapswithme/maps/intent/Factory.java +++ b/android/src/com/mapswithme/maps/intent/Factory.java @@ -27,7 +27,6 @@ import com.mapswithme.maps.bookmarks.BookmarksPageFactory; 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.onboarding.IntroductionScreenFactory; import com.mapswithme.maps.purchase.BookmarksAllSubscriptionActivity; import com.mapswithme.maps.purchase.BookmarksSightsSubscriptionActivity; import com.mapswithme.maps.purchase.PurchaseUtils; @@ -87,18 +86,6 @@ public class Factory return new OldCoreLinkAdapterProcessor(); } - @NonNull - public static IntentProcessor createDlinkBookmarkCatalogueProcessor() - { - return new DlinkBookmarkCatalogueIntentProcessor(); - } - - @NonNull - public static IntentProcessor createDlinkBookmarkGuidesPageProcessor() - { - return new DlinkGuidesPageIntentProcessor(); - } - @NonNull public static IntentProcessor createDlinkBookmarksSubscriptionProcessor() { @@ -348,56 +335,6 @@ public class Factory } } - private static class DlinkBookmarkCatalogueIntentProcessor extends DlinkIntentProcessor - { - static final String CATALOGUE = "catalogue"; - - @Override - boolean isLinkSupported(@NonNull Uri data) - { - return (File.separator + CATALOGUE).equals(data.getPath()); - } - - @Nullable - @Override - MapTask createIntroductionTask(@NonNull String url) - { - return new FreeGuideReadyToDownloadIntroductionTask(url); - } - - @NonNull - @Override - MapTask createTargetTask(@NonNull String url) - { - return new ImportBookmarkCatalogueTask(url); - } - } - - public static class DlinkGuidesPageIntentProcessor extends DlinkIntentProcessor - { - static final String GUIDES_PAGE = "guides_page"; - - @Override - boolean isLinkSupported(@NonNull Uri data) - { - return (File.separator + GUIDES_PAGE).equals(data.getPath()); - } - - @Nullable - @Override - MapTask createIntroductionTask(@NonNull String url) - { - return new GuidesPageToOpenIntroductionTask(url); - } - - @NonNull - @Override - MapTask createTargetTask(@NonNull String url) - { - return new GuidesPageToOpenTask(url); - } - } - public static class DlinkBookmarksSubscriptionIntentProcessor extends DlinkIntentProcessor { static final String SUBSCRIPTION = "subscription"; @@ -426,6 +363,8 @@ public class Factory private static class MapsmeBookmarkCatalogueProcessor extends MapsmeProcessor { + static final String CATALOGUE = "catalogue"; + @NonNull @Override MapTask createMapTask(@NonNull String uri) @@ -433,7 +372,7 @@ public class Factory String url = Uri.parse(uri).buildUpon() .scheme(DlinkIntentProcessor.SCHEME_HTTPS) .authority(DlinkIntentProcessor.HOST) - .path(DlinkBookmarkCatalogueIntentProcessor.CATALOGUE) + .path(CATALOGUE) .build().toString(); return new ImportBookmarkCatalogueTask(url); } @@ -449,7 +388,7 @@ public class Factory return false; String host = data.getHost(); - return DlinkBookmarkCatalogueIntentProcessor.CATALOGUE.equals(host); + return CATALOGUE.equals(host); } } @@ -820,59 +759,6 @@ public class Factory } } - static class FreeGuideReadyToDownloadIntroductionTask extends BaseUrlTask - { - private static final long serialVersionUID = -6851782210156017186L; - - FreeGuideReadyToDownloadIntroductionTask(@NonNull String url) - { - super(url); - } - - @Override - public boolean run(@NonNull MwmActivity target) - { - target.showIntroductionScreenForDeeplink(getUrl(), IntroductionScreenFactory.FREE_GUIDE); - return true; - } - } - - public static class GuidesPageToOpenIntroductionTask extends BaseUrlTask - { - private static final long serialVersionUID = 8388101038319062165L; - - GuidesPageToOpenIntroductionTask(@NonNull String url) - { - super(url); - } - - @Override - public boolean run(@NonNull MwmActivity target) - { - String deeplink = convertUrlToGuidesPageDeeplink(getUrl()); - target.showIntroductionScreenForDeeplink(deeplink, IntroductionScreenFactory.GUIDES_PAGE); - return true; - } - } - - abstract static class BaseUrlTask implements MapTask - { - private static final long serialVersionUID = 9077126080900672394L; - @NonNull - private final String mUrl; - - BaseUrlTask(@NonNull String url) - { - mUrl = url; - } - - @NonNull - String getUrl() - { - return mUrl; - } - } - abstract static class UrlTaskWithStatistics implements MapTask { private static final long serialVersionUID = -8661639898700431066L; diff --git a/android/src/com/mapswithme/maps/news/OnboardingStep.java b/android/src/com/mapswithme/maps/news/OnboardingStep.java deleted file mode 100644 index 4718cf0a10..0000000000 --- a/android/src/com/mapswithme/maps/news/OnboardingStep.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.mapswithme.maps.news; - -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; -import com.mapswithme.maps.R; -import com.mapswithme.util.UiUtils; - -public enum OnboardingStep -{ - CHECK_OUT_SIGHTS(R.string.new_onboarding_step5_3_button, - R.string.later, - R.string.new_onboarding_step5_1_header, - R.string.new_onboarding_step5_3_message), - SUBSCRIBE_TO_CATALOG(R.string.new_onboarding_step5_2_button, - R.string.later, - R.string.new_onboarding_step5_1_header, - R.string.new_onboarding_step5_2_message), - DISCOVER_GUIDES(R.string.new_onboarding_step5_1_button, - R.string.later, - R.string.new_onboarding_step5_1_header, - R.string.new_onboarding_step5_1_message), - SHARE_EMOTIONS(R.string.new_onboarding_button_2, - UiUtils.NO_ID, - R.string.new_onboarding_step4_header, - R.string.new_onboarding_step4_message, - false), - EXPERIENCE(R.string.new_onboarding_button, - UiUtils.NO_ID, - R.string.new_onboarding_step3_header, - R.string.new_onboarding_step3_message, - false), - DREAM_AND_PLAN(R.string.new_onboarding_button, - UiUtils.NO_ID, - R.string.new_onboarding_step2_header, - R.string.new_onboarding_step2_message, - false), - PERMISSION_EXPLANATION(R.string.new_onboarding_button, - R.string.learn_more, - R.string.onboarding_permissions_title, - R.string.onboarding_permissions_message); - - @StringRes - private final int mAcceptButtonResId; - @StringRes - private final int mDeclineButtonResId; - @StringRes - private final int mTitle; - @StringRes - private final int mSubtitle; - - - private final boolean mDeclinedButton; - - OnboardingStep(@StringRes int acceptButtonResId, @StringRes int declineButtonResId, - @StringRes int title, @StringRes int subtitle) - { - - this(acceptButtonResId, declineButtonResId, title, subtitle,true); - } - - OnboardingStep(@StringRes int acceptButtonResId, @StringRes int declineButtonResId, - @StringRes int title, @StringRes int subtitle, - boolean hasDeclinedButton) - { - mAcceptButtonResId = acceptButtonResId; - mDeclineButtonResId = declineButtonResId; - mTitle = title; - mSubtitle = subtitle; - mDeclinedButton = hasDeclinedButton; - } - - @StringRes - public int getAcceptButtonResId() - { - return mAcceptButtonResId; - } - - @StringRes - public int getTitle() - { - return mTitle; - } - - @StringRes - public int getSubtitle() - { - return mSubtitle; - } - - @DrawableRes - public int getImage() - { - return 0; - } - - public boolean hasDeclinedButton() - { - return mDeclinedButton; - } - - @StringRes - public int getDeclinedButtonResId() - { - if (!hasDeclinedButton()) - throw new UnsupportedOperationException("Value : " + name()); - - return mDeclineButtonResId; - } -} diff --git a/android/src/com/mapswithme/maps/onboarding/BaseNewsFragment.java b/android/src/com/mapswithme/maps/onboarding/BaseNewsFragment.java deleted file mode 100644 index e14597440b..0000000000 --- a/android/src/com/mapswithme/maps/onboarding/BaseNewsFragment.java +++ /dev/null @@ -1,427 +0,0 @@ -package com.mapswithme.maps.onboarding; - -import android.app.Dialog; -import android.content.Context; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.view.Window; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.ArrayRes; -import androidx.annotation.CallSuper; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StyleRes; -import androidx.appcompat.widget.SwitchCompat; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; -import androidx.viewpager.widget.PagerAdapter; -import androidx.viewpager.widget.ViewPager; -import com.mapswithme.maps.BuildConfig; -import com.mapswithme.maps.MwmApplication; -import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmDialogFragment; -import com.mapswithme.util.ThemeUtils; -import com.mapswithme.util.UiUtils; -import com.mapswithme.util.Utils; - -import java.util.ArrayList; -import java.util.List; - -public abstract class BaseNewsFragment extends BaseMwmDialogFragment -{ - @ArrayRes - static final int TITLE_KEYS = R.array.news_title_keys; - private ViewPager mPager; - private View mPrevButton; - private View mNextButton; - private View mDoneButton; - private ImageView[] mDots; - - private int mPageCount; - - @Nullable - private NewsDialogListener mListener; - - abstract class Adapter extends PagerAdapter - { - @NonNull - private final int[] mImages; - @NonNull - private final String[] mTitles; - @NonNull - private final String[] mSubtitles; - @NonNull - private final List mPromoButtons; - @NonNull - private final String[] mSwitchTitles; - @NonNull - private final String[] mSwitchSubtitles; - - Adapter() - { - Resources res = MwmApplication.from(requireContext()).getResources(); - - mTitles = getTitles(res); - mSubtitles = res.getStringArray(getSubtitles1()); - - int subtitles2 = getSubtitles2(); - if (subtitles2 != 0) - { - String[] strings = res.getStringArray(subtitles2); - for (int i = 0; i < mSubtitles.length; i++) - { - String s = strings[i]; - if (!TextUtils.isEmpty(s)) - mSubtitles[i] += "\n\n" + s; - } - } - - mPromoButtons = getPromoButtons(res); - mSwitchTitles = res.getStringArray(getSwitchTitles()); - mSwitchSubtitles = res.getStringArray(getSwitchSubtitles()); - - TypedArray images = res.obtainTypedArray(getImages()); - mImages = new int[images.length()]; - for (int i = 0; i < mImages.length; i++) - mImages[i] = images.getResourceId(i, 0); - - images.recycle(); - } - - @NonNull - private String[] getTitles(@NonNull Resources res) - { - String[] keys = res.getStringArray(getTitleKeys()); - final int length = keys.length; - if (length == 0) - throw new AssertionError("Title keys must me non-empty!"); - - String[] titles = new String[length]; - for (int i = 0; i < length; i++) - titles[i] = Utils.getStringValueByKey(getContext(), keys[i]); - - return titles; - } - - @ArrayRes - abstract int getTitleKeys(); - @ArrayRes - abstract int getSubtitles1(); - @ArrayRes - abstract int getSubtitles2(); - @ArrayRes - abstract int getButtonLabels(); - @ArrayRes - abstract int getButtonLinks(); - @ArrayRes - abstract int getSwitchTitles(); - @ArrayRes - abstract int getSwitchSubtitles(); - @ArrayRes - abstract int getImages(); - - @Override - public int getCount() - { - return mImages.length; - } - - @Override - public boolean isViewFromObject(View view, Object object) - { - return (view == object); - } - - @Override - public Object instantiateItem(ViewGroup container, final int position) - { - View res = LayoutInflater.from(container.getContext()).inflate(R.layout.news_page, container, false); - - ((ImageView)res.findViewById(R.id.image)) - .setImageResource(mImages[position]); - - ((TextView)res.findViewById(R.id.title)) - .setText(mTitles[position]); - - ((TextView)res.findViewById(R.id.subtitle)) - .setText(mSubtitles[position]); - - processSwitchBlock(position, res); - processButton(position, res); - - container.addView(res); - return res; - } - - @NonNull - private List getPromoButtons(@NonNull Resources res) - { - String[] labels = res.getStringArray(getButtonLabels()); - String[] links = res.getStringArray(getButtonLinks()); - - if (labels.length != links.length) - throw new AssertionError("Button labels count must be equal to links count!"); - - List result = new ArrayList<>(); - for (int i = 0; i < labels.length; i++) - result.add(new PromoButton(labels[i], links[i])); - - return result; - } - - private void processSwitchBlock(int position, @NonNull View res) - { - View switchBlock = res.findViewById(R.id.switch_block); - String text = mSwitchTitles[position]; - if (TextUtils.isEmpty(text)) - UiUtils.hide(switchBlock); - else - { - ((TextView)switchBlock.findViewById(R.id.switch_title)) - .setText(text); - - TextView subtitle = switchBlock.findViewById(R.id.switch_subtitle); - if (TextUtils.isEmpty(mSwitchSubtitles[position])) - UiUtils.hide(subtitle); - else - subtitle.setText(mSwitchSubtitles[position]); - - final SwitchCompat checkBox = switchBlock.findViewById(R.id.switch_box); - checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> onSwitchChanged(position, isChecked)); - - switchBlock.setOnClickListener(v -> checkBox.performClick()); - } - } - - private void processButton(int position, @NonNull View res) - { - final TextView button = res.findViewById(R.id.button); - PromoButton promo = mPromoButtons.get(position); - if (promo == null || TextUtils.isEmpty(promo.getLabel())) - { - UiUtils.hide(button); - return; - } - - button.setText(promo.getLabel()); - button.setOnClickListener(v -> onPromoButtonClicked(button)); - } - - abstract void onPromoButtonClicked(@NonNull View view); - - @Override - public void destroyItem(ViewGroup container, int position, Object object) - { - container.removeView((View)object); - } - } - - void onSwitchChanged(int index, boolean isChecked) {} - - private void update() - { - int cur = mPager.getCurrentItem(); - UiUtils.showIf(cur > 0, mPrevButton); - UiUtils.showIf(cur + 1 < mPageCount, mNextButton); - UiUtils.visibleIf(cur + 1 == mPageCount, mDoneButton); - - if (mPageCount == 1) - return; - - for (int i = 0; i < mPageCount; i++) - { - mDots[i].setImageResource(ThemeUtils.isNightTheme(requireContext()) ? i == cur ? R.drawable.news_marker_active_night - : R.drawable.news_marker_inactive_night - : i == cur ? R.drawable.news_marker_active - : R.drawable.news_marker_inactive); - } - } - - private void fixPagerSize() - { - Context context = requireContext(); - - if (!UiUtils.isTablet(context)) - return; - - UiUtils.waitLayout(mPager, () -> { - int maxWidth = UiUtils.dimen(context, R.dimen.news_max_width); - int maxHeight = UiUtils.dimen(context, R.dimen.news_max_height); - - if (mPager.getWidth() > maxWidth || mPager.getHeight() > maxHeight) - { - mPager.setLayoutParams(new LinearLayout.LayoutParams(Math.min(maxWidth, mPager.getWidth()), - Math.min(maxHeight, mPager.getHeight()))); - } - }); - } - - abstract Adapter createAdapter(); - - @Override - protected int getCustomTheme() - { - return (UiUtils.isTablet(requireContext()) ? super.getCustomTheme() - : getFullscreenTheme()); - } - - @StyleRes - @Override - protected int getFullscreenLightTheme() - { - return R.style.MwmTheme_DialogFragment_NoFullscreen; - } - - @StyleRes - @Override - protected int getFullscreenDarkTheme() - { - return R.style.MwmTheme_DialogFragment_NoFullscreen_Night; - } - - @Override - public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) - { - Dialog res = super.onCreateDialog(savedInstanceState); - res.requestWindowFeature(Window.FEATURE_NO_TITLE); - - View content = View.inflate(getActivity(), R.layout.fragment_news, null); - res.setContentView(content); - - mPager = content.findViewById(R.id.pager); - fixPagerSize(); - - Adapter adapter = createAdapter(); - mPageCount = adapter.getCount(); - mPager.setAdapter(adapter); - mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() - { - @Override - public void onPageSelected(int position) - { - update(); - } - }); - - ViewGroup dots = content.findViewById(R.id.dots); - if (mPageCount == 1) - UiUtils.hide(dots); - else - { - int dotCount = dots.getChildCount(); - mDots = new ImageView[mPageCount]; - for (int i = 0; i < dotCount; i++) - { - ImageView dot = (ImageView)dots.getChildAt(i); - - if (i < (dotCount - mPageCount)) - UiUtils.hide(dot); - else - mDots[i - (dotCount - mPageCount)] = dot; - } - } - - mPrevButton = content.findViewById(R.id.back); - mNextButton = content.findViewById(R.id.next); - mDoneButton = content.findViewById(R.id.done); - - mPrevButton.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - mPager.setCurrentItem(mPager.getCurrentItem() - 1, true); - } - }); - - mNextButton.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - mPager.setCurrentItem(mPager.getCurrentItem() + 1, true); - } - }); - - mDoneButton.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - onDoneClick(); - } - }); - - update(); - - return res; - } - - @CallSuper - protected void onDoneClick() - { - dismissAllowingStateLoss(); - if (mListener != null) - mListener.onDialogDone(); - } - - @SuppressWarnings("TryWithIdenticalCatches") - static void create(@NonNull FragmentActivity activity, - @NonNull Class clazz, - @Nullable NewsDialogListener listener) - { - try - { - final BaseNewsFragment fragment = clazz.newInstance(); - fragment.mListener = listener; - activity.getSupportFragmentManager() - .beginTransaction() - .add(fragment, clazz.getName()) - .commitAllowingStateLoss(); - } catch (java.lang.InstantiationException ignored) - {} - catch (IllegalAccessException ignored) - {} - } - - static boolean recreate(FragmentActivity activity, Class clazz) - { - FragmentManager fm = activity.getSupportFragmentManager(); - Fragment f = fm.findFragmentByTag(clazz.getName()); - if (f == null) - return false; - - // If we're here, it means that the user has rotated the screen. - // We use different dialog themes for landscape and portrait modes on tablets, - // so the fragment should be recreated to be displayed correctly. - fm.beginTransaction().remove(f).commitAllowingStateLoss(); - fm.executePendingTransactions(); - return true; - } - - @Nullable - protected NewsDialogListener getListener() - { - return mListener; - } - - void resetListener(@Nullable NewsDialogListener listener) - { - mListener = listener; - } - - public interface NewsDialogListener - { - void onDialogDone(); - } -} diff --git a/android/src/com/mapswithme/maps/onboarding/IntroductionDialogFragment.java b/android/src/com/mapswithme/maps/onboarding/IntroductionDialogFragment.java deleted file mode 100644 index 96033a1372..0000000000 --- a/android/src/com/mapswithme/maps/onboarding/IntroductionDialogFragment.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.mapswithme.maps.onboarding; - -import android.app.Dialog; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.fragment.app.FragmentManager; -import android.text.TextUtils; -import android.view.View; -import android.widget.TextView; - -import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmDialogFragment; -import com.mapswithme.util.UiUtils; - -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); - IntroductionScreenFactory factory = getScreenFactory(); - TextView button = content.findViewById(R.id.accept_btn); - button.setText(factory.getAction()); - button.setOnClickListener(v -> onAcceptClicked()); -// ImageView image = content.findViewById(R.id.iv__image); -// image.setImageResource(factory.getImage()); - TextView title = content.findViewById(R.id.tv__title); - title.setText(factory.getTitle()); - TextView subtitle = content.findViewById(R.id.tv__subtitle1); - subtitle.setText(factory.getSubtitle()); - UiUtils.hide(content, R.id.decline_btn); - - return res; - } - - @NonNull - private IntroductionScreenFactory getScreenFactory() - { - Bundle args = getArgumentsOrThrow(); - int dataIndex = args.getInt(ARG_INTRODUCTION_FACTORY); - return IntroductionScreenFactory.values()[dataIndex]; - } - - private void onAcceptClicked() - { - String deepLink = getArgumentsOrThrow().getString(ARG_DEEPLINK); - if (TextUtils.isEmpty(deepLink)) - throw new AssertionError("Deeplink must non-empty within introduction fragment!"); - IntroductionScreenFactory factory = getScreenFactory(); - factory.createButtonClickListener().onIntroductionButtonClick(requireActivity(), deepLink); - dismissAllowingStateLoss(); - } - - @Override - protected int getCustomTheme() - { - return getFullscreenTheme(); - } -} diff --git a/android/src/com/mapswithme/maps/onboarding/IntroductionScreenFactory.java b/android/src/com/mapswithme/maps/onboarding/IntroductionScreenFactory.java deleted file mode 100644 index a95d52e1b5..0000000000 --- a/android/src/com/mapswithme/maps/onboarding/IntroductionScreenFactory.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.mapswithme.maps.onboarding; - -import android.app.Activity; - -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; -import com.mapswithme.maps.R; -import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity; -import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity; -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 0; - } - - @NonNull - @Override - public OnIntroductionButtonClickListener createButtonClickListener() - { - return (activity, deeplink) -> BookmarkCategoriesActivity.startForResult(activity, - BookmarksPageFactory.DOWNLOADED.ordinal(), - deeplink); - } - }, - GUIDES_PAGE - { - @Override - public int getTitle() - { - return R.string.onboarding_bydeeplink_guide_title; - } - - @Override - public int getSubtitle() - { - return R.string.onboarding_bydeeplink_guide_subtitle; - } - - @Override - public int getAction() - { - return R.string.onboarding_guide_direct_download_button; - } - - @Override - public int getImage() - { - return 0; - } - - @NonNull - @Override - public OnIntroductionButtonClickListener createButtonClickListener() - { - return (activity, deeplink) -> BookmarksCatalogActivity.startForResult(activity, - BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY, - 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/onboarding/NewsFragment.java b/android/src/com/mapswithme/maps/onboarding/NewsFragment.java deleted file mode 100644 index 154c6f0270..0000000000 --- a/android/src/com/mapswithme/maps/onboarding/NewsFragment.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.mapswithme.maps.onboarding; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; -import com.mapswithme.maps.BuildConfig; -import com.mapswithme.maps.Framework; -import com.mapswithme.maps.R; -import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity; -import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity; -import com.mapswithme.maps.bookmarks.data.BookmarkCategory; -import com.mapswithme.maps.bookmarks.data.BookmarkManager; -import com.mapswithme.maps.dialog.AlertDialogCallback; -import com.mapswithme.maps.downloader.UpdaterDialogFragment; -import com.mapswithme.maps.purchase.BookmarkAllSubscriptionData; -import com.mapswithme.maps.purchase.BookmarksAllSubscriptionActivity; -import com.mapswithme.maps.purchase.PurchaseUtils; -import com.mapswithme.util.Counters; -import com.mapswithme.util.SharedPropertiesUtils; -import com.mapswithme.util.UTM; -import com.mapswithme.util.UiUtils; - -import static com.mapswithme.maps.purchase.BookmarksAllSubscriptionPage.BOOKMARKS; -import static com.mapswithme.maps.purchase.BookmarksAllSubscriptionPage.ELEVATION; -import static com.mapswithme.maps.purchase.BookmarksAllSubscriptionPage.GUIDES; -import static com.mapswithme.maps.purchase.BookmarksAllSubscriptionPage.LONELY; - -public class NewsFragment extends BaseNewsFragment implements AlertDialogCallback -{ - private class Adapter extends BaseNewsFragment.Adapter - { - @Override - int getTitleKeys() - { - return TITLE_KEYS; - } - - @Override - int getSubtitles1() - { - return R.array.news_messages_1; - } - - @Override - int getSubtitles2() - { - return R.array.news_messages_2; - } - - @Override - int getButtonLabels() - { - return R.array.news_button_labels; - } - - @Override - int getButtonLinks() - { - return R.array.news_button_links; - } - - @Override - int getSwitchTitles() - { - return R.array.news_switch_titles; - } - - @Override - int getSwitchSubtitles() - { - return R.array.news_switch_subtitles; - } - - @Override - int getImages() - { - return R.array.news_images; - } - - @Override - void onPromoButtonClicked(@NonNull View view) - { - UiUtils.hide(view); - BookmarksAllSubscriptionActivity.startForResult(NewsFragment.this, - PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION, - new BookmarkAllSubscriptionData(LONELY, - GUIDES, - BOOKMARKS, - ELEVATION)); - } - } - - @Override - BaseNewsFragment.Adapter createAdapter() - { - return new Adapter(); - } - - @Override - protected void onDoneClick() - { - if (!UpdaterDialogFragment.showOn(getActivity(), getListener())) - super.onDoneClick(); - else - dismissAllowingStateLoss(); - } - - /** - * Displays "What's new" dialog on given {@code activity}. Or not. - * @return whether "What's new" dialog should be shown. - */ - public static boolean showOn(@NonNull FragmentActivity activity, - final @Nullable NewsDialogListener listener) - { - Context context = activity.getApplicationContext(); - - if (Counters.getFirstInstallVersion(context) >= BuildConfig.VERSION_CODE) - return false; - - FragmentManager fm = activity.getSupportFragmentManager(); - if (fm.isDestroyed()) - return false; - - Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName()); - if (f != null) - return UpdaterDialogFragment.showOn(activity, listener); - - f = fm.findFragmentByTag(NewsFragment.class.getName()); - if (f != null) - { - NewsFragment newsFragment = (NewsFragment) f; - newsFragment.resetListener(listener); - return true; - } - - String currentTitle = getCurrentTitleConcatenation(context); - String oldTitle = SharedPropertiesUtils.getWhatsNewTitleConcatenation(context); - if (currentTitle.equals(oldTitle) && !recreate(activity, NewsFragment.class)) - return false; - - create(activity, NewsFragment.class, listener); - - Counters.setWhatsNewShown(context); - SharedPropertiesUtils.setWhatsNewTitleConcatenation(context, currentTitle); - Counters.setShowReviewForOldUser(context, true); - - return true; - } - - @NonNull - private static String getCurrentTitleConcatenation(@NonNull Context context) - { - String[] keys = context.getResources().getStringArray(TITLE_KEYS); - final int length = keys.length; - if (length == 0) - return ""; - - StringBuilder sb = new StringBuilder(); - for (String key : keys) - sb.append(key); - - return sb.toString().trim(); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) - { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode != Activity.RESULT_OK) - return; - - switch (requestCode) - { - case PurchaseUtils.REQ_CODE_PAY_SUBSCRIPTION: - PurchaseUtils.showSubscriptionSuccessDialog(this, - PurchaseUtils.DIALOG_TAG_BMK_SUBSCRIPTION_SUCCESS, - PurchaseUtils.REQ_CODE_BMK_SUBS_SUCCESS_DIALOG); - break; - case BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY: - if (data == null) - break; - - BookmarkCategory category - = data.getParcelableExtra(BookmarksCatalogActivity.EXTRA_DOWNLOADED_CATEGORY); - - if (category == null) - throw new IllegalArgumentException("Category not found in bundle"); - Framework.nativeShowBookmarkCategory(category.getId()); - break; - } - } - - @Override - public void onAlertDialogPositiveClick(int requestCode, int which) - { - if (requestCode == PurchaseUtils.REQ_CODE_BMK_SUBS_SUCCESS_DIALOG) - BookmarksCatalogActivity.startForResult(this, - BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY, - BookmarkManager.INSTANCE.getCatalogFrontendUrl(UTM.UTM_NONE)); - } - - @Override - public void onAlertDialogNegativeClick(int requestCode, int which) - { - // No op. - } - - @Override - public void onAlertDialogCancel(int requestCode) - { - // No op. - } -} diff --git a/android/src/com/mapswithme/maps/onboarding/OnIntroductionButtonClickListener.java b/android/src/com/mapswithme/maps/onboarding/OnIntroductionButtonClickListener.java deleted file mode 100644 index f8d6593363..0000000000 --- a/android/src/com/mapswithme/maps/onboarding/OnIntroductionButtonClickListener.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mapswithme.maps.onboarding; - -import android.app.Activity; -import androidx.annotation.NonNull; - -public interface OnIntroductionButtonClickListener -{ - void onIntroductionButtonClick(@NonNull Activity activity, @NonNull String deeplink); -} diff --git a/android/src/com/mapswithme/maps/onboarding/PromoButton.java b/android/src/com/mapswithme/maps/onboarding/PromoButton.java deleted file mode 100644 index a724e53667..0000000000 --- a/android/src/com/mapswithme/maps/onboarding/PromoButton.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mapswithme.maps.onboarding; - -import androidx.annotation.NonNull; - -class PromoButton -{ - @NonNull - private final String mLabel; - @NonNull - private final String mLink; - - PromoButton(@NonNull String label, @NonNull String link) - { - mLabel = label; - mLink = link; - } - - @NonNull - String getLink() - { - return mLink; - } - - @NonNull - String getLabel() - { - return mLabel; - } -} diff --git a/android/src/com/mapswithme/maps/permissions/PermissionsDialogFragment.java b/android/src/com/mapswithme/maps/permissions/PermissionsDialogFragment.java index cfd35065a1..83f482b35f 100644 --- a/android/src/com/mapswithme/maps/permissions/PermissionsDialogFragment.java +++ b/android/src/com/mapswithme/maps/permissions/PermissionsDialogFragment.java @@ -17,7 +17,6 @@ import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import com.mapswithme.maps.R; -import com.mapswithme.maps.news.OnboardingStep; public class PermissionsDialogFragment extends BasePermissionsDialogFragment {