Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexzatsepin <az@mapswithme.com>2017-01-31 17:27:29 +0300
committerAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2017-01-31 19:56:19 +0300
commit5017b013e9ec91a8e55d3dd862f5f5870d3e7f0e (patch)
treed14297a59585d9dabcb46995935a5a810a9d3b33
parent8efd71f46bfe8983990a44eeae23108fefde1fab (diff)
[android] Moved the loggin settings from the core settings to the android shared preference to avoid problem with core initializationbeta-602
-rw-r--r--android/src/com/mapswithme/maps/MwmApplication.java22
-rw-r--r--android/src/com/mapswithme/maps/search/SearchFragment.java4
-rw-r--r--android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java8
-rw-r--r--android/src/com/mapswithme/util/Config.java12
-rw-r--r--android/src/com/mapswithme/util/LocationUtils.java4
-rw-r--r--android/src/com/mapswithme/util/log/LoggerFactory.java28
6 files changed, 46 insertions, 32 deletions
diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java
index 5a0ee10837..22c2a3654e 100644
--- a/android/src/com/mapswithme/maps/MwmApplication.java
+++ b/android/src/com/mapswithme/maps/MwmApplication.java
@@ -7,6 +7,7 @@ import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import android.text.TextUtils;
@@ -43,7 +44,7 @@ import net.hockeyapp.android.CrashManager;
public class MwmApplication extends Application
{
- private static Logger sLogger;
+ private Logger mLogger;
private final static String TAG = "MwmApplication";
private static final String PW_EMPTY_APP_ID = "XXXXX";
@@ -98,8 +99,11 @@ public class MwmApplication extends Application
return sSelf.mBackgroundTracker;
}
- public static SharedPreferences prefs()
+ public synchronized static SharedPreferences prefs()
{
+ if (sSelf.mPrefs == null)
+ sSelf.mPrefs = sSelf.getSharedPreferences(sSelf.getString(R.string.pref_file_name), MODE_PRIVATE);
+
return sSelf.mPrefs;
}
@@ -113,7 +117,8 @@ public class MwmApplication extends Application
public void onCreate()
{
super.onCreate();
- sLogger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
+ mLogger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
+ mLogger.d(TAG, "Application is created");
mMainLoopHandler = new Handler(getMainLooper());
initHockeyApp();
@@ -126,9 +131,9 @@ public class MwmApplication extends Application
initTracker();
String settingsPath = getSettingsPath();
- sLogger.d(TAG, "onCreate(), setting path = " + settingsPath);
+ mLogger.d(TAG, "onCreate(), setting path = " + settingsPath);
String tempPath = getTempPath();
- sLogger.d(TAG, "onCreate(), temp path = " + tempPath);
+ mLogger.d(TAG, "onCreate(), temp path = " + tempPath);
new File(settingsPath).mkdirs();
new File(tempPath).mkdirs();
@@ -142,7 +147,6 @@ public class MwmApplication extends Application
if (!isInstallationIdFound)
setInstallationIdToCrashlytics();
- mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
mBackgroundTracker = new AppBackgroundTracker();
TrackRecorder.init();
Editor.init();
@@ -237,7 +241,7 @@ public class MwmApplication extends Application
return getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0).sourceDir;
} catch (final NameNotFoundException e)
{
- sLogger.e(TAG, "Can't get apk path from PackageManager", e);
+ mLogger.e(TAG, "Can't get apk path from PackageManager", e);
return "";
}
}
@@ -302,7 +306,7 @@ public class MwmApplication extends Application
}
catch(Exception e)
{
- sLogger.e("Pushwoosh", "Failed to init Pushwoosh", e);
+ mLogger.e("Pushwoosh", "Failed to init Pushwoosh", e);
}
}
@@ -318,7 +322,7 @@ public class MwmApplication extends Application
}
catch(Exception e)
{
- sLogger.e("Pushwoosh", "Failed to send pushwoosh tags", e);
+ mLogger.e("Pushwoosh", "Failed to send pushwoosh tags", e);
}
}
diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java
index ba82ff5bdf..3d05f99c83 100644
--- a/android/src/com/mapswithme/maps/search/SearchFragment.java
+++ b/android/src/com/mapswithme/maps/search/SearchFragment.java
@@ -34,9 +34,9 @@ import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.widget.PlaceholderView;
import com.mapswithme.maps.widget.SearchToolbarController;
import com.mapswithme.util.Animations;
-import com.mapswithme.util.Config;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
+import com.mapswithme.util.log.LoggerFactory;
import com.mapswithme.util.statistics.Statistics;
import java.util.ArrayList;
@@ -469,7 +469,7 @@ public class SearchFragment extends BaseMwmFragment
if (str.equals("?disableLogging"))
{
- Config.setLoggingEnabled(false);
+ LoggerFactory.INSTANCE.setFileLoggingEnabled(false);
MwmApplication.prefs().edit().putBoolean(PREFS_SHOW_ENABLE_LOGGING_SETTING, false).apply();
return true;
}
diff --git a/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java b/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java
index 455dad0439..26a45a6906 100644
--- a/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java
+++ b/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java
@@ -11,6 +11,7 @@ import com.mapswithme.maps.R;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.search.SearchFragment;
import com.mapswithme.util.Config;
+import com.mapswithme.util.log.LoggerFactory;
import com.mapswithme.util.statistics.MytargetHelper;
import com.mapswithme.util.statistics.Statistics;
@@ -73,17 +74,18 @@ public class MiscPrefsFragment extends BaseXmlSettingsFragment
}
else
{
- ((TwoStatePreference) pref).setChecked(Config.isLoggingEnabled());
+ final boolean isLoggingEnabled = LoggerFactory.INSTANCE.isFileLoggingEnabled();
+ ((TwoStatePreference) pref).setChecked(isLoggingEnabled);
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
- boolean oldVal = Config.isLoggingEnabled();
+ boolean oldVal = isLoggingEnabled;
boolean newVal = (Boolean) newValue;
if (oldVal != newVal)
{
- Config.setLoggingEnabled((Boolean) newValue);
+ LoggerFactory.INSTANCE.setFileLoggingEnabled((Boolean) newValue);
}
return true;
}
diff --git a/android/src/com/mapswithme/util/Config.java b/android/src/com/mapswithme/util/Config.java
index f13e79500b..7ae904bcdc 100644
--- a/android/src/com/mapswithme/util/Config.java
+++ b/android/src/com/mapswithme/util/Config.java
@@ -34,7 +34,6 @@ public final class Config
private static final String KEY_MISC_FIRST_START_DIALOG_SEEN = "FirstStartDialogSeen";
private static final String KEY_MISC_UI_THEME = "UiTheme";
private static final String KEY_MISC_UI_THEME_SETTINGS = "UiThemeSettings";
- private static final String KEY_MISC_LOGGING_ENABLED = "LoggingEnabled";
private Config() {}
@@ -310,17 +309,6 @@ public final class Config
setBool(KEY_MISC_FIRST_START_DIALOG_SEEN);
}
- public static void setLoggingEnabled(boolean enabled)
- {
- setBool(KEY_MISC_LOGGING_ENABLED, enabled);
- LoggerFactory.INSTANCE.updateLoggers();
- }
-
- public static boolean isLoggingEnabled()
- {
- return getBool(KEY_MISC_LOGGING_ENABLED, false);
- }
-
public static String getCurrentUiTheme()
{
String res = getString(KEY_MISC_UI_THEME, ThemeUtils.THEME_DEFAULT);
diff --git a/android/src/com/mapswithme/util/LocationUtils.java b/android/src/com/mapswithme/util/LocationUtils.java
index ad8f7262f5..950ef3e46b 100644
--- a/android/src/com/mapswithme/util/LocationUtils.java
+++ b/android/src/com/mapswithme/util/LocationUtils.java
@@ -126,9 +126,9 @@ public class LocationUtils
StringBuilder sb;
if (!providers.isEmpty())
{
- sb = new StringBuilder("Available location providers: ");
+ sb = new StringBuilder("Available location providers:");
for (String provider : providers)
- sb.append(provider).append(" ");
+ sb.append(" ").append(provider);
}
else
{
diff --git a/android/src/com/mapswithme/util/log/LoggerFactory.java b/android/src/com/mapswithme/util/log/LoggerFactory.java
index 3629347695..54a3a422ef 100644
--- a/android/src/com/mapswithme/util/log/LoggerFactory.java
+++ b/android/src/com/mapswithme/util/log/LoggerFactory.java
@@ -1,10 +1,11 @@
package com.mapswithme.util.log;
+import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
-import com.mapswithme.util.Config;
+import com.mapswithme.maps.MwmApplication;
import com.mapswithme.util.StorageUtils;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
@@ -35,6 +36,7 @@ public class LoggerFactory
}
public final static LoggerFactory INSTANCE = new LoggerFactory();
+ private final static String PREF_FILE_LOGGING_ENABLED = "FileLoggingEnabled";
@NonNull
@GuardedBy("this")
@@ -47,6 +49,23 @@ public class LoggerFactory
{
}
+ public boolean isFileLoggingEnabled()
+ {
+ SharedPreferences prefs = MwmApplication.prefs();
+ return prefs.getBoolean(PREF_FILE_LOGGING_ENABLED, false);
+ }
+
+ public void setFileLoggingEnabled(boolean enabled)
+ {
+ if (isFileLoggingEnabled() == enabled)
+ return;
+
+ SharedPreferences prefs = MwmApplication.prefs();
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean(PREF_FILE_LOGGING_ENABLED, enabled).apply();
+ updateLoggers();
+ }
+
@NonNull
public synchronized Logger getLogger(@NonNull Type type)
{
@@ -59,7 +78,7 @@ public class LoggerFactory
return logger;
}
- public synchronized void updateLoggers()
+ private synchronized void updateLoggers()
{
for (Type type: mLoggers.keySet())
{
@@ -70,7 +89,7 @@ public class LoggerFactory
public synchronized void zipLogs(@Nullable OnZipCompletedListener listener)
{
- if (!Config.isLoggingEnabled())
+ if (!isFileLoggingEnabled())
{
if (listener != null)
listener.onCompleted(false);
@@ -100,7 +119,8 @@ public class LoggerFactory
@NonNull
private LoggerStrategy createLoggerStrategy(@NonNull Type type)
{
- if (Config.isLoggingEnabled())
+ SharedPreferences prefs = MwmApplication.prefs();
+ if (prefs.getBoolean(PREF_FILE_LOGGING_ENABLED, false))
{
String logsFolder = StorageUtils.getLogsFolder();
if (!TextUtils.isEmpty(logsFolder))