mirror of
				https://github.com/SimpleMobileTools/Simple-Clock.git
				synced 2025-06-05 22:19:17 +02:00 
			
		
		
		
	add the date under time
This commit is contained in:
		| @@ -41,7 +41,7 @@ android { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|     implementation 'com.simplemobiletools:commons:3.13.20' |     implementation 'com.simplemobiletools:commons:3.14.1' | ||||||
| } | } | ||||||
|  |  | ||||||
| Properties props = new Properties() | Properties props = new Properties() | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import com.simplemobiletools.clock.BuildConfig | |||||||
| import com.simplemobiletools.clock.R | import com.simplemobiletools.clock.R | ||||||
| import com.simplemobiletools.clock.adapters.ViewPagerAdapter | import com.simplemobiletools.clock.adapters.ViewPagerAdapter | ||||||
| import com.simplemobiletools.clock.extensions.config | import com.simplemobiletools.clock.extensions.config | ||||||
|  | import com.simplemobiletools.clock.helpers.TABS_COUNT | ||||||
| import com.simplemobiletools.commons.extensions.* | import com.simplemobiletools.commons.extensions.* | ||||||
| import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN | import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN | ||||||
| import com.simplemobiletools.commons.models.FAQItem | import com.simplemobiletools.commons.models.FAQItem | ||||||
| @@ -102,7 +103,7 @@ class MainActivity : SimpleActivity() { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         viewpager.currentItem = config.lastUsedViewPagerPage |         viewpager.currentItem = config.lastUsedViewPagerPage | ||||||
|         viewpager.offscreenPageLimit = 2 |         viewpager.offscreenPageLimit = TABS_COUNT - 1 | ||||||
|         main_tabs_holder.onTabSelectionChanged( |         main_tabs_holder.onTabSelectionChanged( | ||||||
|                 tabUnselectedAction = { |                 tabUnselectedAction = { | ||||||
|                     it.icon?.applyColorFilter(config.textColor) |                     it.icon?.applyColorFilter(config.textColor) | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import android.view.View | |||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| import com.simplemobiletools.clock.R | import com.simplemobiletools.clock.R | ||||||
| import com.simplemobiletools.clock.activities.SimpleActivity | import com.simplemobiletools.clock.activities.SimpleActivity | ||||||
|  | import com.simplemobiletools.clock.helpers.TABS_COUNT | ||||||
|  |  | ||||||
| class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { | class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { | ||||||
|  |  | ||||||
| @@ -19,7 +20,7 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { | |||||||
|         container.removeView(item as View) |         container.removeView(item as View) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun getCount() = 3 |     override fun getCount() = TABS_COUNT | ||||||
|     override fun isViewFromObject(view: View, item: Any) = view == item |     override fun isViewFromObject(view: View, item: Any) = view == item | ||||||
|  |  | ||||||
|     private fun getFragment(position: Int) = when (position) { |     private fun getFragment(position: Int) = when (position) { | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import android.content.Context | |||||||
| import android.os.Handler | import android.os.Handler | ||||||
| import android.util.AttributeSet | import android.util.AttributeSet | ||||||
| import android.widget.RelativeLayout | import android.widget.RelativeLayout | ||||||
|  | import com.simplemobiletools.clock.R | ||||||
| import com.simplemobiletools.clock.extensions.config | import com.simplemobiletools.clock.extensions.config | ||||||
| import com.simplemobiletools.commons.extensions.updateTextColors | import com.simplemobiletools.commons.extensions.updateTextColors | ||||||
| import kotlinx.android.synthetic.main.fragment_clock.view.* | import kotlinx.android.synthetic.main.fragment_clock.view.* | ||||||
| @@ -12,24 +13,26 @@ import java.util.* | |||||||
| class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) { | class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) { | ||||||
|     private val ONE_SECOND = 1000L |     private val ONE_SECOND = 1000L | ||||||
|     private var passedSeconds = 0 |     private var passedSeconds = 0 | ||||||
|  |     private val calendar = Calendar.getInstance() | ||||||
|  |  | ||||||
|     private val updateHandler = Handler() |     private val updateHandler = Handler() | ||||||
|  |  | ||||||
|     override fun onFinishInflate() { |     override fun onFinishInflate() { | ||||||
|         super.onFinishInflate() |         super.onFinishInflate() | ||||||
|         context.updateTextColors(clock_fragment) |         context.updateTextColors(clock_fragment) | ||||||
|         val offset = Calendar.getInstance().timeZone.rawOffset |         val offset = calendar.timeZone.rawOffset | ||||||
|         passedSeconds = ((Calendar.getInstance().timeInMillis + offset) / 1000).toInt() |         passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt() | ||||||
|         updateCurrentTime() |         updateCurrentTime() | ||||||
|  |         updateDate() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun updateCurrentTime() { |     private fun updateCurrentTime() { | ||||||
|         val hours = (passedSeconds / 3600) % 24 |         val hours = (passedSeconds / 3600) % 24 | ||||||
|         val minutes = (passedSeconds / 60) % 60 |         val minutes = (passedSeconds / 60) % 60 | ||||||
|  |         val seconds = passedSeconds % 60 | ||||||
|         var format = "%02d:%02d" |         var format = "%02d:%02d" | ||||||
|  |  | ||||||
|         val formattedText = if (context.config.showSeconds) { |         val formattedText = if (context.config.showSeconds) { | ||||||
|             val seconds = passedSeconds % 60 |  | ||||||
|             format += ":%02d" |             format += ":%02d" | ||||||
|             String.format(format, hours, minutes, seconds) |             String.format(format, hours, minutes, seconds) | ||||||
|         } else { |         } else { | ||||||
| @@ -38,12 +41,29 @@ class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayo | |||||||
|  |  | ||||||
|         clock_time.text = formattedText |         clock_time.text = formattedText | ||||||
|  |  | ||||||
|  |         if (hours == 0 && minutes == 0 && seconds == 0) { | ||||||
|  |             updateDate() | ||||||
|  |         } | ||||||
|  |  | ||||||
|         updateHandler.postDelayed({ |         updateHandler.postDelayed({ | ||||||
|             passedSeconds++ |             passedSeconds++ | ||||||
|             updateCurrentTime() |             updateCurrentTime() | ||||||
|         }, ONE_SECOND) |         }, 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() { |     override fun onDetachedFromWindow() { | ||||||
|         super.onDetachedFromWindow() |         super.onDetachedFromWindow() | ||||||
|         updateHandler.removeCallbacksAndMessages(null) |         updateHandler.removeCallbacksAndMessages(null) | ||||||
|   | |||||||
| @@ -2,3 +2,5 @@ package com.simplemobiletools.clock.helpers | |||||||
|  |  | ||||||
| // shared preferences | // shared preferences | ||||||
| const val SHOW_SECONDS = "show_seconds" | const val SHOW_SECONDS = "show_seconds" | ||||||
|  |  | ||||||
|  | const val TABS_COUNT = 3 | ||||||
|   | |||||||
| @@ -15,4 +15,13 @@ | |||||||
|         android:textSize="@dimen/clock_text_size" |         android:textSize="@dimen/clock_text_size" | ||||||
|         tools:text="00:00:00"/> |         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> | </com.simplemobiletools.clock.fragments.ClockFragment> | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ buildscript { | |||||||
|         google() |         google() | ||||||
|         jcenter() |         jcenter() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     dependencies { |     dependencies { | ||||||
|         classpath 'com.android.tools.build:gradle:3.0.1' |         classpath 'com.android.tools.build:gradle:3.0.1' | ||||||
|         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user