Support wallpaper

pull/123/head
FongMi 3 years ago
parent 9c474ca56e
commit cae2d4012f
  1. 4
      app/build.gradle
  2. 1
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/DetailActivity.java
  3. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/HomeActivity.java
  4. 1
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/KeepActivity.java
  5. 1
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  6. 36
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/SettingActivity.java
  7. BIN
      app/src/leanback/res/drawable-nodpi/wallpaper_3.webp
  8. BIN
      app/src/leanback/res/drawable-nodpi/wallpaper_4.webp
  9. 64
      app/src/leanback/res/layout/activity_setting.xml
  10. 21
      app/src/main/java/com/fongmi/android/tv/api/ApiConfig.java
  11. 6
      app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java
  12. 26
      app/src/main/java/com/fongmi/android/tv/ui/activity/BaseActivity.java
  13. 7
      app/src/main/java/com/fongmi/android/tv/utils/FileUtil.java
  14. 4
      app/src/main/java/com/fongmi/android/tv/utils/Json.java
  15. 10
      app/src/main/java/com/fongmi/android/tv/utils/Prefers.java
  16. 4
      app/src/main/java/com/fongmi/android/tv/utils/ResUtil.java
  17. BIN
      app/src/main/res/drawable-nodpi/radio.webp
  18. 10
      app/src/main/res/drawable/ic_refresh.xml
  19. BIN
      app/src/main/res/drawable/radio.png
  20. 1
      app/src/main/res/values-zh-rCN/strings.xml
  21. 1
      app/src/main/res/values-zh-rTW/strings.xml
  22. 1
      app/src/main/res/values/strings.xml

