parent
7145ca6631
commit
2dc7e5d2e2
@ -0,0 +1,515 @@ |
||||
package com.github.tvbox.osc.ui.activity; |
||||
|
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
import android.text.TextUtils; |
||||
import android.view.View; |
||||
import android.widget.EditText; |
||||
import android.widget.ImageView; |
||||
import android.widget.LinearLayout; |
||||
import android.widget.TextView; |
||||
import android.widget.Toast; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.lifecycle.ViewModelProvider; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter; |
||||
import com.github.tvbox.osc.R; |
||||
import com.github.tvbox.osc.api.ApiConfig; |
||||
import com.github.tvbox.osc.base.BaseActivity; |
||||
import com.github.tvbox.osc.bean.AbsXml; |
||||
import com.github.tvbox.osc.bean.Movie; |
||||
import com.github.tvbox.osc.bean.SourceBean; |
||||
import com.github.tvbox.osc.event.RefreshEvent; |
||||
import com.github.tvbox.osc.event.ServerEvent; |
||||
import com.github.tvbox.osc.server.ControlManager; |
||||
import com.github.tvbox.osc.ui.adapter.FastListAdapter; |
||||
import com.github.tvbox.osc.ui.adapter.FastSearchAdapter; |
||||
//import com.github.tvbox.osc.ui.adapter.SearchAdapter;
|
||||
import com.github.tvbox.osc.ui.adapter.SearchWordAdapter; |
||||
import com.github.tvbox.osc.ui.dialog.RemoteDialog; |
||||
import com.github.tvbox.osc.ui.tv.QRCodeGen; |
||||
import com.github.tvbox.osc.ui.tv.widget.SearchKeyboard; |
||||
import com.github.tvbox.osc.util.FastClickCheckUtil; |
||||
import com.github.tvbox.osc.util.HawkConfig; |
||||
import com.github.tvbox.osc.viewmodel.SourceViewModel; |
||||
import com.google.gson.Gson; |
||||
import com.google.gson.JsonArray; |
||||
import com.google.gson.JsonElement; |
||||
import com.google.gson.JsonObject; |
||||
import com.google.gson.JsonParser; |
||||
import com.lzy.okgo.OkGo; |
||||
import com.lzy.okgo.callback.AbsCallback; |
||||
import com.lzy.okgo.model.Response; |
||||
import com.orhanobut.hawk.Hawk; |
||||
import com.owen.tvrecyclerview.widget.TvRecyclerView; |
||||
import com.owen.tvrecyclerview.widget.V7GridLayoutManager; |
||||
import com.owen.tvrecyclerview.widget.V7LinearLayoutManager; |
||||
|
||||
import org.greenrobot.eventbus.EventBus; |
||||
import org.greenrobot.eventbus.Subscribe; |
||||
import org.greenrobot.eventbus.ThreadMode; |
||||
|
||||
import java.net.URLEncoder; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.concurrent.ExecutorService; |
||||
import java.util.concurrent.Executors; |
||||
import java.util.concurrent.atomic.AtomicInteger; |
||||
|
||||
/** |
||||
* @author pj567 |
||||
* @date :2020/12/23 |
||||
* @description: |
||||
*/ |
||||
public class FastSearchActivity extends BaseActivity { |
||||
private LinearLayout llLayout; |
||||
private TextView mSearchTitle; |
||||
private TvRecyclerView mGridView; |
||||
private TvRecyclerView mGridViewFilter; |
||||
private TvRecyclerView mGridViewWord; |
||||
private TvRecyclerView mGridViewWordFenci; |
||||
SourceViewModel sourceViewModel; |
||||
// private EditText etSearch;
|
||||
// private TextView tvSearch;
|
||||
// private TextView tvClear;
|
||||
// private SearchKeyboard keyboard;
|
||||
// private TextView tvAddress;
|
||||
// private ImageView ivQRCode;
|
||||
private SearchWordAdapter searchWordAdapter; |
||||
private FastSearchAdapter searchAdapter; |
||||
private FastSearchAdapter searchAdapterFilter; |
||||
private FastListAdapter spListAdapter; |
||||
private String searchTitle = ""; |
||||
private HashMap<String, String> spNames; |
||||
private boolean isFilterMode = false; |
||||
private String searchFilterKey = ""; // 过滤的key
|
||||
private HashMap<String, ArrayList<Movie.Video> > resultVods; // 搜索结果
|
||||
private int finishedCount=0; |
||||
private List<String> quickSearchWord = new ArrayList<>(); |
||||
|
||||
private View.OnFocusChangeListener focusChangeListener = new View.OnFocusChangeListener() { |
||||
@Override |
||||
public void onFocusChange(View itemView, boolean hasFocus) { |
||||
try { |
||||
if(!hasFocus){ |
||||
spListAdapter.onLostFocus(itemView); |
||||
}else{ |
||||
int ret = spListAdapter.onSetFocus(itemView); |
||||
if(ret < 0) return; |
||||
TextView v = (TextView) itemView; |
||||
String sb = v.getText().toString(); |
||||
filterResult(sb); |
||||
} |
||||
}catch (Exception e){ |
||||
Toast.makeText(FastSearchActivity.this,e.toString(), Toast.LENGTH_SHORT).show(); |
||||
} |
||||
|
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
protected int getLayoutResID() { |
||||
return R.layout.activity_fast_search; |
||||
} |
||||
|
||||
@Override |
||||
protected void init() { |
||||
spNames = new HashMap<String, String>(); |
||||
resultVods = new HashMap<String, ArrayList<Movie.Video> >(); |
||||
initView(); |
||||
initViewModel(); |
||||
initData(); |
||||
} |
||||
|
||||
private List<Runnable> pauseRunnable = null; |
||||
|
||||
@Override |
||||
protected void onResume() { |
||||
super.onResume(); |
||||
if (pauseRunnable != null && pauseRunnable.size() > 0) { |
||||
searchExecutorService = Executors.newFixedThreadPool(5); |
||||
allRunCount.set(pauseRunnable.size()); |
||||
for (Runnable runnable : pauseRunnable) { |
||||
searchExecutorService.execute(runnable); |
||||
} |
||||
pauseRunnable.clear(); |
||||
pauseRunnable = null; |
||||
} |
||||
} |
||||
|
||||
private void initView() { |
||||
EventBus.getDefault().register(this); |
||||
llLayout = findViewById(R.id.llLayout); |
||||
mSearchTitle = findViewById(R.id.mSearchTitle); |
||||
mGridView = findViewById(R.id.mGridView); |
||||
mGridViewWord = findViewById(R.id.mGridViewWord); |
||||
mGridViewFilter = findViewById(R.id.mGridViewFilter); |
||||
|
||||
mGridViewWord.setHasFixedSize(true); |
||||
mGridViewWord.setLayoutManager(new V7LinearLayoutManager(this.mContext, 1, false)); |
||||
spListAdapter = new FastListAdapter(); |
||||
mGridViewWord.setAdapter(spListAdapter); |
||||
|
||||
|
||||
// mGridViewWord.setFocusable(true);
|
||||
// mGridViewWord.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
// @Override
|
||||
// public void onFocusChange(View itemView, boolean hasFocus) {}
|
||||
// });
|
||||
|
||||
mGridViewWord.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { |
||||
@Override |
||||
public void onChildViewAttachedToWindow(@NonNull View child) { |
||||
child.setFocusable(true); |
||||
child.setOnFocusChangeListener(focusChangeListener); |
||||
TextView t = (TextView)child; |
||||
if(t.getText() == "全部显示"){ |
||||
t.requestFocus(); |
||||
} |
||||
// if (child.isFocusable() && null == child.getOnFocusChangeListener()) {
|
||||
// child.setOnFocusChangeListener(focusChangeListener);
|
||||
// }
|
||||
} |
||||
|
||||
@Override |
||||
public void onChildViewDetachedFromWindow(@NonNull View view) { |
||||
view.setOnFocusChangeListener(null); |
||||
} |
||||
}); |
||||
|
||||
spListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { |
||||
@Override |
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { |
||||
String spName = spListAdapter.getItem(position); |
||||
filterResult(spName); |
||||
} |
||||
}); |
||||
|
||||
mGridView.setHasFixedSize(true); |
||||
mGridView.setLayoutManager(new V7GridLayoutManager(this.mContext, 5)); |
||||
|
||||
searchAdapter = new FastSearchAdapter(); |
||||
mGridView.setAdapter(searchAdapter); |
||||
|
||||
searchAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { |
||||
@Override |
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { |
||||
FastClickCheckUtil.check(view); |
||||
Movie.Video video = searchAdapter.getData().get(position); |
||||
if (video != null) { |
||||
try { |
||||
if (searchExecutorService != null) { |
||||
pauseRunnable = searchExecutorService.shutdownNow(); |
||||
searchExecutorService = null; |
||||
} |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} |
||||
Bundle bundle = new Bundle(); |
||||
bundle.putString("id", video.id); |
||||
bundle.putString("sourceKey", video.sourceKey); |
||||
jumpActivity(DetailActivity.class, bundle); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
|
||||
mGridViewFilter.setLayoutManager(new V7GridLayoutManager(this.mContext, 5)); |
||||
searchAdapterFilter = new FastSearchAdapter(); |
||||
mGridViewFilter.setAdapter(searchAdapterFilter); |
||||
searchAdapterFilter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { |
||||
@Override |
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { |
||||
FastClickCheckUtil.check(view); |
||||
Movie.Video video = searchAdapterFilter.getData().get(position); |
||||
if (video != null) { |
||||
try { |
||||
if (searchExecutorService != null) { |
||||
pauseRunnable = searchExecutorService.shutdownNow(); |
||||
searchExecutorService = null; |
||||
} |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} |
||||
Bundle bundle = new Bundle(); |
||||
bundle.putString("id", video.id); |
||||
bundle.putString("sourceKey", video.sourceKey); |
||||
jumpActivity(DetailActivity.class, bundle); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
setLoadSir(llLayout); |
||||
|
||||
// 分词
|
||||
searchWordAdapter = new SearchWordAdapter(); |
||||
mGridViewWordFenci = findViewById(R.id.mGridViewWordFenci); |
||||
mGridViewWordFenci.setAdapter(searchWordAdapter); |
||||
mGridViewWordFenci.setLayoutManager(new V7LinearLayoutManager(this.mContext, 0, false)); |
||||
searchWordAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { |
||||
@Override |
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { |
||||
String str = searchWordAdapter.getData().get(position); |
||||
search(str); |
||||
} |
||||
}); |
||||
searchWordAdapter.setNewData(new ArrayList<>()); |
||||
} |
||||
|
||||
private void initViewModel() { |
||||
sourceViewModel = new ViewModelProvider(this).get(SourceViewModel.class); |
||||
} |
||||
private void filterResult(String spName){ |
||||
if(spName == "全部显示"){ |
||||
mGridView.setVisibility(View.VISIBLE); |
||||
mGridViewFilter.setVisibility(View.GONE); |
||||
return; |
||||
} |
||||
String key = spNames.get(spName); |
||||
if(key.isEmpty()) return; |
||||
|
||||
if(searchFilterKey == key) return; |
||||
searchFilterKey = key; |
||||
|
||||
List<Movie.Video> list = resultVods.get(key); |
||||
searchAdapterFilter.setNewData(list); |
||||
mGridView.setVisibility(View.GONE); |
||||
mGridViewFilter.setVisibility(View.VISIBLE); |
||||
} |
||||
|
||||
private void fenci(){ |
||||
if(!quickSearchWord.isEmpty()) return; // 如果经有分词了,不再进行二次分词
|
||||
// 分词
|
||||
OkGo.<String>get("http://api.pullword.com/get.php?source=" + URLEncoder.encode(searchTitle) + "¶m1=0¶m2=0&json=1") |
||||
.tag("fenci") |
||||
.execute(new AbsCallback<String>() { |
||||
@Override |
||||
public String convertResponse(okhttp3.Response response) throws Throwable { |
||||
if (response.body() != null) { |
||||
return response.body().string(); |
||||
} else { |
||||
throw new IllegalStateException("网络请求错误"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onSuccess(Response<String> response) { |
||||
String json = response.body(); |
||||
quickSearchWord.clear(); |
||||
try { |
||||
for (JsonElement je : new Gson().fromJson(json, JsonArray.class)) { |
||||
quickSearchWord.add(je.getAsJsonObject().get("t").getAsString()); |
||||
} |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} |
||||
quickSearchWord.add(searchTitle); |
||||
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_WORD, quickSearchWord)); |
||||
} |
||||
|
||||
@Override |
||||
public void onError(Response<String> response) { |
||||
super.onError(response); |
||||
} |
||||
}); |
||||
} |
||||
private void initData() { |
||||
Intent intent = getIntent(); |
||||
if (intent != null && intent.hasExtra("title")) { |
||||
String title = intent.getStringExtra("title"); |
||||
showLoading(); |
||||
search(title); |
||||
} |
||||
} |
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN) |
||||
public void server(ServerEvent event) { |
||||
if (event.type == ServerEvent.SERVER_SEARCH) { |
||||
String title = (String) event.obj; |
||||
showLoading(); |
||||
search(title); |
||||
} |
||||
} |
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN) |
||||
public void refresh(RefreshEvent event) { |
||||
if(mSearchTitle != null){ |
||||
mSearchTitle.setText(String.format("搜索(%d/%d)", finishedCount, spNames.size())); |
||||
} |
||||
if (event.type == RefreshEvent.TYPE_SEARCH_RESULT) { |
||||
try { |
||||
searchData(event.obj == null ? null : (AbsXml) event.obj); |
||||
} catch (Exception e) { |
||||
searchData(null); |
||||
} |
||||
} |
||||
else if(event.type == RefreshEvent.TYPE_QUICK_SEARCH_WORD){ |
||||
if (event.obj != null) { |
||||
List<String> data = (List<String>) event.obj; |
||||
searchWordAdapter.setNewData(data); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void search(String title) { |
||||
cancel(); |
||||
showLoading(); |
||||
this.searchTitle = title; |
||||
fenci(); |
||||
mGridView.setVisibility(View.INVISIBLE); |
||||
mGridViewFilter.setVisibility(View.GONE); |
||||
searchAdapter.setNewData(new ArrayList<>()); |
||||
searchAdapterFilter.setNewData(new ArrayList<>()); |
||||
|
||||
spListAdapter.reset(); |
||||
resultVods.clear(); |
||||
searchFilterKey = ""; |
||||
isFilterMode = false; |
||||
spNames.clear(); |
||||
finishedCount=0; |
||||
|
||||
searchResult(); |
||||
} |
||||
|
||||
private ExecutorService searchExecutorService = null; |
||||
private AtomicInteger allRunCount = new AtomicInteger(0); |
||||
|
||||
private void searchResult() { |
||||
try { |
||||
if (searchExecutorService != null) { |
||||
searchExecutorService.shutdownNow(); |
||||
searchExecutorService = null; |
||||
} |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} finally { |
||||
searchAdapter.setNewData(new ArrayList<>()); |
||||
searchAdapterFilter.setNewData(new ArrayList<>()); |
||||
allRunCount.set(0); |
||||
} |
||||
searchExecutorService = Executors.newFixedThreadPool(5); |
||||
List<SourceBean> searchRequestList = new ArrayList<>(); |
||||
searchRequestList.addAll(ApiConfig.get().getSourceBeanList()); |
||||
SourceBean home = ApiConfig.get().getHomeSourceBean(); |
||||
searchRequestList.remove(home); |
||||
searchRequestList.add(0, home); |
||||
|
||||
|
||||
ArrayList<String> siteKey = new ArrayList<>(); |
||||
ArrayList<String> hots = new ArrayList<>(); |
||||
|
||||
spListAdapter.setNewData(hots); |
||||
spListAdapter.addData("全部显示"); |
||||
for (SourceBean bean : searchRequestList) { |
||||
if (!bean.isSearchable()) { |
||||
continue; |
||||
} |
||||
siteKey.add(bean.getKey()); |
||||
this.spNames.put(bean.getName(), bean.getKey()); |
||||
allRunCount.incrementAndGet(); |
||||
} |
||||
updateSearchResultCount(0); |
||||
|
||||
for (String key : siteKey) { |
||||
searchExecutorService.execute(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
try { |
||||
sourceViewModel.getSearch(key, searchTitle); |
||||
}catch (Exception e){ |
||||
|
||||
} |
||||
|
||||
updateSearchResultCount(1); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
synchronized private void updateSearchResultCount(int n){ |
||||
finishedCount +=n; |
||||
if(finishedCount > spNames.size()) finishedCount = spNames.size(); |
||||
|
||||
} |
||||
// 向过滤栏添加有结果的spname
|
||||
private String addWordAdapterIfNeed(String key){ |
||||
try { |
||||
String name = ""; |
||||
for (String n : spNames.keySet() ){ |
||||
if(spNames.get(n) == key){ |
||||
name = n; |
||||
} |
||||
} |
||||
if(name == "") return key; |
||||
|
||||
List<String> names = spListAdapter.getData(); |
||||
for (int i =0 ; i < names.size(); ++i){ |
||||
if(name == names.get(i)){ |
||||
return key; |
||||
} |
||||
} |
||||
|
||||
spListAdapter.addData(name); |
||||
return key; |
||||
}catch (Exception e){ |
||||
return key; |
||||
} |
||||
} |
||||
private void searchData(AbsXml absXml) { |
||||
String lastSourceKey = ""; |
||||
|
||||
if (absXml != null && absXml.movie != null && absXml.movie.videoList != null && absXml.movie.videoList.size() > 0) { |
||||
List<Movie.Video> data = new ArrayList<>(); |
||||
for (Movie.Video video : absXml.movie.videoList) { |
||||
if (video.name.contains(searchTitle)) { |
||||
data.add(video); |
||||
if(!resultVods.containsKey(video.sourceKey)){ |
||||
resultVods.put(video.sourceKey, new ArrayList<Movie.Video>()); |
||||
} |
||||
resultVods.get(video.sourceKey).add(video); |
||||
if(video.sourceKey != lastSourceKey){ |
||||
lastSourceKey = this.addWordAdapterIfNeed(video.sourceKey); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (searchAdapter.getData().size() > 0) { |
||||
searchAdapter.addData(data); |
||||
} else { |
||||
showSuccess(); |
||||
if(!isFilterMode) |
||||
mGridView.setVisibility(View.VISIBLE); |
||||
searchAdapter.setNewData(data); |
||||
} |
||||
} |
||||
|
||||
int count = allRunCount.decrementAndGet(); |
||||
if (count <= 0) { |
||||
if (searchAdapter.getData().size() <= 0) { |
||||
showEmpty(); |
||||
} |
||||
cancel(); |
||||
} |
||||
} |
||||
|
||||
private void cancel() { |
||||
OkGo.getInstance().cancelTag("search"); |
||||
} |
||||
|
||||
@Override |
||||
protected void onDestroy() { |
||||
super.onDestroy(); |
||||
cancel(); |
||||
try { |
||||
if (searchExecutorService != null) { |
||||
searchExecutorService.shutdownNow(); |
||||
searchExecutorService = null; |
||||
} |
||||
} catch (Throwable th) { |
||||
th.printStackTrace(); |
||||
} |
||||
EventBus.getDefault().unregister(this); |
||||
} |
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
package com.github.tvbox.osc.ui.adapter; |
||||
|
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
import android.view.ViewParent; |
||||
import android.widget.TextView; |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter; |
||||
import com.chad.library.adapter.base.BaseViewHolder; |
||||
import com.github.tvbox.osc.R; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
|
||||
public class FastListAdapter extends BaseQuickAdapter<String, BaseViewHolder> { |
||||
public FastListAdapter() { |
||||
super(R.layout.item_search_word_hot, new ArrayList<>()); |
||||
} |
||||
|
||||
@Override |
||||
protected void convert(BaseViewHolder helper, String item) { |
||||
helper.setText(R.id.tvSearchWord, item); |
||||
} |
||||
|
||||
|
||||
// 记录失去焦点的控件
|
||||
public void onLostFocus(View child) { |
||||
if(lostFocusTimestamp==0) { |
||||
lostFocusTimestamp = System.currentTimeMillis(); |
||||
} |
||||
} |
||||
|
||||
// 记录获得焦点的控件
|
||||
public int onSetFocus(View child){ |
||||
// 可以调整间隔还判断到底是不是整个view失去了焦点
|
||||
if(System.currentTimeMillis() - lostFocusTimestamp > 200) { |
||||
setp = 0; |
||||
} |
||||
int index=((ViewGroup)child.getParent()).indexOfChild(child); |
||||
if(focusView != null){ |
||||
int index2=((ViewGroup)focusView.getParent()).indexOfChild(focusView); |
||||
if(Math.abs(index-index2) > setp) { // 跳了控件,将焦点恢复到之前的控件上去
|
||||
setp = 0; |
||||
int offset = (index > index2? -1 :1); |
||||
ViewGroup parent = ((ViewGroup)focusView.getParent()); |
||||
parent.getChildAt(index+offset).requestFocus(); |
||||
return -1; |
||||
} |
||||
} |
||||
lostFocusTimestamp =0; |
||||
focusView = child; |
||||
setp =1; |
||||
return 1; |
||||
} |
||||
|
||||
public void reset(){ |
||||
lostFocusTimestamp =0; |
||||
setp =0; |
||||
focusView = null; |
||||
} |
||||
|
||||
public long lostFocusTimestamp=0; // 控件失去焦点的时间
|
||||
public int setp =0; //步长
|
||||
View focusView; // 当前获得焦点的控件
|
||||
} |
||||
@ -0,0 +1,52 @@ |
||||
package com.github.tvbox.osc.ui.adapter; |
||||
|
||||
import android.text.TextUtils; |
||||
import android.widget.ImageView; |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter; |
||||
import com.chad.library.adapter.base.BaseViewHolder; |
||||
import com.github.tvbox.osc.R; |
||||
import com.github.tvbox.osc.api.ApiConfig; |
||||
import com.github.tvbox.osc.bean.Movie; |
||||
import com.github.tvbox.osc.picasso.RoundTransformation; |
||||
import com.github.tvbox.osc.util.HawkConfig; |
||||
import com.github.tvbox.osc.util.MD5; |
||||
import com.orhanobut.hawk.Hawk; |
||||
import com.squareup.picasso.Picasso; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils; |
||||
|
||||
public class FastSearchAdapter extends BaseQuickAdapter<Movie.Video, BaseViewHolder> { |
||||
public FastSearchAdapter() { |
||||
super(R.layout.item_search, new ArrayList<>()); |
||||
} |
||||
|
||||
@Override |
||||
protected void convert(BaseViewHolder helper, Movie.Video item) { |
||||
|
||||
// with preview
|
||||
helper.setText(R.id.tvName, item.name); |
||||
helper.setText(R.id.tvSite, ApiConfig.get().getSource(item.sourceKey).getName()); |
||||
helper.setVisible(R.id.tvNote, item.note != null && !item.note.isEmpty()); |
||||
if (item.note != null && !item.note.isEmpty()) { |
||||
helper.setText(R.id.tvNote, item.note); |
||||
} |
||||
ImageView ivThumb = helper.getView(R.id.ivThumb); |
||||
if (!TextUtils.isEmpty(item.pic)) { |
||||
Picasso.get() |
||||
.load(item.pic) |
||||
.transform(new RoundTransformation(MD5.string2MD5(item.pic + "position=" + helper.getLayoutPosition())) |
||||
.centerCorp(true) |
||||
.override(AutoSizeUtils.mm2px(mContext, 300), AutoSizeUtils.mm2px(mContext, 400)) |
||||
.roundRadius(AutoSizeUtils.mm2px(mContext, 10), RoundTransformation.RoundType.ALL)) |
||||
.placeholder(R.drawable.img_loading_placeholder) |
||||
.error(R.drawable.img_loading_placeholder) |
||||
.into(ivThumb); |
||||
} else { |
||||
ivThumb.setImageResource(R.drawable.img_loading_placeholder); |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,100 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="@dimen/vs_50" |
||||
android:layout_marginTop="@dimen/vs_10" |
||||
android:layout_marginBottom="@dimen/vs_10" |
||||
android:paddingLeft="20mm" |
||||
> |
||||
|
||||
<TextView |
||||
android:id="@+id/mSearchTitle" |
||||
android:layout_width="@dimen/vs_180" |
||||
android:layout_height="match_parent" |
||||
android:text="搜索(0/0)" |
||||
android:layout_gravity="center_horizontal" |
||||
android:textAlignment="center" |
||||
android:textColor="@android:color/white" |
||||
android:paddingTop="@dimen/vs_10" |
||||
android:textSize="@dimen/ts_22" /> |
||||
|
||||
<com.owen.tvrecyclerview.widget.TvRecyclerView |
||||
android:id="@+id/mGridViewWordFenci" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="@dimen/vs_50" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
app:tv_horizontalSpacingWithMargins="@dimen/vs_5" |
||||
app:tv_selectedItemIsCentered="true" |
||||
app:tv_verticalSpacingWithMargins="@dimen/vs_5" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="horizontal"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/llWord" |
||||
android:layout_width="@dimen/vs_180" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" |
||||
android:paddingLeft="20mm" |
||||
android:paddingBottom="@dimen/vs_20"> |
||||
|
||||
<com.owen.tvrecyclerview.widget.TvRecyclerView |
||||
android:id="@+id/mGridViewWord" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:focusable="true" |
||||
app:tv_horizontalSpacingWithMargins="@dimen/vs_5" |
||||
app:tv_selectedItemIsCentered="true" |
||||
app:tv_verticalSpacingWithMargins="@dimen/vs_5" /> |
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/llLayout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" |
||||
android:paddingLeft="20mm" |
||||
android:paddingBottom="@dimen/vs_20" |
||||
android:paddingRight="20mm" > |
||||
|
||||
|
||||
<com.owen.tvrecyclerview.widget.TvRecyclerView |
||||
android:id="@+id/mGridView" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:visibility="invisible" |
||||
app:tv_horizontalSpacingWithMargins="@dimen/vs_5" |
||||
app:tv_selectedItemIsCentered="true" |
||||
app:tv_verticalSpacingWithMargins="@dimen/vs_5" /> |
||||
|
||||
<com.owen.tvrecyclerview.widget.TvRecyclerView |
||||
android:id="@+id/mGridViewFilter" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipChildren="false" |
||||
android:clipToPadding="false" |
||||
android:visibility="invisible" |
||||
app:tv_horizontalSpacingWithMargins="@dimen/vs_5" |
||||
app:tv_selectedItemIsCentered="true" |
||||
app:tv_verticalSpacingWithMargins="@dimen/vs_5" /> |
||||
|
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
Loading…
Reference in new issue