-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix/mediapicker (#50) * Bring all glide request managers to one instance * Switch to test implementation * Check if parent is null for searchview * Ensure open close runs on ui thread * Make glide contract internal * Update changelog * Update version Update changelog for previous prs * v3.4.1 (#63) * Check browser intent before launching (#54) * Update changelog * fix/misc (#55) * Add kapt plugin * Fix kau vector * Debug lintRelease * Revert debug * Update dependencies * Check context finishing state before showing dialog (#61) * Keep copy of shared pref rather than application context (#60) * Keep copy of shared pref rather than application context * Add back preference name * Add resolver checks (#62) Squashed commit of the following: commit 7fe57d4 Author: Allan Wang <me@allanwang.ca> Date: Sat Sep 23 15:25:18 2017 -0400 Add missing quote commit ffc3ac9 Author: Allan Wang <me@allanwang.ca> Date: Sat Sep 23 15:20:54 2017 -0400 Update changelog Update gradle Update version name * Fix bundle NPE for activity creation Update changelog * Feature/kpref time picker (#64) * Init kpref time builder and open up other builders * Enable self refresh * Add readme * Update changelog * Update readme
- Loading branch information
Showing
19 changed files
with
146 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package ca.allanwang.kau.kpref.activity.items | ||
|
||
import android.app.TimePickerDialog | ||
import android.view.View | ||
import android.widget.TimePicker | ||
import ca.allanwang.kau.kpref.activity.GlobalOptions | ||
import ca.allanwang.kau.kpref.activity.R | ||
import java.util.* | ||
|
||
/** | ||
* Created by Allan Wang on 2017-06-14. | ||
* | ||
* Text preference | ||
* Holds a textview to display data on the right | ||
* This is still a generic preference | ||
* | ||
*/ | ||
open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText<Int>(builder) { | ||
|
||
interface KPrefTimeContract : KPrefText.KPrefTextContract<Int> { | ||
var use24HourFormat: Boolean | ||
} | ||
|
||
/** | ||
* Default implementation of [KPrefTimeContract] | ||
*/ | ||
class KPrefTimeBuilder( | ||
globalOptions: GlobalOptions, | ||
titleRes: Int, | ||
getter: () -> Int, | ||
setter: (value: Int) -> Unit | ||
) : KPrefTimeContract, BaseContract<Int> by BaseBuilder<Int>(globalOptions, titleRes, getter, setter), TimePickerDialog.OnTimeSetListener { | ||
|
||
override var use24HourFormat: Boolean = false | ||
|
||
override fun onTimeSet(view: TimePicker, hourOfDay: Int, minute: Int) { | ||
setter((hourOfDay to minute).mergeTime) | ||
reloadSelf() | ||
} | ||
|
||
override var textGetter: (Int) -> String? = { | ||
val (hour, min) = it.splitTime | ||
if (use24HourFormat) | ||
String.format(Locale.CANADA, "%d:%02d", hour, min) | ||
else | ||
String.format(Locale.CANADA, "%d:%02d %s", hour % 12, min, if (hour >= 12) "PM" else "AM") | ||
} | ||
|
||
override var onClick: ((itemView: View, innerContent: View?, item: KPrefItemBase<Int>) -> Boolean)? = { itemView, _, item -> | ||
val (hour, min) = item.pref.splitTime | ||
TimePickerDialog(itemView.context, this, hour, min, use24HourFormat).show() | ||
true | ||
} | ||
|
||
private val Int.splitTime: Pair<Int, Int> | ||
get() = Pair(this / 100, this % 100) | ||
|
||
private val Pair<Int, Int>.mergeTime: Int | ||
get() = first * 100 + second | ||
} | ||
|
||
override fun getType(): Int = R.id.kau_item_pref_time_picker | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.