mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
show the selected time zone times on the main screen
This commit is contained in:
@ -39,7 +39,7 @@ class SelectTimeZonesAdapter(val activity: SimpleActivity, val timeZones: ArrayL
|
||||
selectedPositions.remove(pos)
|
||||
}
|
||||
|
||||
itemViews[pos]?.time_zone_checkbox?.isChecked = select
|
||||
itemViews[pos]?.add_time_zone_checkbox?.isChecked = select
|
||||
}
|
||||
|
||||
private val adapterListener = object : MyAdapterListener {
|
||||
@ -74,12 +74,12 @@ class SelectTimeZonesAdapter(val activity: SimpleActivity, val timeZones: ArrayL
|
||||
class ViewHolder(view: View, val adapterListener: MyAdapterListener) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(timeZone: MyTimeZone, textColor: Int, primaryColor: Int, backgroundColor: Int): View {
|
||||
itemView.apply {
|
||||
time_zone_title.text = timeZone.title
|
||||
time_zone_title.setTextColor(textColor)
|
||||
add_time_zone_title.text = timeZone.title
|
||||
add_time_zone_title.setTextColor(textColor)
|
||||
|
||||
time_zone_checkbox.setColors(textColor, primaryColor, backgroundColor)
|
||||
time_zone_holder.setOnClickListener {
|
||||
adapterListener.toggleItemSelectionAdapter(!time_zone_checkbox.isChecked, adapterPosition)
|
||||
add_time_zone_checkbox.setColors(textColor, primaryColor, backgroundColor)
|
||||
add_time_zone_holder.setOnClickListener {
|
||||
adapterListener.toggleItemSelectionAdapter(!add_time_zone_checkbox.isChecked, adapterPosition)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,70 @@
|
||||
package com.simplemobiletools.clock.adapters
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.item_time_zone.view.*
|
||||
import java.util.*
|
||||
|
||||
class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTimeZone>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_timezones
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
||||
override fun prepareItemSelection(view: View) {}
|
||||
|
||||
override fun markItemSelection(select: Boolean, view: View?) {
|
||||
view?.time_zone_frame?.isSelected = select
|
||||
}
|
||||
|
||||
override fun actionItemPressed(id: Int) {}
|
||||
|
||||
override fun getSelectableItemCount() = timeZones.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = createViewHolder(R.layout.item_time_zone, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||
val contact = timeZones[position]
|
||||
val view = holder.bindView(contact, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, contact)
|
||||
}
|
||||
bindViewHolder(holder, position, view)
|
||||
}
|
||||
|
||||
override fun getItemCount() = timeZones.size
|
||||
|
||||
fun updateItems(newItems: ArrayList<MyTimeZone>) {
|
||||
timeZones = newItems
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
fun updateTimes() {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun setupView(view: View, timeZone: MyTimeZone) {
|
||||
val calendar = Calendar.getInstance(TimeZone.getTimeZone(timeZone.zoneName))
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
val passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
val hours = (passedSeconds / 3600) % 24
|
||||
val minutes = (passedSeconds / 60) % 60
|
||||
val format = "%02d:%02d"
|
||||
val formattedTime = String.format(format, hours, minutes)
|
||||
|
||||
view.apply {
|
||||
time_zone_title.text = timeZone.title.substring(timeZone.title.indexOf(' '))
|
||||
time_zone_title.setTextColor(textColor)
|
||||
|
||||
time_zone_time.text = formattedTime
|
||||
time_zone_time.setTextColor(textColor)
|
||||
}
|
||||
}
|
||||
}
|
@ -8,8 +8,11 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.adapters.TimeZonesAdapter
|
||||
import com.simplemobiletools.clock.dialogs.AddTimeZonesDialog
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.helpers.getAllTimeZones
|
||||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_clock.view.*
|
||||
@ -20,6 +23,7 @@ class ClockFragment : Fragment() {
|
||||
|
||||
private var passedSeconds = 0
|
||||
private var isFirstResume = true
|
||||
private var displayOtherTimeZones = false
|
||||
private var calendar = Calendar.getInstance()
|
||||
private val updateHandler = Handler()
|
||||
|
||||
@ -29,6 +33,7 @@ class ClockFragment : Fragment() {
|
||||
view = inflater.inflate(R.layout.fragment_clock, container, false) as ViewGroup
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
displayOtherTimeZones = context!!.config.displayOtherTimeZones
|
||||
updateCurrentTime()
|
||||
updateDate()
|
||||
setupViews()
|
||||
@ -38,9 +43,11 @@ class ClockFragment : Fragment() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
displayOtherTimeZones = context!!.config.displayOtherTimeZones
|
||||
if (!isFirstResume) {
|
||||
setupViews()
|
||||
}
|
||||
|
||||
isFirstResume = false
|
||||
}
|
||||
|
||||
@ -50,7 +57,6 @@ class ClockFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
val displayOtherTimeZones = context!!.config.displayOtherTimeZones
|
||||
view.apply {
|
||||
context!!.updateTextColors(clock_fragment)
|
||||
time_zones_list.beVisibleIf(displayOtherTimeZones)
|
||||
@ -58,6 +64,10 @@ class ClockFragment : Fragment() {
|
||||
clock_fab.setOnClickListener {
|
||||
fabClicked()
|
||||
}
|
||||
|
||||
if (displayOtherTimeZones) {
|
||||
updateTimeZones()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,8 +86,14 @@ class ClockFragment : Fragment() {
|
||||
|
||||
view.clock_time.text = formattedText
|
||||
|
||||
if (hours == 0 && minutes == 0 && seconds == 0) {
|
||||
updateDate()
|
||||
if (seconds == 0) {
|
||||
if (displayOtherTimeZones) {
|
||||
(view.time_zones_list.adapter as? TimeZonesAdapter)?.updateTimes()
|
||||
}
|
||||
|
||||
if (hours == 0 && minutes == 0) {
|
||||
updateDate()
|
||||
}
|
||||
}
|
||||
|
||||
updateHandler.postDelayed({
|
||||
@ -100,9 +116,25 @@ class ClockFragment : Fragment() {
|
||||
view.clock_date.text = dateString
|
||||
}
|
||||
|
||||
private fun updateTimeZones() {
|
||||
if (!displayOtherTimeZones) {
|
||||
return
|
||||
}
|
||||
|
||||
val selectedTimeZoneIDs = context!!.config.selectedTimeZones.map { it.toInt() }
|
||||
val timeZones = getAllTimeZones().filter { selectedTimeZoneIDs.contains(it.id) } as ArrayList<MyTimeZone>
|
||||
val currAdapter = view.time_zones_list.adapter
|
||||
if (currAdapter == null) {
|
||||
val timeZonesAdapter = TimeZonesAdapter(activity as SimpleActivity, timeZones, view.time_zones_list) {}
|
||||
view.time_zones_list.adapter = timeZonesAdapter
|
||||
} else {
|
||||
(currAdapter as TimeZonesAdapter).updateItems(timeZones)
|
||||
}
|
||||
}
|
||||
|
||||
private fun fabClicked() {
|
||||
AddTimeZonesDialog(activity as SimpleActivity) {
|
||||
|
||||
updateTimeZones()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user