feat:添加了详细的UI布局和功能实现,包括错误处理和图片加载优化。
This commit is contained in:
parent
d60b36f51e
commit
b5deee2b9f
17
.idea/deploymentTargetDropDown.xml
generated
17
.idea/deploymentTargetDropDown.xml
generated
@ -9,13 +9,24 @@
|
|||||||
<type value="RUNNING_DEVICE_TARGET" />
|
<type value="RUNNING_DEVICE_TARGET" />
|
||||||
<deviceKey>
|
<deviceKey>
|
||||||
<Key>
|
<Key>
|
||||||
<type value="SERIAL_NUMBER" />
|
<type value="VIRTUAL_DEVICE_PATH" />
|
||||||
<value value="ZX1G22HXL8" />
|
<value value="D:\Android\.android\avd\Pixel_8_API_34.avd" />
|
||||||
</Key>
|
</Key>
|
||||||
</deviceKey>
|
</deviceKey>
|
||||||
</Target>
|
</Target>
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
</runningDeviceTargetSelectedWithDropDown>
|
||||||
<timeTargetWasSelectedWithDropDown value="2024-04-22T03:53:07.331156800Z" />
|
<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" />
|
||||||
|
</Key>
|
||||||
|
</deviceKey>
|
||||||
|
</Target>
|
||||||
|
</targetSelectedWithDropDown>
|
||||||
|
<timeTargetWasSelectedWithDropDown value="2024-04-23T05:33:53.151174800Z" />
|
||||||
</State>
|
</State>
|
||||||
</entry>
|
</entry>
|
||||||
</value>
|
</value>
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.activity.MainActivity" />
|
<activity android:name=".ui.activity.MainActivity" />
|
||||||
|
<activity android:name=".ui.activity.DetailActivity" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@ -2,4 +2,5 @@ package com.timber.soft.mylivewallpaper.tools
|
|||||||
|
|
||||||
object AppFinalString {
|
object AppFinalString {
|
||||||
const val TABLE_NAME_WALLPAPER = "wallpaper"
|
const val TABLE_NAME_WALLPAPER = "wallpaper"
|
||||||
|
const val KEY_EXTRA = "KEY_EXTRA"
|
||||||
}
|
}
|
||||||
@ -1,11 +1,24 @@
|
|||||||
package com.timber.soft.mylivewallpaper.ui.activity
|
package com.timber.soft.mylivewallpaper.ui.activity
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.Toast
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.load.DataSource
|
||||||
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
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.WallpaperData
|
||||||
import com.timber.soft.mylivewallpaper.databinding.ActivityDetailsBinding
|
import com.timber.soft.mylivewallpaper.databinding.ActivityDetailsBinding
|
||||||
|
import com.timber.soft.mylivewallpaper.tools.AppFinalString
|
||||||
|
|
||||||
class DetailActivity : BaseActivity() {
|
class DetailActivity : BaseActivity(), View.OnClickListener {
|
||||||
|
|
||||||
private lateinit var binding: ActivityDetailsBinding
|
private lateinit var binding: ActivityDetailsBinding
|
||||||
|
private lateinit var wallpaperData: WallpaperData
|
||||||
override fun getActivityContentView(): View {
|
override fun getActivityContentView(): View {
|
||||||
binding = ActivityDetailsBinding.inflate(layoutInflater)
|
binding = ActivityDetailsBinding.inflate(layoutInflater)
|
||||||
return binding.root
|
return binding.root
|
||||||
@ -13,6 +26,72 @@ class DetailActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun initViews() {
|
override fun initViews() {
|
||||||
super.initViews()
|
super.initViews()
|
||||||
|
wallpaperData = intent.getSerializableExtra(AppFinalString.KEY_EXTRA) as WallpaperData
|
||||||
|
initButton()
|
||||||
|
initPreImg()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initPreImg() {
|
||||||
|
Glide.with(this).load(wallpaperData.thumbnail)
|
||||||
|
.transition(DrawableTransitionOptions.withCrossFade())
|
||||||
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||||
|
.listener(object : RequestListener<Drawable> {
|
||||||
|
override fun onLoadFailed(
|
||||||
|
e: GlideException?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable>?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
// 加载失败时的处理
|
||||||
|
binding.detailsProgressbar.visibility = View.INVISIBLE
|
||||||
|
binding.detailsLoadingErr.visibility = View.VISIBLE
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext, "Check network connection!", Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(
|
||||||
|
resource: Drawable?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable>?,
|
||||||
|
dataSource: DataSource?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
// 图片加载完成时的处理
|
||||||
|
binding.detailsProgressbar.visibility = View.INVISIBLE
|
||||||
|
binding.detailsPlayButton.visibility = View.VISIBLE
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}).into(binding.detailsImage)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initButton() {
|
||||||
|
binding.detailsBack.setOnClickListener(this)
|
||||||
|
binding.detailsCollect.setOnClickListener(this)
|
||||||
|
binding.detailsSet.setOnClickListener(this)
|
||||||
|
binding.detailsPlayButton.setOnClickListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View?) {
|
||||||
|
when (v) {
|
||||||
|
binding.detailsBack -> {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.detailsSet -> {
|
||||||
|
Log.e("onclick", "detailsSet has been click!")
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.detailsCollect -> {
|
||||||
|
Log.e("onclick", "detailsCollect has been click!")
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.detailsPlayButton -> {
|
||||||
|
Log.e("onclick", "detailsPlayButton has been click!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.timber.soft.mylivewallpaper.ui.fragment
|
package com.timber.soft.mylivewallpaper.ui.fragment
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
@ -12,7 +13,9 @@ import com.timber.soft.mylivewallpaper.ui.adapter.HomeItemAdapter
|
|||||||
import com.timber.soft.mylivewallpaper.ui.listener.OnHomeItemClickListener
|
import com.timber.soft.mylivewallpaper.ui.listener.OnHomeItemClickListener
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
|
import com.timber.soft.mylivewallpaper.tools.AppFinalString
|
||||||
import com.timber.soft.mylivewallpaper.tools.AppTools.onMain
|
import com.timber.soft.mylivewallpaper.tools.AppTools.onMain
|
||||||
|
import com.timber.soft.mylivewallpaper.ui.activity.DetailActivity
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class HomeFragment : BaseFragment() {
|
class HomeFragment : BaseFragment() {
|
||||||
@ -66,8 +69,9 @@ class HomeFragment : BaseFragment() {
|
|||||||
homeItemAdapter =
|
homeItemAdapter =
|
||||||
HomeItemAdapter(requireContext(), wallpaperDataList, object : OnHomeItemClickListener {
|
HomeItemAdapter(requireContext(), wallpaperDataList, object : OnHomeItemClickListener {
|
||||||
override fun onItemClick(position: Int, wallpaperData: WallpaperData) {
|
override fun onItemClick(position: Int, wallpaperData: WallpaperData) {
|
||||||
// val intent = Intent(requireContext())
|
val intent = Intent(requireContext(), DetailActivity::class.java)
|
||||||
Log.d("home_item_root", "item has been click!")
|
intent.putExtra(AppFinalString.KEY_EXTRA, wallpaperData)
|
||||||
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
binding.homeRecyclerview.run {
|
binding.homeRecyclerview.run {
|
||||||
|
|||||||
7
app/src/main/res/drawable/selector_details_collect.xml
Normal file
7
app/src/main/res/drawable/selector_details_collect.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item android:drawable="@drawable/svg_collect_enable" android:state_selected="true" />
|
||||||
|
<item android:drawable="@drawable/svg_collect" android:state_selected="false" />
|
||||||
|
|
||||||
|
</selector>
|
||||||
6
app/src/main/res/drawable/shape_circular.xml
Normal file
6
app/src/main/res/drawable/shape_circular.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<solid android:color="@color/white" />
|
||||||
|
|
||||||
|
</shape>
|
||||||
9
app/src/main/res/drawable/svg_back.xml
Normal file
9
app/src/main/res/drawable/svg_back.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="200dp"
|
||||||
|
android:height="200dp"
|
||||||
|
android:viewportWidth="1024"
|
||||||
|
android:viewportHeight="1024">
|
||||||
|
<path
|
||||||
|
android:pathData="M672,889.6v6.4h-512v-64h448a256,256 0,0 0,0 -512h-256v102.4a26.5,26.5 0,0 1,-27.6 25.2,29.1 29.1,0 0,1 -16.1,-4.8l-201,-133.8a23.9,23.9 0,0 1,-6.4 -35.2,26.8 26.8,0 0,1 6.4,-5.6l201,-133.8a29.1,29.1 0,0 1,38.4 5.6,23.7 23.7,0 0,1 5.3,14.8V256h256a320,320 0,0 1,64 633.6z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
</vector>
|
||||||
21
app/src/main/res/drawable/svg_collect.xml
Normal file
21
app/src/main/res/drawable/svg_collect.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="208.6dp"
|
||||||
|
android:height="200dp"
|
||||||
|
android:viewportWidth="1068"
|
||||||
|
android:viewportHeight="1024">
|
||||||
|
<path
|
||||||
|
android:pathData="M810.6,679A33.6,33.6 0,0 1,786.7 621.9l205,-208.4 -291.6,-55.6a33.6,33.6 0,1 1,12.6 -65.9l301.7,57.6c26.1,5 44.8,19.9 51.3,40.9s-0.3,43.9 -19,62.8l-212.2,215.8a33.6,33.6 0,0 1,-23.9 10zM1005.8,416.6z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M824,1024c-10.8,0 -22.3,-2.8 -33.7,-8.5L519.5,880.3a33.6,33.6 0,0 1,30 -60.1l261.5,130.6 -37.1,-294.5a33.6,33.6 0,0 1,66.6 -8.4l38.5,304.7c3.3,26.3 -5.1,48.7 -23.1,61.5a54.5,54.5 0,0 1,-31.9 9.9z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M232.5,1020.6a54.7,54.7 0,0 1,-33.1 -10.7c-17.7,-13.1 -25.5,-35.7 -21.6,-62l44.8,-299.3a33.6,33.6 0,0 1,66.4 10l-43.3,289.1 268.5,-126.3a33.6,33.6 0,1 1,28.6 60.7L264.9,1012.8a76.4,76.4 0,0 1,-32.4 7.8z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M255,680.6a33.5,33.5 0,0 1,-24.5 -10.6L20.3,446.1C2.1,426.8 -4.2,403.8 2.8,382.9s26.1,-35.3 52.3,-39.7l298.5,-49.8a33.6,33.6 0,0 1,11 66.2L76.3,407.7l203.1,216.3a33.6,33.6 0,0 1,-24.5 56.5z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M704,355a33.6,33.6 0,0 1,-29.8 -18.1L539.3,77.6l-143,260.1a33.6,33.6 0,1 1,-58.8 -32.3L485.4,36.2C498.2,12.9 518.2,-0.3 540.2,0s41.7,13.9 53.9,37.4l139.6,268.5a33.6,33.6 0,0 1,-29.8 49.1zM546.6,65.1z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
</vector>
|
||||||
9
app/src/main/res/drawable/svg_collect_enable.xml
Normal file
9
app/src/main/res/drawable/svg_collect_enable.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="200.2dp"
|
||||||
|
android:height="200dp"
|
||||||
|
android:viewportWidth="1025"
|
||||||
|
android:viewportHeight="1024">
|
||||||
|
<path
|
||||||
|
android:pathData="M1024,393.5a36.6,36.6 0,0 0,-29.3 -24.9l-311.6,-44.6L544.2,42.4a37.3,37.3 0,0 0,-64.4 0l-139,281.6L30.8,365.7a36.6,36.6 0,0 0,-29.3 24.9,36.6 36.6,0 0,0 9.5,36.6l224.5,219.4 -53.4,311.6a36.6,36.6 0,0 0,14.6 35.1,35.1 35.1,0 0,0 21.2,6.6 33.6,33.6 0,0 0,16.1 -4.4l277.9,-146.3 277.9,146.3a34.4,34.4 0,0 0,37.3 0,36.6 36.6,0 0,0 14.6,-35.1l-53.4,-309.4 224.5,-219.4a36.6,36.6 0,0 0,11 -38z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
</vector>
|
||||||
9
app/src/main/res/drawable/svg_play.xml
Normal file
9
app/src/main/res/drawable/svg_play.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="200dp"
|
||||||
|
android:height="200dp"
|
||||||
|
android:viewportWidth="1024"
|
||||||
|
android:viewportHeight="1024">
|
||||||
|
<path
|
||||||
|
android:pathData="M906.6,421.4L214.4,44.5A102.1,102.1 0,0 0,64 135v753.9a102.1,102.1 0,0 0,150.4 90.6l692.2,-377a103.4,103.4 0,0 0,0 -181.1z"
|
||||||
|
android:fillColor="#3095DE"/>
|
||||||
|
</vector>
|
||||||
@ -1,6 +1,108 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout 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_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.activity.DetailActivity">
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<ImageView
|
||||||
|
android:id="@+id/details_image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="fitXY" />
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:id="@+id/details_set"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:layout_marginStart="80dp"
|
||||||
|
android:layout_marginEnd="80dp"
|
||||||
|
android:layout_marginBottom="44dp"
|
||||||
|
android:backgroundTint="@color/white"
|
||||||
|
app:cardCornerRadius="28dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/details_set_wallpaper"
|
||||||
|
android:textColor="@color/theme_color_dark"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/details_back"
|
||||||
|
android:layout_width="54dp"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="46dp"
|
||||||
|
android:background="@drawable/shape_circular"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:src="@drawable/svg_back" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/details_collect"
|
||||||
|
android:layout_width="54dp"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginTop="46dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:background="@drawable/shape_circular"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:src="@drawable/selector_details_collect" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/details_progressbar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:indeterminateTint="@color/theme_color_dark" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/details_loading_err"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/svg_loading_err"
|
||||||
|
android:visibility="invisible" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/details_play_button"
|
||||||
|
android:layout_width="54dp"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/shape_circular"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:src="@drawable/svg_play"
|
||||||
|
android:visibility="visible" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/details_flPlay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="true"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<SurfaceView
|
||||||
|
android:id="@+id/details_surfaceVideo"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="visible" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/details_ivClose"
|
||||||
|
android:layout_width="54dp"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginTop="46dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:src="@drawable/svg_back"
|
||||||
|
android:visibility="visible" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@ -4,4 +4,6 @@
|
|||||||
<string name="main_home">Home</string>
|
<string name="main_home">Home</string>
|
||||||
<string name="main_collect">Collect</string>
|
<string name="main_collect">Collect</string>
|
||||||
<string name="main_setting">Set</string>
|
<string name="main_setting">Set</string>
|
||||||
|
|
||||||
|
<string name="details_set_wallpaper">Set Wallpaper</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue
Block a user