Skip to content

Commit

Permalink
👕 code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
theapache64 committed Mar 25, 2021
1 parent 991f830 commit 3383e33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/main/kotlin/com/theapache64/klokk/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.theapache64.klokk.composable.BottomToolBar
import com.theapache64.klokk.composable.Clock
import com.theapache64.klokk.movement.alphabet.TextMatrixGenerator
import com.theapache64.klokk.movement.core.Movement
import com.theapache64.klokk.theme.Black
import com.theapache64.klokk.theme.KlokkTheme
Expand All @@ -22,10 +23,6 @@ import kotlinx.coroutines.launch
// Configs
const val COLUMNS = 15
const val ROWS = 8
const val LETTER_WIDTH = 3
const val MAX_CHARS = COLUMNS / LETTER_WIDTH
const val DIGIT_COLUMNS = 3
const val DIGIT_ROWS = 6
const val PADDING = 100
const val CLOCK_SIZE = 60
const val CLOCKS_CONTAINER_WIDTH = CLOCK_SIZE * COLUMNS
Expand All @@ -34,7 +31,6 @@ const val ENJOY_TIME_IN_MILLIS = 1000L
const val IS_DEBUG = false
private val BACKGROUND_COLOR = Black


@ExperimentalFoundationApi
fun main() {

Expand All @@ -44,7 +40,11 @@ fun main() {
size = IntSize(CLOCKS_CONTAINER_WIDTH + PADDING, CLOCKS_CONTAINER_HEIGHT + PADDING + 40),
) {

val infiniteTimeLoop = rememberCoroutineScope()

/**
* To control the infinite animation loop
*/
val infiniteLoopScope = rememberCoroutineScope()

// To hold and control movement transition
var activeMovement by remember { mutableStateOf<Movement>(Movement.StandBy) }
Expand Down Expand Up @@ -119,9 +119,11 @@ fun main() {
BottomToolBar(
activeMovement = activeMovement,
isAnimPlaying = shouldPlayAutoAnim,

// TODO :WIP
textInput = textInput,
onTextInputChanged = { newInput ->
if (newInput.length <= MAX_CHARS) {
if (newInput.length <= TextMatrixGenerator.MAX_CHARS) {
textInput = newInput.trim().toUpperCase()

if (textInput.isEmpty()) {
Expand All @@ -138,7 +140,7 @@ fun main() {

onShowTimeClicked = {
shouldPlayAutoAnim = false // stop auto play
infiniteTimeLoop.launch {
infiniteLoopScope.launch {
while (true) {
activeMovement = Movement.Time() // then show time
delay(activeMovement.durationInMillis.toLong())
Expand All @@ -147,7 +149,7 @@ fun main() {
},
onPlayClicked = {
shouldPlayAutoAnim = true
infiniteTimeLoop.cancel()
infiniteLoopScope.cancel()
},
onStopClicked = {
shouldPlayAutoAnim = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theapache64.klokk.movement.alphabet

import com.theapache64.klokk.COLUMNS
import com.theapache64.klokk.model.ClockData
import com.theapache64.klokk.movement.StandByMatrixGenerator
import com.theapache64.klokk.movement.core.MatrixGenerator
Expand All @@ -11,6 +12,10 @@ import com.theapache64.klokk.movement.core.Movement
class TextMatrixGenerator(data: Movement.Text) : MatrixGenerator<Movement.Text>(data) {

companion object {

private const val LETTER_WIDTH = 3
const val MAX_CHARS = COLUMNS / LETTER_WIDTH

private val keyMap by lazy {
mapOf(
'A' to AMatrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sealed class Movement(
}

/**
*
* TODO :WIP
*/
data class Text(
val text: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.theapache64.klokk.movement.time

import com.theapache64.klokk.DIGIT_COLUMNS
import com.theapache64.klokk.DIGIT_ROWS
import com.theapache64.klokk.model.ClockData
import com.theapache64.klokk.movement.StandByMatrixGenerator
import com.theapache64.klokk.movement.core.MatrixGenerator
Expand All @@ -15,6 +13,9 @@ import java.text.SimpleDateFormat
class TimeMatrixGenerator(data: Movement.Time) : MatrixGenerator<Movement.Time>(data) {
companion object {

private const val DIGIT_COLUMNS = 3
private const val DIGIT_ROWS = 6

private val timeFormat = SimpleDateFormat("HHmmss")

private val h1Position = Pair(1, 1)
Expand Down

0 comments on commit 3383e33

Please sign in to comment.