forked from organicmaps/organicmaps
[new downloader][android] fix: Show "Downloading: 42%" instead of "Preparation" in migration dialog.
This commit is contained in:
parent
014133bcdb
commit
39a6c19a40
8 changed files with 35 additions and 26 deletions
|
@ -422,10 +422,10 @@ void Framework::Migrate(bool keepOldMaps)
|
|||
m_work.Migrate(keepOldMaps);
|
||||
}
|
||||
|
||||
bool Framework::PreMigrate(ms::LatLon const & position, Storage::TChangeCountryFunction const & statusChangeListener,
|
||||
Storage::TProgressFunction const & progressListener)
|
||||
storage::TCountryId Framework::PreMigrate(ms::LatLon const & position, Storage::TChangeCountryFunction const & statusChangeListener,
|
||||
Storage::TProgressFunction const & progressListener)
|
||||
{
|
||||
return (m_work.PreMigrate(position, statusChangeListener, progressListener) != kInvalidCountryId);
|
||||
return m_work.PreMigrate(position, statusChangeListener, progressListener);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -151,8 +151,8 @@ namespace android
|
|||
place_page::Info & GetPlacePageInfo();
|
||||
|
||||
bool HasSpaceForMigration();
|
||||
bool PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & statusChangeListener,
|
||||
storage::Storage::TProgressFunction const & progressListener);
|
||||
storage::TCountryId PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & statusChangeListener,
|
||||
storage::Storage::TProgressFunction const & progressListener);
|
||||
void Migrate(bool keepOldMaps);
|
||||
|
||||
private:
|
||||
|
|
|
@ -121,8 +121,8 @@ static void OnMigrationError(NodeErrorCode error)
|
|||
|
||||
static void MigrationStatusChangedCallback(TCountryId const & countryId, bool keepOldMaps)
|
||||
{
|
||||
NodeAttrs attrs;
|
||||
GetStorage().GetPrefetchStorage()->GetNodeAttrs(countryId, attrs);
|
||||
NodeStatuses attrs;
|
||||
GetStorage().GetPrefetchStorage()->GetNodeStatuses(countryId, attrs);
|
||||
|
||||
switch (attrs.m_status)
|
||||
{
|
||||
|
@ -132,7 +132,7 @@ static void MigrationStatusChangedCallback(TCountryId const & countryId, bool ke
|
|||
|
||||
case NodeStatus::Undefined:
|
||||
case NodeStatus::Error:
|
||||
if (attrs.m_mwmCounter == 1)
|
||||
if (!attrs.m_groupNode)
|
||||
OnMigrationError(attrs.m_error);
|
||||
break;
|
||||
|
||||
|
@ -149,8 +149,8 @@ static void MigrationProgressCallback(TCountryId const & countryId, TLocalAndRem
|
|||
env->CallVoidMethod(g_migrationListener, callback, static_cast<jint>(sizes.first * 100 / sizes.second));
|
||||
}
|
||||
|
||||
// static boolean nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps);
|
||||
JNIEXPORT jboolean JNICALL
|
||||
// static @Nullable String nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps);
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_downloader_MapManager_nativeMigrate(JNIEnv * env, jclass clazz, jobject listener, jdouble lat, jdouble lon, jboolean hasLocation, jboolean keepOldMaps)
|
||||
{
|
||||
ms::LatLon position{};
|
||||
|
@ -159,14 +159,17 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeMigrate(JNIEnv * env, jclas
|
|||
|
||||
g_migrationListener = env->NewGlobalRef(listener);
|
||||
|
||||
if (g_framework->PreMigrate(position, bind(&MigrationStatusChangedCallback, _1, keepOldMaps),
|
||||
bind(&MigrationProgressCallback, _1, _2)))
|
||||
TCountryId id = g_framework->PreMigrate(position, bind(&MigrationStatusChangedCallback, _1, keepOldMaps),
|
||||
bind(&MigrationProgressCallback, _1, _2));
|
||||
if (id != kInvalidCountryId)
|
||||
{
|
||||
return true;
|
||||
NodeAttrs attrs;
|
||||
GetStorage().GetPrefetchStorage()->GetNodeAttrs(id, attrs);
|
||||
return jni::ToJavaString(env, attrs.m_nodeLocalName);
|
||||
}
|
||||
|
||||
OnPrefetchComplete(keepOldMaps);
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// static void nativeCancelMigration();
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_base"
|
||||
android:text="@string/migration_prefetch_status"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"/>
|
||||
|
||||
<FrameLayout
|
||||
|
|
|
@ -137,10 +137,11 @@ public final class MapManager
|
|||
|
||||
/**
|
||||
* Performs migration from old (large MWMs) mode.
|
||||
* @return {@code true} if prefetch was started. {@code false} if maps were queued to downloader and migration process is complete.
|
||||
* In this case {@link MigrationListener#onComplete()} will be called before return from {@code nativeMigrate()}.
|
||||
* @return Name of the country to be loaded during the prefetch.
|
||||
* Or {@code null} if maps were queued to downloader and migration process is complete.
|
||||
* In the latter case {@link MigrationListener#onComplete()} will be called before return from {@code nativeMigrate()}.
|
||||
*/
|
||||
public static native boolean nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps);
|
||||
public static native @Nullable String nativeMigrate(MigrationListener listener, double lat, double lon, boolean hasLocation, boolean keepOldMaps);
|
||||
|
||||
/**
|
||||
* Aborts migration. Affects only prefetch process.
|
||||
|
|
|
@ -19,7 +19,7 @@ final class MigrationController
|
|||
interface Container
|
||||
{
|
||||
void setReadyState();
|
||||
void setProgressState();
|
||||
void setProgressState(String countryName);
|
||||
void setErrorState(int code);
|
||||
void onComplete();
|
||||
|
||||
|
@ -30,6 +30,7 @@ final class MigrationController
|
|||
|
||||
private Container mContainer;
|
||||
private State mState;
|
||||
private String mPrefetchingCountry;
|
||||
private int mProgress;
|
||||
private int mError;
|
||||
|
||||
|
@ -90,7 +91,7 @@ final class MigrationController
|
|||
private void callStateProgress()
|
||||
{
|
||||
if (mContainer != null)
|
||||
mContainer.setProgressState();
|
||||
mContainer.setProgressState(mPrefetchingCountry);
|
||||
}
|
||||
|
||||
private void callStateError()
|
||||
|
@ -152,7 +153,8 @@ final class MigrationController
|
|||
double lat = (loc == null ? 0.0 : loc.getLatitude());
|
||||
double lon = (loc == null ? 0.0 : loc.getLongitude());
|
||||
|
||||
if (!MapManager.nativeMigrate(mListener, lat, lon, (loc != null), keepOld))
|
||||
mPrefetchingCountry = MapManager.nativeMigrate(mListener, lat, lon, (loc != null), keepOld);
|
||||
if (mPrefetchingCountry == null)
|
||||
return;
|
||||
|
||||
mState = State.PROGRESS;
|
||||
|
|
|
@ -24,7 +24,7 @@ public class MigrationFragment extends BaseMwmFragment
|
|||
MigrationController.Container
|
||||
{
|
||||
private TextView mError;
|
||||
private View mPrepare;
|
||||
private TextView mPrepare;
|
||||
private WheelProgressView mProgress;
|
||||
private Button mButtonPrimary;
|
||||
private Button mButtonSecondary;
|
||||
|
@ -56,7 +56,7 @@ public class MigrationFragment extends BaseMwmFragment
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mError = (TextView) view.findViewById(R.id.error);
|
||||
mPrepare = view.findViewById(R.id.preparation);
|
||||
mPrepare = (TextView) view.findViewById(R.id.preparation);
|
||||
mProgress = (WheelProgressView) view.findViewById(R.id.progress);
|
||||
mButtonPrimary = (Button) view.findViewById(R.id.button_primary);
|
||||
mButtonSecondary = (Button) view.findViewById(R.id.button_secondary);
|
||||
|
@ -107,10 +107,11 @@ public class MigrationFragment extends BaseMwmFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setProgressState()
|
||||
public void setProgressState(String countryName)
|
||||
{
|
||||
UiUtils.show(mPrepare, mProgress);
|
||||
UiUtils.hide(mError, mButtonPrimary, mButtonSecondary);
|
||||
mPrepare.setText(String.format("%1$2s %2$s", getString(R.string.downloader_downloading), countryName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,7 +156,9 @@ public class MigrationFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void setProgress(int percents)
|
||||
{
|
||||
mProgress.setProgress(percents);
|
||||
mProgress.setPending(percents == 0);
|
||||
if (percents > 0)
|
||||
mProgress.setProgress(percents);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.widget.Button;
|
|||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -116,7 +117,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
|
|||
{
|
||||
mProgress.setPending(false);
|
||||
mProgress.setProgress(mCurrentCountry.progress);
|
||||
sizeText = mCurrentCountry.progress + "%";
|
||||
sizeText = String.format(Locale.US, "%1$s %2$d%%", mActivity.getString(R.string.downloader_downloading), mCurrentCountry.progress);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue