-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting default device orientation
Resolves #85
- Loading branch information
1 parent
fa629e9
commit a2204b6
Showing
32 changed files
with
573 additions
and
69 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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/ammar/wallflow/model/DeviceOrientation.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ammar.wallflow.model | ||
|
||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.Saver | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@JvmInline | ||
value class DeviceOrientation private constructor(internal val value: Int) { | ||
companion object { | ||
val Vertical = DeviceOrientation(0) | ||
val Horizontal = DeviceOrientation(1) | ||
|
||
fun valueOf(value: Int): DeviceOrientation = if (value == 0) { | ||
Vertical | ||
} else { | ||
Horizontal | ||
} | ||
} | ||
} | ||
|
||
val MutableDeviceOrientationSaver = Saver<MutableState<DeviceOrientation>, Int>( | ||
save = { it.value.value }, | ||
restore = { mutableStateOf(DeviceOrientation.valueOf(it)) }, | ||
) |
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
72 changes: 72 additions & 0 deletions
72
app/src/main/java/com/ammar/wallflow/ui/common/RadioButtonListItem.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.ammar.wallflow.ui.common | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.requiredWidth | ||
import androidx.compose.foundation.selection.selectable | ||
import androidx.compose.material3.LocalTextStyle | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.ammar.wallflow.ui.theme.WallFlowTheme | ||
|
||
@Composable | ||
fun RadioButtonListItem( | ||
modifier: Modifier = Modifier, | ||
selected: Boolean = false, | ||
label: @Composable () -> Unit = {}, | ||
onClick: () -> Unit = {}, | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(56.dp) | ||
.selectable( | ||
selected = selected, | ||
onClick = onClick, | ||
role = Role.RadioButton, | ||
) | ||
.padding(horizontal = 16.dp) | ||
.then(modifier), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
RadioButton( | ||
selected = selected, | ||
onClick = null, | ||
) | ||
Spacer(modifier = Modifier.requiredWidth(16.dp)) | ||
CompositionLocalProvider( | ||
LocalTextStyle provides LocalTextStyle.current.merge( | ||
MaterialTheme.typography.bodyLarge, | ||
), | ||
content = label, | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Composable | ||
private fun PreviewRadioButtonListItem() { | ||
WallFlowTheme { | ||
Surface { | ||
RadioButtonListItem( | ||
label = { | ||
Text(text = "Label") | ||
}, | ||
) | ||
} | ||
} | ||
} |
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.