feat:优化了代码结构,修复了部分错误,提高了代码质量。
This commit is contained in:
parent
be40211f41
commit
d38e59e3dc
13
.idea/deploymentTargetDropDown.xml
generated
13
.idea/deploymentTargetDropDown.xml
generated
@ -15,18 +15,7 @@
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="D:\Android\.android\avd\Pixel_7_API_34.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-04-25T02:40:10.447031700Z" />
|
||||
<timeTargetWasSelectedWithDropDown value="2024-04-26T06:00:58.141729100Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
|
||||
@ -5,11 +5,21 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
signingConfigs {
|
||||
debug {
|
||||
storeFile file('D:\\Android_Files\\MyLiveWallpaper\\app\\info\\livewallpaper_key_test.jks')
|
||||
storePassword 'key123456'
|
||||
keyPassword 'key123456'
|
||||
keyAlias 'key_wallpaper_test'
|
||||
}
|
||||
}
|
||||
|
||||
namespace 'com.timber.soft.mylivewallpaper'
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.timber.soft.mylivewallpaper"
|
||||
applicationId "com.timber.soft.livebackgroundswallpaper.test"
|
||||
minSdk 22
|
||||
targetSdk 34
|
||||
versionCode 1
|
||||
@ -20,7 +30,12 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
debug {
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
BIN
app/info/livewallpaper_key_test.jks
Normal file
BIN
app/info/livewallpaper_key_test.jks
Normal file
Binary file not shown.
22
app/proguard-rules.pro
vendored
22
app/proguard-rules.pro
vendored
@ -19,3 +19,25 @@
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keepattributes Signature
|
||||
-keepattributes *Annotation*
|
||||
-keep class com.google.gson.stream.** { *; }
|
||||
-keep class com.google.gson.examples.android.model.** { *; }
|
||||
-keep class * implements com.google.gson.TypeAdapter { *; }
|
||||
-keep class com.google.gson.internal.LinkedTreeMap { *; }
|
||||
-keep class com.timber.soft.mylivewallpaper.tools.AppTools
|
||||
-keep class com.timber.soft.mylivewallpaper.data.** { *; }
|
||||
|
||||
|
||||
-keepclassmembers class *{
|
||||
@androidx.room.Query <methods>;
|
||||
}
|
||||
|
||||
-keep class com.timber.soft.mylivewallpaper.tools.AppFinalString {
|
||||
public static final java.lang.String DB_NAME;
|
||||
public static final int DB_VERSION;
|
||||
}
|
||||
|
||||
-keepattributes Signature
|
||||
-keepattributes *Annotation*
|
||||
@ -10,10 +10,10 @@
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:icon="@mipmap/icon"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:roundIcon="@mipmap/icon"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MyLiveWallpaper"
|
||||
tools:targetApi="31">
|
||||
@ -28,6 +28,20 @@
|
||||
</activity>
|
||||
<activity android:name=".ui.activity.MainActivity" />
|
||||
<activity android:name=".ui.activity.DetailActivity" />
|
||||
|
||||
<service
|
||||
android:name=".service.VideoWallpaperService"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_WALLPAPER">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.wallpaper.WallpaperService" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.service.wallpaper"
|
||||
android:resource="@xml/wallpaper" />
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -13,6 +13,9 @@ interface WallpaperDao {
|
||||
@Query("delete from t_wallpaper")
|
||||
suspend fun deleteAllData()
|
||||
|
||||
@Query("update t_wallpaper set isCollect = 0")
|
||||
suspend fun deleteAllCollect()
|
||||
|
||||
@Query("select * from t_wallpaper where isCollect = :collect ")
|
||||
suspend fun getCollectData(collect: Boolean = true): List<WallpaperData>
|
||||
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
package com.timber.soft.mylivewallpaper.service
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.media.MediaPlayer
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.service.wallpaper.WallpaperService
|
||||
import android.util.Log
|
||||
import android.view.SurfaceHolder
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.timber.soft.mylivewallpaper.tools.AppFinalString
|
||||
import com.timber.soft.mylivewallpaper.tools.MyApplication
|
||||
|
||||
class VideoWallpaperService : WallpaperService() {
|
||||
|
||||
// companion object {
|
||||
// const val ACTION_SET_WALLPAPER = "VideoWallpaperService"
|
||||
// }
|
||||
|
||||
// private lateinit var mBroadcastManager: LocalBroadcastManager
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
// mBroadcastManager = LocalBroadcastManager.getInstance(this)
|
||||
}
|
||||
|
||||
override fun onCreateEngine(): Engine {
|
||||
return VideoEngine()
|
||||
}
|
||||
|
||||
inner class VideoEngine : Engine() {
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
|
||||
|
||||
// private var mReceiver = object : BroadcastReceiver() {
|
||||
// override fun onReceive(context: Context?, intent: Intent?) {
|
||||
// updateVideo()
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onCreate(surfaceHolder: SurfaceHolder?) {
|
||||
super.onCreate(surfaceHolder)
|
||||
// val filter = IntentFilter(ACTION_SET_WALLPAPER)
|
||||
// mBroadcastManager.registerReceiver(mReceiver, filter)
|
||||
}
|
||||
|
||||
|
||||
override fun onSurfaceCreated(holder: SurfaceHolder?) {
|
||||
super.onSurfaceCreated(holder)
|
||||
val uri = getVideoUri()
|
||||
mediaPlayer = MediaPlayer.create(MyApplication.appContext, uri)
|
||||
mediaPlayer?.setSurface(holder!!.surface)
|
||||
mediaPlayer?.isLooping = true
|
||||
mediaPlayer?.setVolume(0f, 0f)
|
||||
mediaPlayer?.start()
|
||||
|
||||
}
|
||||
|
||||
override fun onVisibilityChanged(visible: Boolean) {
|
||||
super.onVisibilityChanged(visible)
|
||||
if (visible) {
|
||||
mediaPlayer?.start()
|
||||
} else {
|
||||
mediaPlayer?.pause()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
mediaPlayer?.let {
|
||||
if (it.isPlaying) {
|
||||
it.stop()
|
||||
}
|
||||
}
|
||||
mediaPlayer?.release()
|
||||
mediaPlayer = null
|
||||
// mBroadcastManager.unregisterReceiver(mReceiver)
|
||||
}
|
||||
|
||||
// private fun updateVideo() {
|
||||
// val uri = getVideoUri()
|
||||
// mediaPlayer?.reset()
|
||||
// mediaPlayer?.setDataSource(this@VideoWallpaperService, uri)
|
||||
// mediaPlayer?.isLooping = true
|
||||
// mediaPlayer?.setVolume(0f, 0f)
|
||||
// mediaPlayer?.prepare()
|
||||
// }
|
||||
}
|
||||
|
||||
private fun getVideoUri(): Uri {
|
||||
val prefs = MyApplication.appContext.getSharedPreferences(
|
||||
AppFinalString.PREFS_NAME, Context.MODE_PRIVATE
|
||||
)
|
||||
val string = prefs.getString(AppFinalString.KEY_SP, null)
|
||||
return Uri.parse(string)
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
package com.timber.soft.mylivewallpaper.tools
|
||||
|
||||
object AppFinalString {
|
||||
|
||||
const val DB_NAME = "wallpaper_db"
|
||||
const val DB_VERSION = 1
|
||||
const val TABLE_NAME_WALLPAPER = "t_wallpaper"
|
||||
const val KEY_EXTRA = "KEY_EXTRA"
|
||||
const val ACTION_DATABASE_UPDATED = "ACTION_DATABASE_UPDATED"
|
||||
|
||||
const val KEY_SP = "KEY_SP"
|
||||
const val PREFS_NAME = "MyPrefs"
|
||||
}
|
||||
@ -1,10 +1,13 @@
|
||||
package com.timber.soft.mylivewallpaper.ui.activity
|
||||
|
||||
import android.app.WallpaperManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.MediaPlayer
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
@ -16,22 +19,21 @@ 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.R
|
||||
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.service.VideoWallpaperService
|
||||
import com.timber.soft.mylivewallpaper.tools.AppFinalString
|
||||
import com.timber.soft.mylivewallpaper.tools.AppTools.glideDownload
|
||||
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 {
|
||||
|
||||
private lateinit var binding: ActivityDetailsBinding
|
||||
private lateinit var wallpaperData: WallpaperData
|
||||
private lateinit var downDialog: DownLoadDialog
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
private lateinit var videoUrl: String
|
||||
private var isDownload = false
|
||||
@ -103,7 +105,14 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
|
||||
}
|
||||
|
||||
binding.detailsSet -> {
|
||||
Log.e("onclick", "detailsSet has been click!")
|
||||
if (isDownload) {
|
||||
binding.detailsPlayButton.isVisible = false
|
||||
setWallpaper(videoUrl)
|
||||
} else {
|
||||
binding.detailsPlayButton.isVisible = false
|
||||
binding.detailsProgressbar.isVisible = true
|
||||
downloadPaper()
|
||||
}
|
||||
}
|
||||
|
||||
binding.detailsCollect -> {
|
||||
@ -127,6 +136,56 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun downloadPaper() {
|
||||
wallpaperData.preview.let {
|
||||
glideDownload(this, it) { file ->
|
||||
if (file == null) {
|
||||
isDownload = false
|
||||
Toast.makeText(
|
||||
this@DetailActivity, "Sorry, the download failed.", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
binding.detailsProgressbar.isVisible = false
|
||||
} else {
|
||||
binding.detailsProgressbar.isVisible = false
|
||||
file.absolutePath.let { path ->
|
||||
videoUrl = path
|
||||
isDownload = true
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
AppDatabase.dataBase.getWallpaperDao().insertData(wallpaperData.apply {
|
||||
downloadUrl = path
|
||||
})
|
||||
}
|
||||
setWallpaper(videoUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setWallpaper(videoUrl: String) {
|
||||
// binding.detailsCoverView.isVisible = true
|
||||
|
||||
|
||||
val instance = WallpaperManager.getInstance(this)
|
||||
try {
|
||||
instance.clear()
|
||||
}catch (e:Exception){
|
||||
|
||||
}
|
||||
val prefs =
|
||||
applicationContext.getSharedPreferences(AppFinalString.PREFS_NAME, Context.MODE_PRIVATE)
|
||||
val editor = prefs.edit()
|
||||
editor.putString(AppFinalString.KEY_SP, videoUrl)
|
||||
editor.apply()
|
||||
|
||||
val intent = Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
|
||||
intent.putExtra(
|
||||
WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
|
||||
ComponentName(this, VideoWallpaperService::class.java)
|
||||
)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun stopVideo() {
|
||||
try {
|
||||
mediaPlayer?.stop()
|
||||
@ -155,7 +214,7 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
|
||||
this@DetailActivity, "You have unfavorite this sound.", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
AppDatabase.dataBase.getWallpaperDao().deleteData(wallpaperData.apply {
|
||||
AppDatabase.dataBase.getWallpaperDao().updateData(wallpaperData.apply {
|
||||
isCollect = binding.detailsCollect.isSelected
|
||||
})
|
||||
}
|
||||
@ -171,11 +230,10 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
|
||||
this@DetailActivity, "Sorry, the download failed.", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
binding.detailsProgressbar.isVisible = false
|
||||
binding.detailsPlayButton.isVisible = true
|
||||
} else {
|
||||
binding.detailsProgressbar.isVisible = false
|
||||
file.absolutePath.let { path ->
|
||||
// mediaPlayer.setDataSource(path)
|
||||
// mediaPlayer.prepare()
|
||||
videoUrl = path
|
||||
isDownload = true
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
@ -216,10 +274,7 @@ class DetailActivity : BaseActivity(), View.OnClickListener {
|
||||
}
|
||||
|
||||
override fun surfaceChanged(
|
||||
holder: SurfaceHolder,
|
||||
format: Int,
|
||||
width: Int,
|
||||
height: Int
|
||||
holder: SurfaceHolder, format: Int, width: Int, height: Int
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ class SettingFragment : BaseFragment() {
|
||||
binding.setLayoutDelete.setOnClickListener() {
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
AppDatabase.dataBase.getWallpaperDao().deleteAllData()
|
||||
AppDatabase.dataBase.getWallpaperDao().deleteAllCollect()
|
||||
}
|
||||
sendDatabaseUpdatedBroadcast()
|
||||
Toast.makeText(
|
||||
|
||||
@ -97,13 +97,30 @@
|
||||
android:id="@+id/details_video_back"
|
||||
android:layout_width="54dp"
|
||||
android:layout_height="54dp"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginTop="46dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:background="@drawable/shape_circular"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/svg_back" />
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/details_cover_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/cover_color"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/details_setting_wallpaper"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</FrameLayout>
|
||||
@ -22,7 +22,7 @@
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
android:src="@mipmap/icon" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<TextView
|
||||
@ -31,6 +31,7 @@
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:gravity="center"
|
||||
android:lineSpacingExtra="20dp"
|
||||
android:lineSpacingMultiplier="0.6"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@color/theme_color_dark"
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
android:src="@mipmap/icon" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<!--AppName-->
|
||||
|
||||
BIN
app/src/main/res/mipmap-xxxhdpi/icon.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
@ -5,4 +5,5 @@
|
||||
<color name="theme_color_dark">#3095DE</color>
|
||||
<color name="theme_color_light">#80BFEFFF</color>
|
||||
<color name="theme_color_mid">#B4DEFE</color>
|
||||
<color name="cover_color">#BF000000</color>
|
||||
</resources>
|
||||
@ -1,5 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">MyLiveWallpaper</string>
|
||||
<string name="app_name">Live Backgrounds Wallpaper</string>
|
||||
|
||||
<string name="main_home">Home</string>
|
||||
<string name="main_collect">Collect</string>
|
||||
@ -9,7 +9,7 @@
|
||||
<string name="set_score">Rate us</string>
|
||||
<string name="set_share">Share us</string>
|
||||
<string name="set_shop_link">https://play.google.com/store/apps/details?id=</string>
|
||||
<string name="set_rate_us_content">We hope this app is useful for you, if it does, would youplease give us a 5 sar and a mice revtew on Google Play, it really helps!</string>
|
||||
<string name="set_rate_us_content">Please share this app and give us 5 stars if this app was helpful to you, thank you!</string>
|
||||
<string name="set_cancel">CANCEL</string>
|
||||
<string name="set_rate_it">RATE IT</string>
|
||||
<string name="set_setting_delete">Clear All My Favorites</string>
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
|
||||
<string name="details_set_wallpaper">Set Wallpaper</string>
|
||||
<string name="details_setting_wallpaper">Setting wallpaper ...</string>
|
||||
<string name="video_loading">Loading video...</string>
|
||||
|
||||
|
||||
|
||||
6
app/src/main/res/xml/wallpaper.xml
Normal file
6
app/src/main/res/xml/wallpaper.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/app_name"
|
||||
android:thumbnail="@mipmap/ic_launcher">
|
||||
|
||||
</wallpaper>
|
||||
Loading…
Reference in New Issue
Block a user