Merge pull request #5092 from osmandapp/OpenWikiLinks

Now we open wiki links in our browser
This commit is contained in:
Alexey 2018-03-05 14:14:19 +03:00 committed by GitHub
commit 38954241c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
@ -181,7 +182,7 @@ public class WikipediaDialogFragment extends DialogFragment {
@Override
public void onClick(View view) {
String article = "https://" + langSelected.toLowerCase() + ".wikipedia.org/wiki/" + title.replace(' ', '_');
showFullArticle(Uri.parse(article));
showFullArticle(getContext(), Uri.parse(article), darkMode);
}
});
@ -207,16 +208,16 @@ public class WikipediaDialogFragment extends DialogFragment {
}
}
private void showFullArticle(Uri uri) {
public static void showFullArticle(Context context, Uri uri, boolean nightMode) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setToolbarColor(ContextCompat.getColor(getContext(), darkMode ? R.color.actionbar_dark_color : R.color.actionbar_light_color))
.setToolbarColor(ContextCompat.getColor(context, nightMode ? R.color.actionbar_dark_color : R.color.actionbar_light_color))
.build();
customTabsIntent.launchUrl(getContext(), uri);
customTabsIntent.launchUrl(context, uri);
} else {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(uri);
startActivity(i);
context.startActivity(i);
}
}

View file

@ -290,9 +290,13 @@ public class AmenityMenuBuilder extends MenuBuilder {
ll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(text));
v.getContext().startActivity(intent);
if (text.contains(".wikipedia.org/w")) {
WikipediaDialogFragment.showFullArticle(v.getContext(), Uri.parse(text), !light);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(text));
v.getContext().startActivity(intent);
}
}
});
} else if (isWiki) {