Skip to content

Instantly share code, notes, and snippets.

View PrashamTrivedi's full-sized avatar
🏠
Working from home

Prasham Trivedi PrashamTrivedi

🏠
Working from home
View GitHub Profile
@PrashamTrivedi
PrashamTrivedi / LoginActivity.kt
Last active December 21, 2017 12:29
Files to reproduce databinding error in 3.1.0-alpha06
class LoginActivity : AppCompatActivity() {
@Inject lateinit var loginPresenter: LoginPresenter
lateinit var binding: ActivityLoginBinding
val loginViewModel: LoginViewmodel by lazy {
LoginViewmodel()
}
@PrashamTrivedi
PrashamTrivedi / ApiResponse.kt
Last active February 21, 2018 14:06
Code for blogpost. Koroutines, MVP+VM
sealed class ApiResponse<T> {
class Loading<Unit> : ApiResponse<Unit>()
class Nothing<Unit> : ApiResponse<Unit>()
class NoInternet<Unit> : ApiResponse<Unit>()
class ConnectionError<Unit>(val throwable: Throwable, val error: String) : ApiResponse<Unit>()
data class Success<T>(val response: Response<T>,
val data: T? = response.body(),
val headers: Headers? = response.headers()) : ApiResponse<T>()
data class SuccessData<T>(val data: T?) : ApiResponse<T>()
@PrashamTrivedi
PrashamTrivedi / io17Modified.xml
Created November 29, 2017 07:33
Modified intellij theme for io17, with Font Ligatures, Logcat colors and changed size
<scheme name="io17" version="142" parent_scheme="Darcula">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2017-11-13T20:44:16</property>
<property name="ide">AndroidStudio</property>
<property name="ideVersion">3.0.0.18</property>
<property name="modified">2017-11-29T13:01:35</property>
<property name="originalScheme">Darcula</property>
</metaInfo>
<option name="EDITOR_FONT_SIZE" value="16" />
@PrashamTrivedi
PrashamTrivedi / Spaniard.kt
Last active September 14, 2017 08:16
Utils for creating spans with minimum texts
package com.spaniard
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.CharacterStyle
class Spaniard(val originalString: String) {
var spannableStringBuilder = SpannableStringBuilder(originalString)
//Functions.kt
public fun Context.setNotification(id: Int = 0, builderMethod: NotificationCompat.Builder.() -> Any) {
val builder = NotificationCompat.Builder(this)
builder.apply {
builderMethod()
}
notificationManager().notify(id, builder.build())
}
//FCM Service.kt
[email protected](2488, {
//Part of Functions.kt, this and below 3 functions helps to create dialog.
public fun Context.showDialog(cancelable: Boolean = false, cancelableTouchOutside: Boolean = false, builderFunction: AlertDialog.Builder.() -> Any) {
val builder = AlertDialog.Builder(this)
builder.builderFunction()
val dialog = builder.create();
dialog.setCancelable(cancelable)
dialog.setCanceledOnTouchOutside(cancelableTouchOutside)
dialog.show()
}
//DataRepository.kt, which handles all db handling, where I have passed 3 callbacks, finished, error or maximum tabs reached
public fun addTab(tabModelToInsert: TabModel,
onFinished: (tabModel: TabModel) -> Unit = {},
onError: (tabModel: TabModel, message: String) -> Unit = { tabModel, message -> },
onMaxTabReached: (tabModel: TabModel) -> Unit = {}) {
if (canAddMoreTabs()) {
val currentMaxId = getCurrentMaxId() ?: 0
try {
realm.executeTransaction {
addTabModelToRealm()
@PrashamTrivedi
PrashamTrivedi / Callbacks.kt
Last active April 12, 2017 05:58
Kotlin examples for my post
//DataRepository.kt, which handles all db handling, where I have passed 3 callbacks, finished, error or maximum tabs reached
public fun addTab(tabModelToInsert: TabModel,
onFinished: (tabModel: TabModel) -> Unit = {},
onError: (tabModel: TabModel, message: String) -> Unit = { tabModel, message -> },
onMaxTabReached: (tabModel: TabModel) -> Unit = {}) {
if (canAddMoreTabs()) {
val currentMaxId = getCurrentMaxId() ?: 0
try {
realm.executeTransaction {
addTabModelToRealm()