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
val i = 10.5 | |
if (i in 1..10) { | |
println("$i is within the range of 1-10") | |
} else { | |
println("$i is not in range of 1-10") | |
} | |
// outputs "10.5 is within the range of 1-10" |
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
val i = 10.5 | |
if (i in 1..10) { | |
println("$i is within the range of 1-10") | |
} else { | |
println("$i is not in range of 1-10") | |
} | |
// outputs "10.5 is not in range of 1-10" |
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
@kotlin.jvm.JvmName("intRangeContains") | |
public operator fun ClosedRange<Int>.contains(value: Float): Boolean { | |
return start <= value && value <= endInclusive | |
} |
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
@kotlin.jvm.JvmName("intRangeContains") | |
public operator fun ClosedRange<Int>.contains(value: Float): Boolean { | |
return value.toIntExactOrNull().let { if (it != null) contains(it) else false } | |
} | |
internal fun Float.toIntExactOrNull(): Int? { | |
return if (this in Int.MIN_VALUE.toFloat()..Int.MAX_VALUE.toFloat()) this.toInt() else null | |
} |
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
Log.v(TAG, "verbose"); | |
Log.d(TAG, "debug"); | |
Log.i(TAG, "info"); | |
Log.w(TAG, "warning"); | |
Log.e(TAG, "error"); | |
Timber.v("verbose"); | |
Timber.d("debug"); | |
Timber.i("info"); | |
Timber.w("warning"); |
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
public class ProductionLogger extends Timber.Tree { | |
@Override | |
protected void log(int priority, String tag, String message, Throwable t) { | |
if(priority >= Log.WARN) { | |
// do your thing | |
} | |
} | |
} |
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 will strip `Log.v`, `Log.d`, and `Log.i` statements and will leave `Log.w` and `Log.e` statements intact. | |
-assumenosideeffects class android.util.Log { | |
public static boolean isLoggable(java.lang.String, int); | |
public static int v(...); | |
public static int d(...); | |
public static int i(...); | |
} |
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
-assumenosideeffects class timber.log.Timber* { | |
public static *** v(...); | |
public static *** d(...); | |
public static *** i(...); | |
} |
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
data class ViewState( | |
val isLoading: Boolean = false, | |
val progress: Int = 0, | |
val url: String? = null, | |
val isEditing: Boolean = false, | |
val browserShowing: Boolean = false, | |
val showClearButton: Boolean = false | |
) |
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
val viewState: MutableLiveData<ViewState> = MutableLiveData() | |
init { | |
viewState.value = ViewState() | |
} | |
private fun currentViewState(): ViewState = viewState.value!! |