Download progress implemented.
This commit is contained in:
parent
39b63df47f
commit
598bbb3758
4 changed files with 40 additions and 11 deletions
|
@ -627,11 +627,17 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
|
||||
public void setOnProgressUpdateListener(OnProgressUpdateListener onProgressUpdateListener) {
|
||||
this.onProgressUpdateListener = onProgressUpdateListener;
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if (onProgressUpdateListener == null) return;
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
|
||||
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
final boolean isFinished = basicProgressAsyncTask == null
|
||||
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
|
||||
if (isFinished) {
|
||||
this.onProgressUpdateListener.onFinished();
|
||||
onProgressUpdateListener.onFinished();
|
||||
} else {
|
||||
onProgressUpdateListener.onProgressUpdate(
|
||||
basicProgressAsyncTask.getProgressPercentage(),
|
||||
downloadListIndexThread.getDownloads());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.download.items;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -64,13 +65,24 @@ public class RegionDialogFragment extends DialogFragment {
|
|||
});
|
||||
|
||||
if (this.region != null) {
|
||||
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
|
||||
RegionItemsFragment.createInstance(region)).commit();
|
||||
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
|
||||
if (fragment == null) {
|
||||
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
|
||||
RegionItemsFragment.createInstance(region)).commit();
|
||||
}
|
||||
toolbar.setTitle(this.region.getName());
|
||||
}
|
||||
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication().getSettings(),
|
||||
getResources());
|
||||
|
||||
final WorldRegion finalRegion = region;
|
||||
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
|
||||
@Override
|
||||
public void onProgressUpdate(int progressPercentage, int activeTasks) {
|
||||
LOG.debug(finalRegion.getName() + " onProgressUpdate()");
|
||||
super.onProgressUpdate(progressPercentage, activeTasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinished() {
|
||||
super.onFinished();
|
||||
|
@ -85,6 +97,7 @@ public class RegionDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
LOG.debug(region.getName() + " onResume()");
|
||||
getMyActivity().setOnProgressUpdateListener(mProgressListener);
|
||||
}
|
||||
|
||||
|
@ -109,7 +122,7 @@ public class RegionDialogFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
public void onRegionSelected(WorldRegion region) {
|
||||
createInstance(region).show(getChildFragmentManager(), TAG);
|
||||
DownloadsUiHelper.showDialog(getActivity(), createInstance(region));
|
||||
}
|
||||
|
||||
public static RegionDialogFragment createInstance(WorldRegion region) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -66,11 +65,7 @@ public class WorldItemsFragment extends Fragment {
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
WorldRegion region = worldRegionsAdapter.getItem(position);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
||||
fragmentTransaction.addToBackStack(null);
|
||||
RegionDialogFragment.createInstance(region)
|
||||
.show(fragmentTransaction, RegionDialogFragment.TAG);
|
||||
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package net.osmand.plus.download.newimplementation;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
@ -46,6 +50,17 @@ public final class DownloadsUiHelper {
|
|||
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
|
||||
}
|
||||
|
||||
public static void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||
Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
|
||||
if (prev != null) {
|
||||
ft.remove(prev);
|
||||
}
|
||||
ft.addToBackStack(null);
|
||||
|
||||
fragment.show(ft, "dialog");
|
||||
}
|
||||
|
||||
public static class MapDownloadListener implements DownloadActivity.OnProgressUpdateListener {
|
||||
private final View freeVersionBanner;
|
||||
private final View downloadProgressLayout;
|
||||
|
|
Loading…
Reference in a new issue