Merge remote-tracking branch 'origin/master'
BIN
OsmAnd/res/drawable-hdpi/bg_download_bar_light_grey.9.png
Executable file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-hdpi/bg_download_bar_light_orange.9.png
Executable file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-mdpi/bg_download_bar_light_grey.9.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
OsmAnd/res/drawable-mdpi/bg_download_bar_light_orange.9.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
BIN
OsmAnd/res/drawable-xhdpi/bg_download_bar_light_grey.9.png
Executable file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-xhdpi/bg_download_bar_light_orange.9.png
Executable file
After Width: | Height: | Size: 1.4 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/bg_download_bar_light_grey.9.png
Executable file
After Width: | Height: | Size: 1.6 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/bg_download_bar_light_orange.9.png
Executable file
After Width: | Height: | Size: 1.6 KiB |
|
@ -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>
|
206
OsmAnd/res/layout/local_index_fragment.xml
Normal 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>
|
10
OsmAnd/res/layout/maps_in_category_fragment.xml
Normal 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>
|
|
@ -3,20 +3,24 @@
|
|||
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: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>
|
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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,25 +87,25 @@ 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 {
|
||||
// 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);
|
||||
|
||||
|
@ -114,13 +116,16 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
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), NewLocalIndexesFragment.class));
|
||||
|
||||
viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs));
|
||||
mSlidingTabLayout.setViewPager(viewPager);
|
||||
|
||||
viewPager.setCurrentItem(currentTab);
|
||||
}
|
||||
// }
|
||||
|
||||
settings = ((OsmandApplication)getApplication()).getSettings();
|
||||
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,7 +150,7 @@ 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) {
|
||||
|
@ -153,20 +158,20 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
});
|
||||
|
||||
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){
|
||||
((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter) {
|
||||
((BaseExpandableListAdapter) ((OsmandExpandableListFragment) f).getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +199,6 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
|
||||
|
||||
|
||||
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,7 +357,7 @@ 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)));
|
||||
|
@ -348,7 +365,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for(IndexItem i : wi) {
|
||||
for (IndexItem i : wi) {
|
||||
addToDownload(i);
|
||||
}
|
||||
updateDownloadButton();
|
||||
|
@ -356,7 +373,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
if(wi.size() > 0) {
|
||||
if (wi.size() > 0) {
|
||||
bld.show();
|
||||
}
|
||||
}
|
||||
|
@ -365,12 +382,12 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
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);
|
||||
|
@ -378,11 +395,11 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
@ -429,7 +446,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
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);
|
||||
}
|
||||
|
@ -494,12 +510,12 @@ 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);
|
||||
}
|
||||
|
@ -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 {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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,7 +73,7 @@ public class DownloadIndexesThread {
|
|||
dbHelper = new DatabaseHelper(app);
|
||||
}
|
||||
|
||||
public DatabaseHelper getDbHelper(){
|
||||
public DatabaseHelper getDbHelper() {
|
||||
return dbHelper;
|
||||
}
|
||||
|
||||
|
@ -86,8 +87,8 @@ public class DownloadIndexesThread {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -103,11 +104,11 @@ public class DownloadIndexesThread {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -152,7 +153,7 @@ public class DownloadIndexesThread {
|
|||
@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,14 +223,13 @@ public class DownloadIndexesThread {
|
|||
uiActivity.downloadedIndexes();
|
||||
}
|
||||
currentRunningTask.remove(this);
|
||||
if(uiActivity != null) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(false);
|
||||
}
|
||||
updateFilesToUpdate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String doInBackground(IndexItem... filesToDownload) {
|
||||
try {
|
||||
|
@ -237,32 +237,33 @@ 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
|
||||
|
@ -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,7 +332,7 @@ public class DownloadIndexesThread {
|
|||
warnings = manager.indexingMaps(this);
|
||||
}
|
||||
List<String> wns = manager.indexAdditionalMaps(this);
|
||||
if(wns != null) {
|
||||
if (wns != null) {
|
||||
warnings.addAll(wns);
|
||||
}
|
||||
|
||||
|
@ -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,14 +383,14 @@ 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;
|
||||
}
|
||||
|
@ -397,13 +398,13 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
public void runReloadIndexFiles() {
|
||||
checkRunning();
|
||||
final BasicProgressAsyncTask<Void, Void, IndexFileList> inst = new BasicProgressAsyncTask<Void, Void, IndexFileList>(ctx) {
|
||||
runReloadIndexFiles(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndexFileList doInBackground(Void... params) {
|
||||
return DownloadOsmandIndexesHelper.getIndexesList(ctx);
|
||||
};
|
||||
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,23 +480,25 @@ 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 ) {
|
||||
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,14 +510,21 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -517,10 +532,17 @@ public class DownloadIndexesThread {
|
|||
@Override
|
||||
protected List<IndexItem> doInBackground(Void... params) {
|
||||
final List<IndexItem> filtered = getFilteredByType();
|
||||
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>();
|
||||
|
@ -540,22 +562,26 @@ public class DownloadIndexesThread {
|
|||
protected void onPostExecute(List<IndexItem> filtered) {
|
||||
prepareFilesToUpdate();
|
||||
currentRunningTask.remove(this);
|
||||
if(uiActivity != null) {
|
||||
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 {
|
||||
|
@ -616,7 +642,7 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -657,14 +683,14 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
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,13 +710,13 @@ 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;
|
||||
|
@ -700,8 +726,8 @@ public class DownloadIndexesThread {
|
|||
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++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -779,8 +779,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
Map<LocalIndexInfo, List<LocalIndexInfo>> data = new LinkedHashMap<LocalIndexInfo, List<LocalIndexInfo>>();
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
5
OsmAnd/src/net/osmand/plus/helpers/HasName.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
public interface HasName {
|
||||
String getName();
|
||||
}
|