|
|
@@ -1,19 +1,36 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.support.v7.widget.AppCompatAutoCompleteTextView;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.view.inputmethod.EditorInfo;
|
|
|
+import android.widget.AdapterView;
|
|
|
import android.widget.GridView;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.SearchGameRecord;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.MyDbManager;
|
|
|
+import com.sheep.gamegroup.util.ViewHolder;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
import com.sheep.gamegroup.view.adapter.ArrayAdapter;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
@@ -38,48 +55,177 @@ public class ActSearchGame extends BaseActivity {
|
|
|
TextView search_game_bt;
|
|
|
@BindView(R.id.search_game_hot_list)
|
|
|
GridView search_game_hot_list;
|
|
|
+ @BindView(R.id.search_game_list)
|
|
|
+ RecyclerView search_game_list;
|
|
|
+ @BindView(R.id.search_game_hot)
|
|
|
+ View search_game_hot;
|
|
|
+ @BindView(R.id.download_mgr_empty_view)
|
|
|
+ View download_mgr_empty_view;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.act_search_game;
|
|
|
}
|
|
|
+
|
|
|
private ActSearchGame activity;
|
|
|
- private ArrayAdapter<TaskReleaseEty> hotAdapter;
|
|
|
+
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
activity = this;
|
|
|
TitleBarUtils.getInstance()
|
|
|
.setTitle(this, "搜索游戏")
|
|
|
.setTitleFinish(this);
|
|
|
- hotAdapter = new ArrayAdapter<TaskReleaseEty>(activity, R.layout.hot_tag_item){
|
|
|
+ download_mgr_empty_view.setVisibility(View.GONE);
|
|
|
+ initHotList();
|
|
|
+ initList();
|
|
|
+ initInput();
|
|
|
+
|
|
|
+ }
|
|
|
+ private ArrayAdapter<SearchGameRecord> inputAdapter;
|
|
|
+ private void initInput() {
|
|
|
+ inputAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1, searchGameRecordList);
|
|
|
+ search_game_input.setAdapter(inputAdapter);
|
|
|
+ search_game_input.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ Object obj = parent.getItemAtPosition(position);
|
|
|
+ if(obj instanceof SearchGameRecord){
|
|
|
+ search_game_input.setText(((SearchGameRecord) obj).getInput());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+// search_game_input.setThreshold(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AdbCommonRecycler<TaskReleaseEty> adapter;
|
|
|
+ private void initList() {
|
|
|
+ search_game_list.setLayoutManager(new LinearLayoutManager(activity));
|
|
|
+ adapter = new AdbCommonRecycler<TaskReleaseEty>(activity, list) {
|
|
|
+
|
|
|
@Override
|
|
|
- public boolean convert(int position, View convertView, ViewGroup parent, TaskReleaseEty item) {
|
|
|
- if(convertView instanceof TextView){
|
|
|
+ public int getViewIdByType(int type) {
|
|
|
+ return R.layout.item_search_game;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void convert(ViewHolder holder, final TaskReleaseEty item) {
|
|
|
+ View itemView = holder.itemView;
|
|
|
+ final TaskEty taskEty;
|
|
|
+ if (item == null || (taskEty = item.getTask()) == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ImageView find_information_game_icon = (ImageView) itemView.findViewById(R.id.find_information_game_icon);
|
|
|
+ TextView find_information_game_name = (TextView) itemView.findViewById(R.id.find_information_game_name);
|
|
|
+ TextView find_information_game_surplus = (TextView) itemView.findViewById(R.id.find_information_game_surplus);
|
|
|
+ TextView find_information_game_time = (TextView) itemView.findViewById(R.id.find_information_game_time);
|
|
|
+ TextView find_information_game_yuan = (TextView) itemView.findViewById(R.id.find_information_game_yuan);
|
|
|
+ TextView find_information_game_task = (TextView) itemView.findViewById(R.id.find_information_game_task);
|
|
|
+ ViewUtil.setImage(find_information_game_icon, taskEty.getIcon());
|
|
|
+ ViewUtil.setText(find_information_game_name, item.getName());
|
|
|
+ ViewUtil.setText(find_information_game_surplus);
|
|
|
+ ViewUtil.setText(find_information_game_time, taskEty.getTask_name());
|
|
|
+ find_information_game_yuan.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setText("立即充值");
|
|
|
+ find_information_game_task.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ ViewUtil.showGamePayAccount(activity, taskEty.getThird_task_id());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Jump2View.getInstance().goTaskDetailView(activity, item.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ search_game_list.setAdapter(adapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayAdapter<TaskReleaseEty> hotAdapter;
|
|
|
+ private void initHotList() {
|
|
|
+ hotAdapter = new ArrayAdapter<TaskReleaseEty>(activity, R.layout.item_search_game_hot, hotList) {
|
|
|
+ @Override
|
|
|
+ public boolean convert(int position, View convertView, ViewGroup parent, final TaskReleaseEty item) {
|
|
|
+ if (convertView instanceof TextView) {
|
|
|
((TextView) convertView).setText(item.getName());
|
|
|
}
|
|
|
+ convertView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Jump2View.getInstance().goTaskDetailView(activity, item.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
return true;
|
|
|
}
|
|
|
};
|
|
|
search_game_hot_list.setAdapter(hotAdapter);
|
|
|
}
|
|
|
|
|
|
+ private Runnable autoSearchRunnable = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ search_game_bt.performClick();
|
|
|
+ }
|
|
|
+ };
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
+ search_game_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
|
|
+ search_game_bt.performClick();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ search_game_input.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+ search_game_input.removeCallbacks(autoSearchRunnable);
|
|
|
+ search_game_input.postDelayed(autoSearchRunnable, 1000L);//1秒后自动搜索
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ List<SearchGameRecord> searchGameRecordList = new ArrayList<>();
|
|
|
List<TaskReleaseEty> hotList = new ArrayList<>();
|
|
|
+ List<TaskReleaseEty> list = new ArrayList<>();
|
|
|
+
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
+ //初始化搜索历史
|
|
|
+ List<SearchGameRecord> newSgrList = MyDbManager.getInstance().getAllSearchGameRecord();
|
|
|
+ ListUtil.addAll(searchGameRecordList, newSgrList);
|
|
|
+ inputAdapter.notifyDataSetChanged();
|
|
|
+ //初始化热门列表
|
|
|
SheepApp.getInstance().getNetComponent().getApiService()
|
|
|
- .releaseTask(1,9,
|
|
|
- SheepApp.getInstance().getConnectAddress().getPlatForm(),1,
|
|
|
+ .releaseTask(1, 9,
|
|
|
+ SheepApp.getInstance().getConnectAddress().getPlatForm(), 1,
|
|
|
0, 0,
|
|
|
- "-1", 3)
|
|
|
+ "1002,1003,1004", 3)
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
+ download_mgr_empty_view.setVisibility(View.VISIBLE);
|
|
|
+ search_game_hot.setVisibility(View.GONE);
|
|
|
+ search_game_list.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -97,8 +243,68 @@ public class ActSearchGame extends BaseActivity {
|
|
|
switch (view.getId()) {
|
|
|
case R.id.search_game_bt:
|
|
|
SEARCH_GAME_COMMIT.onEvent();
|
|
|
+ toSearchGame();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void toSearchGame() {
|
|
|
+ String inputText = search_game_input.getText().toString();
|
|
|
+ if (TextUtils.isEmpty(inputText)) {
|
|
|
+ list.clear();
|
|
|
+ notifyDataSetChanged();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //保存搜索到数据库
|
|
|
+ SearchGameRecord searchGameRecord = new SearchGameRecord();
|
|
|
+ searchGameRecord.setInput(inputText);
|
|
|
+ searchGameRecord.setTime(System.currentTimeMillis());
|
|
|
+ MyDbManager.getInstance().saveOrUpdate(searchGameRecord);
|
|
|
+ searchGameRecordList.add(searchGameRecord);
|
|
|
+// inputAdapter.notifyDataSetChanged();
|
|
|
+ //执行搜索
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService()
|
|
|
+ .releaseTask(1, 9,
|
|
|
+ SheepApp.getInstance().getConnectAddress().getPlatForm(), 1,
|
|
|
+ 0, 0,
|
|
|
+ "1002,1003,1004", 3, inputText)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ List<TaskReleaseEty> newList = baseMessage.getDatas(TaskReleaseEty.class);
|
|
|
+ list.clear();
|
|
|
+ ListUtil.addAll(list, newList);
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.showToast("暂无游戏");
|
|
|
+ list.clear();
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void notifyDataSetChanged() {
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ if(hotList.isEmpty()) {
|
|
|
+ download_mgr_empty_view.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ search_game_hot.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ search_game_list.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ search_game_list.setVisibility(View.VISIBLE);
|
|
|
+ if(hotList.isEmpty()) {
|
|
|
+ download_mgr_empty_view.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ search_game_hot.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|