diff --git a/android/res/layout/fragment_updater.xml b/android/res/layout/fragment_updater.xml index a307017113..0e393ac7f7 100644 --- a/android/res/layout/fragment_updater.xml +++ b/android/res/layout/fragment_updater.xml @@ -1,15 +1,21 @@ + + android:gravity="center"> - + android:layout_width="@dimen/autoupdate_progress_size" + android:layout_height="@dimen/autoupdate_progress_size" + android:layout_gravity="center" + app:wheelProgressColor="?colorAccent" + app:wheelSecondaryColor="?dividerHorizontal" + app:wheelThickness="@dimen/margin_eighth" + android:visibility="gone" + tools:visibility="visible"/> - + + tools:text="@string/whats_new_auto_update_button_later" + tools:visibility="gone"/> + + + + + + + + + diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index 0a3b140966..c180e27772 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -45,6 +45,7 @@ 40dp @dimen/downloader_status_size 32dp + 36dp 360dp 240dp diff --git a/android/src/com/mapswithme/maps/downloader/CountryItem.java b/android/src/com/mapswithme/maps/downloader/CountryItem.java index ef8ab1af1e..aa826c2465 100644 --- a/android/src/com/mapswithme/maps/downloader/CountryItem.java +++ b/android/src/com/mapswithme/maps/downloader/CountryItem.java @@ -20,12 +20,13 @@ public final class CountryItem implements Comparable // Must correspond to NodeStatus in storage_defines.hpp public static final int STATUS_UNKNOWN = 0; public static final int STATUS_PROGRESS = 1; // Downloading a new mwm or updating an old one. - public static final int STATUS_ENQUEUED = 2; // An mwm is waiting for downloading in the queue. - public static final int STATUS_FAILED = 3; // An error happened while downloading - public static final int STATUS_UPDATABLE = 4; // An update for a downloaded mwm is ready according to counties.txt. - public static final int STATUS_DONE = 5; // Downloaded mwm(s) is up to date. No need to update it. - public static final int STATUS_DOWNLOADABLE = 6; // An mwm can be downloaded but not downloaded yet. - public static final int STATUS_PARTLY = 7; // Leafs of group node has a mix of STATUS_DONE and STATUS_DOWNLOADABLE. + public static final int STATUS_APPLYING = 2; // Applying downloaded diff for an old mwm. + public static final int STATUS_ENQUEUED = 3; // An mwm is waiting for downloading in the queue. + public static final int STATUS_FAILED = 4; // An error happened while downloading + public static final int STATUS_UPDATABLE = 5; // An update for a downloaded mwm is ready according to counties.txt. + public static final int STATUS_DONE = 6; // Downloaded mwm(s) is up to date. No need to update it. + public static final int STATUS_DOWNLOADABLE = 7; // An mwm can be downloaded but not downloaded yet. + public static final int STATUS_PARTLY = 8; // Leafs of group node has a mix of STATUS_DONE and STATUS_DOWNLOADABLE. // Must correspond to NodeErrorCode in storage_defines.hpp public static final int ERROR_NONE = 0; diff --git a/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java b/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java index 0fc91ce0e7..133f1a51dd 100644 --- a/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java +++ b/android/src/com/mapswithme/maps/downloader/UpdaterDialogFragment.java @@ -11,13 +11,13 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.view.View; import android.view.Window; -import android.widget.ProgressBar; import android.widget.TextView; import com.mapswithme.maps.Framework; import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmDialogFragment; import com.mapswithme.maps.news.BaseNewsFragment; +import com.mapswithme.maps.widget.WheelProgressView; import com.mapswithme.util.Constants; import com.mapswithme.util.StringUtils; import com.mapswithme.util.UiUtils; @@ -52,8 +52,13 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment private TextView mTitle; private TextView mUpdateBtn; - private ProgressBar mProgressBar; - private TextView mCancelBtn; + private WheelProgressView mProgressBar; + private TextView mLaterBtn; + private View mInfo; + private TextView mRelativeStatus; + private TextView mCommonStatus; + private View mFrameBtn; + private TextView mHideBtn; private int mListenerSlot = 0; @Nullable @@ -81,20 +86,37 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment mDoneListener.onDialogDone(); } + @NonNull + private final View.OnClickListener mLaterClickListener = new View.OnClickListener() + { + @Override + public void onClick(View v) + { + Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_LATER, 0); + + finish(); + } + }; + @NonNull private final View.OnClickListener mCancelClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - Statistics.INSTANCE.trackDownloaderDialogEvent(MapManager.nativeIsDownloading() - ? DOWNLOADER_DIALOG_LATER - : DOWNLOADER_DIALOG_CANCEL, - mTotalSizeMb); + Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_CANCEL, mTotalSizeMb); - if (MapManager.nativeIsDownloading()) - MapManager.nativeCancel(CountryItem.getRootId()); + MapManager.nativeCancel(CountryItem.getRootId()); + finish(); + } + }; + @NonNull + private final View.OnClickListener mHideClickListener = new View.OnClickListener() + { + @Override + public void onClick(View v) + { finish(); } }; @@ -110,12 +132,13 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment @Override public void run() { + mTitle.setText(getString(R.string.whats_new_auto_update_updating_maps)); + mCommonStatus.setText(""); + mProgressBar.setProgress(0); + mRelativeStatus.setText(GetRelativeStatusFormatted(0, 0, mTotalSizeMb)); MapManager.nativeUpdate(CountryItem.getRootId()); - UiUtils.show(mProgressBar); - UiUtils.hide(mUpdateBtn); - mTitle.setText(String.format(Locale.getDefault(), "%s %d%%", - getString(R.string.whats_new_auto_update_updating_maps), 0)); - mCancelBtn.setText(R.string.cancel); + UiUtils.show(mProgressBar, mInfo, mFrameBtn, mHideBtn); + UiUtils.hide(mUpdateBtn, mLaterBtn); Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_MANUAL_DOWNLOAD, mTotalSizeMb); @@ -206,10 +229,15 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment View content = View.inflate(getActivity(), R.layout.fragment_updater, null); res.setContentView(content); - mTitle = (TextView) content.findViewById(R.id.title); - mUpdateBtn = (TextView) content.findViewById(R.id.update_btn); - mProgressBar = (ProgressBar) content.findViewById(R.id.progress); - mCancelBtn = (TextView) content.findViewById(R.id.cancel_btn); + mTitle = content.findViewById(R.id.title); + mUpdateBtn = content.findViewById(R.id.update_btn); + mProgressBar = content.findViewById(R.id.progress); + mLaterBtn = content.findViewById(R.id.later_btn); + mInfo = content.findViewById(R.id.info); + mRelativeStatus = content.findViewById(R.id.relative_status); + mCommonStatus = content.findViewById(R.id.common_status); + mFrameBtn = content.findViewById(R.id.frame_btn); + mHideBtn = content.findViewById(R.id.hide_btn); initViews(); @@ -300,17 +328,25 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment private void initViews() { - UiUtils.showIf(mAutoUpdate, mProgressBar); - UiUtils.showIf(!mAutoUpdate, mUpdateBtn); + UiUtils.showIf(mAutoUpdate, mProgressBar, mInfo, mFrameBtn, mHideBtn); + UiUtils.showIf(!mAutoUpdate, mUpdateBtn, mLaterBtn); + + mTitle.setText(mAutoUpdate ? getString(R.string.whats_new_auto_update_updating_maps) + : getString(R.string.whats_new_auto_update_title)); mUpdateBtn.setText(getString(R.string.whats_new_auto_update_button_size, mTotalSize)); mUpdateBtn.setOnClickListener(mUpdateClickListener); - mCancelBtn.setText(mAutoUpdate ? R.string.cancel : R.string.whats_new_auto_update_button_later); - mCancelBtn.setOnClickListener(mCancelClickListener); - mTitle.setText(mAutoUpdate ? String.format(Locale.getDefault(), "%s %d%%", - getString(R.string.whats_new_auto_update_updating_maps), - MapManager.nativeGetOverallProgress(mOutdatedMaps)) - : getString(R.string.whats_new_auto_update_title)); + mLaterBtn.setText(R.string.whats_new_auto_update_button_later); + mLaterBtn.setOnClickListener(mLaterClickListener); + mProgressBar.setOnClickListener(mCancelClickListener); + mHideBtn.setOnClickListener(mHideClickListener); + if (mAutoUpdate) + { + int progress = MapManager.nativeGetOverallProgress(mOutdatedMaps); + mProgressBar.setProgress(progress); + mRelativeStatus.setText(GetRelativeStatusFormatted(progress, mTotalSizeMb * progress / 100, + mTotalSizeMb)); + } } private boolean isAllUpdated() @@ -318,6 +354,13 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment return mOutdatedMaps == null || mLeftoverMaps == null || mLeftoverMaps.isEmpty(); } + @NonNull + String GetRelativeStatusFormatted(int progress, long localSize, long remoteSize) + { + return getString(R.string.downloader_percent, progress + "%", + localSize + getString(R.string.mb), remoteSize + getString(R.string.mb)); + } + private static class DetachableStorageCallback implements MapManager.StorageCallback { @Nullable @@ -339,21 +382,46 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment @Override public void onStatusChanged(List data) { + String mwmId = null; + String mwmStatus = null; for (MapManager.StorageCallbackData item : data) { - if (item.isLeafNode && item.newStatus == CountryItem.STATUS_FAILED) + if (!item.isLeafNode) + continue; + + switch (item.newStatus) { - showErrorDialog(item); - return; - } - else if (item.isLeafNode && item.newStatus == CountryItem.STATUS_DONE) - { - LOGGER.i(TAG, "Update finished for: " + item.countryId); - if (mLeftoverMaps != null) - mLeftoverMaps.remove(item.countryId); + 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: + if (mFragment == null) + break; + mwmId = item.countryId; + mwmStatus = mFragment.getString(R.string.downloader_process); + break; + case CountryItem.STATUS_APPLYING: + if (mFragment == null) + break; + mwmId = item.countryId; + mwmStatus = mFragment.getString(R.string.downloader_applying); + break; + default: + break; } } + if (mwmId != null && mwmStatus != null && mFragment != null) + { + mFragment.mCommonStatus.setText(String.format(Locale.getDefault(), mwmStatus, + MapManager.nativeGetName(mwmId))); + } + if (mFragment != null && mFragment.isAdded() && mFragment.isAllUpdated()) mFragment.finish(); } @@ -404,15 +472,18 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment } @Override - public void onProgress(String countryId, long localSize, long remoteSize) + public void onProgress(String countryId, long localSizeBytes, long remoteSizeBytes) { if (mOutdatedMaps == null || mFragment == null || !mFragment.isAdded()) return; int progress = MapManager.nativeGetOverallProgress(mOutdatedMaps); - mFragment.mTitle.setText(String.format(Locale.getDefault(), "%s %d%%", - mFragment.getString(R.string.whats_new_auto_update_updating_maps), - progress)); + mFragment.mProgressBar.setProgress(progress); + String relativeStatusFormatted = + mFragment.GetRelativeStatusFormatted(progress, localSizeBytes / Constants.MB, + remoteSizeBytes / Constants.MB); + mFragment.mRelativeStatus.setText(relativeStatusFormatted); + } void attach(@NonNull UpdaterDialogFragment fragment)