Skip to content

Commit 8033f8a

Browse files
VelorumSDeweyReed
authored andcommitted
Display step name above the timer
1 parent 699caa3 commit 8033f8a

File tree

9 files changed

+123
-4
lines changed

9 files changed

+123
-4
lines changed

app-backup/src/main/java/xyz/aprildown/timer/app/backup/AppPreferencesProviderImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import xyz.aprildown.timer.app.base.data.PreferenceData.getTypeColor
1313
import xyz.aprildown.timer.app.base.data.PreferenceData.oneLayout
1414
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneFourActions
1515
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneTimeSize
16+
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingStep
1617
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingTimingBar
1718
import xyz.aprildown.timer.app.base.data.PreferenceData.saveTypeColor
1819
import xyz.aprildown.timer.app.base.data.PreferenceData.shouldNotifierPlusGoBack
@@ -284,6 +285,7 @@ private class AudioTypePreferenceItem : PreferenceItem {
284285
private class OneLayoutPreferenceItem : PreferenceItem {
285286
override fun storeToMap(context: Context, map: MutableMap<String, String>) {
286287
map[KEY_LAYOUT] = context.oneLayout
288+
map[KEY_ONE_STEP] = context.oneOneUsingStep.toString()
287289
map[KEY_ONE_BAR] = context.oneOneUsingTimingBar.toString()
288290
map[KEY_ONE_SIZE] = context.oneOneTimeSize.toString()
289291
map[KEY_FOUR_ACTIONS] = context.oneOneFourActions.joinToString(separator = ",")
@@ -298,6 +300,9 @@ private class OneLayoutPreferenceItem : PreferenceItem {
298300
prefs.ifHasKey(KEY_LAYOUT) {
299301
editor.putString(KEY_LAYOUT, it)
300302
}
303+
prefs.ifHasKey(KEY_ONE_STEP) {
304+
context.oneOneUsingStep = it.toBoolean()
305+
}
301306
prefs.ifHasKey(KEY_ONE_BAR) {
302307
context.oneOneUsingTimingBar = it.toBoolean()
303308
}
@@ -314,6 +319,7 @@ private class OneLayoutPreferenceItem : PreferenceItem {
314319

315320
companion object {
316321
private const val KEY_LAYOUT = PreferenceData.KEY_ONE_LAYOUT
322+
private const val KEY_ONE_STEP = PreferenceData.PREF_ONE_LAYOUT_ONE_STEP
317323
private const val KEY_ONE_BAR = PreferenceData.PREF_ONE_LAYOUT_ONE_TIMING_BAR
318324
private const val KEY_ONE_SIZE = PreferenceData.PREF_ONE_LAYOUT_ONE_TIME_SIZE
319325
private const val KEY_FOUR_ACTIONS = PreferenceData.PREF_ONE_LAYOUT_ONE_ACTIONS

app-base/src/main/java/xyz/aprildown/timer/app/base/data/PreferenceData.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ object PreferenceData {
180180

181181
// region One Layout: One
182182

183+
const val PREF_ONE_LAYOUT_ONE_STEP = "pref_one_one_step"
184+
var Context.oneOneUsingStep: Boolean
185+
get() = safeSharedPreference.getBoolean(PREF_ONE_LAYOUT_ONE_STEP, false)
186+
set(value) = safeSharedPreference.edit { putBoolean(PREF_ONE_LAYOUT_ONE_STEP, value) }
187+
183188
const val PREF_ONE_LAYOUT_ONE_TIMING_BAR = "pref_one_one_timing_bar"
184189
var Context.oneOneUsingTimingBar: Boolean
185190
get() = safeSharedPreference.getBoolean(PREF_ONE_LAYOUT_ONE_TIMING_BAR, false)

app-base/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
<string name="one_shortcut_name">Shortcut name</string>
348348
<string name="one_shortcut_open_on_click">Open timer screen on click</string>
349349

350+
<string name="one_layout_step">Step</string>
350351
<string name="one_layout_bar">Timing Bar</string>
351352
<string name="one_layout_time_size">Time Text Size</string>
352353

app-intro/src/main/java/xyz/aprildown/timer/app/intro/start/StartRunInstructionView.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ internal class StartRunInstructionView : InstructionView<LayoutIntroStartRunBind
4242
text = (timer.steps.first() as StepEntity.Step).length.produceTime()
4343
}
4444

45+
findViewById<TextView>(RTimerOne.id.textOneStep).run {
46+
textSize = context.dp(context.oneOneTimeSize)
47+
text = (timer.steps.first() as StepEntity.Step).label
48+
}
49+
4550
findViewById<TextView>(RTimerOne.id.textOneLoop)
4651
.text = index.getNiceLoopString(max = timer.loop)
4752

app-timer-one/src/main/java/xyz/aprildown/timer/app/timer/one/OneFragment.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint
1919
import xyz.aprildown.timer.app.base.data.PreferenceData
2020
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneFourActions
2121
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneTimeSize
22+
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingStep
2223
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingTimingBar
2324
import xyz.aprildown.timer.app.base.data.PreferenceData.timePanels
2425
import xyz.aprildown.timer.app.base.utils.produceTime
@@ -213,6 +214,11 @@ class OneFragment :
213214

214215
private fun applySettings(binding: FragmentOneBinding) {
215216
val context = binding.root.context
217+
218+
binding.textOneStep.textSize = context.dp(context.oneOneTimeSize)
219+
binding.layoutTextOneStep.visibility = if (context.oneOneUsingStep) View.VISIBLE else View.GONE
220+
binding.textOneStep.isSelected = true // to allow it to scroll horizontally
221+
216222
if (context.oneOneUsingTimingBar) {
217223
val mpb = binding.stubTimingBar.inflate() as LinearProgressIndicator
218224
viewModel.timerCurrentTime.observe(viewLifecycleOwner) {
@@ -289,11 +295,25 @@ class OneFragment :
289295
viewModel.timerCurrentIndex.observe(viewLifecycleOwner) { index ->
290296
if (index == null) return@observe
291297
val totalLoop = viewModel.timer.value?.loop ?: return@observe
298+
binding.textOneStep.setTextIfChanged(when (index) {
299+
is TimerIndex.Start -> viewModel.timer.value?.startStep?.label
300+
is TimerIndex.Step -> (viewModel.timer.value?.steps?.get(index.stepIndex) as StepEntity.Step).label
301+
is TimerIndex.Group -> ((viewModel.timer.value?.steps?.get(index.stepIndex) as StepEntity.Group).steps[index.groupStepIndex.stepIndex] as StepEntity.Step).label
302+
is TimerIndex.End -> viewModel.timer.value?.endStep?.label
303+
else -> ""
304+
})
292305
binding.textOneLoop.setTextIfChanged(index.getNiceLoopString(totalLoop))
293306
binding.listOneSteps.toIndex(index)
294307
}
295308
viewModel.timer.observe(viewLifecycleOwner) { timer ->
296309
if (timer == null) return@observe
310+
binding.textOneStep.setTextIfChanged(when (val currentIndex = viewModel.timerCurrentIndex.value) {
311+
is TimerIndex.Start -> timer.startStep?.label
312+
is TimerIndex.Step -> (timer.steps[currentIndex.stepIndex] as StepEntity.Step).label
313+
is TimerIndex.Group -> ((timer.steps[currentIndex.stepIndex] as StepEntity.Group).steps[currentIndex.groupStepIndex.stepIndex] as StepEntity.Step).label
314+
is TimerIndex.End -> timer.endStep?.label
315+
else -> ""
316+
})
297317
binding.listOneSteps.setTimer(timer)
298318
}
299319
viewModel.timerCurrentState.observe(viewLifecycleOwner) { state ->

app-timer-one/src/main/java/xyz/aprildown/timer/app/timer/one/layout/one/OneLayoutOneFragment.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.view.View
55
import android.view.ViewGroup
66
import android.view.ViewStub
77
import android.widget.CompoundButton
8+
import android.widget.LinearLayout
89
import android.widget.ProgressBar
910
import android.widget.SeekBar
1011
import android.widget.TextView
@@ -17,6 +18,7 @@ import com.github.zawadz88.materialpopupmenu.popupMenu
1718
import xyz.aprildown.timer.app.base.data.PreferenceData
1819
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneFourActions
1920
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneTimeSize
21+
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingStep
2022
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingTimingBar
2123
import xyz.aprildown.timer.app.base.data.PreferenceData.timePanels
2224
import xyz.aprildown.timer.app.base.data.ShowcaseData
@@ -45,6 +47,9 @@ internal class OneLayoutOneFragment :
4547
view.findViewById<TextView>(R.id.textOneTime).run {
4648
text = 8158000L.produceTime()
4749
}
50+
view.findViewById<TextView>(R.id.textOneStep).run {
51+
text = ShowcaseData.getSampleSteps()[0].label
52+
}
4853
view.findViewById<TextView>(R.id.textOneLoop).text = "1/3"
4954
view.findViewById<StepListView>(R.id.listOneSteps).run {
5055
setHasFixedSize(true)
@@ -56,6 +61,7 @@ internal class OneLayoutOneFragment :
5661
view.findViewById<TweakTimeLayout>(R.id.layoutOneTweakTime)
5762
.setCallback(requireActivity(), this)
5863

64+
toggleStep(context.oneOneUsingStep)
5965
toggleTimingBar(context.oneOneUsingTimingBar)
6066
setTimeTextSize(context.oneOneTimeSize)
6167
toggleTimePanels()
@@ -96,6 +102,16 @@ internal class OneLayoutOneFragment :
96102
val context = requireContext()
97103
val view = View.inflate(context, R.layout.layout_one_settings_one, null)
98104

105+
view.findViewById<ListItemWithLayout>(R.id.itemOneLayoutOneStep).run {
106+
getLayoutView<CompoundButton>().run {
107+
isChecked = context.oneOneUsingStep
108+
setOnCheckedChangeListener { _, isChecked ->
109+
toggleStep(isChecked)
110+
context.oneOneUsingStep = isChecked
111+
}
112+
}
113+
}
114+
99115
view.findViewById<ListItemWithLayout>(R.id.itemOneLayoutOneBar).run {
100116
getLayoutView<CompoundButton>().run {
101117
isChecked = context.oneOneUsingTimingBar
@@ -133,6 +149,11 @@ internal class OneLayoutOneFragment :
133149
return view
134150
}
135151

152+
private fun toggleStep(show: Boolean) {
153+
val view = requireView()
154+
view.findViewById<LinearLayout?>(R.id.layoutTextOneStep).visibility = if (show) View.VISIBLE else View.GONE
155+
}
156+
136157
private fun toggleTimingBar(show: Boolean) {
137158
val view = requireView()
138159
val stub: ViewStub? = view.findViewById(R.id.stubTimingBar)
@@ -152,6 +173,7 @@ internal class OneLayoutOneFragment :
152173

153174
private fun setTimeTextSize(size: Int) {
154175
view?.findViewById<TextView>(R.id.textOneTime)?.textSize = requireContext().dp(size)
176+
view?.findViewById<TextView>(R.id.textOneStep)?.textSize = requireContext().dp(size)
155177
}
156178

157179
private fun toggleTimePanels() {

app-timer-one/src/main/res/layout-land/fragment_one.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@
2727
android:layout_width="match_parent"
2828
android:layout_height="match_parent">
2929

30+
<LinearLayout
31+
android:id="@+id/layoutTextOneStep"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:orientation="vertical"
35+
app:layout_constraintTop_toTopOf="parent"
36+
app:layout_constraintEnd_toEndOf="parent"
37+
app:layout_constraintStart_toStartOf="parent"
38+
app:layout_constraintBottom_toTopOf="@id/textOneTime"
39+
app:layout_constraintVertical_chainStyle="packed">
40+
41+
<TextView
42+
android:id="@+id/textOneStep"
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:layout_gravity="center|fill"
46+
android:ellipsize="marquee"
47+
android:gravity="fill_horizontal"
48+
android:singleLine="true"
49+
android:textAlignment="center"
50+
android:textColor="?android:textColorPrimary"
51+
android:textSize="36sp"
52+
tools:text="Step Name" />
53+
</LinearLayout>
54+
3055
<TextView
3156
android:id="@+id/textOneTime"
3257
android:layout_width="wrap_content"
@@ -36,10 +61,11 @@
3661
android:textSize="36sp"
3762
app:layout_constrainedHeight="true"
3863
app:layout_constrainedWidth="true"
39-
app:layout_constraintBottom_toBottomOf="parent"
64+
app:layout_constraintTop_toBottomOf="@id/layoutTextOneStep"
4065
app:layout_constraintEnd_toEndOf="parent"
4166
app:layout_constraintStart_toStartOf="parent"
42-
app:layout_constraintTop_toTopOf="parent"
67+
app:layout_constraintBottom_toBottomOf="parent"
68+
app:layout_constraintVertical_chainStyle="packed"
4369
tools:text="12:34" />
4470

4571
<Button

app-timer-one/src/main/res/layout/fragment_one.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@
2020
android:layout_width="match_parent"
2121
android:layout_height="match_parent">
2222

23+
<LinearLayout
24+
android:id="@+id/layoutTextOneStep"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:orientation="vertical"
28+
app:layout_constraintTop_toTopOf="parent"
29+
app:layout_constraintEnd_toEndOf="parent"
30+
app:layout_constraintStart_toStartOf="parent"
31+
app:layout_constraintBottom_toTopOf="@id/textOneTime"
32+
app:layout_constraintVertical_chainStyle="packed">
33+
34+
<TextView
35+
android:id="@+id/textOneStep"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:layout_gravity="center|fill"
39+
android:ellipsize="marquee"
40+
android:gravity="fill_horizontal"
41+
android:singleLine="true"
42+
android:textAlignment="center"
43+
android:textColor="?android:textColorPrimary"
44+
android:textSize="36sp"
45+
tools:text="Step Name" />
46+
</LinearLayout>
47+
2348
<ViewStub
2449
android:id="@+id/stubTimePanel"
2550
android:layout_width="match_parent"
@@ -42,10 +67,11 @@
4267
android:textSize="36sp"
4368
app:layout_constrainedHeight="true"
4469
app:layout_constrainedWidth="true"
45-
app:layout_constraintBottom_toBottomOf="parent"
70+
app:layout_constraintTop_toBottomOf="@id/layoutTextOneStep"
4671
app:layout_constraintEnd_toEndOf="parent"
4772
app:layout_constraintStart_toStartOf="parent"
48-
app:layout_constraintTop_toTopOf="parent"
73+
app:layout_constraintBottom_toBottomOf="parent"
74+
app:layout_constraintVertical_chainStyle="packed"
4975
tools:text="12:34" />
5076

5177
<Button

app-timer-one/src/main/res/layout/layout_one_settings_one.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
android:layout_height="wrap_content"
66
android:orientation="vertical">
77

8+
<xyz.aprildown.timer.component.key.ListItemWithLayout
9+
android:id="@+id/itemOneLayoutOneStep"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
app:li_divider="margin"
13+
app:li_layout="@layout/view_list_item_with_layout_switch"
14+
app:li_textPrimary="@string/one_layout_step" />
15+
816
<xyz.aprildown.timer.component.key.ListItemWithLayout
917
android:id="@+id/itemOneLayoutOneBar"
1018
android:layout_width="match_parent"

0 commit comments

Comments
 (0)