diff --git a/LiveWallpaper.jks b/app/LiveWallpaper.jks similarity index 100% rename from LiveWallpaper.jks rename to app/LiveWallpaper.jks diff --git a/app/build.gradle.kts b/app/build.gradle.kts index addea20..40d5a8c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -8,14 +8,14 @@ plugins { val timestamp = SimpleDateFormat("MM_dd_HH_mm").format(Date()) android { namespace = "com.live.mylivewallpaper" - compileSdk = 35 + compileSdk = 34 defaultConfig { applicationId = "com.live.mylivewallpaper" minSdk = 23 - targetSdk = 35 - versionCode = 1 - versionName = "1.0.0" + targetSdk = 34 + versionCode = 2 + versionName = "1.0.1" setProperty( "archivesBaseName", "Live Wallpaper_V" + versionName + "(${versionCode})_$timestamp" diff --git a/app/src/main/java/com/live/mylivewallpaper/activity/VideoActivity.java b/app/src/main/java/com/live/mylivewallpaper/activity/VideoActivity.java index 2041578..0aac3dc 100644 --- a/app/src/main/java/com/live/mylivewallpaper/activity/VideoActivity.java +++ b/app/src/main/java/com/live/mylivewallpaper/activity/VideoActivity.java @@ -1,12 +1,14 @@ package com.live.mylivewallpaper.activity; import android.app.WallpaperManager; +import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Intent; import android.net.Uri; import android.os.CountDownTimer; import android.view.SurfaceHolder; import android.view.View; +import android.widget.Toast; import androidx.annotation.OptIn; import androidx.media3.common.MediaItem; @@ -17,6 +19,7 @@ import androidx.media3.exoplayer.ExoPlayer; import androidx.media3.exoplayer.SimpleExoPlayer; import androidx.media3.exoplayer.source.ProgressiveMediaSource; +import com.live.mylivewallpaper.R; import com.live.mylivewallpaper.base.BaseActivity; import com.live.mylivewallpaper.data.LikeData; import com.live.mylivewallpaper.databinding.ActivityVideoBinding; @@ -29,6 +32,7 @@ import com.live.mylivewallpaper.request.ProgressResponseBody; import com.live.mylivewallpaper.request.RetrofitManager; import java.io.File; +import java.util.concurrent.atomic.AtomicBoolean; import io.reactivex.disposables.Disposable; @@ -41,7 +45,7 @@ public class VideoActivity extends BaseActivity implements private String filePath; private File mFile; - private boolean download = false; +// private boolean download = false; private ExoPlayer exoPlayer; @@ -58,7 +62,8 @@ public class VideoActivity extends BaseActivity implements public static String KEY_wallpaperType = "wallpaperType"; public static String KEY_thumb = "thumb"; - private boolean loadingui = false; + // private boolean loadingui = false; + private AtomicBoolean loadingui ; private Disposable disposable; @Override @@ -82,19 +87,20 @@ public class VideoActivity extends BaseActivity implements initFavorite(); if (mFile.exists()) { Common.logMsg("------checkPlay-"); - download = true; checkPlay(); return; } + loadingui = new AtomicBoolean(false); requestVideo(); } private void requestVideo() { + if (wallpaperType == 2) { //shift - disposable = RetrofitManager.getInstance(this).getShiftMp4(id, image, filePath, new OnVideoResultListener() { + disposable = RetrofitManager.getInstance().getShiftMp4(id, image, filePath,this, new OnVideoResultListener() { @Override public void onVideoResult(boolean success, String path) { Common.logMsg("-------------success =" + success + "--path=" + path); @@ -102,11 +108,8 @@ public class VideoActivity extends BaseActivity implements @Override public void run() { if (success) { - download = true; checkPlay(); } else { - // TODO: 2024/12/23 下载失败 -// showLoading(false,false); showRetry(); Common.logMsg("-------------loading fail"); } @@ -116,7 +119,7 @@ public class VideoActivity extends BaseActivity implements } }); } else { - disposable = RetrofitManager.getInstance(this).getMp4(id, image, filePath, new OnVideoResultListener() { + disposable = RetrofitManager.getInstance().getMp4(id, image, filePath,this, new OnVideoResultListener() { @Override public void onVideoResult(boolean success, String path) { Common.logMsg("-------------success =" + success + "--path=" + path); @@ -124,7 +127,6 @@ public class VideoActivity extends BaseActivity implements @Override public void run() { if (success) { - download = true; checkPlay(); } else { // TODO: 2024/12/23 下载失败 @@ -162,20 +164,19 @@ public class VideoActivity extends BaseActivity implements } private void checkPlay() { - if (download) { - playMedia3(); - } + playMedia3(); } private void showLoading(boolean loading, boolean isHorizontal) { if (loading) { + vb.layoutRetry.setVisibility(View.GONE); vb.relativeLoading.setVisibility(View.VISIBLE); if (isHorizontal) { - vb.horizontalProgress.setVisibility(View.VISIBLE); + vb.horizontalLayout.setVisibility(View.VISIBLE); vb.normalProgress.setVisibility(View.GONE); } else { vb.normalProgress.setVisibility(View.VISIBLE); - vb.horizontalProgress.setVisibility(View.GONE); + vb.horizontalLayout.setVisibility(View.GONE); } } else { if (isHorizontal) { @@ -187,8 +188,9 @@ public class VideoActivity extends BaseActivity implements } private void showRetry() { + Toast.makeText(VideoActivity.this, getString(R.string.check_net), Toast.LENGTH_SHORT).show(); vb.relativeLoading.setVisibility(View.VISIBLE); - vb.horizontalProgress.setVisibility(View.GONE); + vb.horizontalLayout.setVisibility(View.GONE); vb.normalProgress.setVisibility(View.GONE); vb.layoutRetry.setVisibility(View.VISIBLE); } @@ -246,6 +248,7 @@ public class VideoActivity extends BaseActivity implements countDownTimer = null; } if (disposable != null && !disposable.isDisposed()) { + Common.logMsg("-------------dispose"); disposable.dispose(); } @@ -255,6 +258,7 @@ public class VideoActivity extends BaseActivity implements @OptIn(markerClass = UnstableApi.class) private void playMedia3() { try { + Common.logMsg("-------------playMedia3"); Uri uriFromFilePath = Common.getUriFromFilePath(this, filePath); MediaItem mediaItem = MediaItem.fromUri(uriFromFilePath); ProgressiveMediaSource mediaSource = createMediaSource(mediaItem); @@ -290,36 +294,63 @@ public class VideoActivity extends BaseActivity implements Common.logMsg("---------e=" + e.getMessage()); } - ComponentName componentName = new ComponentName(VideoActivity.this, LiveWallpaperService.class); - Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); - intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName); - startActivity(intent); + try { + ComponentName componentName = new ComponentName(VideoActivity.this, LiveWallpaperService.class); + Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); + intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName); + startActivity(intent); + } catch (Exception e) { + Common.logMsg("---------e=" + e.getMessage()); + } finish(); } @Override public void onProgress(long bytesRead, long contentLength, boolean done) { - runOnUiThread(new Runnable() { - @Override - public void run() { - Common.logMsg("------------onProgress=" + Thread.currentThread().getName()); - if (contentLength <= 0) { - } else { - if (!loadingui) { - showLoading(true, true); - loadingui = true; - } - int progress = (int) ((100 * bytesRead) / contentLength); - Common.logMsg("Download progress: " + progress + "%"); - vb.horizontalProgress.setProgress(progress); - } - if (done) { - Common.logMsg("Download complete!"); - } + if (contentLength <= 0) { + Common.logMsg("contentLength" + contentLength); + } else { + int progress = (int) ((100 * bytesRead) / contentLength); +// Common.logMsg("Download progress: " + progress + "%"+"---loadingui="+loadingui); + if (vb.horizontalProgress.getProgress() != progress) { + runOnUiThread(new Runnable() { + @Override + public void run() { + if(vb.horizontalLayout.getVisibility() != View.VISIBLE){ + showLoading(true, true); + Common.logMsg("------------showLoading------11-----"); + }else { + Common.logMsg("------------showLoading------22-----"); + } + vb.horizontalProgress.setProgress(progress); + } + }); } - }); + + } + if (done) { + Common.logMsg("Download complete!"); + } + + +// runOnUiThread(new Runnable() { +// @Override +// public void run() { +// if (contentLength <= 0) { +// Common.logMsg("contentLength" +contentLength); +// } else { +// showLoading(true, true); +// int progress = (int) ((100 * bytesRead) / contentLength); +// Common.logMsg("Download progress: " + progress + "%"+"---loadingui="+loadingui); +// vb.horizontalProgress.setProgress(progress); +// } +// if (done) { +// Common.logMsg("Download complete!"); +// } +// } +// }); } } \ No newline at end of file diff --git a/app/src/main/java/com/live/mylivewallpaper/request/RetrofitManager.java b/app/src/main/java/com/live/mylivewallpaper/request/RetrofitManager.java index 7774cdd..afc0bcd 100644 --- a/app/src/main/java/com/live/mylivewallpaper/request/RetrofitManager.java +++ b/app/src/main/java/com/live/mylivewallpaper/request/RetrofitManager.java @@ -29,44 +29,52 @@ public class RetrofitManager { private static volatile RetrofitManager REQUEST_MANAGER; private Retrofit retrofit; - public MediaType JSON = MediaType.get("application/json; charset=utf-8"); +// public MediaType JSON = MediaType.get("application/json; charset=utf-8"); private MusicApi musicApi; + private Retrofit.Builder builder; + private OkHttpClient.Builder clientBuilder; - private RetrofitManager(ProgressResponseBody.ProgressListener listener) { + private RetrofitManager() { - musicApi = getRetrofit(listener).create(MusicApi.class); } private synchronized Retrofit getRetrofit(ProgressResponseBody.ProgressListener listener) { - if (retrofit == null) { + if (builder == null) { +// retrofit = new Retrofit.Builder() +// .baseUrl(base_Host) +// .client(client) +//// .addConverterFactory(ScalarsConverterFactory.create()) // 支持返回 String 类型 +//// .addConverterFactory(GsonConverterFactory.create()) +// .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) +// .build(); + + builder = new Retrofit.Builder() + .baseUrl(base_Host) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()); + + } + if(clientBuilder == null){ long DEFAULT_TIMEOUT = 5; HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); - OkHttpClient client = new OkHttpClient.Builder() + clientBuilder = new OkHttpClient.Builder() // .addNetworkInterceptor(new GzipInterceptor()) .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) - .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) - .addInterceptor(new ProgressInterceptor(listener)) - .build(); - retrofit = new Retrofit.Builder() - .baseUrl(base_Host) - .client(client) -// .addConverterFactory(ScalarsConverterFactory.create()) // 支持返回 String 类型 -// .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) - .build(); + .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS); } - return retrofit; + clientBuilder.addInterceptor(new ProgressInterceptor(listener)); + + return builder.client(clientBuilder.build()).build(); } - public static RetrofitManager getInstance(ProgressResponseBody.ProgressListener listener) { + public static RetrofitManager getInstance() { if (REQUEST_MANAGER == null) { synchronized (RetrofitManager.class) { if (REQUEST_MANAGER == null) { - REQUEST_MANAGER = new RetrofitManager(listener); + REQUEST_MANAGER = new RetrofitManager(); } } } @@ -74,8 +82,8 @@ public class RetrofitManager { } - public Disposable getMp4(int id, String image, String path, OnVideoResultListener listener) { - Disposable subscribe = musicApi.getMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewLive") + public Disposable getMp4(int id, String image, String path,ProgressResponseBody.ProgressListener progressListener, OnVideoResultListener listener) { + Disposable subscribe = getRetrofit(progressListener).create(MusicApi.class).getMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewLive") .subscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) @@ -95,8 +103,8 @@ public class RetrofitManager { } - public Disposable getShiftMp4(int id, String image, String path, OnVideoResultListener listener) { - Disposable subscribe = musicApi.getShiftMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewShiftLive") + public Disposable getShiftMp4(int id, String image, String path, ProgressResponseBody.ProgressListener progressListener,OnVideoResultListener listener) { + Disposable subscribe = getRetrofit(progressListener).create(MusicApi.class).getShiftMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewShiftLive") .subscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) diff --git a/app/src/main/res/layout/activity_video.xml b/app/src/main/res/layout/activity_video.xml index f07196f..aa727f9 100644 --- a/app/src/main/res/layout/activity_video.xml +++ b/app/src/main/res/layout/activity_video.xml @@ -21,7 +21,6 @@ app:use_controller="false" /> - - + android:gravity="center" + android:id="@+id/horizontal_layout" + android:orientation="vertical"> + + + + + + android:orientation="vertical" + android:visibility="gone"> Loading failed, please check the network and try again Retry You haven not collected any wallpapers yet! + Please check your network connection + Downloading video, please wait patiently \ No newline at end of file