V1.0.1(2) 处理bug

This commit is contained in:
litingting 2024-12-26 13:53:27 +08:00
parent 23491dc1b3
commit 2fba288da6
6 changed files with 134 additions and 75 deletions

View File

@ -8,14 +8,14 @@ plugins {
val timestamp = SimpleDateFormat("MM_dd_HH_mm").format(Date()) val timestamp = SimpleDateFormat("MM_dd_HH_mm").format(Date())
android { android {
namespace = "com.live.mylivewallpaper" namespace = "com.live.mylivewallpaper"
compileSdk = 35 compileSdk = 34
defaultConfig { defaultConfig {
applicationId = "com.live.mylivewallpaper" applicationId = "com.live.mylivewallpaper"
minSdk = 23 minSdk = 23
targetSdk = 35 targetSdk = 34
versionCode = 1 versionCode = 2
versionName = "1.0.0" versionName = "1.0.1"
setProperty( setProperty(
"archivesBaseName", "archivesBaseName",
"Live Wallpaper_V" + versionName + "(${versionCode})_$timestamp" "Live Wallpaper_V" + versionName + "(${versionCode})_$timestamp"

View File

@ -1,12 +1,14 @@
package com.live.mylivewallpaper.activity; package com.live.mylivewallpaper.activity;
import android.app.WallpaperManager; import android.app.WallpaperManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.View; import android.view.View;
import android.widget.Toast;
import androidx.annotation.OptIn; import androidx.annotation.OptIn;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
@ -17,6 +19,7 @@ import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.SimpleExoPlayer; import androidx.media3.exoplayer.SimpleExoPlayer;
import androidx.media3.exoplayer.source.ProgressiveMediaSource; import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import com.live.mylivewallpaper.R;
import com.live.mylivewallpaper.base.BaseActivity; import com.live.mylivewallpaper.base.BaseActivity;
import com.live.mylivewallpaper.data.LikeData; import com.live.mylivewallpaper.data.LikeData;
import com.live.mylivewallpaper.databinding.ActivityVideoBinding; import com.live.mylivewallpaper.databinding.ActivityVideoBinding;
@ -29,6 +32,7 @@ import com.live.mylivewallpaper.request.ProgressResponseBody;
import com.live.mylivewallpaper.request.RetrofitManager; import com.live.mylivewallpaper.request.RetrofitManager;
import java.io.File; import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
@ -41,7 +45,7 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
private String filePath; private String filePath;
private File mFile; private File mFile;
private boolean download = false; // private boolean download = false;
private ExoPlayer exoPlayer; private ExoPlayer exoPlayer;
@ -58,7 +62,8 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
public static String KEY_wallpaperType = "wallpaperType"; public static String KEY_wallpaperType = "wallpaperType";
public static String KEY_thumb = "thumb"; public static String KEY_thumb = "thumb";
private boolean loadingui = false; // private boolean loadingui = false;
private AtomicBoolean loadingui ;
private Disposable disposable; private Disposable disposable;
@Override @Override
@ -82,19 +87,20 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
initFavorite(); initFavorite();
if (mFile.exists()) { if (mFile.exists()) {
Common.logMsg("------checkPlay-"); Common.logMsg("------checkPlay-");
download = true;
checkPlay(); checkPlay();
return; return;
} }
loadingui = new AtomicBoolean(false);
requestVideo(); requestVideo();
} }
private void requestVideo() { private void requestVideo() {
if (wallpaperType == 2) { if (wallpaperType == 2) {
//shift //shift
disposable = RetrofitManager.getInstance(this).getShiftMp4(id, image, filePath, new OnVideoResultListener() { disposable = RetrofitManager.getInstance().getShiftMp4(id, image, filePath,this, new OnVideoResultListener() {
@Override @Override
public void onVideoResult(boolean success, String path) { public void onVideoResult(boolean success, String path) {
Common.logMsg("-------------success =" + success + "--path=" + path); Common.logMsg("-------------success =" + success + "--path=" + path);
@ -102,11 +108,8 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
@Override @Override
public void run() { public void run() {
if (success) { if (success) {
download = true;
checkPlay(); checkPlay();
} else { } else {
// TODO: 2024/12/23 下载失败
// showLoading(false,false);
showRetry(); showRetry();
Common.logMsg("-------------loading fail"); Common.logMsg("-------------loading fail");
} }
@ -116,7 +119,7 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
} }
}); });
} else { } else {
disposable = RetrofitManager.getInstance(this).getMp4(id, image, filePath, new OnVideoResultListener() { disposable = RetrofitManager.getInstance().getMp4(id, image, filePath,this, new OnVideoResultListener() {
@Override @Override
public void onVideoResult(boolean success, String path) { public void onVideoResult(boolean success, String path) {
Common.logMsg("-------------success =" + success + "--path=" + path); Common.logMsg("-------------success =" + success + "--path=" + path);
@ -124,7 +127,6 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
@Override @Override
public void run() { public void run() {
if (success) { if (success) {
download = true;
checkPlay(); checkPlay();
} else { } else {
// TODO: 2024/12/23 下载失败 // TODO: 2024/12/23 下载失败
@ -162,20 +164,19 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
} }
private void checkPlay() { private void checkPlay() {
if (download) { playMedia3();
playMedia3();
}
} }
private void showLoading(boolean loading, boolean isHorizontal) { private void showLoading(boolean loading, boolean isHorizontal) {
if (loading) { if (loading) {
vb.layoutRetry.setVisibility(View.GONE);
vb.relativeLoading.setVisibility(View.VISIBLE); vb.relativeLoading.setVisibility(View.VISIBLE);
if (isHorizontal) { if (isHorizontal) {
vb.horizontalProgress.setVisibility(View.VISIBLE); vb.horizontalLayout.setVisibility(View.VISIBLE);
vb.normalProgress.setVisibility(View.GONE); vb.normalProgress.setVisibility(View.GONE);
} else { } else {
vb.normalProgress.setVisibility(View.VISIBLE); vb.normalProgress.setVisibility(View.VISIBLE);
vb.horizontalProgress.setVisibility(View.GONE); vb.horizontalLayout.setVisibility(View.GONE);
} }
} else { } else {
if (isHorizontal) { if (isHorizontal) {
@ -187,8 +188,9 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
} }
private void showRetry() { private void showRetry() {
Toast.makeText(VideoActivity.this, getString(R.string.check_net), Toast.LENGTH_SHORT).show();
vb.relativeLoading.setVisibility(View.VISIBLE); vb.relativeLoading.setVisibility(View.VISIBLE);
vb.horizontalProgress.setVisibility(View.GONE); vb.horizontalLayout.setVisibility(View.GONE);
vb.normalProgress.setVisibility(View.GONE); vb.normalProgress.setVisibility(View.GONE);
vb.layoutRetry.setVisibility(View.VISIBLE); vb.layoutRetry.setVisibility(View.VISIBLE);
} }
@ -246,6 +248,7 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
countDownTimer = null; countDownTimer = null;
} }
if (disposable != null && !disposable.isDisposed()) { if (disposable != null && !disposable.isDisposed()) {
Common.logMsg("-------------dispose");
disposable.dispose(); disposable.dispose();
} }
@ -255,6 +258,7 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
@OptIn(markerClass = UnstableApi.class) @OptIn(markerClass = UnstableApi.class)
private void playMedia3() { private void playMedia3() {
try { try {
Common.logMsg("-------------playMedia3");
Uri uriFromFilePath = Common.getUriFromFilePath(this, filePath); Uri uriFromFilePath = Common.getUriFromFilePath(this, filePath);
MediaItem mediaItem = MediaItem.fromUri(uriFromFilePath); MediaItem mediaItem = MediaItem.fromUri(uriFromFilePath);
ProgressiveMediaSource mediaSource = createMediaSource(mediaItem); ProgressiveMediaSource mediaSource = createMediaSource(mediaItem);
@ -290,36 +294,63 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> implements
Common.logMsg("---------e=" + e.getMessage()); Common.logMsg("---------e=" + e.getMessage());
} }
ComponentName componentName = new ComponentName(VideoActivity.this, LiveWallpaperService.class); try {
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); ComponentName componentName = new ComponentName(VideoActivity.this, LiveWallpaperService.class);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName); Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
startActivity(intent); intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName);
startActivity(intent);
} catch (Exception e) {
Common.logMsg("---------e=" + e.getMessage());
}
finish(); finish();
} }
@Override @Override
public void onProgress(long bytesRead, long contentLength, boolean done) { 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); if (contentLength <= 0) {
Common.logMsg("Download progress: " + progress + "%"); Common.logMsg("contentLength" + contentLength);
vb.horizontalProgress.setProgress(progress); } else {
} int progress = (int) ((100 * bytesRead) / contentLength);
if (done) { // Common.logMsg("Download progress: " + progress + "%"+"---loadingui="+loadingui);
Common.logMsg("Download complete!"); 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!");
// }
// }
// });
} }
} }

View File

@ -29,44 +29,52 @@ public class RetrofitManager {
private static volatile RetrofitManager REQUEST_MANAGER; private static volatile RetrofitManager REQUEST_MANAGER;
private Retrofit retrofit; 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 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) { 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; long DEFAULT_TIMEOUT = 5;
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder() clientBuilder = new OkHttpClient.Builder()
// .addNetworkInterceptor(new GzipInterceptor()) // .addNetworkInterceptor(new GzipInterceptor())
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(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();
} }
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) { if (REQUEST_MANAGER == null) {
synchronized (RetrofitManager.class) { synchronized (RetrofitManager.class) {
if (REQUEST_MANAGER == null) { 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) { public Disposable getMp4(int id, String image, String path,ProgressResponseBody.ProgressListener progressListener, OnVideoResultListener listener) {
Disposable subscribe = musicApi.getMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewLive") Disposable subscribe = getRetrofit(progressListener).create(MusicApi.class).getMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewLive")
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io())
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
@ -95,8 +103,8 @@ public class RetrofitManager {
} }
public Disposable getShiftMp4(int id, String image, String path, OnVideoResultListener listener) { public Disposable getShiftMp4(int id, String image, String path, ProgressResponseBody.ProgressListener progressListener,OnVideoResultListener listener) {
Disposable subscribe = musicApi.getShiftMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewShiftLive") Disposable subscribe = getRetrofit(progressListener).create(MusicApi.class).getShiftMP4(id, "5eV6snEwfY7Yv6Ub", image, "DL8", "ViewShiftLive")
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io())
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())

View File

@ -21,7 +21,6 @@
app:use_controller="false" /> app:use_controller="false" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="120dp" android:layout_height="120dp"
@ -95,20 +94,39 @@
android:id="@+id/relative_loading" android:id="@+id/relative_loading"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/color_white_80"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:background="@color/color_white_80"
android:visibility="visible"> android:visibility="visible">
<ProgressBar <LinearLayout
android:id="@+id/horizontal_progress" android:layout_width="wrap_content"
style="?android:attr/progressBarStyleHorizontal" android:layout_height="wrap_content"
android:layout_width="200dp"
android:layout_height="6dp"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:max="100" android:gravity="center"
android:progress="0" android:id="@+id/horizontal_layout"
android:progressDrawable="@drawable/progress_bar_horizontal" /> android:orientation="vertical">
<com.live.mylivewallpaper.help.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:lineSpacingExtra="4dp"
android:text="@string/loading"
android:textColor="@color/black"
android:textSize="16sp"
app:apply_font="true" />
<ProgressBar
android:id="@+id/horizontal_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_marginTop="10dp"
android:layout_height="6dp"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progress_bar_horizontal" />
</LinearLayout>
<ProgressBar <ProgressBar
android:id="@+id/normal_progress" android:id="@+id/normal_progress"
@ -124,8 +142,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:visibility="gone" android:orientation="vertical"
android:orientation="vertical"> android:visibility="gone">
<com.live.mylivewallpaper.help.MyTextView <com.live.mylivewallpaper.help.MyTextView
android:id="@+id/tv_load_fail" android:id="@+id/tv_load_fail"

View File

@ -10,4 +10,6 @@
<string name="fail_describe">Loading failed, please check the network and try again</string> <string name="fail_describe">Loading failed, please check the network and try again</string>
<string name="Retry">Retry</string> <string name="Retry">Retry</string>
<string name="empty_favorite">You haven not collected any wallpapers yet!</string> <string name="empty_favorite">You haven not collected any wallpapers yet!</string>
<string name="check_net">Please check your network connection</string>
<string name="loading">Downloading video, please wait patiently</string>
</resources> </resources>