Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Restore state of webview #20084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ class SiteMonitorMapper @Inject constructor(
fun toNoNetworkError(buttonClick: () -> Unit) = SiteMonitorUiState.NoNetworkError(buttonClick = buttonClick)

fun toGenericError(buttonClick: () -> Unit) = SiteMonitorUiState.GenericError(buttonClick = buttonClick)

fun toLoaded() = SiteMonitorUiState.Loaded(siteMonitorUtils.getUserAgent())
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.os.Bundle
import android.util.SparseArray
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -38,6 +39,8 @@ class SiteMonitorParentActivity: AppCompatActivity() {
private var savedStateSparseArray = SparseArray<Fragment.SavedState>()
private var currentSelectItemId = 0

private val parentViewModel: SiteMonitorParentViewModel by viewModels()

@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -53,6 +56,7 @@ class SiteMonitorParentActivity: AppCompatActivity() {
}
setContent {
AppTheme {
parentViewModel.start()
Surface(
modifier = Modifier.fillMaxSize(),
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.wordpress.android.ui.sitemonitor

import android.util.Log
import androidx.lifecycle.MutableLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.viewmodel.ScopedViewModel
import javax.inject.Inject
import javax.inject.Named

@HiltViewModel
class SiteMonitorParentViewModel @Inject constructor(
@param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher
) : ScopedViewModel(bgDispatcher) {
private val _webViewStates = MutableLiveData<Map<SiteMonitorType, SiteMonitorWebViewState?>>(emptyMap())
// val webViewStates: LiveData<Map<SiteMonitorType, SiteMonitorWebViewState?>> = _webViewStates

fun start() {
// todo: understand when the webViewState should be reset
Log.i(javaClass.simpleName, "***=> start: ")
}

fun saveWebViewState(type: SiteMonitorType, state: SiteMonitorWebViewState) {
Log.i(javaClass.simpleName, "***=> saveWebViewState: $type, $state")
_webViewStates.value = _webViewStates.value?.toMutableMap()?.apply {
put(type, state)
}
}

fun getWebViewState(type: SiteMonitorType): SiteMonitorWebViewState? {
Log.i(javaClass.simpleName, "***=> getWebViewState: $type")
return _webViewStates.value?.get(type)
}
}
Loading
Loading