add intent and intent-filter for sharing wikivoyage links
This commit is contained in:
parent
8d7331fd93
commit
d62f5a53df
5 changed files with 85 additions and 17 deletions
|
@ -756,7 +756,35 @@
|
||||||
</receiver>
|
</receiver>
|
||||||
<activity android:name=".liveupdates.OsmLiveActivity"
|
<activity android:name=".liveupdates.OsmLiveActivity"
|
||||||
android:label="@string/osm_live"/>
|
android:label="@string/osm_live"/>
|
||||||
<activity android:name=".wikivoyage.explore.WikivoyageExploreActivity"/>
|
<activity android:name=".wikivoyage.explore.WikivoyageExploreActivity">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<data android:scheme="http" />
|
||||||
|
<data android:host="osmand.net" />
|
||||||
|
<data android:pathPrefix="/travel" />
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<category android:name="android.intent.category.APP_MAPS" />
|
||||||
|
<category android:name="android.intent.category.CAR_MODE" />
|
||||||
|
<category android:name="android.intent.category.CAR_DOCK" />
|
||||||
|
<category android:name="android.intent.category.DESK_DOCK" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<data android:scheme="https" />
|
||||||
|
<data android:host="osmand.net" />
|
||||||
|
<data android:pathPrefix="/travel" />
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<category android:name="android.intent.category.APP_MAPS" />
|
||||||
|
<category android:name="android.intent.category.CAR_MODE" />
|
||||||
|
<category android:name="android.intent.category.CAR_DOCK" />
|
||||||
|
<category android:name="android.intent.category.DESK_DOCK" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
<receiver android:name="net.osmand.plus.liveupdates.LiveUpdatesAlarmReceiver"/>
|
<receiver android:name="net.osmand.plus.liveupdates.LiveUpdatesAlarmReceiver"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
- For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
- For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="share_article">Share article</string>
|
||||||
<string name="get_osmand_live">Get OsmAnd Live to unlock all features: Daily map updates with unlimited downloads, all paid and free plugins, Wikipedia, Wikivoyage and much more.</string>
|
<string name="get_osmand_live">Get OsmAnd Live to unlock all features: Daily map updates with unlimited downloads, all paid and free plugins, Wikipedia, Wikivoyage and much more.</string>
|
||||||
<string name="unirs_render_descr">Modification of the default style to increase contrast of pedestrian and bicycle roads. Uses legacy Mapnik colors.</string>
|
<string name="unirs_render_descr">Modification of the default style to increase contrast of pedestrian and bicycle roads. Uses legacy Mapnik colors.</string>
|
||||||
<string name="shared_string_bookmark">Bookmark</string>
|
<string name="shared_string_bookmark">Bookmark</string>
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
|
||||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
||||||
|
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -37,9 +38,12 @@ public class DiscountHelper {
|
||||||
private static String mDescription;
|
private static String mDescription;
|
||||||
private static String mIcon;
|
private static String mIcon;
|
||||||
private static String mUrl;
|
private static String mUrl;
|
||||||
|
private static String mTravelUrl;
|
||||||
|
private static String mLang;
|
||||||
private static boolean mBannerVisible;
|
private static boolean mBannerVisible;
|
||||||
private static final String URL = "https://osmand.net/api/motd";
|
private static final String URL = "https://osmand.net/api/motd";
|
||||||
private static final String INAPP_PREFIX = "osmand-in-app:";
|
private static final String INAPP_PREFIX = "osmand-in-app:";
|
||||||
|
private static final String TRAVEL_PREFIX = "travel:";
|
||||||
|
|
||||||
|
|
||||||
public static void checkAndDisplay(final MapActivity mapActivity) {
|
public static void checkAndDisplay(final MapActivity mapActivity) {
|
||||||
|
@ -49,7 +53,7 @@ public class DiscountHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mBannerVisible) {
|
if (mBannerVisible) {
|
||||||
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl);
|
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl, mTravelUrl, mLang);
|
||||||
}
|
}
|
||||||
if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24
|
if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24
|
||||||
|| !settings.isInternetConnectionAvailable()
|
|| !settings.isInternetConnectionAvailable()
|
||||||
|
@ -100,6 +104,8 @@ public class DiscountHelper {
|
||||||
String description = obj.getString("description");
|
String description = obj.getString("description");
|
||||||
String icon = obj.getString("icon");
|
String icon = obj.getString("icon");
|
||||||
String url = parseUrl(app, obj.getString("url"));
|
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");
|
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm");
|
||||||
Date start = df.parse(obj.getString("start"));
|
Date start = df.parse(obj.getString("start"));
|
||||||
Date end = df.parse(obj.getString("end"));
|
Date end = df.parse(obj.getString("end"));
|
||||||
|
@ -136,7 +142,7 @@ public class DiscountHelper {
|
||||||
settings.DISCOUNT_TOTAL_SHOW.set(settings.DISCOUNT_TOTAL_SHOW.get() + 1);
|
settings.DISCOUNT_TOTAL_SHOW.set(settings.DISCOUNT_TOTAL_SHOW.get() + 1);
|
||||||
settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.set(app.getAppInitializer().getNumberOfStarts());
|
settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.set(app.getAppInitializer().getNumberOfStarts());
|
||||||
settings.DISCOUNT_SHOW_DATETIME_MS.set(System.currentTimeMillis());
|
settings.DISCOUNT_SHOW_DATETIME_MS.set(System.currentTimeMillis());
|
||||||
showDiscountBanner(mapActivity, message, description, icon, url);
|
showDiscountBanner(mapActivity, message, description, icon, url, travelUrl, lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,8 +172,8 @@ public class DiscountHelper {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showDiscountBanner(final MapActivity mapActivity, final String title,
|
private static void showDiscountBanner(final MapActivity mapActivity, final String title, final String description,
|
||||||
final String description, final String icon, final String url) {
|
final String icon, final String url, final String travelUrl, final String lang) {
|
||||||
final DiscountBarController toolbarController = new DiscountBarController();
|
final DiscountBarController toolbarController = new DiscountBarController();
|
||||||
toolbarController.setTitle(title);
|
toolbarController.setTitle(title);
|
||||||
toolbarController.setDescription(description);
|
toolbarController.setDescription(description);
|
||||||
|
@ -180,7 +186,7 @@ public class DiscountHelper {
|
||||||
mapActivity.getMyApplication().logEvent(mapActivity, "motd_click");
|
mapActivity.getMyApplication().logEvent(mapActivity, "motd_click");
|
||||||
mBannerVisible = false;
|
mBannerVisible = false;
|
||||||
mapActivity.hideTopToolbar(toolbarController);
|
mapActivity.hideTopToolbar(toolbarController);
|
||||||
openUrl(mapActivity, url);
|
openUrl(mapActivity, url, lang);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toolbarController.setOnTitleClickListener(new View.OnClickListener() {
|
toolbarController.setOnTitleClickListener(new View.OnClickListener() {
|
||||||
|
@ -189,7 +195,7 @@ public class DiscountHelper {
|
||||||
mapActivity.getMyApplication().logEvent(mapActivity, "motd_click");
|
mapActivity.getMyApplication().logEvent(mapActivity, "motd_click");
|
||||||
mBannerVisible = false;
|
mBannerVisible = false;
|
||||||
mapActivity.hideTopToolbar(toolbarController);
|
mapActivity.hideTopToolbar(toolbarController);
|
||||||
openUrl(mapActivity, url);
|
openUrl(mapActivity, url, lang);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -206,12 +212,14 @@ public class DiscountHelper {
|
||||||
mDescription = description;
|
mDescription = description;
|
||||||
mIcon = icon;
|
mIcon = icon;
|
||||||
mUrl = url;
|
mUrl = url;
|
||||||
|
mTravelUrl = travelUrl;
|
||||||
|
mLang = lang;
|
||||||
mBannerVisible = true;
|
mBannerVisible = true;
|
||||||
|
|
||||||
mapActivity.showTopToolbar(toolbarController);
|
mapActivity.showTopToolbar(toolbarController);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void openUrl(final MapActivity mapActivity, String url) {
|
private static void openUrl(final MapActivity mapActivity, String url, String lang) {
|
||||||
if (url.startsWith(INAPP_PREFIX)) {
|
if (url.startsWith(INAPP_PREFIX)) {
|
||||||
if (url.contains(InAppPurchaseHelper.SKU_FULL_VERSION_PRICE)) {
|
if (url.contains(InAppPurchaseHelper.SKU_FULL_VERSION_PRICE)) {
|
||||||
OsmandApplication app = mapActivity.getMyApplication();
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
|
@ -223,6 +231,11 @@ public class DiscountHelper {
|
||||||
} else if (url.contains(InAppPurchaseHelper.SKU_LIVE_UPDATES)){
|
} else if (url.contains(InAppPurchaseHelper.SKU_LIVE_UPDATES)){
|
||||||
ChoosePlanDialogFragment.showOsmLiveInstance(mapActivity.getSupportFragmentManager());
|
ChoosePlanDialogFragment.showOsmLiveInstance(mapActivity.getSupportFragmentManager());
|
||||||
}
|
}
|
||||||
|
} else if (url.startsWith(TRAVEL_PREFIX)) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, WikiArticleHelper.buildTravelUrl(url, lang));
|
||||||
|
intent.setType("text/plain");
|
||||||
|
mapActivity.startActivity(Intent.createChooser(intent, mapActivity.getString(R.string.share_article)));
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse(url));
|
intent.setData(Uri.parse(url));
|
||||||
|
|
|
@ -324,4 +324,9 @@ public class WikiArticleHelper {
|
||||||
|
|
||||||
return res.toString();
|
return res.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String buildTravelUrl(String url, String lang) {
|
||||||
|
String query = url.substring(url.indexOf(':') + 1);
|
||||||
|
return "https://osmand.net/travel?query=" + query + "&lang=" + lang;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -35,6 +36,7 @@ import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||||
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -168,15 +170,34 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
|
Uri data = intent.getData();
|
||||||
|
if (data != null) {
|
||||||
|
String scheme = data.getScheme();
|
||||||
|
String host = data.getHost();
|
||||||
|
String path = data.getPath();
|
||||||
|
if (("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme))
|
||||||
|
&& host != null
|
||||||
|
&& path != null
|
||||||
|
&& host.contains("osmand.net")
|
||||||
|
&& path.startsWith("/travel")) {
|
||||||
|
String query = data.getQueryParameter("query");
|
||||||
|
String selectedLang = data.getQueryParameter("lang");
|
||||||
|
if (!Algorithms.isEmpty(query) && !Algorithms.isEmpty(selectedLang)) {
|
||||||
|
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), query, selectedLang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
int currentItem = intent.getIntExtra(TAB_SELECTED, 0);
|
int currentItem = intent.getIntExtra(TAB_SELECTED, 0);
|
||||||
if (currentItem == SAVED_ARTICLES_POSITION) {
|
if (currentItem == SAVED_ARTICLES_POSITION) {
|
||||||
BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation);
|
BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation);
|
||||||
bottomNav.setSelectedItemId(R.id.action_saved_articles);
|
bottomNav.setSelectedItemId(R.id.action_saved_articles);
|
||||||
}
|
}
|
||||||
long cityId = intent.getLongExtra(CITY_ID_KEY, -1);
|
long articleId = intent.getLongExtra(CITY_ID_KEY, -1);
|
||||||
String selectedLang = intent.getStringExtra(SELECTED_LANG_KEY);
|
String selectedLang = intent.getStringExtra(SELECTED_LANG_KEY);
|
||||||
if (cityId != -1) {
|
|
||||||
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), cityId, selectedLang);
|
if (articleId != -1) {
|
||||||
|
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), articleId, selectedLang);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setIntent(null);
|
setIntent(null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue