文件整理

This commit is contained in:
huangzhuanghua
2016-09-02 17:14:05 +08:00
parent b1df05ea47
commit 6dd0c75cdc
84 changed files with 2020 additions and 1190 deletions

View File

@ -1,6 +1,7 @@
package com.gh.gamecenter;
import android.os.Bundle;
import android.support.v4.util.ArrayMap;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -14,6 +15,7 @@ import com.gh.base.BaseActivity;
import com.gh.common.util.DisplayUtils;
import com.gh.gamecenter.adapter.GameNewsAdapter;
import com.gh.gamecenter.adapter.GameNewsTypeListAdapter;
import com.gh.gamecenter.eventbus.EBTypeChange;
import java.util.ArrayList;
@ -22,17 +24,23 @@ import java.util.ArrayList;
*/
public class GameNewsActivity extends BaseActivity implements View.OnClickListener{
private static GameNewsAdapter adapter;
private static GameNewsTypeListAdapter typeListAdapter;
private GameNewsAdapter adapter;
private GameNewsTypeListAdapter typeListAdapter;
private RecyclerView game_news_list;
private RecyclerView game_news_top_type_list;
private LinearLayoutManager layoutManager;
private ImageView ivSearch;
private boolean isDestroy;
private ArrayMap<String, GameNewsAdapter> adapterMap;
public static int selectedPosition = 0; //新闻类型选中位置
private ArrayList<String> typeList;
private String gameId;
private float startY = 0;
private boolean isDestroy;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -52,26 +60,31 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
ivSearchParams.setMargins(0, 0, DisplayUtils.dip2px(this, 10), 0);
RelativeLayout reuse_actionbar = (RelativeLayout) contentView.findViewById(R.id.reuse_actionbar);
reuse_actionbar.addView(ivSearch,ivSearchParams);
reuse_actionbar.addView(ivSearch, ivSearchParams);
ivSearch.setOnClickListener(this);
ivSearch.setVisibility(View.GONE);
String gameName = getIntent().getStringExtra("gameName");
init(contentView, gameName);
final ArrayList<String> typeList = getIntent().getStringArrayListExtra("articleTypes");
adapterMap = new ArrayMap<>();
typeList = getIntent().getStringArrayListExtra("articleTypes");
typeList.add(0, "全部");
String gameId = getIntent().getStringExtra("gameId");
gameId = getIntent().getStringExtra("gameId");
game_news_list.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
game_news_list.setLayoutManager(layoutManager);
adapter = new GameNewsAdapter(this, typeList, gameId, game_news_top_type_list,game_news_list);
adapter = new GameNewsAdapter(this, typeList, game_news_list, gameId, "全部");
adapterMap.put("全部", adapter);
game_news_list.setAdapter(adapter);
game_news_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (layoutManager.findFirstVisibleItemPosition() >= 1) {
game_news_top_type_list.setVisibility(View.VISIBLE);
ivSearch.setVisibility(View.VISIBLE);
@ -86,7 +99,7 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (!isDestroy && newState == RecyclerView.SCROLL_STATE_IDLE
&& layoutManager.findLastVisibleItemPosition() == 3) {
&& layoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) {
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
adapter.addList(adapter.getNewsList().size());
}
@ -96,37 +109,39 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
game_news_top_type_list.setHasFixedSize(true);
game_news_top_type_list.setLayoutManager(new GridLayoutManager(this, 5));
typeListAdapter = new GameNewsTypeListAdapter(this, typeList);
typeListAdapter = new GameNewsTypeListAdapter(typeList, "全部");
game_news_top_type_list.setAdapter(typeListAdapter);
ViewGroup.LayoutParams params = game_news_top_type_list.getLayoutParams();
params.height = (int) Math.ceil(typeList.size() / 5f) * DisplayUtils.dip2px(this, 37);
game_news_top_type_list.setLayoutParams(params);
//禁止由于滑动出现的阴影
game_news_top_type_list.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float Y1 = 0;
float Y2;
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
Y1 = event.getY();
break;
case MotionEvent.ACTION_MOVE:
Y2 = event.getY();
if (Math.abs(Y1 - Y2)>0){
return true;
}
break;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
startY = event.getY();
} else if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (Math.abs(startY - event.getY()) > 0) {
return true;
}
}
return false;
}
});
}
public static void notifyTypeItem(String type){
adapter.notifyDataTypeAdapter(type);
typeListAdapter.notifyDataSetChanged();
public void onEventMainThread(EBTypeChange change) {
adapter = adapterMap.get(change.getType());
if (adapter == null) {
adapter = new GameNewsAdapter(this, typeList, game_news_list, gameId, change.getType());
adapterMap.put(change.getType(), adapter);
}
game_news_list.setAdapter(adapter);
game_news_top_type_list.setVisibility(View.GONE);
typeListAdapter.setNewsType(change.getType(), change.getPosition());
}
@Override
@ -135,7 +150,6 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
isDestroy = true;
adapter = null;
typeListAdapter = null;
selectedPosition = 0;
}
@Override