Skip to content

Commit fb11bc0

Browse files
Interval time picker added, event model added, libs updated
1 parent 761eb2a commit fb11bc0

File tree

6 files changed

+159
-57
lines changed

6 files changed

+159
-57
lines changed

app/build.gradle

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -97,52 +97,6 @@ dependencies {
9797
testImplementation 'junit:junit:4.13.2'
9898
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
9999
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
100-
// androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
101-
102-
// ----------------------------------------------------------------
103-
// Compose
104-
// ----------------------------------------------------------------
105-
// implementation "androidx.compose.ui:ui:$compose_version"
106-
// implementation "androidx.compose.ui:ui-util:$compose_version"
107-
// // Tooling support (Previews, etc.)
108-
// implementation "androidx.compose.ui:ui-tooling:1.0.0-beta09" //$compose_version"
109-
// // Animation
110-
// implementation "androidx.compose.animation:animation:$compose_version"
111-
// // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
112-
// implementation "androidx.compose.foundation:foundation:$compose_version"
113-
// implementation "androidx.compose.foundation:foundation-layout:$compose_version"
114-
// // Material Design
115-
// implementation "androidx.compose.material:material:$compose_version"
116-
// // Material design icons
117-
// // implementation "androidx.compose.material:material-icons-core:$compose_version"
118-
// // implementation "androidx.compose.material:material-icons-extended:$compose_version"
119-
// // Integration with observables
120-
// implementation "androidx.compose.runtime:runtime:$compose_version"
121-
// implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
122-
// // Compose Navigation Component
123-
// implementation "androidx.navigation:navigation-compose:2.4.0-alpha04"
124-
// // Constraint Layout
125-
// implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha08"
126-
// // Integration with activities
127-
// implementation 'androidx.activity:activity-compose:1.3.0-rc02'
128-
//
129-
// // Fragments
130-
// // implementation "androidx.fragment:fragment-ktx:1.4.0-alpha01"
131-
//
132-
// // Jetpack Compose Integration for ViewModel
133-
// implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07"
134-
//
135-
// // Paging
136-
// implementation "androidx.paging:paging-compose:1.0.0-alpha11"
137-
//
138-
// // Accompanist
139-
// implementation "com.google.accompanist:accompanist-glide:$accompanist_version"
140-
// implementation "com.google.accompanist:accompanist-insets:$accompanist_version"
141-
// implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version"
142-
// implementation "com.google.accompanist:accompanist-flowlayout:$accompanist_version"
143-
// implementation "com.google.accompanist:accompanist-pager:$accompanist_version"
144-
145-
// ----------------------------------------------------------------
146100

147101
// Material Design
148102
implementation 'com.google.android.material:material:1.4.0'
@@ -191,12 +145,11 @@ dependencies {
191145
implementation 'com.karumi:dexter:6.2.2'
192146

193147
// Timber
194-
implementation 'com.jakewharton.timber:timber:4.7.1'
148+
implementation 'com.jakewharton.timber:timber:5.0.1'
195149

196150
// Hilt
197151
implementation "com.google.dagger:hilt-android:$hilt_version"
198152
kapt "com.google.dagger:hilt-compiler:$hilt_version"
199-
// implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
200153

201154
// Shimmer
202155
implementation 'com.facebook.shimmer:shimmer:0.5.0'
@@ -224,10 +177,10 @@ dependencies {
224177
implementation "org.imaginativeworld.whynotimagecarousel:whynotimagecarousel:2.0.2"
225178

226179
// OneSignal SDK
227-
implementation 'com.onesignal:OneSignal:4.4.2'
180+
implementation 'com.onesignal:OneSignal:4.5.1'
228181

229182
// Coil
230-
implementation("io.coil-kt:coil:1.3.1")
183+
implementation("io.coil-kt:coil:1.3.2")
231184

232185
// Palette
233186
implementation 'androidx.palette:palette-ktx:1.0.0'

app/src/main/java/org/imaginativeworld/simplemvvm/models/Event.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ package org.imaginativeworld.simplemvvm.models
1919
*/
2020
data class Event<out T>(
2121
val value: T,
22-
val id: Int = ++lastId,
22+
private val id: Int = if (lastId == Int.MAX_VALUE) {
23+
lastId = Int.MIN_VALUE
24+
Int.MAX_VALUE
25+
} else lastId++,
2326
) {
2427
companion object {
25-
private var lastId = 0
28+
private var lastId = Int.MAX_VALUE
2629
}
2730
}

app/src/main/java/org/imaginativeworld/simplemvvm/ui/activities/main/MainActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import org.imaginativeworld.simplemvvm.databinding.ActivityMainBinding
1616
import org.imaginativeworld.simplemvvm.interfaces.CommonFunctions
1717
import org.imaginativeworld.simplemvvm.interfaces.MainActivityExtraOnFragmentInteractionListener
1818
import org.imaginativeworld.simplemvvm.interfaces.OnFragmentInteractionListener
19+
import org.imaginativeworld.simplemvvm.models.Event
1920
import org.imaginativeworld.simplemvvm.utils.SharedPref
2021
import org.imaginativeworld.simplemvvm.utils.extensions.hideKeyboard
2122
import org.imaginativeworld.simplemvvm.utils.extensions.indefiniteSnackbar
2223
import org.imaginativeworld.simplemvvm.utils.extensions.longSnackbar
24+
import timber.log.Timber
2325
import javax.inject.Inject
2426

2527
@AndroidEntryPoint
@@ -50,6 +52,13 @@ class MainActivity :
5052
initListeners()
5153

5254
sharedPref.isUserLoggedIn()
55+
56+
val v1 = Event("v1")
57+
val v2 = Event("v2")
58+
val v3 = Event("v3")
59+
val v4 = Event("v4")
60+
61+
Timber.e("$v1, $v2, $v3, $v4")
5362
}
5463

5564
// todo Add this to onResume

app/src/main/java/org/imaginativeworld/simplemvvm/utils/extensions/ExtDialog.kt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.google.android.material.textfield.TextInputEditText
2222
import org.imaginativeworld.simplemvvm.R
2323
import org.imaginativeworld.simplemvvm.databinding.DialogMonthPickerBinding
2424
import org.imaginativeworld.simplemvvm.databinding.DialogSingleInputBinding
25+
import org.imaginativeworld.simplemvvm.databinding.DialogTimePickerBinding
2526
import java.util.*
2627

2728
/**
@@ -221,6 +222,95 @@ fun Int.getMonthName(): String {
221222
}
222223
}
223224

225+
interface TimePickerListener {
226+
fun onSuccess(hour: Int, min: Int)
227+
}
228+
229+
/**
230+
* Show a time picker with interval 30 minutes.
231+
*
232+
* AM | PM | AM
233+
* 12 Hrs: 12 1 2 3 4 5 6 7 8 9 10 11 | 12 1 2 3 4 5 6 7 8 9 10 11 | 12
234+
* 24 Hrs: 0 1 2 3 4 5 6 7 8 9 10 11 | 12 13 14 15 16 17 18 19 20 21 22 23 | 0
235+
* MOD 12: 0 1 2 3 4 5 6 7 8 9 10 11 | 0 1 2 3 4 5 6 7 8 9 10 11 | 0
236+
*/
237+
fun Context.showTimePickerDialog(
238+
currentHour: Int = 0,
239+
currentMin: Int = 1,
240+
listener: TimePickerListener
241+
) {
242+
val hours = (1..12).map { "%02d".format(it) }.toTypedArray()
243+
val minutes = arrayOf("00", "30")
244+
val amPm = arrayOf("AM", "PM")
245+
246+
val binding = DialogTimePickerBinding.inflate(LayoutInflater.from(this))
247+
248+
val builder = AlertDialog.Builder(this, R.style.AppTheme_AlertDialog)
249+
.setView(binding.root)
250+
.setPositiveButton("Ok") { _, _ ->
251+
val hour = if (binding.pickerAmPm.value == 1) { // PM
252+
if (binding.pickerHour.value < 12)
253+
binding.pickerHour.value + 12
254+
else binding.pickerHour.value
255+
} else if (binding.pickerHour.value == 12) // AM
256+
0
257+
else binding.pickerHour.value
258+
259+
listener.onSuccess(
260+
hour,
261+
minutes[binding.pickerMinute.value].toInt()
262+
)
263+
}
264+
.setNegativeButton("Cancel") { _, _ ->
265+
// ...
266+
}
267+
268+
val alertDialog = builder.create()
269+
270+
binding.pickerHour.minValue = 1
271+
binding.pickerHour.maxValue = 12
272+
binding.pickerHour.displayedValues = hours
273+
274+
binding.pickerMinute.minValue = 0
275+
binding.pickerMinute.maxValue = 1
276+
binding.pickerMinute.displayedValues = minutes
277+
278+
binding.pickerAmPm.minValue = 0
279+
binding.pickerAmPm.maxValue = 1
280+
binding.pickerAmPm.displayedValues = amPm
281+
282+
// We will select the next hour
283+
val nextHour = currentHour + 1
284+
val currentHourMod12 = nextHour % 12
285+
binding.pickerHour.value = if (currentHourMod12 == 0) 12 else currentHourMod12
286+
287+
binding.pickerAmPm.value = if (nextHour <= 11) 0 else 1
288+
289+
// Select minute
290+
binding.pickerMinute.value = if (currentMin >= 30) 1 else 0
291+
292+
alertDialog.show()
293+
}
294+
295+
/*
296+
// TODO: add sample usage
297+
298+
private void showTimePicker() {
299+
int mHour = myCalendar.get(Calendar.HOUR_OF_DAY);
300+
int mMinute = myCalendar.get(Calendar.MINUTE);
301+
int mDayOfYear = myCalendar.get(Calendar.DAY_OF_YEAR);
302+
303+
ExtDialogKt.showTimePickerDialog(
304+
this,
305+
mHour,
306+
mMinute,
307+
(hour, minutes) -> {
308+
Timber.e("hour: " + hour + " | minutes: " + minutes);
309+
}
310+
);
311+
}
312+
*/
313+
224314
/**
225315
* Ask to open a url.
226316
*
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<LinearLayout
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_gravity="center"
11+
android:layout_marginTop="16dp"
12+
android:orientation="horizontal">
13+
14+
<NumberPicker
15+
android:id="@+id/picker_hour"
16+
android:layout_width="wrap_content"
17+
android:layout_height="wrap_content"
18+
android:layout_marginEnd="8dp"
19+
android:solidColor="@android:color/white"
20+
android:theme="@style/NumberPickerDefault" />
21+
22+
<TextView
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:layout_gravity="center"
26+
android:layout_marginBottom="2dp"
27+
android:text=":"
28+
android:textColor="@android:color/black"
29+
android:textSize="24sp" />
30+
31+
<NumberPicker
32+
android:id="@+id/picker_minute"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:layout_marginStart="8dp"
36+
android:solidColor="@android:color/white"
37+
android:theme="@style/NumberPickerDefault" />
38+
39+
<NumberPicker
40+
android:id="@+id/picker_am_pm"
41+
android:layout_width="wrap_content"
42+
android:layout_height="wrap_content"
43+
android:layout_marginStart="8dp"
44+
android:solidColor="@android:color/white"
45+
android:theme="@style/NumberPickerDefault" />
46+
47+
</LinearLayout>
48+
49+
</LinearLayout>

build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
buildscript {
44
ext {
5-
kotlin_version = '1.5.21'
5+
kotlin_version = '1.5.30'
66
lifecycle_version = '2.4.0-alpha03'
7-
// compose_version = '1.0.1'
87
hilt_version = '2.38.1'
9-
// accompanist_version = '0.16.1'
108
}
119
repositories {
1210
google()
@@ -15,11 +13,11 @@ buildscript {
1513
jcenter()
1614
}
1715
dependencies {
18-
classpath 'com.android.tools.build:gradle:7.1.0-alpha03'
16+
classpath 'com.android.tools.build:gradle:7.0.2'
1917
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2018
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
2119
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
22-
classpath 'com.google.gms:google-services:4.3.8'
20+
classpath 'com.google.gms:google-services:4.3.10'
2321
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.13.4'
2422
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
2523
}

0 commit comments

Comments
 (0)