[misskey-link] Open Misskey links in app
This commit is contained in:
parent
75c4cdd886
commit
be43cb67a8
|
@ -47,7 +47,7 @@ class AboutActivity : BottomSheetActivity(), Injectable {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -686,8 +686,8 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
startActivityWithSlideInAnimation(intent)
|
||||
}
|
||||
|
||||
override fun onViewUrl(url: String) {
|
||||
viewUrl(url)
|
||||
override fun onViewUrl(url: String, text: String) {
|
||||
viewUrl(url, text)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
|
|
@ -44,6 +44,8 @@ abstract class BottomSheetActivity : BaseActivity() {
|
|||
@Inject
|
||||
lateinit var mastodonApi: MastodonApi
|
||||
|
||||
private val forceBrowser = arrayOf("リモートで結果を表示")
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
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)) {
|
||||
openLink(url)
|
||||
return
|
||||
|
@ -174,6 +181,7 @@ abstract class BottomSheetActivity : BaseActivity() {
|
|||
// https://pleroma.foo.bar/notice/43456787654678
|
||||
// https://pleroma.foo.bar/objects/d4643c42-3ae0-4b73-b8b0-c725f5819207
|
||||
// https://mastodon.foo.bar/users/User/statuses/000000000000000000
|
||||
// https://new.misskey.foo.bar/notes/012789abyz
|
||||
fun looksLikeMastodonUrl(urlString: String): Boolean {
|
||||
val uri: URI
|
||||
try {
|
||||
|
@ -194,5 +202,7 @@ fun looksLikeMastodonUrl(urlString: String): Boolean {
|
|||
path.matches("^/@[^/]+/\\d+$".toRegex()) ||
|
||||
path.matches("^/notice/\\d+$".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())
|
||||
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
|
|||
if (intent != null) {
|
||||
String statusUrl = intent.getStringExtra(STATUS_URL);
|
||||
if (statusUrl != null) {
|
||||
viewUrl(statusUrl);
|
||||
viewUrl(statusUrl, statusUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ class ReportActivity : BottomSheetActivity(), HasAndroidInjector {
|
|||
viewModel.checkUrl.observe(this, Observer {
|
||||
if (!it.isNullOrBlank()) {
|
||||
viewModel.urlChecked()
|
||||
viewUrl(it)
|
||||
viewUrl(it, it)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ class ReportStatusesFragment : Fragment(), Injectable, AdapterHandler {
|
|||
|
||||
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 {
|
||||
fun newInstance() = ReportStatusesFragment()
|
||||
|
|
|
@ -124,8 +124,8 @@ abstract class SearchFragment<T> : Fragment(),
|
|||
|
||||
override fun onViewTag(tag: String) = startActivity(ViewTagActivity.getIntent(requireContext(), tag))
|
||||
|
||||
override fun onViewUrl(url: String) {
|
||||
bottomSheetActivity?.viewUrl(url)
|
||||
override fun onViewUrl(url: String, text: String) {
|
||||
bottomSheetActivity?.viewUrl(url, text)
|
||||
}
|
||||
|
||||
protected val bottomSheetActivity = (activity as? BottomSheetActivity)
|
||||
|
|
|
@ -131,8 +131,8 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
bottomSheetActivity.viewAccount(accountId);
|
||||
}
|
||||
|
||||
public void onViewUrl(String url) {
|
||||
bottomSheetActivity.viewUrl(url);
|
||||
public void onViewUrl(String url, String text) {
|
||||
bottomSheetActivity.viewUrl(url, text);
|
||||
}
|
||||
|
||||
protected void reply(Status status) {
|
||||
|
|
|
@ -18,5 +18,5 @@ package com.keylesspalace.tusky.interfaces;
|
|||
public interface LinkListener {
|
||||
void onViewTag(String tag);
|
||||
void onViewAccount(String id);
|
||||
void onViewUrl(String url);
|
||||
void onViewUrl(String url, String text);
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class LinkHelper {
|
|||
customSpan = new CustomURLSpan(span.getURL()) {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
listener.onViewUrl(getURL());
|
||||
listener.onViewUrl(getURL(), text.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -99,9 +99,9 @@ public class QuoteInlineHelper {
|
|||
quoteAvatar.setOnClickListener(view -> listener.onViewAccount(accountId));
|
||||
quoteDisplayName.setOnClickListener(view -> listener.onViewAccount(accountId));
|
||||
quoteUsername.setOnClickListener(view -> listener.onViewAccount(accountId));
|
||||
quoteContent.setOnClickListener(view -> listener.onViewUrl(statusUrl));
|
||||
quoteMedia.setOnClickListener(view -> listener.onViewUrl(statusUrl));
|
||||
quoteContainer.setOnClickListener(view -> listener.onViewUrl(statusUrl));
|
||||
quoteContent.setOnClickListener(view -> listener.onViewUrl(statusUrl, statusUrl));
|
||||
quoteMedia.setOnClickListener(view -> listener.onViewUrl(statusUrl, statusUrl));
|
||||
quoteContainer.setOnClickListener(view -> listener.onViewUrl(statusUrl, statusUrl));
|
||||
}
|
||||
|
||||
public void setupQuoteContainer() {
|
||||
|
|
Loading…
Reference in New Issue