mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-02-02 11:36:52 +01:00
properly handle adding a new alarmsound from edit alarm dialog too
This commit is contained in:
parent
2df47166a9
commit
8f07546831
@ -61,7 +61,7 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
val configTextColor = config.textColor
|
||||
if (storedTextColor != configTextColor) {
|
||||
getInactiveTabIndexes(viewpager.currentItem).forEach {
|
||||
getInactiveTabIndexes(view_pager.currentItem).forEach {
|
||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(configTextColor)
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ class MainActivity : SimpleActivity() {
|
||||
val configPrimaryColor = config.primaryColor
|
||||
if (storedPrimaryColor != configPrimaryColor) {
|
||||
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
if (config.preventPhoneFromSleeping) {
|
||||
@ -92,7 +92,7 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
config.lastUsedViewPagerPage = viewpager.currentItem
|
||||
config.lastUsedViewPagerPage = view_pager.currentItem
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@ -111,7 +111,7 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
if (intent.extras?.containsKey(OPEN_TAB) == true) {
|
||||
viewpager.setCurrentItem(intent.getIntExtra(OPEN_TAB, TAB_CLOCK), false)
|
||||
view_pager.setCurrentItem(intent.getIntExtra(OPEN_TAB, TAB_CLOCK), false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,27 +153,30 @@ class MainActivity : SimpleActivity() {
|
||||
contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
}
|
||||
|
||||
when (viewpager.currentItem) {
|
||||
TAB_TIMER -> (viewpager.adapter as? ViewPagerAdapter)?.updateTimerAlarmSound(newAlarmSound)
|
||||
when (view_pager.currentItem) {
|
||||
TAB_ALARM -> getViewPagerAdapter()?.updateAlarmTabAlarmSound(newAlarmSound)
|
||||
TAB_TIMER -> getViewPagerAdapter()?.updateTimerTabAlarmSound(newAlarmSound)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getViewPagerAdapter() = view_pager.adapter as? ViewPagerAdapter
|
||||
|
||||
private fun initFragments() {
|
||||
viewpager.adapter = ViewPagerAdapter(supportFragmentManager)
|
||||
viewpager.onPageChangeListener {
|
||||
view_pager.adapter = ViewPagerAdapter(supportFragmentManager)
|
||||
view_pager.onPageChangeListener {
|
||||
main_tabs_holder.getTabAt(it)?.select()
|
||||
}
|
||||
|
||||
val tabToOpen = intent.getIntExtra(OPEN_TAB, config.lastUsedViewPagerPage)
|
||||
intent.removeExtra(OPEN_TAB)
|
||||
viewpager.currentItem = tabToOpen
|
||||
viewpager.offscreenPageLimit = TABS_COUNT - 1
|
||||
view_pager.currentItem = tabToOpen
|
||||
view_pager.offscreenPageLimit = TABS_COUNT - 1
|
||||
main_tabs_holder.onTabSelectionChanged(
|
||||
tabUnselectedAction = {
|
||||
it.icon?.applyColorFilter(config.textColor)
|
||||
},
|
||||
tabSelectedAction = {
|
||||
viewpager.currentItem = it.position
|
||||
view_pager.currentItem = it.position
|
||||
it.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
)
|
||||
|
@ -9,6 +9,7 @@ import com.simplemobiletools.clock.fragments.ClockFragment
|
||||
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_TIMER
|
||||
import com.simplemobiletools.clock.models.AlarmSound
|
||||
|
||||
@ -36,7 +37,11 @@ class ViewPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
|
||||
else -> throw RuntimeException("Trying to fetch unknown fragment id $position")
|
||||
}
|
||||
|
||||
fun updateTimerAlarmSound(alarmSound: AlarmSound) {
|
||||
fun updateAlarmTabAlarmSound(alarmSound: AlarmSound) {
|
||||
(fragments[TAB_ALARM] as AlarmFragment).updateAlarmSound(alarmSound)
|
||||
}
|
||||
|
||||
fun updateTimerTabAlarmSound(alarmSound: AlarmSound) {
|
||||
(fragments[TAB_TIMER] as TimerFragment).updateAlarmSound(alarmSound)
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.dbHelper
|
||||
import com.simplemobiletools.clock.extensions.getFormattedTime
|
||||
import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.clock.models.AlarmSound
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import kotlinx.android.synthetic.main.dialog_edit_alarm.view.*
|
||||
|
||||
@ -32,9 +33,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
edit_alarm_sound.setOnClickListener {
|
||||
SelectAlarmSoundDialog(activity, alarm.soundUri, AudioManager.STREAM_ALARM) {
|
||||
if (it != null) {
|
||||
alarm.soundTitle = it.title
|
||||
alarm.soundUri = it.uri
|
||||
edit_alarm_sound.text = it.title
|
||||
alarmSoundUpdated(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,4 +122,14 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
drawable.applyColorFilter(textColor)
|
||||
return drawable
|
||||
}
|
||||
|
||||
private fun alarmSoundUpdated(alarmSound: AlarmSound) {
|
||||
alarm.soundTitle = alarmSound.title
|
||||
alarm.soundUri = alarmSound.uri
|
||||
view.edit_alarm_sound.text = alarmSound.title
|
||||
}
|
||||
|
||||
fun updateSelectedAlarmSound(alarmSound: AlarmSound) {
|
||||
alarmSoundUpdated(alarmSound)
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.DEFAULT_ALARM_MINUTES
|
||||
import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface
|
||||
import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.clock.models.AlarmSound
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_alarm.view.*
|
||||
@ -20,6 +21,7 @@ import java.util.*
|
||||
|
||||
class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
private var alarms = ArrayList<Alarm>()
|
||||
private var currentEditAlarmDialog: EditAlarmDialog? = null
|
||||
|
||||
private var storedTextColor = 0
|
||||
|
||||
@ -79,10 +81,12 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
}
|
||||
|
||||
private fun openEditAlarm(alarm: Alarm) {
|
||||
EditAlarmDialog(activity as SimpleActivity, alarm) {
|
||||
currentEditAlarmDialog = EditAlarmDialog(activity as SimpleActivity, alarm) {
|
||||
currentEditAlarmDialog = null
|
||||
setupAlarms()
|
||||
checkAlarmState(alarm)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
||||
@ -103,4 +107,8 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
context!!.cancelAlarmClock(alarm)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateAlarmSound(alarmSound: AlarmSound) {
|
||||
currentEditAlarmDialog?.updateSelectedAlarmSound(alarmSound)
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
</android.support.design.widget.TabLayout>
|
||||
|
||||
<com.booking.rtlviewpager.RtlViewPager
|
||||
android:id="@+id/viewpager"
|
||||
android:id="@+id/view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/main_tabs_holder"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user