Skip to content

Instantly share code, notes, and snippets.

View ajaypro's full-sized avatar
:octocat:
open source = great knowledge + fast upgrade

AjayDeepak ajaypro

:octocat:
open source = great knowledge + fast upgrade
  • Plume - Smart Wifi Services
  • Amersterdam, Netherlands
View GitHub Profile
@ajaypro
ajaypro / gist:3209347ba8ab9acd23e932a3e4f3806e
Created November 3, 2018 09:35
Activity from which I'm taking geopoint
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;
@ajaypro
ajaypro / gist:88a159ed4eb3205bc3a7288efea292ce
Created November 3, 2018 09:36
Model Class - OfflineData.java
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
@ajaypro
ajaypro / introrx.md
Created November 24, 2018 07:38 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@ajaypro
ajaypro / Pair & Triple in kotlin
Last active June 6, 2019 08:46
To have multiple return types using Pair and Triple in kotlin, Also read infixfunction, destructuring declaration of variables to combine and use with pair and triple
/**
* 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
*/
@ajaypro
ajaypro / LabledReturn from lambda and function
Last active August 13, 2019 12:14
Learn how to use unlabled and labled return from function and lambdas
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
@ajaypro
ajaypro / Using lazy in Kotlin
Last active August 30, 2019 10:11
Kotlin lazy functions
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
@ajaypro
ajaypro / RailwayOP-CompleteExample.kt
Created September 13, 2019 10:19 — forked from antonyharfield/RailwayOP-CompleteExample.kt
Railway Oriented Programming in Kotlin (as described here)
// 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)
@ajaypro
ajaypro / "actionDone" does not work
Created December 14, 2019 12:47
android:imeOptions="actionDone" does not work
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"
@ajaypro
ajaypro / static and dynamic text display.txt
Last active February 12, 2020 05:39
Displaying static and dynamic data in a view with a simple technique
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