Update progress
This commit is contained in:
parent
cbc3cd5602
commit
bb264fb38a
3 changed files with 67 additions and 38 deletions
|
@ -26,5 +26,32 @@ public interface IProgress {
|
|||
public boolean isIndeterminate();
|
||||
|
||||
public boolean isInterrupted();
|
||||
|
||||
public IProgress EMPTY_PROGRESS = new IProgress() {
|
||||
|
||||
@Override
|
||||
public void startWork(int work) {}
|
||||
|
||||
@Override
|
||||
public void startTask(String taskName, int work) {}
|
||||
|
||||
@Override
|
||||
public void setGeneralProgress(String genProgress) {}
|
||||
|
||||
@Override
|
||||
public void remaining(int remainingWork) {}
|
||||
|
||||
@Override
|
||||
public void progress(int deltaWork) {}
|
||||
|
||||
@Override
|
||||
public boolean isInterrupted() {return false;}
|
||||
|
||||
@Override
|
||||
public boolean isIndeterminate() {return false;}
|
||||
|
||||
@Override
|
||||
public void finishTask() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<string name="local_index_mi_delete">Delete</string>
|
||||
<string name="local_index_mi_reload">Reload</string>
|
||||
<string name="local_index_download">Download</string>
|
||||
<string name="local_index_tile_data">Tile data %1$s - minimum zoom %2$d, maximum zoom %3$d</string>
|
||||
<string name="local_index_tile_data">Tile data: \n %1$s - minimum zoom \n %2$d, maximum zoom %3$d</string>
|
||||
<string name="local_index_poi_data">POI data</string>
|
||||
<string name="local_index_address_data">Address data</string>
|
||||
<string name="local_index_transport_data">Transport data</string>
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.ProgressDialogImplementation;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -45,7 +46,6 @@ public class LocalIndexesActivity extends ExpandableListActivity {
|
|||
|
||||
private AsyncTask<Activity, LocalIndexInfo, List<LocalIndexInfo>> asyncLoader;
|
||||
private LocalIndexesAdapter listAdapter;
|
||||
private ProgressDialog progressDlg;
|
||||
private LoadLocalIndexDescriptionTask descriptionLoader;
|
||||
private LocalIndexOperationTask operationTask;
|
||||
|
||||
|
@ -151,6 +151,9 @@ public class LocalIndexesActivity extends ExpandableListActivity {
|
|||
}
|
||||
|
||||
private boolean move(File from, File to){
|
||||
if(!to.getParentFile().exists()){
|
||||
to.getParentFile().mkdirs();
|
||||
}
|
||||
return from.renameTo(to);
|
||||
}
|
||||
|
||||
|
@ -254,6 +257,9 @@ public class LocalIndexesActivity extends ExpandableListActivity {
|
|||
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
||||
descriptionLoader.execute(item);
|
||||
}
|
||||
if(selectionMode){
|
||||
selectedItems.add(item);
|
||||
}
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
return true;
|
||||
}
|
||||
|
@ -269,10 +275,6 @@ public class LocalIndexesActivity extends ExpandableListActivity {
|
|||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (progressDlg != null) {
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
asyncLoader.cancel(true);
|
||||
descriptionLoader.cancel(true);
|
||||
}
|
||||
|
@ -401,43 +403,43 @@ public class LocalIndexesActivity extends ExpandableListActivity {
|
|||
|
||||
|
||||
public void reloadIndexes() {
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
|
||||
impl.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
showWarnings(((OsmandApplication) getApplication()).getResourceManager().reloadIndexes(impl));
|
||||
} finally {
|
||||
if (progressDlg != null) {
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
AsyncTask<Void, String, List<String>> task = new AsyncTask<Void, String, List<String>>(){
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<String> warnings) {
|
||||
findViewById(R.id.ProgressBar).setVisibility(View.INVISIBLE);
|
||||
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);
|
||||
}
|
||||
});
|
||||
impl.run();
|
||||
Toast.makeText(LocalIndexesActivity.this, b.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
findViewById(R.id.ProgressBar).setVisibility(View.VISIBLE);
|
||||
}
|
||||
@Override
|
||||
protected List<String> doInBackground(Void... params) {
|
||||
return ((OsmandApplication) getApplication()).getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS);
|
||||
}
|
||||
|
||||
};
|
||||
task.execute();
|
||||
|
||||
}
|
||||
|
||||
protected void showWarnings(List<String> warnings) {
|
||||
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);
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(LocalIndexesActivity.this, b.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue