Downloads progress implementation in progress.

This commit is contained in:
GaidamakUA 2015-10-02 11:15:59 +03:00
parent 2b6cdf2d9b
commit 2807fb7329
10 changed files with 156 additions and 127 deletions

View file

@ -3,73 +3,5 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="@layout/free_version_banner"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/list_world_regions_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="World Regions"
android:textSize="@dimen/default_desc_text_size"/>
<ListView
android:id="@+id/list_world_regions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="@android:color/transparent"
android:isScrollContainer="false"
android:scrollbars="none"/>
<TextView
android:id="@+id/list_world_maps_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="World Maps"
android:textSize="@dimen/default_desc_text_size"/>
<ListView
android:id="@+id/list_world_maps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="@android:color/transparent"
android:isScrollContainer="false"
android:scrollbars="none"/>
<TextView
android:id="@+id/list_voice_promts_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="Voice Promts"
android:textSize="@dimen/default_desc_text_size"/>
<ListView
android:id="@+id/list_voice_promts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="@android:color/transparent"
android:isScrollContainer="false"
android:scrollbars="none"/>
</LinearLayout>
</ScrollView>
<include layout="@layout/free_version_banner"/><include layout="@layout/local_items_fragment"/>
</LinearLayout>

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/download_index_fragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/list_world_regions_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="World Regions"
android:textSize="@dimen/default_desc_text_size"/>
<ListView
android:id="@+id/list_world_regions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="@android:color/transparent"
android:isScrollContainer="false"
android:scrollbars="none"/>
<TextView
android:id="@+id/list_world_maps_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="World Maps"
android:textSize="@dimen/default_desc_text_size"/>
<ListView
android:id="@+id/list_world_maps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="@android:color/transparent"
android:isScrollContainer="false"
android:scrollbars="none"/>
<TextView
android:id="@+id/list_voice_promts_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="Voice Promts"
android:textSize="@dimen/default_desc_text_size"/>
<ListView
android:id="@+id/list_voice_promts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="@android:color/transparent"
android:isScrollContainer="false"
android:scrollbars="none"/>
</LinearLayout>
</ScrollView>

View file

@ -15,7 +15,8 @@
app:contentInsetLeft="72dp"
app:contentInsetStart="72dp"/>
<include layout="@layout/free_version_banner"/>
<include layout="@layout/free_version_banner"
android:background="#F00"/>
<LinearLayout
android:id="@+id/downloadProgressLayout"
xmlns:tools="http://schemas.android.com/tools"

View file

@ -55,9 +55,9 @@ public class ItemViewHolder {
public void onClick(View v) {
((BaseDownloadActivity) v.getContext())
.startDownload((IndexItem) v.getTag(R.id.index_item));
progressBar.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(getContextIcon(context,
R.drawable.ic_action_remove_dark));
// progressBar.setVisibility(View.VISIBLE);
// rightImageButton.setImageDrawable(getContextIcon(context,
// R.drawable.ic_action_remove_dark));
}
});
progressBar.setVisibility(View.GONE);

View file

