Skip to content

Commit

Permalink
feat: クリップ一覧画面でも共通エラーハンドラーを使うようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jan 10, 2024
1 parent 2bed164 commit c5f89f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/features/clip/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
implementation project(path: ':modules:common_viewmodel')
implementation project(path: ':modules:common_compose')
implementation project(path: ':modules:features:note')
implementation project(path: ':modules:common_android')
testImplementation libs.junit
androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import dagger.hilt.android.AndroidEntryPoint
import net.pantasystem.milktea.common.ui.ApplyTheme
import net.pantasystem.milktea.common_android_ui.error.UserActionAppGlobalErrorListener
import net.pantasystem.milktea.common_compose.MilkteaStyleConfigApplyAndTheme
import net.pantasystem.milktea.common_navigation.ClipDetailNavigation
import net.pantasystem.milktea.common_navigation.ClipListNavigation
Expand All @@ -29,6 +30,9 @@ class ClipListActivity : AppCompatActivity() {
@Inject
internal lateinit var configRepository: LocalConfigRepository

@Inject
internal lateinit var userActionAppGlobalErrorListener: UserActionAppGlobalErrorListener

private val mode: ClipListNavigationArgs.Mode by lazy {
intent.getStringExtra(ClipListNavigationImpl.EXTRA_MODE)?.let {
ClipListNavigationArgs.Mode.valueOf(it)
Expand All @@ -41,6 +45,7 @@ class ClipListActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

applyTheme()
userActionAppGlobalErrorListener(lifecycle, supportFragmentManager)

setContent {
val uiState by clipListViewModel.uiState.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import net.pantasystem.milktea.app_store.account.AccountStore
import net.pantasystem.milktea.app_store.handler.AppGlobalError
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorStore
import net.pantasystem.milktea.common.Logger
import net.pantasystem.milktea.common.ResultState
import net.pantasystem.milktea.common.asLoadingStateFlow
import net.pantasystem.milktea.common.initialState
import net.pantasystem.milktea.common_android.resource.StringSource
import net.pantasystem.milktea.common_navigation.ClipListNavigationArgs
import net.pantasystem.milktea.model.account.Account
import net.pantasystem.milktea.model.clip.Clip
Expand All @@ -26,6 +29,7 @@ class ClipListViewModel @Inject constructor(
private val accountStore: AccountStore,
private val toggleClipAddToTabUseCase: ToggleClipAddToTabUseCase,
private val savedStateHandle: SavedStateHandle,
private val userActionAppGlobalErrorStore: UserActionAppGlobalErrorStore,
) : ViewModel() {

private val logger by lazy(LazyThreadSafetyMode.NONE) {
Expand Down Expand Up @@ -113,7 +117,16 @@ class ClipListViewModel @Inject constructor(
toggleClipAddToTabUseCase(
clipItemState.clip,
savedStateHandle[ClipListNavigationImpl.EXTRA_ADD_TAB_TO_ACCOUNT_ID]
)
).onFailure {
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"ClipListViewModel.onToggleAddToTabButtonClicked",
AppGlobalError.ErrorLevel.Error,
StringSource.invoke("add/remove clip to tab failed"),
it
)
)
}
}
}

Expand Down

0 comments on commit c5f89f8

Please sign in to comment.