Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-17 19:31:16 +02:00
commit 27ba888bf1
2 changed files with 24 additions and 173 deletions

View file

@ -1,25 +1,13 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.app.AlertDialog; import java.io.File;
import android.app.AlertDialog.Builder; import java.lang.ref.WeakReference;
import android.content.ActivityNotFoundException; import java.text.MessageFormat;
import android.content.DialogInterface; import java.util.ArrayList;
import android.content.Intent; import java.util.List;
import android.net.Uri; import java.util.Locale;
import android.os.AsyncTask; import java.util.Map;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -39,16 +27,21 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.File; import android.content.ActivityNotFoundException;
import java.lang.ref.WeakReference; import android.content.Intent;
import java.text.MessageFormat; import android.net.Uri;
import java.util.ArrayList; import android.os.AsyncTask;
import java.util.Collection; import android.os.Bundle;
import java.util.HashSet; import android.os.StatFs;
import java.util.List; import android.support.v4.app.DialogFragment;
import java.util.Locale; import android.support.v4.app.Fragment;
import java.util.Map; import android.support.v4.app.FragmentActivity;
import java.util.Set; import android.support.v4.view.ViewPager;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
public class DownloadActivity extends BaseDownloadActivity implements DialogDismissListener { public class DownloadActivity extends BaseDownloadActivity implements DialogDismissListener {
@ -300,66 +293,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
} }
protected void downloadWikiFiles() {
if (Version.isFreeVersion(getMyApplication())) {
new InstallPaidVersionDialogFragment().show(getSupportFragmentManager(),
InstallPaidVersionDialogFragment.TAG);
} else {
Builder bld = new AlertDialog.Builder(this);
final List<IndexItem> wi = getWikipediaItems();
long size = 0;
for (IndexItem i : wi) {
size += i.getSize();
}
bld.setMessage(getString(R.string.download_wikipedia_files, (size >> 20)));
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (IndexItem i : wi) {
addToDownload(i);
}
updateFragments();
checkOldWikiFiles();
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
if (wi.size() > 0) {
bld.show();
}
}
}
protected void checkOldWikiFiles() {
Map<String, String> fileNames = getMyApplication().getResourceManager().getIndexFileNames();
final Set<String> wiki = new HashSet<String>();
for (String s : fileNames.keySet()) {
if (s.contains("_wiki")) {
wiki.add(s);
}
}
if (wiki.size() > 0) {
Builder bld = new AlertDialog.Builder(this);
bld.setMessage(R.string.archive_wikipedia_data);
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (String w : wiki) {
File fl = getMyApplication().getAppPath(w);
File nf = new File(fl.getParentFile(), IndexConstants.BACKUP_INDEX_DIR + "/" + fl.getName());
boolean res = fl.renameTo(nf);
if (!res) {
System.err.println("Renaming from " + fl.getAbsolutePath() + " to " + nf.getAbsolutePath() + " failed");
}
}
}
});
bld.show();
}
}
@Override @Override
public void updateFragments() { public void updateFragments() {
@ -374,41 +308,6 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
} }
} }
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) {
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")) {
wikipediaItems.add(fname);
}
}
}
for (IndexItem i : getEntriesToDownload().keySet()) {
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
wikipediaItems.remove(i.getBasename());
}
}
List<IndexItem> res = new ArrayList<IndexItem>();
IndexFileList list = downloadListIndexThread.getIndexFiles();
if (list != null) {
List<IndexItem> indexFiles = list.getIndexFiles();
for (IndexItem i : indexFiles) {
if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE &&
wikipediaItems.contains(i.getBasename())) {
res.add(i);
}
}
}
return res;
}
public List<DownloadActivityType> getDownloadTypes() { public List<DownloadActivityType> getDownloadTypes() {
return downloadTypes; return downloadTypes;
} }
@ -443,55 +342,6 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
return downloadListIndexThread != null ? downloadListIndexThread.getCachedIndexFiles() : null; return downloadListIndexThread != null ? downloadListIndexThread.getCachedIndexFiles() : null;
} }
public void showDialogToDownloadMaps(Collection<String> maps) {
int count = 0;
int sz = 0;
String s = "";
for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) {
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) {
count++;
sz += d.sizeMB;
}
if (s.length() > 0) {
s += ", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getEntriesToDownload().put(i, de);
}
}
}
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() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadFilesCheckInternet();
}
});
builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getEntriesToDownload().clear();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
getEntriesToDownload().clear();
}
});
builder.show();
}
}
public void registerFreeVersionBanner(View view) { public void registerFreeVersionBanner(View view) {
visibleBanner = new BannerAndDownloadFreeVersion(view, this); visibleBanner = new BannerAndDownloadFreeVersion(view, this);

View file

@ -1171,6 +1171,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment
IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText, IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText,
iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE); iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
getDownloadActivity().addToDownload(ii); getDownloadActivity().addToDownload(ii);
getDownloadActivity().downloadFilesCheckFreeVersion();
getDownloadActivity().updateFragments(); getDownloadActivity().updateFragments();
} }
} }