Cleanup code
This commit is contained in:
1 parent
ca62b9f4bf
commit
71bd11a941
7 files changed
+48
-43
No files matched your search
@@ -39,6 +39,7 @@ import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail
|
||||
import com.hippo.ehviewer.ui.login.LocalNavController
|
||||
import com.hippo.util.tellClipboardWithToast
|
||||
|
||||
private const val INDEX_URL = 2
|
||||
@@ -104,6 +105,7 @@ fun GalleryInfoBottomSheet(
|
||||
ModalBottomSheet(onDismissRequest) {
|
||||
check(data.size == keys.size)
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center,
|
||||
@@ -116,7 +118,7 @@ fun GalleryInfoBottomSheet(
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.keyline_margin)).clickable {
|
||||
if (index == INDEX_PARENT) {
|
||||
UrlOpener.openUrl(context, data[index], true)
|
||||
data[index]?.let { navController.navWithUrl(it) }
|
||||
} else {
|
||||
context tellClipboardWithToast data[index]
|
||||
if (index == INDEX_URL) {
|
||||
|
||||
@@ -158,7 +158,7 @@ class MainActivity : EhActivity() {
|
||||
val action = intent.action
|
||||
if (Intent.ACTION_VIEW == action) {
|
||||
val uri = intent.data ?: return false
|
||||
navController.jumpWithUrl(uri.toString())
|
||||
navController.navWithUrl(uri.toString())
|
||||
} else if (Intent.ACTION_SEND == action) {
|
||||
val type = intent.type
|
||||
if ("text/plain" == type) {
|
||||
|
||||
@@ -35,42 +35,11 @@ import com.hippo.ehviewer.ui.scene.ProgressScene
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
|
||||
object UrlOpener {
|
||||
fun openUrl(
|
||||
context: Context,
|
||||
url: String?,
|
||||
ehUrl: Boolean,
|
||||
galleryDetail: GalleryDetail? = null,
|
||||
) {
|
||||
fun openUrl(context: Context, url: String?) {
|
||||
if (url.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
val intent: Intent
|
||||
val uri = Uri.parse(url)
|
||||
if (ehUrl) {
|
||||
if (galleryDetail != null) {
|
||||
val result = GalleryPageUrlParser.parse(url)
|
||||
if (result != null) {
|
||||
if (result.gid == galleryDetail.gid) {
|
||||
intent = Intent(context, ReaderActivity::class.java)
|
||||
intent.action = ReaderActivity.ACTION_EH
|
||||
intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, galleryDetail)
|
||||
intent.putExtra(ReaderActivity.KEY_PAGE, result.page)
|
||||
context.startActivity(intent)
|
||||
return
|
||||
}
|
||||
} else if (url.startsWith("#c")) {
|
||||
try {
|
||||
intent = Intent(context, ReaderActivity::class.java)
|
||||
intent.action = ReaderActivity.ACTION_EH
|
||||
intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, galleryDetail)
|
||||
intent.putExtra(ReaderActivity.KEY_PAGE, url.replace("#c", "").toInt() - 1)
|
||||
context.startActivity(intent)
|
||||
return
|
||||
} catch (_: NumberFormatException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val customTabsIntent = CustomTabsIntent.Builder()
|
||||
customTabsIntent.setShowTitle(true)
|
||||
try {
|
||||
@@ -82,7 +51,32 @@ object UrlOpener {
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun NavController.jumpWithUrl(url: String): Boolean {
|
||||
fun Context.jumpToReaderByPage(url: String, detail: GalleryDetail): Boolean {
|
||||
fun jump(page: Int) {
|
||||
Intent(this, ReaderActivity::class.java).apply {
|
||||
action = ReaderActivity.ACTION_EH
|
||||
putExtra(ReaderActivity.KEY_GALLERY_INFO, detail)
|
||||
putExtra(ReaderActivity.KEY_PAGE, page)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
GalleryPageUrlParser.parse(url)?.let {
|
||||
if (it.gid == detail.gid) {
|
||||
jump(it.page)
|
||||
return true
|
||||
}
|
||||
}
|
||||
if (url.startsWith("#c")) {
|
||||
runCatching {
|
||||
jump(url.replace("#c", "").toInt() - 1)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@MainThread
|
||||
fun NavController.navWithUrl(url: String): Boolean {
|
||||
if (url.isEmpty()) return false
|
||||
GalleryListUrlParser.parse(url)?.let { lub ->
|
||||
Bundle().apply {
|
||||
|
||||
@@ -210,7 +210,6 @@ fun SignInScreen(windowSizeClass: WindowSizeClass) {
|
||||
UrlOpener.openUrl(
|
||||
requireActivity(context),
|
||||
EhUrl.URL_REGISTER,
|
||||
false,
|
||||
)
|
||||
},
|
||||
Modifier
|
||||
@@ -407,7 +406,6 @@ fun SignInScreen(windowSizeClass: WindowSizeClass) {
|
||||
UrlOpener.openUrl(
|
||||
requireActivity(context),
|
||||
EhUrl.URL_REGISTER,
|
||||
false,
|
||||
)
|
||||
},
|
||||
Modifier
|
||||
|
||||
@@ -75,7 +75,8 @@ import com.hippo.ehviewer.client.data.ListUrlBuilder
|
||||
import com.hippo.ehviewer.client.parser.VoteCommentParser
|
||||
import com.hippo.ehviewer.dao.Filter
|
||||
import com.hippo.ehviewer.ui.UrlOpener
|
||||
import com.hippo.ehviewer.ui.jumpWithUrl
|
||||
import com.hippo.ehviewer.ui.jumpToReaderByPage
|
||||
import com.hippo.ehviewer.ui.navWithUrl
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene.Companion.toStartArgs
|
||||
import com.hippo.text.URLImageGetter
|
||||
import com.hippo.util.ExceptionUtils
|
||||
@@ -485,8 +486,13 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
if (holder is ActualCommentHolder) {
|
||||
val span = holder.comment.currentSpan
|
||||
holder.comment.clearCurrentSpan()
|
||||
val detail = mGalleryDetail ?: return false
|
||||
if (span is URLSpan) {
|
||||
if (!findNavController().jumpWithUrl(span.url)) UrlOpener.openUrl(activity, span.url, true, mGalleryDetail)
|
||||
if (!activity.jumpToReaderByPage(span.url, detail)) {
|
||||
if (!findNavController().navWithUrl(span.url)) {
|
||||
UrlOpener.openUrl(activity, span.url)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showCommentDialog(position, holder.sp)
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
|
||||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -155,6 +156,7 @@ import com.hippo.ehviewer.ui.GalleryInfoBottomSheet
|
||||
import com.hippo.ehviewer.ui.MainActivity
|
||||
import com.hippo.ehviewer.ui.UrlOpener
|
||||
import com.hippo.ehviewer.ui.addToFavorites
|
||||
import com.hippo.ehviewer.ui.login.LocalNavController
|
||||
import com.hippo.ehviewer.ui.removeFromFavorites
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene.Companion.toStartArgs
|
||||
import com.hippo.ehviewer.ui.widget.CrystalCard
|
||||
@@ -349,7 +351,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
val url = galleryDetailUrl
|
||||
val activity: Activity? = mainActivity
|
||||
if (null != url && null != activity) {
|
||||
UrlOpener.openUrl(activity, url, false)
|
||||
UrlOpener.openUrl(activity, url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +526,10 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
fun onGalleryInfoCardClick() {
|
||||
showSheet = true
|
||||
}
|
||||
composeBindingGD?.let { if (showSheet) GalleryInfoBottomSheet(galleryDetail = it) { showSheet = false } }
|
||||
val navController = remember { findNavController() }
|
||||
CompositionLocalProvider(LocalNavController provides navController) {
|
||||
composeBindingGD?.let { if (showSheet) GalleryInfoBottomSheet(galleryDetail = it) { showSheet = false } }
|
||||
}
|
||||
val windowSizeClass = calculateWindowSizeClass(requireActivity())
|
||||
// Padding is not subtracted here to have the same column count as gallery list and preview
|
||||
val totalSpace = LocalConfiguration.current.screenWidthDp
|
||||
@@ -1372,7 +1377,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
}
|
||||
|
||||
R.id.show_definition -> {
|
||||
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(temp), false)
|
||||
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(temp))
|
||||
}
|
||||
|
||||
R.id.add_filter -> {
|
||||
|
||||
@@ -36,6 +36,6 @@ class UrlPreference @JvmOverloads constructor(context: Context, attrs: Attribute
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
UrlOpener.openUrl(context, mUrl, true)
|
||||
UrlOpener.openUrl(context, mUrl)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user