Fragment added
This commit is contained in:
parent
002b25e426
commit
e258fc702a
3 changed files with 1010 additions and 134 deletions
108
OsmAnd/res/layout/local_index_fragment.xml
Normal file
108
OsmAnd/res/layout/local_index_fragment.xml
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?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">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Free Version"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="8 downloads left"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="@string/free_version_message"/>
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@android:style/Widget.ProgressBar.Horizontal"
|
||||
android:max="10"/>
|
||||
|
||||
<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_marginBottom="@dimen/dialog_content_bottom_margin"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/dialog_content_bottom_margin"
|
||||
android:paddingRight="@dimen/dialog_content_bottom_margin"
|
||||
android:paddingTop="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/local_size_height"
|
||||
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"
|
||||
android:text="@string/free"
|
||||
android:textStyle="bold"/>
|
||||
</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>
|
||||
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:focusable="true"
|
||||
android:groupIndicator="@android:color/transparent"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -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;
|
||||
|
@ -22,27 +34,15 @@ import net.osmand.plus.activities.TabActivity;
|
|||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||
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 +85,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 +131,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 +140,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 +148,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 +156,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 +197,6 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public Map<String, String> getIndexActivatedFileNames() {
|
||||
return downloadListIndexThread != null ? downloadListIndexThread.getIndexActivatedFileNames() : null;
|
||||
}
|
||||
|
@ -222,11 +224,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 +250,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 +280,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 +292,39 @@ 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) {
|
||||
public void downloadListUpdated() {
|
||||
for (WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if(f instanceof DownloadIndexFragment) {
|
||||
if(!f.isDetached()) {
|
||||
((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
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 +342,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 +350,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 +358,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 +367,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 +380,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 +431,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 +440,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 +454,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 +477,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 +495,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 +514,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
|
||||
|
||||
public Map<String,String> getIndexFileNames() {
|
||||
public Map<String, String> getIndexFileNames() {
|
||||
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
|
||||
}
|
||||
|
||||
|
@ -526,19 +527,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 +568,4 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
772
OsmAnd/src/net/osmand/plus/download/NewLocalIndexesFragment.java
Normal file
772
OsmAnd/src/net/osmand/plus/download/NewLocalIndexesFragment.java
Normal file
|
@ -0,0 +1,772 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.StatFs;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.LocalIndexHelper;
|
||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.Collator;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class NewLocalIndexesFragment extends OsmAndListFragment {
|
||||
|
||||
private LoadLocalIndexTask asyncLoader;
|
||||
private BaseAdapter listAdapter;
|
||||
private AsyncTask<LocalIndexInfo, ?, ?> operationTask;
|
||||
|
||||
private boolean selectionMode = false;
|
||||
private Set<LocalIndexInfo> selectedItems = new LinkedHashSet<LocalIndexInfo>();
|
||||
|
||||
protected static int DELETE_OPERATION = 1;
|
||||
protected static int BACKUP_OPERATION = 2;
|
||||
protected static int RESTORE_OPERATION = 3;
|
||||
|
||||
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
||||
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
|
||||
private ContextMenuAdapter optionsMenuAdapter;
|
||||
private ActionMode actionMode;
|
||||
|
||||
private TextView descriptionText;
|
||||
private ProgressBar sizeProgress;
|
||||
|
||||
Drawable backup;
|
||||
Drawable sdcard;
|
||||
Drawable planet;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.local_index_fragment, container, false);
|
||||
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
|
||||
ListView listView = (ListView)view.findViewById(android.R.id.list);
|
||||
// listAdapter = new LocalIndexesAdapter(getActivity());
|
||||
// listView.setAdapter(listAdapter);
|
||||
// setListView(listView);
|
||||
descriptionText = (TextView) view.findViewById(R.id.memory_size);
|
||||
sizeProgress = (ProgressBar) view.findViewById(R.id.memory_progress);
|
||||
updateDescriptionTextWithSize();
|
||||
colorDrawables();
|
||||
return view;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked","deprecation"})
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (asyncLoader == null || asyncLoader.getResult() == null) {
|
||||
// getLastNonConfigurationInstance method should be in onCreate() method
|
||||
// (onResume() doesn't work)
|
||||
Object indexes = getActivity().getLastNonConfigurationInstance();
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
if (indexes instanceof List<?>) {
|
||||
asyncLoader.setResult((List<LocalIndexInfo>) indexes);
|
||||
}
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
private void colorDrawables(){
|
||||
boolean light = getMyApplication().getSettings().isLightContent();
|
||||
backup = getActivity().getResources().getDrawable(R.drawable.ic_type_archive);
|
||||
backup.mutate();
|
||||
if (light) {
|
||||
backup.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
sdcard = getActivity().getResources().getDrawable(R.drawable.ic_sdcard);
|
||||
sdcard.mutate();
|
||||
sdcard.setColorFilter(getActivity().getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (asyncLoader == null || asyncLoader.getResult() == null) {
|
||||
reloadData();
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadData() {
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
asyncLoader.execute(getActivity());
|
||||
}
|
||||
|
||||
|
||||
private void showContextMenu(final LocalIndexInfo info) {
|
||||
Builder builder = new Builder(getActivity());
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter(getActivity());
|
||||
basicFileOperation(info, adapter);
|
||||
OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
|
||||
|
||||
String[] values = adapter.getItemNames();
|
||||
builder.setItems(values, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
OnContextMenuClick clk = adapter.getClickAdapter(which);
|
||||
if (clk != null) {
|
||||
clk.onContextMenuClick(null, adapter.getElementId(which), which, false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
||||
private void basicFileOperation(final LocalIndexInfo info, ContextMenuAdapter adapter) {
|
||||
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
|
||||
return performBasicOperation(resId, info);
|
||||
}
|
||||
};
|
||||
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
|
||||
info.getType() == LocalIndexType.WIKI_DATA){
|
||||
if(!info.isBackupedData()){
|
||||
adapter.item(R.string.local_index_mi_backup).listen(listener).position( 1).reg();
|
||||
}
|
||||
}
|
||||
if(info.isBackupedData()){
|
||||
adapter.item(R.string.local_index_mi_restore).listen(listener).position(2).reg();
|
||||
}
|
||||
if(info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA){
|
||||
adapter.item(R.string.shared_string_rename).listen(listener).position(3).reg();
|
||||
}
|
||||
adapter.item(R.string.shared_string_delete).listen(listener).position(4).reg();
|
||||
}
|
||||
|
||||
private boolean performBasicOperation(int resId, final LocalIndexInfo info) {
|
||||
if (resId == R.string.shared_string_rename) {
|
||||
renameFile(getActivity(), new File(info.getPathToData()), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
reloadIndexes();
|
||||
}
|
||||
});
|
||||
} else if (resId == R.string.local_index_mi_restore) {
|
||||
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
|
||||
} else if (resId == R.string.shared_string_delete) {
|
||||
Builder confirm = new Builder(getActivity());
|
||||
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new LocalIndexOperationTask(DELETE_OPERATION).execute(info);
|
||||
}
|
||||
});
|
||||
confirm.setNegativeButton(R.string.shared_string_no, null);
|
||||
String fn = FileNameTranslationHelper.getFileName(getActivity(),
|
||||
getMyApplication().getResourceManager().getOsmandRegions(),
|
||||
info.getFileName());
|
||||
confirm.setMessage(getString(R.string.delete_confirmation_msg, fn));
|
||||
confirm.show();
|
||||
} else if (resId == R.string.local_index_mi_backup) {
|
||||
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void renameFile(final Activity a, final File f, final Runnable callback) {
|
||||
Builder b = new Builder(a);
|
||||
if(f.exists()){
|
||||
int xt = f.getName().lastIndexOf('.');
|
||||
final String ext = xt == -1 ? "" : f.getName().substring(xt);
|
||||
final String originalName = xt == -1 ? f.getName() : f.getName().substring(0, xt);
|
||||
final EditText editText = new EditText(a);
|
||||
editText.setText(originalName);
|
||||
b.setView(editText);
|
||||
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String newName = editText.getText().toString() + ext;
|
||||
File dest = new File(f.getParentFile(), newName);
|
||||
if (dest.exists()) {
|
||||
AccessibleToast.makeText(a, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
if(!dest.getParentFile().exists()) {
|
||||
dest.getParentFile().mkdirs();
|
||||
}
|
||||
if(f.renameTo(dest)){
|
||||
if(callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
} else {
|
||||
AccessibleToast.makeText(a, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
b.show();
|
||||
}
|
||||
}
|
||||
|
||||
public class LoadLocalIndexTask extends AsyncTask<Activity, LocalIndexInfo, List<LocalIndexInfo>> {
|
||||
|
||||
private List<LocalIndexInfo> result;
|
||||
|
||||
@Override
|
||||
protected List<LocalIndexInfo> doInBackground(Activity... params) {
|
||||
LocalIndexHelper helper = new LocalIndexHelper(getMyApplication());
|
||||
return null; //helper.getLocalIndexData(this);
|
||||
}
|
||||
|
||||
public void loadFile(LocalIndexInfo... loaded) {
|
||||
publishProgress(loaded);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
|
||||
// listAdapter.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(LocalIndexInfo... values) {
|
||||
for (LocalIndexInfo v : values) {
|
||||
// listAdapter.addLocalIndexInfo(v);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setResult(List<LocalIndexInfo> result) {
|
||||
this.result = result;
|
||||
if(result == null){
|
||||
// listAdapter.clear();
|
||||
} else {
|
||||
for (LocalIndexInfo v : result) {
|
||||
// listAdapter.addLocalIndexInfo(v);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
onPostExecute(result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<LocalIndexInfo> result) {
|
||||
this.result = result;
|
||||
// listAdapter.sortData();
|
||||
if (getDownloadActivity() != null){
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
getDownloadActivity().setLocalIndexInfos(result);
|
||||
}
|
||||
}
|
||||
|
||||
public List<LocalIndexInfo> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private File getFileToRestore(LocalIndexInfo i){
|
||||
if(i.isBackupedData()){
|
||||
File parent = new File(i.getPathToData()).getParentFile();
|
||||
if(i.getType() == LocalIndexType.SRTM_DATA){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR);
|
||||
} else if(i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.ROADS_INDEX_DIR);
|
||||
} else if(i.getType() == LocalIndexType.WIKI_DATA){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR);
|
||||
} else if(i.getType() == LocalIndexType.MAP_DATA){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH);
|
||||
} else if(i.getType() == LocalIndexType.TILES_DATA){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
} else if(i.getType() == LocalIndexType.VOICE_DATA){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
} else if(i.getType() == LocalIndexType.TTS_VOICE_DATA){
|
||||
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
}
|
||||
return new File(parent, i.getFileName());
|
||||
}
|
||||
return new File(i.getPathToData());
|
||||
}
|
||||
|
||||
private File getFileToBackup(LocalIndexInfo i) {
|
||||
if(!i.isBackupedData()){
|
||||
return new File(getMyApplication().getAppPath(IndexConstants.BACKUP_INDEX_DIR), i.getFileName());
|
||||
}
|
||||
return new File(i.getPathToData());
|
||||
}
|
||||
|
||||
private boolean move(File from, File to){
|
||||
if(!to.getParentFile().exists()){
|
||||
to.getParentFile().mkdirs();
|
||||
}
|
||||
return from.renameTo(to);
|
||||
}
|
||||
|
||||
public class LocalIndexOperationTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, String> {
|
||||
|
||||
private final int operation;
|
||||
|
||||
public LocalIndexOperationTask(int operation){
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String doInBackground(LocalIndexInfo... params) {
|
||||
int count = 0;
|
||||
int total = 0;
|
||||
for(LocalIndexInfo info : params) {
|
||||
if(!isCancelled()){
|
||||
boolean successfull = false;
|
||||
if(operation == DELETE_OPERATION){
|
||||
File f = new File(info.getPathToData());
|
||||
successfull = Algorithms.removeAllFiles(f);
|
||||
} else if(operation == RESTORE_OPERATION){
|
||||
successfull = move(new File(info.getPathToData()), getFileToRestore(info));
|
||||
if(successfull){
|
||||
info.setBackupedData(false);
|
||||
}
|
||||
} else if(operation == BACKUP_OPERATION){
|
||||
successfull = move(new File(info.getPathToData()), getFileToBackup(info));
|
||||
if(successfull){
|
||||
info.setBackupedData(true);
|
||||
getMyApplication().getResourceManager().closeFile(info.getFileName());
|
||||
}
|
||||
}
|
||||
total ++;
|
||||
if(successfull){
|
||||
count++;
|
||||
publishProgress(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(operation == DELETE_OPERATION){
|
||||
return getString(R.string.local_index_items_deleted, count, total);
|
||||
} else if(operation == BACKUP_OPERATION){
|
||||
return getString(R.string.local_index_items_backuped, count, total);
|
||||
} else if(operation == RESTORE_OPERATION){
|
||||
return getString(R.string.local_index_items_restored, count, total);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(LocalIndexInfo... values) {
|
||||
if(operation == DELETE_OPERATION){
|
||||
// listAdapter.delete(values);
|
||||
} else if(operation == BACKUP_OPERATION){
|
||||
// listAdapter.move(values, false);
|
||||
} else if(operation == RESTORE_OPERATION){
|
||||
// listAdapter.move(values, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
getDownloadActivity().setProgressBarIndeterminateVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
getDownloadActivity().setProgressBarIndeterminateVisibility(false);
|
||||
AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
|
||||
if (operation == RESTORE_OPERATION || operation == BACKUP_OPERATION){
|
||||
// listAdapter.clear();
|
||||
reloadIndexes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Set<LocalIndexInfo> getSelectedItems() {
|
||||
return selectedItems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if(operationTask != null){
|
||||
operationTask.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
asyncLoader.cancel(true);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (!this.isAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//fixes issue when local files not shown after switching tabs
|
||||
//Next line throws NPE in some circumstances when called from dashboard and listAdpater=null is not checked for. (Checking !this.isAdded above is not sufficient!)
|
||||
ActionBar actionBar = getDownloadActivity().getSupportActionBar();
|
||||
//hide action bar from downloadindexfragment
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
optionsMenuAdapter = new ContextMenuAdapter(getDownloadActivity());
|
||||
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
localOptionsMenu(itemId);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
optionsMenuAdapter.item(R.string.local_index_mi_reload)
|
||||
.icon(R.drawable.ic_action_refresh_dark)
|
||||
.listen(listener).position(1).reg();
|
||||
optionsMenuAdapter.item(R.string.shared_string_delete)
|
||||
.icon(R.drawable.ic_action_delete_dark)
|
||||
.listen(listener).position(2).reg();
|
||||
optionsMenuAdapter.item(R.string.local_index_mi_backup)
|
||||
.listen(listener).position(3).reg();
|
||||
optionsMenuAdapter.item(R.string.local_index_mi_restore)
|
||||
.listen(listener).position(4).reg();
|
||||
// doesn't work correctly
|
||||
//int max = getResources().getInteger(R.integer.abs__max_action_buttons);
|
||||
int max = 3;
|
||||
SubMenu split = null;
|
||||
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
|
||||
MenuItem item;
|
||||
if (j + 1 >= max && optionsMenuAdapter.length() > max) {
|
||||
if (split == null) {
|
||||
split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
|
||||
split.setIcon(R.drawable.ic_overflow_menu_white);
|
||||
split.getItem();
|
||||
MenuItemCompat.setShowAsAction(split.getItem(),MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
item = split.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS );
|
||||
} else {
|
||||
item = menu.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS );
|
||||
}
|
||||
OsmandApplication app = getMyApplication();
|
||||
|
||||
}
|
||||
|
||||
if(operationTask == null || operationTask.getStatus() == AsyncTask.Status.FINISHED){
|
||||
menu.setGroupVisible(0, true);
|
||||
} else {
|
||||
menu.setGroupVisible(0, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
for (int i = 0; i < optionsMenuAdapter.length(); i++) {
|
||||
if (itemId == optionsMenuAdapter.getElementId(i)) {
|
||||
optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void doAction(int actionResId){
|
||||
if(actionResId == R.string.local_index_mi_backup){
|
||||
operationTask = new LocalIndexOperationTask(BACKUP_OPERATION);
|
||||
} else if(actionResId == R.string.shared_string_delete){
|
||||
operationTask = new LocalIndexOperationTask(DELETE_OPERATION);
|
||||
} else if(actionResId == R.string.local_index_mi_restore){
|
||||
operationTask = new LocalIndexOperationTask(RESTORE_OPERATION);
|
||||
} else {
|
||||
operationTask = null;
|
||||
}
|
||||
if(operationTask != null){
|
||||
operationTask.execute(selectedItems.toArray(new LocalIndexInfo[selectedItems.size()]));
|
||||
}
|
||||
if(actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void openSelectionMode(final int actionResId, final int actionIconId,
|
||||
final DialogInterface.OnClickListener listener){
|
||||
String value = getString(actionResId);
|
||||
if (value.endsWith("...")) {
|
||||
value = value.substring(0, value.length() - 3);
|
||||
}
|
||||
final String actionButton = value;
|
||||
|
||||
selectionMode = true;
|
||||
selectedItems.clear();
|
||||
//findViewById(R.id.DescriptionText).setVisibility(View.GONE);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateDescriptionTextWithSize(){
|
||||
File dir = getMyApplication().getAppPath("").getParentFile();
|
||||
String size = formatGb.format(new Object[]{0});
|
||||
int percent = 0;
|
||||
if(dir.canRead()){
|
||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
|
||||
percent = (int) (fs.getAvailableBlocks() * 100 / fs.getBlockCount());
|
||||
}
|
||||
sizeProgress.setProgress(percent);
|
||||
String text = getString(R.string.free, size);
|
||||
int l = text.indexOf('.');
|
||||
if(l == -1) {
|
||||
l = text.length();
|
||||
}
|
||||
descriptionText.setText(text);
|
||||
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public void localOptionsMenu(final int itemId) {
|
||||
if (itemId == R.string.local_index_mi_reload) {
|
||||
reloadIndexes();
|
||||
} else if (itemId == R.string.shared_string_delete) {
|
||||
openSelectionMode(itemId, R.drawable.ic_action_delete_dark,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doAction(itemId);
|
||||
}
|
||||
}, null, null);
|
||||
} else if (itemId == R.string.local_index_mi_backup) {
|
||||
openSelectionMode(itemId, R.drawable.ic_type_archive,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doAction(itemId);
|
||||
}
|
||||
}, Boolean.FALSE, LocalIndexType.MAP_DATA);
|
||||
} else if (itemId == R.string.local_index_mi_restore) {
|
||||
openSelectionMode(itemId, R.drawable.ic_type_archive,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doAction(itemId);
|
||||
}
|
||||
}, Boolean.TRUE, LocalIndexType.MAP_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
public void openSelectionMode(int stringRes, int darkIcon, DialogInterface.OnClickListener listener, Boolean backup,
|
||||
LocalIndexType filter) {
|
||||
openSelectionMode(stringRes, darkIcon, listener);
|
||||
}
|
||||
|
||||
|
||||
public void reloadIndexes() {
|
||||
asyncLoader = new LoadLocalIndexTask();
|
||||
AsyncTask<Void, String, List<String>> task = new AsyncTask<Void, String, List<String>>(){
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<String> warnings) {
|
||||
if ( getDownloadActivity() == null) {
|
||||
return;
|
||||
}
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
if (!warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if (f) {
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
b.append(w);
|
||||
}
|
||||
AccessibleToast.makeText(getDownloadActivity(), b.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if(asyncLoader.getStatus() == Status.PENDING) {
|
||||
asyncLoader.execute(getDownloadActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
|
||||
}
|
||||
@Override
|
||||
protected List<String> doInBackground(Void... params) {
|
||||
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
|
||||
new ArrayList<String>()
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
task.execute();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void openPopUpMenu(View v, final LocalIndexInfo info) {
|
||||
IconsCache iconsCache = getMyApplication().getIconsCache();
|
||||
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
|
||||
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
|
||||
final boolean restore = info.isBackupedData();
|
||||
MenuItem item;
|
||||
if (info.getType() == LocalIndexType.MAP_DATA) {
|
||||
item = optionsMenu.getMenu().add(restore? R.string.local_index_mi_restore : R.string.local_index_mi_backup)
|
||||
.setIcon(backup);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
performBasicOperation(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup, info);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_rename)
|
||||
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_edit_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
performBasicOperation(R.string.shared_string_rename, info);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
item = optionsMenu.getMenu().add(R.string.shared_string_delete)
|
||||
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_delete_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
performBasicOperation(R.string.shared_string_delete, info);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if(getMyApplication().getSettings().BETA_TESTING_LIVE_UPDATES.get()) {
|
||||
item = optionsMenu.getMenu().add("Live updates")
|
||||
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_refresh_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
runLiveUpdate(info);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
optionsMenu.show();
|
||||
}
|
||||
|
||||
private void runLiveUpdate(final LocalIndexInfo info) {
|
||||
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
|
||||
new AsyncTask<Object, Object, IncrementalUpdateList>() {
|
||||
|
||||
protected void onPreExecute() {
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
protected IncrementalUpdateList doInBackground(Object... params) {
|
||||
IncrementalChangesManager cm = getMyApplication().getResourceManager().getChangesManager();
|
||||
return cm.getUpdatesByMonth(fnExt);
|
||||
}
|
||||
|
||||
protected void onPostExecute(IncrementalUpdateList result) {
|
||||
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
if (result.errorMessage != null) {
|
||||
Toast.makeText(getDownloadActivity(), result.errorMessage, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
List<IncrementalUpdate> ll = result.getItemsForUpdate();
|
||||
if(ll.isEmpty()) {
|
||||
Toast.makeText(getDownloadActivity(), R.string.no_updates_available, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
for (IncrementalUpdate iu : ll) {
|
||||
IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText,
|
||||
iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
|
||||
getDownloadActivity().addToDownload(ii);
|
||||
getDownloadActivity().updateDownloadButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}.execute(new Object[] { fnExt });
|
||||
}
|
||||
|
||||
|
||||
private DownloadActivity getDownloadActivity() {
|
||||
return (DownloadActivity) getActivity();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue