diff --git a/android/jni/com/mapswithme/maps/MapFragment.cpp b/android/jni/com/mapswithme/maps/MapFragment.cpp index e17839b167..bf05a000e2 100644 --- a/android/jni/com/mapswithme/maps/MapFragment.cpp +++ b/android/jni/com/mapswithme/maps/MapFragment.cpp @@ -12,7 +12,10 @@ #include "base/logging.hpp" #include "platform/file_logging.hpp" +#include "platform/settings.hpp" +using namespace storage; +using namespace storage_utils; extern "C" { @@ -31,25 +34,57 @@ extern "C" #pragma clang pop_options - static void CallOnDownloadCountryClicked(shared_ptr const & obj, storage::TIndex const & idx, int options, jmethodID methodID) + static void CallOnDownloadClicked(shared_ptr const & obj, TIndex const & idx, int options, jmethodID methodID) { JNIEnv * env = jni::GetEnv(); env->CallVoidMethod(*obj.get(), methodID, idx.m_group, idx.m_country, idx.m_region, options); } - JNIEXPORT void JNICALL - Java_com_mapswithme_maps_MapFragment_nativeConnectDownloadButton(JNIEnv * env, jobject thiz) + static void OnCancelDownload(TIndex const & idx) { - jmethodID methodID = jni::GetMethodID(env, thiz, "onDownloadCountryClicked", "(IIII)V"); - g_framework->NativeFramework()->SetDownloadCountryListener(bind(&CallOnDownloadCountryClicked, - jni::make_global_ref(thiz), _1, _2, methodID)); + GetMapLayout().CancelDownloading(idx); + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_MapFragment_nativeConnectDownloaderListeners(JNIEnv * env, jobject thiz) + { + g_framework->NativeFramework()->SetDownloadCountryListener([env, thiz](TIndex const & idx, int options) + { + jmethodID methodID = jni::GetMethodID(env, thiz, "onDownloadClicked", "(IIII)V"); + env->CallVoidMethod(thiz, methodID, idx.m_group, idx.m_country, idx.m_region, options); + }); + + g_framework->NativeFramework()->SetDownloadCancelListener([](TIndex const & idx) + { + GetMapLayout().CancelDownloading(idx); + }); + + g_framework->NativeFramework()->SetAutoDownloadListener([](TIndex const & idx) + { + if (g_framework->NeedMigrate()) + return; + + bool autoDownload = true; + Settings::Get("AutoDownloadEnabled", autoDownload); + + if (autoDownload && Platform::ConnectionStatus() == Platform::EConnectionType::CONNECTION_WIFI) + GetMapLayout().DownloadMap(idx, MapOptions::Map); + }); + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_MapFragment_nativeDisconnectListeners(JNIEnv * env, jclass clazz) + { + g_framework->NativeFramework()->SetDownloadCountryListener(nullptr); + g_framework->NativeFramework()->SetDownloadCancelListener(nullptr); + g_framework->NativeFramework()->SetAutoDownloadListener(nullptr); } JNIEXPORT void JNICALL Java_com_mapswithme_maps_MapFragment_nativeDownloadCountry(JNIEnv * env, jclass clazz, jobject idx, jint options) { - storage::TIndex index = storage::ToNative(idx); - storage::ActiveMapsLayout & layout = storage_utils::GetMapLayout(); + TIndex index = ToNative(idx); + ActiveMapsLayout & layout = storage_utils::GetMapLayout(); if (options == -1) layout.RetryDownloading(index); else diff --git a/android/res/values/donottranslate.xml b/android/res/values/donottranslate.xml index 81e5729f44..83702a6eaa 100644 --- a/android/res/values/donottranslate.xml +++ b/android/res/values/donottranslate.xml @@ -40,6 +40,7 @@ MapStyle TtsEnabled TtsLanguage + AutoDownloadMap 3D 3DBuildings TrackRecord diff --git a/android/res/xml-v21/prefs_map.xml b/android/res/xml-v21/prefs_map.xml index 7f28fdf9bf..3e0d2eb23d 100644 --- a/android/res/xml-v21/prefs_map.xml +++ b/android/res/xml-v21/prefs_map.xml @@ -30,23 +30,30 @@ android:entryValues="@array/map_style_values" android:order="4"/> + + + android:order="6"/> + android:order="7"/> + android:order="8"/> \ No newline at end of file diff --git a/android/res/xml/prefs_map.xml b/android/res/xml/prefs_map.xml index 74db851d52..8aa5a5cbad 100644 --- a/android/res/xml/prefs_map.xml +++ b/android/res/xml/prefs_map.xml @@ -28,21 +28,26 @@ android:entryValues="@array/map_style_values" android:order="4"/> + + + android:order="6"/> + android:order="7"/> + android:order="8"/> \ No newline at end of file diff --git a/android/src/com/mapswithme/maps/MapFragment.java b/android/src/com/mapswithme/maps/MapFragment.java index 7f5c23ea59..42efd5d785 100644 --- a/android/src/com/mapswithme/maps/MapFragment.java +++ b/android/src/com/mapswithme/maps/MapFragment.java @@ -58,13 +58,11 @@ public class MapFragment extends BaseMwmFragment private boolean mEngineCreated; private static boolean sWasCopyrightDisplayed; - public interface MapRenderingListener + interface MapRenderingListener { void onRenderingInitialized(); } - public static final String FRAGMENT_TAG = MapFragment.class.getName(); - private void setupWidgets(int width, int height) { mHeight = height; @@ -224,7 +222,14 @@ public class MapFragment extends BaseMwmFragment super.onViewCreated(view, savedInstanceState); final SurfaceView surfaceView = (SurfaceView) view.findViewById(R.id.map_surfaceview); surfaceView.getHolder().addCallback(this); - nativeConnectDownloadButton(); + nativeConnectDownloaderListeners(); + } + + @Override + public void onDestroyView() + { + super.onDestroyView(); + nativeDisconnectListeners(); } @Override @@ -276,7 +281,7 @@ public class MapFragment extends BaseMwmFragment } @SuppressWarnings("UnusedDeclaration") - public void onDownloadCountryClicked(final int group, final int country, final int region, final int options) + public void onDownloadClicked(final int group, final int country, final int region, final int options) { UiThread.run(new Runnable() { @@ -309,7 +314,8 @@ public class MapFragment extends BaseMwmFragment }); } - private native void nativeConnectDownloadButton(); + private native void nativeConnectDownloaderListeners(); + private static native void nativeDisconnectListeners(); private static native void nativeDownloadCountry(MapStorage.Index index, int options); static native void nativeCompassUpdated(double magneticNorth, double trueNorth, boolean forceRedraw); static native void nativeScalePlus(); diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 54d4ecc3b4..5608fce027 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -394,13 +394,13 @@ public class MwmActivity extends BaseMwmFragmentActivity } }); - mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MapFragment.FRAGMENT_TAG); + mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MapFragment.class.getName()); if (mMapFragment == null) { mMapFragment = (MapFragment) MapFragment.instantiate(this, MapFragment.class.getName(), null); getSupportFragmentManager() .beginTransaction() - .replace(R.id.map_fragment_container, mMapFragment, MapFragment.FRAGMENT_TAG) + .replace(R.id.map_fragment_container, mMapFragment, MapFragment.class.getName()) .commit(); } mFrame.setOnTouchListener(this); diff --git a/android/src/com/mapswithme/maps/ads/LikesManager.java b/android/src/com/mapswithme/maps/ads/LikesManager.java index 42df223b25..8c0c2c5335 100644 --- a/android/src/com/mapswithme/maps/ads/LikesManager.java +++ b/android/src/com/mapswithme/maps/ads/LikesManager.java @@ -3,15 +3,14 @@ package com.mapswithme.maps.ads; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.util.SparseArray; -import com.mapswithme.maps.BuildConfig; -import com.mapswithme.maps.MwmApplication; -import com.mapswithme.util.Config; -import com.mapswithme.util.ConnectionState; -import com.mapswithme.util.Config; -import com.mapswithme.util.concurrency.UiThread; import java.lang.ref.WeakReference; +import com.mapswithme.maps.BuildConfig; +import com.mapswithme.util.Config; +import com.mapswithme.util.ConnectionState; +import com.mapswithme.util.concurrency.UiThread; + public enum LikesManager { INSTANCE; diff --git a/android/src/com/mapswithme/maps/settings/MapPrefsFragment.java b/android/src/com/mapswithme/maps/settings/MapPrefsFragment.java index f7f7aae450..b37d6134e2 100644 --- a/android/src/com/mapswithme/maps/settings/MapPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/MapPrefsFragment.java @@ -136,6 +136,18 @@ public class MapPrefsFragment extends BaseXmlSettingsFragment } }); + TwoStatePreference prefAutodownload = (TwoStatePreference)findPreference(getString(R.string.pref_autodownload)); + prefAutodownload.setChecked(Config.isAutoDownloadEnabled()); + prefAutodownload.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() + { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) + { + Config.setAutoDownloadEnabled((Boolean)newValue); + return true; + } + }); + final Framework.Params3dMode _3d = new Framework.Params3dMode(); Framework.nativeGet3dMode(_3d); diff --git a/android/src/com/mapswithme/util/Config.java b/android/src/com/mapswithme/util/Config.java index b2c8603893..976d42b810 100644 --- a/android/src/com/mapswithme/util/Config.java +++ b/android/src/com/mapswithme/util/Config.java @@ -19,6 +19,7 @@ public final class Config private static final String KEY_PREF_ZOOM_BUTTONS = "ZoomButtonsEnabled"; private static final String KEY_PREF_STATISTICS = "StatisticsEnabled"; + private static final String KEY_PREF_AUTODOWNLOAD = "AutoDownloadEnabled"; private static final String KEY_LIKES_RATED_DIALOG = "RatedDialog"; private static final String KEY_LIKES_LAST_RATED_SESSION = "LastRatedSession"; @@ -213,6 +214,16 @@ public final class Config setBool(KEY_PREF_STATISTICS, enabled); } + public static boolean isAutoDownloadEnabled() + { + return getBool(KEY_PREF_AUTODOWNLOAD, true); + } + + public static void setAutoDownloadEnabled(boolean enabled) + { + setBool(KEY_PREF_AUTODOWNLOAD, enabled); + } + public static boolean isRatingApplied(Class dialogFragmentClass) { return getBool(KEY_LIKES_RATED_DIALOG + dialogFragmentClass.getSimpleName()); @@ -220,7 +231,7 @@ public final class Config public static void setRatingApplied(Class dialogFragmentClass) { - setBool(KEY_LIKES_RATED_DIALOG + dialogFragmentClass.getSimpleName(), true); + setBool(KEY_LIKES_RATED_DIALOG + dialogFragmentClass.getSimpleName()); } public static boolean isSessionRated(int session) @@ -240,7 +251,7 @@ public final class Config public static void acceptRoutingDisclaimer() { - setBool(KEY_MISC_DISCLAIMER_ACCEPTED, true); + setBool(KEY_MISC_DISCLAIMER_ACCEPTED); } public static boolean isKitKatMigrationComplete()