Skip to content

Instantly share code, notes, and snippets.

@ruben-h
ruben-h / CountryListArrayAdapter.java
Last active August 29, 2015 14:21
CountryListArrayAdapter before Butterknife
public class CountryListArrayAdapter extends ArrayAdapter<CountrycodeActivity.Country> {
private final List<CountrycodeActivity.Country> list;
private final Activity context;
static class ViewHolder {
protected TextView name;
protected ImageView flag;
}
@ruben-h
ruben-h / CountryListArrayAdapter-butter.java
Last active August 29, 2015 14:21
CountryListArrayAdapter with Butterknife
public class CountryListArrayAdapter extends ArrayAdapter<CountrycodeActivity.Country> {
private final List<CountrycodeActivity.Country> list;
private LayoutInflater inflator;
static class ViewHolder {
@InjectView(R.id.name) TextView name;
@InjectView(R.id.flag) ImageView flag;
public ViewHolder(View view){
@ruben-h
ruben-h / Codeship dokku deployment recipe.md
Last active August 29, 2015 14:22 — forked from bibstha/gist:49540af53fa0ec5ab869
Codeship deployment to a dokku app

After migrating from heroku to dokku, we had to also chance codeship so we deploy to dokku. I followed the following steps to successfully deploy to dokku.

  1. Save the public key of the codeship project. It is found in Project Settings > General Settings.
  2. Copy the public key to a file /tmp/codeship_projectname.pub.
  3. Make sure when pasting, all the contents are in a single line and not multiple lines.
  4. Add the public key to dokku using the following command in console. Reference.
cat /tmp/codeship_projectname.pub | ssh root@yourdokkuinstance "sudo sshcommand acl-add dokku [description]"

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder

Example of click listener in RecyclerView

static class ActionItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    @InjectView(R.id.actionItemLayout) LinearLayout actionItemLayout;
    @InjectView(R.id.actionIcon) ImageView actionIcon;
    @InjectView(R.id.actionTitle) TextView actionTitle;

    OrganizationContactAction mItem; //Keep item ref for clickevents
 private ActionItemViewHolderClicks listener; //click event listener
@ruben-h
ruben-h / Devices.java
Last active August 29, 2015 14:26
Helper class to get the consumer friendly device name.
/*
* Copyright (C) 2014 Jared Rummler <jared.rummler@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
@ruben-h
ruben-h / RxJava.md
Created September 28, 2015 12:15 — forked from cesarferreira/RxJava.md
Party tricks with RxJava, RxAndroid & Retrolambda

View Click

Instead of the verbose setOnClickListener:

RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));

Filter even numbers

Observable
    .just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
@ruben-h
ruben-h / api.java
Created September 28, 2015 12:19 — forked from cesarferreira/api.java
RxJava and Retrofit sample
public interface API {
@GET("/user/{username}/dogs")
Observable<Dog> getAllDogsOf(@Path("username") String username);
@GET("/dog/{id}")
Observable<Dog> getDogInfoById(@Path("id") int dogId);
}
@ruben-h
ruben-h / Input validation with RxJs and rx.angular.js
Last active February 27, 2017 18:22
Validation of 3 different inputs, and enabling submit button only when all are valid
/**
* Handle send later input validation, and enabling/disabling the
* submit button if all requirements are met
* (all three fields are filled out and valid).
*/
$scope.formIsValid = false;
function returnNewvalue(data){
return data.newValue;
}
@ruben-h
ruben-h / migration-guide.md
Created December 15, 2015 10:03 — forked from staltz/migration-guide.md
How to show migration guides in GitHub Markdown

How to show migration guides in GitHub Markdown

Use the diff code highlighting tag.

  ```diff
  - foo
  + bar

Example: