remove unused fields in DiscountHelper and add decodeTitleFromTravelUrl
This commit is contained in:
parent
22592206c7
commit
ea157a2d9c
3 changed files with 29 additions and 28 deletions
|
@ -18,7 +18,6 @@ import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
|
|||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
||||
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
@ -38,12 +37,10 @@ public class DiscountHelper {
|
|||
private static String mDescription;
|
||||
private static String mIcon;
|
||||
private static String mUrl;
|
||||
private static String mTravelUrl;
|
||||
private static String mLang;
|
||||
private static boolean mBannerVisible;
|
||||
private static final String URL = "https://osmand.net/api/motd";
|
||||
private static final String INAPP_PREFIX = "osmand-in-app:";
|
||||
private static final String TRAVEL_PREFIX = "travel:";
|
||||
private static final String TRAVEL_PREFIX = "https://osmand.net/travel";
|
||||
|
||||
|
||||
public static void checkAndDisplay(final MapActivity mapActivity) {
|
||||
|
@ -53,7 +50,7 @@ public class DiscountHelper {
|
|||
return;
|
||||
}
|
||||
if (mBannerVisible) {
|
||||
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl, mTravelUrl, mLang);
|
||||
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl);
|
||||
}
|
||||
if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24
|
||||
|| !settings.isInternetConnectionAvailable()
|
||||
|
@ -104,8 +101,6 @@ public class DiscountHelper {
|
|||
String description = obj.getString("description");
|
||||
String icon = obj.getString("icon");
|
||||
String url = parseUrl(app, obj.getString("url"));
|
||||
String travelUrl = parseUrl(app, obj.getString("travel"));
|
||||
String lang = parseUrl(app, obj.getString("lang"));
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm");
|
||||
Date start = df.parse(obj.getString("start"));
|
||||
Date end = df.parse(obj.getString("end"));
|
||||
|
@ -142,7 +137,7 @@ public class DiscountHelper {
|
|||
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, travelUrl, lang);
|
||||
showDiscountBanner(mapActivity, message, description, icon, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,8 +167,8 @@ public class DiscountHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static void showDiscountBanner(final MapActivity mapActivity, final String title, final String description,
|
||||
final String icon, final String url, final String travelUrl, final String lang) {
|
||||
private static void showDiscountBanner(final MapActivity mapActivity, final String title,
|
||||
final String description, final String icon, final String url) {
|
||||
final DiscountBarController toolbarController = new DiscountBarController();
|
||||
toolbarController.setTitle(title);
|
||||
toolbarController.setDescription(description);
|
||||
|
@ -186,7 +181,7 @@ public class DiscountHelper {
|
|||
mapActivity.getMyApplication().logEvent(mapActivity, "motd_click");
|
||||
mBannerVisible = false;
|
||||
mapActivity.hideTopToolbar(toolbarController);
|
||||
openUrl(mapActivity, url, lang);
|
||||
openUrl(mapActivity, url);
|
||||
}
|
||||
});
|
||||
toolbarController.setOnTitleClickListener(new View.OnClickListener() {
|
||||
|
@ -195,7 +190,7 @@ public class DiscountHelper {
|
|||
mapActivity.getMyApplication().logEvent(mapActivity, "motd_click");
|
||||
mBannerVisible = false;
|
||||
mapActivity.hideTopToolbar(toolbarController);
|
||||
openUrl(mapActivity, url, lang);
|
||||
openUrl(mapActivity, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -212,14 +207,12 @@ public class DiscountHelper {
|
|||
mDescription = description;
|
||||
mIcon = icon;
|
||||
mUrl = url;
|
||||
mTravelUrl = travelUrl;
|
||||
mLang = lang;
|
||||
mBannerVisible = true;
|
||||
|
||||
mapActivity.showTopToolbar(toolbarController);
|
||||
}
|
||||
|
||||
private static void openUrl(final MapActivity mapActivity, String url, String lang) {
|
||||
private static void openUrl(final MapActivity mapActivity, String url) {
|
||||
if (url.startsWith(INAPP_PREFIX)) {
|
||||
if (url.contains(InAppPurchaseHelper.SKU_FULL_VERSION_PRICE)) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
@ -233,7 +226,7 @@ public class DiscountHelper {
|
|||
}
|
||||
} else if (url.startsWith(TRAVEL_PREFIX)) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, WikiArticleHelper.buildTravelUrl(url, lang));
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
intent.setType("text/plain");
|
||||
mapActivity.startActivity(Intent.createChooser(intent, mapActivity.getString(R.string.shared_string_share)));
|
||||
} else {
|
||||
|
|
|
@ -335,4 +335,17 @@ public class WikiArticleHelper {
|
|||
}
|
||||
return "https://osmand.net/travel?title=" + title + "&lang=" + lang;
|
||||
}
|
||||
|
||||
public static String decodeTitleFromTravelUrl(String url) {
|
||||
String title = "";
|
||||
try {
|
||||
if (!Algorithms.isEmpty(url)) {
|
||||
title = url.replace("_", " ");
|
||||
title = URLDecoder.decode(title, "UTF-8");
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return title;
|
||||
}
|
||||
}
|
|
@ -32,15 +32,14 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.TabActivity;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -182,17 +181,13 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
|
|||
&& path != null
|
||||
&& host.contains("osmand.net")
|
||||
&& path.startsWith("/travel")) {
|
||||
String query = data.getQueryParameter("title");
|
||||
try {
|
||||
if (!Algorithms.isEmpty(query)) {
|
||||
query = URLDecoder.decode(query, "UTF-8");
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
String title = WikiArticleHelper.decodeTitleFromTravelUrl(data.getQueryParameter("title"));
|
||||
String selectedLang = data.getQueryParameter("lang");
|
||||
if (!Algorithms.isEmpty(query) && !Algorithms.isEmpty(selectedLang)) {
|
||||
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), query, selectedLang);
|
||||
if (!Algorithms.isEmpty(title) && !Algorithms.isEmpty(selectedLang)) {
|
||||
long articleId = app.getTravelDbHelper().getArticleId(title, selectedLang);
|
||||
if (articleId != -1) {
|
||||
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), articleId, selectedLang);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue