Special handling of the Open Original button

This commit is contained in:
Jackson Harper
2023-05-10 21:39:59 +08:00
parent d03d8b931a
commit c16c5e4ca2
3 changed files with 19 additions and 11 deletions

View File

@ -71,7 +71,7 @@ fun WebReader(
var handled: Boolean? = null
request?.let {
if ((request?.isForMainFrame == true) && (request?.hasGesture() == true) && viewModel != null) {
viewModel?.showOpenLinkSheet(request.url)
viewModel?.showOpenLinkSheet(context, request.url)
handled = true
}
}

View File

@ -160,9 +160,9 @@ fun WebReaderLoadingContainer(slug: String? = null, requestID: String? = null,
val modalBottomSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
confirmStateChange = {
// if (it == ModalBottomSheetValue.Hidden) {
// webReaderViewModel.resetBottomSheet()
// }
if (it == ModalBottomSheetValue.Hidden) {
webReaderViewModel.resetBottomSheet()
}
true
}
)

View File

@ -7,8 +7,6 @@ import android.content.Intent
import android.net.Uri
import android.util.Log
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat.startActivity
import androidx.lifecycle.*
import app.omnivore.omnivore.DatastoreKeys
@ -99,19 +97,29 @@ class WebReaderViewModel @Inject constructor(
bottomSheetStateLiveData.postValue(BottomSheetState.NONE)
}
fun showOpenLinkSheet(uri: Uri) {
currentLink = uri
bottomSheetStateLiveData.postValue(BottomSheetState.LINK)
fun showOpenLinkSheet(context: Context, uri: Uri) {
webReaderParamsLiveData.value?.let {
if (it.item.pageURLString == uri.toString()) {
openLink(context, uri)
} else {
currentLink = uri
bottomSheetStateLiveData.postValue(BottomSheetState.LINK)
}
}
}
fun openCurrentLink(context: Context) {
currentLink?.let {
val browserIntent = Intent(Intent.ACTION_VIEW, it)
startActivity(context, browserIntent, null)
openLink(context, it)
}
bottomSheetStateLiveData.postValue(BottomSheetState.NONE)
}
fun openLink(context: Context, uri: Uri) {
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
startActivity(context, browserIntent, null)
}
fun saveCurrentLink(context: Context) {
currentLink?.let {
viewModelScope.launch {