Skip to content

Instantly share code, notes, and snippets.

@gorrotowi
Last active December 14, 2019 21:01
Show Gist options
  • Save gorrotowi/b6213bcf44830f235bc08bf2867d572b to your computer and use it in GitHub Desktop.
Save gorrotowi/b6213bcf44830f235bc08bf2867d572b to your computer and use it in GitHub Desktop.
FirebaseWorkshop
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcProducts"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_add"
app:useCompatPadding="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.gorrotowi.firebaseworkshop.R
import com.gorrotowi.firebaseworkshop.entities.FirebaseProduct
import kotlinx.android.synthetic.main.item_product.view.*
import kotlin.properties.Delegates
class AdapterProducts : RecyclerView.Adapter<AdapterProducts.ProducsViewHolder>() {
var dataSource: List<FirebaseProduct> by Delegates.observable(emptyList()) { _, _, _ -> notifyDataSetChanged() }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProducsViewHolder =
ProducsViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.item_product,
parent,
false
)
)
override fun getItemCount(): Int = dataSource.size
override fun onBindViewHolder(holder: ProducsViewHolder, position: Int) {
holder.bindView(dataSource[position])
}
class ProducsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindView(data: FirebaseProduct) {
with(itemView) {
txtItemProductName?.text = data.name
txtItemProductDescr?.text = data.url
}
}
}
}
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'ru.superjob:kotlin-permissions:1.0.3'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
data class FirebaseProduct(
val name: String = "",
val description: String = "",
val url: String = ""
)
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgItemProduct"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_margin="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/avatars" />
<TextView
android:id="@+id/txtItemProductName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="10dp"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@id/txtItemProductDescr"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imgItemProduct"
app:layout_constraintTop_toTopOf="@id/imgItemProduct"
tools:text="Product Name" />
<TextView
android:id="@+id/txtItemProductDescr"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imgItemProduct"
app:layout_constraintTop_toBottomOf="@id/txtItemProductName"
tools:text="Product Description" />
</androidx.constraintlayout.widget.ConstraintLayout>
import com.google.gson.annotations.SerializedName
data class ProductJson(
@field:SerializedName("descrip")
val descrip: String? = null,
@field:SerializedName("name")
val name: String? = null,
@field:SerializedName("url")
val url: String? = null
)
https://tinyurl.com/firebaseworkshopdevfest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment