add the date under time
This commit is contained in:
parent
60f4244acf
commit
40cee86c0d
7 changed files with 40 additions and 6 deletions
|
@ -41,7 +41,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.13.20'
|
||||
implementation 'com.simplemobiletools:commons:3.14.1'
|
||||
}
|
||||
|
||||
Properties props = new Properties()
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.simplemobiletools.clock.BuildConfig
|
|||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.adapters.ViewPagerAdapter
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.helpers.TABS_COUNT
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||
import com.simplemobiletools.commons.models.FAQItem
|
||||
|
@ -102,7 +103,7 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||
viewpager.offscreenPageLimit = 2
|
||||
viewpager.offscreenPageLimit = TABS_COUNT - 1
|
||||
main_tabs_holder.onTabSelectionChanged(
|
||||
tabUnselectedAction = {
|
||||
it.icon?.applyColorFilter(config.textColor)
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.helpers.TABS_COUNT
|
||||
|
||||
class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||
|
||||
|
@ -19,7 +20,7 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
|||
container.removeView(item as View)
|
||||
}
|
||||
|
||||
override fun getCount() = 3
|
||||
override fun getCount() = TABS_COUNT
|
||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||
|
||||
private fun getFragment(position: Int) = when (position) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.os.Handler
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_clock.view.*
|
||||
|
@ -12,24 +13,26 @@ import java.util.*
|
|||
class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
private val ONE_SECOND = 1000L
|
||||
private var passedSeconds = 0
|
||||
private val calendar = Calendar.getInstance()
|
||||
|
||||
private val updateHandler = Handler()
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
context.updateTextColors(clock_fragment)
|
||||
val offset = Calendar.getInstance().timeZone.rawOffset
|
||||
passedSeconds = ((Calendar.getInstance().timeInMillis + offset) / 1000).toInt()
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
updateCurrentTime()
|
||||
updateDate()
|
||||
}
|
||||
|
||||
private fun updateCurrentTime() {
|
||||
val hours = (passedSeconds / 3600) % 24
|
||||
val minutes = (passedSeconds / 60) % 60
|
||||
val seconds = passedSeconds % 60
|
||||
var format = "%02d:%02d"
|
||||
|
||||
val formattedText = if (context.config.showSeconds) {
|
||||
val seconds = passedSeconds % 60
|
||||
format += ":%02d"
|
||||
String.format(format, hours, minutes, seconds)
|
||||
} else {
|
||||
|
@ -38,12 +41,29 @@ class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayo
|
|||
|
||||
clock_time.text = formattedText
|
||||
|
||||
if (hours == 0 && minutes == 0 && seconds == 0) {
|
||||
updateDate()
|
||||
}
|
||||
|
||||
updateHandler.postDelayed({
|
||||
passedSeconds++
|
||||
updateCurrentTime()
|
||||
}, ONE_SECOND)
|
||||
}
|
||||
|
||||
private fun updateDate() {
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 // make sure index 0 means monday
|
||||
val dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
|
||||
val month = calendar.get(Calendar.MONTH)
|
||||
|
||||
val dayString = context.resources.getStringArray(R.array.week_days)[dayOfWeek]
|
||||
val shortDayString = dayString.substring(0, Math.min(3, dayString.length))
|
||||
val monthString = context.resources.getStringArray(R.array.months)[month]
|
||||
|
||||
val dateString = "$shortDayString, $dayOfMonth $monthString"
|
||||
clock_date.text = dateString
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
updateHandler.removeCallbacksAndMessages(null)
|
||||
|
|
|
@ -2,3 +2,5 @@ package com.simplemobiletools.clock.helpers
|
|||
|
||||
// shared preferences
|
||||
const val SHOW_SECONDS = "show_seconds"
|
||||
|
||||
const val TABS_COUNT = 3
|
||||
|
|
|
@ -15,4 +15,13 @@
|
|||
android:textSize="@dimen/clock_text_size"
|
||||
tools:text="00:00:00"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/clock_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/clock_time"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="Mon, 1 January"/>
|
||||
|
||||
</com.simplemobiletools.clock.fragments.ClockFragment>
|
||||
|
|
|
@ -7,6 +7,7 @@ buildscript {
|
|||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
|
Loading…
Reference in a new issue