[misskey-link] Open Misskey links in app

This commit is contained in:
kyori 2018-09-08 20:03:28 +09:00 committed by kyori19
parent 75c4cdd886
commit be43cb67a8
11 changed files with 27 additions and 17 deletions

View File

@ -47,7 +47,7 @@ class AboutActivity : BottomSheetActivity(), Injectable {
} }
private fun onAccountButtonClick() { private fun onAccountButtonClick() {
viewUrl("https://mastodon.social/@Tusky") viewUrl("https://mastodon.social/@Tusky", getString(R.string.about_tusky_account))
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {

View File

@ -686,8 +686,8 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
startActivityWithSlideInAnimation(intent) startActivityWithSlideInAnimation(intent)
} }
override fun onViewUrl(url: String) { override fun onViewUrl(url: String, text: String) {
viewUrl(url) viewUrl(url, text)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {

View File

@ -44,6 +44,8 @@ abstract class BottomSheetActivity : BaseActivity() {
@Inject @Inject
lateinit var mastodonApi: MastodonApi lateinit var mastodonApi: MastodonApi
private val forceBrowser = arrayOf("リモートで結果を表示")
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState) super.onPostCreate(savedInstanceState)
@ -62,7 +64,12 @@ abstract class BottomSheetActivity : BaseActivity() {
} }
open fun viewUrl(url: String) { open fun viewUrl(url: String, text: String) {
if (forceBrowser.contains(text)) {
openLink(url)
return
}
if (!looksLikeMastodonUrl(url)) { if (!looksLikeMastodonUrl(url)) {
openLink(url) openLink(url)
return return
@ -174,6 +181,7 @@ abstract class BottomSheetActivity : BaseActivity() {
// https://pleroma.foo.bar/notice/43456787654678 // https://pleroma.foo.bar/notice/43456787654678
// https://pleroma.foo.bar/objects/d4643c42-3ae0-4b73-b8b0-c725f5819207 // https://pleroma.foo.bar/objects/d4643c42-3ae0-4b73-b8b0-c725f5819207
// https://mastodon.foo.bar/users/User/statuses/000000000000000000 // https://mastodon.foo.bar/users/User/statuses/000000000000000000
// https://new.misskey.foo.bar/notes/012789abyz
fun looksLikeMastodonUrl(urlString: String): Boolean { fun looksLikeMastodonUrl(urlString: String): Boolean {
val uri: URI val uri: URI
try { try {
@ -194,5 +202,7 @@ fun looksLikeMastodonUrl(urlString: String): Boolean {
path.matches("^/@[^/]+/\\d+$".toRegex()) || path.matches("^/@[^/]+/\\d+$".toRegex()) ||
path.matches("^/notice/\\d+$".toRegex()) || path.matches("^/notice/\\d+$".toRegex()) ||
path.matches("^/objects/[-a-f0-9]+$".toRegex()) || path.matches("^/objects/[-a-f0-9]+$".toRegex()) ||
path.matches("^/users/[^/]+/statuses/[0-9]+$".toRegex()) path.matches("^/users/[^/]+/statuses/[0-9]+$".toRegex()) ||
path.matches("^/notes/[a-z0-9]+$".toRegex())
} }

View File

@ -315,7 +315,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
if (intent != null) { if (intent != null) {
String statusUrl = intent.getStringExtra(STATUS_URL); String statusUrl = intent.getStringExtra(STATUS_URL);
if (statusUrl != null) { if (statusUrl != null) {
viewUrl(statusUrl); viewUrl(statusUrl, statusUrl);
} }
} }
} }

View File

@ -98,7 +98,7 @@ class ReportActivity : BottomSheetActivity(), HasAndroidInjector {
viewModel.checkUrl.observe(this, Observer { viewModel.checkUrl.observe(this, Observer {
if (!it.isNullOrBlank()) { if (!it.isNullOrBlank()) {
viewModel.urlChecked() viewModel.urlChecked()
viewUrl(it) viewUrl(it, it)
} }
}) })
} }

View File

@ -204,7 +204,7 @@ class ReportStatusesFragment : Fragment(), Injectable, AdapterHandler {
override fun onViewTag(tag: String) = startActivity(ViewTagActivity.getIntent(requireContext(), tag)) override fun onViewTag(tag: String) = startActivity(ViewTagActivity.getIntent(requireContext(), tag))
override fun onViewUrl(url: String?) = viewModel.checkClickedUrl(url) override fun onViewUrl(url: String?, text: String?) = viewModel.checkClickedUrl(url)
companion object { companion object {
fun newInstance() = ReportStatusesFragment() fun newInstance() = ReportStatusesFragment()

View File

@ -124,8 +124,8 @@ abstract class SearchFragment<T> : Fragment(),
override fun onViewTag(tag: String) = startActivity(ViewTagActivity.getIntent(requireContext(), tag)) override fun onViewTag(tag: String) = startActivity(ViewTagActivity.getIntent(requireContext(), tag))
override fun onViewUrl(url: String) { override fun onViewUrl(url: String, text: String) {
bottomSheetActivity?.viewUrl(url) bottomSheetActivity?.viewUrl(url, text)
} }
protected val bottomSheetActivity = (activity as? BottomSheetActivity) protected val bottomSheetActivity = (activity as? BottomSheetActivity)

View File

@ -131,8 +131,8 @@ public abstract class SFragment extends BaseFragment implements Injectable {
bottomSheetActivity.viewAccount(accountId); bottomSheetActivity.viewAccount(accountId);
} }
public void onViewUrl(String url) { public void onViewUrl(String url, String text) {
bottomSheetActivity.viewUrl(url); bottomSheetActivity.viewUrl(url, text);
} }
protected void reply(Status status) { protected void reply(Status status) {

View File

@ -18,5 +18,5 @@ package com.keylesspalace.tusky.interfaces;
public interface LinkListener { public interface LinkListener {
void onViewTag(String tag); void onViewTag(String tag);
void onViewAccount(String id); void onViewAccount(String id);
void onViewUrl(String url); void onViewUrl(String url, String text);
} }

View File

@ -112,7 +112,7 @@ public class LinkHelper {
customSpan = new CustomURLSpan(span.getURL()) { customSpan = new CustomURLSpan(span.getURL()) {
@Override @Override
public void onClick(View widget) { public void onClick(View widget) {
listener.onViewUrl(getURL()); listener.onViewUrl(getURL(), text.toString());
} }
}; };
} }

View File

@ -99,9 +99,9 @@ public class QuoteInlineHelper {
quoteAvatar.setOnClickListener(view -> listener.onViewAccount(accountId)); quoteAvatar.setOnClickListener(view -> listener.onViewAccount(accountId));
quoteDisplayName.setOnClickListener(view -> listener.onViewAccount(accountId)); quoteDisplayName.setOnClickListener(view -> listener.onViewAccount(accountId));
quoteUsername.setOnClickListener(view -> listener.onViewAccount(accountId)); quoteUsername.setOnClickListener(view -> listener.onViewAccount(accountId));
quoteContent.setOnClickListener(view -> listener.onViewUrl(statusUrl)); quoteContent.setOnClickListener(view -> listener.onViewUrl(statusUrl, statusUrl));
quoteMedia.setOnClickListener(view -> listener.onViewUrl(statusUrl)); quoteMedia.setOnClickListener(view -> listener.onViewUrl(statusUrl, statusUrl));
quoteContainer.setOnClickListener(view -> listener.onViewUrl(statusUrl)); quoteContainer.setOnClickListener(view -> listener.onViewUrl(statusUrl, statusUrl));
} }
public void setupQuoteContainer() { public void setupQuoteContainer() {