navigate to web reader via navhost when item card is tapped
This commit is contained in:
@ -13,6 +13,7 @@ import com.google.android.gms.tasks.Task
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@ -36,6 +37,10 @@ class LoginViewModel @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.asLiveData()
|
||||
|
||||
fun getAuthCookieString(): String? = runBlocking {
|
||||
datastoreRepo.getString(DatastoreKeys.omnivoreAuthCookieString)
|
||||
}
|
||||
|
||||
fun login(email: String, password: String) {
|
||||
val emailLogin = RetrofitHelper.getInstance().create(EmailLoginSubmit::class.java)
|
||||
|
||||
@ -121,8 +126,6 @@ class LoginViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
if (result.body()?.authCookieString != null) {
|
||||
Log.d("loggo", result.body()?.authCookieString!!)
|
||||
|
||||
datastoreRepo.putString(
|
||||
DatastoreKeys.omnivoreAuthCookieString, result.body()?.authCookieString!!
|
||||
)
|
||||
|
||||
@ -119,14 +119,12 @@ fun LogoutButton(actionHandler: () -> Unit) {
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Composable
|
||||
fun ArticleWebView(slug: String) {
|
||||
fun ArticleWebView(slug: String, authCookieString: String) {
|
||||
WebView.setWebContentsDebuggingEnabled(true)
|
||||
|
||||
val authCookieString = "auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIwODFkZThlOC01ODU0LTExZWMtODY4ZS03ZjU0ZjhiMzY0NGEiLCJpYXQiOjE2NjE4OTA1NjB9.zDE6SOGgRKKV7QuZUIsxEzb_M7o2pyTwshI_Lc_C8Co; Expires=Wed, 30 Aug 2023 20:16:00 GMT; HttpOnly; secure;"
|
||||
// val authCookieString = "auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIwODFkZThlOC01ODU0LTExZWMtODY4ZS03ZjU0ZjhiMzY0NGEiLCJpYXQiOjE2NjE4OTA1NjB9.zDE6SOGgRKKV7QuZUIsxEzb_M7o2pyTwshI_Lc_C8Co; Expires=Wed, 30 Aug 2023 20:16:00 GMT; HttpOnly; secure;"
|
||||
val url = "https://demo.omnivore.app/app/me/$slug"
|
||||
|
||||
// Adding a WebView inside AndroidView
|
||||
// with layout as full screen
|
||||
AndroidView(factory = {
|
||||
WebView(it).apply {
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
|
||||
@ -3,6 +3,7 @@ package app.omnivore.omnivore.ui.root
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
@ -38,7 +39,10 @@ fun PrimaryNavigator(loginViewModel: LoginViewModel, homeViewModel: HomeViewMode
|
||||
}
|
||||
|
||||
composable("WebReader/{slug}") {
|
||||
ArticleWebView(it.arguments?.getString("slug") ?: "")
|
||||
ArticleWebView(
|
||||
it.arguments?.getString("slug") ?: "",
|
||||
authCookieString = loginViewModel.getAuthCookieString() ?: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user