Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-09-23 15:22:14 +02:00
commit 9c28eace80
23 changed files with 1114 additions and 314 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item android:id="@android:id/background">-->
<!--</item>-->
<item android:id="@android:id/secondaryProgress">
<clip>
<nine-patch android:src="@drawable/bg_download_bar_light_orange"/>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<nine-patch android:src="@drawable/bg_download_bar_light_grey"/>
</clip>
</item>
</layer-list>

View file

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/free_version_title"/>
<TextView
android:id="@+id/downloadsLeftTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/downloads_left_template"/>
</LinearLayout>
<TextView
android:id="@+id/freeVersionDescriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
tools:text="@string/free_version_message"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_margin="4dp">
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:max="10"
android:progress="5"
android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable"
android:secondaryProgress="10"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GET FULL VERSION"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="LATER"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="?attr/bg_card"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/device_memory"/>
<TextView
android:id="@+id/memory_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:text="@string/free"/>
</LinearLayout>
<ProgressBar
android:id="@+id/memory_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:progressDrawable="?attr/size_progress_bar"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="World regions"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:groupIndicator="@android:color/transparent"/>
</LinearLayout>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -1,22 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height" >
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:focusable="false"
android:focusableInTouchMode="false">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="center_vertical"
android:drawablePadding="24dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:drawableLeft="@drawable/ic_action_search_dark"
tools:text="@string/layer_poi" />
tools:text="@string/layer_poi"/>
</LinearLayout>

View file

@ -2270,4 +2270,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="count_of_lines">Count of lines</string>
<string name="are_you_sure">Are you sure?</string>
<string name="unsaved_changes_will_be_lost">Any unsaved changes will be lost. Continue?</string>
<string name="downloads_left_template">%1$s downloads left</string>
</resources>

View file

@ -1,19 +1,5 @@
package net.osmand.plus.download;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
@ -23,6 +9,22 @@ import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Denis
* on 25.11.2014.
@ -31,8 +33,8 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
protected OsmandSettings settings;
public static DownloadIndexesThread downloadListIndexThread;
protected List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
protected List<IndexItem> downloadQueue = new ArrayList<IndexItem>();
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
protected List<IndexItem> downloadQueue = new ArrayList<>();
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
@ -63,7 +65,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
super.onResume();
downloadListIndexThread.setUiActivity(this);
}
@Override
protected void onPause() {
super.onPause();
@ -85,7 +87,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
if (downloadListIndexThread == null) {
return new LinkedHashMap<IndexItem, List<DownloadEntry>>();
return new LinkedHashMap<>();
}
return downloadListIndexThread.getEntriesToDownload();
}
@ -110,6 +112,11 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
public void onCategorizationFinished(List<IndexItem> filtered,
List<IndexItemCategoryWithSubcat> cats) {
}
public boolean startDownload(IndexItem item) {
if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
downloadQueue.add(item);
@ -267,7 +274,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
} else {
msg.setNeutralButton(R.string.shared_string_ok, null);
}
msg.show();
}
}

View file

