Skip to content

Display step name above the timer #127

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import xyz.aprildown.timer.app.base.data.PreferenceData.getTypeColor
import xyz.aprildown.timer.app.base.data.PreferenceData.oneLayout
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneFourActions
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneTimeSize
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingStep
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingTimingBar
import xyz.aprildown.timer.app.base.data.PreferenceData.saveTypeColor
import xyz.aprildown.timer.app.base.data.PreferenceData.shouldNotifierPlusGoBack
Expand Down Expand Up @@ -284,6 +285,7 @@ private class AudioTypePreferenceItem : PreferenceItem {
private class OneLayoutPreferenceItem : PreferenceItem {
override fun storeToMap(context: Context, map: MutableMap<String, String>) {
map[KEY_LAYOUT] = context.oneLayout
map[KEY_ONE_STEP] = context.oneOneUsingStep.toString()
map[KEY_ONE_BAR] = context.oneOneUsingTimingBar.toString()
map[KEY_ONE_SIZE] = context.oneOneTimeSize.toString()
map[KEY_FOUR_ACTIONS] = context.oneOneFourActions.joinToString(separator = ",")
Expand All @@ -298,6 +300,9 @@ private class OneLayoutPreferenceItem : PreferenceItem {
prefs.ifHasKey(KEY_LAYOUT) {
editor.putString(KEY_LAYOUT, it)
}
prefs.ifHasKey(KEY_ONE_STEP) {
context.oneOneUsingStep = it.toBoolean()
}
prefs.ifHasKey(KEY_ONE_BAR) {
context.oneOneUsingTimingBar = it.toBoolean()
}
Expand All @@ -314,6 +319,7 @@ private class OneLayoutPreferenceItem : PreferenceItem {

companion object {
private const val KEY_LAYOUT = PreferenceData.KEY_ONE_LAYOUT
private const val KEY_ONE_STEP = PreferenceData.PREF_ONE_LAYOUT_ONE_STEP
private const val KEY_ONE_BAR = PreferenceData.PREF_ONE_LAYOUT_ONE_TIMING_BAR
private const val KEY_ONE_SIZE = PreferenceData.PREF_ONE_LAYOUT_ONE_TIME_SIZE
private const val KEY_FOUR_ACTIONS = PreferenceData.PREF_ONE_LAYOUT_ONE_ACTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ object PreferenceData {

// region One Layout: One

const val PREF_ONE_LAYOUT_ONE_STEP = "pref_one_one_step"
var Context.oneOneUsingStep: Boolean
get() = safeSharedPreference.getBoolean(PREF_ONE_LAYOUT_ONE_STEP, false)
set(value) = safeSharedPreference.edit { putBoolean(PREF_ONE_LAYOUT_ONE_STEP, value) }

const val PREF_ONE_LAYOUT_ONE_TIMING_BAR = "pref_one_one_timing_bar"
var Context.oneOneUsingTimingBar: Boolean
get() = safeSharedPreference.getBoolean(PREF_ONE_LAYOUT_ONE_TIMING_BAR, false)
Expand Down
1 change: 1 addition & 0 deletions app-base/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
<string name="one_shortcut_name">Shortcut name</string>
<string name="one_shortcut_open_on_click">Open timer screen on click</string>

<string name="one_layout_step">Step</string>
<string name="one_layout_bar">Timing Bar</string>
<string name="one_layout_time_size">Time Text Size</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ internal class StartRunInstructionView : InstructionView<LayoutIntroStartRunBind
text = (timer.steps.first() as StepEntity.Step).length.produceTime()
}

findViewById<TextView>(RTimerOne.id.textOneStep).run {
textSize = context.dp(context.oneOneTimeSize)
text = (timer.steps.first() as StepEntity.Step).label
}

findViewById<TextView>(RTimerOne.id.textOneLoop)
.text = index.getNiceLoopString(max = timer.loop)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint
import xyz.aprildown.timer.app.base.data.PreferenceData
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneFourActions
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneTimeSize
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingStep
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingTimingBar
import xyz.aprildown.timer.app.base.data.PreferenceData.timePanels
import xyz.aprildown.timer.app.base.utils.produceTime
Expand Down Expand Up @@ -213,6 +214,11 @@ class OneFragment :

private fun applySettings(binding: FragmentOneBinding) {
val context = binding.root.context

binding.textOneStep.textSize = context.dp(context.oneOneTimeSize)
binding.layoutTextOneStep.visibility = if (context.oneOneUsingStep) View.VISIBLE else View.GONE
binding.textOneStep.isSelected = true // to allow it to scroll horizontally

if (context.oneOneUsingTimingBar) {
val mpb = binding.stubTimingBar.inflate() as LinearProgressIndicator
viewModel.timerCurrentTime.observe(viewLifecycleOwner) {
Expand Down Expand Up @@ -289,11 +295,25 @@ class OneFragment :
viewModel.timerCurrentIndex.observe(viewLifecycleOwner) { index ->
if (index == null) return@observe
val totalLoop = viewModel.timer.value?.loop ?: return@observe
binding.textOneStep.setTextIfChanged(when (index) {
is TimerIndex.Start -> viewModel.timer.value?.startStep?.label
is TimerIndex.Step -> (viewModel.timer.value?.steps?.get(index.stepIndex) as StepEntity.Step).label
is TimerIndex.Group -> ((viewModel.timer.value?.steps?.get(index.stepIndex) as StepEntity.Group).steps[index.groupStepIndex.stepIndex] as StepEntity.Step).label
is TimerIndex.End -> viewModel.timer.value?.endStep?.label
else -> ""
})
binding.textOneLoop.setTextIfChanged(index.getNiceLoopString(totalLoop))
binding.listOneSteps.toIndex(index)
}
viewModel.timer.observe(viewLifecycleOwner) { timer ->
if (timer == null) return@observe
binding.textOneStep.setTextIfChanged(when (val currentIndex = viewModel.timerCurrentIndex.value) {
is TimerIndex.Start -> timer.startStep?.label
is TimerIndex.Step -> (timer.steps[currentIndex.stepIndex] as StepEntity.Step).label
is TimerIndex.Group -> ((timer.steps[currentIndex.stepIndex] as StepEntity.Group).steps[currentIndex.groupStepIndex.stepIndex] as StepEntity.Step).label
is TimerIndex.End -> timer.endStep?.label
else -> ""
})
binding.listOneSteps.setTimer(timer)
}
viewModel.timerCurrentState.observe(viewLifecycleOwner) { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewStub
import android.widget.CompoundButton
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.SeekBar
import android.widget.TextView
Expand All @@ -17,6 +18,7 @@ import com.github.zawadz88.materialpopupmenu.popupMenu
import xyz.aprildown.timer.app.base.data.PreferenceData
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneFourActions
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneTimeSize
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingStep
import xyz.aprildown.timer.app.base.data.PreferenceData.oneOneUsingTimingBar
import xyz.aprildown.timer.app.base.data.PreferenceData.timePanels
import xyz.aprildown.timer.app.base.data.ShowcaseData
Expand Down Expand Up @@ -45,6 +47,9 @@ internal class OneLayoutOneFragment :
view.findViewById<TextView>(R.id.textOneTime).run {
text = 8158000L.produceTime()
}
view.findViewById<TextView>(R.id.textOneStep).run {
text = ShowcaseData.getSampleSteps()[0].label
}
view.findViewById<TextView>(R.id.textOneLoop).text = "1/3"
view.findViewById<StepListView>(R.id.listOneSteps).run {
setHasFixedSize(true)
Expand All @@ -56,6 +61,7 @@ internal class OneLayoutOneFragment :
view.findViewById<TweakTimeLayout>(R.id.layoutOneTweakTime)
.setCallback(requireActivity(), this)

toggleStep(context.oneOneUsingStep)
toggleTimingBar(context.oneOneUsingTimingBar)
setTimeTextSize(context.oneOneTimeSize)
toggleTimePanels()
Expand Down Expand Up @@ -96,6 +102,16 @@ internal class OneLayoutOneFragment :
val context = requireContext()
val view = View.inflate(context, R.layout.layout_one_settings_one, null)

view.findViewById<ListItemWithLayout>(R.id.itemOneLayoutOneStep).run {
getLayoutView<CompoundButton>().run {
isChecked = context.oneOneUsingStep
setOnCheckedChangeListener { _, isChecked ->
toggleStep(isChecked)
context.oneOneUsingStep = isChecked
}
}
}

view.findViewById<ListItemWithLayout>(R.id.itemOneLayoutOneBar).run {
getLayoutView<CompoundButton>().run {
isChecked = context.oneOneUsingTimingBar
Expand Down Expand Up @@ -133,6 +149,11 @@ internal class OneLayoutOneFragment :
return view
}

private fun toggleStep(show: Boolean) {
val view = requireView()
view.findViewById<LinearLayout?>(R.id.layoutTextOneStep).visibility = if (show) View.VISIBLE else View.GONE
}

private fun toggleTimingBar(show: Boolean) {
val view = requireView()
val stub: ViewStub? = view.findViewById(R.id.stubTimingBar)
Expand All @@ -152,6 +173,7 @@ internal class OneLayoutOneFragment :

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

private fun toggleTimePanels() {
Expand Down
30 changes: 28 additions & 2 deletions app-timer-one/src/main/res/layout-land/fragment_one.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/layoutTextOneStep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textOneTime"
app:layout_constraintVertical_chainStyle="packed">

<TextView
android:id="@+id/textOneStep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|fill"
android:ellipsize="marquee"
android:gravity="fill_horizontal"
android:singleLine="true"
android:textAlignment="center"
android:textColor="?android:textColorPrimary"
android:textSize="36sp"
tools:text="Step Name" />
</LinearLayout>

<TextView
android:id="@+id/textOneTime"
android:layout_width="wrap_content"
Expand All @@ -36,10 +61,11 @@
android:textSize="36sp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/layoutTextOneStep"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="12:34" />

<Button
Expand Down
30 changes: 28 additions & 2 deletions app-timer-one/src/main/res/layout/fragment_one.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/layoutTextOneStep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textOneTime"
app:layout_constraintVertical_chainStyle="packed">

<TextView
android:id="@+id/textOneStep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|fill"
android:ellipsize="marquee"
android:gravity="fill_horizontal"
android:singleLine="true"
android:textAlignment="center"
android:textColor="?android:textColorPrimary"
android:textSize="36sp"
tools:text="Step Name" />
</LinearLayout>

<ViewStub
android:id="@+id/stubTimePanel"
android:layout_width="match_parent"
Expand All @@ -42,10 +67,11 @@
android:textSize="36sp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/layoutTextOneStep"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="12:34" />

<Button
Expand Down
8 changes: 8 additions & 0 deletions app-timer-one/src/main/res/layout/layout_one_settings_one.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<xyz.aprildown.timer.component.key.ListItemWithLayout
android:id="@+id/itemOneLayoutOneStep"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:li_divider="margin"
app:li_layout="@layout/view_list_item_with_layout_switch"
app:li_textPrimary="@string/one_layout_step" />

<xyz.aprildown.timer.component.key.ListItemWithLayout
android:id="@+id/itemOneLayoutOneBar"
android:layout_width="match_parent"
Expand Down