From a3045f05f81f9702ef156cba8636bd62e461e19c Mon Sep 17 00:00:00 2001 From: Alexander Marchuk Date: Mon, 29 Feb 2016 15:31:44 +0300 Subject: [PATCH] [new downloader][android] fix: Review fixes. --- .../jni/com/mapswithme/maps/MapManager.cpp | 43 +++++++++---------- .../maps/downloader/MigrationController.java | 2 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/android/jni/com/mapswithme/maps/MapManager.cpp b/android/jni/com/mapswithme/maps/MapManager.cpp index b03ef4844a..9bf2d804c6 100644 --- a/android/jni/com/mapswithme/maps/MapManager.cpp +++ b/android/jni/com/mapswithme/maps/MapManager.cpp @@ -24,6 +24,7 @@ enum ItemCategory : uint32_t jmethodID g_listAddMethod; jclass g_countryItemClass; jobject g_countryChangedListener; +jobject g_migrationListener; Storage & GetStorage() { @@ -65,34 +66,32 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeIsLegacyMode(JNIEnv * env, return g_framework->NeedMigrate(); } -static void FinishMigration(JNIEnv * env, jobject const listener) +static void FinishMigration(JNIEnv * env) { - env->DeleteGlobalRef(listener); + env->DeleteGlobalRef(g_migrationListener); } -static void OnPrefetchComplete(jobject const listener, bool keepOldMaps) +static void OnPrefetchComplete(bool keepOldMaps) { g_framework->Migrate(keepOldMaps); JNIEnv * env = jni::GetEnv(); - jmethodID const callback = jni::GetMethodID(env, listener, "onComplete", "()V"); - ASSERT(callback, ()); - env->CallVoidMethod(listener, callback); + static jmethodID const callback = jni::GetMethodID(env, g_migrationListener, "onComplete", "()V"); + env->CallVoidMethod(g_migrationListener, callback); - FinishMigration(env, listener); + FinishMigration(env); } -static void OnMigrationError(jobject const listener, NodeErrorCode error) +static void OnMigrationError(NodeErrorCode error) { JNIEnv * env = jni::GetEnv(); - jmethodID const callback = jni::GetMethodID(env, listener, "onError", "(I)V"); - ASSERT(callback, ()); - env->CallVoidMethod(listener, callback, static_cast(error)); + static jmethodID const callback = jni::GetMethodID(env, g_migrationListener, "onError", "(I)V"); + env->CallVoidMethod(g_migrationListener, callback, static_cast(error)); - FinishMigration(env, listener); + FinishMigration(env); } -static void MigrationStatusChangedCallback(jobject const listener, TCountryId const & countryId, bool keepOldMaps) +static void MigrationStatusChangedCallback(TCountryId const & countryId, bool keepOldMaps) { NodeAttrs attrs; GetStorage().GetPrefetchStorage()->GetNodeAttrs(countryId, attrs); @@ -100,22 +99,22 @@ static void MigrationStatusChangedCallback(jobject const listener, TCountryId co switch (attrs.m_status) { case NodeStatus::OnDisk: - OnPrefetchComplete(listener, keepOldMaps); + OnPrefetchComplete(keepOldMaps); break; case NodeStatus::Undefined: case NodeStatus::Error: - OnMigrationError(listener, attrs.m_error); + OnMigrationError(attrs.m_error); break; } } -static void MigrationProgressCallback(jobject const listener, TCountryId const & countryId, TLocalAndRemoteSize const & sizes) +static void MigrationProgressCallback(TCountryId const & countryId, TLocalAndRemoteSize const & sizes) { JNIEnv * env = jni::GetEnv(); - jmethodID const callback = jni::GetMethodID(env, listener, "onProgress", "(I)V"); - env->CallVoidMethod(listener, callback, static_cast(sizes.first * 100 / sizes.second)); + static jmethodID const callback = jni::GetMethodID(env, g_migrationListener, "onProgress", "(I)V"); + env->CallVoidMethod(g_migrationListener, callback, static_cast(sizes.first * 100 / sizes.second)); } // static boolean nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps); @@ -126,15 +125,15 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeMigrate(JNIEnv * env, jclas if (hasLocation) position = MercatorBounds::ToLatLon(g_framework->GetViewportCenter()); - listener = env->NewGlobalRef(listener); + g_migrationListener = env->NewGlobalRef(listener); - if (g_framework->PreMigrate(position, bind(&MigrationStatusChangedCallback, listener, _1, keepOldMaps), - bind(&MigrationProgressCallback, listener, _1, _2))) + if (g_framework->PreMigrate(position, bind(&MigrationStatusChangedCallback, _1, keepOldMaps), + bind(&MigrationProgressCallback, _1, _2))) { return true; } - OnPrefetchComplete(listener, keepOldMaps); + OnPrefetchComplete(keepOldMaps); return false; } diff --git a/android/src/com/mapswithme/maps/downloader/MigrationController.java b/android/src/com/mapswithme/maps/downloader/MigrationController.java index 694cfacb10..f79cab3aa7 100644 --- a/android/src/com/mapswithme/maps/downloader/MigrationController.java +++ b/android/src/com/mapswithme/maps/downloader/MigrationController.java @@ -152,7 +152,7 @@ final class MigrationController if (!MapManager.nativeMigrate(mListener, lat, lon, (loc != null), keepOld)) return; - mState = State.PROGRESS; + mState = State.PROGRESS; mProgress = 0; callStateProgress(); callUpdateProgress();