-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
445 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 23 additions & 2 deletions
25
core/src/main/java/com/m3u/core/architecture/preferences/LocalPreferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
package com.m3u.core.architecture.preferences | ||
|
||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import dagger.hilt.EntryPoint | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.EntryPointAccessors | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
val LocalPreferences = compositionLocalOf<Preferences> { error("Please provide pref.") } | ||
@Composable | ||
fun hiltPreferences(): Preferences { | ||
val context = LocalContext.current | ||
return remember { | ||
val applicationContext = context.applicationContext ?: throw IllegalStateException() | ||
EntryPointAccessors | ||
.fromApplication<PreferencesEntryPoint>(applicationContext) | ||
.preferences | ||
} | ||
} | ||
|
||
@EntryPoint | ||
@InstallIn(SingletonComponent::class) | ||
private interface PreferencesEntryPoint { | ||
val preferences: Preferences | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
package com.m3u.data.service | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.m3u.core.wrapper.Message | ||
import dagger.hilt.EntryPoint | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.EntryPointAccessors | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
interface Messager { | ||
fun emit(message: Message) | ||
fun emit(message: String) | ||
val message: StateFlow<Message> | ||
} | ||
|
||
@EntryPoint | ||
@InstallIn(SingletonComponent::class) | ||
private interface MessagerEntryPoint { | ||
val messager: Messager | ||
} | ||
|
||
@Composable | ||
fun collectMessageAsState(): State<Message> { | ||
val context = LocalContext.current | ||
return remember { | ||
val applicationContext = context.applicationContext ?: throw IllegalStateException() | ||
EntryPointAccessors | ||
.fromApplication<MessagerEntryPoint>(applicationContext) | ||
.messager | ||
.message | ||
} | ||
.collectAsState() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.