187 lines
5.7 KiB
Java
187 lines
5.7 KiB
Java
package com.gh.gamecenter;
|
|
|
|
import android.os.Bundle;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import android.view.View.OnClickListener;
|
|
import android.view.ViewGroup.LayoutParams;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.gh.base.AppController;
|
|
import com.gh.base.BaseActivity;
|
|
import com.gh.common.view.VerticalItemDecoration;
|
|
import com.gh.gamecenter.adapter.NewsOrRaidersListAdapter;
|
|
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
|
import com.gh.gamecenter.eventbus.EBNetworkState;
|
|
|
|
/**
|
|
* @author 温冠超
|
|
* @email 294299195@qq.com
|
|
* @date 2015-8-10 首页资讯或攻略板块
|
|
*/
|
|
public class NewsOrRaidersActivity extends BaseActivity {
|
|
|
|
private RecyclerView news_list;
|
|
private LinearLayoutManager layoutManager;
|
|
private NewsOrRaidersListAdapter adapter;
|
|
private LinearLayout news_ll_loading, reuse_no_connection;
|
|
private TextView news_tv_label;
|
|
private RelativeLayout news_rl_label;
|
|
private RelativeLayout.LayoutParams rparams;
|
|
|
|
private String type;
|
|
|
|
private boolean isDestroy;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
type = getIntent().getStringExtra("type");
|
|
|
|
isDestroy = false;
|
|
|
|
View contentView = View.inflate(this,
|
|
R.layout.activity_news_or_raiders, null);
|
|
|
|
init(contentView, type);
|
|
|
|
reuse_no_connection.setOnClickListener(new OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
news_list.setVisibility(View.GONE);
|
|
news_ll_loading.setVisibility(View.VISIBLE);
|
|
reuse_no_connection.setVisibility(View.GONE);
|
|
adapter = new NewsOrRaidersListAdapter(
|
|
NewsOrRaidersActivity.this, news_list, news_ll_loading,
|
|
reuse_no_connection, type, news_rl_label, news_tv_label);
|
|
news_list.setAdapter(adapter);
|
|
}
|
|
});
|
|
|
|
rparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
|
|
LayoutParams.WRAP_CONTENT);
|
|
|
|
news_list.setHasFixedSize(true);
|
|
layoutManager = new LinearLayoutManager(this);
|
|
news_list.setLayoutManager(layoutManager);
|
|
|
|
adapter = new NewsOrRaidersListAdapter(this, news_list,
|
|
news_ll_loading, reuse_no_connection, type, news_rl_label,
|
|
news_tv_label);
|
|
|
|
news_list.setAdapter(adapter);
|
|
news_list.setOnTouchListener(new View.OnTouchListener() {
|
|
@Override
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
v.performClick();
|
|
}
|
|
if (news_ll_loading.getVisibility() == View.VISIBLE) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
news_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
super.onScrolled(recyclerView, dx, dy);
|
|
|
|
int position = layoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (adapter.getPosition_today() != -1
|
|
&& position >= adapter.getPosition_today()
|
|
&& position <= adapter.getTodaySize()
|
|
+ adapter.getPosition_today()) {
|
|
news_tv_label.setText("今天");
|
|
news_tv_label.setBackgroundResource(R.drawable.title_red);
|
|
} else if (adapter.getPosition_before() != -1
|
|
&& position >= adapter.getPosition_before()) {
|
|
news_tv_label.setText("昨天/以前");
|
|
news_tv_label.setBackgroundResource(R.drawable.title_gray);
|
|
} else if (adapter.getPosition_mygame() != -1) {
|
|
news_tv_label.setText("我的游戏");
|
|
news_tv_label.setBackgroundResource(R.drawable.title_blue);
|
|
}
|
|
|
|
if (position == adapter.getPosition_today() - 1
|
|
|| position == adapter.getPosition_before() - 1) {
|
|
int buttom = layoutManager.findViewByPosition(position)
|
|
.getBottom();
|
|
if (buttom <= news_rl_label.getHeight()) {
|
|
rparams.topMargin = buttom - news_rl_label.getHeight();
|
|
news_rl_label.setLayoutParams(rparams);
|
|
} else {
|
|
rparams.topMargin = 0;
|
|
news_rl_label.setLayoutParams(rparams);
|
|
}
|
|
} else {
|
|
rparams.topMargin = 0;
|
|
news_rl_label.setLayoutParams(rparams);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onScrollStateChanged(RecyclerView recyclerView,
|
|
int newState) {
|
|
super.onScrollStateChanged(recyclerView, newState);
|
|
if (!isDestroy && newState == RecyclerView.SCROLL_STATE_IDLE
|
|
&& layoutManager.findLastVisibleItemPosition() + 1 == adapter.getItemCount()) {
|
|
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
|
adapter.addList();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
news_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
|
}
|
|
|
|
public void onEventMainThread(EBConcernChanged busSeven) {
|
|
adapter.updateMyGameNews();
|
|
}
|
|
|
|
public void onEventMainThread(EBNetworkState busNetworkState) {
|
|
if (busNetworkState.isNetworkConnected()) {
|
|
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
|
news_list.setVisibility(View.GONE);
|
|
news_ll_loading.setVisibility(View.VISIBLE);
|
|
reuse_no_connection.setVisibility(View.GONE);
|
|
adapter = new NewsOrRaidersListAdapter(this, news_list,
|
|
news_ll_loading, reuse_no_connection, type,
|
|
news_rl_label, news_tv_label);
|
|
news_list.setAdapter(adapter);
|
|
} else if (adapter.isNetworkError()) {
|
|
adapter.setNetworkError(false);
|
|
adapter.notifyItemChanged(adapter.getItemCount());
|
|
adapter.addList();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
isDestroy = true;
|
|
AppController.canclePendingRequests(NewsOrRaidersActivity.class);
|
|
news_list = null;
|
|
layoutManager = null;
|
|
adapter = null;
|
|
news_ll_loading = null;
|
|
reuse_no_connection = null;
|
|
news_tv_label = null;
|
|
news_rl_label = null;
|
|
rparams = null;
|
|
type = null;
|
|
}
|
|
|
|
}
|