Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-22 10:29:15 +02:00
commit 7151522f37
5 changed files with 47 additions and 32 deletions

View file

@ -56,11 +56,8 @@ import btools.routingapp.BRouterServiceConnection;
public class AppInitializer implements IProgress { public class AppInitializer implements IProgress {
public static final boolean TIPS_AND_TRICKS = false; public static final boolean TIPS_AND_TRICKS = false;
private static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
protected static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$
protected static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$
private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$ private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$
private static final String VERSION_INSTALLED = "VERSION_INSTALLED"; //$NON-NLS-1$
private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$ private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$
public static final String LATEST_CHANGES_URL = "changes-2.1.html"; public static final String LATEST_CHANGES_URL = "changes-2.1.html";
@ -113,23 +110,19 @@ public class AppInitializer implements IProgress {
if(initSettings) { if(initSettings) {
return; return;
} }
SharedPreferences pref = activity.getPreferences(Context.MODE_WORLD_WRITEABLE); OsmandSettings settings = getSettings(activity);
if(!pref.contains(NUMBER_OF_STARTS)) { firstTime = settings.FIRST_TIME_APP_RUN.get();
pref.edit().putInt(NUMBER_OF_STARTS, 1).commit(); if (firstTime) {
} else { settings.FIRST_TIME_APP_RUN.set(false);
pref.edit().putInt(NUMBER_OF_STARTS, pref.getInt(NUMBER_OF_STARTS, 0) + 1).commit(); settings.VERSION_INSTALLED.set(Version.getFullVersion(app));
} } else if (!Version.getFullVersion(app).equals(settings.VERSION_INSTALLED.get())) {
if (!pref.contains(FIRST_INSTALLED)) { settings.VERSION_INSTALLED.set(Version.getFullVersion(app));
pref.edit().putLong(FIRST_INSTALLED, System.currentTimeMillis()).commit();
}
if (!pref.contains(FIRST_TIME_APP_RUN)) {
firstTime = true;
pref.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
pref.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
} else if (!Version.getFullVersion(app).equals(pref.getString(VERSION_INSTALLED, ""))) {
pref.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true; appVersionChanged = true;
} }
settings.NUMBER_OF_APPLICATION_STARTS.set(settings.NUMBER_OF_APPLICATION_STARTS.get() + 1);
if (settings.FIRST_INSTALLED_DATE.get() == -1) {
settings.FIRST_INSTALLED_DATE.set(System.currentTimeMillis());
}
initSettings = true; initSettings = true;
} }
@ -142,6 +135,16 @@ public class AppInitializer implements IProgress {
this.firstTime = firstTime; this.firstTime = firstTime;
} }
public void writeFirstTime(boolean firstTime, Activity activity) {
setFirstTime(firstTime);
OsmandSettings settings = getSettings(activity);
settings.FIRST_TIME_APP_RUN.set(firstTime);
}
private OsmandSettings getSettings(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings();
}
public boolean checkAppVersionChanged(Activity activity) { public boolean checkAppVersionChanged(Activity activity) {
initUiVars(activity); initUiVars(activity);
boolean showRecentChangesDialog = !firstTime && appVersionChanged; boolean showRecentChangesDialog = !firstTime && appVersionChanged;

View file

@ -137,10 +137,6 @@ public class OsmandApplication extends Application {
timeToStart = System.currentTimeMillis(); timeToStart = System.currentTimeMillis();
OsmandPlugin.initPlugins(this); OsmandPlugin.initPlugins(this);
System.out.println("Time to init plugins " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms"); System.out.println("Time to init plugins " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms");
osmandSettings.NUMBER_OF_APPLICATION_STARTS.set(
osmandSettings.NUMBER_OF_APPLICATION_STARTS.get() + 1);
} }
public AppInitializer getAppInitializer() { public AppInitializer getAppInitializer() {

View file

@ -1874,10 +1874,7 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_RULER = public final CommonPreference<Boolean> SHOW_RULER =
new BooleanPreference("show_ruler", true).makeProfile().cache(); new BooleanPreference("show_ruler", true).makeProfile().cache();
public final OsmandPreference<Long> FIRST_INSTALLED_DATE = new LongPreference("first_installed_date", -1).makeGlobal();
public final OsmandPreference<Integer> NUMBER_OF_STARTS = new IntPreference(AppInitializer.NUMBER_OF_STARTS, 0).makeGlobal();
public final OsmandPreference<Long> FIRST_INSTALLED_DATE = new LongPreference(AppInitializer.FIRST_INSTALLED, 0).makeGlobal();
// public final OsmandPreference<Integer> NUMBER_OF_FREE_DOWNLOADS_V2 = new IntPreference("free_downloads_v2", 0).makeGlobal(); // public final OsmandPreference<Integer> NUMBER_OF_FREE_DOWNLOADS_V2 = new IntPreference("free_downloads_v2", 0).makeGlobal();
@ -1893,6 +1890,10 @@ public class OsmandSettings {
DashRateUsFragment.RateUsState.INITIAL_STATE, DashRateUsFragment.RateUsState.values()) DashRateUsFragment.RateUsState.INITIAL_STATE, DashRateUsFragment.RateUsState.values())
.makeGlobal() .makeGlobal()
.cache(); .cache();
public final OsmandPreference<Boolean> FIRST_TIME_APP_RUN =
new BooleanPreference("first_time_app_run", true).makeGlobal().cache();
public final OsmandPreference<String> VERSION_INSTALLED =
new StringPreference("version_installed", null).makeGlobal().cache();
public enum DayNightMode { public enum DayNightMode {

View file

@ -182,6 +182,21 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
cat.addPreference(createCheckBoxPreference(settings.SHOULD_SHOW_FREE_VERSION_BANNER, cat.addPreference(createCheckBoxPreference(settings.SHOULD_SHOW_FREE_VERSION_BANNER,
R.string.show_free_version_banner, R.string.show_free_version_banner,
R.string.show_free_version_banner_description)); R.string.show_free_version_banner_description));
final Preference firstRunPreference = new Preference(this);
firstRunPreference.setTitle("Reset first run");
firstRunPreference.setSummary("After reset app wold act like it is it's firs run");
firstRunPreference.setSelectable(true);
firstRunPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
final SettingsDevelopmentActivity activity = SettingsDevelopmentActivity.this;
activity.getMyApplication().getAppInitializer()
.writeFirstTime(true, activity);
firstRunPreference.setSummary("First run flag has been reset");
return true;
}
});
cat.addPreference(firstRunPreference);
} }
protected void availableProfileDialog() { protected void availableProfileDialog() {

View file

@ -187,7 +187,7 @@ public class DownloadOsmandIndexesHelper {
if(nd > 0) { if(nd > 0) {
strUrl += "&nd=" + ((System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l)); strUrl += "&nd=" + ((System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l));
} }
strUrl += "&ns=" + settings.NUMBER_OF_STARTS.get(); strUrl += "&ns=" + settings.NUMBER_OF_APPLICATION_STARTS.get();
try { try {
strUrl += "&aid=" + Secure.getString(ctx.getContentResolver(), Secure.ANDROID_ID); strUrl += "&aid=" + Secure.getString(ctx.getContentResolver(), Secure.ANDROID_ID);
} catch (Exception e) { } catch (Exception e) {