forked from organicmaps/organicmaps
[android] Fix map updater dialog behavior.
This commit is contained in:
parent
6e4b1c0be8
commit
a3022e007f
3 changed files with 46 additions and 78 deletions
|
@ -15,9 +15,9 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.maps.news.BaseNewsFragment;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -53,7 +53,8 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
private boolean mAutoUpdate;
|
||||
@Nullable
|
||||
private String[] mOutdatedMaps;
|
||||
private boolean mFromInstanceState;
|
||||
@Nullable
|
||||
private BaseNewsFragment.NewsDialogListener mDoneTask;
|
||||
|
||||
@NonNull
|
||||
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
|
||||
|
@ -95,7 +96,6 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO remove attachMap() when dialog migrated to SplashActivity
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,6 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
if (!isAllUpdated())
|
||||
return;
|
||||
|
||||
// TODO remove attachMap() when dialog migrated to SplashActivity
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@ -126,9 +125,9 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
|
||||
private void finish()
|
||||
{
|
||||
attachMap();
|
||||
updateActivityMenu();
|
||||
dismiss();
|
||||
if (mDoneTask != null)
|
||||
mDoneTask.onDialogDone();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -145,7 +144,6 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
if (MapManager.nativeIsDownloading())
|
||||
MapManager.nativeCancel(CountryItem.getRootId());
|
||||
|
||||
// TODO remove attachMap() when dialog migrated to SplashActivity
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
@ -168,27 +166,38 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
}
|
||||
};
|
||||
|
||||
public static boolean showOn(@NonNull FragmentActivity activity)
|
||||
public static boolean showOn(@NonNull FragmentActivity activity,
|
||||
@Nullable BaseNewsFragment.NewsDialogListener doneTask)
|
||||
{
|
||||
final FragmentManager fm = activity.getSupportFragmentManager();
|
||||
if (fm.isDestroyed())
|
||||
return false;
|
||||
|
||||
Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName());
|
||||
if (f != null)
|
||||
return false;
|
||||
|
||||
@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();
|
||||
@Framework.DoAfterUpdate
|
||||
final int result;
|
||||
|
||||
final long size = info.totalSize / Constants.MB;
|
||||
Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName());
|
||||
if (f != null)
|
||||
{
|
||||
fm.beginTransaction().remove(f).commitAllowingStateLoss();
|
||||
fm.executePendingTransactions();
|
||||
result = Framework.DO_AFTER_UPDATE_AUTO_UPDATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Framework.nativeToDoAfterUpdate();
|
||||
if (result == Framework.DO_AFTER_UPDATE_MIGRATE || result == Framework.DO_AFTER_UPDATE_NOTHING)
|
||||
return false;
|
||||
|
||||
Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_SHOW, size);
|
||||
}
|
||||
|
||||
final Bundle args = new Bundle();
|
||||
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);
|
||||
|
@ -196,15 +205,11 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
|
||||
final UpdaterDialogFragment fragment = new UpdaterDialogFragment();
|
||||
fragment.setArguments(args);
|
||||
fragment.mDoneTask = doneTask;
|
||||
FragmentTransaction transaction = fm.beginTransaction()
|
||||
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
// TODO remove detachMap() when dialog migrated to SplashActivity
|
||||
if (activity instanceof MwmActivity)
|
||||
((MwmActivity) activity).detachMap(transaction);
|
||||
fragment.show(transaction, UpdaterDialogFragment.class.getName());
|
||||
|
||||
Statistics.INSTANCE.trackDownloaderDialogEvent(DOWNLOADER_DIALOG_SHOW, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -219,7 +224,6 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mFromInstanceState = savedInstanceState != null;
|
||||
readArguments();
|
||||
}
|
||||
|
||||
|
@ -250,20 +254,10 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
|
||||
if (isAllUpdated())
|
||||
{
|
||||
// TODO remove attachMap() when dialog migrated to SplashActivity
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO remove detachMap() when dialog migrated to SplashActivity
|
||||
if (getActivity() instanceof MwmActivity && mFromInstanceState)
|
||||
{
|
||||
FragmentTransaction transaction = getActivity().getSupportFragmentManager()
|
||||
.beginTransaction();
|
||||
((MwmActivity) getActivity()).detachMap(transaction);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
mListenerSlot = MapManager.nativeSubscribe(mStorageCallback);
|
||||
|
||||
if (mAutoUpdate && !MapManager.nativeIsDownloading())
|
||||
|
@ -291,29 +285,12 @@ public class UpdaterDialogFragment extends BaseMwmDialogFragment
|
|||
if (MapManager.nativeIsDownloading())
|
||||
MapManager.nativeCancel(CountryItem.getRootId());
|
||||
|
||||
// TODO remove attachMap() when dialog migrated to SplashActivity
|
||||
attachMap();
|
||||
updateActivityMenu();
|
||||
if (mDoneTask != null)
|
||||
mDoneTask.onDialogDone();
|
||||
|
||||
super.onCancel(dialog);
|
||||
}
|
||||
|
||||
private void updateActivityMenu()
|
||||
{
|
||||
if (!(getActivity() instanceof MwmActivity))
|
||||
return;
|
||||
|
||||
((MwmActivity)getActivity()).getMainMenu().onResume(null);
|
||||
}
|
||||
|
||||
//TODO remove attachMap() when dialog migrated to SplashActivity
|
||||
private void attachMap()
|
||||
{
|
||||
if (!(getActivity() instanceof MwmActivity))
|
||||
return;
|
||||
|
||||
((MwmActivity)getActivity()).attachMap();
|
||||
}
|
||||
|
||||
private void readArguments()
|
||||
{
|
||||
Bundle args = getArguments();
|
||||
|
|
|
@ -332,6 +332,12 @@ public abstract class BaseNewsFragment extends BaseMwmDialogFragment
|
|||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected NewsDialogListener getListener()
|
||||
{
|
||||
return mListener;
|
||||
}
|
||||
|
||||
public interface NewsDialogListener
|
||||
{
|
||||
void onDialogDone();
|
||||
|
|
|
@ -2,30 +2,17 @@ package com.mapswithme.maps.news;
|
|||
|
||||
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 com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.downloader.UpdaterDialogFragment;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
import com.mapswithme.util.Counters;
|
||||
|
||||
public class NewsFragment extends BaseNewsFragment
|
||||
{
|
||||
private static final long DONE_DELAY = MwmApplication.get().getResources()
|
||||
.getInteger(android.R.integer.config_longAnimTime);
|
||||
|
||||
@NonNull
|
||||
private final Runnable mDoneTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
NewsFragment.super.onDoneClick();
|
||||
}
|
||||
};
|
||||
|
||||
private class Adapter extends BaseNewsFragment.Adapter
|
||||
{
|
||||
|
@ -75,17 +62,10 @@ public class NewsFragment extends BaseNewsFragment
|
|||
@Override
|
||||
protected void onDoneClick()
|
||||
{
|
||||
if (!UpdaterDialogFragment.showOn(getActivity()))
|
||||
if (!UpdaterDialogFragment.showOn(getActivity(), getListener()))
|
||||
super.onDoneClick();
|
||||
else
|
||||
UiThread.runLater(mDoneTask, DONE_DELAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
UiThread.cancelDelayedTasks(mDoneTask);
|
||||
super.onDestroy();
|
||||
dismissAllowingStateLoss();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +73,7 @@ public class NewsFragment extends BaseNewsFragment
|
|||
* @return whether "What's new" dialog should be shown.
|
||||
*/
|
||||
public static boolean showOn(@NonNull FragmentActivity activity,
|
||||
@Nullable NewsDialogListener listener)
|
||||
final @Nullable NewsDialogListener listener)
|
||||
{
|
||||
if (Counters.getFirstInstallVersion() >= BuildConfig.VERSION_CODE)
|
||||
return false;
|
||||
|
@ -102,6 +82,10 @@ public class NewsFragment extends BaseNewsFragment
|
|||
if (fm.isDestroyed())
|
||||
return false;
|
||||
|
||||
Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName());
|
||||
if (f != null)
|
||||
return UpdaterDialogFragment.showOn(activity, listener);
|
||||
|
||||
if (Counters.getLastWhatsNewVersion() / 10 >= BuildConfig.VERSION_CODE / 10 &&
|
||||
!recreate(activity, NewsFragment.class))
|
||||
return false;
|
||||
|
@ -109,6 +93,7 @@ public class NewsFragment extends BaseNewsFragment
|
|||
create(activity, NewsFragment.class, listener);
|
||||
|
||||
Counters.setWhatsNewShown();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue