diff --git a/android/app/proguard-mwm.txt b/android/app/proguard-mwm.txt index 65cebc8c05..b874cafb47 100644 --- a/android/app/proguard-mwm.txt +++ b/android/app/proguard-mwm.txt @@ -6,14 +6,6 @@ # Also remove everything else what is not needed. -keep class !android.support.v7.internal.view.menu.**,** {*;} -# Gson support --keep class app.organicmaps.util.Gsonable --keep class * implements app.organicmaps.util.Gsonable - --keepclassmembernames class * implements app.organicmaps.util.Gsonable { - !transient ; -} - # Enabling shrinking causes # Execution failed for task ':minifyFdroidReleaseWithR8'. # > com.android.tools.r8.CompilationFailedException: Compilation failed to complete @@ -22,14 +14,6 @@ # It requires to manually mark all methods and classes called from NDK. -dontoptimize --keepnames class * implements app.organicmaps.util.Gsonable { - !transient ; -} - --keepclassmembers class * implements app.organicmaps.util.Gsonable { - (...); -} - -dontwarn com.google.android.material.** -keep class com.google.android.material.** { *; } diff --git a/android/app/src/main/java/app/organicmaps/ChartController.java b/android/app/src/main/java/app/organicmaps/ChartController.java index f62360f2ad..7d64e44a6b 100644 --- a/android/app/src/main/java/app/organicmaps/ChartController.java +++ b/android/app/src/main/java/app/organicmaps/ChartController.java @@ -21,8 +21,7 @@ import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.formatter.ValueFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; -import app.organicmaps.base.Hideable; -import app.organicmaps.base.Initializable; + import app.organicmaps.bookmarks.data.BookmarkManager; import app.organicmaps.bookmarks.data.ElevationInfo; import app.organicmaps.widget.placepage.AxisValueFormatter; @@ -37,10 +36,9 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -public class ChartController implements OnChartValueSelectedListener, Initializable, +public class ChartController implements OnChartValueSelectedListener, BookmarkManager.OnElevationActivePointChangedListener, - BookmarkManager.OnElevationCurrentPositionChangedListener, - Hideable + BookmarkManager.OnElevationCurrentPositionChangedListener { private static final int CHART_Y_LABEL_COUNT = 3; private static final int CHART_X_LABEL_COUNT = 6; @@ -75,10 +73,8 @@ public class ChartController implements OnChartValueSelectedListener, Initializa mContext = context; } - @Override - public void initialize(@Nullable View view) + public void initialize(@NonNull View view) { - Objects.requireNonNull(view); BookmarkManager.INSTANCE.setElevationActivePointChangedListener(this); BookmarkManager.INSTANCE.setElevationCurrentPositionChangedListener(this); final Resources resources = mContext.getResources(); @@ -110,7 +106,6 @@ public class ChartController implements OnChartValueSelectedListener, Initializa initAxises(); } - @Override public void destroy() { BookmarkManager.INSTANCE.setElevationActivePointChangedListener(null); @@ -253,7 +248,6 @@ public class ChartController implements OnChartValueSelectedListener, Initializa return new Highlight((float) activeX, 0f, 0); } - @Override public void onHide() { mChart.fitScreen(); diff --git a/android/app/src/main/java/app/organicmaps/MwmActivity.java b/android/app/src/main/java/app/organicmaps/MwmActivity.java index 4ee518394e..340ab3bed0 100644 --- a/android/app/src/main/java/app/organicmaps/MwmActivity.java +++ b/android/app/src/main/java/app/organicmaps/MwmActivity.java @@ -41,8 +41,6 @@ import androidx.lifecycle.ViewModelProvider; import app.organicmaps.Framework.PlacePageActivationListener; import app.organicmaps.api.Const; import app.organicmaps.base.BaseMwmFragmentActivity; -import app.organicmaps.base.CustomNavigateUpListener; -import app.organicmaps.base.NoConnectionListener; import app.organicmaps.base.OnBackPressListener; import app.organicmaps.bookmarks.BookmarkCategoriesActivity; import app.organicmaps.bookmarks.data.BookmarkInfo; @@ -125,7 +123,6 @@ public class MwmActivity extends BaseMwmFragmentActivity implements PlacePageActivationListener, View.OnTouchListener, MapRenderingListener, - CustomNavigateUpListener, RoutingController.Container, LocationListener, SensorListener, @@ -134,7 +131,6 @@ public class MwmActivity extends BaseMwmFragmentActivity RoutingBottomMenuListener, BookmarkManager.BookmarksLoadingListener, FloatingSearchToolbarController.SearchToolbarListener, - NoConnectionListener, MenuBottomSheetFragment.MenuBottomSheetInterfaceWithHeader, PlacePageController.PlacePageRouteSettingsListener, MapButtonsController.MapButtonClickListener, @@ -515,18 +511,6 @@ public class MwmActivity extends BaseMwmFragmentActivity return info == null ? 0 : info.filesCount; } - @Override - public void onNoConnectionError() - { - dismissAlertDialog(); - mAlertDialog = new MaterialAlertDialogBuilder(this, R.style.MwmTheme_AlertDialog) - .setTitle(R.string.common_check_internet_connection_dialog_title) - .setMessage(R.string.common_check_internet_connection_dialog) - .setPositiveButton(R.string.ok, null) - .setOnDismissListener(dialog -> mAlertDialog = null) - .show(); - } - private void initViews(boolean isLaunchByDeeplink) { initMap(isLaunchByDeeplink); @@ -1257,7 +1241,6 @@ public class MwmActivity extends BaseMwmFragmentActivity return mMapFragment != null && mMapFragment.onTouch(view, event); } - @Override public void customOnNavigateUp() { if (removeCurrentFragment(true)) diff --git a/android/app/src/main/java/app/organicmaps/MwmApplication.java b/android/app/src/main/java/app/organicmaps/MwmApplication.java index 9fcc4f2a9b..9c96aec67d 100644 --- a/android/app/src/main/java/app/organicmaps/MwmApplication.java +++ b/android/app/src/main/java/app/organicmaps/MwmApplication.java @@ -20,7 +20,6 @@ import androidx.lifecycle.ProcessLifecycleOwner; import app.organicmaps.background.OsmUploadWork; import app.organicmaps.downloader.DownloaderNotifier; -import app.organicmaps.base.MediaPlayerWrapper; import app.organicmaps.bookmarks.data.BookmarkManager; import app.organicmaps.display.DisplayManager; import app.organicmaps.downloader.CountryItem; @@ -82,7 +81,6 @@ public class MwmApplication extends Application implements Application.ActivityL private final Object mMainQueueToken = new Object(); @NonNull private final MapManager.StorageCallback mStorageCallbacks = new StorageCallbackImpl(); - private MediaPlayerWrapper mPlayer; @Nullable private WeakReference mTopActivity; @@ -167,7 +165,6 @@ public class MwmApplication extends Application implements Application.ActivityL mIsolinesManager = new IsolinesManager(this); mLocationHelper = new LocationHelper(this); mSensorHelper = new SensorHelper(this); - mPlayer = new MediaPlayerWrapper(this); mDisplayManager = new DisplayManager(); } @@ -238,14 +235,14 @@ public class MwmApplication extends Application implements Application.ActivityL initNativeStrings(); ThemeSwitcher.INSTANCE.initialize(this); - SearchEngine.INSTANCE.initialize(null); + SearchEngine.INSTANCE.initialize(); BookmarkManager.loadBookmarks(); TtsPlayer.INSTANCE.initialize(this); ThemeSwitcher.INSTANCE.restart(false); RoutingController.get().initialize(this); - TrafficManager.INSTANCE.initialize(null); - SubwayManager.from(this).initialize(null); - IsolinesManager.from(this).initialize(null); + TrafficManager.INSTANCE.initialize(); + SubwayManager.from(this).initialize(); + IsolinesManager.from(this).initialize(); ProcessLifecycleOwner.get().getLifecycle().addObserver(mProcessLifecycleObserver); Logger.i(TAG, "Framework initialized"); @@ -288,12 +285,6 @@ public class MwmApplication extends Application implements Application.ActivityL mMainLoopHandler.sendMessage(m); } - @NonNull - public MediaPlayerWrapper getMediaPlayer() - { - return mPlayer; - } - private static native void nativeSetSettingsDir(String settingsPath); private native void nativeInitPlatform(String apkPath, String writablePath, String privatePath, String tmpPath, String flavorName, String buildType, diff --git a/android/app/src/main/java/app/organicmaps/base/BaseAsyncOperationFragment.java b/android/app/src/main/java/app/organicmaps/base/BaseAsyncOperationFragment.java deleted file mode 100644 index 61ab909a35..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/BaseAsyncOperationFragment.java +++ /dev/null @@ -1,38 +0,0 @@ -package app.organicmaps.base; - -import androidx.annotation.StringRes; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentManager; - -import app.organicmaps.R; -import app.organicmaps.dialog.ProgressDialogFragment; - -public abstract class BaseAsyncOperationFragment extends BaseMwmFragment -{ - private static final String PROGRESS_DIALOG_TAG = "base_progress_dialog"; - - protected void showProgress() - { - final int resId = getProgressMessageId(); - final String title = getString(resId); - final ProgressDialogFragment dialog = ProgressDialogFragment.newInstance(title); - getParentFragmentManager() - .beginTransaction() - .add(dialog, PROGRESS_DIALOG_TAG) - .commitAllowingStateLoss(); - } - - @StringRes - protected int getProgressMessageId() - { - return R.string.downloading; - } - - protected void hideProgress() - { - final FragmentManager fm = getParentFragmentManager(); - final DialogFragment frag = (DialogFragment) fm.findFragmentByTag(PROGRESS_DIALOG_TAG); - if (frag != null) - frag.dismissAllowingStateLoss(); - } -} diff --git a/android/app/src/main/java/app/organicmaps/base/BaseMwmToolbarFragment.java b/android/app/src/main/java/app/organicmaps/base/BaseMwmToolbarFragment.java index 075ea07c98..fd22f57f39 100644 --- a/android/app/src/main/java/app/organicmaps/base/BaseMwmToolbarFragment.java +++ b/android/app/src/main/java/app/organicmaps/base/BaseMwmToolbarFragment.java @@ -5,10 +5,15 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.FragmentManager; +import app.organicmaps.R; +import app.organicmaps.dialog.ProgressDialogFragment; import app.organicmaps.widget.ToolbarController; -public class BaseMwmToolbarFragment extends BaseAsyncOperationFragment +public class BaseMwmToolbarFragment extends BaseMwmFragment { @SuppressWarnings("NullableProblems") @NonNull diff --git a/android/app/src/main/java/app/organicmaps/base/CustomNavigateUpListener.java b/android/app/src/main/java/app/organicmaps/base/CustomNavigateUpListener.java deleted file mode 100644 index a5b8b2cb68..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/CustomNavigateUpListener.java +++ /dev/null @@ -1,10 +0,0 @@ -package app.organicmaps.base; - -/** - * Interface for activities to implement to perform custom 'up' navigation - * (when up arrow in actionbar/toolbar is pressed) - */ -public interface CustomNavigateUpListener -{ - void customOnNavigateUp(); -} diff --git a/android/app/src/main/java/app/organicmaps/base/DataChangedListener.java b/android/app/src/main/java/app/organicmaps/base/DataChangedListener.java deleted file mode 100644 index c436f089ec..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/DataChangedListener.java +++ /dev/null @@ -1,6 +0,0 @@ -package app.organicmaps.base; - -public interface DataChangedListener extends Detachable -{ - void onChanged(); -} diff --git a/android/app/src/main/java/app/organicmaps/base/Detachable.java b/android/app/src/main/java/app/organicmaps/base/Detachable.java deleted file mode 100644 index 5fb1a93fc7..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/Detachable.java +++ /dev/null @@ -1,9 +0,0 @@ -package app.organicmaps.base; - -import androidx.annotation.NonNull; - -public interface Detachable -{ - void attach(@NonNull T object); - void detach(); -} diff --git a/android/app/src/main/java/app/organicmaps/base/Hideable.java b/android/app/src/main/java/app/organicmaps/base/Hideable.java deleted file mode 100644 index 9b2773f0ba..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/Hideable.java +++ /dev/null @@ -1,6 +0,0 @@ -package app.organicmaps.base; - -public interface Hideable -{ - void onHide(); -} diff --git a/android/app/src/main/java/app/organicmaps/base/Initializable.java b/android/app/src/main/java/app/organicmaps/base/Initializable.java deleted file mode 100644 index 0c1eed2b33..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/Initializable.java +++ /dev/null @@ -1,9 +0,0 @@ -package app.organicmaps.base; - -import androidx.annotation.Nullable; - -public interface Initializable -{ - void initialize(@Nullable T t); - void destroy(); -} diff --git a/android/app/src/main/java/app/organicmaps/base/NoConnectionListener.java b/android/app/src/main/java/app/organicmaps/base/NoConnectionListener.java deleted file mode 100644 index 239405995d..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/NoConnectionListener.java +++ /dev/null @@ -1,6 +0,0 @@ -package app.organicmaps.base; - -public interface NoConnectionListener -{ - void onNoConnectionError(); -} diff --git a/android/app/src/main/java/app/organicmaps/base/Observable.java b/android/app/src/main/java/app/organicmaps/base/Observable.java deleted file mode 100644 index f526ba5faf..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/Observable.java +++ /dev/null @@ -1,35 +0,0 @@ -package app.organicmaps.base; - -import androidx.annotation.NonNull; - -import java.util.ArrayList; -import java.util.List; - -public abstract class Observable -{ - @NonNull - private final List mListeners = new ArrayList<>(); - - public void registerListener(@NonNull T listener) - { - if (mListeners.contains(listener)) - throw new IllegalStateException("Observer " + listener + " is already registered."); - - mListeners.add(listener); - } - - public void unregisterListener(@NonNull T listener) - { - int index = mListeners.indexOf(listener); - if (index == -1) - throw new IllegalStateException("Observer " + listener + " was not registered."); - - mListeners.remove(index); - } - - protected void notifyChanged() - { - for (T item : mListeners) - item.onChanged(); - } -} diff --git a/android/app/src/main/java/app/organicmaps/base/Savable.java b/android/app/src/main/java/app/organicmaps/base/Savable.java deleted file mode 100644 index 8686f082f4..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/Savable.java +++ /dev/null @@ -1,9 +0,0 @@ -package app.organicmaps.base; - -import androidx.annotation.NonNull; - -public interface Savable -{ - void onSave(@NonNull T outState); - void onRestore(@NonNull T inState); -} diff --git a/android/app/src/main/java/app/organicmaps/base/Supportable.java b/android/app/src/main/java/app/organicmaps/base/Supportable.java deleted file mode 100644 index 509986770f..0000000000 --- a/android/app/src/main/java/app/organicmaps/base/Supportable.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.organicmaps.base; - -import androidx.annotation.NonNull; - -public interface Supportable -{ - boolean support(@NonNull T object); -} diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java index c040bd84f7..d6ea736a37 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java @@ -21,7 +21,6 @@ import app.organicmaps.MwmApplication; import app.organicmaps.R; import app.organicmaps.adapter.OnItemClickListener; import app.organicmaps.base.BaseMwmRecyclerFragment; -import app.organicmaps.base.DataChangedListener; import app.organicmaps.bookmarks.data.BookmarkCategory; import app.organicmaps.bookmarks.data.BookmarkManager; import app.organicmaps.bookmarks.data.BookmarkSharingResult; @@ -102,7 +101,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment + private void onCategoriesChanged() { - @Nullable - private BookmarkCategoriesFragment mFragment; - - CategoriesAdapterObserver(@NonNull BookmarkCategoriesFragment fragment) - { - mFragment = fragment; - } - - @Override - public void attach(@NonNull BookmarkCategoriesFragment object) - { - mFragment = object; - } - - @Override - public void detach() - { - mFragment = null; - } - - @Override - public void onChanged() - { - if (mFragment == null) - return; - - mFragment.getAdapter().setItems(BookmarkManager.INSTANCE.getCategories()); - } + getAdapter().setItems(BookmarkManager.INSTANCE.getCategories()); } } diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/DataChangedListener.java b/android/app/src/main/java/app/organicmaps/bookmarks/DataChangedListener.java new file mode 100644 index 0000000000..07b5c51cf7 --- /dev/null +++ b/android/app/src/main/java/app/organicmaps/bookmarks/DataChangedListener.java @@ -0,0 +1,6 @@ +package app.organicmaps.bookmarks; + +public interface DataChangedListener +{ + void onChanged(); +} diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java index fc5c10549c..43ae9ee395 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java @@ -12,8 +12,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import app.organicmaps.Framework; -import app.organicmaps.base.DataChangedListener; -import app.organicmaps.base.Observable; +import app.organicmaps.bookmarks.DataChangedListener; +import app.organicmaps.bookmarks.BookmarkCategoriesFragment; import app.organicmaps.util.KeyValue; import app.organicmaps.util.StorageUtils; import app.organicmaps.util.concurrency.UiThread; @@ -1001,10 +1001,12 @@ public enum BookmarkManager UPLOAD_RESULT_INVALID_CALL } - static class BookmarkCategoriesCache extends Observable + static class BookmarkCategoriesCache { @NonNull private final List mCategories = new ArrayList<>(); + @NonNull + private final List mListeners = new ArrayList<>(); void update(@NonNull List categories) { @@ -1018,5 +1020,28 @@ public enum BookmarkManager { return Collections.unmodifiableList(mCategories); } + + public void registerListener(@NonNull DataChangedListener listener) + { + if (mListeners.contains(listener)) + throw new IllegalStateException("Observer " + listener + " is already registered."); + + mListeners.add(listener); + } + + public void unregisterListener(@NonNull DataChangedListener listener) + { + int index = mListeners.indexOf(listener); + if (index == -1) + throw new IllegalStateException("Observer " + listener + " was not registered."); + + mListeners.remove(index); + } + + protected void notifyChanged() + { + for (DataChangedListener item : mListeners) + item.onChanged(); + } } } diff --git a/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java b/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java index 6c291ce51a..4653bd8de1 100644 --- a/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java +++ b/android/app/src/main/java/app/organicmaps/editor/EditorHostFragment.java @@ -19,7 +19,6 @@ import androidx.fragment.app.FragmentManager; import app.organicmaps.MwmApplication; import app.organicmaps.R; import app.organicmaps.base.BaseMwmToolbarFragment; -import app.organicmaps.base.OnBackPressListener; import app.organicmaps.editor.data.Language; import app.organicmaps.editor.data.LocalizedName; import app.organicmaps.editor.data.LocalizedStreet; @@ -35,8 +34,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.util.ArrayList; import java.util.List; -public class EditorHostFragment extends BaseMwmToolbarFragment - implements OnBackPressListener, View.OnClickListener, LanguagesFragment.Listener +public class EditorHostFragment extends BaseMwmToolbarFragment implements View.OnClickListener, + LanguagesFragment.Listener { private boolean mIsNewObject; @Nullable diff --git a/android/app/src/main/java/app/organicmaps/editor/TimetableContainerFragment.java b/android/app/src/main/java/app/organicmaps/editor/TimetableContainerFragment.java index e869a2a7b0..ca99dfcd68 100644 --- a/android/app/src/main/java/app/organicmaps/editor/TimetableContainerFragment.java +++ b/android/app/src/main/java/app/organicmaps/editor/TimetableContainerFragment.java @@ -21,8 +21,7 @@ import app.organicmaps.base.OnBackPressListener; import app.organicmaps.util.UiUtils; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -public class TimetableContainerFragment extends BaseMwmFragment implements OnBackPressListener, - TimetableChangedListener +public class TimetableContainerFragment extends BaseMwmFragment implements TimetableChangedListener { public static final String EXTRA_TIME = "Time"; diff --git a/android/app/src/main/java/app/organicmaps/help/CopyrightFragment.java b/android/app/src/main/java/app/organicmaps/help/CopyrightFragment.java index 0308b56001..a6b3596700 100644 --- a/android/app/src/main/java/app/organicmaps/help/CopyrightFragment.java +++ b/android/app/src/main/java/app/organicmaps/help/CopyrightFragment.java @@ -11,10 +11,9 @@ import androidx.annotation.Nullable; import app.organicmaps.R; import app.organicmaps.WebContainerDelegate; import app.organicmaps.base.BaseMwmFragment; -import app.organicmaps.base.OnBackPressListener; import app.organicmaps.util.Constants; -public class CopyrightFragment extends BaseMwmFragment implements OnBackPressListener +public class CopyrightFragment extends BaseMwmFragment { private WebContainerDelegate mDelegate; diff --git a/android/app/src/main/java/app/organicmaps/location/LocationHelper.java b/android/app/src/main/java/app/organicmaps/location/LocationHelper.java index d3fa54cf51..fd7cb25680 100644 --- a/android/app/src/main/java/app/organicmaps/location/LocationHelper.java +++ b/android/app/src/main/java/app/organicmaps/location/LocationHelper.java @@ -15,7 +15,6 @@ import androidx.annotation.UiThread; import app.organicmaps.Framework; import app.organicmaps.MwmApplication; -import app.organicmaps.base.Initializable; import app.organicmaps.bookmarks.data.FeatureId; import app.organicmaps.bookmarks.data.MapObject; import app.organicmaps.routing.RoutingController; diff --git a/android/app/src/main/java/app/organicmaps/maplayer/isolines/IsolinesManager.java b/android/app/src/main/java/app/organicmaps/maplayer/isolines/IsolinesManager.java index aa3386bc6c..b6a98b8691 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/isolines/IsolinesManager.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/isolines/IsolinesManager.java @@ -8,17 +8,15 @@ import androidx.annotation.Nullable; import app.organicmaps.Framework; import app.organicmaps.MwmApplication; -import app.organicmaps.base.Detachable; -import app.organicmaps.base.Initializable; -public class IsolinesManager implements Initializable, Detachable +public class IsolinesManager { @NonNull - private final OnIsolinesChangedListenerImpl mListener; + private final OnIsolinesChangedListener mListener; public IsolinesManager(@NonNull Application application) { - mListener = new OnIsolinesChangedListenerImpl(application); + mListener = new OnIsolinesChangedListener(application); } public boolean isEnabled() @@ -44,18 +42,11 @@ public class IsolinesManager implements Initializable, Detachable, Detachable -{ - @NonNull - private final Application mApp; - private IsolinesErrorDialogListener mListener; - - OnIsolinesChangedListenerImpl(@NonNull Application app) - { - mApp = app; - } - - @Override - public void onStateChanged(int type) - { - IsolinesState state = IsolinesState.values()[type]; - if (mListener == null) - { - state.activate(mApp, null, null); - return; - } - - mListener.onStateChanged(state); - } - - @Override - public void attach(@NonNull IsolinesErrorDialogListener listener) - { - mListener = listener; - } - - @Override - public void detach() - { - mListener = null; - } -} diff --git a/android/app/src/main/java/app/organicmaps/maplayer/subway/SubwayManager.java b/android/app/src/main/java/app/organicmaps/maplayer/subway/SubwayManager.java index 2c9d4bdd85..8755d21214 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/subway/SubwayManager.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/subway/SubwayManager.java @@ -8,9 +8,8 @@ import androidx.annotation.Nullable; import app.organicmaps.Framework; import app.organicmaps.MwmApplication; -import app.organicmaps.base.Initializable; -public class SubwayManager implements Initializable +public class SubwayManager { @NonNull private final OnTransitSchemeChangedListener mSchemeChangedListener; @@ -38,18 +37,11 @@ public class SubwayManager implements Initializable setEnabled(!isEnabled()); } - @Override - public void initialize(@Nullable Void aVoid) + public void initialize() { registerListener(); } - @Override - public void destroy() - { - // No op. - } - private void registerListener() { nativeAddListener(mSchemeChangedListener); diff --git a/android/app/src/main/java/app/organicmaps/maplayer/traffic/TrafficManager.java b/android/app/src/main/java/app/organicmaps/maplayer/traffic/TrafficManager.java index f8266d01fa..8e96d7c94f 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/traffic/TrafficManager.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/traffic/TrafficManager.java @@ -3,14 +3,14 @@ package app.organicmaps.maplayer.traffic; import androidx.annotation.MainThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import app.organicmaps.base.Initializable; + import app.organicmaps.util.log.Logger; import java.util.ArrayList; import java.util.List; @MainThread -public enum TrafficManager implements Initializable +public enum TrafficManager { INSTANCE; @@ -27,20 +27,13 @@ public enum TrafficManager implements Initializable private boolean mInitialized = false; - @Override - public void initialize(@Nullable Void aVoid) + public void initialize() { Logger.d(TAG, "Initialization of traffic manager and setting the listener for traffic state changes"); TrafficState.nativeSetListener(mStateChangeListener); mInitialized = true; } - @Override - public void destroy() - { - // No op. - } - public void toggle() { checkInitialization(); diff --git a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java index 2ab907d92f..ff85e0d381 100644 --- a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java +++ b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java @@ -30,7 +30,7 @@ import androidx.core.content.ContextCompat; import app.organicmaps.Framework; import app.organicmaps.MwmActivity; import app.organicmaps.R; -import app.organicmaps.base.MediaPlayerWrapper; +import app.organicmaps.sound.MediaPlayerWrapper; import app.organicmaps.location.LocationHelper; import app.organicmaps.location.LocationListener; import app.organicmaps.sound.TtsPlayer; diff --git a/android/app/src/main/java/app/organicmaps/routing/RoutingController.java b/android/app/src/main/java/app/organicmaps/routing/RoutingController.java index b77775a70b..6cee979c4a 100644 --- a/android/app/src/main/java/app/organicmaps/routing/RoutingController.java +++ b/android/app/src/main/java/app/organicmaps/routing/RoutingController.java @@ -13,7 +13,6 @@ import androidx.core.util.Pair; import app.organicmaps.Framework; import app.organicmaps.R; -import app.organicmaps.base.Initializable; import app.organicmaps.bookmarks.data.FeatureId; import app.organicmaps.bookmarks.data.MapObject; import app.organicmaps.location.LocationHelper; @@ -28,7 +27,7 @@ import java.util.concurrent.TimeUnit; @androidx.annotation.UiThread -public class RoutingController implements Initializable +public class RoutingController { private static final String TAG = RoutingController.class.getSimpleName(); @@ -253,7 +252,6 @@ public class RoutingController implements Initializable mContainer = container; } - @Override public void initialize(@NonNull Context context) { mLastRouterType = Framework.nativeGetLastUsedRouter(); @@ -269,12 +267,6 @@ public class RoutingController implements Initializable Framework.nativeSetRoutingLoadPointsListener(mRoutingLoadPointsListener); } - @Override - public void destroy() - { - // No op. - } - public void detach() { mContainer = null; diff --git a/android/app/src/main/java/app/organicmaps/routing/RoutingPlanFragment.java b/android/app/src/main/java/app/organicmaps/routing/RoutingPlanFragment.java index bb06a88b30..bfb3e119d2 100644 --- a/android/app/src/main/java/app/organicmaps/routing/RoutingPlanFragment.java +++ b/android/app/src/main/java/app/organicmaps/routing/RoutingPlanFragment.java @@ -15,7 +15,6 @@ import app.organicmaps.base.BaseMwmFragment; import app.organicmaps.base.OnBackPressListener; public class RoutingPlanFragment extends BaseMwmFragment - implements OnBackPressListener { private RoutingPlanController mPlanController; diff --git a/android/app/src/main/java/app/organicmaps/search/SearchEngine.java b/android/app/src/main/java/app/organicmaps/search/SearchEngine.java index da03bdd8ba..6a3d972773 100644 --- a/android/app/src/main/java/app/organicmaps/search/SearchEngine.java +++ b/android/app/src/main/java/app/organicmaps/search/SearchEngine.java @@ -7,7 +7,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import app.organicmaps.Framework; import app.organicmaps.api.ParsedMwmRequest; -import app.organicmaps.base.Initializable; import app.organicmaps.util.Language; import app.organicmaps.util.Listeners; import app.organicmaps.util.concurrency.UiThread; @@ -16,8 +15,7 @@ import java.nio.charset.StandardCharsets; public enum SearchEngine implements NativeSearchListener, NativeMapSearchListener, - NativeBookmarkSearchListener, - Initializable + NativeBookmarkSearchListener { INSTANCE; @@ -210,18 +208,11 @@ public enum SearchEngine implements NativeSearchListener, nativeShowResult(index); } - @Override - public void initialize(@Nullable Void aVoid) + public void initialize() { nativeInit(); } - @Override - public void destroy() - { - // No op. - } - /** * @param bytes utf-8 formatted bytes of query. */ diff --git a/android/app/src/main/java/app/organicmaps/search/SearchFragment.java b/android/app/src/main/java/app/organicmaps/search/SearchFragment.java index e4b56d5bc3..b25262c760 100644 --- a/android/app/src/main/java/app/organicmaps/search/SearchFragment.java +++ b/android/app/src/main/java/app/organicmaps/search/SearchFragment.java @@ -46,8 +46,7 @@ import java.util.Arrays; import java.util.List; public class SearchFragment extends BaseMwmFragment - implements OnBackPressListener, - NativeSearchListener, + implements NativeSearchListener, CategoriesAdapter.CategoriesUiListener { private long mLastQueryTimestamp; diff --git a/android/app/src/main/java/app/organicmaps/settings/StoragePathFragment.java b/android/app/src/main/java/app/organicmaps/settings/StoragePathFragment.java index 4ccff2bfc2..5afa04ba9c 100644 --- a/android/app/src/main/java/app/organicmaps/settings/StoragePathFragment.java +++ b/android/app/src/main/java/app/organicmaps/settings/StoragePathFragment.java @@ -14,7 +14,6 @@ import androidx.annotation.NonNull; import app.organicmaps.Framework; import app.organicmaps.R; -import app.organicmaps.base.OnBackPressListener; import app.organicmaps.util.Config; import app.organicmaps.util.StorageUtils; import app.organicmaps.util.Utils; @@ -26,7 +25,6 @@ import java.io.File; import java.util.List; public class StoragePathFragment extends BaseSettingsFragment - implements OnBackPressListener { private TextView mHeader; diff --git a/android/app/src/main/java/app/organicmaps/base/MediaPlayerWrapper.java b/android/app/src/main/java/app/organicmaps/sound/MediaPlayerWrapper.java similarity index 99% rename from android/app/src/main/java/app/organicmaps/base/MediaPlayerWrapper.java rename to android/app/src/main/java/app/organicmaps/sound/MediaPlayerWrapper.java index 1f5caba400..0f773d8cd4 100644 --- a/android/app/src/main/java/app/organicmaps/base/MediaPlayerWrapper.java +++ b/android/app/src/main/java/app/organicmaps/sound/MediaPlayerWrapper.java @@ -1,4 +1,4 @@ -package app.organicmaps.base; +package app.organicmaps.sound; import android.content.Context; import android.media.MediaPlayer; diff --git a/android/app/src/main/java/app/organicmaps/sound/TtsPlayer.java b/android/app/src/main/java/app/organicmaps/sound/TtsPlayer.java index be3b92e233..81f97504f3 100644 --- a/android/app/src/main/java/app/organicmaps/sound/TtsPlayer.java +++ b/android/app/src/main/java/app/organicmaps/sound/TtsPlayer.java @@ -12,7 +12,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import app.organicmaps.MwmApplication; import app.organicmaps.R; -import app.organicmaps.base.Initializable; import app.organicmaps.util.Config; import app.organicmaps.util.log.Logger; @@ -35,7 +34,7 @@ import java.util.Locale; *

