Merge pull request #5483 from osmandapp/WikivoyageSharingLinks

Wikivoyage sharing links
This commit is contained in:
Alexey 2018-05-25 15:13:02 +03:00 committed by GitHub
commit cb6fe98a00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 10 deletions

View file

@ -756,7 +756,23 @@
</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: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>

View file

@ -54,6 +54,15 @@
tools:text="En" tools:text="En"
tools:textColor="?attr/wikivoyage_active_color"/> 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> </LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>

View file

@ -31,6 +31,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -324,4 +325,27 @@ public class WikiArticleHelper {
return res.toString(); 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;
}
} }

View file

@ -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;
@ -31,10 +32,12 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.TabActivity; import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; 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.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,21 +171,41 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
super.onResume(); super.onResume();
Intent intent = getIntent(); Intent intent = getIntent();
if (intent != null) { if (intent != null) {
int currentItem = intent.getIntExtra(TAB_SELECTED, 0); Uri data = intent.getData();
if (currentItem == SAVED_ARTICLES_POSITION) { if (data != null && ("http".equalsIgnoreCase(data.getScheme()) || "https".equalsIgnoreCase(data.getScheme()))) {
BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation); parseLaunchIntentLink(data);
bottomNav.setSelectedItemId(R.id.action_saved_articles); } else {
} int currentItem = intent.getIntExtra(TAB_SELECTED, 0);
long cityId = intent.getLongExtra(CITY_ID_KEY, -1); if (currentItem == SAVED_ARTICLES_POSITION) {
String selectedLang = intent.getStringExtra(SELECTED_LANG_KEY); BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation);
if (cityId != -1) { bottomNav.setSelectedItemId(R.id.action_saved_articles);
WikivoyageArticleDialogFragment.showInstance(app, getSupportFragmentManager(), cityId, selectedLang); }
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); setIntent(null);
} }
getMyApplication().getDownloadThread().setUiActivity(this); 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 @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();