-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
24 changed files
with
734 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package live.mehiz.mpvkt.database | ||
|
||
import androidx.room.migration.Migration | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
|
||
val Migrations: Array<Migration> = arrayOf( | ||
MIGRATION1to2 | ||
) | ||
|
||
private object MIGRATION1to2 : Migration(1, 2) { | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
listOf("subDelay", "secondarySubDelay", "audioDelay").forEach { | ||
db.execSQL("ALTER TABLE PlaybackStateEntity ADD COLUMN $it INTEGER NOT NULL DEFAULT 0") | ||
} | ||
db.execSQL("ALTER TABLE PlaybackStateEntity ADD COLUMN subSpeed REAL NOT NULL DEFAULT 0") | ||
} | ||
} |
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
132 changes: 132 additions & 0 deletions
132
app/src/main/java/live/mehiz/mpvkt/presentation/OutlinedNumericChooser.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,132 @@ | ||
package live.mehiz.mpvkt.presentation | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.AddCircle | ||
import androidx.compose.material.icons.filled.RemoveCircle | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.unit.dp | ||
import live.mehiz.mpvkt.R | ||
|
||
@Composable | ||
fun OutlinedNumericChooser( | ||
value: Int, | ||
onChange: (Int) -> Unit, | ||
max: Int, | ||
step: Int, | ||
modifier: Modifier = Modifier, | ||
min: Int = 0, | ||
suffix: (@Composable () -> Unit)? = null, | ||
label: (@Composable () -> Unit)? = null, | ||
) { | ||
assert(max > min) { "min can't be larger than max ($min > $max)" } | ||
Row( | ||
modifier = modifier, | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
) { | ||
RepeatingIconButton(onClick = { onChange(value - step) }) { | ||
Icon(Icons.Filled.RemoveCircle, null) | ||
} | ||
var valueString by remember { mutableStateOf("$value") } | ||
LaunchedEffect(value) { | ||
if (valueString.isBlank()) return@LaunchedEffect | ||
valueString = value.toString() | ||
} | ||
OutlinedTextField( | ||
label = label, | ||
value = valueString, | ||
onValueChange = { newValue -> | ||
if (newValue.isBlank()) { | ||
valueString = newValue | ||
onChange(0) | ||
} | ||
runCatching { | ||
val intValue = newValue.toInt() | ||
onChange(intValue) | ||
valueString = newValue | ||
} | ||
}, | ||
isError = value > max || value < min, | ||
supportingText = { | ||
if (value > max) Text(stringResource(R.string.numeric_chooser_value_too_big)) | ||
if (value < min) Text(stringResource(R.string.numeric_chooser_value_too_small)) | ||
}, | ||
suffix = suffix, | ||
modifier = Modifier.weight(1f), | ||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), | ||
) | ||
RepeatingIconButton(onClick = { onChange(value + step) }) { | ||
Icon(Icons.Filled.AddCircle, null) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun OutlinedNumericChooser( | ||
value: Float, | ||
onChange: (Float) -> Unit, | ||
max: Float, | ||
step: Float, | ||
modifier: Modifier = Modifier, | ||
min: Float = 0f, | ||
suffix: (@Composable () -> Unit)? = null, | ||
label: (@Composable () -> Unit)? = null, | ||
) { | ||
assert(max > min) { "min can't be larger than max ($min > $max)" } | ||
Row( | ||
modifier, | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
) { | ||
RepeatingIconButton(onClick = { onChange(value - step) }) { | ||
Icon(Icons.Filled.RemoveCircle, null) | ||
} | ||
var valueString by remember { mutableStateOf("$value") } | ||
LaunchedEffect(value) { | ||
if (valueString.isBlank()) return@LaunchedEffect | ||
valueString = value.toString().dropLastWhile { it == '0' }.dropLastWhile { it == '.' } | ||
} | ||
OutlinedTextField( | ||
value = valueString, | ||
label = label, | ||
onValueChange = { newValue -> | ||
if (newValue.isBlank()) { | ||
valueString = newValue | ||
onChange(0f) | ||
} | ||
runCatching { | ||
if (newValue.startsWith('.')) return@runCatching | ||
val floatValue = newValue.toFloat() | ||
onChange(floatValue) | ||
valueString = newValue | ||
} | ||
}, | ||
isError = value > max || value < min, | ||
supportingText = { | ||
if (value > max) Text(stringResource(R.string.numeric_chooser_value_too_big)) | ||
if (value < min) Text(stringResource(R.string.numeric_chooser_value_too_small)) | ||
}, | ||
modifier = Modifier.weight(1f), | ||
suffix = suffix, | ||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), | ||
) | ||
RepeatingIconButton(onClick = { onChange(value + step) }) { | ||
Icon(Icons.Filled.AddCircle, null) | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/main/java/live/mehiz/mpvkt/presentation/RepeatingIconButton.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,60 @@ | ||
package live.mehiz.mpvkt.presentation | ||
|
||
import android.view.MotionEvent | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.pointer.pointerInteropFilter | ||
import kotlinx.coroutines.delay | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
@Composable | ||
fun RepeatingIconButton( | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, | ||
maxDelayMillis: Long = 750, | ||
minDelayMillis: Long = 5, | ||
delayDecayFactor: Float = .25f, | ||
content: @Composable () -> Unit, | ||
) { | ||
val currentClickListener by rememberUpdatedState(onClick) | ||
var pressed by remember { mutableStateOf(false) } | ||
|
||
IconButton( | ||
modifier = modifier.pointerInteropFilter { | ||
pressed = when (it.action) { | ||
MotionEvent.ACTION_DOWN -> true | ||
|
||
else -> false | ||
} | ||
|
||
true | ||
}, | ||
onClick = {}, | ||
enabled = enabled, | ||
interactionSource = interactionSource, | ||
content = content, | ||
) | ||
|
||
LaunchedEffect(pressed, enabled) { | ||
var currentDelayMillis = maxDelayMillis | ||
|
||
while (enabled && pressed) { | ||
currentClickListener() | ||
delay(currentDelayMillis) | ||
currentDelayMillis = | ||
(currentDelayMillis - (currentDelayMillis * delayDecayFactor)) | ||
.toLong().coerceAtLeast(minDelayMillis) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.