206 lines
7.2 KiB
Java
206 lines
7.2 KiB
Java
package com.gh.gamecenter;
|
|
|
|
import android.animation.Animator;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.os.Bundle;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.text.TextUtils;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.PopupWindow;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.gh.base.BaseActivity;
|
|
import com.gh.common.util.MeasureHeightLayoutManager;
|
|
import com.gh.gamecenter.adapter.StrategyAdapter;
|
|
import com.gh.gamecenter.adapter.StrategyDialogAdapter;
|
|
import com.gh.gamecenter.db.info.ConcernInfo;
|
|
import com.gh.gamecenter.manager.ConcernManager;
|
|
import com.jakewharton.rxbinding.view.RxView;
|
|
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import butterknife.BindView;
|
|
import rx.functions.Action1;
|
|
|
|
/**
|
|
* Created by khy on 2016/12/5.
|
|
*
|
|
*/
|
|
public class StrategyActivity extends BaseActivity implements StrategyDialogAdapter.OnStrategyDialogCallBackListener{
|
|
|
|
@BindView(R.id.strategy_game_name) TextView mGameName;
|
|
@BindView(R.id.strategy_select_game_rl) RelativeLayout mSelectGameRl;
|
|
@BindView(R.id.strategy_rv) RecyclerView mStrategyRv;
|
|
@BindView(R.id.popup_bg) View popupBg;
|
|
@BindView(R.id.reuse_none_data) LinearLayout mNoData;
|
|
|
|
private StrategyAdapter mStrategyAdapter;
|
|
|
|
private PopupWindow mPopupWindow;
|
|
|
|
private static int mDialogGamePosition = -1;
|
|
private static String gameId;
|
|
private static String gameName;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
View contentView = View.inflate(this, R.layout.activity_strategy, null);
|
|
init(contentView, "攻略");
|
|
|
|
mStrategyAdapter = new StrategyAdapter(this, gameId, mNoData);
|
|
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
|
mStrategyRv.setLayoutManager(layoutManager);
|
|
mStrategyRv.setAdapter(mStrategyAdapter);
|
|
|
|
mStrategyRv.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
@Override
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
super.onScrollStateChanged(recyclerView, newState);
|
|
if(layoutManager.findLastVisibleItemPosition() + 1 == mStrategyAdapter.getItemCount()
|
|
&& newState == RecyclerView.SCROLL_STATE_IDLE && mStrategyAdapter.isCanLoading()) {
|
|
mStrategyAdapter.addList(mStrategyAdapter.getItemCount()-1);
|
|
}
|
|
}
|
|
});
|
|
|
|
ConcernManager concernManager = new ConcernManager(this);
|
|
List<ConcernInfo> concernGame = concernManager.getConcernGame();
|
|
if (concernGame.size() >1 || (concernGame.size() == 1
|
|
&& !concernGame.get(0).getId().equals("5618b86e8ab49e17088b4575"))) {
|
|
mSelectGameRl.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(gameName)) {
|
|
mGameName.setText(gameName);
|
|
}
|
|
|
|
// 防抖处理
|
|
RxView.clicks(mSelectGameRl)
|
|
.throttleFirst(1, TimeUnit.SECONDS)
|
|
.subscribe(new Action1<Void>() {
|
|
@Override
|
|
public void call(Void aVoid) {
|
|
OnSelectGameClickListener();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void OnSelectGameClickListener() {
|
|
isShowPopupBg(true);
|
|
|
|
View contentView = View.inflate(this, R.layout.dialog_strategy_select_game, null);
|
|
RecyclerView selectGameRv = (RecyclerView) contentView.findViewById(R.id.dialog_strategy_select_game_rv);
|
|
ImageView selectIcon = (ImageView) contentView.findViewById(R.id.dialog_strategy_select_game_icon);
|
|
RelativeLayout allGameRl = (RelativeLayout) contentView.findViewById(R.id.dialog_strategy_select_game_rl);
|
|
|
|
allGameRl.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
mGameName.setText("全部游戏");
|
|
mDialogGamePosition = -1;
|
|
gameId = null;
|
|
isShowPopupBg(false);
|
|
mStrategyAdapter = new StrategyAdapter(StrategyActivity.this, gameId, mNoData);
|
|
mStrategyRv.setAdapter(mStrategyAdapter);
|
|
}
|
|
});
|
|
|
|
if (mDialogGamePosition == -1) {
|
|
selectIcon.setImageResource(R.drawable.strategy_game_select);
|
|
} else {
|
|
selectIcon.setImageDrawable(new ColorDrawable(0));
|
|
}
|
|
|
|
selectGameRv.setLayoutManager(new MeasureHeightLayoutManager(this));
|
|
selectGameRv.setAdapter(new StrategyDialogAdapter(this, mDialogGamePosition));
|
|
|
|
mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
|
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
|
mPopupWindow.setAnimationStyle(R.style.scale_popwindow_anim_style);
|
|
mPopupWindow.showAtLocation(mSelectGameRl, 0, 0, 0);
|
|
|
|
selectGameRv.setOnKeyListener(new View.OnKeyListener() {
|
|
@Override
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
if (keyCode == KeyEvent.KEYCODE_BACK
|
|
&& event.getRepeatCount() == 0
|
|
&& mPopupWindow != null
|
|
&& mPopupWindow.isShowing()) {
|
|
isShowPopupBg(false);
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
|
|
contentView.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
isShowPopupBg(false);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void isShowPopupBg(boolean isShow) {
|
|
if(isShow) {
|
|
popupBg.setVisibility(View.VISIBLE);
|
|
popupBg.animate()
|
|
.alpha(1f)
|
|
.setDuration(300)
|
|
.setListener(null);
|
|
} else {
|
|
mPopupWindow.dismiss();
|
|
popupBg.animate()
|
|
.alpha(0f)
|
|
.setDuration(300)
|
|
.setListener(new Animator.AnimatorListener() {
|
|
@Override
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAnimationEnd(Animator animation) {
|
|
popupBg.setVisibility(View.GONE);
|
|
}
|
|
|
|
@Override
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAnimationRepeat(Animator animation) {
|
|
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
public boolean selectRlIsVisible() {
|
|
return mSelectGameRl.getVisibility() == View.VISIBLE;
|
|
}
|
|
|
|
@Override
|
|
public void selectPosition(int position, ConcernInfo concernInfo) {
|
|
gameId = concernInfo.getId();
|
|
gameName = concernInfo.getGameName();
|
|
mNoData.setVisibility(View.GONE);
|
|
mDialogGamePosition = position;
|
|
|
|
mGameName.setText(gameName);
|
|
isShowPopupBg(false);
|
|
|
|
mStrategyAdapter = new StrategyAdapter(this, gameId, mNoData);
|
|
mStrategyRv.setAdapter(mStrategyAdapter);
|
|
}
|
|
}
|