@ -72,7 +72,7 @@ dependencies {
implementation 'androidx.room:room-runtime:2.4.3'
implementation 'cat.ereza:customactivityoncrash:2.4.0'
implementation 'com.github.bassaer:materialdesigncolors:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.14.1'
implementation 'com.github.bumptech.glide:glide:4.14.2'
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.google.zxing:core:3.5.0'
@ -84,5 +84,5 @@ dependencies {
implementation('org.simpleframework:simple-xml:2.7.1') { exclude group: 'stax', module: 'stax-api' exclude group: 'xpp3', module: 'xpp3' }
leanbackImplementation 'androidx.leanback:leanback:1.2.0-alpha02'
annotationProcessor 'androidx.room:room-compiler:2.4.3'
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
}

@ -150,7 +150,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
@Override
protected void initEvent() {
EventBus.getDefault().register(this);
mControl.replay.setOnClickListener(view -> getPlayer(true));
mBinding.video.setOnClickListener(view -> enterFullscreen());
mBinding.desc.setOnClickListener(view -> onDesc());

@ -87,7 +87,6 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
@Override
protected void initEvent() {
EventBus.getDefault().register(this);
mBinding.title.setListener(this);
mBinding.recycler.addOnChildViewHolderSelectedListener(new OnChildViewHolderSelectedListener() {
@Override
@ -252,6 +251,7 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) {
super.onRefreshEvent(event);
switch (event.getType()) {
case VIDEO:
getVideo();

@ -36,7 +36,6 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis
@Override
protected void initView() {
EventBus.getDefault().register(this);
setRecyclerView();
getKeep();
}

@ -109,7 +109,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
protected void initEvent() {
mBinding.group.setListener(this);
mBinding.channel.setListener(this);
EventBus.getDefault().register(this);
getPlayerView().setOnClickListener(view -> toggle());
mBinding.group.addOnChildViewHolderSelectedListener(new OnChildViewHolderSelectedListener() {
@Override

@ -8,10 +8,12 @@ import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.viewbinding.ViewBinding;
@ -29,15 +31,23 @@ import com.fongmi.android.tv.impl.ConfigCallback;
import com.fongmi.android.tv.impl.LiveCallback;
import com.fongmi.android.tv.impl.SiteCallback;
import com.fongmi.android.tv.net.Callback;
import com.fongmi.android.tv.net.OKHttp;
import com.fongmi.android.tv.ui.custom.dialog.ConfigDialog;
import com.fongmi.android.tv.ui.custom.dialog.HistoryDialog;
import com.fongmi.android.tv.ui.custom.dialog.LiveDialog;
import com.fongmi.android.tv.ui.custom.dialog.SiteDialog;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.ResUtil;
import com.fongmi.android.tv.utils.Updater;
import java.io.File;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Response;
public class SettingActivity extends BaseActivity implements ConfigCallback, SiteCallback, LiveCallback {
private final ActivityResultLauncher<String> launcherString = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> loadConfig());
@ -59,15 +69,17 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
protected void initView() {
mBinding.vodUrl.setText(ApiConfig.getUrl());
mBinding.liveUrl.setText(LiveConfig.getUrl());
mBinding.versionText.setText(BuildConfig.VERSION_NAME);
mBinding.wallpaperUrl.setText(ApiConfig.get().getWallpaper());
mBinding.sizeText.setText(ResUtil.getStringArray(R.array.select_size)[Prefers.getSize()]);
mBinding.scaleText.setText(ResUtil.getStringArray(R.array.select_scale)[Prefers.getScale()]);
mBinding.renderText.setText(ResUtil.getStringArray(R.array.select_render)[Prefers.getRender()]);
mBinding.qualityText.setText(ResUtil.getStringArray(R.array.select_quality)[Prefers.getQuality()]);
mBinding.versionText.setText(BuildConfig.VERSION_NAME);
}
@Override
protected void initEvent() {
mBinding.wallpaper.setOnClickListener(view -> Notify.show("下個版本見"));
mBinding.vodHome.setOnClickListener(view -> SiteDialog.create(this).show());
mBinding.liveHome.setOnClickListener(view -> LiveDialog.create(this).show());
mBinding.vod.setOnClickListener(view -> ConfigDialog.create(this).type(0).show());
@ -75,6 +87,8 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
mBinding.vodHistory.setOnClickListener(view -> HistoryDialog.create(this).type(0).show());
mBinding.liveHistory.setOnClickListener(view -> HistoryDialog.create(this).type(1).show());
mBinding.version.setOnClickListener(view -> Updater.create(this).force().start());
mBinding.wallpaperDefault.setOnClickListener(this::setWallpaperDefault);
mBinding.wallpaperRefresh.setOnClickListener(this::setWallpaperRefresh);
mBinding.quality.setOnClickListener(this::setQuality);
mBinding.render.setOnClickListener(this::setRender);
mBinding.scale.setOnClickListener(this::setScale);
@ -135,6 +149,7 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
private void refresh(int resId) {
Notify.dismiss();
Notify.show(resId);
mBinding.wallpaperUrl.setText(ApiConfig.get().getWallpaper());
if (resId != 0) config.delete();
if (config.isLive()) return;
RefreshEvent.history();
@ -181,4 +196,23 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
mBinding.sizeText.setText(array[index]);
RefreshEvent.size();
}
private void setWallpaperDefault(View view) {
int index = Prefers.getWallpaper();
Prefers.putWallpaper(index == 4 ? 1 : ++index);
RefreshEvent.wallpaper();
}
private void setWallpaperRefresh(View view) {
if (TextUtils.isEmpty(ApiConfig.get().getWallpaper())) return;
OKHttp.newCall(ApiConfig.get().getWallpaper()).enqueue(new Callback() {
@Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
File file = FileUtil.write(FileUtil.getWallpaper(0), response.body().bytes());
if (!file.exists() || file.length() == 0) return;
Prefers.putWallpaper(0);
RefreshEvent.wallpaper();
}
});
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -72,7 +72,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:nextFocusDown="@id/render"
android:orientation="horizontal">
<LinearLayout
@ -131,6 +130,69 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:nextFocusDown="@id/render"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/wallpaper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setting_wallpaper"
android:textColor="@color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/wallpaperUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="18sp"
tools:ignore="NestedWeights"
tools:text="https://" />
</LinearLayout>
<ImageView
android:id="@+id/wallpaperDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="8dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_home" />
<ImageView
android:id="@+id/wallpaperRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="8dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_refresh" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

@ -38,6 +38,7 @@ public class ApiConfig {
private List<Live> lives;
private JarLoader jLoader;
private PyLoader pLoader;
private String wallpaper;
private Handler handler;
private Config config;
private Parse parse;
@ -97,6 +98,7 @@ public class ApiConfig {
this.parses.clear();
this.jLoader.clear();
this.pLoader.clear();
this.wallpaper = null;
LiveConfig.get().remove(lives);
return this;
}
@ -130,7 +132,7 @@ public class ApiConfig {
private void parseConfig(JsonObject object, Callback callback) {
try {
parseJson(object);
jLoader.parseJar("", Json.safeString(object, "spider", ""));
jLoader.parseJar("", Json.safeString(object, "spider"));
config.json(object.toString()).update();
handler.post(callback::success);
} catch (Exception e) {
@ -157,6 +159,7 @@ public class ApiConfig {
}
if (home == null) setHome(sites.isEmpty() ? new Site() : sites.get(0));
if (parse == null) setParse(parses.isEmpty() ? new Parse() : parses.get(0));
setWallpaper(Json.safeString(object, "wallpaper"));
flags.addAll(Json.safeListString(object, "flags"));
ads.addAll(Json.safeListString(object, "ads"));
}
@ -207,20 +210,24 @@ public class ApiConfig {
return lives == null ? Collections.emptyList() : lives;
}
public void setLives(List<Live> lives) {
this.lives = lives;
}
public List<Parse> getParses() {
return parses == null ? Collections.emptyList() : parses;
}
public List<String> getFlags() {
return flags == null ? Collections.emptyList() : flags;
}
public String getAds() {
return ads == null ? "" : ads.toString();
}
public List<String> getFlags() {
return flags == null ? Collections.emptyList() : flags;
public String getWallpaper() {
return TextUtils.isEmpty(wallpaper) ? "" : wallpaper;
}
public void setWallpaper(String wallpaper) {
this.wallpaper = wallpaper;
}
public Config getConfig() {

@ -26,6 +26,10 @@ public class RefreshEvent {
EventBus.getDefault().post(new RefreshEvent(Type.SIZE));
}
public static void wallpaper() {
EventBus.getDefault().post(new RefreshEvent(Type.WALLPAPER));
}
private RefreshEvent(Type type) {
this.type = type;
}
@ -35,6 +39,6 @@ public class RefreshEvent {
}
public enum Type {
IMAGE, VIDEO, HISTORY, KEEP, SIZE
IMAGE, VIDEO, HISTORY, KEEP, SIZE, WALLPAPER
}
}

@ -3,14 +3,25 @@ package com.fongmi.android.tv.ui.activity;
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.ResUtil;
import com.fongmi.android.tv.utils.Utils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import me.jessyan.autosize.AutoSizeCompat;
public abstract class BaseActivity extends AppCompatActivity {
@ -21,7 +32,9 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getBinding().getRoot());
EventBus.getDefault().register(this);
Utils.hideSystemUI(this);
setWallpaper();
initView();
initEvent();
}
@ -36,13 +49,24 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void initEvent() {
}
protected void hackResources() {
private void setWallpaper() {
File file = FileUtil.getWallpaper(Prefers.getWallpaper());
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(Drawable.createFromPath(file.getPath()));
else getWindow().setBackgroundDrawableResource(ResUtil.getDrawable(file.getName()));
}
private void hackResources() {
try {
AutoSizeCompat.autoConvertDensityOfGlobal(super.getResources());
} catch (Exception ignored) {
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) {
if (event.getType() == RefreshEvent.Type.WALLPAPER) setWallpaper();
}
@Override
public Resources getResources() {
hackResources();

@ -15,6 +15,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.security.MessageDigest;
@ -47,6 +48,10 @@ public class FileUtil {
return getCacheFile(Utils.getMD5(fileName).concat(".jar"));
}
public static File getWallpaper(int index) {
return getCacheFile("wallpaper_" + index);
}
public static File getLocal(String path) {
if (path.contains(getRootPath())) return new File(path);
return new File(path.replace("file:/", getRootPath()));
@ -61,7 +66,7 @@ public class FileUtil {
return TextUtils.isEmpty(mimeType) ? "*/*" : mimeType;
}
public static File write(File file, byte[] data) throws Exception {
public static File write(File file, byte[] data) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.flush();

@ -21,9 +21,9 @@ public class Json {
}
}
public static String safeString(JsonObject obj, String key, String value) {
public static String safeString(JsonObject obj, String key) {
if (obj.has(key)) return obj.getAsJsonPrimitive(key).getAsString().trim();
else return value;
else return "";
}
public static List<String> safeListString(JsonObject obj, String key) {

@ -59,6 +59,14 @@ public class Prefers {
put("keep", keep);
}
public static int getWallpaper() {
return getInt("wallpaper", 1);
}
public static void putWallpaper(int wallpaper) {
put("wallpaper", wallpaper);
}
public static int getRender() {
return getInt("render", 0);
}
@ -68,7 +76,7 @@ public class Prefers {
}
public static int getQuality() {
return getInt("quality", 1);
return getInt("quality", 2);
}
public static void putQuality(int quality) {

@ -40,6 +40,10 @@ public class ResUtil {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getDisplayMetrics());
}
public static int getDrawable(String resId) {
return App.get().getResources().getIdentifier(resId, "drawable", App.get().getPackageName());
}
public static String getString(@StringRes int resId) {
return App.get().getString(resId);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@color/white"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/white"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z" />
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 KiB

@ -61,6 +61,7 @@
<!-- Setting -->
<string name="setting_vod">点播</string>
<string name="setting_live">直播</string>
<string name="setting_wallpaper">壁纸</string>
<string name="setting_render">渲染方式</string>
<string name="setting_scale">缩放比例</string>
<string name="setting_quality">图片品质</string>

@ -61,6 +61,7 @@
<!-- Setting -->
<string name="setting_vod">點播</string>
<string name="setting_live">直播</string>
<string name="setting_wallpaper">壁紙</string>
<string name="setting_render">渲染方式</string>
<string name="setting_scale">縮放比例</string>
<string name="setting_quality">圖片品質</string>

@ -61,6 +61,7 @@
<!-- Setting -->
<string name="setting_vod">Vod</string>
<string name="setting_live">Live</string>
<string name="setting_wallpaper">Wallpaper</string>
<string name="setting_render">Render type</string>
<string name="setting_scale">Scale type</string>
<string name="setting_quality">Image quality</string>

Loading…
Cancel
Save