Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Add support for 24 hour clock (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth authored Oct 24, 2022
1 parent 3946578 commit 6c91189
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/dev/sasikanth/pinnit/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.sasikanth.pinnit.di

import android.content.Context
import android.text.format.DateFormat
import androidx.room.Room
import com.spotify.mobius.android.runners.MainThreadWorkRunner
import com.spotify.mobius.runners.WorkRunner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.sasikanth.pinnit.di

import android.content.Context
import android.text.format.DateFormat
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import dev.sasikanth.pinnit.di.DateTimeFormat.Type.ScheduleDateFormat
import dev.sasikanth.pinnit.di.DateTimeFormat.Type.ScheduleTimeFormat
Expand All @@ -21,7 +24,20 @@ object DateTimeFormatterModule {

@Provides
@DateTimeFormat(ScheduleTimeFormat)
fun providesScheduleTimeFormat(): DateTimeFormatter {
return DateTimeFormatter.ofPattern("h:mm a")
fun providesScheduleTimeFormat(
isClock24HourFormat: Boolean
): DateTimeFormatter {
return if (isClock24HourFormat) {
DateTimeFormatter.ofPattern("HH:mm")
} else {
DateTimeFormatter.ofPattern("h:mm a")
}
}

@Provides
fun providesIsClock24HourFormat(
@ApplicationContext context: Context
): Boolean {
return DateFormat.is24HourFormat(context)
}
}
12 changes: 11 additions & 1 deletion app/src/main/java/dev/sasikanth/pinnit/editor/EditorScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.sasikanth.pinnit.editor

import android.content.Context
import android.os.Bundle
import android.text.format.DateFormat
import android.text.util.Linkify
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -71,6 +72,9 @@ class EditorScreen : Fragment(), EditorScreenUi {
@DateTimeFormat(ScheduleTimeFormat)
lateinit var scheduleTimeFormatter: DateTimeFormatter

@set:Inject
var isClock24HourFormat: Boolean = false

private val viewModel: EditorScreenViewModel by viewModels()

private val args by navArgs<EditorScreenArgs>()
Expand Down Expand Up @@ -444,8 +448,14 @@ class EditorScreen : Fragment(), EditorScreenUi {
}

private fun showTimePickerDialog(time: LocalTime) {
val timeFormat = if (isClock24HourFormat) {
TimeFormat.CLOCK_24H
} else {
TimeFormat.CLOCK_12H
}

val timePicker = MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_12H)
.setTimeFormat(timeFormat)
.setHour(time.hour)
.setMinute(time.minute)
.build()
Expand Down

0 comments on commit 6c91189

Please sign in to comment.