Skip to content

Instantly share code, notes, and snippets.

View ChanSek's full-sized avatar

Chandra Sekhar Nayak ChanSek

View GitHub Profile
@ChanSek
ChanSek / onCreateViewHolder.txt
Last active July 12, 2016 12:26
FirebaseRecyclerView.onCreateViewHolder()
@Override
public VH onCreateViewHolder(ViewGroup parent, int viewType) {
ViewGroup view = (ViewGroup) LayoutInflater.from(parent.getContext()).inflate(mModelLayout, parent, false);
try {
Constructor<VH> constructor = mViewHolderClass.getConstructor(View.class);
return constructor.newInstance(view);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
@ChanSek
ChanSek / ViewHolder
Created July 12, 2016 12:45
Multiple ViewHolder classes for supporting multiple view types
class ViewHolder1 extends RecyclerView.ViewHolder {
...
}
class ViewHolder2 extends RecyclerView.ViewHolder {
...
}
class ViewHolder3 extends RecyclerView.ViewHolder {
...
@ChanSek
ChanSek / FirebaseRecyclerAdapter
Last active May 16, 2020 21:53
FirebaseRecyclerAdapter with multiple view type supported
mAdapter = new FirebaseRecyclerAdapter<User, RecyclerView.ViewHolder>(
User.class, R.layout.item_user, RecyclerView.ViewHolder.class, ref) {
@Override
protected void populateViewHolder(final RecyclerView.ViewHolder viewHolder, final User user,
final int position) {
switch (user.getType()) {
case Constants.USER_TYPE_1:
populateType1((ViewHolder1) viewHolder, user, position);
break;
case Constants.USER_TYPE_2:
@ChanSek
ChanSek / gist:f103fc13423119479b6ff8d7f64f0a78
Created August 14, 2016 09:56
<id> can overlap <id> if <string>, <string> grow due to localized text expansion
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
@ChanSek
ChanSek / gist:6020ae0a392386a5bc7c2b85063d5893
Created August 14, 2016 11:07
CoordinatorLayout with background
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<!-- Some conetnt -->
</android.support.design.widget.CoordinatorLayout>
@ChanSek
ChanSek / gist:848f4b9bd9fccc3361b9aa269ad3a905
Created February 10, 2017 15:16
Inner class accessing private method of Outer class
public class Printer {
private void printHello() {
System.out.println("Hello World");
}
private class Test {
private void testPrint() {
printHello();
}
}
// Delete a remote branch
git push origin --delete <branch_name>
// Delete a local branch
git branch -d <branch_name>
// Force delete a local branch
git branch -D <branch_name>
@ChanSek
ChanSek / User.java
Created May 19, 2017 14:04
Java sample User class for migrating to Kotlin
public class User {
private String userId;
private String email;
private String userName;
private String name;
private String phNumber;
private String country;
private String profilePic;
@ChanSek
ChanSek / User.kt
Created May 19, 2017 14:07
User class after migrated to Kotlin
class User {
var userId: String? = null
var email: String? = null
var userName: String? = null
var name: String? = null
var phNumber: String? = null
var country: String? = null
var profilePic: String? = null
@ChanSek
ChanSek / User.kt
Last active May 19, 2017 14:12
User class after removing null
class User {
var userId: String = ""
var email: String = ""
var userName: String = ""
var name: String = ""
var phNumber: String = ""
var country: String = ""
var profilePic: String = ""