Update discount information

This commit is contained in:
Victor Shcherb 2016-08-17 14:11:27 +02:00
parent 57d53a7d29
commit a0a81b08d8
8 changed files with 63 additions and 39 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="no_update_info_desc">Don\'t check any updates about new versions, discounts related to OsmAnd</string>
<string name="no_update_info">Don\'t show updates</string>
<string name="update_all_maps_now">Do you want to update all maps now?</string>
<string name="clear_tile_data">Clear all tiles</string>
<string name="routing_attr_short_way_name">Fuel-efficient way</string>

View file

@ -10,7 +10,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AlertDialog;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
@ -60,7 +59,6 @@ import java.util.List;
import java.util.Random;
import btools.routingapp.BRouterServiceConnection;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
@ -181,11 +179,13 @@ public class AppInitializer implements IProgress {
return startPrefs.getInt(NUMBER_OF_STARTS, 1);
}
public long getFirstInstalled() {
public long getFirstInstalledDays() {
if(startPrefs == null) {
return 0;
}
return startPrefs.getLong(FIRST_INSTALLED, 0);
long nd = startPrefs.getLong(FIRST_INSTALLED, 0);
return (System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l);
}
public void resetFirstTimeRun() {

View file

@ -906,6 +906,7 @@ public class OsmandSettings {
public final OsmandPreference<Integer> DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
public final OsmandPreference<Integer> DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();
public final OsmandPreference<Integer> DISCOUNT_TOTAL_SHOW = new IntPreference("discount_total_show", 0).makeGlobal();
public final OsmandPreference<Long> DISCOUNT_SHOW_DATETIME_MS = new LongPreference("show_discount_datetime_ms", 0).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
@ -1082,6 +1083,8 @@ public class OsmandSettings {
public final OsmandPreference<String> OSMO_GROUPS = new StringPreference("osmo_groups", "{}").makeGlobal();
public final OsmandPreference<Boolean> NO_DISCOUNT_INFO = new BooleanPreference("no_discount_info", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> DEBUG_RENDERING_INFO = new BooleanPreference("debug_rendering", false).makeGlobal();

View file

@ -419,7 +419,7 @@ public class MapActivityLayers {
adapter.addItem(builder.createItem());
}
public void selectMapLayer(final OsmandMapTileView mapView, final ContextMenuItem it) {
public void selectMapLayer(final OsmandMapTileView mapView, final ContextMenuItem it, final ArrayAdapter<ContextMenuItem> adapter) {
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
Toast.makeText(activity, R.string.map_online_plugin_is_not_installed, Toast.LENGTH_LONG).show();
return;
@ -477,9 +477,8 @@ public class MapActivityLayers {
case layerOsmVector:
settings.MAP_ONLINE_DATA.set(false);
updateMapSource(mapView, null);
if(it != null) {
it.setDescription(null);
}
it.setDescription(null);
adapter.notifyDataSetChanged();
break;
case layerEditInstall:
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() {
@ -513,12 +512,11 @@ public class MapActivityLayers {
if (count == 1) {
settings.MAP_TILE_SOURCES.set(template.getName());
settings.MAP_ONLINE_DATA.set(true);
if(it != null) {
it.setDescription(template.getName());
}
it.setDescription(template.getName());
adapter.notifyDataSetChanged();
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
} else {
selectMapLayer(mapView, it);
selectMapLayer(mapView, it, adapter);
}
} else {
count++;
@ -536,9 +534,8 @@ public class MapActivityLayers {
default:
settings.MAP_TILE_SOURCES.set(layerKey);
settings.MAP_ONLINE_DATA.set(true);
if(it != null) {
it.setDescription(layerKey);
}
it.setDescription(layerKey);
adapter.notifyDataSetChanged();
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
break;
}

View file

@ -39,7 +39,8 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
super.onCreate(savedInstanceState);
getToolbar().setTitle(R.string.debugging_and_development);
PreferenceScreen cat = getPreferenceScreen();
CheckBoxPreference dbg = createCheckBoxPreference(settings.DEBUG_RENDERING_INFO,
R.string.trace_rendering, R.string.trace_rendering_descr);
cat.addPreference(dbg);
@ -81,6 +82,10 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
cat.addPreference(createCheckBoxPreference(settings.SHOULD_SHOW_FREE_VERSION_BANNER,
R.string.show_free_version_banner,
R.string.show_free_version_banner_description));
cat.addPreference(createCheckBoxPreference(settings.NO_DISCOUNT_INFO,
R.string.no_update_info, R.string.no_update_info_desc));
// FIXME delete USE_MAP_MARKERS
// cat.addPreference(createCheckBoxPreference(settings.USE_MAP_MARKERS,
@ -110,6 +115,8 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
}
});
cat.addPreference(pref);
pref = new Preference(this);
pref.setTitle(R.string.test_voice_prompts);

View file

@ -164,7 +164,7 @@ public class ConfigureMapMenu {
ma.startActivity(intent);
} else {
ContextMenuItem it = adapter.getItem(pos);
ma.getMapLayers().selectMapLayer(ma.getMapView(), it);
ma.getMapLayers().selectMapLayer(ma.getMapView(), it, adapter);
}
}
adapter.notifyDataSetChanged();
@ -620,14 +620,20 @@ public class ConfigureMapMenu {
};
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder().setTitleId(strId, activity)
.setIcon(icon).setListener(clickListener);
boolean selected = false;
for(OsmandSettings.CommonPreference<Boolean> p : prefs) {
if(p.get()) {
selected = true;
break;
}
}
builder.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
if (useDescription) {
final String descr = getDescription(prefs);
builder.setDescription(descr);
builder.setLayout(R.layout.list_item_single_line_descrition_narrow);
} else {
boolean selected = false;
builder.setListener(new OnRowItemClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos, boolean isChecked) {
return clickListener.onContextMenuClick(a, itemId, pos, isChecked);
@ -642,13 +648,6 @@ public class ConfigureMapMenu {
}
});
builder.setSecondaryIcon(R.drawable.ic_action_additional_option);
for(OsmandSettings.CommonPreference<Boolean> p : prefs) {
if(p.get()) {
selected = true;
break;
}
}
builder.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
builder.setSelected(selected);
}
return builder.createItem();

View file

@ -182,11 +182,9 @@ public class DownloadOsmandIndexesHelper {
log.debug("Start loading list of index files"); //$NON-NLS-1$
try {
String strUrl = ctx.getAppCustomization().getIndexesUrl();
OsmandSettings settings = ctx.getSettings();
long nd = ctx.getAppInitializer().getFirstInstalled();
long nd = ctx.getAppInitializer().getFirstInstalledDays();
if(nd > 0) {
strUrl += "&nd=" + ((System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l));
strUrl += "&nd=" + nd;
}
strUrl += "&ns=" + ctx.getAppInitializer().getNumberOfStarts();
try {

View file

@ -2,6 +2,8 @@ package net.osmand.plus.helpers;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import net.osmand.AndroidNetworkUtils;
import net.osmand.plus.OsmandApplication;
@ -33,24 +35,32 @@ public class DiscountHelper {
private static String mIcon;
private static String mUrl;
private static boolean mBannerVisible;
private static final String URL = "http://osmand.net/api/motd";
public static void checkAndDisplay(final MapActivity mapActivity) {
if (mBannerVisible) {
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl);
}
OsmandApplication app = mapActivity.getMyApplication();
if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24
|| !mapActivity.getMyApplication().getSettings().isInternetConnectionAvailable()) {
|| !app.getSettings().isInternetConnectionAvailable()
|| app.getSettings().NO_DISCOUNT_INFO.get()) {
return;
}
mLastCheckTime = System.currentTimeMillis();
final Map<String, String> pms = new LinkedHashMap<>();
pms.put("name", Version.getAppName(app));
pms.put("version", Version.getAppVersion(app));
pms.put("nd", app.getAppInitializer().getFirstInstalledDays() +"");
pms.put("ns", app.getAppInitializer().getNumberOfStarts() + "");
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
String res = AndroidNetworkUtils.sendRequest(mapActivity.getMyApplication(),
"http://osmand.net/api/motd", null, "Requesting discount info...", false);
URL, pms, "Requesting discount info...", false);
return res;
} catch (Exception e) {
logError("Requesting discount info error: ", e);
@ -81,7 +91,8 @@ public class DiscountHelper {
Date start = df.parse(obj.getString("start"));
Date end = df.parse(obj.getString("end"));
int showStartFrequency = obj.getInt("show_start_frequency");
int showDayFrequency = obj.getInt("show_day_frequency");
double showDayFrequency = obj.getDouble("show_day_frequency");
int maxTotalShow = obj.getInt("max_total_show");
JSONObject application = obj.getJSONObject("application");
String appName = app.getPackageName();
@ -91,14 +102,21 @@ public class DiscountHelper {
OsmandSettings settings = app.getSettings();
int discountId = getDiscountId(message, description, start, end);
if (settings.DISCOUNT_ID.get() != discountId
boolean discountChanged = settings.DISCOUNT_ID.get() != discountId;
if(discountChanged) {
settings.DISCOUNT_TOTAL_SHOW.set(0);
}
if (discountChanged
|| app.getAppInitializer().getNumberOfStarts() - settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.get() >= showStartFrequency
|| System.currentTimeMillis() - settings.DISCOUNT_SHOW_DATETIME_MS.get() > 1000L * 60 * 60 * 24 * showDayFrequency) {
settings.DISCOUNT_ID.set(discountId);
settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.set(app.getAppInitializer().getNumberOfStarts());
settings.DISCOUNT_SHOW_DATETIME_MS.set(System.currentTimeMillis());
showDiscountBanner(mapActivity, message, description, icon, url);
if(settings.DISCOUNT_TOTAL_SHOW.get() < maxTotalShow){
settings.DISCOUNT_ID.set(discountId);
settings.DISCOUNT_TOTAL_SHOW.set(settings.DISCOUNT_TOTAL_SHOW.get() + 1);
settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.set(app.getAppInitializer().getNumberOfStarts());
settings.DISCOUNT_SHOW_DATETIME_MS.set(System.currentTimeMillis());
showDiscountBanner(mapActivity, message, description, icon, url);
}
}
}