修改为正式广告,修复崩溃
This commit is contained in:
parent
261f5fa16c
commit
ba0ac9fcaf
@ -19,8 +19,8 @@ android {
|
|||||||
applicationId = "com.wallart.art.wallpapers.hd"
|
applicationId = "com.wallart.art.wallpapers.hd"
|
||||||
minSdk = 23
|
minSdk = 23
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 3
|
versionCode = 4
|
||||||
versionName = "1.0.2"
|
versionName = "1.0.3"
|
||||||
setProperty("archivesBaseName", "Art Wallpaper_V" + versionName + "(${versionCode})_$timestamp")
|
setProperty("archivesBaseName", "Art Wallpaper_V" + versionName + "(${versionCode})_$timestamp")
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class CategoryPagerAdapter(private val ctx: Context, private val list: MutableLi
|
|||||||
|
|
||||||
|
|
||||||
val url = if (DownloadUtil.isExist(bean.sourceURl, bean.getTag())) {
|
val url = if (DownloadUtil.isExist(bean.sourceURl, bean.getTag())) {
|
||||||
DownloadUtil.getFilePath(bean.sourceURl, bean.getTag())
|
DownloadUtil.getFilePath(bean.getTag())
|
||||||
} else {
|
} else {
|
||||||
bean.previewURl
|
bean.previewURl
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class ImagePagerAdapter(private val ctx: Context, private val list: MutableList<
|
|||||||
|
|
||||||
|
|
||||||
val url = if (DownloadUtil.isExist(bean.sourceURl, bean.getTag())) {
|
val url = if (DownloadUtil.isExist(bean.sourceURl, bean.getTag())) {
|
||||||
DownloadUtil.getFilePath(bean.sourceURl, bean.getTag())
|
DownloadUtil.getFilePath(bean.getTag())
|
||||||
} else {
|
} else {
|
||||||
bean.previewURl
|
bean.previewURl
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,8 @@ class Data(var previewURl: String, var sourceURl: String) : Serializable {
|
|||||||
|
|
||||||
val lastIndex2 = sourceURl.lastIndexOf(".")
|
val lastIndex2 = sourceURl.lastIndexOf(".")
|
||||||
|
|
||||||
val substring = sourceURl.substring(lastIndex1, lastIndex2)
|
val substring = sourceURl.substring(lastIndex1+1, lastIndex2)
|
||||||
Log.d("-----------","----------$substring")
|
Log.d("-----------","------TAG----$substring")
|
||||||
|
|
||||||
return substring
|
return substring
|
||||||
|
|
||||||
|
|||||||
@ -149,7 +149,6 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
|||||||
val image = mList[mCurPos]
|
val image = mList[mCurPos]
|
||||||
val path =
|
val path =
|
||||||
DownloadUtil.getFilePath(
|
DownloadUtil.getFilePath(
|
||||||
image.sourceURl,
|
|
||||||
image.getTag()
|
image.getTag()
|
||||||
)
|
)
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
@ -161,12 +160,16 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
|||||||
mSetAsDialog = SetAsDialog(this) {
|
mSetAsDialog = SetAsDialog(this) {
|
||||||
onClickHomeScreen = {
|
onClickHomeScreen = {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
wallpaperManager.setStream(
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
file.inputStream(),
|
wallpaperManager.setStream(
|
||||||
null,
|
file.inputStream(),
|
||||||
true,
|
null,
|
||||||
WallpaperManager.FLAG_SYSTEM
|
true,
|
||||||
)
|
WallpaperManager.FLAG_SYSTEM
|
||||||
|
)
|
||||||
|
}else{
|
||||||
|
wallpaperManager.setStream(file.inputStream())
|
||||||
|
}
|
||||||
onMain {
|
onMain {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@CategoryPreviewAbility,
|
this@CategoryPreviewAbility,
|
||||||
@ -179,12 +182,16 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
|||||||
|
|
||||||
onClickLockScreen = {
|
onClickLockScreen = {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
wallpaperManager.setStream(
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
file.inputStream(),
|
wallpaperManager.setStream(
|
||||||
null,
|
file.inputStream(),
|
||||||
true,
|
null,
|
||||||
WallpaperManager.FLAG_LOCK
|
true,
|
||||||
)
|
WallpaperManager.FLAG_LOCK
|
||||||
|
)
|
||||||
|
}else{
|
||||||
|
wallpaperManager.setStream(file.inputStream())
|
||||||
|
}
|
||||||
onMain {
|
onMain {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@CategoryPreviewAbility,
|
this@CategoryPreviewAbility,
|
||||||
@ -235,7 +242,7 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
|||||||
}
|
}
|
||||||
binding.flDownload.show()
|
binding.flDownload.show()
|
||||||
FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
||||||
.setPath(DownloadUtil.getFilePath(mList[mCurPos].sourceURl, mList[mCurPos].getTag()))
|
.setPath(DownloadUtil.getFilePath( mList[mCurPos].getTag()))
|
||||||
.setCallbackProgressTimes(300)
|
.setCallbackProgressTimes(300)
|
||||||
.setMinIntervalUpdateSpeed(400)
|
.setMinIntervalUpdateSpeed(400)
|
||||||
.setListener(object : FileDownloadListener() {
|
.setListener(object : FileDownloadListener() {
|
||||||
@ -301,7 +308,6 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
|||||||
val image = mList[mCurPos]
|
val image = mList[mCurPos]
|
||||||
val path =
|
val path =
|
||||||
DownloadUtil.getFilePath(
|
DownloadUtil.getFilePath(
|
||||||
image.sourceURl,
|
|
||||||
image.getTag()
|
image.getTag()
|
||||||
)
|
)
|
||||||
val saved = MediaUtil.saveImageToSystemAlbum(path, this@CategoryPreviewAbility)
|
val saved = MediaUtil.saveImageToSystemAlbum(path, this@CategoryPreviewAbility)
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import android.widget.Toast
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
import com.cute.girl.hd.pink.img.wallpaper.R
|
import com.cute.girl.hd.pink.img.wallpaper.R
|
||||||
import com.cute.girl.hd.pink.img.wallpaper.adapter.ImagePagerAdapter
|
import com.cute.girl.hd.pink.img.wallpaper.adapter.ImagePagerAdapter
|
||||||
import com.cute.girl.hd.pink.img.wallpaper.databinding.AbilityPreviewBinding
|
import com.cute.girl.hd.pink.img.wallpaper.databinding.AbilityPreviewBinding
|
||||||
@ -179,7 +180,6 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
|||||||
val image = mList[mCurPos]
|
val image = mList[mCurPos]
|
||||||
val path =
|
val path =
|
||||||
DownloadUtil.getFilePath(
|
DownloadUtil.getFilePath(
|
||||||
image.sourceURl,
|
|
||||||
image.getTag()
|
image.getTag()
|
||||||
)
|
)
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
@ -282,29 +282,16 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
|||||||
if (isFinishing) {
|
if (isFinishing) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val filePath = DownloadUtil.getFilePath(mList[mCurPos].sourceURl, mList[mCurPos].getTag())
|
val filePath = DownloadUtil.getFilePath( mList[mCurPos].getTag())
|
||||||
Log.d(
|
Log.d(
|
||||||
"-----------",
|
"-----------",
|
||||||
"---------startDownload-${mList[mCurPos].sourceURl} filePath=${filePath}"
|
"---------startDownload-${mList[mCurPos].sourceURl} filePath=${filePath}"
|
||||||
)
|
)
|
||||||
binding.flDownload.show()
|
binding.flDownload.show()
|
||||||
FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
DownloadUtil.downloadFile(mList[mCurPos].sourceURl,filePath){
|
||||||
.setPath(filePath)
|
runOnUiThread {
|
||||||
.setCallbackProgressTimes(300)
|
binding.flDownload.hide()
|
||||||
.setMinIntervalUpdateSpeed(400)
|
if(it){
|
||||||
.setListener(object : FileDownloadListener() {
|
|
||||||
override fun pending(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun progress(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
|
||||||
if (!isFinishing) {
|
|
||||||
binding.pbb.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun completed(task: BaseDownloadTask?) {
|
|
||||||
Log.d("-----------", "---------completed")
|
|
||||||
if (!isFinishing) {
|
if (!isFinishing) {
|
||||||
binding.flDownload.hide()
|
binding.flDownload.hide()
|
||||||
mImagePagerAdapter?.notifyItemChanged(mCurPos)
|
mImagePagerAdapter?.notifyItemChanged(mCurPos)
|
||||||
@ -314,9 +301,7 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
|||||||
saveWallpaper()
|
saveWallpaper()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}else{
|
||||||
|
|
||||||
override fun paused(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
|
||||||
if (!isFinishing) {
|
if (!isFinishing) {
|
||||||
binding.flDownload.hide()
|
binding.flDownload.hide()
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@ -326,37 +311,77 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
|||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun error(task: BaseDownloadTask?, e: Throwable?) {
|
// FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
||||||
if (!isFinishing) {
|
// .setPath(filePath)
|
||||||
binding.flDownload.hide()
|
// .setCallbackProgressTimes(300)
|
||||||
Toast.makeText(
|
// .setMinIntervalUpdateSpeed(400)
|
||||||
this@PreviewAbility,
|
// .setListener(object : FileDownloadListener() {
|
||||||
R.string.download_failed,
|
// override fun pending(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
||||||
Toast.LENGTH_SHORT
|
//
|
||||||
).show()
|
// }
|
||||||
}
|
//
|
||||||
}
|
// override fun progress(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
||||||
|
// if (!isFinishing) {
|
||||||
override fun warn(task: BaseDownloadTask?) {
|
// binding.pbb.show()
|
||||||
if (!isFinishing) {
|
// }
|
||||||
binding.flDownload.hide()
|
// }
|
||||||
Toast.makeText(
|
//
|
||||||
this@PreviewAbility,
|
// override fun completed(task: BaseDownloadTask?) {
|
||||||
R.string.download_failed,
|
// Log.d("-----------", "---------completed")
|
||||||
Toast.LENGTH_SHORT
|
// if (!isFinishing) {
|
||||||
).show()
|
// binding.flDownload.hide()
|
||||||
}
|
// mImagePagerAdapter?.notifyItemChanged(mCurPos)
|
||||||
}
|
// if (mAction == 0) {
|
||||||
|
// set4KWallpaper()
|
||||||
}).start()
|
// } else {
|
||||||
|
// saveWallpaper()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun paused(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
||||||
|
// if (!isFinishing) {
|
||||||
|
// binding.flDownload.hide()
|
||||||
|
// Toast.makeText(
|
||||||
|
// this@PreviewAbility,
|
||||||
|
// R.string.download_failed,
|
||||||
|
// Toast.LENGTH_SHORT
|
||||||
|
// ).show()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun error(task: BaseDownloadTask?, e: Throwable?) {
|
||||||
|
// if (!isFinishing) {
|
||||||
|
// binding.flDownload.hide()
|
||||||
|
// Toast.makeText(
|
||||||
|
// this@PreviewAbility,
|
||||||
|
// R.string.download_failed,
|
||||||
|
// Toast.LENGTH_SHORT
|
||||||
|
// ).show()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun warn(task: BaseDownloadTask?) {
|
||||||
|
// if (!isFinishing) {
|
||||||
|
// binding.flDownload.hide()
|
||||||
|
// Toast.makeText(
|
||||||
|
// this@PreviewAbility,
|
||||||
|
// R.string.download_failed,
|
||||||
|
// Toast.LENGTH_SHORT
|
||||||
|
// ).show()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }).start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveWallpaper() {
|
private fun saveWallpaper() {
|
||||||
val image = mList[mCurPos]
|
val image = mList[mCurPos]
|
||||||
val path =
|
val path =
|
||||||
DownloadUtil.getFilePath(
|
DownloadUtil.getFilePath(
|
||||||
image.sourceURl,
|
|
||||||
image.getTag()
|
image.getTag()
|
||||||
)
|
)
|
||||||
val saved = MediaUtil.saveImageToSystemAlbum(path, this@PreviewAbility)
|
val saved = MediaUtil.saveImageToSystemAlbum(path, this@PreviewAbility)
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import java.util.Objects;
|
|||||||
public class UnityAdManager {
|
public class UnityAdManager {
|
||||||
public static String unityGameID = "5649501";
|
public static String unityGameID = "5649501";
|
||||||
|
|
||||||
public static Boolean testMode = true;
|
public static Boolean testMode = false;
|
||||||
|
|
||||||
public static String unitAd1 = "Art_Wallpaper_ad_unity_inst_open";
|
public static String unitAd1 = "Art_Wallpaper_ad_unity_inst_open";
|
||||||
public static String unitAd2 = "Art_Wallpaper_ad_unity_inst_set";
|
public static String unitAd2 = "Art_Wallpaper_ad_unity_inst_set";
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
package com.cute.girl.hd.pink.img.wallpaper.unityad;
|
|
||||||
|
|
||||||
public interface onLoadCallBack {
|
|
||||||
|
|
||||||
void onIsLoad(boolean loaded);
|
|
||||||
}
|
|
||||||
@ -3,7 +3,17 @@ package com.cute.girl.hd.pink.img.wallpaper.utils
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.annotation.MainThread
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Callback
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
object DownloadUtil {
|
object DownloadUtil {
|
||||||
|
|
||||||
@ -24,26 +34,83 @@ object DownloadUtil {
|
|||||||
/**
|
/**
|
||||||
* 获取文件下载路径
|
* 获取文件下载路径
|
||||||
* path:/storage/emulated/0/Android/data/com.lux.sound.pranks.hilarious.effects/X4D/download/hairclipper_4.jpg
|
* path:/storage/emulated/0/Android/data/com.lux.sound.pranks.hilarious.effects/X4D/download/hairclipper_4.jpg
|
||||||
|
*
|
||||||
|
* /storage/emulated/0/Android/data/com.wallart.art.wallpapers.hd/files/PrankSound/download//c189c2a257a0591c3ff5060c235c7342
|
||||||
*/
|
*/
|
||||||
fun getFilePath(url: String, tag: String?): String {
|
fun getFilePath(tag: String?): String {
|
||||||
|
|
||||||
val s = FileUtil.getDownloadDirectory() + File.separator + tag
|
val s = FileUtil.getDownloadDirectory() + File.separator + tag
|
||||||
Log.d("--------","----getFilePath--$s")
|
Log.d("-----------", "----getFilePath--$s")
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFile(url: String, tag: String?): File {
|
|
||||||
return File(getFilePath(url, tag))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFileUri(url: String, tag: String?): Uri {
|
|
||||||
return Uri.fromFile(File(getFilePath(url, tag)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param url 文件网络地址http://dadaad.png
|
* @param url 文件网络地址http://dadaad.png
|
||||||
*/
|
*/
|
||||||
fun isExist(url: String, tag: String?): Boolean {
|
fun isExist(url: String, tag: String?): Boolean {
|
||||||
return File(getFilePath(url, tag)).exists()
|
return File(getFilePath(tag)).exists()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
fun writeFile(input: InputStream, filePath: String): Boolean {
|
||||||
|
try {
|
||||||
|
val byte = ByteArray(4096)
|
||||||
|
val output = ByteArrayOutputStream()
|
||||||
|
var l: Int
|
||||||
|
while (input.read(byte).also { l = it } != -1) {
|
||||||
|
output.write(byte, 0, l)
|
||||||
|
}
|
||||||
|
val fileDe = File(filePath)
|
||||||
|
if (!fileDe.exists()) {
|
||||||
|
fileDe.createNewFile()
|
||||||
|
}
|
||||||
|
val fileOutputStream = FileOutputStream(filePath)
|
||||||
|
|
||||||
|
fileOutputStream.write(output.toByteArray())
|
||||||
|
output.close()
|
||||||
|
fileOutputStream.close()
|
||||||
|
return true
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Log.d(
|
||||||
|
"-----------",
|
||||||
|
"---------ex="+ex.message
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载网络文件
|
||||||
|
fun downloadFile(url: String, path: String, result: (Boolean) -> Unit) {
|
||||||
|
var client = OkHttpClient() // 创建一个okhttp客户端对象
|
||||||
|
// 创建一个GET方式的请求结构
|
||||||
|
var request = Request.Builder().url(url).build()
|
||||||
|
var call = client.newCall(request); // 根据请求结构创建调用对象
|
||||||
|
// 加入HTTP请求队列。异步调用,并设置接口应答的回调方法
|
||||||
|
call.enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
result.invoke(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
response.body?.run {
|
||||||
|
val byteStream = byteStream()
|
||||||
|
val writeFile = writeFile(byteStream, path)
|
||||||
|
result.invoke(writeFile)
|
||||||
|
} ?:run{
|
||||||
|
result.invoke(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import java.io.OutputStream
|
|||||||
|
|
||||||
|
|
||||||
object FileUtil {
|
object FileUtil {
|
||||||
private const val DIR_FILE_NAME = "PrankSound"
|
private const val DIR_FILE_NAME = "ArtWallpaper"
|
||||||
private const val DIR_DOWNLOAD = "download"
|
private const val DIR_DOWNLOAD = "download"
|
||||||
private const val DIR_CREATE = "create"
|
private const val DIR_CREATE = "create"
|
||||||
|
|
||||||
@ -42,7 +42,11 @@ object FileUtil {
|
|||||||
* /storage/emulated/0/Android/data/com.prank.sounds.funny.toy.fart.haircut/cache/download
|
* /storage/emulated/0/Android/data/com.prank.sounds.funny.toy.fart.haircut/cache/download
|
||||||
*/
|
*/
|
||||||
fun getDownloadDirectory(): String {
|
fun getDownloadDirectory(): String {
|
||||||
return getDefaultDirectory() + File.separator + DIR_DOWNLOAD
|
val s = getDefaultDirectory()
|
||||||
|
if(!File(s).exists()){
|
||||||
|
File(s).mkdir()
|
||||||
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user