修改为正式广告,修复崩溃
This commit is contained in:
parent
261f5fa16c
commit
ba0ac9fcaf
@ -19,8 +19,8 @@ android {
|
||||
applicationId = "com.wallart.art.wallpapers.hd"
|
||||
minSdk = 23
|
||||
targetSdk = 34
|
||||
versionCode = 3
|
||||
versionName = "1.0.2"
|
||||
versionCode = 4
|
||||
versionName = "1.0.3"
|
||||
setProperty("archivesBaseName", "Art Wallpaper_V" + versionName + "(${versionCode})_$timestamp")
|
||||
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())) {
|
||||
DownloadUtil.getFilePath(bean.sourceURl, bean.getTag())
|
||||
DownloadUtil.getFilePath(bean.getTag())
|
||||
} else {
|
||||
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())) {
|
||||
DownloadUtil.getFilePath(bean.sourceURl, bean.getTag())
|
||||
DownloadUtil.getFilePath(bean.getTag())
|
||||
} else {
|
||||
bean.previewURl
|
||||
}
|
||||
|
||||
@ -10,8 +10,8 @@ class Data(var previewURl: String, var sourceURl: String) : Serializable {
|
||||
|
||||
val lastIndex2 = sourceURl.lastIndexOf(".")
|
||||
|
||||
val substring = sourceURl.substring(lastIndex1, lastIndex2)
|
||||
Log.d("-----------","----------$substring")
|
||||
val substring = sourceURl.substring(lastIndex1+1, lastIndex2)
|
||||
Log.d("-----------","------TAG----$substring")
|
||||
|
||||
return substring
|
||||
|
||||
|
||||
@ -149,7 +149,6 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
||||
val image = mList[mCurPos]
|
||||
val path =
|
||||
DownloadUtil.getFilePath(
|
||||
image.sourceURl,
|
||||
image.getTag()
|
||||
)
|
||||
val file = File(path)
|
||||
@ -161,12 +160,16 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
||||
mSetAsDialog = SetAsDialog(this) {
|
||||
onClickHomeScreen = {
|
||||
lifecycleScope.launch {
|
||||
wallpaperManager.setStream(
|
||||
file.inputStream(),
|
||||
null,
|
||||
true,
|
||||
WallpaperManager.FLAG_SYSTEM
|
||||
)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallpaperManager.setStream(
|
||||
file.inputStream(),
|
||||
null,
|
||||
true,
|
||||
WallpaperManager.FLAG_SYSTEM
|
||||
)
|
||||
}else{
|
||||
wallpaperManager.setStream(file.inputStream())
|
||||
}
|
||||
onMain {
|
||||
Toast.makeText(
|
||||
this@CategoryPreviewAbility,
|
||||
@ -179,12 +182,16 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
||||
|
||||
onClickLockScreen = {
|
||||
lifecycleScope.launch {
|
||||
wallpaperManager.setStream(
|
||||
file.inputStream(),
|
||||
null,
|
||||
true,
|
||||
WallpaperManager.FLAG_LOCK
|
||||
)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallpaperManager.setStream(
|
||||
file.inputStream(),
|
||||
null,
|
||||
true,
|
||||
WallpaperManager.FLAG_LOCK
|
||||
)
|
||||
}else{
|
||||
wallpaperManager.setStream(file.inputStream())
|
||||
}
|
||||
onMain {
|
||||
Toast.makeText(
|
||||
this@CategoryPreviewAbility,
|
||||
@ -235,7 +242,7 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
||||
}
|
||||
binding.flDownload.show()
|
||||
FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
||||
.setPath(DownloadUtil.getFilePath(mList[mCurPos].sourceURl, mList[mCurPos].getTag()))
|
||||
.setPath(DownloadUtil.getFilePath( mList[mCurPos].getTag()))
|
||||
.setCallbackProgressTimes(300)
|
||||
.setMinIntervalUpdateSpeed(400)
|
||||
.setListener(object : FileDownloadListener() {
|
||||
@ -301,7 +308,6 @@ class CategoryPreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCa
|
||||
val image = mList[mCurPos]
|
||||
val path =
|
||||
DownloadUtil.getFilePath(
|
||||
image.sourceURl,
|
||||
image.getTag()
|
||||
)
|
||||
val saved = MediaUtil.saveImageToSystemAlbum(path, this@CategoryPreviewAbility)
|
||||
|
||||
@ -12,6 +12,7 @@ import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
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.adapter.ImagePagerAdapter
|
||||
import com.cute.girl.hd.pink.img.wallpaper.databinding.AbilityPreviewBinding
|
||||
@ -179,7 +180,6 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
||||
val image = mList[mCurPos]
|
||||
val path =
|
||||
DownloadUtil.getFilePath(
|
||||
image.sourceURl,
|
||||
image.getTag()
|
||||
)
|
||||
val file = File(path)
|
||||
@ -282,29 +282,16 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
||||
if (isFinishing) {
|
||||
return
|
||||
}
|
||||
val filePath = DownloadUtil.getFilePath(mList[mCurPos].sourceURl, mList[mCurPos].getTag())
|
||||
val filePath = DownloadUtil.getFilePath( mList[mCurPos].getTag())
|
||||
Log.d(
|
||||
"-----------",
|
||||
"---------startDownload-${mList[mCurPos].sourceURl} filePath=${filePath}"
|
||||
)
|
||||
binding.flDownload.show()
|
||||
FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
||||
.setPath(filePath)
|
||||
.setCallbackProgressTimes(300)
|
||||
.setMinIntervalUpdateSpeed(400)
|
||||
.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")
|
||||
DownloadUtil.downloadFile(mList[mCurPos].sourceURl,filePath){
|
||||
runOnUiThread {
|
||||
binding.flDownload.hide()
|
||||
if(it){
|
||||
if (!isFinishing) {
|
||||
binding.flDownload.hide()
|
||||
mImagePagerAdapter?.notifyItemChanged(mCurPos)
|
||||
@ -314,9 +301,7 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
||||
saveWallpaper()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun paused(task: BaseDownloadTask?, soFarBytes: Int, totalBytes: Int) {
|
||||
}else{
|
||||
if (!isFinishing) {
|
||||
binding.flDownload.hide()
|
||||
Toast.makeText(
|
||||
@ -326,37 +311,77 @@ class PreviewAbility : AppCompatActivity(), EasyPermissions.PermissionCallbacks
|
||||
).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()
|
||||
// FileDownloader.getImpl().create(mList[mCurPos].sourceURl)
|
||||
// .setPath(filePath)
|
||||
// .setCallbackProgressTimes(300)
|
||||
// .setMinIntervalUpdateSpeed(400)
|
||||
// .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) {
|
||||
// binding.flDownload.hide()
|
||||
// mImagePagerAdapter?.notifyItemChanged(mCurPos)
|
||||
// if (mAction == 0) {
|
||||
// set4KWallpaper()
|
||||
// } 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() {
|
||||
val image = mList[mCurPos]
|
||||
val path =
|
||||
DownloadUtil.getFilePath(
|
||||
image.sourceURl,
|
||||
image.getTag()
|
||||
)
|
||||
val saved = MediaUtil.saveImageToSystemAlbum(path, this@PreviewAbility)
|
||||
|
||||
@ -15,7 +15,7 @@ import java.util.Objects;
|
||||
public class UnityAdManager {
|
||||
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 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.text.TextUtils
|
||||
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.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
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
|
||||
*
|
||||
* /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
|
||||
Log.d("--------","----getFilePath--$s")
|
||||
Log.d("-----------", "----getFilePath--$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
|
||||
*/
|
||||
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 {
|
||||
private const val DIR_FILE_NAME = "PrankSound"
|
||||
private const val DIR_FILE_NAME = "ArtWallpaper"
|
||||
private const val DIR_DOWNLOAD = "download"
|
||||
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
|
||||
*/
|
||||
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