|
|
@ -19,6 +19,7 @@ import android.content.Intent |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.widget.LinearLayout |
|
|
|
import android.widget.LinearLayout |
|
|
|
|
|
|
|
import android.widget.Toast |
|
|
|
import androidx.annotation.VisibleForTesting |
|
|
|
import androidx.annotation.VisibleForTesting |
|
|
|
import androidx.lifecycle.Lifecycle |
|
|
|
import androidx.lifecycle.Lifecycle |
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior |
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior |
|
|
@ -62,7 +63,7 @@ abstract class BottomSheetActivity : BaseActivity() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open fun viewUrl(url: String) { |
|
|
|
open fun viewUrl(url: String, lookupFallbackBehavior: PostLookupFallbackBehavior = PostLookupFallbackBehavior.OPEN_IN_BROWSER) { |
|
|
|
if (!looksLikeMastodonUrl(url)) { |
|
|
|
if (!looksLikeMastodonUrl(url)) { |
|
|
|
openLink(url) |
|
|
|
openLink(url) |
|
|
|
return |
|
|
|
return |
|
|
@ -88,11 +89,11 @@ abstract class BottomSheetActivity : BaseActivity() { |
|
|
|
return@subscribe |
|
|
|
return@subscribe |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
openLink(url) |
|
|
|
performUrlFallbackAction(url, lookupFallbackBehavior) |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
if (!getCancelSearchRequested(url)) { |
|
|
|
if (!getCancelSearchRequested(url)) { |
|
|
|
onEndSearch(url) |
|
|
|
onEndSearch(url) |
|
|
|
openLink(url) |
|
|
|
performUrlFallbackAction(url, lookupFallbackBehavior) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -113,6 +114,13 @@ abstract class BottomSheetActivity : BaseActivity() { |
|
|
|
startActivityWithSlideInAnimation(intent) |
|
|
|
startActivityWithSlideInAnimation(intent) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected open fun performUrlFallbackAction(url: String, fallbackBehavior: PostLookupFallbackBehavior) { |
|
|
|
|
|
|
|
when (fallbackBehavior) { |
|
|
|
|
|
|
|
PostLookupFallbackBehavior.OPEN_IN_BROWSER -> openLink(url) |
|
|
|
|
|
|
|
PostLookupFallbackBehavior.DISPLAY_ERROR -> Toast.makeText(this, getString(R.string.post_lookup_error_format, url), Toast.LENGTH_SHORT).show() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting |
|
|
|
@VisibleForTesting |
|
|
|
fun onBeginSearch(url: String) { |
|
|
|
fun onBeginSearch(url: String) { |
|
|
|
searchUrl = url |
|
|
|
searchUrl = url |
|
|
@ -187,3 +195,8 @@ fun looksLikeMastodonUrl(urlString: String): Boolean { |
|
|
|
path.matches("^/notice/\\d+$".toRegex()) || |
|
|
|
path.matches("^/notice/\\d+$".toRegex()) || |
|
|
|
path.matches("^/objects/[-a-f0-9]+$".toRegex()) |
|
|
|
path.matches("^/objects/[-a-f0-9]+$".toRegex()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class PostLookupFallbackBehavior { |
|
|
|
|
|
|
|
OPEN_IN_BROWSER, |
|
|
|
|
|
|
|
DISPLAY_ERROR, |
|
|
|
|
|
|
|
} |
|
|
|