fix #7, show pending alarms at the clock tab

This commit is contained in:
tibbi 2018-05-16 16:00:07 +02:00
parent 3b4a0c85cf
commit 081f51763b
5 changed files with 38 additions and 7 deletions

View file

@ -128,6 +128,10 @@ class MainActivity : SimpleActivity() {
}
}
fun updateClockTabAlarm() {
getViewPagerAdapter()?.updateClockTabAlarm()
}
private fun getViewPagerAdapter() = view_pager.adapter as? ViewPagerAdapter
private fun initFragments() {

View file

@ -10,6 +10,7 @@ import com.simplemobiletools.clock.fragments.StopwatchFragment
import com.simplemobiletools.clock.fragments.TimerFragment
import com.simplemobiletools.clock.helpers.TABS_COUNT
import com.simplemobiletools.clock.helpers.TAB_ALARM
import com.simplemobiletools.clock.helpers.TAB_CLOCK
import com.simplemobiletools.clock.helpers.TAB_TIMER
import com.simplemobiletools.commons.models.AlarmSound
@ -37,6 +38,10 @@ class ViewPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
else -> throw RuntimeException("Trying to fetch unknown fragment id $position")
}
fun updateClockTabAlarm() {
(fragments[TAB_CLOCK] as ClockFragment).updateAlarm()
}
fun updateAlarmTabAlarmSound(alarmSound: AlarmSound) {
(fragments[TAB_ALARM] as AlarmFragment).updateAlarmSound(alarmSound)
}

View file

@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.MainActivity
import com.simplemobiletools.clock.activities.SimpleActivity
import com.simplemobiletools.clock.adapters.AlarmsAdapter
import com.simplemobiletools.clock.dialogs.EditAlarmDialog
@ -105,6 +106,7 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
} else {
context?.cancelAlarmClock(alarm)
}
(activity as? MainActivity)?.updateClockTabAlarm()
}
fun updateAlarmSound(alarmSound: AlarmSound) {

View file

@ -11,10 +11,7 @@ import com.simplemobiletools.clock.activities.SimpleActivity
import com.simplemobiletools.clock.adapters.TimeZonesAdapter
import com.simplemobiletools.clock.dialogs.AddTimeZonesDialog
import com.simplemobiletools.clock.dialogs.EditTimeZoneDialog
import com.simplemobiletools.clock.extensions.config
import com.simplemobiletools.clock.extensions.getAllTimeZonesModified
import com.simplemobiletools.clock.extensions.getFormattedDate
import com.simplemobiletools.clock.extensions.getFormattedTime
import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.clock.helpers.getPassedSeconds
import com.simplemobiletools.clock.models.MyTimeZone
import com.simplemobiletools.commons.extensions.beVisibleIf
@ -64,6 +61,7 @@ class ClockFragment : Fragment() {
passedSeconds = getPassedSeconds()
updateCurrentTime()
updateDate()
updateAlarm()
setupViews()
}
@ -109,6 +107,15 @@ class ClockFragment : Fragment() {
(view.time_zones_list.adapter as? TimeZonesAdapter)?.todayDateString = formattedDate
}
fun updateAlarm() {
view.apply {
val nextAlarm = context!!.getNextAlarm()
clock_alarm.beVisibleIf(nextAlarm.isNotEmpty())
clock_alarm.text = nextAlarm
clock_alarm.colorLeftDrawable(context!!.config.textColor)
}
}
private fun updateTimeZones() {
val selectedTimeZones = context!!.config.selectedTimeZones
view.time_zones_list.beVisibleIf(selectedTimeZones.isNotEmpty())

View file

@ -16,7 +16,7 @@
android:id="@+id/clock_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/big_margin"
android:layout_marginTop="@dimen/activity_margin"
android:gravity="center_horizontal"
android:textSize="@dimen/clock_text_size"
tools:text="00:00:00"/>
@ -30,12 +30,25 @@
android:textSize="@dimen/big_text_size"
tools:text="Mon, 1 January"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/clock_alarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/clock_date"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/medium_margin"
android:drawableLeft="@drawable/ic_clock"
android:drawablePadding="@dimen/small_margin"
android:gravity="center_horizontal"
android:textSize="@dimen/big_text_size"
tools:text="Thu, 8:00"/>
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/time_zones_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/clock_date"
android:layout_marginTop="@dimen/activity_margin"
android:layout_below="@+id/clock_alarm"
android:layout_marginTop="@dimen/normal_margin"
android:clipToPadding="false"
android:overScrollMode="ifContentScrolls"
android:scrollbars="none"