Update maps

This commit is contained in:
Victor Shcherb 2015-10-06 16:18:48 +03:00
parent 16348e1343
commit e26148780c
10 changed files with 205 additions and 653 deletions

View file

@ -28,8 +28,6 @@
<LinearLayout
android:id="@+id/downloadProgressLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"

View file

@ -20,7 +20,6 @@ import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.ItemsListBuilder;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
@ -114,11 +113,6 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
public void onCategorizationFinished(List<IndexItem> filtered,
List<IndexItemCategoryWithSubcat> cats) {
}
public void onCategorizationFinished() {
}

View file

@ -1,12 +1,43 @@
package net.osmand.plus.download;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.WorldItemsFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
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.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;
@ -21,31 +52,6 @@ import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.WorldItemsFragment;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by Denis
@ -59,6 +65,7 @@ public class DownloadActivity extends BaseDownloadActivity {
private TextView progressMessage;
private TextView progressPercent;
private ImageView cancel;
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
private String initialFilter = "";
@ -75,9 +82,8 @@ public class DownloadActivity extends BaseDownloadActivity {
public static final String UPDATES_TAB = "updates";
public static final String SINGLE_TAB = "SINGLE_TAB";
private List<DownloadActivityType> downloadTypes = new ArrayList<DownloadActivityType>();
private List<IndexItemCategoryWithSubcat> cats;
private BannerAndDownloadFreeVersion visibleBanner;
private OnProgressUpdateListener onProgressUpdateListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -260,19 +266,30 @@ public class DownloadActivity extends BaseDownloadActivity {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
final boolean isFinished = basicProgressAsyncTask == null
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
if (onProgressUpdateListener != null) {
if (isFinished) {
onProgressUpdateListener.onFinished();
} else {
onProgressUpdateListener.onProgressUpdate(
basicProgressAsyncTask.getProgressPercentage(),
downloadListIndexThread.getDownloads());
boolean indeterminate = true;
int percent = 0;
String message = "";
if(!isFinished) {
indeterminate = basicProgressAsyncTask.isIndeterminate();
message = basicProgressAsyncTask.getDescription();
if(!indeterminate) {
percent = basicProgressAsyncTask.getProgressPercentage();
}
}
if(visibleBanner != null) {
visibleBanner.updateProgress(isFinished, indeterminate, percent, message);
}
if(!updateOnlyProgress) {
updateDownloadButton();
}
// TODO delete after refactoring!
//needed when rotation is performed and progress can be null
if (progressView == null) {
return;
}
if (updateOnlyProgress) {
if (!basicProgressAsyncTask.isIndeterminate()) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
@ -281,7 +298,6 @@ public class DownloadActivity extends BaseDownloadActivity {
} else {
progressView.setVisibility(!isFinished ? View.VISIBLE : View.GONE);
if (!isFinished) {
boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
@ -293,8 +309,6 @@ public class DownloadActivity extends BaseDownloadActivity {
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
}
updateDownloadButton();
}
}
@ -553,11 +567,6 @@ public class DownloadActivity extends BaseDownloadActivity {
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
}
public List<IndexItemCategoryWithSubcat> getCats() {
List<IndexItemCategoryWithSubcat> toReturn = cats;
cats = null;
return toReturn;
}
public void showDialogToDownloadMaps(Collection<String> maps) {
int count = 0;
@ -607,25 +616,131 @@ public class DownloadActivity extends BaseDownloadActivity {
}
}
public void initFreeVersionBanner(View header) {
final View freeVersionBanner = header.findViewById(R.id.freeVersionBanner);
visibleBanner = new BannerAndDownloadFreeVersion(freeVersionBanner, this);
}
public 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);
public void setOnProgressUpdateListener(OnProgressUpdateListener onProgressUpdateListener) {
this.onProgressUpdateListener = onProgressUpdateListener;
if (onProgressUpdateListener == null) return;
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
final boolean isFinished = basicProgressAsyncTask == null
|| basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED;
if (isFinished) {
onProgressUpdateListener.onFinished();
} else {
onProgressUpdateListener.onProgressUpdate(
basicProgressAsyncTask.getProgressPercentage(),
downloadListIndexThread.getDownloads());
fragment.show(ft, "dialog");
}
private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener {
private final View freeVersionDescriptionTextView;
private final View buttonsLinearLayout;
private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView,
View buttonsLinearLayout) {
this.freeVersionDescriptionTextView = freeVersionDescriptionTextView;
this.buttonsLinearLayout = buttonsLinearLayout;
}
@Override
public void onClick(View v) {
if (freeVersionDescriptionTextView.getVisibility() == View.VISIBLE) {
freeVersionDescriptionTextView.setVisibility(View.GONE);
buttonsLinearLayout.setVisibility(View.GONE);
} else {
freeVersionDescriptionTextView.setVisibility(View.VISIBLE);
buttonsLinearLayout.setVisibility(View.VISIBLE);
}
}
}
public interface OnProgressUpdateListener {
void onProgressUpdate(int progressPercentage, int activeTasks);
void onFinished();
public static class BannerAndDownloadFreeVersion {
private final View freeVersionBanner;
private final View downloadProgressLayout;
private final ProgressBar progressBar;
private final TextView leftTextView;
private final TextView rightTextView;
private final Context ctx;
private OsmandApplication application;
public BannerAndDownloadFreeVersion(View view, Context ctx) {
this.ctx = ctx;
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);
application = (OsmandApplication) ctx.getApplicationContext();
onCreateBanner(view);
}
public void updateProgress(boolean isFinished, boolean indeterminate, int percent, String message) {
if(isFinished) {
downloadProgressLayout.setVisibility(View.GONE);
// TODO BUG restore free version
} else {
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
freeVersionBanner.setVisibility(View.GONE);
}
downloadProgressLayout.setVisibility(View.VISIBLE);
if(indeterminate) {
// TODO
leftTextView.setText(message);
} else {
// TODO if only 1 map, show map name
progressBar.setProgress(percent);
// final String format = ctx.getString(R.string.downloading_number_of_files);
leftTextView.setText(message);
rightTextView.setText(percent + "%");
}
}
}
private void onCreateBanner(View view) {
OsmandSettings settings = application.getSettings();
if (!Version.isFreeVersion(application) && !settings.SHOULD_SHOW_FREE_VERSION_BANNER.get()) {
freeVersionBanner.setVisibility(View.GONE);
return;
}
TextView downloadsLeftTextView = (TextView) view.findViewById(R.id.downloadsLeftTextView);
final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
- settings.NUMBER_OF_FREE_DOWNLOADS.get();
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
final TextView freeVersionDescriptionTextView = (TextView) view
.findViewById(R.id.freeVersionDescriptionTextView);
freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message,
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
View buttonsLinearLayout = view.findViewById(R.id.buttonsLinearLayout);
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout));
ProgressBar downloadsLeftProgressBar = (ProgressBar) view.findViewById(R.id.downloadsLeftProgressBar);
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
view.findViewById(R.id.getFullVersionButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BaseDownloadActivity context = (BaseDownloadActivity) v.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(context
.getMyApplication()) + "net.osmand.plus"));
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
view.findViewById(R.id.laterButton).setOnClickListener(
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout));
}
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.download;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
@ -30,7 +31,6 @@ import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
import net.osmand.plus.download.items.ItemsListBuilder;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import net.osmand.plus.helpers.DatabaseHelper;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
@ -689,7 +689,6 @@ public class DownloadIndexesThread {
public void runCategorization() {
final BasicProgressAsyncTask<Void, Void, List<IndexItem>> inst
= new BasicProgressAsyncTask<Void, Void, List<IndexItem>>(ctx) {
private List<IndexItemCategoryWithSubcat> catsWithSubcats;
@Override
protected void onPreExecute() {
@ -704,8 +703,6 @@ public class DownloadIndexesThread {
@Override
protected List<IndexItem> doInBackground(Void... params) {
final List<IndexItem> filtered = getFilteredByType();
catsWithSubcats =
IndexItemCategoryWithSubcat.categorizeIndexItems(app, filtered);
updateLoadedFiles();
return filtered;
}
@ -726,7 +723,6 @@ public class DownloadIndexesThread {
prepareFilesToUpdate();
currentRunningTask.remove(this);
if (uiActivity != null) {
uiActivity.onCategorizationFinished(filtered, catsWithSubcats);
uiActivity.updateProgress(false);
}
}

View file

@ -675,7 +675,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
if(dir.canRead()){
StatFs fs = new StatFs(dir.getAbsolutePath());
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
percent = (int) (fs.getAvailableBlocks() * 100 / fs.getBlockCount());
percent = 100 - (int) (fs.getAvailableBlocks() * 100 / fs.getBlockCount());
}
sizeProgress.setProgress(percent);
String text = getString(R.string.free, size);

View file

@ -1,5 +1,10 @@
package net.osmand.plus.download.items;
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 android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
@ -8,22 +13,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.PlatformUtil;
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;
public class RegionDialogFragment extends DialogFragment {
private static final Log LOG = PlatformUtil.getLog(RegionDialogFragment.class);
public static final String TAG = "RegionDialogFragment";
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
private String regionId;
private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -68,38 +61,10 @@ public class RegionDialogFragment extends DialogFragment {
toolbar.setTitle(region.getName());
}
}
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(),
getResources());
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
@Override
public void onProgressUpdate(int progressPercentage, int activeTasks) {
super.onProgressUpdate(progressPercentage, activeTasks);
}
@Override
public void onFinished() {
super.onFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication(), getResources());
}
};
((DownloadActivity)getActivity()).initFreeVersionBanner(view);
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.putString(REGION_ID_DLG_KEY, regionId);
@ -110,12 +75,8 @@ public class RegionDialogFragment extends DialogFragment {
return (OsmandApplication) getActivity().getApplication();
}
private DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
public void onRegionSelected(String regionId) {
DownloadsUiHelper.showDialog(getActivity(), createInstance(regionId));
((DownloadActivity)getActivity()).showDialog(getActivity(), createInstance(regionId));
}
public static RegionDialogFragment createInstance(String regionId) {

View file

@ -1,5 +1,25 @@
package net.osmand.plus.download.items;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import org.apache.commons.logging.Log;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@ -16,27 +36,6 @@ import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.newimplementation.DownloadsUiHelper;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class WorldItemsFragment extends OsmandExpandableListFragment {
public static final String TAG = "WorldItemsFragment";
private static final Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
@ -70,8 +69,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
onCategorizationFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication(), getResources());
((DownloadActivity) getActivity()).initFreeVersionBanner(view);
return view;
}
@ -128,7 +126,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (groupPosition == worldRegionsIndex) {
WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
((DownloadActivity)getActivity()).showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
return true;
} else if (groupPosition == voicePromptsIndex) {
//

View file

@ -1,132 +0,0 @@
package net.osmand.plus.download.newimplementation;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.plus.R;
public class CategoryStaticData implements Parcelable {
public static final CategoryStaticData WORLD_WIDE_AND_TOPIC =
new CategoryStaticData(R.string.index_name_other, 0);
public static final CategoryStaticData NAME_VOICE =
new CategoryStaticData(R.string.index_name_voice, 1);
public static final CategoryStaticData TTS_VOICE =
new CategoryStaticData(R.string.index_name_tts_voice, 2);
public static final CategoryStaticData WIKI =
new CategoryStaticData(R.string.index_name_wiki, 10);
public static final CategoryStaticData OPENMAPS =
new CategoryStaticData(R.string.index_name_openmaps, 90);
public static final CategoryStaticData NORTH_AMERICA =
new CategoryStaticData(R.string.index_name_north_america, 30);
public static final CategoryStaticData US =
new CategoryStaticData(R.string.index_name_us, 31, NORTH_AMERICA);
public static final CategoryStaticData CANADA =
new CategoryStaticData(R.string.index_name_canada, 32, NORTH_AMERICA);
public static final CategoryStaticData CENTRAL_AMERICA =
new CategoryStaticData(R.string.index_name_central_america, 40);
public static final CategoryStaticData SOUTH_AMERICA =
new CategoryStaticData(R.string.index_name_south_america, 45);
public static final CategoryStaticData RUSSIA =
new CategoryStaticData(R.string.index_name_russia, 25);
public static final CategoryStaticData EUROPE =
new CategoryStaticData(R.string.index_name_europe, 15);
public static final CategoryStaticData GERMANY =
new CategoryStaticData(R.string.index_name_germany, 16, EUROPE);
public static final CategoryStaticData FRANCE =
new CategoryStaticData(R.string.index_name_france, 17, EUROPE);
public static final CategoryStaticData ITALY =
new CategoryStaticData(R.string.index_name_italy, 18, EUROPE);
public static final CategoryStaticData GB =
new CategoryStaticData(R.string.index_name_gb, 19, EUROPE);
public static final CategoryStaticData NETHERLANDS =
new CategoryStaticData(R.string.index_name_netherlands, 20, EUROPE);
public static final CategoryStaticData AFRICA =
new CategoryStaticData(R.string.index_name_africa, 80);
public static final CategoryStaticData ASIA =
new CategoryStaticData(R.string.index_name_asia, 50);
public static final CategoryStaticData OCEANIA =
new CategoryStaticData(R.string.index_name_oceania, 70);
public static final CategoryStaticData TOURS =
new CategoryStaticData(R.string.index_tours, 0);
private final int nameId;
private final int order;
private final CategoryStaticData parent;
private String name;
CategoryStaticData(int nameId, int order) {
this.nameId = nameId;
this.order = order;
parent = null;
}
CategoryStaticData(int nameId, int order, CategoryStaticData parent) {
this.nameId = nameId;
this.order = order;
this.parent = parent;
}
public int getNameId() {
return nameId;
}
public int getOrder() {
return order;
}
public CategoryStaticData getParent() {
return parent;
}
public boolean hasParent() {
return parent != null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "CategoryStaticData{" +
"nameId=" + nameId +
", order=" + order +
", parent=" + parent +
", name='" + name + '\'' +
'}';
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.nameId);
dest.writeInt(this.order);
dest.writeParcelable(this.parent, flags);
dest.writeString(this.name);
}
protected CategoryStaticData(Parcel in) {
this.nameId = in.readInt();
this.order = in.readInt();
this.parent = in.readParcelable(CategoryStaticData.class.getClassLoader());
this.name = in.readString();
}
public static final Parcelable.Creator<CategoryStaticData> CREATOR = new Parcelable.Creator<CategoryStaticData>() {
public CategoryStaticData createFromParcel(Parcel source) {
return new CategoryStaticData(source);
}
public CategoryStaticData[] newArray(int size) {
return new CategoryStaticData[size];
}
};
}

View file

@ -1,139 +0,0 @@
package net.osmand.plus.download.newimplementation;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
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;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
public final class DownloadsUiHelper {
private DownloadsUiHelper() {
}
public static void initFreeVersionBanner(View header, OsmandApplication application,
Resources resources) {
final View freeVersionBanner = header.findViewById(R.id.freeVersionBanner);
OsmandSettings settings = application.getSettings();
if(!Version.isFreeVersion(application) && !settings.SHOULD_SHOW_FREE_VERSION_BANNER.get()) {
freeVersionBanner.setVisibility(View.GONE);
return;
}
TextView downloadsLeftTextView = (TextView) header.findViewById(R.id.downloadsLeftTextView);
final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
- settings.NUMBER_OF_FREE_DOWNLOADS.get();
downloadsLeftTextView.setText(resources.getString(R.string.downloads_left_template,
downloadsLeft));
final TextView freeVersionDescriptionTextView =
(TextView) header.findViewById(R.id.freeVersionDescriptionTextView);
freeVersionDescriptionTextView.setText(resources.getString(R.string.free_version_message,
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
final View buttonsLinearLayout = header.findViewById(R.id.buttonsLinearLayout);
freeVersionBanner.setOnClickListener(
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout));
ProgressBar downloadsLeftProgressBar =
(ProgressBar) header.findViewById(R.id.downloadsLeftProgressBar);
downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get());
header.findViewById(R.id.getFullVersionButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BaseDownloadActivity context = (BaseDownloadActivity) v.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(Version.marketPrefix(context.getMyApplication())
+ "net.osmand.plus"));
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
header.findViewById(R.id.laterButton).setOnClickListener(
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout));
}
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");
}
private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener {
private final View freeVersionDescriptionTextView;
private final View buttonsLinearLayout;
private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView,
View buttonsLinearLayout) {
this.freeVersionDescriptionTextView = freeVersionDescriptionTextView;
this.buttonsLinearLayout = buttonsLinearLayout;
}
@Override
public void onClick(View v) {
if (freeVersionDescriptionTextView.getVisibility() == View.VISIBLE) {
freeVersionDescriptionTextView.setVisibility(View.GONE);
buttonsLinearLayout.setVisibility(View.GONE);
} else {
freeVersionDescriptionTextView.setVisibility(View.VISIBLE);
buttonsLinearLayout.setVisibility(View.VISIBLE);
}
}
}
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_files);
String numberOfTasks = String.format(format, activeTasks);
leftTextView.setText(numberOfTasks);
rightTextView.setText(progressPercentage + "%");
}
@Override
public void onFinished() {
downloadProgressLayout.setVisibility(View.GONE);
}
}
}

