From d0286c1556fd68f8c5b29d298f6c004819862f39 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 24 Apr 2018 18:39:07 +0300 Subject: [PATCH] [android] Auto-update screen. Reload info on resume --- .../jni/com/mapswithme/maps/MapManager.cpp | 8 +- .../maps/downloader/MapManager.java | 2 + .../downloader/UpdaterDialogFragment.java | 90 ++++++++++++++----- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/android/jni/com/mapswithme/maps/MapManager.cpp b/android/jni/com/mapswithme/maps/MapManager.cpp index e23998519a..99091db254 100644 --- a/android/jni/com/mapswithme/maps/MapManager.cpp +++ b/android/jni/com/mapswithme/maps/MapManager.cpp @@ -448,7 +448,13 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeFindCountry(JNIEnv * env, j JNIEXPORT jboolean JNICALL Java_com_mapswithme_maps_downloader_MapManager_nativeIsDownloading(JNIEnv * env, jclass clazz) { - return GetStorage().IsDownloadInProgress(); + return static_cast(GetStorage().IsDownloadInProgress()); +} + +JNIEXPORT jstring JNICALL +Java_com_mapswithme_maps_downloader_MapManager_nativeGetCurrentDownloadingCountryId(JNIEnv * env, jclass) +{ + return jni::ToJavaString(env, GetStorage().GetCurrentDownloadingCountryId()); } static void StartBatchingCallbacks() diff --git a/android/src/com/mapswithme/maps/downloader/MapManager.java b/android/src/com/mapswithme/maps/downloader/MapManager.java index d16218784c..e119c22f14 100644 --- a/android/src/com/mapswithme/maps/downloader/MapManager.java +++ b/android/src/com/mapswithme/maps/downloader/MapManager.java @@ -392,6 +392,8 @@ public final class MapManager */ public static native boolean nativeIsDownloading(); + public static native String nativeGetCurrentDownloadingCountryId(); + /** * Enqueues given {@code root} node and its children in downloader. */ diff --git a/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java b/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java index 30768cf599..75fe6f9d00 100644 --- a/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java +++ b/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java @@ -107,16 +107,10 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment mTotalSizeBytes / Constants.MB); MapManager.nativeCancel(CountryItem.getRootId()); - final UpdateInfo info = MapManager.nativeGetUpdateInfo(CountryItem.getRootId()); - if (info == null) - { - finish(); - return; - } + + updateTotalSizes(); mAutoUpdate = false; - mTotalSize = StringUtils.getFileSizeString(info.totalSize); - mTotalSizeBytes = info.totalSize; mOutdatedMaps = Framework.nativeGetOutdatedCountries(); if (mStorageCallback != null) @@ -262,28 +256,39 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment { super.onResume(); - if (isAllUpdated()) + // The storage callback must be non-null at this point. + //noinspection ConstantConditions + mStorageCallback.attach(this); + + if (isAllUpdated() || Framework.nativeGetOutdatedCountries().length == 0) { finish(); return; } - // The storage callback must be non-null at this point. - //noinspection ConstantConditions - mStorageCallback.attach(this); - - if (mAutoUpdate && !MapManager.nativeIsDownloading()) + if (mAutoUpdate) { - MapManager.warnOn3gUpdate(getActivity(), CountryItem.getRootId(), new Runnable() + if (!MapManager.nativeIsDownloading()) { - @Override - public void run() + MapManager.warnOn3gUpdate(getActivity(), CountryItem.getRootId(), new Runnable() { - MapManager.nativeUpdate(CountryItem.getRootId()); - Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_DOWNLOAD, - mTotalSizeBytes / Constants.MB); - } - }); + @Override + public void run() + { + MapManager.nativeUpdate(CountryItem.getRootId()); + Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_DOWNLOAD, + mTotalSizeBytes / Constants.MB); + } + }); + } + else + { + updateTotalSizes(); + updateProgress(); + + updateProcessedMapInfo(); + setCommonStatus(mProcessedMapId, mCommonStatusResId); + } } } @@ -385,6 +390,47 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment String status = getString(mwmStatusResId, MapManager.nativeGetName(mwmId)); mTitle.setText(status); } + + void updateTotalSizes() + { + final UpdateInfo info = MapManager.nativeGetUpdateInfo(CountryItem.getRootId()); + if (info == null) + { + finish(); + return; + } + + mTotalSize = StringUtils.getFileSizeString(info.totalSize); + mTotalSizeBytes = info.totalSize; + } + + void updateProgress() + { + int progress = MapManager.nativeGetOverallProgress(mOutdatedMaps); + setProgress(progress, mTotalSizeBytes * progress / 100, mTotalSizeBytes); + } + + void updateProcessedMapInfo() + { + mProcessedMapId = MapManager.nativeGetCurrentDownloadingCountryId(); + + 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 = 0; + break; + } + } + private static class DetachableStorageCallback implements MapManager.StorageCallback { @Nullable