(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
package io.github.project_travel_mate.destinations.description; | |
import android.arch.persistence.room.TypeConverter; | |
import android.arch.persistence.room.TypeConverters; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.v7.app.AppCompatActivity; |
package io.github.project_travel_mate.destinations.offlinedata; | |
import android.arch.persistence.room.ColumnInfo; | |
import android.arch.persistence.room.Entity; | |
import android.arch.persistence.room.PrimaryKey; | |
import android.arch.persistence.room.TypeConverters; | |
import android.content.Context; | |
import org.osmdroid.util.GeoPoint; |
@Database(entities = {objects.ChecklistItem.class, OfflineData.class}, version = 4, exportSchema = false) | |
@TypeConverters({DateConverter.class, GeopointsConverter.class}) | |
public abstract class DbChecklist extends RoomDatabase { | |
private static final Object LOCK = new Object(); | |
private static final String DATABASE_NAME = "****.db"; | |
private static DbChecklist sInstance; | |
public static DbChecklist getsInstance(Context context) { | |
//to make sure that Singleton Pattern is followed |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
/** | |
* Usage of infix functio, Pair<String, Int> and multiple return types | |
*/ | |
fun main() { | |
/** you can assign the variables of the Pair to another variable and use those | |
* variables like below | |
*/ | |
Labledreturn from function | |
fun main(args: Array<String>) { | |
foo(listOf(1,0,3,4)) | |
} | |
fun foo(ints: List<Int>) { | |
ints.forEach inner@ { | |
if (it == 0) return@inner | |
When we have to define a variable that will be later initialized as done below. | |
fun main() { | |
var lazyValue: Int? = null | |
fun getlazyValue(): Int?{ | |
if(lazyValue == null){ | |
lazyValue = 45 | |
// Result is a superpowered enum that can be Success or Failure | |
// and the basis for a railway junction | |
sealed class Result<T> | |
data class Success<T>(val value: T): Result<T>() | |
data class Failure<T>(val errorMessage: String): Result<T>() | |
// Composition: apply a function f to Success results | |
infix fun <T,U> Result<T>.then(f: (T) -> Result<U>) = | |
when (this) { | |
is Success -> f(this.value) |
consider you want to have an EditText for taking only alpha numeric values as input. | |
<android.support.v7.widget.AppCompatEditText | |
android:id="@+id/newDeliverable" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginEnd="8dp" | |
android:layout_marginStart="8dp" | |
android:digits="1234567890 abcdefghijklmnopqrstuvwxyz" | |
android:hint="@string/hint_add_new_deliverable" |
UseCase: If we want to show in a textview "Model : BMW" | |
model - static data | |
BMW - dynamic data, If your doing a n/w call and in your model you have a model attribute for vehcile object, below is one of approach. | |
------- | |
define this in your strings.xml | |
<string name="display_model">Model %s</string> | |
* In case you have a data object vehicle as a livedata then you do something like this in your Viewmodel | |
* displayModel is a variable that will be used by data binding to show in your layout |