* If no core supported languages can be used by the system, TTS is locked down and can not be enabled and used. */ -public enum TtsPlayer implements Initializable +public enum TtsPlayer { INSTANCE; @@ -135,8 +134,7 @@ public enum TtsPlayer implements Initializable setEnabled(false); } - @Override - public void initialize(@Nullable Context context) + public void initialize(@NonNull Context context) { mContext = context; @@ -175,12 +173,6 @@ public enum TtsPlayer implements Initializable }); } - @Override - public void destroy() - { - // No op. - } - private static boolean isReady() { return (INSTANCE.mTts != null && !INSTANCE.mUnavailable && !INSTANCE.mInitializing); diff --git a/android/app/src/main/java/app/organicmaps/util/ConnectionState.java b/android/app/src/main/java/app/organicmaps/util/ConnectionState.java index 69274576f3..3657e95f7c 100644 --- a/android/app/src/main/java/app/organicmaps/util/ConnectionState.java +++ b/android/app/src/main/java/app/organicmaps/util/ConnectionState.java @@ -11,9 +11,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import app.organicmaps.MwmApplication; -import app.organicmaps.base.Initializable; -public enum ConnectionState implements Initializable +public enum ConnectionState { INSTANCE; @@ -51,16 +50,9 @@ public enum ConnectionState implements Initializable } } - @Override - public void initialize(@Nullable Context context) + public void initialize(@NonNull Context context) { - mContext = MwmApplication.from(context); - } - - @Override - public void destroy() - { - // No op + mContext = context; } private boolean isNetworkConnected(int networkType) diff --git a/android/app/src/main/java/app/organicmaps/util/FragmentListHelper.java b/android/app/src/main/java/app/organicmaps/util/FragmentListHelper.java deleted file mode 100644 index a6c8d77b75..0000000000 --- a/android/app/src/main/java/app/organicmaps/util/FragmentListHelper.java +++ /dev/null @@ -1,59 +0,0 @@ -package app.organicmaps.util; - -import android.app.Fragment; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Helper class to track fragments attached to Activity. - * Its primary goal is to implement getFragments() that is present in Support Library - * but is missed in native FragmentManager. - * - *

- * Usage: - *

    - *
  • Create instance of FragmentListHelper in your Activity.
  • - *
  • Override {@link android.app.Activity#onAttachFragment(Fragment)} in your Activity and call {@link FragmentListHelper#onAttachFragment(Fragment)}.
  • - *
  • Call {@link FragmentListHelper#getFragments()} to obtain list of fragments currently added to your Activity.
  • - *
- */ -public class FragmentListHelper -{ - private final Map> mFragments = new HashMap<>(); - - public void onAttachFragment(Fragment fragment) - { - mFragments.put(fragment.getClass().getName(), new WeakReference<>(fragment)); - } - - public List getFragments() - { - List toRemove = null; - - List res = new ArrayList<>(mFragments.size()); - for (String key : mFragments.keySet()) - { - Fragment f = mFragments.get(key).get(); - if (f == null || !f.isAdded()) - { - if (toRemove == null) - toRemove = new ArrayList<>(); - - toRemove.add(key); - continue; - } - - res.add(f); - } - - if (toRemove != null) - for (String key : toRemove) - mFragments.remove(key); - - return res; - } -} diff --git a/android/app/src/main/java/app/organicmaps/util/Gsonable.java b/android/app/src/main/java/app/organicmaps/util/Gsonable.java deleted file mode 100644 index c5751214c1..0000000000 --- a/android/app/src/main/java/app/organicmaps/util/Gsonable.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.organicmaps.util; - -/** - * Marker for classes that are (de)serializable from/to JSON using Google Gson library. - */ -public interface Gsonable -{} diff --git a/android/app/src/main/java/app/organicmaps/util/Predicate.java b/android/app/src/main/java/app/organicmaps/util/Predicate.java deleted file mode 100644 index a1b53f8dcb..0000000000 --- a/android/app/src/main/java/app/organicmaps/util/Predicate.java +++ /dev/null @@ -1,42 +0,0 @@ -package app.organicmaps.util; - -import androidx.annotation.NonNull; - -public abstract class Predicate -{ - @NonNull - private final T mBaseValue; - - Predicate(@NonNull T baseValue) - { - mBaseValue = baseValue; - } - - @NonNull - T getBaseValue() - { - return mBaseValue; - } - - public abstract boolean apply(@NonNull D field); - - public static class Equals extends Predicate - { - @NonNull - private final TypeConverter mConverter; - - public Equals(@NonNull TypeConverter converter, @NonNull T data) - { - super(data); - mConverter = converter; - } - - @Override - public boolean apply(@NonNull D field) - { - T converted = mConverter.convert(field); - T value = getBaseValue(); - return value == converted || value.equals(converted); - } - } -} diff --git a/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java b/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java index f755118732..c0f7e5f76e 100644 --- a/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java +++ b/android/app/src/main/java/app/organicmaps/util/ThemeSwitcher.java @@ -5,19 +5,17 @@ import android.content.Context; import android.location.Location; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import app.organicmaps.Framework; import app.organicmaps.MwmApplication; import app.organicmaps.R; -import app.organicmaps.base.Initializable; import app.organicmaps.display.DisplayManager; import app.organicmaps.downloader.DownloaderStatusIcon; import app.organicmaps.location.LocationHelper; import app.organicmaps.routing.RoutingController; import app.organicmaps.util.concurrency.UiThread; -public enum ThemeSwitcher implements Initializable +public enum ThemeSwitcher { INSTANCE; @@ -60,18 +58,11 @@ public enum ThemeSwitcher implements Initializable @NonNull private Context mContext; - @Override - public void initialize(@Nullable Context context) + public void initialize(@NonNull Context context) { mContext = context; } - @Override - public void destroy() - { - // No op. - } - /** * Changes the UI theme of application and the map style if necessary. If the contract regarding * the input parameter is broken, the UI will be frozen during attempting to change the map style diff --git a/android/app/src/main/java/app/organicmaps/util/TypeConverter.java b/android/app/src/main/java/app/organicmaps/util/TypeConverter.java deleted file mode 100644 index 6f979ad543..0000000000 --- a/android/app/src/main/java/app/organicmaps/util/TypeConverter.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.organicmaps.util; - -import androidx.annotation.NonNull; - -public interface TypeConverter -{ - T convert(@NonNull D data); -} diff --git a/android/app/src/main/java/app/organicmaps/util/Utils.java b/android/app/src/main/java/app/organicmaps/util/Utils.java index d3dd73e1e0..c5d1471ef6 100644 --- a/android/app/src/main/java/app/organicmaps/util/Utils.java +++ b/android/app/src/main/java/app/organicmaps/util/Utils.java @@ -41,9 +41,9 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import app.organicmaps.BuildConfig; +import app.organicmaps.MwmActivity; import app.organicmaps.MwmApplication; import app.organicmaps.R; -import app.organicmaps.base.CustomNavigateUpListener; import app.organicmaps.util.concurrency.UiThread; import app.organicmaps.util.log.Logger; import app.organicmaps.util.log.LogsManager; @@ -347,13 +347,11 @@ public class Utils Constants.Email.SUPPORT)); } - public static void navigateToParent(@Nullable Activity activity) + public static void navigateToParent(@NonNull Activity activity) { - if (activity == null) - return; - - if (activity instanceof CustomNavigateUpListener) - ((CustomNavigateUpListener) activity).customOnNavigateUp(); + // MwmActivity is a top-level activity that implements custom handling of Fragments. + if (activity instanceof MwmActivity) + ((MwmActivity) activity).customOnNavigateUp(); else NavUtils.navigateUpFromSameTask(activity); } diff --git a/android/app/src/main/java/app/organicmaps/widget/ToolbarController.java b/android/app/src/main/java/app/organicmaps/widget/ToolbarController.java index f0cd3b3f53..d7f9dce0cf 100644 --- a/android/app/src/main/java/app/organicmaps/widget/ToolbarController.java +++ b/android/app/src/main/java/app/organicmaps/widget/ToolbarController.java @@ -13,11 +13,10 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.view.ViewCompat; import app.organicmaps.R; -import app.organicmaps.base.Detachable; import app.organicmaps.util.UiUtils; import app.organicmaps.util.Utils; -public class ToolbarController implements Detachable +public class ToolbarController { @Nullable private Activity mActivity; @@ -105,13 +104,11 @@ public class ToolbarController implements Detachable return mToolbar; } - @Override public void attach(@NonNull Activity activity) { mActivity = activity; } - @Override public void detach() { mActivity = null; diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java b/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java index d710f7a1b6..a8a630768a 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/ElevationProfileViewRenderer.java @@ -19,8 +19,8 @@ import app.organicmaps.util.UiUtils; import java.util.Objects; -public class ElevationProfileViewRenderer implements PlacePageViewRenderer, - PlacePageStateListener +@SuppressWarnings("unused") // https://github.com/organicmaps/organicmaps/issues/2829 +public class ElevationProfileViewRenderer implements PlacePageStateListener { // Must be correspond to map/elevation_info.hpp constants. private static final int MAX_DIFFICULTY_LEVEL = 3; @@ -61,7 +61,6 @@ public class ElevationProfileViewRenderer implements PlacePageViewRenderer extends Initializable, Savable, - Hideable, Supportable -{ - void render(@NonNull Data data); -}