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())
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"

View File

@ -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<ActivityVideoBinding> 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<ActivityVideoBinding> 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<ActivityVideoBinding> 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<ActivityVideoBinding> 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<ActivityVideoBinding> 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<ActivityVideoBinding> implements
@Override
public void run() {
if (success) {
download = true;
checkPlay();
} else {
// TODO: 2024/12/23 下载失败
@ -162,20 +164,19 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> 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<ActivityVideoBinding> 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<ActivityVideoBinding> implements
countDownTimer = null;
}
if (disposable != null && !disposable.isDisposed()) {
Common.logMsg("-------------dispose");
disposable.dispose();
}
@ -255,6 +258,7 @@ public class VideoActivity extends BaseActivity<ActivityVideoBinding> 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<ActivityVideoBinding> 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!");
// }
// }
// });
}
}

View File

@ -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())

View File

@ -21,7 +21,6 @@
app:use_controller="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="120dp"
@ -95,20 +94,39 @@
android:id="@+id/relative_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_white_80"
android:clickable="true"
android:focusable="true"
android:background="@color/color_white_80"
android:visibility="visible">
<ProgressBar
android:id="@+id/horizontal_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="6dp"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progress_bar_horizontal" />
android:gravity="center"
android:id="@+id/horizontal_layout"
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
android:id="@+id/normal_progress"
@ -124,8 +142,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<com.live.mylivewallpaper.help.MyTextView
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="Retry">Retry</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>