Skip to content

Instantly share code, notes, and snippets.

View NezSpencer's full-sized avatar

Nnabueze Uhiara NezSpencer

  • Portugal
View GitHub Profile
import com.google.firebase.auth.FirebaseAuth
data class AuthState(val state: Progress,
val auth: FirebaseAuth?)
@NezSpencer
NezSpencer / SubViewModel.kt
Created March 16, 2019 18:46
Activity viewModel
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import android.text.TextUtils
import com.google.firebase.auth.FirebaseAuth
class SubViewModel : ViewModel(), FirebaseAuth.AuthStateListener{
private val mAuth : FirebaseAuth = FirebaseAuth.getInstance()
private val _authLivedata : MutableLiveData<AuthState> = MutableLiveData()
val authLivedata : LiveData<AuthState>
@NezSpencer
NezSpencer / SubActivity.kt
Created March 16, 2019 10:58
Activity with viewModel pattern applied
import android.app.ProgressDialog
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
@NezSpencer
NezSpencer / SubActivity.kt
Created March 14, 2019 21:22
Callback-based Firebase auth code. This allows user to sign up and login and also monitors the state of user authentication
import android.app.ProgressDialog
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import com.nezspencer.testapp.databinding.ActivitySubBinding
val list = mutableListOf<String>()
for (i in 1 .. 50)
list.add("Text name $i")
list[0] = "" //dummy data for header
list.add("") // dummy data for footer
@NezSpencer
NezSpencer / MainActivity.kt
Created March 10, 2019 07:26
Recyclerview adapter with the header-footer pattern applied
inner class ItemAdapter(private val list: MutableList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val itemHeader = 20
private val itemBody = 21
private val itemFooter = 22
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): RecyclerView.ViewHolder {
return when(p1){
itemHeader -> HeaderHolder(ItemHeaderBinding.inflate(LayoutInflater.from(p0.context), p0, false))
itemBody -> BodyHolder(ItemNameBinding.inflate(LayoutInflater.from(p0.context), p0, false))
else -> FooterHolder(ItemFooterBinding.inflate(LayoutInflater.from(p0.context), p0, false))
}
@NezSpencer
NezSpencer / item_footer.xml
Created March 10, 2019 07:21
Recyclerview Footer item
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_image"
android:layout_width="200dp"
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
@NezSpencer
NezSpencer / activity_main.xml
Created March 9, 2019 21:00
recycler view with other views in a scrollView
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView android:layout_width="match_parent"
android:fillViewport="true"
android:padding="16dp"
android:layout_height="match_parent">