Skip to content

Commit

Permalink
fix: replace uncertain meaning return types #20
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Nov 4, 2023
1 parent 57b3014 commit c158ba3
Show file tree
Hide file tree
Showing 32 changed files with 163 additions and 267 deletions.
3 changes: 2 additions & 1 deletion androidApp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.apk
/src/test
/src/androidTest
/release
/release
/debug
20 changes: 0 additions & 20 deletions androidApp/debug/output-metadata.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import androidx.compose.animation.slideOutVertically
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.m3u.features.about.navigation.aboutScreen
import com.m3u.features.console.navigation.consoleScreen
import com.m3u.features.feed.navigation.feedScreen
import com.m3u.features.live.navigation.livePlaylistScreen
import com.m3u.features.live.navigation.liveScreen
import com.m3u.i18n.R.string
import com.m3u.material.model.LocalNavController
import com.m3u.ui.Destination
import com.m3u.ui.LocalHelper
import com.m3u.ui.Navigate

@Composable
fun M3UNavHost(
navController: NavHostController,
currentPage: Int,
onCurrentPage: (Int) -> Unit,
navigate: Navigate,
Expand All @@ -30,6 +29,7 @@ fun M3UNavHost(
) {
val helper = LocalHelper.current
val context = LocalContext.current
val navController = LocalNavController.current
NavHost(
navController = navController,
startDestination = startDestination,
Expand Down
21 changes: 13 additions & 8 deletions androidApp/src/main/java/com/m3u/androidApp/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package com.m3u.androidApp.ui

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.m3u.androidApp.navigation.M3UNavHost
import com.m3u.material.model.LocalNavController
import com.m3u.ui.EmptyHelper
import com.m3u.ui.EventHandler
import com.m3u.ui.Helper
Expand Down Expand Up @@ -40,7 +42,7 @@ fun App(

AppScaffold(
title = title,
snacker = snacker,
snacker = snacker.value,
actionsFactory = { actions },
rootDestination = rootDestination,
fob = fob,
Expand All @@ -54,13 +56,16 @@ fun App(
cinemaMode = cinemaMode,
isPlaying = isPlaying
) {
M3UNavHost(
navController = appState.navController,
currentPage = appState.currentPage,
onCurrentPage = { appState.currentPage = it },
navigate = appState::navigate,
modifier = Modifier.fillMaxSize()
)
CompositionLocalProvider(
LocalNavController provides appState.navController
) {
M3UNavHost(
currentPage = appState.currentPage,
onCurrentPage = { appState.currentPage = it },
navigate = appState::navigate,
modifier = Modifier.fillMaxSize()
)
}
}

EventHandler(state.rootDestination) { root ->
Expand Down
4 changes: 2 additions & 2 deletions androidApp/src/main/java/com/m3u/androidApp/ui/AppScaffold.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.m3u.material.components.AppTopBar
import com.m3u.material.components.IconButton
import com.m3u.material.model.LocalSpacing
import com.m3u.material.model.Theme
import com.m3u.ui.Action
import com.m3u.ui.ActionsFactory
import com.m3u.ui.Destination
import com.m3u.ui.Fob
import com.m3u.ui.Helper
Expand All @@ -39,7 +39,7 @@ import kotlin.time.Duration.Companion.milliseconds
internal fun AppScaffold(
title: String,
snacker: String,
actionsFactory: () -> List<Action>,
actionsFactory: ActionsFactory,
rootDestination: Destination.Root?,
fob: Fob?,
isSystemBarVisible: Boolean,
Expand Down
11 changes: 2 additions & 9 deletions core/src/main/java/com/m3u/core/util/compose/ObservableState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.snapshots.StateFactoryMarker

@StateFactoryMarker
fun <T> observableStateOf(
delegate: MutableState<T>,
onChanged: (T) -> Unit
): MutableState<T> {
return ObservableState(delegate, onChanged)
}

@StateFactoryMarker
fun <T> observableStateOf(
value: T,
onChanged: (T) -> Unit
): MutableState<T> {
return ObservableState(mutableStateOf(value), onChanged)
val delegate = mutableStateOf(value)
return ObservableState(delegate, onChanged)
}

private class ObservableState<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.m3u.core.util.context

import android.content.SharedPreferences
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import com.m3u.core.util.compose.observableStateOf
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -78,6 +77,6 @@ private fun <T> SharedPreferences.delegateAsState(
getter: SharedPreferences.(String, T) -> T,
setter: SharedPreferences.Editor.(String, T) -> SharedPreferences.Editor
): MutableState<T> = observableStateOf(
delegate = mutableStateOf(getter(key, defaultValue)),
value = getter(key, defaultValue),
onChanged = { edit().setter(key, it).apply() }
)
9 changes: 0 additions & 9 deletions data/src/main/java/com/m3u/data/api/DropboxApi.kt

This file was deleted.

1 change: 0 additions & 1 deletion data/src/main/java/com/m3u/data/contract/Apis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ package com.m3u.data.contract

object Apis {
const val GITHUB_BASE_URL = "https://api.github.com"
const val DROPBOX_BASE_URL = "https://api.dropboxapi.com/2"
}
9 changes: 0 additions & 9 deletions data/src/main/java/com/m3u/data/di/ApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.m3u.data.di

import com.m3u.core.architecture.configuration.SharedConfiguration
import com.m3u.core.util.serialization.asConverterFactory
import com.m3u.data.api.DropboxApi
import com.m3u.data.api.GithubApi
import com.m3u.data.contract.Apis
import dagger.Module
Expand Down Expand Up @@ -59,12 +58,4 @@ internal object ApiModule {
.baseUrl(Apis.GITHUB_BASE_URL)
.build()
.create()

@Provides
fun provideDropboxApi(
builder: Retrofit.Builder
): DropboxApi = builder
.baseUrl(Apis.DROPBOX_BASE_URL)
.build()
.create()
}
3 changes: 2 additions & 1 deletion data/src/main/java/com/m3u/data/logger/UiLogger.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.m3u.data.logger

import com.m3u.core.architecture.Logger
import com.m3u.data.service.Message
import com.m3u.data.service.UiService
import javax.inject.Inject

Expand All @@ -14,7 +15,7 @@ class UiLogger @Inject constructor(
private val logger: Logger
) : Logger {
override fun log(text: String) {
uiService.snack(text)
uiService.snack(Message(text))
}

override fun log(throwable: Throwable) {
Expand Down
6 changes: 0 additions & 6 deletions data/src/main/java/com/m3u/data/repository/CloudRepository.kt

This file was deleted.

This file was deleted.

15 changes: 11 additions & 4 deletions data/src/main/java/com/m3u/data/service/UiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ package com.m3u.data.service

import kotlinx.coroutines.flow.StateFlow

@JvmInline
value class Message(val value: String) {
companion object {
val Empty = Message("")
}
}

interface UiService {
fun snack(message: String)
fun toast(message: String)
val snacker: StateFlow<String>
val toaster: StateFlow<String>
fun snack(message: Message)
fun toast(message: Message)
val snacker: StateFlow<Message>
val toaster: StateFlow<Message>
}
19 changes: 10 additions & 9 deletions data/src/main/java/com/m3u/data/service/impl/UiServiceImpl.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.m3u.data.service.impl

import com.m3u.data.service.Message
import com.m3u.data.service.UiService
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
Expand All @@ -14,27 +15,27 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

class UiServiceImpl @Inject constructor() : UiService {
override fun snack(message: String) {
override fun snack(message: Message) {
MainScope().launch {
_snacker.notify(message)
}
}

override fun toast(message: String) {
override fun toast(message: Message) {
MainScope().launch {
_toaster.notify(message)
}
}

private val _snacker = MutableStateFlow("")
override val snacker: StateFlow<String> get() = _snacker.asStateFlow()
private val _snacker = MutableStateFlow(Message.Empty)
override val snacker: StateFlow<Message> get() = _snacker.asStateFlow()

private val _toaster = MutableStateFlow("")
override val toaster: StateFlow<String> get() = _toaster.asStateFlow()
private val _toaster = MutableStateFlow(Message.Empty)
override val toaster: StateFlow<Message> get() = _toaster.asStateFlow()

private var job: Job? = null
private suspend fun MutableStateFlow<String>.notify(
value: String,
private suspend fun MutableStateFlow<Message>.notify(
value: Message,
duration: Duration = 3.seconds
) {
job?.cancel()
Expand All @@ -44,7 +45,7 @@ class UiServiceImpl @Inject constructor() : UiService {
delay(duration)
}.apply {
invokeOnCompletion {
this@notify.value = ""
this@notify.value = Message.Empty
}
}
}
Expand Down
Loading

0 comments on commit c158ba3

Please sign in to comment.