Skip to content

Instantly share code, notes, and snippets.

@alwarren
alwarren / HelloViewModel.kt
Last active February 28, 2018 06:49
Android LiveData ViewModel (Kotlin/Dagger)
internal class HelloViewModel @Inject constructor(private val dataSource: Hello) : ViewModel() {
// observed by ViewModel as a trigger to retrieve data from the source
private var liveEndpoint: MutableLiveData<String> = MutableLiveData()
// observed by Activity/Fragment or some other class as a trigger to do something with the data
private var liveData: LiveData<String>
init {
// default observable endpoint
@alwarren
alwarren / AndroidAPI26Gradle.txt
Last active August 23, 2017 21:50
Android API26 (O) Gradle Setup
Android API26 (O) Gradle Setup
--------------------------------------------------------------------------------
#gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
PORTRAIT MODE
MDPI is 320x480 dp = 320x480px (1x)
LDPI is 0.75 x MDPI = 240x360px
HDPI is 1.5 x MDPI = 480x720px
XHDPI is 2 x MDPI = 640x960px
XXHDPI is 3 x MDPI = 960x1440px
XXXHDPI is 4 x MDPI = 1280x1920px
LANDSCAPE MODE
MDPI is 480x320 dp = 480x320px (1x)
@alwarren
alwarren / RecyclerViewAdapter.java
Created August 10, 2017 01:16 — forked from slidenerd/RecyclerViewAdapter.java
A single adapter that supports Cursor + an optional header + optional footer
import android.database.Cursor;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public abstract class RecyclerCursorAdapter<U, V extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnSwipeListener {
//The number of headers to be displayed by default if child classes want a header
public static final int HEADER_COUNT = 1;
//The number of footers to be displated by default if child classes want a footer
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alwarren
alwarren / CursorRecyclerAdapter.java
Created August 8, 2017 14:24 — forked from nesquena/CursorRecyclerAdapter.java
Cursor Adapters for RecyclerView
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 ARNAUD FRUGIER
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@alwarren
alwarren / PerPageTrait.php
Last active April 22, 2016 08:56
A Laravel 5.2 trait that stores a value in the session that can be used with a form select to set the per page value for a length aware paginator.
<?php
namespace App\Traits;
use Illuminate\Http\Request;
/**
* A Laravel 5.2 trait that stores a value in the session that can be used with
* a form select to set the per page value for a length aware paginator.
*