Skip to content

Instantly share code, notes, and snippets.

View hieuwu's full-sized avatar
🌞
Free

Hieu Vu hieuwu

🌞
Free
View GitHub Profile
@hieuwu
hieuwu / OrderDao.kt
Created March 21, 2022 14:59
Order dao
@Dao
interface OrderDao {
//Get an order along with its line items by orderId
@Transaction
@Query("SELECT * FROM orders WHERE orderId = :id")
fun getById(id: String): Flow<OrderWithLineItems>
//Get an order by its status
@Transaction
@Query("SELECT * FROM orders WHERE status = :status LIMIT 1 ")
@hieuwu
hieuwu / WeatherItemAdapter.kt
Last active June 12, 2022 06:59
Multiple view types in RecyclerView - Naive approach
class WeatherItemAdapter :
ListAdapter<Weather, WeatherItemAdapter.WeatherItemViewHolder>(DiffCallback) {
// Other implementation for DiffCallback
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WeatherItemViewHolder {
when (viewType) {
WeatherViewType.DAY.ordinal -> {
val view = LayoutInflater.from(parent.context).inflate(R.layout.weather_day_item, parent, false)
return WeatherDayItemViewHolder(view)
@hieuwu
hieuwu / SwipingItem.kt
Created February 19, 2023 09:23
Swipe to delete item wrapper
val state = rememberDismissState(
confirmStateChange = {
if (it == DismissValue.DismissedToStart) {
viewModel.onRemoveTag(item)
}
true
}
)
SwipeToDismiss(
state = state,
@hieuwu
hieuwu / build.gradle (app)
Created August 1, 2023 14:21
build.gradle (app)
implementation "io.github.jan-tennert.supabase:postgrest-kt:$supabase_version"
implementation "io.github.jan-tennert.supabase:storage-kt:$supabase_version"
implementation "io.github.jan-tennert.supabase:gotrue-kt:$supabase_version"
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-utils:$ktor_version"
@hieuwu
hieuwu / build.gradle (app)
Created August 1, 2023 14:22
build.gradle (app)
plugins {
...
id 'org.jetbrains.kotlin.plugin.serialization' version '$kotlin_version'
...
}
@hieuwu
hieuwu / build.gradle (app)
Created August 1, 2023 14:23
build.gradle (app)
implementation "com.google.dagger:hilt-android:$hilt_version"
annotationProcessor "com.google.dagger:hilt-compiler:$hilt_version"
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
@hieuwu
hieuwu / SupabaseModule.kt
Created August 1, 2023 14:24
SupabaseModule.kt
@InstallIn(SingletonComponent::class)
@Module
object SupabaseModule {
@Provides
@Singleton
fun provideSupabaseClient(): SupabaseClient {
return createSupabaseClient(
supabaseUrl = BuildConfig.SUPABASE_URL,
supabaseKey = BuildConfig.SUPABASE_ANON_KEY
@Serializable
data class ProductDto(
@SerialName("name")
val name: String,
@SerialName("price")
val price: Double,
@SerialName("image")
data class Product(
val id: String,
val name: String,
val price: Double,
val image: String?
)
interface ProductRepository {
suspend fun createProduct(product: Product): Boolean
suspend fun getProducts(): List<ProductDto>?
suspend fun getProduct(id: String): ProductDto
suspend fun deleteProduct(id: String)
suspend fun updateProduct(
id: String, name: String, price: Double, imageName: String, imageFile: ByteArray
)
}