This commit is contained in:
Victor Shcherb 2015-04-17 01:24:59 +02:00
parent 6e7a0b3426
commit 696e87f8aa
7 changed files with 67 additions and 44 deletions

View file

@ -96,7 +96,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
work = -1;
progress = 0;
if (taskName != null) {
message = ctx.getResources().getString(R.string.finished_task) + " : " + taskName; //$NON-NLS-1$
message = ctx.getResources().getString(R.string.finished_task) + ": " + taskName; //$NON-NLS-1$
updProgress(false);
}
}

View file

@ -105,7 +105,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
public void updateDownloadButton(boolean scroll) {
public void updateDownloadButton() {
}

View file

@ -1,18 +1,10 @@
package net.osmand.plus.download;
import android.app.AlertDialog;
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.view.ViewPager;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
@ -20,16 +12,29 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
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 java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import android.app.AlertDialog;
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.BaseAdapter;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
@ -230,7 +235,7 @@ public class DownloadActivity extends BaseDownloadActivity {
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
}
updateDownloadButton(false);
updateDownloadButton();
}
}
@ -292,7 +297,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
@Override
public void updateDownloadButton(boolean scroll) {
public void updateDownloadButton() {
// View view = getView();
// if (view == null || getExpandableListView() == null){
// return;
@ -314,7 +319,6 @@ public class DownloadActivity extends BaseDownloadActivity {
}
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
if (Version.isFreeVersion(getMyApplication())) {
int countedDownloads = DownloadActivity.downloadListIndexThread.getDownloads();
int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
boolean excessLimit = left < 0;
if (left < 0)
@ -325,6 +329,24 @@ public class DownloadActivity extends BaseDownloadActivity {
}
((Button) findViewById(R.id.DownloadButton)).setText(text);
}
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if (!f.isDetached()) {
if (f instanceof OsmandExpandableListFragment) {
ExpandableListAdapter ad = ((OsmandExpandableListFragment) f).getExpandableListView()
.getExpandableListAdapter();
if (ad instanceof OsmandBaseExpandableListAdapter) {
((OsmandBaseExpandableListAdapter) ad).notifyDataSetChanged();
}
} else if(f instanceof ListFragment) {
ListAdapter la = ((ListFragment) f).getListAdapter();
if(la instanceof BaseAdapter) {
((BaseAdapter) la).notifyDataSetChanged();
}
}
}
}
// if (scroll) {
// getExpandableListView().scrollTo(x, y);
// }

View file

@ -18,6 +18,7 @@ import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -257,7 +258,9 @@ public class DownloadFileHelper {
if(mb == 0) {
mb = 1;
}
String taskName = ctx.getString(R.string.shared_string_downloading) + " " + de.baseName /*+ " " + mb + " MB"*/;
String taskName = ctx.getString(R.string.shared_string_downloading) + " " +
//+ de.baseName /*+ " " + mb + " MB"*/;
FileNameTranslationHelper.getFileName(ctx, ctx.getRegions(), de.baseName);
progress.startTask(taskName, len / 1024);
if (!de.zipStream) {

View file

@ -8,24 +8,22 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.view.*;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.AdapterView;
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.CheckBox;
import android.widget.EditText;
@ -207,7 +205,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
AccessibleToast.makeText(getDownloadActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
listAdapter.notifyDataSetInvalidated();
if(selected > 0){
getDownloadActivity().updateDownloadButton(true);
getDownloadActivity().updateDownloadButton();
}
}
@ -221,7 +219,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if(ch.isChecked()){
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
getDownloadActivity().updateDownloadButton();
return true;
}
@ -230,7 +228,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
// if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
getDownloadActivity().updateDownloadButton();
ch.setChecked(!ch.isChecked());
}
return true;

View file

@ -151,7 +151,7 @@ public class DownloadIndexesThread {
if (o instanceof DownloadEntry) {
if (uiActivity != null) {
uiActivity.downloadListUpdated();
uiActivity.updateDownloadButton(false);
uiActivity.updateDownloadButton();
DownloadEntry item = (DownloadEntry)o;
String name = item.item.getBasename();
long count = dbHelper.getCount(name, DatabaseHelper.DOWNLOAD_ENTRY) + 1;
@ -166,7 +166,7 @@ public class DownloadIndexesThread {
entriesToDownload.remove(o);
if (uiActivity != null) {
uiActivity.downloadListUpdated();
uiActivity.updateDownloadButton(false);
uiActivity.updateDownloadButton();
IndexItem item = (IndexItem)o;
long count = dbHelper.getCount(item.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) + 1;

View file

@ -151,12 +151,12 @@ public class UpdatesIndexFragment extends ListFragment {
if (ch.isChecked()) {
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
getDownloadActivity().updateDownloadButton();
} else {
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
getDownloadActivity().updateDownloadButton();
ch.setChecked(!ch.isChecked());
}
}
@ -217,7 +217,7 @@ public class UpdatesIndexFragment extends ListFragment {
AccessibleToast.makeText(getDownloadActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
listAdapter.notifyDataSetInvalidated();
if (selected > 0) {
getDownloadActivity().updateDownloadButton(true);
getDownloadActivity().updateDownloadButton();
}
}