@ -12,6 +12,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.newimplementation.DownloadsUiHelper;
import org.apache.commons.logging.Log;
@ -20,6 +22,7 @@ public class LocalDialogFragment extends DialogFragment {
public static final String TAG = "LocalDialogFragment";
private static final String REGION_DLG_KEY = "world_region_dialog_key";
private WorldRegion region;
private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -33,7 +36,7 @@ public class LocalDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
WorldRegion region = null;
if (savedInstanceState != null) {
@ -65,10 +68,32 @@ public class LocalDialogFragment extends DialogFragment {
LocalItemsFragment.createInstance(region)).commit();
toolbar.setTitle(this.region.getName());
}
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication().getSettings(),
getResources());
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
@Override
public void onFinished() {
super.onFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication().getSettings(), getResources());
}
};
return view;
}
@Override
public void onResume() {
super.onResume();
getMyActivity().setOnProgressUpdateListener(mProgressListener);
}
@Override
public void onPause() {
super.onPause();
getMyActivity().setOnProgressUpdateListener(null);
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(REGION_DLG_KEY, region);
@ -79,6 +104,10 @@ public class LocalDialogFragment extends DialogFragment {
return (OsmandApplication) getActivity().getApplication();
}
private DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
public void onRegionSelected(WorldRegion region) {
createInstance(region).show(getChildFragmentManager(), TAG);
}

View file

@ -9,20 +9,15 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import org.apache.commons.logging.Log;
@ -74,7 +69,7 @@ public class LocalItemsFragment extends Fragment {
this.region = region;
View view = inflater.inflate(R.layout.download_index_fragment, container, false);
View view = inflater.inflate(R.layout.local_items_fragment, container, false);
builder = new ItemsListBuilder(getMyApplication(), this.region);

View file

@ -23,7 +23,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.newimplementation.DownloadsUiInitHelper;
import net.osmand.plus.download.newimplementation.DownloadsUiHelper;
import org.apache.commons.logging.Log;
@ -88,7 +88,7 @@ public class WorldItemsFragment extends Fragment {
onCategorizationFinished();
DownloadsUiInitHelper.initFreeVersionBanner(view,
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication().getSettings(), getResources());
return view;

View file

@ -8,9 +8,10 @@ import android.widget.TextView;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
public final class DownloadsUiInitHelper {
private DownloadsUiInitHelper() {
public final class DownloadsUiHelper {
private DownloadsUiHelper() {
}
public static void initFreeVersionBanner(View header, OsmandSettings settings,
@ -44,4 +45,40 @@ public final class DownloadsUiInitHelper {
(ProgressBar) header.findViewById(R.id.downloadsLeftProgressBar);
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
}
public static class MapDownloadListener implements DownloadActivity.OnProgressUpdateListener {
private final View freeVersionBanner;
private final View downloadProgressLayout;
private final ProgressBar progressBar;
private final TextView leftTextView;
private final TextView rightTextView;
private final Resources resources;
public MapDownloadListener(View view, Resources resources) {
this.resources = resources;
freeVersionBanner = view.findViewById(R.id.freeVersionBanner);
downloadProgressLayout = view.findViewById(R.id.downloadProgressLayout);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
leftTextView = (TextView) view.findViewById(R.id.leftTextView);
rightTextView = (TextView) view.findViewById(R.id.rightTextView);
}
@Override
public void onProgressUpdate(int progressPercentage, int activeTasks) {
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
freeVersionBanner.setVisibility(View.GONE);
downloadProgressLayout.setVisibility(View.VISIBLE);
}
progressBar.setProgress(progressPercentage);
final String format = resources.getString(R.string.downloading_number_of_fiels);
String numberOfTasks = String.format(format, activeTasks);
leftTextView.setText(numberOfTasks);
rightTextView.setText(progressPercentage + "%");
}
@Override
public void onFinished() {
freeVersionBanner.setVisibility(View.VISIBLE);
downloadProgressLayout.setVisibility(View.GONE);
}
}
}

View file

@ -1,6 +1,5 @@
package net.osmand.plus.download.newimplementation;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
@ -8,8 +7,6 @@ import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
@ -23,7 +20,7 @@ public class MapsInCategoryFragment extends DialogFragment {
private static final Log LOG = PlatformUtil.getLog(IndexItemCategoryWithSubcat.class);
public static final String TAG = "MapsInCategoryFragment";
private static final String CATEGORY = "category";
private MapDownloadListener mProgressListener;
private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -44,7 +41,6 @@ public class MapsInCategoryFragment extends DialogFragment {
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
SubcategoriesFragment.createInstance(category)).commit();
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(category.getName());
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
@ -55,13 +51,13 @@ public class MapsInCategoryFragment extends DialogFragment {
}
});
DownloadsUiInitHelper.initFreeVersionBanner(view,
DownloadsUiHelper.initFreeVersionBanner(view,
getMyActivity().getMyApplication().getSettings(), getResources());
mProgressListener = new MapDownloadListener(view, getResources()){
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
@Override
public void onFinished() {
super.onFinished();
DownloadsUiInitHelper.initFreeVersionBanner(view,
DownloadsUiHelper.initFreeVersionBanner(view,
getMyActivity().getMyApplication().getSettings(), getResources());
}
};
@ -104,39 +100,5 @@ public class MapsInCategoryFragment extends DialogFragment {
return fragment;
}
private static class MapDownloadListener implements DownloadActivity.OnProgressUpdateListener {
private final View freeVersionBanner;
private final View downloadProgressLayout;
private final ProgressBar progressBar;
private final TextView leftTextView;
private final TextView rightTextView;
private final Resources resources;
MapDownloadListener(View view, Resources resources) {
this.resources = resources;
freeVersionBanner = view.findViewById(R.id.freeVersionBanner);
downloadProgressLayout = view.findViewById(R.id.downloadProgressLayout);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
leftTextView = (TextView) view.findViewById(R.id.leftTextView);
rightTextView = (TextView) view.findViewById(R.id.rightTextView);
}
@Override
public void onProgressUpdate(int progressPercentage, int activeTasks) {
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
freeVersionBanner.setVisibility(View.GONE);
downloadProgressLayout.setVisibility(View.VISIBLE);
}
progressBar.setProgress(progressPercentage);
final String format = resources.getString(R.string.downloading_number_of_fiels);
String numberOfTasks = String.format(format, activeTasks);
leftTextView.setText(numberOfTasks);
rightTextView.setText(progressPercentage + "%");
}
@Override
public void onFinished() {
freeVersionBanner.setVisibility(View.VISIBLE);
downloadProgressLayout.setVisibility(View.GONE);
}
}
}

View file

@ -69,7 +69,7 @@ public class NewLocalIndexesFragment extends OsmAndListFragment {
View header = inflater.inflate(R.layout.local_index_fragment_header, listView, false);
initMemoryConsumedCard(header);
DownloadsUiInitHelper.initFreeVersionBanner(header, getMyApplication().getSettings(),
DownloadsUiHelper.initFreeVersionBanner(header, getMyApplication().getSettings(),
getResources());
listView.addHeaderView(header);