Refactor ui callbacks for DownloadIndexesThread
This commit is contained in:
parent
607faa7857
commit
618b705d6c
4 changed files with 51 additions and 68 deletions
|
@ -93,10 +93,8 @@ import net.osmand.plus.helpers.ImportHelper;
|
|||
import net.osmand.plus.helpers.ImportHelper.ImportGpxBottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.WakeLockHelper;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
|
||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||
|
@ -1613,13 +1611,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
// DownloadEvents
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
FirstUsageWizardFragment wizardFragment = getFirstUsageWizardFragment();
|
||||
if (wizardFragment != null) {
|
||||
wizardFragment.newDownloadIndexes();
|
||||
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
|
||||
if (fragment instanceof DownloadEvents) {
|
||||
((DownloadEvents) fragment).newDownloadIndexes();
|
||||
}
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = getContextMenu().findMenuFragment();
|
||||
if (fragmentRef != null) {
|
||||
fragmentRef.get().newDownloadIndexes();
|
||||
}
|
||||
if (dashboardOnMap.isVisible()) {
|
||||
dashboardOnMap.onNewDownloadIndexes();
|
||||
|
@ -1629,13 +1624,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
|
||||
@Override
|
||||
public void downloadInProgress() {
|
||||
FirstUsageWizardFragment wizardFragment = getFirstUsageWizardFragment();
|
||||
if (wizardFragment != null) {
|
||||
wizardFragment.downloadInProgress();
|
||||
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
|
||||
if (fragment instanceof DownloadEvents) {
|
||||
((DownloadEvents) fragment).downloadInProgress();
|
||||
}
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = getContextMenu().findMenuFragment();
|
||||
if (fragmentRef != null) {
|
||||
fragmentRef.get().downloadInProgress();
|
||||
}
|
||||
if (dashboardOnMap.isVisible()) {
|
||||
dashboardOnMap.onDownloadInProgress();
|
||||
|
@ -1644,13 +1636,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
FirstUsageWizardFragment wizardFragment = getFirstUsageWizardFragment();
|
||||
if (wizardFragment != null) {
|
||||
wizardFragment.downloadHasFinished();
|
||||
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
|
||||
if (fragment instanceof DownloadEvents) {
|
||||
((DownloadEvents) fragment).downloadHasFinished();
|
||||
}
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = getContextMenu().findMenuFragment();
|
||||
if (fragmentRef != null) {
|
||||
fragmentRef.get().downloadHasFinished();
|
||||
}
|
||||
if (dashboardOnMap.isVisible()) {
|
||||
dashboardOnMap.onDownloadHasFinished();
|
||||
|
|
|
@ -52,7 +52,7 @@ public class DownloadIndexesThread {
|
|||
private static final int NOTIFICATION_ID = 45;
|
||||
private OsmandApplication app;
|
||||
|
||||
private Set<DownloadEvents> uiCallbacks = new HashSet<>();
|
||||
private DownloadEvents uiActivity = null;
|
||||
private DatabaseHelper dbHelper;
|
||||
private DownloadFileHelper downloadFileHelper;
|
||||
private List<BasicProgressAsyncTask<?, ?, ?, ?>> currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?, ?>>());
|
||||
|
@ -87,20 +87,20 @@ public class DownloadIndexesThread {
|
|||
|
||||
/// UI notifications methods
|
||||
public void setUiActivity(DownloadEvents uiActivity) {
|
||||
uiCallbacks.add(uiActivity);
|
||||
this.uiActivity = uiActivity;
|
||||
}
|
||||
|
||||
public void resetUiActivity(DownloadEvents uiActivity) {
|
||||
uiCallbacks.remove(uiActivity);
|
||||
if (this.uiActivity == uiActivity) {
|
||||
this.uiActivity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
protected void downloadInProgress() {
|
||||
for (DownloadEvents uiActivity : uiCallbacks) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.downloadInProgress();
|
||||
}
|
||||
}
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
|
@ -151,11 +151,9 @@ public class DownloadIndexesThread {
|
|||
|
||||
@UiThread
|
||||
protected void downloadHasFinished() {
|
||||
for (DownloadEvents uiActivity : uiCallbacks) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.downloadHasFinished();
|
||||
}
|
||||
}
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
|
@ -188,12 +186,10 @@ public class DownloadIndexesThread {
|
|||
|
||||
@UiThread
|
||||
protected void newDownloadIndexes() {
|
||||
for (DownloadEvents uiActivity : uiCallbacks) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.newDownloadIndexes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PUBLIC API
|
||||
|
@ -258,11 +254,9 @@ public class DownloadIndexesThread {
|
|||
return;
|
||||
}
|
||||
}
|
||||
for (DownloadEvents uiActivity : uiCallbacks) {
|
||||
if(uiActivity instanceof Activity) {
|
||||
if (uiActivity instanceof Activity) {
|
||||
app.logEvent((Activity) uiActivity, "download_files");
|
||||
}
|
||||
}
|
||||
for(IndexItem item : items) {
|
||||
if (!item.equals(currentDownloadingItem) && !indexItemDownloading.contains(item)) {
|
||||
indexItemDownloading.add(item);
|
||||
|
@ -460,14 +454,12 @@ public class DownloadIndexesThread {
|
|||
currentRunningTask.add(this);
|
||||
super.onPreExecute();
|
||||
downloadFileHelper.setInterruptDownloading(false);
|
||||
for (DownloadEvents uiActivity : uiCallbacks) {
|
||||
if (uiActivity instanceof Activity) {
|
||||
View mainView = ((Activity) uiActivity).findViewById(R.id.MainLayout);
|
||||
if (mainView != null) {
|
||||
mainView.setKeepScreenOn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
startTask(ctx.getString(R.string.shared_string_downloading) + ctx.getString(R.string.shared_string_ellipsis), -1);
|
||||
}
|
||||
|
||||
|
@ -476,14 +468,12 @@ public class DownloadIndexesThread {
|
|||
if (result != null && result.length() > 0) {
|
||||
Toast.makeText(ctx, result, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
for (DownloadEvents uiActivity : uiCallbacks) {
|
||||
if (uiActivity instanceof Activity) {
|
||||
View mainView = ((Activity) uiActivity).findViewById(R.id.MainLayout);
|
||||
if (mainView != null) {
|
||||
mainView.setKeepScreenOn(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
currentRunningTask.remove(this);
|
||||
indexes.updateFilesToUpdate();
|
||||
downloadHasFinished();
|
||||
|
|
|
@ -67,18 +67,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getMyApplication().getDownloadThread().setUiActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getMyApplication().getDownloadThread().resetUiActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
if (downloadIndexesRequested) {
|
||||
|
|
|
@ -24,13 +24,14 @@ import net.osmand.PicassoUtils;
|
|||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragment {
|
||||
public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragment implements DownloadIndexesThread.DownloadEvents {
|
||||
|
||||
public static final String TAG = "WikivoyageExploreDialogFragment";
|
||||
|
||||
|
@ -146,6 +147,21 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
exploreTabFragment.newDownloadIndexes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadInProgress() {
|
||||
exploreTabFragment.downloadInProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
exploreTabFragment.downloadHasFinished();
|
||||
}
|
||||
|
||||
private ColorStateList createBottomNavColorStateList() {
|
||||
return AndroidUtils.createCheckedColorStateList(getContext(), nightMode,
|
||||
R.color.icon_color, R.color.wikivoyage_active_light,
|
||||
|
|
Loading…
Reference in a new issue