Fix drawable bug

pull/586/head
FongMi 2 years ago
parent 5d8762b29e
commit ada47db2c3
  1. 8
      app/src/leanback/java/com/fongmi/android/tv/ui/base/BaseActivity.java
  2. 12
      app/src/main/java/com/fongmi/android/tv/api/config/WallConfig.java
  3. 8
      app/src/mobile/java/com/fongmi/android/tv/ui/base/BaseActivity.java

@ -3,6 +3,7 @@ package com.fongmi.android.tv.ui.base;
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
@ -15,7 +16,6 @@ import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.api.config.WallConfig;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.ResUtil;
@ -96,7 +96,7 @@ public abstract class BaseActivity extends AppCompatActivity {
try {
if (!customWall()) return;
File file = FileUtil.getWall(Setting.getWall());
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(WallConfig.drawable(file));
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(Drawable.createFromPath(file.getAbsolutePath()));
else getWindow().setBackgroundDrawableResource(ResUtil.getDrawable(file.getName()));
} catch (Exception e) {
getWindow().setBackgroundDrawableResource(R.drawable.wallpaper_1);
@ -114,9 +114,7 @@ public abstract class BaseActivity extends AppCompatActivity {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) {
if (event.getType() != RefreshEvent.Type.WALL) return;
WallConfig.get().setDrawable(null);
refreshWall();
if (event.getType() == RefreshEvent.Type.WALL) refreshWall();
}
@Override

@ -1,7 +1,6 @@
package com.fongmi.android.tv.api.config;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import com.bumptech.glide.Glide;
@ -24,7 +23,6 @@ import java.io.FileOutputStream;
public class WallConfig {
private Drawable drawable;
private Config config;
private boolean sync;
@ -44,12 +42,6 @@ public class WallConfig {
return get().getConfig().getDesc();
}
public static Drawable drawable(File file) {
if (get().drawable != null) return get().drawable;
get().setDrawable(Drawable.createFromPath(file.getAbsolutePath()));
return get().drawable;
}
public static void load(Config config, Callback callback) {
get().clear().config(config).load(callback);
}
@ -74,10 +66,6 @@ public class WallConfig {
return config == null ? Config.wall() : config;
}
public void setDrawable(Drawable drawable) {
this.drawable = drawable;
}
public void load(Callback callback) {
App.execute(() -> loadConfig(callback));
}

@ -2,6 +2,7 @@ package com.fongmi.android.tv.ui.base;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.DisplayCutout;
@ -15,7 +16,6 @@ import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.api.config.WallConfig;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.ResUtil;
@ -120,7 +120,7 @@ public abstract class BaseActivity extends AppCompatActivity {
try {
if (!customWall()) return;
File file = FileUtil.getWall(Setting.getWall());
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(WallConfig.drawable(file));
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(Drawable.createFromPath(file.getAbsolutePath()));
else getWindow().setBackgroundDrawableResource(ResUtil.getDrawable(file.getName()));
} catch (Exception e) {
getWindow().setBackgroundDrawableResource(R.drawable.wallpaper_1);
@ -129,9 +129,7 @@ public abstract class BaseActivity extends AppCompatActivity {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) {
if (event.getType() != RefreshEvent.Type.WALL) return;
WallConfig.get().setDrawable(null);
refreshWall();
if (event.getType() == RefreshEvent.Type.WALL) refreshWall();
}
@Override

Loading…
Cancel
Save