Skip to content

Instantly share code, notes, and snippets.

View daniel-stoneuk's full-sized avatar

Daniel Stone daniel-stoneuk

View GitHub Profile
@daniel-stoneuk
daniel-stoneuk / EmptyViewListAdapter.kt
Created June 8, 2020 10:07
Empty View List Adapter - show view when ListAdapter is empty
import android.view.View
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
abstract class EmptyViewListAdapter<T, VH: RecyclerView.ViewHolder>(itemCallback: DiffUtil.ItemCallback<T>,
private val emptyView: View): ListAdapter<T, VH>(itemCallback) {
override fun onCurrentListChanged(previousList: MutableList<T>, currentList: MutableList<T>) {
if (currentList.size == 0) {
@daniel-stoneuk
daniel-stoneuk / MotionLayoutOnEndExtension.kt
Created June 3, 2020 10:16
Motion Layout .doOnEnd() kotlin extension function
import androidx.constraintlayout.motion.widget.MotionLayout
fun MotionLayout.doOnEnd(onEnd: () -> Unit) {
this.setTransitionListener(object: MotionLayout.TransitionListener {
override fun onTransitionTrigger(
p0: MotionLayout?,
p1: Int,
p2: Boolean,
p3: Float
@daniel-stoneuk
daniel-stoneuk / ListGenerator.java
Created June 2, 2019 09:16
Merge sort implemented with Java
import java.util.Random;
public class ListGenerator {
public static int[] generateList(int size, int upperBound) {
Random r = new Random();
int[] array = new int[size];
for (int i = 0; i < size; i++) {
int random = r.nextInt(upperBound);
array[i] = r.nextInt(upperBound);
@daniel-stoneuk
daniel-stoneuk / 01.java
Created August 14, 2018 10:48
Polling Retrofit API
private final CompositeDisposable disposables = new CompositeDisposable();
// START POLLING every 5 seconds, with a timeout of 5 seconds.
disposables.add(Observable.interval(0, 5, TimeUnit.SECONDS)
.flatMap((Function<Long, ObservableSource<?>>) aLong -> energyHiveService.getCurrentValuesSummary()
.takeUntil(Observable.timer(5, TimeUnit.SECONDS))
)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
// Use result, example below.
@daniel-stoneuk
daniel-stoneuk / Anagram.java
Created January 7, 2018 12:38
British Informatics Olympiad 2010 Anagram
// Quick solution to solve question one of http://www.olympiad.org.uk/papers/2010/bio/bio-10-exam.pdf
package com.danielstone.alevels;
import java.util.Arrays;
import java.util.Scanner;
public class Anagram {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Integer userInput = input.nextInt();
@daniel-stoneuk
daniel-stoneuk / ExampleUse.java
Last active July 14, 2017 09:31 — forked from 1zaman/ResultHolder.java
Loader for Retrofit 2.3 API. (Forked) Using support library implementation.
Call<T> call = retrofitService.apiCall();
RetrofitLoader.load(this, getSupportLoaderManager(), id, call, new RetrofitLoader.RetrofitLoaderCallback<T>() {
@Override
public void onLoad(Response<T> result) {
Log.i(TAG, "onLoad: " + result.body());
}
@Override
public void onFail(Throwable t) {
@daniel-stoneuk
daniel-stoneuk / cRandomGen.js
Created June 9, 2017 13:15
Javascript closure examples.
/**
* cRandomGen
* @param input
* @param inRender render object
* @returns {cRandomGen}
*/
function cRandomGen(input, inRender)
{
this.input = input;
package com.danielstone.energyhive.intro;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.util.Log;
@daniel-stoneuk
daniel-stoneuk / AndroidManifest.xml
Created February 21, 2017 22:33
Content Provider
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.evo.passwordgenerator">
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fitsSystemWindows="true">
@daniel-stoneuk
daniel-stoneuk / AndroidManifest.xml
Created February 21, 2017 22:31
COntent PRovider
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.evo.passwordgenerator">
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fitsSystemWindows="true">