forked from organicmaps/organicmaps
[android] Use Framework::ToDoAfterUpdate() method
This commit is contained in:
parent
fdec2dd46e
commit
723a0c06f7
4 changed files with 43 additions and 24 deletions
|
@ -554,7 +554,7 @@ uber::RideRequestLinks Framework::GetUberLinks(string const & productId, ms::Lat
|
|||
return uber::Api::GetRideRequestLinks(productId, from, to);
|
||||
}
|
||||
|
||||
|
||||
int Framework::ToDoAfterUpdate() const { return (int)m_work.ToDoAfterUpdate(); }
|
||||
} // namespace android
|
||||
|
||||
//============ GLUE CODE for com.mapswithme.maps.Framework class =============//
|
||||
|
@ -764,6 +764,12 @@ Java_com_mapswithme_maps_Framework_nativeGetOutdatedCountries(JNIEnv * env, jcla
|
|||
return jni::ToJavaStringArray(env, ids);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeToDoAfterUpdate(JNIEnv * env, jclass)
|
||||
{
|
||||
return g_framework->ToDoAfterUpdate();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeIsDataVersionChanged(JNIEnv * env, jclass)
|
||||
{
|
||||
|
|
|
@ -181,6 +181,8 @@ namespace android
|
|||
ms::LatLon const & to, uber::ProductsCallback const & callback,
|
||||
uber::ErrorCallback const & errorCallback);
|
||||
static uber::RideRequestLinks GetUberLinks(string const & productId, ms::LatLon const & from, ms::LatLon const & to);
|
||||
|
||||
int ToDoAfterUpdate() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,16 @@ public class Framework
|
|||
public static final int ROUTER_TYPE_BICYCLE = 2;
|
||||
public static final int ROUTER_TYPE_TAXI = 3;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({DO_AFTER_UPDATE_NOTHING, DO_AFTER_UPDATE_AUTO_UPDATE, DO_AFTER_UPDATE_ASK_FOR_UPDATE,
|
||||
DO_AFTER_UPDATE_MIGRATE})
|
||||
public @interface DoAfterUpdate {}
|
||||
|
||||
public static final int DO_AFTER_UPDATE_NOTHING = 0;
|
||||
public static final int DO_AFTER_UPDATE_AUTO_UPDATE = 1;
|
||||
public static final int DO_AFTER_UPDATE_ASK_FOR_UPDATE = 2;
|
||||
public static final int DO_AFTER_UPDATE_MIGRATE = 3;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface MapObjectListener
|
||||
{
|
||||
|
@ -140,8 +150,12 @@ public class Framework
|
|||
public static native String nativeGetOutdatedCountriesString();
|
||||
|
||||
@UiThread
|
||||
@NonNull
|
||||
public static native String[] nativeGetOutdatedCountries();
|
||||
|
||||
@DoAfterUpdate
|
||||
public static native int nativeToDoAfterUpdate();
|
||||
|
||||
public static native boolean nativeIsDataVersionChanged();
|
||||
|
||||
public static native void nativeUpdateSavedDataVersion();
|
||||
|
|
|
@ -8,6 +8,7 @@ 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.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -16,7 +17,6 @@ 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;
|
||||
|
@ -40,7 +40,6 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
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;
|
||||
|
@ -149,17 +148,9 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
}
|
||||
};
|
||||
|
||||
@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();
|
||||
final FragmentManager fm = activity.getSupportFragmentManager();
|
||||
if (fm.isDestroyed())
|
||||
return false;
|
||||
|
||||
|
@ -167,21 +158,27 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
if (f != null)
|
||||
return false;
|
||||
|
||||
Bundle args = new Bundle();
|
||||
long size = info.totalSize / Constants.MB;
|
||||
args.putBoolean(ARG_UPDATE_IMMEDIATELY, size < AUTO_UPDATE_THRESHOLD);
|
||||
@Framework.DoAfterUpdate
|
||||
final int result = Framework.nativeToDoAfterUpdate();
|
||||
if (result == Framework.DO_AFTER_UPDATE_MIGRATE || result == Framework.DO_AFTER_UPDATE_NOTHING)
|
||||
return false;
|
||||
|
||||
final UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
|
||||
if (info == null)
|
||||
return false;
|
||||
|
||||
final Bundle args = new Bundle();
|
||||
final long size = info.totalSize / Constants.MB;
|
||||
args.putBoolean(ARG_UPDATE_IMMEDIATELY, result == Framework.DO_AFTER_UPDATE_AUTO_UPDATE);
|
||||
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)
|
||||
{}
|
||||
|
||||
final UpdaterDialogFragment fragment = new UpdaterDialogFragment();
|
||||
fragment.setArguments(args);
|
||||
FragmentTransaction transaction = fm.beginTransaction()
|
||||
.addToBackStack(null);
|
||||
fragment.show(transaction, UpdaterDialogFragment.class.getName());
|
||||
|
||||
Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_SHOW, size);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue