Update process now will be visible for Dashboard even if it was started at downloads activity
This commit is contained in:
parent
284e6953c8
commit
f3a95c842b
6 changed files with 153 additions and 27 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.dashboard;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -10,6 +11,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||
import net.osmand.plus.download.BaseDownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadEntry;
|
||||
|
@ -22,6 +24,11 @@ import java.util.List;
|
|||
* Created by Denis on 21.11.2014.
|
||||
*/
|
||||
public class DashUpdatesFragment extends DashBaseFragment {
|
||||
private ProgressBar currentProgress;
|
||||
private List<ProgressBar> progressBars = new ArrayList<ProgressBar>();
|
||||
private List<String> baseNames = new ArrayList<String>();
|
||||
private List<View> downloadButtons = new ArrayList<View>();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_updates_fragment, container, false);
|
||||
|
@ -55,6 +62,9 @@ public class DashUpdatesFragment extends DashBaseFragment {
|
|||
if (mainView == null) {
|
||||
return;
|
||||
}
|
||||
progressBars.clear();
|
||||
baseNames.clear();
|
||||
downloadButtons.clear();
|
||||
if (list.size() > 0) {
|
||||
mainView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
@ -80,17 +90,63 @@ public class DashUpdatesFragment extends DashBaseFragment {
|
|||
((TextView) view.findViewById(R.id.map_name)).setText(eName);
|
||||
((TextView) view.findViewById(R.id.map_descr)).setText(d);
|
||||
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.ProgressBar);
|
||||
(view.findViewById(R.id.btn_download)).setOnClickListener(new View.OnClickListener() {
|
||||
View downloadButton = (view.findViewById(R.id.btn_download));
|
||||
downloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getDownloadActivity().startDownload(progressBar, item);
|
||||
getDownloadActivity().startDownload(item);
|
||||
currentProgress = progressBar;
|
||||
}
|
||||
});
|
||||
downloadButtons.add(downloadButton);
|
||||
baseNames.add(item.getBasename());
|
||||
progressBars.add(progressBar);
|
||||
updates.addView(view);
|
||||
}
|
||||
updateProgress(BaseDownloadActivity.downloadListIndexThread.getCurrentRunningTask(), true);
|
||||
}
|
||||
|
||||
private BaseDownloadActivity getDownloadActivity(){
|
||||
return (BaseDownloadActivity)getActivity();
|
||||
}
|
||||
|
||||
public void updateProgress(BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask, boolean updateOnlyProgress) {
|
||||
if (basicProgressAsyncTask == null){
|
||||
return;
|
||||
}
|
||||
//needed when rotation is performed and progress can be null
|
||||
if (currentProgress == null){
|
||||
getProgressIfPossible(basicProgressAsyncTask.getDescription());
|
||||
if (currentProgress == null){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(updateOnlyProgress){
|
||||
if(!basicProgressAsyncTask.isIndeterminate()){
|
||||
currentProgress.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
} else {
|
||||
boolean visible = basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != AsyncTask.Status.FINISHED;
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean intermediate = basicProgressAsyncTask.isIndeterminate();
|
||||
currentProgress.setVisibility(intermediate ? View.GONE : View.VISIBLE);
|
||||
if (!intermediate) {
|
||||
currentProgress.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getProgressIfPossible(String message) {
|
||||
for (int i =0; i<baseNames.size(); i++){
|
||||
if (message.equals(getActivity().getString(R.string.downloading_file_new) + " " + baseNames.get(i))){
|
||||
currentProgress = progressBars.get(i);
|
||||
currentProgress.setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
package net.osmand.plus.dashboard;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.SpannableString;
|
||||
|
@ -20,6 +26,7 @@ import android.widget.*;
|
|||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.*;
|
||||
|
@ -29,7 +36,9 @@ import net.osmand.plus.base.FavoriteImageDrawable;
|
|||
import net.osmand.plus.download.*;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +47,7 @@ import java.util.*;
|
|||
public class DashboardActivity extends BaseDownloadActivity {
|
||||
|
||||
private static final String CONTRIBUTION_VERSION_FLAG = "CONTRIBUTION_VERSION_FLAG";
|
||||
private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$
|
||||
|
||||
public static final boolean TIPS_AND_TRICKS = false;
|
||||
|
||||
|
@ -141,28 +151,21 @@ public class DashboardActivity extends BaseDownloadActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
downloadListIndexThread.resetUiActivity(DashboardActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
//needed when rotation is performed and progress can be null
|
||||
if (progressBar == null){
|
||||
return;
|
||||
}
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = BaseDownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
|
||||
if(updateOnlyProgress){
|
||||
if(!basicProgressAsyncTask.isIndeterminate()){
|
||||
progressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
} else {
|
||||
boolean visible = basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != AsyncTask.Status.FINISHED;
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean intermediate = basicProgressAsyncTask.isIndeterminate();
|
||||
progressBar.setVisibility(intermediate ? View.GONE : View.VISIBLE);
|
||||
if (!intermediate) {
|
||||
progressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
for(WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if(f instanceof DashUpdatesFragment) {
|
||||
if(!f.isDetached()) {
|
||||
((DashUpdatesFragment) f).updateProgress(basicProgressAsyncTask, updateOnlyProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,4 +174,51 @@ public class DashboardActivity extends BaseDownloadActivity {
|
|||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkPreviousRunsForExceptions(boolean firstTime) {
|
||||
long size = getPreferences(MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0);
|
||||
final OsmandApplication app = ((OsmandApplication) getApplication());
|
||||
final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
if (size != file.length() && !firstTime) {
|
||||
String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH);
|
||||
AlertDialog.Builder builder = new AccessibleAlertBuilder(DashboardActivity.this);
|
||||
builder.setMessage(msg).setNeutralButton(getString(R.string.close), null);
|
||||
builder.setPositiveButton(R.string.send_report, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "osmand.app+crash@gmail.com" }); //$NON-NLS-1$
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
||||
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "OsmAnd bug"); //$NON-NLS-1$
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append("\nDevice : ").append(Build.DEVICE); //$NON-NLS-1$
|
||||
text.append("\nBrand : ").append(Build.BRAND); //$NON-NLS-1$
|
||||
text.append("\nModel : ").append(Build.MODEL); //$NON-NLS-1$
|
||||
text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$
|
||||
text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$
|
||||
text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$
|
||||
text.append("\nApp Version : ").append(Version.getAppName(app)); //$NON-NLS-1$
|
||||
try {
|
||||
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
if (info != null) {
|
||||
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
}
|
||||
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
getPreferences(MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
|
||||
} else {
|
||||
if (size > 0) {
|
||||
getPreferences(MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
@ -27,7 +28,6 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
|
|||
protected OsmandSettings settings;
|
||||
public static DownloadIndexesThread downloadListIndexThread;
|
||||
protected List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
|
||||
protected ProgressBar progressBar;
|
||||
|
||||
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
||||
|
||||
|
@ -42,6 +42,12 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
|
|||
} else {
|
||||
downloadListIndexThread.runReloadIndexFiles();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
downloadListIndexThread.setUiActivity(this);
|
||||
}
|
||||
|
||||
|
@ -84,14 +90,13 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
|
|||
|
||||
}
|
||||
|
||||
public void startDownload(ProgressBar progressBar, IndexItem item){
|
||||
public void startDownload(IndexItem item){
|
||||
if (downloadListIndexThread.getCurrentRunningTask() != null){
|
||||
Toast.makeText(this, "Please wait before previous download is finished", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
List<DownloadEntry> download = item.createDownloadEntry(getMyApplication(), item.getType(), new ArrayList<DownloadEntry>());
|
||||
getEntriesToDownload().put(item, download);
|
||||
this.progressBar = progressBar;
|
||||
downloadFilesCheckFreeVersion();
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,12 @@ public class DownloadActivity extends BaseDownloadActivity {
|
|||
public static final String UPDATES_TAB = "updates";
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
BaseDownloadActivity.downloadListIndexThread.resetUiActivity(DownloadActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getMyApplication().applyTheme(this);
|
||||
|
|
|
@ -281,7 +281,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
|||
EditText filterText = (EditText) getView().findViewById(R.id.search_box);
|
||||
filterText.removeTextChangedListener(textWatcher);
|
||||
}
|
||||
DownloadActivity.downloadListIndexThread.setUiActivity(null);
|
||||
}
|
||||
|
||||
public List<String> toString(List<DownloadActivityType> t) {
|
||||
|
|
|
@ -72,7 +72,7 @@ public class DownloadIndexesThread {
|
|||
public void setUiActivity(BaseDownloadActivity uiActivity) {
|
||||
this.uiActivity = uiActivity;
|
||||
}
|
||||
|
||||
|
||||
public List<DownloadEntry> flattenDownloadEntries() {
|
||||
List<DownloadEntry> res = new ArrayList<DownloadEntry>();
|
||||
for(List<DownloadEntry> ens : getEntriesToDownload().values()) {
|
||||
|
@ -120,7 +120,17 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
public List<IndexItem> getItemsToUpdate() { return itemsToUpdate;}
|
||||
|
||||
|
||||
public void resetUiActivity(Class<?> downloadActivityClass) {
|
||||
if (uiActivity== null){
|
||||
return;
|
||||
}
|
||||
|
||||
if (uiActivity.getClass().equals(downloadActivityClass)){
|
||||
uiActivity = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {
|
||||
|
||||
private OsmandPreference<Integer> downloads;
|
||||
|
|
Loading…
Reference in a new issue