Skip to content

Commit cbd1b51

Browse files
committed
Replace Checkboxes with switches for alarms
Closes #6 All preferences will eventually use the new material switch in place of checkboxes.
1 parent 86081cf commit cbd1b51

3 files changed

Lines changed: 56 additions & 61 deletions

File tree

app/src/main/kotlin/org/fossify/clock/adapters/AlarmsAdapter.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.fossify.clock.adapters
33
import android.view.Menu
44
import android.view.View
55
import android.view.ViewGroup
6-
import android.widget.RelativeLayout
76
import org.fossify.clock.R
87
import org.fossify.clock.activities.SimpleActivity
98
import org.fossify.clock.databinding.ItemAlarmBinding
@@ -16,7 +15,6 @@ import org.fossify.clock.models.Alarm
1615
import org.fossify.commons.adapters.MyRecyclerViewAdapter
1716
import org.fossify.commons.dialogs.ConfirmationDialog
1817
import org.fossify.commons.extensions.beVisibleIf
19-
import org.fossify.commons.extensions.isVisible
2018
import org.fossify.commons.extensions.toast
2119
import org.fossify.commons.views.MyRecyclerView
2220

@@ -92,7 +90,7 @@ class AlarmsAdapter(
9290
private fun setupView(view: View, alarm: Alarm) {
9391
val isSelected = selectedKeys.contains(alarm.id)
9492
ItemAlarmBinding.bind(view).apply {
95-
alarmFrame.isSelected = isSelected
93+
alarmHolder.isSelected = isSelected
9694
alarmTime.text = activity.getFormattedTime(alarm.timeInMinutes * 60, false, true)
9795
alarmTime.setTextColor(textColor)
9896

@@ -137,9 +135,6 @@ class AlarmsAdapter(
137135
toggleAlarmInterface.alarmToggled(alarm.id, alarmSwitch.isChecked)
138136
}
139137
}
140-
141-
val layoutParams = alarmSwitch.layoutParams as RelativeLayout.LayoutParams
142-
layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, if (alarmLabel.isVisible()) alarmLabel.id else alarmLabel.id)
143138
}
144139
}
145140
}

app/src/main/res/layout/fragment_alarm.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
45
android:id="@+id/alarm_fragment"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent">
@@ -18,7 +19,8 @@
1819
android:overScrollMode="ifContentScrolls"
1920
android:paddingBottom="@dimen/fab_list_bottom_padding"
2021
android:scrollbars="none"
21-
app:layoutManager="org.fossify.commons.views.MyLinearLayoutManager" />
22+
app:layoutManager="org.fossify.commons.views.MyLinearLayoutManager"
23+
tools:listitem="@layout/item_alarm" />
2224

2325
</RelativeLayout>
2426

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,65 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
xmlns:tools="http://schemas.android.com/tools"
4-
android:id="@+id/alarm_frame"
5+
android:id="@+id/alarm_holder"
56
android:layout_width="match_parent"
67
android:layout_height="wrap_content"
78
android:background="?attr/selectableItemBackground"
89
android:clickable="true"
910
android:focusable="true"
10-
android:foreground="@drawable/selector">
11+
android:foreground="@drawable/selector"
12+
android:paddingHorizontal="@dimen/activity_margin"
13+
android:paddingVertical="@dimen/medium_margin">
1114

12-
<RelativeLayout
13-
android:id="@+id/alarm_holder"
14-
android:layout_width="match_parent"
15+
<org.fossify.commons.views.MyTextView
16+
android:id="@+id/alarm_time"
17+
android:layout_width="0dp"
1518
android:layout_height="wrap_content"
16-
android:paddingStart="@dimen/activity_margin"
17-
android:paddingTop="@dimen/medium_margin"
18-
android:paddingBottom="@dimen/medium_margin">
19+
android:ellipsize="end"
20+
android:includeFontPadding="false"
21+
android:maxLines="1"
22+
android:textSize="@dimen/alarm_text_size"
23+
app:layout_constraintEnd_toStartOf="@id/alarm_switch"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintTop_toTopOf="parent"
26+
tools:text="07:00" />
1927

