Skip to content

Instantly share code, notes, and snippets.

fun setTimeToStartOfDay(calendar: Calendar): Calendar {
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar
}
fun setTimeToEndOfDay(calendar: Calendar): Calendar {
calendar.set(Calendar.HOUR_OF_DAY, 23)
fun getDaysBetweenRoundUp(t1: Long, t2: Long): Int {
val msDiff = t2 - t1
val daysFraction = msDiff.toFloat() / android.text.format.DateUtils.DAY_IN_MILLIS
return ceil(daysFraction.toDouble()).toInt()
}
fun getDaysBetweenRoundUp(c1: Calendar, c2: Calendar): Int {
return getDaysBetweenRoundUp(c1.timeInMillis, c2.timeInMillis)
}
object ReadableDateUtils {
private const val flagsDateOnly = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_ABBREV_MONTH
private const val flagsDateOnlyWithDayOfWeek =
DateUtils.FORMAT_SHOW_DATE or
DateUtils.FORMAT_ABBREV_MONTH or
DateUtils.FORMAT_ABBREV_WEEKDAY or
DateUtils.FORMAT_SHOW_WEEKDAY
@tomergoldst
tomergoldst / ViewPagerAdapter.java
Last active January 20, 2019 08:26
An implementation of PagerAdapter for views
/**
* View Pager Adapter - An implementation of PagerAdapter for views
* Simplified implementation which enables access to created view at a specific position
* for controlling the view status and force pre creation of a view when necessary
*
* Created by tomergoldst on 15/11/2018.
*/
public abstract class ViewPagerAdapter<T> extends PagerAdapter {
@tomergoldst
tomergoldst / KeyStoreDataSource.kt
Created December 2, 2018 12:05
Key-Value store interface and shared preferences implementation example plus memory (mock) implemetnation in Kotlin
interface KeyStoreDataSource {
fun getString(key: String, defaultValue: String?): String?
fun putString(key: String, value: String?)
fun getInt(key: String, defaultValue: Int): Int
fun putInt(key: String, value: Int)
fun getLong(key: String, defaultValue: Long): Long
fun putLong(key: String, value: Long)
fun getFloat(key: String, defaultValue: Float): Float
fun putFloat(key: String, value: Float)
@tomergoldst
tomergoldst / Singleton.kt
Last active August 21, 2021 21:11
Kotlin singleton pattern with class paramters
class Singelton private constructor(context: Context) {
companion object {
@Volatile
private var INSTANCE: Singelton? = null
fun getInstance(context: Context): Singelton =
INSTANCE ?: synchronized(this) {
INSTANCE ?: Singelton(context).also { INSTANCE = it }
@tomergoldst
tomergoldst / KeyStoreDataSource.java
Last active December 2, 2018 09:18
Key-Value store interface and shared preferences implementation example plus memory (mock) implemetnation
public interface KeyStoreDataSource {
String getString(String key, String defaultValue);
void putString(String key, String value);
int getInt(String key, int defaultValue);
void putInt(String key, int value);
long getLong(String key, long defaultValue);
void putLong(String key, long value);
float getFloat(String key, float defaultValue);
void putFloat(String key, float value);