feat:修复了数据库表名错误,更新了收藏界面,调整了评分对话框。

This commit is contained in:
LUX-Timber 2024-04-23 13:38:58 +08:00
parent e21ee88828
commit 5fb27f8d85
13 changed files with 226 additions and 37 deletions

View File

@ -4,29 +4,18 @@
<value>
<entry key="app">
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="D:\Android\.android\avd\Pixel_8_API_34.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="D:\Android\.android\avd\Pixel_8_API_34.avd" />
<value value="D:\Android\.android\avd\Pixel_7_API_34.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-04-23T05:33:53.151174800Z" />
<timeTargetWasSelectedWithDropDown value="2024-04-24T03:32:20.457610Z" />
</State>
</entry>
</value>

View File

@ -0,0 +1,25 @@
package com.timber.soft.mylivewallpaper.data
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.timber.soft.mylivewallpaper.tools.AppFinalString
import com.timber.soft.mylivewallpaper.tools.MyApplication
@Database(
entities = [WallpaperData::class], version = AppFinalString.DB_VERSION, exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {
companion object {
val dataBase: AppDatabase by lazy {
getInstance()
}
private fun getInstance(): AppDatabase {
return Room.databaseBuilder(
MyApplication.appContext, AppDatabase::class.java, AppFinalString.DB_NAME
).build()
}
}
abstract fun getWallpaperDao(): WallpaperDao
}

View File

@ -8,7 +8,7 @@ import androidx.room.Update
@Dao
interface WallpaperDao {
@Query("select * from wallpaper where isCollect = :collect ")
@Query("select * from t_wallpaper where isCollect = :collect ")
suspend fun getCollectData(collect: Boolean = true): List<WallpaperData>
@Update

View File

@ -1,6 +1,10 @@
package com.timber.soft.mylivewallpaper.tools
object AppFinalString {
const val TABLE_NAME_WALLPAPER = "wallpaper"
const val DB_NAME = "wallpaper_db"
const val DB_VERSION = 1
const val TABLE_NAME_WALLPAPER = "t_wallpaper"
const val KEY_EXTRA = "KEY_EXTRA"
}

View File

@ -1,6 +1,8 @@
package com.timber.soft.mylivewallpaper.ui.activity
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Build
import android.util.Log
import android.view.View
import android.widget.Toast
@ -11,11 +13,15 @@ import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.timber.soft.mylivewallpaper.data.AppDatabase
import com.timber.soft.mylivewallpaper.data.WallpaperData
import com.timber.soft.mylivewallpaper.databinding.ActivityDetailsBinding
import com.timber.soft.mylivewallpaper.tools.AppFinalString
import com.timber.soft.mylivewallpaper.tools.AppTools.isExist
import com.timber.soft.mylivewallpaper.ui.customerView.DownLoadDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class DetailActivity : BaseActivity(), View.OnClickListener {
@ -28,8 +34,15 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
}
override fun initViews() {
super.initViews()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
window.statusBarColor = Color.TRANSPARENT
}
wallpaperData = intent.getSerializableExtra(AppFinalString.KEY_EXTRA) as WallpaperData
initButton()
initPreImg()
@ -38,8 +51,7 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
private fun initPreImg() {
Glide.with(this).load(wallpaperData.thumbnail)
.transition(DrawableTransitionOptions.withCrossFade())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.listener(object : RequestListener<Drawable> {
.diskCacheStrategy(DiskCacheStrategy.ALL).listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
@ -75,6 +87,7 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
binding.detailsCollect.setOnClickListener(this)
binding.detailsSet.setOnClickListener(this)
binding.detailsPlayButton.setOnClickListener(this)
binding.detailsCollect.isSelected = wallpaperData.isCollect
}
override fun onClick(v: View?) {
@ -88,7 +101,7 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
}
binding.detailsCollect -> {
Log.e("onclick", "detailsCollect has been click!")
setCollect()
}
binding.detailsPlayButton -> {
@ -101,12 +114,37 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
}
}
private fun showDownloadDialog() {
private fun setCollect() {
if (!binding.detailsCollect.isSelected) {
binding.detailsCollect.isSelected = !binding.detailsCollect.isSelected
Toast.makeText(
this@DetailActivity, "You have collected this sound.", Toast.LENGTH_SHORT
).show()
CoroutineScope(Dispatchers.IO).launch {
AppDatabase.dataBase.getWallpaperDao().insertData(wallpaperData.apply {
isCollect = binding.detailsCollect.isSelected
})
}
} else {
binding.detailsCollect.isSelected = !binding.detailsCollect.isSelected
Toast.makeText(
this@DetailActivity, "You have unfavorite this sound.", Toast.LENGTH_SHORT
).show()
CoroutineScope(Dispatchers.IO).launch {
AppDatabase.dataBase.getWallpaperDao().deleteData(wallpaperData.apply {
isCollect = binding.detailsCollect.isSelected
})
}
}
}
private fun showDownloadDialog() {
Log.e("file_play", "file is null!")
}
private fun playVideo() {
Log.e("file_play", "file is exist!")
}
private fun isExist(): Boolean {

View File

@ -1,4 +1,59 @@
package com.timber.soft.mylivewallpaper.ui.adapter
class RateStartAdapter {
import android.annotation.SuppressLint
import android.content.Context
import android.service.autofill.OnClickAction
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.timber.soft.mylivewallpaper.databinding.FragmentRateBinding
import com.timber.soft.mylivewallpaper.databinding.ItemRateStartBinding
class RateStartAdapter(
private val context: Context,
private var clickAction: (Int) -> Unit
) : RecyclerView.Adapter<RateStartAdapter.RateViewHolder>() {
private var clickPos: Int? = null
fun getRate(): Int? = clickPos
@SuppressLint("NotifyDataSetChanged")
inner class RateViewHolder(private val binding: ItemRateStartBinding) :
RecyclerView.ViewHolder(binding.root) {
init {
// binding.root.setOnClickListener {
// val position = bindingAdapterPosition
// if (position != RecyclerView.NO_POSITION) {
// clickAction.invoke(position)
// }
// }
}
fun bind(position: Int) {
clickPos?.let {
binding.itemStart.isSelected = position <= it
}
binding.consStart.setOnClickListener {
clickAction.invoke(position)
clickPos = position
notifyDataSetChanged()
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RateViewHolder =
RateViewHolder(
ItemRateStartBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
override fun getItemCount(): Int = 5
override fun onBindViewHolder(holder: RateViewHolder, position: Int) {
holder.bind(position)
}
}

View File

@ -21,6 +21,7 @@ abstract class BaseFragment : Fragment() {
}
open fun initViews() {
}
abstract fun getFragmentContentView(): View

View File

@ -1,7 +1,9 @@
package com.timber.soft.mylivewallpaper.ui.fragment
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
@ -10,6 +12,7 @@ import android.view.ViewGroup
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.timber.soft.mylivewallpaper.R
import com.timber.soft.mylivewallpaper.databinding.FragmentRateBinding
import com.timber.soft.mylivewallpaper.ui.adapter.RateStartAdapter
@ -31,9 +34,7 @@ class RateFragment : DialogFragment() {
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
binding = FragmentRateBinding.inflate(layoutInflater)
return binding.root
@ -60,8 +61,40 @@ class RateFragment : DialogFragment() {
private fun initDialog() {
binding.run {
rateStartAdapter = RateStartAdapter(requireContext()) {
tvRateIt.run {
isSelected = true
isClickable = true
}
}
recyclerStart.apply {
adapter = rateStartAdapter
layoutManager = LinearLayoutManager(requireContext()).apply {
orientation = LinearLayoutManager.HORIZONTAL
}
}
tvRateIt.run {
isSelected = false
isClickable = false
}
rateCancel.setOnClickListener() { dismiss() }
tvRateIt.setOnClickListener {
rateStartAdapter.getRate()?.let {
if (it >= 3) {
goRate()
dismiss()
} else {
dismiss()
}
}
}
}
}
private fun goRate() {
val intent = Intent("android.intent.action.VIEW")
val stringBuilder = getString(R.string.set_shop_link) + (requireContext().packageName)
intent.data = Uri.parse(stringBuilder)
startActivity(intent)
}
}

View File

@ -20,7 +20,7 @@ class SettingFragment : BaseFragment() {
override fun initViews() {
super.initViews()
binding.setLayoutRating.setOnClickListener {
//TODO:no implement
RateFragment.newInstance(0, 0).show(childFragmentManager, "")
}
binding.setLayoutShare.setOnClickListener {
val url = getString(R.string.set_shop_link) + (activity?.packageName ?: "")

View File

@ -1,6 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/theme_color_light"
android:orientation="vertical"
tools:context=".ui.fragment.CollectFragment">
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:gravity="center_horizontal"
android:paddingBottom="8dp"
android:text="@string/collect_title"
android:textColor="@color/black"
android:textSize="18sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_collect"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="4dp" />
</LinearLayout>

View File

@ -10,7 +10,7 @@
tools:context=".ui.fragment.RateFragment">
<TextView
android:id="@+id/tvTitle"
android:id="@+id/rate_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
@ -24,7 +24,7 @@
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_content"
android:id="@+id/rate_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
@ -36,7 +36,7 @@
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
app:layout_constraintTop_toBottomOf="@id/rate_title" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_start"
@ -45,10 +45,10 @@
android:layout_marginTop="24dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_content" />
app:layout_constraintTop_toBottomOf="@id/rate_content" />
<TextView
android:id="@+id/tv_cancel"
android:id="@+id/rate_cancel"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="24dp"
@ -72,8 +72,8 @@
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintLeft_toRightOf="@id/tv_cancel"
app:layout_constraintLeft_toRightOf="@id/rate_cancel"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_cancel" />
app:layout_constraintTop_toTopOf="@id/rate_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,17 @@
<?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"
android:id="@+id/cons_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView
android:id="@+id/item_start"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/selector_details_collect"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -13,6 +13,8 @@
<string name="set_cancel">CANCEL</string>
<string name="set_rate_it">RATE IT</string>
<string name="collect_title">My Collection</string>
<string name="details_set_wallpaper">Set Wallpaper</string>
<string name="video_loading">Loading video...</string>