完成插件跳转助手工具箱需求 https://gitlab.ghzs.com/pm/halo-app-issues/issues/636
This commit is contained in:
@ -14,27 +14,35 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.TextHelper;
|
||||
import com.gh.common.util.UrlFilterUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.ToolBoxRvAdapter;
|
||||
import com.gh.gamecenter.entity.ToolBoxEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.gamecenter.suggest.SuggestType;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.lightgame.utils.Util_System_Keyboard;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 24/05/17.
|
||||
*/
|
||||
|
||||
public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener,
|
||||
OnRequestCallBackListener {
|
||||
|
||||
public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener, OnRequestCallBackListener {
|
||||
|
||||
@BindView(R.id.et_search)
|
||||
public EditText searchEt;
|
||||
@BindView(R.id.tv_search)
|
||||
@ -55,58 +63,64 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
SwipeRefreshLayout mRefresh;
|
||||
@BindView(R.id.reuse_ll_loading)
|
||||
View mLoading;
|
||||
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private ToolBoxRvAdapter mRvAdapter;
|
||||
private ToolBoxRvAdapter mNormalRvAdapter;
|
||||
|
||||
|
||||
private boolean mIsSearch; // 记录页面状态 搜索页面/普通页面
|
||||
private String mSearchKey; // 记录搜索关键字
|
||||
|
||||
|
||||
Runnable runnable = () -> changeAdapter(true);
|
||||
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
Intent intent = new Intent(context, ToolBoxActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_toolbox;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setNavigationTitle("光环工具箱");
|
||||
|
||||
|
||||
mRefresh.setColorSchemeResources(R.color.theme);
|
||||
mRefresh.setOnRefreshListener(this);
|
||||
|
||||
|
||||
|
||||
// 跳转到工具箱 https://gitlab.ghzs.com/pm/halo-app-issues/issues/636
|
||||
String gameId = getIntent().getStringExtra(EntranceUtils.KEY_GAMEID);
|
||||
String targetUrl = getIntent().getStringExtra(EntranceUtils.KEY_URL);
|
||||
if (!TextUtils.isEmpty(targetUrl) && !TextUtils.isEmpty(gameId)) {
|
||||
findGameAndOpenItsToolboxWebview(gameId, targetUrl);
|
||||
}
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mToolboxRv.setLayoutManager(mLayoutManager);
|
||||
mRvAdapter = new ToolBoxRvAdapter(this, this, mIsSearch, mSearchKey);
|
||||
mToolboxRv.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
mToolboxRv.setAdapter(mRvAdapter);
|
||||
|
||||
|
||||
mNormalRvAdapter = mRvAdapter;
|
||||
|
||||
|
||||
mToolboxRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& mLayoutManager.findLastVisibleItemPosition() + 1 == mRvAdapter.getItemCount()) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE && mLayoutManager.findLastVisibleItemPosition() + 1 == mRvAdapter
|
||||
.getItemCount()) {
|
||||
if (!mRvAdapter.isOver() && !mRvAdapter.isLoading() && !mRvAdapter.isNetworkError()) {
|
||||
mRvAdapter.loadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mAppBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
|
||||
if (verticalOffset == 0) {
|
||||
mRefresh.setEnabled(true);
|
||||
@ -118,17 +132,38 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
Util_System_Keyboard.hideSoftKeyboard(this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
initSearch();
|
||||
}
|
||||
|
||||
|
||||
private void findGameAndOpenItsToolboxWebview(String gameId, String url) {
|
||||
RetrofitManager.getInstance(this)
|
||||
.getApi()
|
||||
.getGameToolBoxData(1, UrlFilterUtils.getFilterQuery("game_id", gameId))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<ToolBoxEntity>>() {
|
||||
@Override
|
||||
public void onResponse(@Nullable List<ToolBoxEntity> response) {
|
||||
if (response == null) return;
|
||||
|
||||
for (ToolBoxEntity toolbox : response) {
|
||||
if (url.equals(toolbox.getUrl())) {
|
||||
Intent intent = WebActivity.getWebByCollectionTools(ToolBoxActivity.this, toolbox, false);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initSearch() {
|
||||
backTv.setOnClickListener(v -> search(false, searchEt.getText().toString()));
|
||||
|
||||
|
||||
TextHelper.limitTheLengthOfEditText(searchEt, 20, () -> {
|
||||
Utils.toast(this, "最多输入20字");
|
||||
});
|
||||
|
||||
|
||||
searchTv.setOnClickListener(v -> {
|
||||
if (TextUtils.isEmpty(searchEt.getText().toString())) {
|
||||
Utils.toast(this, R.string.search_hint);
|
||||
@ -136,13 +171,13 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
}
|
||||
search(true, searchEt.getText().toString());
|
||||
});
|
||||
|
||||
|
||||
searchEt.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
Util_System_Keyboard.hideSoftKeyboard(this, searchEt);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
searchEt.setOnEditorActionListener((v, actionId, event) -> {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
searchTv.performClick();
|
||||
@ -150,8 +185,8 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@OnClick({R.id.reuse_no_connection, R.id.reuse_none_data})
|
||||
public void onClick(View view) {
|
||||
if (view.getId() == R.id.reuse_no_connection) {
|
||||
@ -165,7 +200,7 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
mRefresh.setRefreshing(false);
|
||||
@ -173,12 +208,12 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mLoading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
mRefresh.setRefreshing(false);
|
||||
@ -191,7 +226,7 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
mNoneDataTv.setText(getResources().getString(R.string.game_empty));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
mRefresh.setRefreshing(false);
|
||||
@ -199,12 +234,12 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
mLoading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mRefresh.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
|
||||
public void search(boolean isSearch, String searchKey) {
|
||||
if (mNoneData.getVisibility() == View.VISIBLE) {
|
||||
mNoneData.setVisibility(View.GONE);
|
||||
@ -216,7 +251,7 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
mSearchKey = searchKey;
|
||||
changeAdapter(false);
|
||||
}
|
||||
|
||||
|
||||
private void changeAdapter(boolean isRefresh) {
|
||||
if (mIsSearch) {
|
||||
mRvAdapter = new ToolBoxRvAdapter(this, this, mIsSearch, mSearchKey);
|
||||
@ -229,12 +264,12 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
}
|
||||
}
|
||||
mToolboxRv.setAdapter(mRvAdapter);
|
||||
|
||||
|
||||
if (mSearchKey != null) {
|
||||
searchEt.setText(mSearchKey);
|
||||
searchEt.setSelection(searchEt.getText().length());
|
||||
}
|
||||
|
||||
|
||||
if (mIsSearch) {
|
||||
backTv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user