[android] Added map updater dialog.

This commit is contained in:
Roman Romanov 2017-04-12 12:20:33 +04:00
parent 7f96c9a7fb
commit fdec2dd46e
7 changed files with 422 additions and 2 deletions

View file

@ -198,7 +198,8 @@ bool HandleJavaException(JNIEnv * env)
const jthrowable e = env->ExceptionOccurred();
env->ExceptionDescribe();
env->ExceptionClear();
LOG(LERROR, (ToNativeString(env, e)));
//LOG(LERROR, (ToNativeString(env, e)));
LOG(LWARNING, (ToNativeString(env, e)));
return true;
}
return false;

View file

@ -751,6 +751,19 @@ Java_com_mapswithme_maps_Framework_nativeGetOutdatedCountriesString(JNIEnv * env
return jni::ToJavaString(env, g_framework->GetOutdatedCountriesString());
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_Framework_nativeGetOutdatedCountries(JNIEnv * env, jclass)
{
vector<Country const *> countries;
vector<string> ids;
class Storage const & storage = g_framework->GetStorage();
storage.GetOutdatedCountries(countries);
for (auto country: countries)
ids.push_back(country->Name());
return jni::ToJavaStringArray(env, ids);
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_Framework_nativeIsDataVersionChanged(JNIEnv * env, jclass)
{

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:layout_gravity="center_horizontal"
android:tag="@string/tag_height_limited"
android:src="@drawable/img_migration"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Title"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:fontFamily="@string/robotoMedium"
tools:text="Update your downloaded maps"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="Update maps supports information about objects in the current state"/>
<FrameLayout
android:layout_width="match_parent"
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_gravity="center_horizontal">
<TextView
android:id="@+id/update_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
android:textColor="?accentButtonTextColor"
android:background="?accentButtonBackground"
android:gravity="center"
android:visibility="gone"
tools:text="Update (203 MB)"
tools:visibility="visible"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
<TextView
android:id="@+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
android:textColor="?buttonDialogTextColor"
android:layout_gravity="center_horizontal"
tools:text="Manually update later"/>
</LinearLayout>
</com.mapswithme.maps.widget.HeightLimitedFrameLayout>

View file

@ -139,6 +139,9 @@ public class Framework
@UiThread
public static native String nativeGetOutdatedCountriesString();
@UiThread
public static native String[] nativeGetOutdatedCountries();
public static native boolean nativeIsDataVersionChanged();
public static native void nativeUpdateSavedDataVersion();

View file

@ -46,6 +46,7 @@ import com.mapswithme.maps.downloader.DownloaderFragment;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.downloader.MigrationFragment;
import com.mapswithme.maps.downloader.OnmapDownloader;
import com.mapswithme.maps.downloader.UpdaterDialogFragment;
import com.mapswithme.maps.editor.AuthDialogFragment;
import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.editor.EditorActivity;
@ -1031,9 +1032,16 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (!NewsFragment.showOn(this))
{
if (ViralFragment.shouldDisplay())
{
new ViralFragment().show(getSupportFragmentManager(), "");
}
else
{
if (UpdaterDialogFragment.showOn(this))
return;
LikesManager.INSTANCE.showDialogs(this);
}
}
}

View file

@ -0,0 +1,289 @@
package com.mapswithme.maps.downloader;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
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.util.ConnectionState;
import com.mapswithme.util.Constants;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_CANCEL;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_DOWNLOAD;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_LATER;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_MANUAL_DOWNLOAD;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_SHOW;
public class UpdaterDialogFragment extends BaseMwmDialogFragment
{
private static final String ARG_UPDATE_IMMEDIATELY = "arg_update_immediately";
private static final String ARG_TOTAL_SIZE = "arg_total_size";
private static final String ARG_TOTAL_SIZE_MB = "arg_total_size_mb";
private static final String ARG_OUTDATED_MAPS = "arg_outdated_maps";
private static final int AUTO_UPDATE_THRESHOLD = 100;
private TextView mTitle;
private TextView mUpdateBtn;
private ProgressBar mProgressBar;
private TextView mCancelBtn;
private int mListenerSlot;
@Nullable
private String mTotalSize;
private long mTotalSizeMb;
private boolean mAutoUpdate;
@NonNull
private final Map<String, CountryItem> mOutdatedMaps = new HashMap<>();
@NonNull
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
{
@Override
public void onStatusChanged(List<MapManager.StorageCallbackData> data)
{
for (MapManager.StorageCallbackData item : data)
{
if (item.isLeafNode && item.newStatus == CountryItem.STATUS_FAILED)
{
String text;
switch (item.errorCode)
{
case CountryItem.ERROR_NO_INTERNET:
text = getString(R.string.common_check_internet_connection_dialog);
break;
case CountryItem.ERROR_OOM:
text = getString(R.string.downloader_no_space_title);
break;
default:
text = String.valueOf(item.errorCode);
}
Statistics.INSTANCE.trackDownloaderDialogError(mTotalSizeMb, text);
MapManager.showError(getActivity(), item, null);
dismiss();
return;
}
CountryItem country = mOutdatedMaps.get(item.countryId);
if (country != null)
country.update();
}
for (CountryItem country : mOutdatedMaps.values())
{
if (country.status != CountryItem.STATUS_DONE)
return;
}
dismiss();
}
@Override
public void onProgress(String countryId, long localSize, long remoteSize)
{
CountryItem country = mOutdatedMaps.get(countryId);
if (country == null)
return;
country.update();
float progress = 0;
for (CountryItem item : mOutdatedMaps.values())
progress += item.progress / mOutdatedMaps.size();
// TODO string resources
mTitle.setText(String.format(Locale.getDefault(), "%s %d%%", "Updating maps", (int) progress));
}
};
@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);
dismiss();
}
};
@NonNull
private final View.OnClickListener mUpdateClickListener = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
MapManager.nativeUpdate(CountryItem.getRootId());
UiUtils.show(mProgressBar);
UiUtils.hide(mUpdateBtn);
// TODO string resources
mTitle.setText(String.format(Locale.getDefault(), "%s %d%%", "Updating maps", 0));
mCancelBtn.setText(R.string.cancel);
Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_MANUAL_DOWNLOAD,
mTotalSizeMb);
}
};
@SuppressWarnings("TryWithIdenticalCatches")
public static boolean showOn(@NonNull FragmentActivity activity)
{
if (!ConnectionState.isWifiConnected() || MapManager.nativeIsLegacyMode())
return false;
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
if (info == null || info.filesCount == 0)
return false;
FragmentManager fm = activity.getSupportFragmentManager();
if (fm.isDestroyed())
return false;
Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName());
if (f != null)
return false;
Bundle args = new Bundle();
long size = info.totalSize / Constants.MB;
args.putBoolean(ARG_UPDATE_IMMEDIATELY, size < AUTO_UPDATE_THRESHOLD);
args.putString(ARG_TOTAL_SIZE, StringUtils.getFileSizeString(info.totalSize));
args.putLong(ARG_TOTAL_SIZE_MB, size);
args.putStringArray(ARG_OUTDATED_MAPS, Framework.nativeGetOutdatedCountries());
try
{
final UpdaterDialogFragment fragment = UpdaterDialogFragment.class.newInstance();
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), UpdaterDialogFragment.class.getName());
} catch (java.lang.InstantiationException ignored)
{}
catch (IllegalAccessException ignored)
{}
Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_SHOW, size);
return true;
}
@Override
protected int getCustomTheme()
{
return super.getFullscreenTheme();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
readArguments();
mListenerSlot = MapManager.nativeSubscribe(mStorageCallback);
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
Dialog res = super.onCreateDialog(savedInstanceState);
res.requestWindowFeature(Window.FEATURE_NO_TITLE);
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);
initViews();
if (mAutoUpdate)
{
MapManager.nativeUpdate(CountryItem.getRootId());
Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_DOWNLOAD,
mTotalSizeMb);
}
return res;
}
@Override
public void onDestroy()
{
MapManager.nativeUnsubscribe(mListenerSlot);
super.onDestroy();
}
@Override
public void onDismiss(DialogInterface dialog)
{
if (MapManager.nativeIsDownloading())
MapManager.nativeCancel(CountryItem.getRootId());
super.onDismiss(dialog);
}
private void readArguments()
{
Bundle args = getArguments();
if (args == null)
return;
mAutoUpdate = args.getBoolean(ARG_UPDATE_IMMEDIATELY);
if (!mAutoUpdate && MapManager.nativeIsDownloading())
mAutoUpdate = true;
mTotalSize = args.getString(ARG_TOTAL_SIZE);
mTotalSizeMb = args.getLong(ARG_TOTAL_SIZE_MB, 0L);
mOutdatedMaps.clear();
String[] ids = args.getStringArray(ARG_OUTDATED_MAPS);
if (ids != null)
{
for (String id : ids)
{
CountryItem item = new CountryItem(id);
item.update();
mOutdatedMaps.put(id, item);
}
}
}
private void initViews()
{
UiUtils.showIf(mAutoUpdate, mProgressBar);
UiUtils.showIf(!mAutoUpdate, mUpdateBtn);
mUpdateBtn.setText(String.format(Locale.US, "%s (%s)", getString(R.string.downloader_update_all_button),
mTotalSize));
mUpdateBtn.setOnClickListener(mUpdateClickListener);
mCancelBtn.setText(mAutoUpdate ? R.string.cancel : R.string.later);
mCancelBtn.setOnClickListener(mCancelClickListener);
// TODO string resources
mTitle.setText(mAutoUpdate ? String.format(Locale.getDefault(), "%s %d%%", "Updating maps", 0)
: "Update your downloaded maps");
}
}

