forked from organicmaps/organicmaps
[android] Refactored method names, removed obsolete bookmark migration.
(cherry picked from commit 38b0ff0)
This commit is contained in:
parent
9f3c0de908
commit
5b168909d2
6 changed files with 35 additions and 183 deletions
|
@ -34,7 +34,7 @@ extern "C"
|
|||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_MwmApplication_hasFreeSpace(JNIEnv * env, jobject thiz, jlong size)
|
||||
Java_com_mapswithme_maps_MwmApplication_nativeHasFreeSpace(JNIEnv * env, jobject thiz, jlong size)
|
||||
{
|
||||
return android::Platform::Instance().HasAvailableSpaceForWriting(size);
|
||||
}
|
||||
|
|
|
@ -117,11 +117,8 @@ public class MwmApplication extends Application
|
|||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private void initPaths()
|
||||
{
|
||||
final String extStoragePath = getDataStoragePath();
|
||||
final String extTmpPath = getTempPath();
|
||||
|
||||
new File(extStoragePath).mkdirs();
|
||||
new File(extTmpPath).mkdirs();
|
||||
new File(getDataStoragePath()).mkdirs();
|
||||
new File(getTempPath()).mkdirs();
|
||||
}
|
||||
|
||||
private void initNativeStrings()
|
||||
|
@ -197,11 +194,6 @@ public class MwmApplication extends Application
|
|||
|
||||
private native void nativeAddLocalization(String name, String value);
|
||||
|
||||
/**
|
||||
* Check if device have at least {@code size} bytes free.
|
||||
*/
|
||||
public native boolean hasFreeSpace(long size);
|
||||
|
||||
/*
|
||||
* init Parse SDK
|
||||
*/
|
||||
|
|
|
@ -5,16 +5,17 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.google.android.gms.plus.PlusOneButton;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class GooglePlusDialogFragment extends DialogFragment
|
||||
public class GooglePlusDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,19 +8,17 @@ import android.os.Environment;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MapStorage;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
@ -62,7 +60,6 @@ public class StoragePathManager
|
|||
|
||||
static final String TAG = StoragePathManager.class.getName();
|
||||
|
||||
|
||||
private OnStorageListChangedListener mStoragesChangedListener;
|
||||
private MoveFilesListener mMoveFilesListener;
|
||||
|
||||
|
@ -193,76 +190,6 @@ public class StoragePathManager
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public boolean moveBookmarksToPrimaryStorage()
|
||||
{
|
||||
ArrayList<String> paths = new ArrayList<>();
|
||||
StorageUtils.parseStorages(paths);
|
||||
|
||||
List<String> approvedPaths = new ArrayList<>();
|
||||
for (String path : paths)
|
||||
{
|
||||
String mwmPath = path + Constants.MWM_DIR_POSTFIX;
|
||||
File f = new File(mwmPath);
|
||||
if (f.exists() || f.canRead() || f.isDirectory())
|
||||
approvedPaths.add(mwmPath);
|
||||
}
|
||||
final String settingsDir = Framework.nativeGetSettingsDir();
|
||||
final String writableDir = Framework.nativeGetWritableDir();
|
||||
final String bookmarkDir = Framework.nativeGetBookmarkDir();
|
||||
final String bookmarkFileExt = Framework.nativeGetBookmarksExt();
|
||||
|
||||
Set<File> bookmarks = new LinkedHashSet<>();
|
||||
if (!settingsDir.equals(writableDir))
|
||||
approvedPaths.add(writableDir);
|
||||
|
||||
for (String path : approvedPaths)
|
||||
{
|
||||
if (!path.equals(settingsDir))
|
||||
accumulateFiles(path, bookmarkFileExt, bookmarks);
|
||||
}
|
||||
|
||||
long bookmarksSize = 0;
|
||||
for (File f : bookmarks)
|
||||
bookmarksSize += f.length();
|
||||
|
||||
if (StorageUtils.getFreeBytesAtPath(bookmarkDir) < bookmarksSize)
|
||||
return false;
|
||||
|
||||
for (File oldBookmark : bookmarks)
|
||||
{
|
||||
String newBookmarkPath = BookmarkManager.generateUniqueBookmarkName(oldBookmark.getName().replace(bookmarkFileExt, ""));
|
||||
try
|
||||
{
|
||||
StorageUtils.copyFile(oldBookmark, new File(newBookmarkPath));
|
||||
oldBookmark.delete();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Framework.nativeLoadBookmarks();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void accumulateFiles(final String dirPath, final String filesExtension, Set<File> result)
|
||||
{
|
||||
File f = new File(dirPath);
|
||||
File[] bookmarks = f.listFiles(new FileFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File pathname)
|
||||
{
|
||||
return pathname.getName().endsWith(filesExtension);
|
||||
}
|
||||
});
|
||||
|
||||
result.addAll(Arrays.asList(bookmarks));
|
||||
}
|
||||
|
||||
protected void changeStorage(int newIndex)
|
||||
{
|
||||
final StorageItem oldItem = (mCurrentStorageIndex != -1) ? mItems.get(mCurrentStorageIndex) : null;
|
||||
|
@ -320,12 +247,36 @@ public class StoragePathManager
|
|||
* Checks whether current directory is actually writable on Kitkat devices. On earlier versions of android ( < 4.4 ) the root of external
|
||||
* storages was writable, but on Kitkat it isn't, so we should move our maps to other directory.
|
||||
* http://www.doubleencore.com/2014/03/android-external-storage/ check that link for explanations
|
||||
* <p/>
|
||||
* TODO : use SAF framework to allow custom sdcard folder selections on Lollipop+ devices.
|
||||
* https://developer.android.com/guide/topics/providers/document-provider.html#client
|
||||
* https://code.google.com/p/android/issues/detail?id=103249
|
||||
*/
|
||||
public void checkExternalStoragePathOnKitkat(Context context, MoveFilesListener listener)
|
||||
public void checkKitkatMigration(final Activity activity)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT ||
|
||||
Config.isKitKatMigrationComplete())
|
||||
return;
|
||||
|
||||
checkExternalStoragePathOnKitkat(activity, new MoveFilesListener()
|
||||
{
|
||||
@Override
|
||||
public void moveFilesFinished(String newPath)
|
||||
{
|
||||
Config.setKitKatMigrationComplete();
|
||||
UiUtils.showAlertDialog(activity, R.string.kitkat_migrate_ok);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveFilesFailed(int errorCode)
|
||||
{
|
||||
UiUtils.showAlertDialog(activity, R.string.kitkat_migrate_failed);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkExternalStoragePathOnKitkat(Context context, MoveFilesListener listener)
|
||||
{
|
||||
final String settingsDir = Framework.nativeGetSettingsDir();
|
||||
final String writableDir = Framework.nativeGetWritableDir();
|
||||
|
||||
|
@ -347,87 +298,6 @@ public class StoragePathManager
|
|||
listener.moveFilesFailed(UNKNOWN_KITKAT_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks bookmarks and data(mwms, routing, indexes etc) locations on external storages.
|
||||
* <p/>
|
||||
* Bookmarks should be placed in main MapsWithMe directory on primary storage (eg. SettingsDir, where settings.ini file is placed). If they were copied
|
||||
* to external storage (can happen on 2.6 and earlier mapswithme application versions) - we should move them back.
|
||||
* <p/>
|
||||
* Data should be placed in private app directory on Kitkat+ devices, hence root of sdcard isn't writable anymore there.
|
||||
*/
|
||||
public void checkKitkatMigration(final Activity activity)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
|
||||
return;
|
||||
|
||||
migrateBookmarks(new MoveFilesListener()
|
||||
{
|
||||
@Override
|
||||
public void moveFilesFinished(String newPath)
|
||||
{
|
||||
migrateMaps(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveFilesFailed(int errorCode)
|
||||
{
|
||||
UiUtils.showAlertDialog(activity, R.string.bookmark_move_fail);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void migrateBookmarks(final MoveFilesListener listener)
|
||||
{
|
||||
if (Config.isKmlMoved())
|
||||
listener.moveFilesFinished("");
|
||||
else
|
||||
ThreadPool.getStorage().execute(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final boolean res = moveBookmarksToPrimaryStorage();
|
||||
|
||||
UiThread.run(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (res)
|
||||
{
|
||||
Config.setKmlMoved();
|
||||
listener.moveFilesFinished("");
|
||||
}
|
||||
else
|
||||
listener.moveFilesFailed(NULL_ERROR);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void migrateMaps(final Activity activity)
|
||||
{
|
||||
if (Config.isKitKatMigrationComplete())
|
||||
return;
|
||||
|
||||
checkExternalStoragePathOnKitkat(activity, new MoveFilesListener()
|
||||
{
|
||||
@Override
|
||||
public void moveFilesFinished(String newPath)
|
||||
{
|
||||
Config.setKitKatMigrationComplete();
|
||||
UiUtils.showAlertDialog(activity, R.string.kitkat_migrate_ok);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveFilesFailed(int errorCode)
|
||||
{
|
||||
UiUtils.showAlertDialog(activity, R.string.kitkat_migrate_failed);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setStoragePath(final Context context, final MoveFilesListener listener, final StorageItem newStorage,
|
||||
final StorageItem oldStorage, final int messageId)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Dialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -12,13 +11,14 @@ import android.widget.AdapterView;
|
|||
import android.widget.GridView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.maps.bookmarks.IconsAdapter;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.Icon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BookmarkColorDialogFragment extends DialogFragment
|
||||
public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
public static final String ICON_TYPE = "ExtraIconType";
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ public final class Config
|
|||
private static final String KEY_LIKES_LAST_RATED_SESSION = "LastRatedSession";
|
||||
|
||||
private static final String KEY_MISC_DISCLAIMER_ACCEPTED = "IsDisclaimerApproved";
|
||||
private static final String KEY_MISC_KML_MOVED = "KmlBeenMoved";
|
||||
private static final String KEY_MISC_KITKAT_MIGRATED = "KitKatMigrationCompleted";
|
||||
private static final String KEY_MISC_NEWS_LAST_VERSION = "WhatsNewShownVersion";
|
||||
|
||||
|
@ -241,16 +240,6 @@ public final class Config
|
|||
setBool(KEY_MISC_DISCLAIMER_ACCEPTED, true);
|
||||
}
|
||||
|
||||
public static boolean isKmlMoved()
|
||||
{
|
||||
return getBool(KEY_MISC_KML_MOVED);
|
||||
}
|
||||
|
||||
public static void setKmlMoved()
|
||||
{
|
||||
setBool(KEY_MISC_KML_MOVED);
|
||||
}
|
||||
|
||||
public static boolean isKitKatMigrationComplete()
|
||||
{
|
||||
return getBool(KEY_MISC_KITKAT_MIGRATED);
|
||||
|
|
Loading…
Add table
Reference in a new issue