[android] auto-update screen

This commit is contained in:
Arsentiy Milchakov 2018-02-13 18:09:12 +03:00 committed by Aleksandr Zatsepin
parent 2268d704f4
commit f6fdf63b30
4 changed files with 201 additions and 58 deletions

View file

@ -1,15 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/update_widget"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center">
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -45,7 +51,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_half"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/update_btn"
@ -59,24 +65,88 @@
android:visibility="gone"
tools:text="@string/whats_new_auto_update_button_size"
tools:visibility="visible"/>
<ProgressBar
<com.mapswithme.maps.widget.WheelProgressView
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_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"/>
</FrameLayout>
<TextView
android:id="@+id/cancel_btn"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base">
<TextView
android:id="@+id/later_btn"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
android:textColor="?buttonDialogTextColor"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:background="?clickableBackground"
tools:text="@string/whats_new_auto_update_button_later"/>
tools:text="@string/whats_new_auto_update_button_later"
tools:visibility="gone"/>
<LinearLayout
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="@dimen/height_block_base"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="@+id/relative_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
android:text="@string/downloader_percent"/>
<TextView
android:id="@+id/common_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
android:text="@string/downloader_process"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/frame_btn"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_double_plus"
android:layout_marginTop="@dimen/margin_base_plus"
android:paddingTop="@dimen/margin_quarter_plus"
android:paddingBottom="@dimen/margin_quarter_plus"
android:paddingRight="@dimen/margin_half"
android:paddingLeft="@dimen/margin_half"
android:background="?accentButtonBackground"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="@+id/hide_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="@dimen/margin_half"
android:paddingRight="@dimen/margin_half"
android:textAppearance="@style/MwmTextAppearance.Button"
android:textColor="?accentButtonTextColor"
android:fontFamily="@string/robotoMedium"
android:text="@string/downloader_hide_screen"
android:gravity="center_vertical"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="?clickableBackground"
tools:targetApi="jelly_bean"/>
</RelativeLayout>
</LinearLayout>
</com.mapswithme.maps.widget.HeightLimitedFrameLayout>

View file

@ -45,6 +45,7 @@
<dimen name="downloader_status_size">40dp</dimen>
<dimen name="downloader_ad_icon_size">@dimen/downloader_status_size</dimen>
<dimen name="search_progress_size">32dp</dimen>
<dimen name="autoupdate_progress_size">36dp</dimen>
<dimen name="panel_width">360dp</dimen>
<dimen name="button_width">240dp</dimen>

View file

@ -20,12 +20,13 @@ public final class CountryItem implements Comparable<CountryItem>
// 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;

View file

@ -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<MapManager.StorageCallbackData> 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)