From af81ddfaa69e997c81ed9713cf6c5eb8632c0e59 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 18 Sep 2014 18:15:49 +0300 Subject: [PATCH] Fixed bug when select storage dialog not shows on first start of application --- .../plus/download/DownloadActivity.java | 71 +++++++++++++++++++ .../plus/download/DownloadIndexFragment.java | 64 ----------------- 2 files changed, 71 insertions(+), 64 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 5106250936..0cf6e1ca08 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; @@ -14,11 +15,16 @@ import android.widget.*; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Window; +import net.osmand.IndexConstants; +import net.osmand.access.AccessibleAlertBuilder; import net.osmand.plus.*; import net.osmand.plus.activities.FavouritesActivity; +import net.osmand.plus.activities.SettingsGeneralActivity; import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.srtmplugin.SRTMPlugin; +import java.io.File; import java.text.MessageFormat; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -127,6 +133,53 @@ public class DownloadActivity extends SherlockFragmentActivity { } } + if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) { + boolean showedDialog = false; + if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { + SuggestExternalDirectoryDialog.showDialog(this, null, null); + } + if(!showedDialog) { + showDialogOfFreeDownloadsIfNeeded(); + } + } else { + showDialogOfFreeDownloadsIfNeeded(); + } + + + if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { + final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath(); + String primaryStorage = settings.getDefaultExternalStorageLocation(); + if (!currentStorage.startsWith(primaryStorage)) { + // secondary storage + boolean currentDirectoryNotWritable = true; + for (String writeableDirectory : settings.getWritableSecondaryStorageDirectorys()) { + if (currentStorage.startsWith(writeableDirectory)) { + currentDirectoryNotWritable = false; + break; + } + } + if (currentDirectoryNotWritable) { + currentDirectoryNotWritable = !OsmandSettings.isWritable(settings.getExternalStorageDirectory()); + } + if (currentDirectoryNotWritable) { + final String newLoc = settings.getMatchingExternalFilesDir(currentStorage); + if (newLoc != null && newLoc.length() != 0) { + AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this); + ab.setMessage(getString(R.string.android_19_location_disabled, + settings.getExternalStorageDirectory())); + ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + copyFilesForAndroid19(newLoc); + } + }); + ab.setNegativeButton(R.string.default_buttons_cancel, null); + ab.show(); + } + } + } + } + getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @@ -387,4 +440,22 @@ public class DownloadActivity extends SherlockFragmentActivity { return ((OsmandApplication) getApplication()).getSettings().isLightActionBar(); } + private void copyFilesForAndroid19(final String newLoc) { + SettingsGeneralActivity.MoveFilesToDifferentDirectory task = + new SettingsGeneralActivity.MoveFilesToDifferentDirectory(this, + new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR), + new File(newLoc, IndexConstants.APP_DIR)) { + protected Boolean doInBackground(Void[] params) { + Boolean result = super.doInBackground(params); + if(result) { + settings.setExternalStorageDirectory(newLoc); + getMyApplication().getResourceManager().resetStoreDirectory(); + getMyApplication().getResourceManager().reloadIndexes(progress) ; + } + return result; + }; + }; + task.execute(); + } + } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java index 3a3549edf7..76b0218898 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexFragment.java @@ -105,70 +105,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment { settings = getMyApplication().getSettings(); - if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) { - boolean showedDialog = false; - if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { - SuggestExternalDirectoryDialog.showDialog(getActivity(), null, null); - } - if(!showedDialog) { - getDownloadActivity().showDialogOfFreeDownloadsIfNeeded(); - } - } else { - getDownloadActivity().showDialogOfFreeDownloadsIfNeeded(); - } - - - if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { - final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath(); - String primaryStorage = settings.getDefaultExternalStorageLocation(); - if (!currentStorage.startsWith(primaryStorage)) { - // secondary storage - boolean currentDirectoryNotWritable = true; - for (String writeableDirectory : settings.getWritableSecondaryStorageDirectorys()) { - if (currentStorage.startsWith(writeableDirectory)) { - currentDirectoryNotWritable = false; - break; - } - } - if (currentDirectoryNotWritable) { - currentDirectoryNotWritable = !OsmandSettings.isWritable(settings.getExternalStorageDirectory()); - } - if (currentDirectoryNotWritable) { - final String newLoc = settings.getMatchingExternalFilesDir(currentStorage); - if (newLoc != null && newLoc.length() != 0) { - AccessibleAlertBuilder ab = new AccessibleAlertBuilder(getDownloadActivity()); - ab.setMessage(getString(R.string.android_19_location_disabled, - settings.getExternalStorageDirectory())); - ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - copyFilesForAndroid19(newLoc); - } - }); - ab.setNegativeButton(R.string.default_buttons_cancel, null); - ab.show(); - } - } - } - } - } - - private void copyFilesForAndroid19(final String newLoc) { - MoveFilesToDifferentDirectory task = - new MoveFilesToDifferentDirectory(getDownloadActivity(), - new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR), - new File(newLoc, IndexConstants.APP_DIR)) { - protected Boolean doInBackground(Void[] params) { - Boolean result = super.doInBackground(params); - if(result) { - settings.setExternalStorageDirectory(newLoc); - getMyApplication().getResourceManager().resetStoreDirectory(); - getMyApplication().getResourceManager().reloadIndexes(progress) ; - } - return result; - }; - }; - task.execute(); } @Override