Merge pull request #5483 from osmandapp/WikivoyageSharingLinks
Wikivoyage sharing links
This commit is contained in:
commit
cb6fe98a00
4 changed files with 82 additions and 10 deletions
|
@ -756,7 +756,23 @@
|
|||
</receiver>
|
||||
<activity android:name=".liveupdates.OsmLiveActivity"
|
||||
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: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"/>
|
||||
</application>
|
||||
|
|
|
@ -54,6 +54,15 @@
|
|||
tools:text="En"
|
||||
tools:textColor="?attr/wikivoyage_active_color"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:id="@+id/options_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="top"
|
||||
android:contentDescription="@string/shared_string_options"
|
||||
tools:src="@drawable/ic_overflow_menu_white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -324,4 +325,27 @@ public class WikiArticleHelper {
|
|||
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
public static String buildTravelUrl(String url, String lang) {
|
||||
String title = url.replace(" ", "_");
|
||||
try {
|
||||
title = URLEncoder.encode(title, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore;
|
|||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -31,10 +32,12 @@ 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.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
@ -168,21 +171,41 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
|
|||
super.onResume();
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
int currentItem = intent.getIntExtra(TAB_SELECTED, 0);
|
||||
if (currentItem == SAVED_ARTICLES_POSITION) {
|
||||
BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation);
|
||||
bottomNav.setSelectedItemId(R.id.action_saved_articles);
|
||||
}
|
||||
long cityId = intent.getLongExtra(CITY_ID_KEY, -1);
|
||||
String selectedLang = intent.getStringExtra(SELECTED_LANG_KEY);
|
||||
if (cityId != -1) {
|
||||
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), cityId, selectedLang);
|
||||
Uri data = intent.getData();
|
||||
if (data != null && ("http".equalsIgnoreCase(data.getScheme()) || "https".equalsIgnoreCase(data.getScheme()))) {
|
||||
parseLaunchIntentLink(data);
|
||||
} else {
|
||||
int currentItem = intent.getIntExtra(TAB_SELECTED, 0);
|
||||
if (currentItem == SAVED_ARTICLES_POSITION) {
|
||||
BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation);
|
||||
bottomNav.setSelectedItemId(R.id.action_saved_articles);
|
||||
}
|
||||
long articleId = intent.getLongExtra(CITY_ID_KEY, -1);
|
||||
String selectedLang = intent.getStringExtra(SELECTED_LANG_KEY);
|
||||
if (articleId != -1) {
|
||||
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), articleId, selectedLang);
|
||||
}
|
||||
}
|
||||
setIntent(null);
|
||||
}
|
||||
getMyApplication().getDownloadThread().setUiActivity(this);
|
||||
}
|
||||
|
||||
protected void parseLaunchIntentLink(Uri data) {
|
||||
String host = data.getHost();
|
||||
String path = data.getPath();
|
||||
if (host != null && path != null && host.contains("osmand.net") && path.startsWith("/travel")) {
|
||||
String title = WikiArticleHelper.decodeTitleFromTravelUrl(data.getQueryParameter("title"));
|
||||
String selectedLang = data.getQueryParameter("lang");
|
||||
if (!Algorithms.isEmpty(title) && !Algorithms.isEmpty(selectedLang)) {
|
||||
long articleId = app.getTravelDbHelper().getArticleId(title, selectedLang);
|
||||
if (articleId != -1) {
|
||||
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), articleId, selectedLang);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
|
Loading…
Reference in a new issue