20-
<org.fossify.commons.views.MyTextView
21-
android:id="@+id/alarm_time"
22-
android:layout_width="wrap_content"
23-
android:layout_height="wrap_content"
24-
android:ellipsize="end"
25-
android:includeFontPadding="false"
26-
android:maxLines="1"
27-
android:textSize="@dimen/alarm_text_size"
28-
tools:text="07:00" />
29-
30-
<org.fossify.commons.views.MyTextView
31-
android:id="@+id/alarm_days"
32-
android:layout_width="match_parent"
33-
android:layout_height="wrap_content"
34-
android:layout_below="@+id/alarm_time"
35-
android:layout_toStartOf="@+id/alarm_switch"
36-
android:ellipsize="end"
37-
android:includeFontPadding="false"
38-
android:maxLines="1"
39-
android:paddingStart="@dimen/tiny_margin"
40-
android:textSize="@dimen/bigger_text_size"
41-
tools:text="Mon, Tue, Wed, Thu, Fri" />
28+
<org.fossify.commons.views.MyTextView
29+
android:id="@+id/alarm_days"
30+
android:layout_width="0dp"
31+
android:layout_height="wrap_content"
32+
android:ellipsize="end"
33+
android:includeFontPadding="false"
34+
android:maxLines="1"
35+
android:paddingHorizontal="@dimen/tiny_margin"
36+
android:textSize="@dimen/bigger_text_size"
37+
app:layout_constraintEnd_toStartOf="@id/alarm_switch"
38+
app:layout_constraintStart_toStartOf="parent"
39+
app:layout_constraintTop_toBottomOf="@id/alarm_time"
40+
tools:text="Mon, Tue, Wed, Thu, Fri" />
4241

43-
<org.fossify.commons.views.MyTextView
44-
android:id="@+id/alarm_label"
45-
android:layout_width="match_parent"
46-
android:layout_height="wrap_content"
47-
android:layout_below="@+id/alarm_days"
48-
android:layout_toStartOf="@+id/alarm_switch"
49-
android:ellipsize="end"
50-
android:includeFontPadding="false"
51-
android:maxLines="1"
52-
android:paddingStart="@dimen/tiny_margin"
53-
android:textSize="@dimen/bigger_text_size"
54-
tools:text="Good morning!" />
42+
<org.fossify.commons.views.MyTextView
43+
android:id="@+id/alarm_label"
44+
android:layout_width="0dp"
45+
android:layout_height="wrap_content"
46+
android:ellipsize="end"
47+
android:includeFontPadding="false"
48+
android:maxLines="1"
49+
android:paddingHorizontal="@dimen/tiny_margin"
50+
android:textSize="@dimen/bigger_text_size"
51+
app:layout_constraintEnd_toStartOf="@id/alarm_switch"
52+
app:layout_constraintStart_toStartOf="parent"
53+
app:layout_constraintTop_toBottomOf="@id/alarm_days"
54+
tools:text="Good morning!" />
5555

56-
<org.fossify.commons.views.MyAppCompatCheckbox
57-
android:id="@+id/alarm_switch"
58-
android:layout_width="wrap_content"
59-
android:layout_height="match_parent"
60-
android:layout_alignTop="@+id/alarm_time"
61-
android:layout_alignBottom="@id/alarm_label"
62-
android:layout_alignParentEnd="true"
63-
android:paddingStart="@dimen/activity_margin"
64-
android:paddingEnd="@dimen/medium_margin" />
56+
<org.fossify.commons.views.MyMaterialSwitch
57+
android:id="@+id/alarm_switch"
58+
android:layout_width="wrap_content"
59+
android:layout_height="wrap_content"
60+
android:paddingHorizontal="@dimen/normal_margin"
61+
app:layout_constraintBottom_toBottomOf="parent"
62+
app:layout_constraintEnd_toEndOf="parent"
63+
app:layout_constraintTop_toTopOf="parent" />
6564

66-
</RelativeLayout>
67-
</FrameLayout>
65+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)