Skip to content

Commit

Permalink
*demoted dependencies from beta to stable as they where causing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
iZakirSheikh committed Nov 25, 2022
1 parent 5515c2b commit d110e14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
42 changes: 28 additions & 14 deletions app/src/main/java/com/primex/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.LocalAbsoluteElevation
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AddCircle
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.outlined.Menu
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -19,10 +22,7 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.tooling.preview.Preview
import com.primex.preferences.*
import com.primex.sample.ui.theme.SampleTheme
import com.primex.ui.Button
import com.primex.ui.Preference
import com.primex.ui.SliderPreference
import com.primex.ui.activity
import com.primex.ui.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.first
Expand All @@ -31,7 +31,7 @@ import kotlin.coroutines.EmptyCoroutineContext


private val KEY_COUNTER =
intPreferenceKey("Counter3", false, object : IntSaver<Boolean>{
intPreferenceKey("Counter3", false, object : IntSaver<Boolean> {
override fun save(value: Boolean): Int = if (value) 1 else 0

override fun restore(value: Int): Boolean = value == 1
Expand All @@ -49,13 +49,14 @@ class MainActivity : ComponentActivity() {
SampleTheme {
Box(modifier = Modifier.fillMaxSize()) {

val counter by preferences.observeAsState(key = KEY_COUNTER)

Button(label = "$counter", onClick = {
preferences[KEY_COUNTER] = !counter
})
/* val counter by preferences.observeAsState(key = KEY_COUNTER)
Button(label = "$counter", onClick = {
preferences[KEY_COUNTER] = !counter
})
*/

PreviewPerf()
}
}
}
Expand Down Expand Up @@ -83,8 +84,8 @@ fun DefaultPreview() {
fun <S, O> preference(key: Key<S, O>): State<O?> {
val activity = LocalContext.activity
require(activity is MainActivity)
val preferences =activity.preferences
val flow = when(key){
val preferences = activity.preferences
val flow = when (key) {
is Key.Key1 -> preferences[key]
is Key.Key2 -> preferences[key]
}
Expand All @@ -93,7 +94,7 @@ fun <S, O> preference(key: Key<S, O>): State<O?> {
runBlocking { flow.first() }
}

return produceState(first, flow, EmptyCoroutineContext){
return produceState(first, flow, EmptyCoroutineContext) {
flow.collectLatest {
value = it
}
Expand All @@ -103,7 +104,20 @@ fun <S, O> preference(key: Key<S, O>): State<O?> {

@Composable
private fun PreviewPerf() {
Column {
val x = rememberScrollState()
Column(modifier = Modifier.verticalScroll(x)) {


SwitchPreference(checked = false,
title = AnnotatedString("Dark Mode"),
summery = AnnotatedString("Toggle Darl Mode"),
icon = Icons.Outlined.Menu,
onCheckedChange = { new: Boolean ->
/*
set(Audiofy.NIGHT_MODE, if (new) NightMode.YES else NightMode.NO)
activity.showAd(force = true)
*/
})

SliderPreference(
title = AnnotatedString("Color Secondary"),
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buildscript {
ext {
compose_version = '1.4.0-alpha02'
kotlin_version = '1.7.21'
compiler_v = "1.4.0-alpha02"
compose_version = '1.3.1'
kotlin_version = '1.7.20'
compiler_v = "1.3.2"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
Expand Down

0 comments on commit d110e14

Please sign in to comment.