[leanback] clean code

pull/123/head
FongMi 3 years ago
parent db73ccaa44
commit 36d3151b5f
  1. 13
      app/src/leanback/java/com/fongmi/android/tv/ui/fragment/VodFragment.java
  2. 44
      app/src/main/java/com/fongmi/android/tv/bean/Config.java

@ -16,6 +16,7 @@ import androidx.leanback.widget.ListRow;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.App;
import com.fongmi.android.tv.Product;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.bean.Filter;
@ -136,12 +137,13 @@ public class VodFragment extends BaseFragment implements CustomScroller.Callback
}
private void getVideo(String typeId, String page) {
if (page.equals("1")) mLast = null;
if (page.equals("1")) showProgress();
boolean first = page.equals("1");
if (first) mLast = null;
if (first) showProgress();
if (isFolder()) mTypeIds.add(typeId);
if (isFolder() && !mOpen) mBinding.recycler.moveToTop();
int filterSize = mOpen ? mFilters.size() : 0;
boolean clear = page.equals("1") && mAdapter.size() > filterSize;
boolean clear = first && mAdapter.size() > filterSize;
if (clear) mAdapter.removeItems(filterSize, mAdapter.size() - filterSize);
mViewModel.categoryContent(getKey(), typeId, page, true, mExtends);
}
@ -176,7 +178,7 @@ public class VodFragment extends BaseFragment implements CustomScroller.Callback
}
private void showProgress() {
mBinding.progress.getRoot().setVisibility(View.VISIBLE);
if (!mOpen) mBinding.progress.getRoot().setVisibility(View.VISIBLE);
}
private void hideProgress() {
@ -186,8 +188,9 @@ public class VodFragment extends BaseFragment implements CustomScroller.Callback
private void showFilter() {
List<ListRow> rows = new ArrayList<>();
for (Filter filter : mFilters) rows.add(getRow(filter));
App.post(() -> mBinding.recycler.smoothScrollToPosition(0), 48);
mAdapter.addAll(0, rows);
mBinding.recycler.postDelayed(() -> mBinding.recycler.smoothScrollToPosition(0), 50);
hideProgress();
}
private void hideFilter() {

@ -3,7 +3,6 @@ package com.fongmi.android.tv.bean;
import android.text.TextUtils;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;
@ -24,29 +23,20 @@ public class Config {
private String home;
private String parse;
public static Config create(int type) {
return new Config(type);
}
public static Config create(String url, int type) {
return new Config(url, "", type);
public Config() {
this.id = -1;
}
public static Config create(String url, String name, int type) {
return new Config(url, name, type);
public static Config create(int type) {
return new Config().type(type);
}
@Ignore
public Config(int type) {
this.type = type;
this.id = -1;
public static Config create(int type, String url) {
return new Config().type(type).url(url).insert();
}
public Config(String url, String name, int type) {
this.url = url;
this.name = name;
this.type = type;
this.id = (int) insert();
public static Config create(int type, String url, String name) {
return new Config().type(type).url(url).name(name).insert();
}
public int getId() {
@ -118,6 +108,11 @@ public class Config {
return this;
}
public Config url(String url) {
setUrl(url);
return this;
}
public Config name(String name) {
setName(name);
return this;
@ -177,26 +172,27 @@ public class Config {
public static Config find(String url, int type) {
Config item = AppDatabase.get().getConfigDao().find(url, type);
return item == null ? create(url, type) : item.type(type);
return item == null ? create(type, url) : item.type(type);
}
public static Config find(String url, String name, int type) {
Config item = AppDatabase.get().getConfigDao().find(url, type);
return item == null ? create(url, name, type) : item.type(type).name(name);
return item == null ? create(type, url, name) : item.type(type).name(name);
}
public static Config find(Config config, int type) {
Config item = AppDatabase.get().getConfigDao().find(config.getUrl(), type);
return item == null ? create(config.getUrl(), config.getName(), type) : item.type(type).name(config.getName());
return item == null ? create(type, config.getUrl(), config.getName()) : item.type(type).name(config.getName());
}
public static Config find(Depot depot, int type) {
Config item = AppDatabase.get().getConfigDao().find(depot.getUrl(), type);
return item == null ? create(depot.getUrl(), depot.getName(), type) : item.type(type).name(depot.getName());
return item == null ? create(type, depot.getUrl(), depot.getName()) : item.type(type).name(depot.getName());
}
public long insert() {
return getUrl().isEmpty() ? -1 : AppDatabase.get().getConfigDao().insert(this);
public Config insert() {
setId(TextUtils.isEmpty(url) ? -1 : Math.toIntExact(AppDatabase.get().getConfigDao().insert(this)));
return this;
}
public Config update() {

Loading…
Cancel
Save