mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 02:46:54 -04:00
implement favorite button
This commit is contained in:
@@ -15,12 +15,18 @@ interface UserDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun saveAll(entities: List<UserEntity>)
|
||||
|
||||
@Query("UPDATE ${UserEntity.TABLE_NAME} SET isFavorite = :favorite WHERE id = :id")
|
||||
fun saveFavorite(id: Int, favorite: Boolean): Int
|
||||
|
||||
@get:Query("SELECT * FROM ${UserEntity.TABLE_NAME}")
|
||||
val all: List<UserEntity>
|
||||
|
||||
@Query("SELECT * FROM ${UserEntity.TABLE_NAME}")
|
||||
@Query("SELECT * FROM ${UserEntity.TABLE_NAME} ORDER BY id ASC")
|
||||
fun getAllUsers(): List<UserEntity>
|
||||
|
||||
@Query("SELECT * FROM ${UserEntity.TABLE_NAME} WHERE isFavorite = 1 ORDER BY id ASC")
|
||||
fun getFavoriteUsers(): List<UserEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${UserEntity.TABLE_NAME}")
|
||||
fun count(): Int
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ data class UserEntity(
|
||||
val userName: String,
|
||||
val email: String,
|
||||
val phone: String,
|
||||
val website: String
|
||||
val website: String,
|
||||
val isFavorite: Boolean = true
|
||||
) {
|
||||
companion object {
|
||||
const val TABLE_NAME = "users"
|
||||
|
||||
@@ -4,4 +4,5 @@ sealed class RequestStatus {
|
||||
object Ready : RequestStatus()
|
||||
object Loading : RequestStatus()
|
||||
object Errored : RequestStatus()
|
||||
object Empty : RequestStatus()
|
||||
}
|
||||
|
||||
@@ -11,3 +11,5 @@ fun <T> LiveData<T>.observeNonNull(owner: LifecycleOwner, func: (T) -> Unit) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun Int.wasUpdated() = this > 0
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.hako.base.navigation
|
||||
|
||||
interface ShowFabButton
|
||||
23
base/src/main/java/com/hako/base/widgets/EmptyOverlay.kt
Normal file
23
base/src/main/java/com/hako/base/widgets/EmptyOverlay.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.hako.base.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.FrameLayout
|
||||
import com.hako.base.R
|
||||
import com.hako.base.extensions.inflate
|
||||
import kotlinx.android.synthetic.main.empty_overlay.view.*
|
||||
|
||||
class EmptyOverlay @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
init {
|
||||
inflate(R.layout.empty_overlay, true)
|
||||
}
|
||||
|
||||
fun setLabel(message: String) {
|
||||
empty_overlay_label.text = message
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.like_button.view.*
|
||||
private const val LIKE_MIN_FRAME = 0
|
||||
private const val LIKE_MAX_FRAME = 28
|
||||
private const val LIKE_ANIM_SPEED = 1f
|
||||
private const val DISLIKE_MIN_FRAME = 28
|
||||
private const val DISLIKE_MIN_FRAME = 29
|
||||
private const val DISLIKE_MAX_FRAME = 70
|
||||
private const val DISLIKE_ANIM_SPEED = 2f
|
||||
|
||||
@@ -29,16 +29,24 @@ class LikeButton @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun dislike() {
|
||||
like_button_animation_view.frame = LIKE_MIN_FRAME
|
||||
like_button_animation_view.frame = DISLIKE_MAX_FRAME
|
||||
}
|
||||
|
||||
fun playLike() {
|
||||
fun play() {
|
||||
if (like_button_animation_view.frame <= LIKE_MAX_FRAME){
|
||||
playDislike()
|
||||
} else {
|
||||
playLike()
|
||||
}
|
||||
}
|
||||
|
||||
private fun playLike() {
|
||||
like_button_animation_view.setMinAndMaxFrame(LIKE_MIN_FRAME, LIKE_MAX_FRAME)
|
||||
like_button_animation_view.speed = LIKE_ANIM_SPEED
|
||||
like_button_animation_view.playAnimation()
|
||||
}
|
||||
|
||||
fun playDislike() {
|
||||
private fun playDislike() {
|
||||
like_button_animation_view.setMinAndMaxFrame(DISLIKE_MIN_FRAME, DISLIKE_MAX_FRAME)
|
||||
like_button_animation_view.speed = DISLIKE_ANIM_SPEED
|
||||
like_button_animation_view.playAnimation()
|
||||
|
||||
33
base/src/main/res/layout/empty_overlay.xml
Normal file
33
base/src/main/res/layout/empty_overlay.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@color/soft_background">
|
||||
|
||||
<com.airbnb.lottie.LottieAnimationView
|
||||
android:id="@+id/empty_overlay_animation_view"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:scaleType="centerCrop"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.39"
|
||||
app:lottie_autoPlay="true"
|
||||
app:lottie_loop="true"
|
||||
app:lottie_rawRes="@raw/empty_animation" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_overlay_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="No tienes favoritos!"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="@+id/empty_overlay_animation_view"
|
||||
app:layout_constraintStart_toStartOf="@+id/empty_overlay_animation_view"
|
||||
app:layout_constraintTop_toBottomOf="@+id/empty_overlay_animation_view" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -6,7 +6,7 @@
|
||||
android:background="@color/soft_background">
|
||||
|
||||
<com.airbnb.lottie.LottieAnimationView
|
||||
android:id="@+id/loading_overlay_animation_view"
|
||||
android:id="@+id/network_error_overlay_animation_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="centerInside"
|
||||
@@ -20,14 +20,14 @@
|
||||
app:lottie_rawRes="@raw/network_animation" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/network_error_overlay_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Network error!"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="@+id/loading_overlay_animation_view"
|
||||
app:layout_constraintStart_toStartOf="@+id/loading_overlay_animation_view"
|
||||
app:layout_constraintTop_toBottomOf="@+id/loading_overlay_animation_view" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/network_error_overlay_animation_view"
|
||||
app:layout_constraintStart_toStartOf="@+id/network_error_overlay_animation_view"
|
||||
app:layout_constraintTop_toBottomOf="@+id/network_error_overlay_animation_view" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
1
base/src/main/res/raw/empty_animation.json
Normal file
1
base/src/main/res/raw/empty_animation.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user