View file

@ -1,239 +0,0 @@
package net.osmand.plus.download.newimplementation;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import net.osmand.Collator;
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.HasName;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
public class IndexItemCategoryWithSubcat implements Comparable<IndexItemCategoryWithSubcat>,
HasName, Parcelable {
private static final Log LOG = PlatformUtil.getLog(IndexItemCategoryWithSubcat.class);
public final List<IndexItem> items;
public final List<IndexItemCategoryWithSubcat> subcats;
public final CategoryStaticData categoryStaticData;
public final TreeSet<Integer> types;
public IndexItemCategoryWithSubcat(CategoryStaticData categoryStaticData) {
this.categoryStaticData = categoryStaticData;
items = new ArrayList<>();
subcats = new ArrayList<>();
types = new TreeSet<>();
}
@Override
public int compareTo(@NonNull IndexItemCategoryWithSubcat another) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if (this == another) return EQUAL;
if (this.categoryStaticData.getOrder() < another.categoryStaticData.getOrder())
return BEFORE;
if (this.categoryStaticData.getOrder() > another.categoryStaticData.getOrder())
return AFTER;
return EQUAL;
}
public static List<IndexItemCategoryWithSubcat> categorizeIndexItems(final OsmandApplication ctx,
Collection<IndexItem> indexItems) {
boolean skipWiki = Version.isFreeVersion(ctx);
final Map<String, IndexItemCategoryWithSubcat> cats = new TreeMap<>();
ArrayList<IndexItemCategoryWithSubcat> mainList = new ArrayList<>();
for (IndexItem i : indexItems) {
String lowerCase = i.getFileName().toLowerCase();
CategoryStaticData categoryStaticData;
if (lowerCase.endsWith(".voice.zip")) {
categoryStaticData = CategoryStaticData.NAME_VOICE;
} else if (lowerCase.contains(".ttsvoice.zip")) {
categoryStaticData = CategoryStaticData.TTS_VOICE;
} else if (lowerCase.contains("_wiki_")) {
if (skipWiki) {
continue;
}
categoryStaticData = CategoryStaticData.WIKI;
} else if (lowerCase.startsWith("us") ||
(lowerCase.contains("united states") && lowerCase.startsWith("north-america"))) {
categoryStaticData = CategoryStaticData.US;
} else if (lowerCase.startsWith("canada")) {
categoryStaticData = CategoryStaticData.CANADA;
} else if (lowerCase.contains("openmaps")) {
categoryStaticData = CategoryStaticData.OPENMAPS;
} else if (lowerCase.contains("northamerica") || lowerCase.contains("north-america")) {
categoryStaticData = CategoryStaticData.NORTH_AMERICA;
} else if (lowerCase.contains("centralamerica") || lowerCase.contains("central-america")
|| lowerCase.contains("caribbean")) {
categoryStaticData = CategoryStaticData.CENTRAL_AMERICA;
} else if (lowerCase.contains("southamerica") || lowerCase.contains("south-america")) {
categoryStaticData = CategoryStaticData.SOUTH_AMERICA;
} else if (lowerCase.contains("germany")) {
categoryStaticData = CategoryStaticData.GERMANY;
} else if (lowerCase.startsWith("france_")) {
categoryStaticData = CategoryStaticData.FRANCE;
} else if (lowerCase.startsWith("italy_")) {
categoryStaticData = CategoryStaticData.ITALY;
} else if (lowerCase.startsWith("gb_") || lowerCase.startsWith("british")) {
categoryStaticData = CategoryStaticData.GB;
} else if (lowerCase.contains("netherlands")) {
categoryStaticData = CategoryStaticData.NETHERLANDS;
} else if (lowerCase.contains("russia")) {
categoryStaticData = CategoryStaticData.RUSSIA;
} else if (lowerCase.contains("europe")) {
categoryStaticData = CategoryStaticData.EUROPE;
} else if (lowerCase.contains("africa") && !lowerCase.contains("_wiki_")) {
categoryStaticData = CategoryStaticData.AFRICA;
} else if (lowerCase.contains("_asia") || lowerCase.startsWith("asia")) {
categoryStaticData = CategoryStaticData.ASIA;
} else if (lowerCase.contains("oceania") || lowerCase.contains("australia")) {
categoryStaticData = CategoryStaticData.OCEANIA;
} else if (lowerCase.contains("tour")) {
categoryStaticData = CategoryStaticData.TOURS;
} else {
categoryStaticData = CategoryStaticData.WORLD_WIDE_AND_TOPIC;
}
String name = ctx.getString(categoryStaticData.getNameId());
categoryStaticData.setName(name);
IndexItemCategoryWithSubcat category = cats.get(name);
if (category == null) {
category = new IndexItemCategoryWithSubcat(categoryStaticData);
cats.put(name, category);
if (!categoryStaticData.hasParent()) {
mainList.add(category);
} else {
final CategoryStaticData parent = categoryStaticData.getParent();
if (cats.get(parent.getName()) == null) {
cats.put(parent.getName(), new IndexItemCategoryWithSubcat(parent));
} else {
cats.get(parent.getName()).subcats.add(category);
}
}
}
if (i.getType() == DownloadActivityType.VOICE_FILE) {
category.items.add(i);
} else {
IndexItemCategoryWithSubcat region;
region = cats.get(i.getBasename());
// TODO remove
final String visibleName = i.getVisibleName(ctx, ctx.getRegions());
i.setName(visibleName);
if (region == null) {
final CategoryStaticData regionStaticData = new CategoryStaticData(0, 0);
regionStaticData.setName(visibleName);
region = new IndexItemCategoryWithSubcat(regionStaticData);
cats.put(i.getBasename(), region);
category.subcats.add(region);
}
region.items.add(i);
if (i.getType() == DownloadActivityType.NORMAL_FILE
|| i.getType() == DownloadActivityType.WIKIPEDIA_FILE
|| i.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| i.getType() == DownloadActivityType.HILLSHADE_FILE) {
category.types.add(i.getType().getStringResource());
region.types.add(i.getType().getStringResource());
}
}
}
final Collator collator = OsmAndCollator.primaryCollator();
for (IndexItemCategoryWithSubcat category : mainList) {
final OsmandRegions osmandRegions = ctx.getResourceManager().getOsmandRegions();
sortIndexItemCategoryWithSybcat(category, ctx, osmandRegions, collator);
}
Collections.sort(mainList);
return mainList;
}
private static void sortIndexItemCategoryWithSybcat(final IndexItemCategoryWithSubcat category,
final OsmandApplication context,
final OsmandRegions osmandRegions,
final Collator collator) {
if (category.subcats.size() > 0) {
Collections.sort(category.subcats, new Comparator<IndexItemCategoryWithSubcat>() {
@Override
public int compare(IndexItemCategoryWithSubcat lhs, IndexItemCategoryWithSubcat rhs) {
return collator.compare(lhs.getName(), rhs.getName());
}
});
for (IndexItemCategoryWithSubcat subcat : category.subcats) {
sortIndexItemCategoryWithSybcat(subcat, context, osmandRegions, collator);
}
}
Collections.sort(category.items, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(context, osmandRegions),
rhs.getVisibleName(context, osmandRegions));
}
});
}
@Override
public String getName() {
return categoryStaticData.getName();
}
@Override
public String toString() {
return "IndexItemCategoryWithSubcat{" +
"items=" + items +
", subcats=" + subcats +
", categoryStaticData=" + categoryStaticData +
'}';
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(this.items);
dest.writeList(this.subcats);
dest.writeParcelable(this.categoryStaticData, 0);
dest.writeSerializable(this.types);
}
protected IndexItemCategoryWithSubcat(Parcel in) {
this.items = new ArrayList<IndexItem>();
in.readList(this.items, List.class.getClassLoader());
this.subcats = new ArrayList<IndexItemCategoryWithSubcat>();
in.readList(this.subcats, List.class.getClassLoader());
this.categoryStaticData = in.readParcelable(CategoryStaticData.class.getClassLoader());
this.types = (TreeSet<Integer>) in.readSerializable();
}
public static final Parcelable.Creator<IndexItemCategoryWithSubcat> CREATOR = new Parcelable.Creator<IndexItemCategoryWithSubcat>() {
public IndexItemCategoryWithSubcat createFromParcel(Parcel source) {
return new IndexItemCategoryWithSubcat(source);
}
public IndexItemCategoryWithSubcat[] newArray(int size) {
return new IndexItemCategoryWithSubcat[size];
}
};
}