Skip to content

Instantly share code, notes, and snippets.

View dinorahto's full-sized avatar

Dinorah Tovar dinorahto

View GitHub Profile
@dinorahto
dinorahto / ViewPagerAdapter.kt
Created May 1, 2019 17:58
ViewPager adapter for not drag event
/**
* Created by Dinorah Tovar on 12/20/17.
* ViewPager
*/
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
setMyScroller();
@dinorahto
dinorahto / twoObservablesFlatMap.kt
Created May 1, 2019 18:07
Two observables as Flat map
/**
* Returns an observable from a function that decrypts stored user data
*/
fun currentUserObservable(): Observable<UserViewModel> {
return Observable.create(ObservableOnSubscribe<UserViewModel> { subscriber ->
val user = currentUser()
if (user != null)
subscriber.onNext(user)
else
subscriber.onError(Throwable("User is null"))
@dinorahto
dinorahto / BaseActivity.kt
Created May 1, 2019 18:11
Base Activity for Disposables
/**
* Created by Dinorah Tovar on 8/21/18
* Base custom activity managing all the disposables
*/
open class BaseActivity : AppCompatActivity() {
/**
* Keep reference of the active presenter.
*/
@dinorahto
dinorahto / InterceptorAutheticatorOkhttpClient.kt
Created May 1, 2019 18:12
Interceptor Autheticator OkhttpClient
/**
* OkHttpClient
*/
@Provides
@Singleton
fun getUnsafeOkHttpClient(): OkHttpClient {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.HEADERS
interceptor.level = HttpLoggingInterceptor.Level.BODY
val builder = OkHttpClient.Builder()
@dinorahto
dinorahto / TextInputLayoutNoPaddingHintWithDrawable.kt
Created May 1, 2019 18:14
Text Input Layout without padding with Left Drawable
import android.content.Context
import android.graphics.Rect
import android.support.design.widget.TextInputLayout
import android.util.AttributeSet
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method
/**
* Created by Dinorah Tovar on 6/19/18
* Password with
@dinorahto
dinorahto / Interceptor.kt
Created May 1, 2019 18:15
Extending Interceptor for HTTP request
/**
* Created by Dinorah Tovar on 04/04/18.
* Secondary helper interceptor to skip interceptor headers over Data Module
*/
class SupportInterceptor: Interceptor {
/**
* Interceptor class for setting of the headers for every request
@dinorahto
dinorahto / BaseFragment.kt
Created May 1, 2019 18:18
Base Fragment for dispose observables
/**
* Created by Dinorah Tovar on 8/21/18
* All fragments should extend from this fragment.
*/
open class BaseFragment : Fragment() {
/**
* Keep reference of the active presenter
*/
@dinorahto
dinorahto / ProductEntity.kt
Last active July 16, 2019 14:02
Entity Data Class
@Entity(tableName = "Products",
foreignKeys = [ForeignKey(entity = ImagesEntity::class,
parentColumns = arrayOf("imageId"), childColumns = arrayOf("cityId")),
ForeignKey(entity = PricesEntity::class,
parentColumns = arrayOf("skuId"), childColumns = arrayOf("idProduct"))],
indices = [Index(value = ["idProduct", "skuId"])])
data class ProductEntity (
@PrimaryKey(autoGenerate = false)
@ColumnInfo(name = "idProduct")
@dinorahto
dinorahto / Migration.kt
Created July 16, 2019 14:09
Create the migration from SQlite to Room
@Database(entities = [ProductEntity::class], version = SharedContentDataBase.VERSION)
abstract class SharedContentDataBase : RoomDatabase() {
companion object {
const val VERSION = 2
val migrationRoom: Migration = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
//This is where the magic happends
@dinorahto
dinorahto / AddTable.kt
Last active July 16, 2019 14:36
Add Table to old SQLite database
database.execSQL("ALTER TABLE Product ADD COLUMN hasAddedToCart INT")