|
|
@ -3,6 +3,7 @@ package xyz.fycz.myreader.ui.search; |
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.Intent; |
|
|
|
|
|
|
|
import android.os.Build; |
|
|
|
import android.os.Handler; |
|
|
|
import android.os.Handler; |
|
|
|
import android.os.Message; |
|
|
|
import android.os.Message; |
|
|
|
import android.text.Editable; |
|
|
|
import android.text.Editable; |
|
|
@ -49,6 +50,7 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
private String searchKey;//搜索关键字
|
|
|
|
private String searchKey;//搜索关键字
|
|
|
|
private ArrayList<SearchBookBean> mBooksBean = new ArrayList<>(); |
|
|
|
private ArrayList<SearchBookBean> mBooksBean = new ArrayList<>(); |
|
|
|
private ConcurrentMultiValueMap<SearchBookBean, Book> mBooks = new ConcurrentMultiValueMap<>(); |
|
|
|
private ConcurrentMultiValueMap<SearchBookBean, Book> mBooks = new ConcurrentMultiValueMap<>(); |
|
|
|
|
|
|
|
private ArrayList<Book> mAdapterBooks = new ArrayList<>(); |
|
|
|
private ArrayList<SearchHistory> mSearchHistories = new ArrayList<>(); |
|
|
|
private ArrayList<SearchHistory> mSearchHistories = new ArrayList<>(); |
|
|
|
private ArrayList<String> mSuggestions = new ArrayList<>(); |
|
|
|
private ArrayList<String> mSuggestions = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
@ -56,7 +58,6 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
|
|
|
|
|
|
|
|
private SearchHistoryAdapter mSearchHistoryAdapter; |
|
|
|
private SearchHistoryAdapter mSearchHistoryAdapter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int curThreadCount; |
|
|
|
private int curThreadCount; |
|
|
|
|
|
|
|
|
|
|
|
private int allThreadCount; |
|
|
|
private int allThreadCount; |
|
|
@ -102,15 +103,12 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
mSearchBookActivity.getTvTitleText().setText("搜索"); |
|
|
|
mSearchBookActivity.getTvTitleText().setText("搜索"); |
|
|
|
mSearchBookActivity.etSearchKey.requestFocus();//get the focus
|
|
|
|
mSearchBookActivity.etSearchKey.requestFocus();//get the focus
|
|
|
|
//enter事件
|
|
|
|
//enter事件
|
|
|
|
mSearchBookActivity.getEtSearchKey().setOnEditorActionListener(new TextView.OnEditorActionListener() { |
|
|
|
mSearchBookActivity.getEtSearchKey().setOnEditorActionListener((textView, i, keyEvent) -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { |
|
|
|
|
|
|
|
if (i == EditorInfo.IME_ACTION_UNSPECIFIED) { |
|
|
|
if (i == EditorInfo.IME_ACTION_UNSPECIFIED) { |
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
return (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER); |
|
|
|
return (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER); |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//换一批点击事件
|
|
|
|
//换一批点击事件
|
|
|
|
mSearchBookActivity.getRenewByImage().setOnClickListener(new RenewSuggestionBook()); |
|
|
|
mSearchBookActivity.getRenewByImage().setOnClickListener(new RenewSuggestionBook()); |
|
|
@ -142,66 +140,43 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//进入书籍详情页
|
|
|
|
//进入书籍详情页
|
|
|
|
mSearchBookActivity.getLvSearchBooksList().setOnItemClickListener(new AdapterView.OnItemClickListener() { |
|
|
|
mSearchBookActivity.getGvSearchBooksList().setOnItemClickListener((adapterView, view, i, l) -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { |
|
|
|
|
|
|
|
Intent intent = new Intent(mSearchBookActivity, BookInfoActivity.class); |
|
|
|
Intent intent = new Intent(mSearchBookActivity, BookInfoActivity.class); |
|
|
|
intent.putExtra(APPCONST.SEARCH_BOOK_BEAN, new ArrayList<>(mBooks.getValues(mBooksBean.get(i)))); |
|
|
|
intent.putExtra(APPCONST.SEARCH_BOOK_BEAN, new ArrayList<>(mBooks.getValues(mBooksBean.get(i)))); |
|
|
|
mSearchBookActivity.startActivity(intent); |
|
|
|
mSearchBookActivity.startActivity(intent); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//搜索按钮点击事件
|
|
|
|
//搜索按钮点击事件
|
|
|
|
mSearchBookActivity.getTvSearchConform().setOnClickListener(new View.OnClickListener() { |
|
|
|
mSearchBookActivity.getTvSearchConform().setOnClickListener(view -> mHandler.sendMessage(mHandler.obtainMessage(1))); |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View view) { |
|
|
|
|
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
//suggestion搜索事件
|
|
|
|
//suggestion搜索事件
|
|
|
|
mSearchBookActivity.getTgSuggestBook().setOnTagClickListener(new TagGroup.OnTagClickListener() { |
|
|
|
mSearchBookActivity.getTgSuggestBook().setOnTagClickListener(tag -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onTagClick(String tag) { |
|
|
|
|
|
|
|
mSearchBookActivity.getEtSearchKey().setText(tag); |
|
|
|
mSearchBookActivity.getEtSearchKey().setText(tag); |
|
|
|
mSearchBookActivity.getEtSearchKey().setSelection(tag.length()); |
|
|
|
mSearchBookActivity.getEtSearchKey().setSelection(tag.length()); |
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//历史记录搜索事件
|
|
|
|
//历史记录搜索事件
|
|
|
|
mSearchBookActivity.getLvHistoryList().setOnItemClickListener(new AdapterView.OnItemClickListener() { |
|
|
|
mSearchBookActivity.getLvHistoryList().setOnItemClickListener((parent, view, position, id) -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
|
|
|
mSearchBookActivity.getEtSearchKey().setText(mSearchHistories.get(position).getContent()); |
|
|
|
mSearchBookActivity.getEtSearchKey().setText(mSearchHistories.get(position).getContent()); |
|
|
|
mSearchBookActivity.getEtSearchKey().setSelection(mSearchHistories.get(position).getContent().length()); |
|
|
|
mSearchBookActivity.getEtSearchKey().setSelection(mSearchHistories.get(position).getContent().length()); |
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//清空历史记录
|
|
|
|
//清空历史记录
|
|
|
|
mSearchBookActivity.getLlClearHistory().setOnClickListener(new View.OnClickListener() { |
|
|
|
mSearchBookActivity.getLlClearHistory().setOnClickListener(v -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
mSearchHistoryService.clearHistory(); |
|
|
|
mSearchHistoryService.clearHistory(); |
|
|
|
initHistoryList(); |
|
|
|
initHistoryList(); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//清除单个历史记录
|
|
|
|
//清除单个历史记录
|
|
|
|
mSearchBookActivity.getLvHistoryList().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { |
|
|
|
mSearchBookActivity.getLvHistoryList().setOnItemLongClickListener((parent, view, position, id) -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
|
|
|
if (mSearchHistories.get(position) != null) { |
|
|
|
if (mSearchHistories.get(position) != null) { |
|
|
|
mSearchHistoryService.deleteHistory(mSearchHistories.get(position)); |
|
|
|
mSearchHistoryService.deleteHistory(mSearchHistories.get(position)); |
|
|
|
initHistoryList(); |
|
|
|
initHistoryList(); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
//上拉刷新
|
|
|
|
//上拉刷新
|
|
|
|
mSearchBookActivity.getSrlSearchBookList().setOnRefreshListener(new OnRefreshListener() { |
|
|
|
mSearchBookActivity.getSrlSearchBookList().setOnRefreshListener(refreshLayout -> mHandler.sendMessage(mHandler.obtainMessage(1))); |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onRefresh(@NonNull RefreshLayout refreshLayout) { |
|
|
|
|
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(false); |
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(false); |
|
|
|
|
|
|
|
mSearchBookActivity.getGvSearchBooksList().setNumColumns(1); |
|
|
|
|
|
|
|
mSearchBookActivity.getGvSearchBooksList().setDragModel(-1); |
|
|
|
initSuggestionBook(); |
|
|
|
initSuggestionBook(); |
|
|
|
initHistoryList(); |
|
|
|
initHistoryList(); |
|
|
|
} |
|
|
|
} |
|
|
@ -247,8 +222,8 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
initmBooksBean(); |
|
|
|
initmBooksBean(); |
|
|
|
mSearchBookAdapter = new SearchBookAdapter(mSearchBookActivity, |
|
|
|
mSearchBookAdapter = new SearchBookAdapter(mSearchBookActivity, |
|
|
|
R.layout.listview_search_book_item, mBooksBean, mBooks); |
|
|
|
R.layout.listview_search_book_item, mBooksBean, mBooks); |
|
|
|
mSearchBookActivity.getLvSearchBooksList().setAdapter(mSearchBookAdapter); |
|
|
|
mSearchBookActivity.getGvSearchBooksList().setAdapter(mSearchBookAdapter); |
|
|
|
mSearchBookActivity.getLvSearchBooksList().setVisibility(View.VISIBLE); |
|
|
|
mSearchBookActivity.getGvSearchBooksList().setVisibility(View.VISIBLE); |
|
|
|
mSearchBookActivity.getLlSuggestBooksView().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlSuggestBooksView().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlHistoryView().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlHistoryView().setVisibility(View.GONE); |
|
|
|
} |
|
|
|
} |
|
|
@ -272,9 +247,7 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
mBooksBean.addAll(mBooks.keySet()); |
|
|
|
mBooksBean.addAll(mBooks.keySet()); |
|
|
|
//排序,基于最符合关键字的搜书结果应该是最短的
|
|
|
|
//排序,基于最符合关键字的搜书结果应该是最短的
|
|
|
|
//TODO ;这里只做了简单的比较排序,还需要继续完善
|
|
|
|
//TODO ;这里只做了简单的比较排序,还需要继续完善
|
|
|
|
Collections.sort(mBooksBean, new Comparator<SearchBookBean>() { |
|
|
|
Collections.sort(mBooksBean, (o1, o2) -> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public int compare(SearchBookBean o1, SearchBookBean o2) { |
|
|
|
|
|
|
|
if (searchKey.equals(o1.getName())) |
|
|
|
if (searchKey.equals(o1.getName())) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
if (searchKey.equals(o2.getName())) |
|
|
|
if (searchKey.equals(o2.getName())) |
|
|
@ -288,7 +261,6 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
if (o1.getName().length() == o2.getName().length()) |
|
|
|
if (o1.getName().length() == o2.getName().length()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
/*MyApplication.runOnUiThread(new Runnable() { |
|
|
|
/*MyApplication.runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -320,17 +292,25 @@ public class SearchBookPrensenter implements BasePresenter { |
|
|
|
mSearchBookActivity.getPbLoading().setVisibility(View.VISIBLE); |
|
|
|
mSearchBookActivity.getPbLoading().setVisibility(View.VISIBLE); |
|
|
|
if (StringHelper.isEmpty(searchKey)) { |
|
|
|
if (StringHelper.isEmpty(searchKey)) { |
|
|
|
mSearchBookActivity.getPbLoading().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getPbLoading().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLvSearchBooksList().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getGvSearchBooksList().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlSuggestBooksView().setVisibility(View.VISIBLE); |
|
|
|
mSearchBookActivity.getLlSuggestBooksView().setVisibility(View.VISIBLE); |
|
|
|
initHistoryList(); |
|
|
|
initHistoryList(); |
|
|
|
mSearchBookActivity.getLvSearchBooksList().setAdapter(null); |
|
|
|
mSearchBookActivity.getGvSearchBooksList().setAdapter(null); |
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(false); |
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(false); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mSearchBookActivity.getLvSearchBooksList().setVisibility(View.VISIBLE); |
|
|
|
mSearchBookActivity.getGvSearchBooksList().setVisibility(View.VISIBLE); |
|
|
|
mSearchBookActivity.getLlSuggestBooksView().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlSuggestBooksView().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlHistoryView().setVisibility(View.GONE); |
|
|
|
mSearchBookActivity.getLlHistoryView().setVisibility(View.GONE); |
|
|
|
getData(); |
|
|
|
getData(); |
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
|
|
|
|
|
if (mSearchBookActivity.getGvSearchBooksList().getmScrollView().getScrollY() == 0){ |
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(true); |
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//滑动监听器
|
|
|
|
|
|
|
|
mSearchBookActivity.getGvSearchBooksList().getmScrollView().setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> { |
|
|
|
|
|
|
|
mSearchBookActivity.getSrlSearchBookList().setEnableRefresh(scrollY == 0); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
mSearchHistoryService.addOrUpadteHistory(searchKey); |
|
|
|
mSearchHistoryService.addOrUpadteHistory(searchKey); |
|
|
|
//收起软键盘
|
|
|
|
//收起软键盘
|
|
|
|
InputMethodManager imm = (InputMethodManager) MyApplication.getmContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
|
|
|
InputMethodManager imm = (InputMethodManager) MyApplication.getmContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
|
|
|