Skip to content

Instantly share code, notes, and snippets.

View khunzohn's full-sized avatar
🏠
Working from home

khunzohn khunzohn

🏠
Working from home
  • BandLab
  • Myanmar
View GitHub Profile
@khunzohn
khunzohn / YearFragment.java
Created November 13, 2015 02:03
Nested RecyclerView within another RecyclerView used in generating calendar 's year grid view.
package com.hilllander.naunginlecalendar.view.fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@khunzohn
khunzohn / YearMainAdapter.java
Created November 13, 2015 02:08
Outer RecyclerView adapter
package com.hilllander.naunginlecalendar.util.adapter;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@khunzohn
khunzohn / YearInnerAdapter.java
Created November 13, 2015 02:09
Inner RecyclerView Adapter
package com.hilllander.naunginlecalendar.util.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.hilllander.naunginlecalendar.R;
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin_extensions)
welcomeMessage.text = "Hello Kotlin!"
helloButton.setOnClickListener { toast.("Hello Kotlin") }
}
fun setMessaeg(message: String) {
welcomeMessage.text = message // this wont call findViewById again
public class Utils {
public static String mapDigitToWord(int digit) throws DigitRangeException {
if(digit < 0 || digit > 9)
throw new DigitRangeException();
switch (digit) {
case 0: return "Zero";
case 1: return "One";
// case 2,3,...9
default: return "";
public class DigitMapper {
public DigitMapper() {
}
public String mapToWord(int digit) throws DigitRangeException {
if (digit < 0 || digit > 9) throw new DigitRangeException();
switch (digit) {
fun Int.mapToWord(): String {
val word: String
when (this) { // this refers to Int with its scope limited to the method level
0 -> word = "Zero"
1 -> word = "One"
2 -> word = "Two"
// 3,4,5,6,7,8,9
else -> word = "Invalid Digit Range"
}
return word
override fun onCreate(savedInstanceState : Bundle?) {
setContentView(R.layout.activity_upload)
val digit = 2
val wordTwo: String = digit.mapToWord() // return "Two"
}
@khunzohn
khunzohn / User.java
Last active January 23, 2018 18:27
Data object that contains States information
public final class User {
public final String id;
public final String name;
public final Throwable error; // the reason for failing to fetch will be stored here
public final State state; //either of SUCCESS,PROGRESS,ERROR enum
public User(Throwable error, State state, String id, String name) {
this.error = error;
this.state = state;
this.id = id;