View file

@ -20,7 +20,6 @@ import com.mapswithme.maps.PrivateVariables;
import com.mapswithme.maps.ads.MwmNativeAd;
import com.mapswithme.maps.ads.NativeAdError;
import com.mapswithme.maps.api.ParsedMwmRequest;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.editor.Editor;
@ -35,6 +34,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_BLANK;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_BOOK;
@ -45,10 +45,12 @@ import static com.mapswithme.util.statistics.Statistics.EventParam.ERROR_MESSAGE
import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL;
import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL_LAT;
import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL_LON;
import static com.mapswithme.util.statistics.Statistics.EventParam.MAP_DATA_SIZE;
import static com.mapswithme.util.statistics.Statistics.EventParam.PROVIDER;
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT;
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LAT;
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LON;
import static com.mapswithme.util.statistics.Statistics.EventParam.TYPE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.BOOKING_COM;
import static com.mapswithme.util.statistics.Statistics.ParamValue.OPENTABLE;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_HOTEL_REVIEWS_LAND;
@ -72,6 +74,12 @@ public enum Statistics
public static final String DOWNLOADER_ERROR = "Downloader_Map_error";
public static final String DOWNLOADER_ACTION = "Downloader_Map_action";
public static final String DOWNLOADER_CANCEL = "Downloader_Cancel_downloading";
public static final String DOWNLOADER_DIALOG_SHOW = "Downloader_OnStartScreen_show";
public static final String DOWNLOADER_DIALOG_MANUAL_DOWNLOAD = "Downloader_OnStartScreen_manual_download";
public static final String DOWNLOADER_DIALOG_DOWNLOAD = "Downloader_OnStartScreen_auto_download";
public static final String DOWNLOADER_DIALOG_LATER = "Downloader_OnStartScreen_select_later";
public static final String DOWNLOADER_DIALOG_CANCEL = "Downloader_OnStartScreen_cancel_download";
static final String DOWNLOADER_DIALOG_ERROR = "Downloader_OnStartScreen_error";
// bookmarks
public static final String BMK_DESCRIPTION_CHANGED = "Bookmark. Description changed";
@ -260,6 +268,7 @@ public enum Statistics
static final String BANNER_STATE = "state";
static final String ERROR_CODE = "error_code";
static final String ERROR_MESSAGE = "error_message";
static final String MAP_DATA_SIZE = "map_data_size:";
private EventParam() {}
}
@ -556,6 +565,19 @@ public enum Statistics
.get());
}
public void trackDownloaderDialogEvent(@NonNull String eventName, long size)
{
trackEvent(eventName, Statistics.params()
.add(MAP_DATA_SIZE, size));
}
public void trackDownloaderDialogError(long size, @NonNull String error)
{
trackEvent(DOWNLOADER_DIALOG_ERROR, Statistics.params()
.add(MAP_DATA_SIZE, size)
.add(TYPE, error));
}
public static ParameterBuilder params()
{
return new ParameterBuilder();