@ -1,13 +1,25 @@
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 android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
@ -20,29 +32,19 @@ 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.newimplementation.IndexItemCategoryWithSubcat;
import net.osmand.plus.download.newimplementation.NewLocalIndexesFragment;
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.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
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;
/**
@ -85,42 +87,45 @@ public class DownloadActivity extends BaseDownloadActivity {
int currentTab = 0;
String tab = getIntent() == null || getIntent().getExtras() == null ? null : getIntent().getExtras().getString(TAB_TO_OPEN);
if (tab != null) {
if (tab.equals(DOWNLOAD_TAB)){
if (tab.equals(DOWNLOAD_TAB)) {
currentTab = 1;
} else if (tab.equals(UPDATES_TAB)){
} else if (tab.equals(UPDATES_TAB)) {
currentTab = 2;
}
}
if (singleTab) {
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setVisibility(View.GONE);
Fragment f = currentTab == 0 ? new LocalIndexesFragment() :
(currentTab == 1? new DownloadIndexFragment() : new UpdatesIndexFragment());
String tag = currentTab == 0 ? LOCAL_TAB :
(currentTab == 1 ? DOWNLOAD_TAB : UPDATES_TAB);
findViewById(R.id.layout).setVisibility(View.VISIBLE);
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
if (manager.findFragmentByTag(tag) == null){
getSupportFragmentManager().beginTransaction().add(R.id.layout, f, tag).commit();
}
} else {
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
// if (singleTab) {
// ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
// viewPager.setVisibility(View.GONE);
// Fragment f = currentTab == 0 ? new LocalIndexesFragment() :
// (currentTab == 1? new DownloadIndexFragment() : new UpdatesIndexFragment());
// String tag = currentTab == 0 ? LOCAL_TAB :
// (currentTab == 1 ? DOWNLOAD_TAB : UPDATES_TAB);
// findViewById(R.id.layout).setVisibility(View.VISIBLE);
// android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
// if (manager.findFragmentByTag(tag) == null){
// getSupportFragmentManager().beginTransaction().add(R.id.layout, f, tag).commit();
// }
// } else {
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
getString(R.string.download_tab_local), LocalIndexesFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
getString(R.string.download_tab_downloads), DownloadIndexFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_updates,
getString(R.string.download_tab_updates), UpdatesIndexFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
getString(R.string.download_tab_local), LocalIndexesFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads,
getString(R.string.download_tab_downloads), DownloadIndexFragment.class));
mTabs.add(new TabActivity.TabItem(R.string.download_tab_updates,
getString(R.string.download_tab_updates), UpdatesIndexFragment.class));
viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs));
mSlidingTabLayout.setViewPager(viewPager);
mTabs.add(new TabActivity.TabItem(R.string.download_tab_local,
getString(R.string.download_tab_local), NewLocalIndexesFragment.class));
viewPager.setCurrentItem(currentTab);
}
viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs));
mSlidingTabLayout.setViewPager(viewPager);
settings = ((OsmandApplication)getApplication()).getSettings();
viewPager.setCurrentItem(currentTab);
// }
settings = ((OsmandApplication) getApplication()).getSettings();
indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
determinateProgressBar = (ProgressBar) findViewById(R.id.memory_progress);
@ -128,7 +133,7 @@ public class DownloadActivity extends BaseDownloadActivity {
progressMessage = (TextView) findViewById(R.id.ProgressMessage);
progressPercent = (TextView) findViewById(R.id.ProgressPercent);
cancel = (ImageView) findViewById(R.id.Cancel);
cancel.setImageDrawable(getMyApplication().getIconsCache() .getContentIcon(R.drawable.ic_action_remove_dark));
cancel.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark));
cancel.setOnClickListener(new View.OnClickListener() {
@Override
@ -137,7 +142,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
});
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -145,28 +150,28 @@ public class DownloadActivity extends BaseDownloadActivity {
}
});
findViewById(R.id.WikiButton).setOnClickListener(new View.OnClickListener(){
findViewById(R.id.WikiButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
downloadWikiFiles();
}
});
findViewById(R.id.CancelAll).setOnClickListener(new View.OnClickListener(){
findViewById(R.id.CancelAll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getEntriesToDownload().clear();
updateDownloadButton();
for(WeakReference<Fragment> ref : fragList) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof OsmAndListFragment) {
if(!f.isDetached() && ((OsmAndListFragment) f).getListAdapter() instanceof ArrayAdapter) {
if (f instanceof OsmAndListFragment) {
if (!f.isDetached() && ((OsmAndListFragment) f).getListAdapter() instanceof ArrayAdapter) {
((ArrayAdapter) ((OsmAndListFragment) f).getListAdapter()).notifyDataSetChanged();
}
} else if (!f.isDetached() && f instanceof OsmandExpandableListFragment &&
((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter){
} else if (!f.isDetached() && f instanceof OsmandExpandableListFragment &&
((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter) {
((BaseExpandableListAdapter) ((OsmandExpandableListFragment) f).getAdapter()).notifyDataSetChanged();
}
}
@ -193,8 +198,7 @@ public class DownloadActivity extends BaseDownloadActivity {
changeType(downloadTypes.get(0));
}
public Map<String, String> getIndexActivatedFileNames() {
return downloadListIndexThread != null ? downloadListIndexThread.getIndexActivatedFileNames() : null;
}
@ -222,11 +226,11 @@ public class DownloadActivity extends BaseDownloadActivity {
return false;
}
public void setLocalIndexInfos(List<LocalIndexInfo> list){
public void setLocalIndexInfos(List<LocalIndexInfo> list) {
this.localIndexInfos = list;
}
public List<LocalIndexInfo> getLocalIndexInfos(){
public List<LocalIndexInfo> getLocalIndexInfos() {
return localIndexInfos;
}
@ -248,12 +252,12 @@ public class DownloadActivity extends BaseDownloadActivity {
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
//needed when rotation is performed and progress can be null
if (progressView == null){
if (progressView == null) {
return;
}
if(updateOnlyProgress) {
if(!basicProgressAsyncTask.isIndeterminate()) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
if (updateOnlyProgress) {
if (!basicProgressAsyncTask.isIndeterminate()) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
} else {
@ -278,11 +282,11 @@ public class DownloadActivity extends BaseDownloadActivity {
}
@Override
public void updateDownloadList(List<IndexItem> list){
for(WeakReference<Fragment> ref : fragList) {
public void updateDownloadList(List<IndexItem> list) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof UpdatesIndexFragment) {
if(!f.isDetached()) {
if (f instanceof UpdatesIndexFragment) {
if (!f.isDetached()) {
((UpdatesIndexFragment) f).updateItemsList(list);
}
}
@ -290,39 +294,52 @@ public class DownloadActivity extends BaseDownloadActivity {
}
@Override
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats){
for(WeakReference<Fragment> ref : fragList) {
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) {
if (f instanceof DownloadIndexFragment) {
if (!f.isDetached()) {
((DownloadIndexFragment) f).categorizationFinished(filtered, cats);
}
}
}
}
public void downloadListUpdated(){
for(WeakReference<Fragment> ref : fragList) {
@Override
public void onCategorizationFinished(List<IndexItem> filtered,
List<IndexItemCategoryWithSubcat> cats) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) {
((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter()).notifyDataSetInvalidated();
if (f instanceof NewLocalIndexesFragment) {
if (!f.isDetached()) {
((NewLocalIndexesFragment) f).onCategorizationFinished(filtered, cats);
}
}
}
}
public void downloadListUpdated() {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if (f instanceof DownloadIndexFragment) {
if (!f.isDetached()) {
((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter()).notifyDataSetInvalidated();
}
}
}
}
@Override
public void downloadedIndexes(){
for(WeakReference<Fragment> ref : fragList) {
public void downloadedIndexes() {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof LocalIndexesFragment){
if(!f.isDetached()){
if (f instanceof LocalIndexesFragment) {
if (!f.isDetached()) {
((LocalIndexesFragment) f).reloadData();
}
} else if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) {
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter());
} else if (f instanceof DownloadIndexFragment) {
if (!f.isDetached()) {
DownloadIndexAdapter adapter = ((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter());
if (adapter != null) {
adapter.setLoadedFiles(getIndexActivatedFileNames(), getIndexFileNames());
@ -340,15 +357,15 @@ public class DownloadActivity extends BaseDownloadActivity {
Builder bld = new AlertDialog.Builder(this);
final List<IndexItem> wi = getWikipediaItems();
long size = 0;
for(IndexItem i : wi) {
for (IndexItem i : wi) {
size += i.getSize();
}
bld.setMessage(getString(R.string.download_wikipedia_files, (size >> 20)));
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for(IndexItem i : wi) {
for (IndexItem i : wi) {
addToDownload(i);
}
updateDownloadButton();
@ -356,33 +373,33 @@ public class DownloadActivity extends BaseDownloadActivity {
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
if(wi.size() > 0) {
if (wi.size() > 0) {
bld.show();
}
}
}
protected void checkOldWikiFiles() {
Map<String, String> fileNames = getMyApplication().getResourceManager().getIndexFileNames();
final Set<String> wiki = new HashSet<String>();
for(String s : fileNames.keySet()) {
if(s.contains("_wiki")) {
for (String s : fileNames.keySet()) {
if (s.contains("_wiki")) {
wiki.add(s);
}
}
if(wiki.size() > 0) {
if (wiki.size() > 0) {
Builder bld = new AlertDialog.Builder(this);
bld.setMessage(R.string.archive_wikipedia_data);
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for(String w : wiki) {
for (String w : wiki) {
File fl = getMyApplication().getAppPath(w);
File nf = new File(fl.getParentFile(), IndexConstants.BACKUP_INDEX_DIR + "/"+fl.getName());
File nf = new File(fl.getParentFile(), IndexConstants.BACKUP_INDEX_DIR + "/" + fl.getName());
boolean res = fl.renameTo(nf);
if(!res) {
if (!res) {
System.err.println("Renaming from " + fl.getAbsolutePath() + " to " + nf.getAbsolutePath() + " failed");
}
}
@ -428,8 +445,8 @@ public class DownloadActivity extends BaseDownloadActivity {
List<IndexItem> wikipediaItems = getWikipediaItems();
findViewById(R.id.WikiButton).setVisibility(wikipediaItems.size() == 0 ? View.GONE : View.VISIBLE);
}
for(WeakReference<Fragment> ref : fragList) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if (!f.isDetached()) {
if (f instanceof OsmandExpandableListFragment) {
@ -438,9 +455,9 @@ public class DownloadActivity extends BaseDownloadActivity {
if (ad instanceof OsmandBaseExpandableListAdapter) {
((OsmandBaseExpandableListAdapter) ad).notifyDataSetChanged();
}
} else if(f instanceof ListFragment) {
} else if (f instanceof ListFragment) {
ListAdapter la = ((ListFragment) f).getListAdapter();
if(la instanceof BaseAdapter) {
if (la instanceof BaseAdapter) {
((BaseAdapter) la).notifyDataSetChanged();
}
}
@ -452,23 +469,22 @@ public class DownloadActivity extends BaseDownloadActivity {
}
private List<IndexItem> getWikipediaItems() {
Set<String> wikipediaItems = new HashSet<String>();
Map<String, String> indexed = getMyApplication().getResourceManager().getIndexFileNames();
for(IndexItem i : getEntriesToDownload().keySet()) {
if(i.getType() == DownloadActivityType.NORMAL_FILE) {
for (IndexItem i : getEntriesToDownload().keySet()) {
if (i.getType() == DownloadActivityType.NORMAL_FILE) {
boolean fit = true;
fit = fit && i.getFileName().contains("obf");
fit = fit && !i.getFileName().contains("world");
String fname = i.getBasename();
if(fit && !indexed.containsKey(fname+".wiki.obf") ) {
if (fit && !indexed.containsKey(fname + ".wiki.obf")) {
wikipediaItems.add(fname);
}
}
}
for(IndexItem i : getEntriesToDownload().keySet()) {
if(i.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
for (IndexItem i : getEntriesToDownload().keySet()) {
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
wikipediaItems.remove(i.getBasename());
}
}
@ -476,8 +492,8 @@ public class DownloadActivity extends BaseDownloadActivity {
IndexFileList list = downloadListIndexThread.getIndexFiles();
if (list != null) {
List<IndexItem> indexFiles = list.getIndexFiles();
for(IndexItem i : indexFiles) {
if(i.getType() == DownloadActivityType.WIKIPEDIA_FILE &&
for (IndexItem i : indexFiles) {
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE &&
wikipediaItems.contains(i.getBasename())) {
res.add(i);
}
@ -485,8 +501,8 @@ public class DownloadActivity extends BaseDownloadActivity {
}
return res;
}
public List<DownloadActivityType> getDownloadTypes() {
return downloadTypes;
}
@ -494,16 +510,16 @@ public class DownloadActivity extends BaseDownloadActivity {
public List<DownloadActivityType> createDownloadTypes() {
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();
items.add(DownloadActivityType.NORMAL_FILE);
if(!Version.isFreeVersion(getMyApplication())) {
if (!Version.isFreeVersion(getMyApplication())) {
items.add(DownloadActivityType.WIKIPEDIA_FILE);
}
items.add(DownloadActivityType.VOICE_FILE);
items.add(DownloadActivityType.ROADS_FILE);
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
items.add(DownloadActivityType.HILLSHADE_FILE);
items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
}
getMyApplication().getAppCustomization().getDownloadTypes(items);
return items;
}
@ -513,7 +529,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
public Map<String,String> getIndexFileNames() {
public Map<String, String> getIndexFileNames() {
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
}
@ -526,19 +542,19 @@ public class DownloadActivity extends BaseDownloadActivity {
if ((i.getFileName().equals(map + ".obf.zip") || i.getFileName().equals(map + "_" + IndexConstants.BINARY_MAP_VERSION + ".obf.zip"))
&& i.getType() == DownloadActivityType.NORMAL_FILE) {
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
for(DownloadEntry d : de ) {
for (DownloadEntry d : de) {
count++;
sz += d.sizeMB;
}
if(s.length() > 0) {
s +=", ";
if (s.length() > 0) {
s += ", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getEntriesToDownload().put(i, de);
}
}
}
if(count > 0){
if (count > 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@ -567,9 +583,4 @@ public class DownloadActivity extends BaseDownloadActivity {
}
}

View file

@ -1,6 +1,37 @@
package net.osmand.plus.download;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Build;
import android.os.StatFs;
import android.view.View;
import android.widget.Toast;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
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.newimplementation.IndexItemCategoryWithSubcat;
import net.osmand.plus.helpers.DatabaseHelper;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -16,36 +47,6 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
import net.osmand.plus.helpers.DatabaseHelper;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Build;
import android.os.StatFs;
import android.view.View;
import android.widget.Toast;
@SuppressLint("NewApi")
public class DownloadIndexesThread {
private BaseDownloadActivity uiActivity = null;
@ -56,7 +57,7 @@ public class DownloadIndexesThread {
private OsmandApplication app;
private final static Log log = PlatformUtil.getLog(DownloadIndexesThread.class);
private DownloadFileHelper downloadFileHelper;
private List<BasicProgressAsyncTask<?, ?, ?> > currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>());
private List<BasicProgressAsyncTask<?, ?, ?>> currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>());
private Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>();
private java.text.DateFormat dateFormat;
@ -72,22 +73,22 @@ public class DownloadIndexesThread {
dbHelper = new DatabaseHelper(app);
}
public DatabaseHelper getDbHelper(){
public DatabaseHelper getDbHelper() {
return dbHelper;
}
public void clear() {
indexFiles = null;
}
public void setUiActivity(BaseDownloadActivity uiActivity) {
this.uiActivity = uiActivity;
}
public List<DownloadEntry> flattenDownloadEntries() {
List<DownloadEntry> res = new ArrayList<DownloadEntry>();
for(List<DownloadEntry> ens : getEntriesToDownload().values()) {
if(ens != null) {
for (List<DownloadEntry> ens : getEntriesToDownload().values()) {
if (ens != null) {
res.addAll(ens);
}
}
@ -98,19 +99,19 @@ public class DownloadIndexesThread {
return indexFiles != null ? indexFiles.getIndexFiles() : null;
}
public IndexFileList getIndexFiles() {
return indexFiles;
}
public Map<String, String> getIndexFileNames(){
public Map<String, String> getIndexFileNames() {
return indexFileNames;
}
public Map<String, String> getIndexActivatedFileNames(){
public Map<String, String> getIndexActivatedFileNames() {
return indexActivatedFileNames;
}
public void updateLoadedFiles() {
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
@ -126,7 +127,7 @@ public class DownloadIndexesThread {
this.indexActivatedFileNames = indexActivatedFileNames;
//updateFilesToDownload();
}
public Map<String, String> getDownloadedIndexFileNames() {
return indexFileNames;
}
@ -148,11 +149,11 @@ public class DownloadIndexesThread {
super(ctx);
downloads = app.getSettings().NUMBER_OF_FREE_DOWNLOADS;
}
@Override
public void setInterrupted(boolean interrupted) {
super.setInterrupted(interrupted);
if(interrupted) {
if (interrupted) {
downloadFileHelper.setInterruptDownloading(true);
}
}
@ -164,10 +165,10 @@ public class DownloadIndexesThread {
if (uiActivity != null) {
uiActivity.downloadListUpdated();
uiActivity.updateDownloadButton();
DownloadEntry item = (DownloadEntry)o;
DownloadEntry item = (DownloadEntry) o;
String name = item.item.getBasename();
long count = dbHelper.getCount(name, DatabaseHelper.DOWNLOAD_ENTRY) + 1;
DatabaseHelper.HistoryDownloadEntry entry = new DatabaseHelper.HistoryDownloadEntry(name,count);
DatabaseHelper.HistoryDownloadEntry entry = new DatabaseHelper.HistoryDownloadEntry(name, count);
if (count == 1) {
dbHelper.add(entry, DatabaseHelper.DOWNLOAD_ENTRY);
} else {
@ -179,14 +180,14 @@ public class DownloadIndexesThread {
if (uiActivity != null) {
uiActivity.downloadListUpdated();
uiActivity.updateDownloadButton();
IndexItem item = (IndexItem)o;
IndexItem item = (IndexItem) o;
long count = dbHelper.getCount(item.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) + 1;
dbHelper.add(new DatabaseHelper.HistoryDownloadEntry(item.getBasename(), count), DatabaseHelper.DOWNLOAD_ENTRY);
}
} else if (o instanceof String) {
String message = (String) o;
if(!message.equals("I/O error occurred : Interrupted")){
if (!message.equals("I/O error occurred : Interrupted")) {
AccessibleToast.makeText(ctx, message, Toast.LENGTH_LONG).show();
}
}
@ -196,7 +197,7 @@ public class DownloadIndexesThread {
@Override
protected void onPreExecute() {
currentRunningTask.add( this);
currentRunningTask.add(this);
super.onPreExecute();
if (uiActivity != null) {
downloadFileHelper.setInterruptDownloading(false);
@ -222,13 +223,12 @@ public class DownloadIndexesThread {
uiActivity.downloadedIndexes();
}
currentRunningTask.remove(this);
if(uiActivity != null) {
if (uiActivity != null) {
uiActivity.updateProgress(false);
}
updateFilesToUpdate();
}
@Override
protected String doInBackground(IndexItem... filesToDownload) {
@ -237,39 +237,40 @@ public class DownloadIndexesThread {
boolean forceWifi = downloadFileHelper.isWifiConnected();
currentDownloads = new HashSet<DownloadEntry>();
String breakDownloadMessage = null;
downloadCycle : while(!entriesToDownload.isEmpty() ) {
downloadCycle:
while (!entriesToDownload.isEmpty()) {
Iterator<Entry<IndexItem, List<DownloadEntry>>> it = entriesToDownload.entrySet().iterator();
IndexItem file = null;
List<DownloadEntry> list = null;
while(it.hasNext()) {
while (it.hasNext()) {
Entry<IndexItem, List<DownloadEntry>> n = it.next();
if(!currentDownloads.containsAll(n.getValue())) {
if (!currentDownloads.containsAll(n.getValue())) {
file = n.getKey();
list = n.getValue();
break;
}
}
if(file == null) {
if (file == null) {
break downloadCycle;
}
if (list != null) {
boolean success = false;
for (DownloadEntry entry : list) {
if(currentDownloads.contains(entry)) {
if (currentDownloads.contains(entry)) {
continue;
}
currentDownloads.add(entry);
double asz = getAvailableSpace();
// validate interrupted
if(downloadFileHelper.isInterruptDownloading()) {
if (downloadFileHelper.isInterruptDownloading()) {
break downloadCycle;
}
// validate enough space
if (asz != -1 && entry.sizeMB > asz) {
breakDownloadMessage = app.getString(R.string.download_files_not_enough_space, entry.sizeMB, asz);
breakDownloadMessage = app.getString(R.string.download_files_not_enough_space, entry.sizeMB, asz);
break downloadCycle;
}
}
if (exceedsFreelimit(entry)) {
breakDownloadMessage = app.getString(R.string.free_version_message, DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
+ "");
@ -288,15 +289,15 @@ public class DownloadIndexesThread {
publishProgress(entry);
}
}
if(success) {
if (success) {
entriesToDownload.remove(file);
}
}
}
String warn = reindexFiles(filesToReindex);
if(breakDownloadMessage != null) {
if(warn != null) {
if (breakDownloadMessage != null) {
if (warn != null) {
warn = breakDownloadMessage + "\n" + warn;
} else {
warn = breakDownloadMessage;
@ -331,10 +332,10 @@ public class DownloadIndexesThread {
warnings = manager.indexingMaps(this);
}
List<String> wns = manager.indexAdditionalMaps(this);
if(wns != null) {
if (wns != null) {
warnings.addAll(wns);
}
if (!warnings.isEmpty()) {
return warnings.get(0);
}
@ -366,7 +367,7 @@ public class DownloadIndexesThread {
if (ctx != null) {
ResourceManager.copyAssets(ctx.getAssets(), de.assetName, de.targetFile);
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
if(!changedDate) {
if (!changedDate) {
log.error("Set last timestamp is not supported");
}
res = true;
@ -382,28 +383,28 @@ public class DownloadIndexesThread {
@Override
protected void updateProgress(boolean updateOnlyProgress) {
if(uiActivity != null) {
if (uiActivity != null) {
uiActivity.updateProgress(updateOnlyProgress);
}
}
}
private boolean checkRunning() {
if(getCurrentRunningTask() != null) {
if (getCurrentRunningTask() != null) {
AccessibleToast.makeText(app, R.string.wait_current_task_finished, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
public void runReloadIndexFiles() {
checkRunning();
final BasicProgressAsyncTask<Void, Void, IndexFileList> inst = new BasicProgressAsyncTask<Void, Void, IndexFileList>(ctx) {
@Override
protected IndexFileList doInBackground(Void... params) {
return DownloadOsmandIndexesHelper.getIndexesList(ctx);
};
public void runReloadIndexFiles() {
runReloadIndexFiles(false);
}
public void runReloadIndexFiles(final boolean withSubcats) {
checkRunning();
final BasicProgressAsyncTask<Void, Void, IndexFileList> inst
= new BasicProgressAsyncTask<Void, Void, IndexFileList>(ctx) {
@Override
protected void onPreExecute() {
@ -412,13 +413,18 @@ public class DownloadIndexesThread {
this.message = ctx.getString(R.string.downloading_list_indexes);
}
@Override
protected IndexFileList doInBackground(Void... params) {
return DownloadOsmandIndexesHelper.getIndexesList(ctx);
}
protected void onPostExecute(IndexFileList result) {
indexFiles = result;
if (indexFiles != null && uiActivity != null) {
prepareFilesToUpdate();
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap();
if (basemap != null ) {
if (basemap != null) {
String dt = uiActivity.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate(dateFormat))) {
List<DownloadEntry> downloadEntry = basemap
@ -427,8 +433,8 @@ public class DownloadIndexesThread {
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show();
if (uiActivity instanceof DownloadActivity){
((DownloadActivity)uiActivity).updateDownloadButton();
if (uiActivity instanceof DownloadActivity) {
((DownloadActivity) uiActivity).updateDownloadButton();
}
}
}
@ -441,7 +447,7 @@ public class DownloadIndexesThread {
currentRunningTask.remove(this);
if (uiActivity != null) {
uiActivity.updateProgress(false);
runCategorization(uiActivity.getDownloadType());
runCategorization(uiActivity.getDownloadType(), withSubcats);
}
}
@ -474,24 +480,26 @@ public class DownloadIndexesThread {
uiActivity.updateProgress(updateOnlyProgress);
}
};
}
;
};
execute(inst, new Void[0]);
execute(inst);
}
public void runDownloadFiles(){
if(checkRunning()) {
public void runDownloadFiles() {
if (checkRunning()) {
return;
}
DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(ctx);
execute(task, new IndexItem[0]);
execute(task);
}
private <P>void execute(BasicProgressAsyncTask<P, ?, ?> task, P... indexItems) {
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, indexItems);
private <P> void execute(BasicProgressAsyncTask<P, ?, ?> task, P... indexItems) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, indexItems);
} else {
task.execute(indexItems);
}
@ -502,26 +510,40 @@ public class DownloadIndexesThread {
}
public void runCategorization(final DownloadActivityType type) {
final BasicProgressAsyncTask<Void, Void, List<IndexItem>> inst = new BasicProgressAsyncTask<Void, Void, List<IndexItem>>(ctx) {
runCategorization(type, false);
}
public void runCategorization(final DownloadActivityType type, final boolean withSubcats) {
final BasicProgressAsyncTask<Void, Void, List<IndexItem>> inst
= new BasicProgressAsyncTask<Void, Void, List<IndexItem>>(ctx) {
private List<IndexItemCategory> cats;
private List<IndexItemCategoryWithSubcat> catsWithSubcats;
@Override
protected void onPreExecute() {
super.onPreExecute();
currentRunningTask.add(this);
this.message = ctx.getString(R.string.downloading_list_indexes);
if(uiActivity != null) {
if (uiActivity != null) {
uiActivity.updateProgress(false);
}
}
@Override
protected List<IndexItem> doInBackground(Void... params) {
final List<IndexItem> filtered = getFilteredByType();
cats = IndexItemCategory.categorizeIndexItems(app, filtered);
if (withSubcats) {
catsWithSubcats =
IndexItemCategoryWithSubcat.categorizeIndexItems(app, filtered);
} else {
cats = IndexItemCategory.categorizeIndexItems(app, filtered);
}
updateLoadedFiles();
return filtered;
};
}
;
public List<IndexItem> getFilteredByType() {
final List<IndexItem> filtered = new ArrayList<IndexItem>();
List<IndexItem> cachedIndexFiles = getCachedIndexFiles();
@ -534,28 +556,32 @@ public class DownloadIndexesThread {
}
return filtered;
}
@Override
protected void onPostExecute(List<IndexItem> filtered) {
prepareFilesToUpdate();
currentRunningTask.remove(this);
if(uiActivity != null) {
uiActivity.categorizationFinished(filtered, cats);
if (uiActivity != null) {
if (withSubcats) {
uiActivity.onCategorizationFinished(filtered, catsWithSubcats);
} else {
uiActivity.categorizationFinished(filtered, cats);
}
uiActivity.updateProgress(false);
}
}
@Override
protected void updateProgress(boolean updateOnlyProgress) {
if(uiActivity != null) {
if (uiActivity != null) {
uiActivity.updateProgress(updateOnlyProgress);
}
};
}
};
execute(inst, new Void[0]);
execute(inst);
}
private void prepareFilesToUpdate() {
@ -565,11 +591,11 @@ public class DownloadIndexesThread {
for (IndexItem item : filtered) {
boolean outdated = checkIfItemOutdated(item);
//include only activated files here
if(outdated && indexActivatedFileNames.containsKey(item.getTargetFileName())) {
if (outdated && indexActivatedFileNames.containsKey(item.getTargetFileName())) {
itemsToUpdate.add(item);
}
}
if (uiActivity != null){
if (uiActivity != null) {
uiActivity.updateDownloadList(itemsToUpdate);
}
}
@ -588,17 +614,17 @@ public class DownloadIndexesThread {
if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) ||
item.getType() == DownloadActivityType.ROADS_FILE ||
item.getType() == DownloadActivityType.WIKIPEDIA_FILE ||
item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE){
item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
outdated = true;
} else {
long itemSize = item.getContentSize();
long oldItemSize = 0;
if(item.getType() == DownloadActivityType.VOICE_FILE) {
if(item instanceof AssetIndexItem) {
if (item.getType() == DownloadActivityType.VOICE_FILE) {
if (item instanceof AssetIndexItem) {
File file = new File(((AssetIndexItem) item).getDestFile());
oldItemSize = file.length();
} else {
File fl = new File(item.getType().getDownloadFolder(app, item), sfName +"/_config.p");
File fl = new File(item.getType().getDownloadFolder(app, item), sfName + "/_config.p");
if (fl.exists()) {
oldItemSize = fl.length();
try {
@ -612,11 +638,11 @@ public class DownloadIndexesThread {
}
}
} else {
oldItemSize = app.getAppPath(item.getTargetFileName()).length();
oldItemSize = app.getAppPath(item.getTargetFileName()).length();
}
if (itemSize != oldItemSize){
if (itemSize != oldItemSize) {
outdated = true;
}
}
@ -624,7 +650,7 @@ public class DownloadIndexesThread {
return outdated;
}
private void updateFilesToUpdate(){
private void updateFilesToUpdate() {
List<IndexItem> stillUpdate = new ArrayList<IndexItem>();
for (IndexItem item : itemsToUpdate) {
String sfName = item.getTargetFileName();
@ -640,7 +666,7 @@ public class DownloadIndexesThread {
}
}
itemsToUpdate = stillUpdate;
if (uiActivity != null){
if (uiActivity != null) {
uiActivity.updateDownloadList(itemsToUpdate);
}
}
@ -655,16 +681,16 @@ public class DownloadIndexesThread {
}
return false;
}
public BasicProgressAsyncTask<?, ?, ?> getCurrentRunningTask() {
for(int i = 0; i< currentRunningTask.size(); ) {
if(currentRunningTask.get(i).getStatus() == Status.FINISHED) {
for (int i = 0; i < currentRunningTask.size(); ) {
if (currentRunningTask.get(i).getStatus() == Status.FINISHED) {
currentRunningTask.remove(i);
} else {
i++;
}
}
if(currentRunningTask.size() > 0) {
if (currentRunningTask.size() > 0) {
return currentRunningTask.get(0);
}
return null;
@ -684,30 +710,30 @@ public class DownloadIndexesThread {
int i = 0;
Collection<List<DownloadEntry>> vs = getEntriesToDownload().values();
for (List<DownloadEntry> v : vs) {
for(DownloadEntry e : v) {
if(!currentDownloads.contains(e)) {
for (DownloadEntry e : v) {
if (!currentDownloads.contains(e)) {
i++;
}
}
}
if(!currentDownloads.isEmpty()) {
if (!currentDownloads.isEmpty()) {
i++;
}
return i;
}
public int getCountedDownloads() {
int i = 0;
Collection<List<DownloadEntry>> vs = getEntriesToDownload().values();
for (List<DownloadEntry> v : vs) {
for(DownloadEntry e : v) {
if(DownloadActivityType.isCountedInDownloads(e.item)) {
for (DownloadEntry e : v) {
if (DownloadActivityType.isCountedInDownloads(e.item)) {
i++;
}
}
}
return i;
}
}

View file

@ -1,22 +1,24 @@
package net.osmand.plus.download;
import android.content.Context;
import android.support.annotation.NonNull;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.helpers.HasName;
import org.apache.commons.logging.Log;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import org.apache.commons.logging.Log;
import android.content.Context;
public class IndexItem implements Comparable<IndexItem> {
public class IndexItem implements Comparable<IndexItem>, HasName {
private static final Log log = PlatformUtil.getLog(IndexItem.class);
String description;
@ -110,7 +112,7 @@ public class IndexItem implements Comparable<IndexItem> {
}
@Override
public int compareTo(IndexItem another) {
public int compareTo(@NonNull IndexItem another) {
if(another == null) {
return -1;
}
@ -141,4 +143,8 @@ public class IndexItem implements Comparable<IndexItem> {
return format.format(new Date(timestamp));
}
@Override
public String getName() {
return getBasename();
}
}

View file

@ -1,5 +1,14 @@
package net.osmand.plus.download;
import android.support.annotation.NonNull;
import net.osmand.Collator;
import net.osmand.OsmAndCollator;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -8,16 +17,9 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.osmand.Collator;
import net.osmand.OsmAndCollator;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
public class IndexItemCategory implements Comparable<IndexItemCategory> {
public final String name;
public final List<IndexItem> items = new ArrayList<IndexItem>();
public final List<IndexItem> items = new ArrayList<>();
private final int order;
public IndexItemCategory(String name, int order) {
@ -26,14 +28,14 @@ public class IndexItemCategory implements Comparable<IndexItemCategory> {
}
@Override
public int compareTo(IndexItemCategory another) {
public int compareTo(@NonNull IndexItemCategory another) {
return order < another.order ? -1 : 1;
}
public static List<IndexItemCategory> categorizeIndexItems(final OsmandApplication ctx,
Collection<IndexItem> indexItems) {
boolean skipWiki = Version.isFreeVersion(ctx);
final Map<String, IndexItemCategory> cats = new TreeMap<String, IndexItemCategory>();
final Map<String, IndexItemCategory> cats = new TreeMap<>();
for (IndexItem i : indexItems) {
int nameId = R.string.index_name_other;
int order = 0;
@ -110,7 +112,7 @@ public class IndexItemCategory implements Comparable<IndexItemCategory> {
}
cats.get(name).items.add(i);
}
ArrayList<IndexItemCategory> r = new ArrayList<IndexItemCategory>(cats.values());
ArrayList<IndexItemCategory> r = new ArrayList<>(cats.values());
final Collator collator = OsmAndCollator.primaryCollator();
for(IndexItemCategory ct : r) {
final OsmandRegions osmandRegions = ctx.getResourceManager().getOsmandRegions();

View file

@ -779,8 +779,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
Map<LocalIndexInfo, List<LocalIndexInfo>> data = new LinkedHashMap<LocalIndexInfo, List<LocalIndexInfo>>();

View file

@ -0,0 +1,261 @@
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.R;
import net.osmand.plus.Version;
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;
public class IndexItemCategoryWithSubcat implements Comparable<IndexItemCategoryWithSubcat>,
Parcelable, HasName {
private static final Log LOG = PlatformUtil.getLog(IndexItemCategoryWithSubcat.class);
public final List<IndexItem> items;
public final List<IndexItemCategoryWithSubcat> subcats;
public final CategoryStaticData categoryStaticData;
public IndexItemCategoryWithSubcat(CategoryStaticData categoryStaticData) {
this.categoryStaticData = categoryStaticData;
items = new ArrayList<>();
subcats = new ArrayList<>();
}
@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);
final IndexItemCategoryWithSubcat category =
new IndexItemCategoryWithSubcat(categoryStaticData);
if (!cats.containsKey(name)) {
cats.put(name, category);
LOG.debug("category=" + category.categoryStaticData);
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);
}
}
}
cats.get(name).items.add(i);
}
final Collator collator = OsmAndCollator.primaryCollator();
for (IndexItemCategoryWithSubcat ct : mainList) {
final OsmandRegions osmandRegions = ctx.getResourceManager().getOsmandRegions();
Collections.sort(ct.items, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(ctx, osmandRegions),
rhs.getVisibleName(ctx, osmandRegions));
}
});
}
Collections.sort(mainList);
return mainList;
}
@Override
public String getName() {
return categoryStaticData.getName();
}
public enum CategoryStaticData {
WORLD_WIDE_AND_TOPIC(R.string.index_name_other, 0),
NAME_VOICE(R.string.index_name_voice, 1),
TTS_VOICE(R.string.index_name_tts_voice, 2),
WIKI(R.string.index_name_wiki, 10),
OPENMAPS(R.string.index_name_openmaps, 90),
NORTH_AMERICA(R.string.index_name_north_america, 30),
US(R.string.index_name_us, 31, NORTH_AMERICA),
CANADA(R.string.index_name_canada, 32, NORTH_AMERICA),
CENTRAL_AMERICA(R.string.index_name_central_america, 40),
SOUTH_AMERICA(R.string.index_name_south_america, 45),
RUSSIA(R.string.index_name_russia, 25),
EUROPE(R.string.index_name_europe, 15),
GERMANY(R.string.index_name_germany, 16, EUROPE),
FRANCE(R.string.index_name_france, 17, EUROPE),
ITALY(R.string.index_name_italy, 18, EUROPE),
GB(R.string.index_name_gb, 19, EUROPE),
NETHERLANDS(R.string.index_name_netherlands, 20, EUROPE),
AFRICA(R.string.index_name_africa, 80),
ASIA(R.string.index_name_asia, 50),
OCEANIA(R.string.index_name_oceania, 70),
TOURS(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.writeList(this.items);
dest.writeList(this.subcats);
dest.writeInt(this.categoryStaticData.ordinal());
dest.writeString(this.categoryStaticData.getName());
}
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());
int tmpCategoryStaticData = in.readInt();
this.categoryStaticData = CategoryStaticData.values()[tmpCategoryStaticData];
this.categoryStaticData.setName(in.readString());
}
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];
}
};
}

View file

@ -0,0 +1,86 @@
package net.osmand.plus.download.newimplementation;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.helpers.HasName;
public class MapsInCategoryFragment extends DialogFragment {
public static final String TAG = "MapsInCategoryFragment";
private static final String CATEGORY = "category";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
IndexItemCategoryWithSubcat category = getArguments().getParcelable(CATEGORY);
assert category != null;
ListView listView = (ListView) view.findViewById(android.R.id.list);
final MapFilesAdapter mAdapter = new MapFilesAdapter(getActivity());
listView.setAdapter(mAdapter);
mAdapter.add(new Divider("maps"));
mAdapter.addAll(category.items);
mAdapter.add(new Divider("subcategories"));
mAdapter.addAll(category.subcats);
return view;
}
public static MapsInCategoryFragment createInstance(
@NonNull IndexItemCategoryWithSubcat category) {
Bundle bundle = new Bundle();
bundle.putParcelable(CATEGORY, category);
MapsInCategoryFragment fragment = new MapsInCategoryFragment();
fragment.setArguments(bundle);
return fragment;
}
private static class MapFilesAdapter extends ArrayAdapter<HasName> {
public MapFilesAdapter(Context context) {
super(context, R.layout.simple_list_menu_item);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.simple_list_menu_item, parent, false);
viewHolder = new ViewHolder();
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.textView.setText(getItem(position).getName());
return convertView;
}
private static class ViewHolder {
TextView textView;
}
}
public static class Divider implements HasName {
private final String text;
public Divider(String text) {
this.text = text;
}
@Override
public String getName() {
return text;
}
}
}

View file

@ -0,0 +1,159 @@
package net.osmand.plus.download.newimplementation;
import android.content.Context;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v4.view.MenuItemCompat;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import org.apache.commons.logging.Log;
import java.io.File;
import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;
public class NewLocalIndexesFragment extends OsmAndListFragment {
private static final Log LOG = PlatformUtil.getLog(NewLocalIndexesFragment.class);
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
public static final int RELOAD_ID = 0;
private CategoriesAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.local_index_fragment, container, false);
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
ProgressBar sizeProgress = (ProgressBar) view.findViewById(R.id.memory_progress);
File dir = getMyApplication().getAppPath("").getParentFile();
String size = formatGb.format(new Object[]{0});
int percent = 0;
if (dir.canRead()) {
StatFs statFs = new StatFs(dir.getAbsolutePath());
//noinspection deprecation
size = formatGb.format(new Object[]{(float) (statFs.getAvailableBlocks()) * statFs.getBlockSize() / (1 << 30)});
//noinspection deprecation
percent = statFs.getAvailableBlocks() * 100 / statFs.getBlockCount();
}
sizeProgress.setProgress(percent);
String text = getString(R.string.free, size);
TextView descriptionText = (TextView) view.findViewById(R.id.memory_size);
descriptionText.setText(Html.fromHtml(text));
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
TextView downloadsLeftTextView = (TextView) view.findViewById(R.id.downloadsLeftTextView);
downloadsLeftTextView.setText(getString(R.string.downloads_left_template,
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
- getMyApplication().getSettings().NUMBER_OF_FREE_DOWNLOADS.get()));
TextView freeVersionDescriptionTextView =
(TextView) view.findViewById(R.id.freeVersionDescriptionTextView);
freeVersionDescriptionTextView.setText(getString(R.string.free_version_message,
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
ListView listView = (ListView) view.findViewById(android.R.id.list);
mAdapter = new CategoriesAdapter(getActivity());
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LOG.debug("onItemClick()");
}
});
// listAdapter = new LocalIndexesAdapter(getActivity());
// listView.setAdapter(listAdapter);
// setListView(listView);
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(0, RELOAD_ID, 0, R.string.shared_string_refresh);
item.setIcon(R.drawable.ic_action_refresh_dark);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) {
// re-create the thread
DownloadActivity.downloadListIndexThread.runReloadIndexFiles(true);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
MapsInCategoryFragment.createInstance(mAdapter.getItem(position))
.show(getChildFragmentManager(), MapsInCategoryFragment.TAG);
LOG.debug("onListItemClick()");
super.onListItemClick(l, v, position, id);
}
private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}
public void onCategorizationFinished(List<IndexItem> filtered, List<IndexItemCategoryWithSubcat> cats) {
LOG.debug("cats=" + cats);
mAdapter.clear();
mAdapter.addAll(cats);
}
private static class CategoriesAdapter extends ArrayAdapter<IndexItemCategoryWithSubcat> {
public CategoriesAdapter(Context context) {
super(context, R.layout.simple_list_menu_item);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.simple_list_menu_item, parent, false);
viewHolder = new ViewHolder();
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.textView.setText(getItem(position).categoryStaticData.getName());
return convertView;
}
private static class ViewHolder {
TextView textView;
}
}
}

View file

@ -0,0 +1,5 @@
package net.osmand.plus.helpers;
public interface HasName {
String getName();
}