新的攻略页面-完成
This commit is contained in:
174
app/src/main/java/com/gh/gamecenter/StrategyActivity.java
Normal file
174
app/src/main/java/com/gh/gamecenter/StrategyActivity.java
Normal file
@ -0,0 +1,174 @@
|
||||
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.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 butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* 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 int mDialogGamePosition;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_strategy, null);
|
||||
init(contentView, "攻略");
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
mDialogGamePosition = -1;
|
||||
|
||||
mStrategyAdapter = new StrategyAdapter(this, null, 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick(R.id.strategy_select_game_rl)
|
||||
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;
|
||||
isShowPopupBg(false);
|
||||
mStrategyAdapter = new StrategyAdapter(StrategyActivity.this, null, 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) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPosition(int position, ConcernInfo concernInfo) {
|
||||
mNoData.setVisibility(View.GONE);
|
||||
mDialogGamePosition = position;
|
||||
mGameName.setText(concernInfo.getGameName());
|
||||
isShowPopupBg(false);
|
||||
|
||||
mStrategyAdapter = new StrategyAdapter(this, concernInfo.getId(), mNoData);
|
||||
mStrategyRv.setAdapter(mStrategyAdapter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user