diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8131e1bb6c..fa5ed9b5ce 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -63,7 +63,7 @@ android:value="81DB144D555386A38A70B833537EC256" /> + android:value="GH_202"/> @@ -194,6 +194,12 @@ + + diff --git a/app/src/main/java/com/gh/base/BaseActivity.java b/app/src/main/java/com/gh/base/BaseActivity.java index 49b893069e..052fe40093 100644 --- a/app/src/main/java/com/gh/base/BaseActivity.java +++ b/app/src/main/java/com/gh/base/BaseActivity.java @@ -3,6 +3,7 @@ package com.gh.base; import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.view.View; @@ -68,7 +69,7 @@ public class BaseActivity extends Activity implements OnCallBackListener { setTranslucentStatus(true); tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); - tintManager.setStatusBarTintResource(R.color.theme); + tintManager.setStatusBarTintColor(Color.BLACK); SystemBarConfig config = tintManager.getConfig(); contentView.setPadding(0, config.getPixelInsetTop(false), 0, config.getPixelInsetBottom()); @@ -80,7 +81,7 @@ public class BaseActivity extends Activity implements OnCallBackListener { int actionbar_height = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE).getInt("actionbar_height", - DisplayUtils.dip2px(getApplicationContext(), 48)); + DisplayUtils.dip2px(getApplicationContext(), 55)); RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar); LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( diff --git a/app/src/main/java/com/gh/base/BaseFragmentActivity.java b/app/src/main/java/com/gh/base/BaseFragmentActivity.java index 002fc2dc42..6b8aa4ae89 100644 --- a/app/src/main/java/com/gh/base/BaseFragmentActivity.java +++ b/app/src/main/java/com/gh/base/BaseFragmentActivity.java @@ -2,6 +2,7 @@ package com.gh.base; import android.annotation.TargetApi; import android.content.Context; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentActivity; @@ -65,7 +66,7 @@ public class BaseFragmentActivity extends FragmentActivity { setTranslucentStatus(true); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); - tintManager.setStatusBarTintResource(R.color.theme); + tintManager.setStatusBarTintColor(Color.BLACK); SystemBarConfig config = tintManager.getConfig(); contentView.setPadding(0, config.getPixelInsetTop(false), 0, config.getPixelInsetBottom()); diff --git a/app/src/main/java/com/gh/base/HomeFragment.java b/app/src/main/java/com/gh/base/HomeFragment.java index 3b2b1c05a5..93747b4eeb 100644 --- a/app/src/main/java/com/gh/base/HomeFragment.java +++ b/app/src/main/java/com/gh/base/HomeFragment.java @@ -8,10 +8,12 @@ import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.ScaleAnimation; import android.widget.LinearLayout; import android.widget.TextView; @@ -28,6 +30,8 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.manager.PackageManager; +import java.util.ArrayList; + import de.greenrobot.event.EventBus; /** @@ -43,13 +47,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener { private TextView downloadHint; private TextView searchHint; - private String hint; + private AlphaAnimation mAlphaAnimation; + + private ArrayList hintList; + private int hintIndex; @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - if (!TextUtils.isEmpty(hint)) { - outState.putString("hint", hint); + if (!hintList.isEmpty()) { + outState.putStringArrayList("hint", hintList); } } @@ -58,17 +65,18 @@ public class HomeFragment extends Fragment implements View.OnClickListener { super.onCreate(savedInstanceState); if (savedInstanceState != null) { - hint = savedInstanceState.getString("hint"); + hintList = savedInstanceState.getStringArrayList("hint"); } + hintIndex = 0; + view = View.inflate(getActivity(), R.layout.fragment_home, null); SharedPreferences sp = getActivity().getSharedPreferences( Config.PREFERENCE, Context.MODE_PRIVATE); LinearLayout home_actionbar = (LinearLayout) view.findViewById(R.id.home_actionbar); LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, sp.getInt("actionbar_height", - DisplayUtils.dip2px(getActivity(), 48))); + LinearLayout.LayoutParams.MATCH_PARENT,DisplayUtils.dip2px(getActivity(), 55)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int top = DisplayUtils.getStatusBarHeight(getResources()); @@ -79,6 +87,70 @@ public class HomeFragment extends Fragment implements View.OnClickListener { initActionBar(); + final ScaleAnimation scaleAnimation = new ScaleAnimation(0.4f, 1.0f, 0.4f, 1.0f + , Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + scaleAnimation.setDuration(500); + + mAlphaAnimation = new AlphaAnimation(1f, 0.2f); + mAlphaAnimation.setDuration(300); + mAlphaAnimation.setStartOffset(5000); + + scaleAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + if (mAlphaAnimation != null) { + searchHint.setAnimation(mAlphaAnimation); + mAlphaAnimation.start(); + } + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + + mAlphaAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + // 切换数据 + if (hintIndex > hintList.size() - 1) { + hintIndex = 0; + } + searchHint.setHint(hintList.get(hintIndex)); + hintIndex ++; + + if (scaleAnimation != null) { + searchHint.setAnimation(scaleAnimation); + scaleAnimation.start(); + } + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + + if (hintList != null && hintList.size() > 0) { + if (hintList.size() > 1) { + searchHint.setAnimation(mAlphaAnimation); + } else { + String hint = hintList.get(0); + searchHint.setHint(hint); + } + } + EventBus.getDefault().register(this); } @@ -96,6 +168,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener { view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this); view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this); view.findViewById(R.id.actionbar_notification).setOnClickListener(this); + view.findViewById(R.id.actionbar_search_rl).setOnClickListener(this); if (Config.isShow(getActivity())) { view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE); @@ -118,9 +191,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener { searchHint = (TextView) view.findViewById(R.id.actionbar_search_input); searchHint.setOnClickListener(this); - if (!TextUtils.isEmpty(hint)) { - searchHint.setHint(hint); - } } @Override @@ -140,16 +210,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener { Intent intent = new Intent(getActivity(), SearchActivity.class); intent.putExtra("clicked", true); - intent.putExtra("hint", hint); + intent.putExtra("hint", searchHint.getHint().toString()); intent.putExtra("entrance", "(工具栏)"); startActivity(intent); - } else if (id == R.id.actionbar_search_input) { + } else if (id == R.id.actionbar_search_input || id == R.id.actionbar_search_rl) { DataUtils.onEvent(getActivity(), "主页", "搜索框"); DataCollectionUtils.uploadClick(getActivity(), "搜索框", "主页"); Intent intent = new Intent(getActivity(), SearchActivity.class); intent.putExtra("clicked", false); - intent.putExtra("hint", hint); + intent.putExtra("hint", searchHint.getHint().toString()); intent.putExtra("entrance", "(工具栏)"); startActivity(intent); } else if (id == R.id.actionbar_notification) { @@ -173,11 +243,13 @@ public class HomeFragment extends Fragment implements View.OnClickListener { } } - public void setHint(String hint) { - if (!TextUtils.isEmpty(hint)) { - this.hint = hint; - if (searchHint != null) { - searchHint.setHint(hint); + public void setHint(ArrayList hint) { + if (hint != null && hint.size() > 0) { + hintList = hint; + if (hint.size() == 1 && searchHint != null) { + searchHint.setHint(hintList.get(0)); + } else if (mAlphaAnimation != null && searchHint != null) { + searchHint.setAnimation(mAlphaAnimation); } } } diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index d78270181f..390a837162 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -6,7 +6,7 @@ import android.content.SharedPreferences; public class Config { - public static final String HOST = "http://api.ghzhushou.com/v2d4/"; + public static final String HOST = "http://api.ghzhushou.com/v2d5/"; public static final String USER_HOST = "http://user.ghzhushou.com/v1d2/"; public static final String COMMENT_HOST = "http://comment.ghzhushou.com/v1d1/"; public static final String DATA_HOST = "http://data.ghzhushou.com/"; diff --git a/app/src/main/java/com/gh/common/constant/ItemViewType.java b/app/src/main/java/com/gh/common/constant/ItemViewType.java index 19e3ef3699..c23a6390f0 100644 --- a/app/src/main/java/com/gh/common/constant/ItemViewType.java +++ b/app/src/main/java/com/gh/common/constant/ItemViewType.java @@ -23,5 +23,6 @@ public class ItemViewType { public static final int LIBAO_NORMAL = 15; // 礼包正常布局 public static final int LIBAO_SKIP_CONCERN = 16; // 跳转关注管理页面布局 public static final int KC_HINT = 16; + public static final int ZIXUNTOP_TOP = 7; // 有料顶部布局 } diff --git a/app/src/main/java/com/gh/common/util/GameViewUtils.java b/app/src/main/java/com/gh/common/util/GameViewUtils.java index 255f538d78..00fda1fac1 100644 --- a/app/src/main/java/com/gh/common/util/GameViewUtils.java +++ b/app/src/main/java/com/gh/common/util/GameViewUtils.java @@ -39,7 +39,7 @@ public class GameViewUtils { if (i == size - 1) { view = getGameTagView(context, tag.get(i), 0); } else { - view = getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 5)); + view = getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 6)); } if (view != null) { labelLayout.addView(view); diff --git a/app/src/main/java/com/gh/common/util/KaiFuUtils.java b/app/src/main/java/com/gh/common/util/KaiFuUtils.java new file mode 100644 index 0000000000..329d468625 --- /dev/null +++ b/app/src/main/java/com/gh/common/util/KaiFuUtils.java @@ -0,0 +1,78 @@ +package com.gh.common.util; + +import android.graphics.Color; +import android.widget.TextView; + +import com.gh.gamecenter.R; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** + * Created by khy on 2017/3/19. + */ +public class KaiFuUtils { + + public static void setKaiFuTime(TextView textView, long time) { + time = time * 1000; + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); + try { + long today = format.parse(format.format(new Date())).getTime(); + if (time >= today && time < today + 86400 * 1000) { + format.applyPattern("HH:mm"); + textView.setText(String.format("今天 %s", format.format(time))); + textView.setBackgroundResource(R.drawable.border_white_bg); + textView.setTextColor(Color.parseColor("#ffb13c")); + } else if (time >= today - 86400 * 1000 && time < today) { + format.applyPattern("HH:mm"); + textView.setText(String.format("昨天 %s", format.format(time))); + textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray); + textView.setTextColor(Color.parseColor("#c7c7c7")); + } else if (time > today && time < today + 86400 * 1000 * 2){ + format.applyPattern("HH:mm"); + textView.setText(String.format("明天 %s", format.format(time))); + textView.setBackgroundResource(R.drawable.border_white_bg); + textView.setTextColor(Color.parseColor("#ffb13c")); + } else if (time >= today - 86400 * 1000 * 2 && time < today){ + format.applyPattern("HH:mm"); + textView.setText(String.format("前天 %s", format.format(time))); + textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray); + textView.setTextColor(Color.parseColor("#c7c7c7")); + } else if (time > today && time < today + 86400 * 1000 * 3){ + format.applyPattern("HH:mm"); + textView.setText(String.format("后天 %s", format.format(time))); + textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray); + textView.setTextColor(Color.parseColor("#c7c7c7")); + } else { + format.applyPattern("MM-dd HH:mm"); + textView.setText(format.format(time)); + textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray); + textView.setTextColor(Color.parseColor("#c7c7c7")); + } + } catch (ParseException e) { + e.printStackTrace(); + format.applyPattern("yyyy年MM月dd日 HH:mm"); + textView.setText(format.format(time)); + } + } + + public static void setKaiFuType(TextView textView, String type) { + textView.setText(type); + switch (type) { + case "不删档内测": + textView.setBackgroundColor(Color.parseColor("#c7c7c7")); + break; + case "删档内测": + textView.setBackgroundColor(Color.parseColor("#c7c7c7")); + break; + case "公测": + textView.setBackgroundColor(Color.parseColor("#06d0a8")); + break; + default: + textView.setBackgroundColor(Color.parseColor("#06d0a8")); + break; + } + } +} diff --git a/app/src/main/java/com/gh/common/view/VerticalItemDecoration.java b/app/src/main/java/com/gh/common/view/VerticalItemDecoration.java index f04471d28c..68b080df50 100644 --- a/app/src/main/java/com/gh/common/view/VerticalItemDecoration.java +++ b/app/src/main/java/com/gh/common/view/VerticalItemDecoration.java @@ -14,30 +14,42 @@ public class VerticalItemDecoration extends RecyclerView.ItemDecoration { private Paint paint; private int mInterval = 0; + private boolean isShowIntervalTop; - public VerticalItemDecoration(Context context, int interval) { + public VerticalItemDecoration(Context context, int interval, boolean isShowIntervalTop) { paint = new Paint(); - paint.setColor(context.getResources().getColor(R.color.background)); + paint.setColor(context.getResources().getColor(R.color.background )); mInterval = DisplayUtils.dip2px(context, interval); + this.isShowIntervalTop = isShowIntervalTop; } @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { int left = parent.getPaddingLeft(); int right = parent.getMeasuredWidth() - parent.getPaddingRight(); - for (int i = 0, size = parent.getChildCount() - 1; i < size; i++) { + for (int i = 0, size = parent.getChildCount(); i < size; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child .getLayoutParams(); int top = child.getBottom() + layoutParams.bottomMargin; int bottom = top + mInterval; - c.drawRect(left, top, right, bottom, paint); + + if (i == 0 && isShowIntervalTop) { + c.drawRect(left, 0, right, bottom, paint); + } else { + c.drawRect(left, top, right, bottom, paint); + } } } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { - outRect.set(0, 0, 0, mInterval); + int position = parent.getChildPosition(view); + if (position == 0 && isShowIntervalTop) { + outRect.set(0, mInterval, 0, mInterval); + } else { + outRect.set(0, 0, 0, mInterval); + } } } diff --git a/app/src/main/java/com/gh/gamecenter/CleanApkActivity.java b/app/src/main/java/com/gh/gamecenter/CleanApkActivity.java index 2ae0ad9f25..57f824cf12 100644 --- a/app/src/main/java/com/gh/gamecenter/CleanApkActivity.java +++ b/app/src/main/java/com/gh/gamecenter/CleanApkActivity.java @@ -17,6 +17,7 @@ import android.widget.TextView; import com.gh.base.BaseActivity; import com.gh.common.util.DialogUtils; import com.gh.common.util.Utils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.CleanApkAdapter; import com.gh.gamecenter.entity.InstallGameEntity; import com.gh.gamecenter.eventbus.EBSkip; @@ -57,6 +58,7 @@ public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.On mAdapter = new CleanApkAdapter(this, mApkDeleteBtn, mApkSelectAll); mApkRv.setLayoutManager(new LinearLayoutManager(this)); + mApkRv.addItemDecoration(new VerticalItemDecoration(this, 8, true)); mApkRv.setAdapter(mAdapter); mApkSelectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { diff --git a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java index 247c0ffaf3..1362b45632 100644 --- a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java @@ -12,6 +12,7 @@ import com.gh.base.BaseDetailActivity; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.changeskin.ChangeSkinUtils; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.eventbus.EBConcernChanged; @@ -75,6 +76,7 @@ public class GameDetailActivity extends BaseDetailActivity implements View.OnCli adapter = new GameDetailAdapter(this, entrance); detail_rv_show.setLayoutManager(new LinearLayoutManager(this)); + detail_rv_show.addItemDecoration(new VerticalItemDecoration(this, 8, true)); detail_rv_show.setAdapter(adapter); detail_ll_bottom.setOnClickListener(this); diff --git a/app/src/main/java/com/gh/gamecenter/KaiFuActivity.java b/app/src/main/java/com/gh/gamecenter/KaiFuActivity.java new file mode 100644 index 0000000000..bcfddc27a1 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/KaiFuActivity.java @@ -0,0 +1,401 @@ +package com.gh.gamecenter; + +import android.animation.Animator; +import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; +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.LinearLayout; +import android.widget.PopupWindow; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; +import com.gh.base.BaseActivity; +import com.gh.common.util.DownloadItemUtils; +import com.gh.common.util.MeasureHeightLayoutManager; +import com.gh.common.view.VerticalItemDecoration; +import com.gh.download.DataWatcher; +import com.gh.download.DownloadEntity; +import com.gh.download.DownloadManager; +import com.gh.gamecenter.adapter.KaiFuAdapter; +import com.gh.gamecenter.adapter.KaiFuDialogAdapter; +import com.gh.gamecenter.entity.ApkEntity; +import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.eventbus.EBDownloadStatus; +import com.gh.gamecenter.eventbus.EBNetworkState; +import com.gh.gamecenter.eventbus.EBPackage; +import com.jakewharton.rxbinding.view.RxView; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import butterknife.BindView; +import rx.functions.Action1; + +/** + * Created by khy on 2017/3/16. + */ +public class KaiFuActivity extends BaseActivity implements KaiFuDialogAdapter.OnKaiFuDialogCallBackListener + , KaiFuAdapter.OnScrollToKaiFuIndex, SwipeRefreshLayout.OnRefreshListener{ + + @BindView(R.id.kaifu_rv) RecyclerView mRecyclerView; + @BindView(R.id.kaifu_pb) ProgressBarCircularIndeterminate mPbLoading; + @BindView(R.id.kaifu_refresh) SwipeRefreshLayout mRefreshLayout; + @BindView(R.id.kaifu_game_name) TextView mGameName; + @BindView(R.id.popup_bg) View mPopupBg; + @BindView(R.id.kaifu_select_game_rl) RelativeLayout mSelectGameRl; + @BindView(R.id.reuse_no_connection) LinearLayout mNoConnection; + + private PopupWindow mPopupWindow; + + private KaiFuAdapter mAdapter; + + private LinearLayoutManager layoutManager; + + private boolean isEverpause = false; + + private String kaifuType; + + private int mDialogGamePosition; // 顶部弹窗过滤位置 + private int kaifuOffset = 0; + + private DataWatcher dataWatcher = new DataWatcher() { + @Override + public void onDataChanged(DownloadEntity downloadEntity) { + ArrayList locationList = mAdapter.getLocationMap().get(downloadEntity.getPackageName()); + if (locationList != null) { + GameEntity gameEntity; + for (int location : locationList) { + gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex()); + if (gameEntity != null) { + DownloadItemUtils.processDate(KaiFuActivity.this, gameEntity, downloadEntity, + mAdapter, location); + } + } + } + } + }; + + private int getGameEntityIndex() { + if (kaifuOffset != 0) { + return 1; + } + return 0; + } + + Runnable runnable = new Runnable() { + @Override + public void run() { + mAdapter = new KaiFuAdapter(KaiFuActivity.this, kaifuType); + mRecyclerView.setAdapter(mAdapter); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + View view = View.inflate(this, R.layout.activity_kaifu, null); + init(view, "开服表"); + + kaifuType = "全部"; + + mRefreshLayout.setColorSchemeResources(R.color.theme); + mRefreshLayout.setOnRefreshListener(this); + mRefreshLayout.setEnabled(false); + + mAdapter = new KaiFuAdapter(this, kaifuType); + layoutManager = new LinearLayoutManager(this); + mRecyclerView.addItemDecoration(new VerticalItemDecoration(this, 8, false)); + mRecyclerView.setLayoutManager(layoutManager); + mRecyclerView.setAdapter(mAdapter); + + mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + //上拉加载 + if (mAdapter.isLoadedBottom() && newState == RecyclerView.SCROLL_STATE_IDLE + && mAdapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1){ + mAdapter.initListBottom(kaifuOffset + mAdapter.loadCountBottom()); + } + //下拉加载 + if (kaifuOffset >0 && mAdapter.isLoadedTop() && newState == RecyclerView.SCROLL_STATE_IDLE + && layoutManager.findFirstVisibleItemPosition() == 0) { + int countTop = mAdapter.loadCountTop(); + if (countTop%20 == 0) { // 不是20的倍数 证明加载完毕 + int offset = kaifuOffset - countTop; + int limit = 20; + if (offset < 0) { + limit = limit + offset; + offset = 0; + } + + if (limit == 0) return; + + mAdapter.initListTop(offset, limit); + } + } + } + }); + + + // 防抖处理 + RxView.clicks(mSelectGameRl) + .throttleFirst(1, TimeUnit.SECONDS) + .subscribe(new Action1() { + @Override + public void call(Void aVoid) { + initSelectGameDialog(); + } + }); + + } + + private void initSelectGameDialog() { + isShowPopupBg(true); + + View contentView = View.inflate(this, R.layout.dialog_kaifu_select_game, null); + RecyclerView selectGameRv = (RecyclerView) contentView.findViewById(R.id.dialog_kaifu_select_game_rv); + final TextView selectGameTitle = (TextView) contentView.findViewById(R.id.dialog_kaifu_title); + + final MeasureHeightLayoutManager layout = new MeasureHeightLayoutManager(this); + selectGameRv.setLayoutManager(layout); + selectGameRv.setAdapter(new KaiFuDialogAdapter(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.setOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + + if (layout.findFirstVisibleItemPosition() >= 5) { + selectGameTitle.setVisibility(View.VISIBLE); + } else { + selectGameTitle.setVisibility(View.GONE); + } + + } + }); + + 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); + } + }); + } + + @Override + public void selectPosition(int position, String tag, String gameName) { + mDialogGamePosition = position; + if (!TextUtils.isEmpty(gameName)) { + mGameName.setText(gameName); + } else { + mGameName.setText(tag); + } + isShowPopupBg(false); + + kaifuOffset = 0; + kaifuType = tag; + + mRecyclerView.setVisibility(View.VISIBLE); + mPbLoading.setVisibility(View.VISIBLE); + mNoConnection.setVisibility(View.GONE); + + mAdapter = new KaiFuAdapter(this, kaifuType); + mRecyclerView.setAdapter(mAdapter); + } + + public void isShowPopupBg(boolean isShow) { + if(isShow) { + mPopupBg.setVisibility(View.VISIBLE); + mPopupBg.animate() + .alpha(1f) + .setDuration(300) + .setListener(null); + } else { + mPopupWindow.dismiss(); + mPopupBg.animate() + .alpha(0f) + .setDuration(300) + .setListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + + } + + @Override + public void onAnimationEnd(Animator animation) { + mPopupBg.setVisibility(View.GONE); + } + + @Override + public void onAnimationCancel(Animator animation) { + + } + + @Override + public void onAnimationRepeat(Animator animation) { + + } + + }); + } + + } + + @Override + public void loadError() { + if (mPbLoading != null && mPbLoading.getVisibility() == View.VISIBLE) { + mPbLoading.setVisibility(View.GONE); + } + toast("加载失败,请检查网络状态"); + mPbLoading.setVisibility(View.GONE); + mNoConnection.setVisibility(View.VISIBLE); + } + + @Override + public void loadDone() { + if (mPbLoading != null && mPbLoading.getVisibility() == View.VISIBLE) { + mPbLoading.setVisibility(View.GONE); + } + + if (mRefreshLayout.isRefreshing()) { + mRefreshLayout.setRefreshing(false); + } + } + + @Override + public void loadDone(Object obj) { + super.loadDone(obj); + + kaifuOffset = (int) obj; + + if (kaifuOffset == 0) { + mRefreshLayout.setEnabled(true); + } else { + mRefreshLayout.setEnabled(false); + } + } + + // 下载被删除事件 + public void onEventMainThread(EBDownloadStatus status) { + if ("delete".equals(status.getStatus())) { + DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform()); + + ArrayList locationList = mAdapter.getLocationMap().get(status.getPackageName()); + if (locationList != null) { + GameEntity gameEntity; + for (int location : locationList) { + + gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex()); + if (gameEntity != null && gameEntity.getEntryMap() != null) { + gameEntity.getEntryMap().remove(status.getPlatform()); + } + mAdapter.notifyItemChanged(location); + } + } + } + } + + public void onEventMainThread(EBPackage busFour) { + ArrayList locationList = mAdapter.getLocationMap().get(busFour.getPackageName()); + if (locationList != null) { + GameEntity gameEntity; + for (int location : locationList) { + if ("安装".equals(busFour.getType())) { + gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex()); + for (ApkEntity apkEntity : gameEntity.getApk()) { + if (apkEntity.getPackageName().equals(busFour.getPackageName())) { + if (gameEntity.getEntryMap() != null) { + gameEntity.getEntryMap().remove(apkEntity.getPlatform()); + } + mAdapter.notifyItemChanged(location + getGameEntityIndex()); + break; + } + } + } else if ("卸载".equals(busFour.getType())) { + mAdapter.notifyItemChanged(location + getGameEntityIndex()); + } + } + } + } + + //连接上网络事件 + public void onEventMainThread(EBNetworkState busNetworkState) { + if (busNetworkState.isNetworkConnected()) { + if (mNoConnection.getVisibility() == View.VISIBLE) { + mRecyclerView.setVisibility(View.VISIBLE); + mPbLoading.setVisibility(View.VISIBLE); + mNoConnection.setVisibility(View.GONE); + mAdapter = new KaiFuAdapter(KaiFuActivity.this, kaifuType); + mRecyclerView.setAdapter(mAdapter); + } + } + } + + @Override + public void onResume() { + super.onResume(); + if (isEverpause) { + for (GameEntity entity : mAdapter.getSubjectList()) { + entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName())); + } + } + isEverpause = false; + DownloadManager.getInstance(getApplicationContext()).addObserver(dataWatcher); + } + + @Override + public void onPause() { + super.onPause(); + isEverpause = true; + DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher); + } + + private void moveToPosition(int n) { + int firstItem = layoutManager.findFirstVisibleItemPosition(); + int lastItem = layoutManager.findLastVisibleItemPosition(); + if (n <= firstItem ){ + mRecyclerView.scrollToPosition(n); + }else if ( n <= lastItem ){ + int top = mRecyclerView.getChildAt(n - firstItem).getTop(); + mRecyclerView.scrollBy(0, top); + }else{ + mRecyclerView.scrollToPosition(n); + } + + } + + @Override + public void onScroll(int scrollPosition) { + moveToPosition(scrollPosition + getGameEntityIndex()); + } + + @Override + public void onRefresh() { + mRecyclerView.postDelayed(runnable, 1000); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/KcSelectGameActivity.java b/app/src/main/java/com/gh/gamecenter/KcSelectGameActivity.java index b8bc117bd9..525024d9c7 100644 --- a/app/src/main/java/com/gh/gamecenter/KcSelectGameActivity.java +++ b/app/src/main/java/com/gh/gamecenter/KcSelectGameActivity.java @@ -16,6 +16,7 @@ import com.gh.base.AppController; import com.gh.base.BaseActivity; import com.gh.common.util.DisplayUtils; import com.gh.common.util.Utils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.KcSelectGameAdapter; import com.gh.gamecenter.kuaichuan.FileInfo; @@ -70,6 +71,7 @@ public class KcSelectGameActivity extends BaseActivity { mAdapter = new KcSelectGameAdapter(this, mSelectSend, installCount, installRl, mSelectPb); layoutManager = new LinearLayoutManager(this); mSelectRv.setLayoutManager(layoutManager); + mSelectRv.addItemDecoration(new VerticalItemDecoration(this, 8, false)); mSelectRv.setAdapter(mAdapter); rparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, diff --git a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java index ef10e19894..c68fb4ad20 100644 --- a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java @@ -6,6 +6,7 @@ import android.view.View; import com.gh.base.AppController; import com.gh.base.BaseDetailActivity; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.LibaoDetailAdapter; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.LibaoEntity; @@ -44,9 +45,11 @@ public class LibaoDetailActivity extends BaseDetailActivity { mAdapter = new LibaoDetailAdapter(this, mLibaoEntity, detail_tv_download); detail_rv_show.setLayoutManager(new LinearLayoutManager(this)); + detail_rv_show.addItemDecoration(new VerticalItemDecoration(this, 8, true)); detail_rv_show.setAdapter(mAdapter); - if (mLibaoEntity.getGame().getId() != null) { + if (mLibaoEntity!= null && mLibaoEntity.getGame() != null + && mLibaoEntity.getGame().getId() != null) { title = mLibaoEntity.getName(); getGameDigest(); } diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 91d7461dd4..35168ea80c 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -38,7 +38,6 @@ import com.gh.common.util.GameUtils; import com.gh.common.util.LibaoUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; -import com.gh.common.util.RandomUtils; import com.gh.common.util.TokenUtils; import com.gh.common.util.TrafficUtils; import com.gh.download.DataWatcher; @@ -69,6 +68,7 @@ import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.ObservableUtil; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; +import com.gh.gamecenter.zixun.ZiXunFragment; import org.json.JSONArray; import org.json.JSONObject; @@ -99,7 +99,8 @@ import rx.schedulers.Schedulers; */ public class MainActivity extends BaseFragmentActivity implements OnClickListener { - private NewsFragment newsFragment; + // private NewsFragment newsFragment; + private ZiXunFragment ziXunFragment; private PersonalFragment personalFragment; private GameFragment gameFragment; private ImageView ivGame; @@ -112,7 +113,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene private SharedPreferences sp; private ConcernManager concernManager; - private String searchHint; + private ArrayList searchHint; private int currentTab; @@ -880,20 +881,22 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene RetrofitManager.getApi().getSearchHints() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response>() { + .subscribe(new Response>() { @Override - public void onResponse(List response) { + public void onResponse(ArrayList response) { if (response.size() != 0) { - if (response.size() == 1) { - searchHint = response.get(0); - } else { - searchHint = response.get(RandomUtils.nextInt(response.size())); - } +// if (response.size() == 1) { +// searchHint = response.get(0); +// } else { +// searchHint = response.get(RandomUtils.nextInt(response.size())); +// } + + searchHint = response; if (gameFragment != null) { gameFragment.setHint(searchHint); } - if (newsFragment != null) { - newsFragment.setHint(searchHint); + if (ziXunFragment != null) { + ziXunFragment.setHint(searchHint); } } } @@ -970,7 +973,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } if (gameFragment == null) { gameFragment = new GameFragment(); - if (!TextUtils.isEmpty(searchHint)) { + if (searchHint != null && searchHint.size() > 0) { gameFragment.setHint(searchHint); } transaction.add(R.id.main_content, gameFragment); @@ -983,26 +986,26 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene case 1: ivNews.setImageResource(R.drawable.ic_news_select); tvNews.setTextColor(getResources().getColor(R.color.theme)); - if (newsFragment == null) { + if (ziXunFragment == null) { List list = getSupportFragmentManager().getFragments(); if (list != null) { for (Fragment fragment : list) { if (fragment.getClass().equals(NewsFragment.class)) { - newsFragment = (NewsFragment) fragment; - transaction.show(newsFragment); + ziXunFragment = (ZiXunFragment) fragment; + transaction.show(ziXunFragment); break; } } } - if (newsFragment == null) { - newsFragment = new NewsFragment(); - if (!TextUtils.isEmpty(searchHint)) { - newsFragment.setHint(searchHint); + if (ziXunFragment == null) { + ziXunFragment = new ZiXunFragment(); + if (searchHint != null && searchHint.size() > 0) { + ziXunFragment.setHint(searchHint); } - transaction.add(R.id.main_content, newsFragment); + transaction.add(R.id.main_content, ziXunFragment); } } else { - transaction.show(newsFragment); + transaction.show(ziXunFragment); } currentTab = 1; break; @@ -1053,8 +1056,8 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (gameFragment != null) { transaction.hide(gameFragment); } - if (newsFragment != null) { - transaction.hide(newsFragment); + if (ziXunFragment != null) { + transaction.hide(ziXunFragment); } List list = getSupportFragmentManager().getFragments(); diff --git a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java index 3502b2e2f3..f3eb98ad94 100644 --- a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java @@ -57,7 +57,6 @@ import butterknife.OnClick; import butterknife.OnTouch; import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; import rx.schedulers.Schedulers; /** @@ -211,8 +210,8 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail .subscribe(new com.gh.gamecenter.retrofit.Response>(){ @Override - public void onNext(List response) { - super.onNext(response); + public void onResponse(List response) { + super.onResponse(response); if (response.size() > 0) { if (!TextUtils.isEmpty(mConcernEntity.getId())){ commentNum = response.get(0).getNum(); @@ -260,9 +259,9 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail .getNewsViews(newsId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Action1>() { + .subscribe(new Response>(){ @Override - public void call(List viewsEntities) { + public void onResponse(List viewsEntities) { if (viewsEntities.size() > 0) { mConcernEntity.setViews(viewsEntities.get(0).getViews()); adapter.notifyItemChanged(0); diff --git a/app/src/main/java/com/gh/gamecenter/NewsNormalActivity.java b/app/src/main/java/com/gh/gamecenter/NewsNormalActivity.java new file mode 100644 index 0000000000..9bc2e55b43 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/NewsNormalActivity.java @@ -0,0 +1,123 @@ +package com.gh.gamecenter; + +import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; + +import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; +import com.gh.base.BaseActivity; +import com.gh.common.view.VerticalItemDecoration; +import com.gh.gamecenter.adapter.NewsNormalAdapter; +import com.gh.gamecenter.eventbus.EBNetworkState; + +import butterknife.BindView; +import butterknife.OnClick; + +/** + * Created by khy on 2017/3/15. + * + * 原创 + 资讯 + */ +public class NewsNormalActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener{ + + @BindView(R.id.newsnormal_srl) + SwipeRefreshLayout mRefreshLayout; + @BindView(R.id.newsnormal_rv) + RecyclerView mRecyclerView; + @BindView(R.id.newsnormal_pb) + ProgressBarCircularIndeterminate loadingLayout; + @BindView(R.id.reuse_no_connection) LinearLayout mNoConnectionLayout; + + private LinearLayoutManager layoutManager; + private NewsNormalAdapter mAdapter; + + private String mNewsType; + + Runnable runnable = new Runnable() { + @Override + public void run() { + mAdapter = new NewsNormalAdapter(NewsNormalActivity.this, mNewsType); + mRecyclerView.setAdapter(mAdapter); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mNewsType = getIntent().getExtras().getString("newsType"); + + View view = View.inflate(this, R.layout.activity_newsnormal, null); + + if ("yuanchuang".equals(mNewsType)) { + init(view, "原创"); + } else { + init(view, "资讯"); + } + + mRefreshLayout.setColorSchemeResources(R.color.theme); + mRefreshLayout.setOnRefreshListener(this); + + mRecyclerView.setHasFixedSize(true); + layoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(layoutManager); + mAdapter = new NewsNormalAdapter(NewsNormalActivity.this, mNewsType); + mRecyclerView.addItemDecoration(new VerticalItemDecoration(this, 8, true)); + mRecyclerView.setAdapter(mAdapter); + mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + if (newState == RecyclerView.SCROLL_STATE_IDLE + && layoutManager.findLastVisibleItemPosition() + 1 == mAdapter.getItemCount()) { + if (!mAdapter.isOver() && !mAdapter.isLoading() && !mAdapter.isNetworkError()) { + mAdapter.addList(mAdapter.getNewsListSize()); + } + } + } + }); + + } + + @OnClick(R.id.reuse_no_connection) + public void reconnection() { // 重新连接 + mRefreshLayout.setRefreshing(true); + mRecyclerView.setVisibility(View.VISIBLE); + loadingLayout.setVisibility(View.VISIBLE); + mNoConnectionLayout.setVisibility(View.GONE); + mRecyclerView.postDelayed(runnable, 1000); + } + + @Override + public void loadDone() { // 数据加载成功回调 + mRefreshLayout.setRefreshing(false); + loadingLayout.setVisibility(View.GONE); + } + + @Override + public void loadError() { // 数据加载失败回调 + mRefreshLayout.setRefreshing(false); + loadingLayout.setVisibility(View.GONE); + mRecyclerView.setVisibility(View.GONE); + mNoConnectionLayout.setVisibility(View.VISIBLE); + } + + // 连接上网络事件 + public void onEventMainThread(EBNetworkState busNetworkState) { + if (busNetworkState.isNetworkConnected()) { + if (mNoConnectionLayout.getVisibility() == View.VISIBLE) { + reconnection(); + } else if (mAdapter.isNetworkError()) { + mAdapter.setNetworkError(false); + mAdapter.notifyItemChanged(mAdapter.getItemCount() - 1); + mAdapter.addList(mAdapter.getNewsListSize()); + } + } + } + + @Override + public void onRefresh() { + mRecyclerView.postDelayed(runnable, 1000); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java index a9b7ec01e5..1f358fdb3b 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java @@ -2,7 +2,6 @@ package com.gh.gamecenter; import android.content.Context; import android.content.Intent; -import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.support.v7.widget.RecyclerView; @@ -18,15 +17,13 @@ import android.widget.TextView; import android.widget.Toast; import com.gh.base.BaseActivity; -import com.gh.common.constant.Config; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.MeasureHeightLayoutManager; import com.gh.common.util.NewsUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; +import com.gh.gamecenter.adapter.viewholder.NewsTextViewHolder; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -54,7 +51,6 @@ public class NewsSearchActivity extends BaseActivity { @BindView(R.id.et_search) EditText et_search; @BindView(R.id.gamedetail_news_ll_loading) LinearLayout gamedetail_news_ll_loading; @BindView(R.id.reuse_no_connection) LinearLayout reuse_no_connection; - @BindView(R.id.gamedetail_news_cardView) CardLinearLayout gamedetail_news_cardView; private MeasureHeightLayoutManager layoutManager; private List newsEntities; @@ -89,14 +85,6 @@ public class NewsSearchActivity extends BaseActivity { DisplayMetrics outMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(outMetrics); - ViewGroup.LayoutParams params = gamedetail_news_cardView.getLayoutParams(); - params.height = outMetrics.heightPixels - - DisplayUtils.dip2px(this, 38 + 16 + 8 + 8) - - getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE).getInt("actionbar_height", - DisplayUtils.dip2px(getApplicationContext(), 48)) - - DisplayUtils.getStatusBarHeight(getResources()); - gamedetail_news_cardView.setLayoutParams(params); - newsEntities = new ArrayList<>(); searchAdapter = new NewsSearchAdapter(); @@ -104,7 +92,7 @@ public class NewsSearchActivity extends BaseActivity { gamedetail_news_rv.setLayoutManager(layoutManager); gamedetail_news_rv.setAdapter(searchAdapter); - gamedetail_news_rv.addItemDecoration(new VerticalItemDecoration(NewsSearchActivity.this, 1)); + gamedetail_news_rv.addItemDecoration(new VerticalItemDecoration(NewsSearchActivity.this, 1, false)); et_search.setText(searchKey); @@ -124,7 +112,6 @@ public class NewsSearchActivity extends BaseActivity { searchAdapter.notifyDataSetChanged(); gamedetail_news_ll_loading.setVisibility(View.VISIBLE); reuse_none_data.setVisibility(View.GONE); - gamedetail_news_cardView.setVisibility(View.GONE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); handler.postDelayed(new Runnable() { @@ -160,7 +147,6 @@ public class NewsSearchActivity extends BaseActivity { public void onClick(View v) { reuse_no_connection.setVisibility(View.GONE); gamedetail_news_ll_loading.setVisibility(View.VISIBLE); - gamedetail_news_cardView.setVisibility(View.GONE); handler.postDelayed(new Runnable() { @Override public void run() { @@ -191,7 +177,6 @@ public class NewsSearchActivity extends BaseActivity { public void onResponse(List response) { isLoadOver = true; gamedetail_news_ll_loading.setVisibility(View.GONE); - gamedetail_news_cardView.setVisibility(View.VISIBLE); reuse_none_data.setVisibility(View.GONE); if (response.size() != 0) { @@ -199,7 +184,6 @@ public class NewsSearchActivity extends BaseActivity { searchAdapter.notifyDataSetChanged(); } else { if (page == 1) { - gamedetail_news_cardView.setVisibility(View.GONE); reuse_none_data.setVisibility(View.VISIBLE); } @@ -243,31 +227,20 @@ public class NewsSearchActivity extends BaseActivity { R.layout.refresh_footerview, parent, false); return new FooterViewHolder(view); } else { - LinearLayout linearLayout = new LinearLayout(parent.getContext()); - linearLayout.setOrientation(LinearLayout.HORIZONTAL); - linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - linearLayout.setBackgroundResource(R.drawable.cardview_item_style); - - TextView textView = new TextView(parent.getContext()); - textView.setPadding(DisplayUtils.dip2px(NewsSearchActivity.this,10),DisplayUtils.dip2px(NewsSearchActivity.this,10) - ,0, DisplayUtils.dip2px(NewsSearchActivity.this,10)); - textView.setTextColor(Color.parseColor("#3a3a3a")); - textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - textView.setSingleLine(); - textView.setTextSize(15); - - linearLayout.addView(textView); - - return new ViewHolder(linearLayout); + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.news_text_item, parent, false); + return new NewsTextViewHolder(view); } } @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolder){ - ViewHolder viewHolder = (ViewHolder) holder; - viewHolder.tvTitle.setText(Html.fromHtml(newsEntities.get(position).getTitle())); - viewHolder.linearLayout.setOnClickListener(new View.OnClickListener() { + if (holder instanceof NewsTextViewHolder){ + NewsTextViewHolder viewHolder = (NewsTextViewHolder) holder; + viewHolder.title.setText(Html.fromHtml(newsEntities.get(position).getTitle())); + viewHolder.type.setVisibility(View.GONE); + viewHolder.line.setVisibility(View.GONE); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NewsEntity newsEntity = newsEntities.get(holder.getPosition()); @@ -321,14 +294,5 @@ public class NewsSearchActivity extends BaseActivity { return newsEntities.size() + 1; } - public class ViewHolder extends RecyclerView.ViewHolder{ - LinearLayout linearLayout; - TextView tvTitle; - public ViewHolder(View itemView) { - super(itemView); - linearLayout = (LinearLayout) itemView; - tvTitle = (TextView) linearLayout.getChildAt(0); - } - } } } diff --git a/app/src/main/java/com/gh/gamecenter/SearchActivity.java b/app/src/main/java/com/gh/gamecenter/SearchActivity.java index c42fe2fcee..0d50135e24 100644 --- a/app/src/main/java/com/gh/gamecenter/SearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SearchActivity.java @@ -75,7 +75,7 @@ public class SearchActivity extends BaseFragmentActivity { setTranslucentStatus(true); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); - tintManager.setStatusBarTintResource(R.color.theme); + tintManager.setStatusBarTintResource(R.color.back); SystemBarConfig config = tintManager.getConfig(); contentView.setPadding(0, config.getPixelInsetTop(false), 0, config.getPixelInsetBottom()); diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index 4050381265..b425c18f9a 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -325,11 +325,6 @@ public class SplashScreenActivity extends BaseActivity { bundle = getIntent().getBundleExtra("data"); } - if (sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true)) { - bundle = new Bundle(); - bundle.putString("to", "DownloadManagerActivity"); - } - Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); intent.putExtra("data", bundle); startActivity(intent); diff --git a/app/src/main/java/com/gh/gamecenter/SubjectActivity.java b/app/src/main/java/com/gh/gamecenter/SubjectActivity.java index 4647ad4247..14a02e08aa 100644 --- a/app/src/main/java/com/gh/gamecenter/SubjectActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SubjectActivity.java @@ -1,20 +1,25 @@ package com.gh.gamecenter; import android.os.Bundle; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.View; +import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.BaseActivity; +import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.download.DataWatcher; import com.gh.download.DownloadEntity; import com.gh.download.DownloadManager; import com.gh.gamecenter.adapter.SubjectAdapter; +import com.gh.gamecenter.adapter.SubjectTypeAdapter; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.eventbus.EBDownloadStatus; @@ -32,9 +37,10 @@ import butterknife.BindView; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; -public class SubjectActivity extends BaseActivity { +public class SubjectActivity extends BaseActivity implements SubjectTypeAdapter.OnSelectTypeListener { @BindView(R.id.subject_list) RecyclerView subject_list; + @BindView(R.id.subject_type_list) RecyclerView subject_type_list; @BindView(R.id.subject_pb_loading) ProgressBarCircularIndeterminate subject_pb_loading; @BindView(R.id.reuse_no_connection) LinearLayout reuse_no_connection; @@ -89,6 +95,7 @@ public class SubjectActivity extends BaseActivity { layoutManager = new LinearLayoutManager(this); + subject_list.addItemDecoration(new VerticalItemDecoration(this, 8, true)); subject_list.setHasFixedSize(true); subject_list.setLayoutManager(layoutManager); adapter = new SubjectAdapter(this); @@ -106,10 +113,20 @@ public class SubjectActivity extends BaseActivity { } }); + GridLayoutManager layout = new GridLayoutManager(this, 4){ + @Override + public boolean canScrollVertically() { + return false; + } + }; + subject_type_list.setLayoutManager(layout); + if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(id)) { getSubjectName(id); } + + } private void getSubjectName(String id) { @@ -147,6 +164,18 @@ public class SubjectActivity extends BaseActivity { } } + @Override + public void loadDone(Object obj) { + super.loadDone(obj); + ArrayList gameType = (ArrayList) obj; + gameType.add(0, "全部"); + ViewGroup.LayoutParams params = subject_type_list.getLayoutParams(); + params.height = (int) Math.ceil(gameType.size() / 4f) * DisplayUtils.dip2px(this, 37); + subject_type_list.setLayoutParams(params); + SubjectTypeAdapter adapter = new SubjectTypeAdapter(SubjectActivity.this, gameType); + subject_type_list.setAdapter(adapter); + } + // 下载被删除事件 public void onEventMainThread(EBDownloadStatus status) { if ("delete".equals(status.getStatus())) { @@ -221,4 +250,8 @@ public class SubjectActivity extends BaseActivity { DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher); } + @Override + public void onSelectType(String type) { + + } } diff --git a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java index 6a36973930..3998031a4b 100644 --- a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java @@ -12,12 +12,12 @@ import android.view.View.OnClickListener; import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.TextView; import com.gh.base.BaseActivity; import com.gh.common.util.DialogUtils; import com.gh.common.util.PackageUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -47,7 +47,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener @BindView(R.id.tv_suggest_connectway) TextView tv_suggest_connectway; @BindView(R.id.et_suggest_content) EditText et_suggest_content; @BindView(R.id.et_suggest_connectway) EditText et_suggest_connectway; - @BindView(R.id.btn_suggest_post) CardLinearLayout btn_suggest_post; + @BindView(R.id.btn_suggest_post) LinearLayout btn_suggest_post; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/gh/gamecenter/adapter/CleanApkAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/CleanApkAdapter.java index 4e20022acc..aea79fe6c7 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/CleanApkAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/CleanApkAdapter.java @@ -18,7 +18,6 @@ import android.widget.TextView; import com.gh.common.util.BitmapUtils; import com.gh.common.util.PackageUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.CleanApkActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.KcSelectGameViewHolder; @@ -205,19 +204,19 @@ public class CleanApkAdapter extends RecyclerView.Adapter { + private Context context; + private OnCallBackListener listener; + private OnScrollToKaiFuIndex scrollToKaiFuIndex; + + private List subjectList; + + private ArrayMap> locationMap; + + private String kaifuType; + + private int kaifuIndex = 0; // 开服零界点 + private int initOffset; + private int loadCountTop; // 记录加载数量 上 + private int loadCountBottom;// 记录加载数量 下 + + private boolean isRemoveBottom; + private boolean isRemoveTop; + private boolean isNetworkError; + private boolean isLoadedBottom; + private boolean isLoadedTop; + + public KaiFuAdapter(KaiFuActivity activity, String kaifuType) { + + this.context = activity; + this.listener = activity; + this.kaifuType = kaifuType; + this.scrollToKaiFuIndex = activity; + + locationMap = new ArrayMap<>(); + + subjectList = new ArrayList<>(); + isLoadedTop = false; + isLoadedBottom = false; + isNetworkError = false; + + kaifuIndex = 0; + loadCountBottom = 0; + loadCountTop = 0; + + if ("全部".equals(kaifuType)) { + this.kaifuType = "all"; + } + + initKaiFuOffset(); + } + + public void initKaiFuOffset() { + RetrofitManager.getApi() + .getKaiFuOffset(kaifuType) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new JSONObjectResponse(){ + @Override + public void onResponse(JSONObject response) { + super.onResponse(response); + JSONObject jsonObject = response; + int offset = 0; + try { + offset = jsonObject.getInt("offset"); + } catch (JSONException e) { + e.printStackTrace(); + } + initOffset = offset; + listener.loadDone(offset); + initListBottom(offset); + } + + @Override + public void onFailure(HttpException e) { + super.onFailure(e); + listener.loadError(); + } + }); + + } + + public void initListBottom(final int offset) { + + isLoadedBottom = false; + RetrofitManager.getApi().getKaiFuData(kaifuType, offset, 20) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + + GameManager manager = new GameManager(context); + if (response.size() != 0) { + + if (offset == initOffset) { + long curTime = System.currentTimeMillis()/1000; + for (int i = 0; i < response.size(); i++) { + long time = response.get(i).getServerEntity().getTime(); + long l = time - curTime; + if (l > 0) { + kaifuIndex = i + 1; + } + } + } + + for (GameEntity entity : response) { + // 黄壮华 初始化游戏状态 修改2015/8/15 + entity.setEntryMap(DownloadManager.getInstance(context).getEntryMap(entity.getName())); + manager.addOrUpdate(entity.getApk(), entity.getId(), entity.getName()); + } + + subjectList.addAll(response); + notifyItemRangeInserted(getItemCount() - 1 - response.size(), response.size()); + + if (offset == initOffset) { + isLoadedTop = true; //首次加载 手动设置下拉加载完成 + loadCountTop = response.size();//首次加载 下拉加载减去初始加载值 获取正确偏移量 + + subjectList.add(kaifuIndex, new GameEntity()); // 添加一个空的实体当做 零界点ITEM + } + + if (response.size() < 20) { + isRemoveBottom = true; + notifyItemChanged(getItemCount() - 1); + } + + loadCountBottom = loadCountBottom + response.size(); + } else { + isRemoveBottom = true; + notifyDataSetChanged(); + } + + initLocationMap(); + + if (listener != null) { + listener.loadDone(); + } + + isLoadedBottom = true; + + if (offset == initOffset) { //定位到开服零界点 + scrollToKaiFuIndex.onScroll(kaifuIndex); + } + } + + @Override + public void onFailure(HttpException e) { + if (offset == initOffset){ + if (listener != null) { + listener.loadError(); + } + }else { + Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + + isNetworkError = true; + notifyDataSetChanged(); + } + } + }); + } + + public void initListTop(final int offset, int limit) { + + isLoadedTop = false; + RetrofitManager.getApi().getKaiFuData(kaifuType, offset, limit) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + + GameManager manager = new GameManager(context); + if (response.size() != 0) { + for (GameEntity entity : response) { + // 黄壮华 初始化游戏状态 修改2015/8/15 + entity.setEntryMap(DownloadManager.getInstance(context).getEntryMap(entity.getName())); + manager.addOrUpdate(entity.getApk(), entity.getId(), entity.getName()); + } + + subjectList.addAll(0, response); + notifyItemRangeInserted(0, response.size()); + + if (response.size() < 20 || offset == 0) { + isRemoveTop = true; + notifyItemChanged(getItemCount() - 1); + } + + loadCountTop = loadCountTop + response.size(); + } else { + isRemoveTop = true; + notifyDataSetChanged(); + } + + initLocationMap(); + isLoadedTop = true; + } + + @Override + public void onFailure(HttpException e) { + if (offset == initOffset){ + if (listener != null) { + listener.loadError(); + } + }else { + Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + + isNetworkError = true; + notifyDataSetChanged(); + } + } + }); + } + + + private void initLocationMap() { + + ArrayList list; + GameEntity gameEntity; + for (int i = 0, size = subjectList.size(); i < size; i++) { + + int index = 0; + if (initOffset != 0) { + index ++; + } + + gameEntity = subjectList.get(i); + if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) { + for (ApkEntity apkEntity : gameEntity.getApk()) { + list = locationMap.get(apkEntity.getPackageName()); + if (list == null) { + list = new ArrayList<>(); + locationMap.put(apkEntity.getPackageName(), list); + } + list.add(i + index); + } + } + + } + } + + @Override + public int getItemCount() { + if (subjectList.size() < 1) { + return 0; + } + if (initOffset != 0) { + return subjectList.size() + 2; + } + return subjectList.size() + 1; + } + + @Override + public int getItemViewType(int position) { + int index = 0; + if (initOffset != 0) { + index ++; + } + + if (position == getItemCount() - 1 || (position == 0 && initOffset != 0)) { + return ItemViewType.LOADING; + } + if (TextUtils.isEmpty(subjectList.get(position- index).getId())) { + return 100; + } else { + return ItemViewType.GAME_TEST; + } + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { + if (viewType == ItemViewType.LOADING){ + View view = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.refresh_footerview, viewGroup, false); + return new FooterViewHolder(view); + } else if (viewType == ItemViewType.GAME_TEST) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.game_test_item, viewGroup, false); + return new GameTestViewHolder(view); + } else if (viewType == ItemViewType.GAME_NORMAL) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate( + R.layout.game_normal_item, viewGroup, false); + return new GameNormalViewHolder(view); + } else if (viewType == 100) { + TextView textView = new TextView(context); + textView.setText("↓当前开服 · 即将开服↑"); + textView.setTextColor(context.getResources().getColor(R.color.hint)); + textView.setTextSize(13); + textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT + , DisplayUtils.dip2px(context, 42))); + textView.setGravity(Gravity.CENTER); + return new KaiFuIndexViewHolder(textView); + } + return null; + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { + int index = 0; + if (initOffset != 0) { + index ++; + } + + if (viewHolder instanceof GameTestViewHolder) { + initGameTestViewHolder((GameTestViewHolder) viewHolder, position - index); + } else if (viewHolder instanceof FooterViewHolder) { + initFooterViewHolder((FooterViewHolder) viewHolder, position); + } + } + + private void initFooterViewHolder(FooterViewHolder viewHolder, final int position) { + if (isNetworkError) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载失败,点击重试"); + viewHolder.itemView.setClickable(true); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isNetworkError = false; + notifyDataSetChanged(); + if (position == getItemCount() - 1) { + initListBottom(kaifuIndex + loadCountBottom); + } else { + int offset = kaifuIndex - loadCountTop; + int limit = 20; + if (offset < 0) { + limit = limit + offset; + offset = 0; + } + initListTop(offset, limit); + } + } + }); + } else if ((isRemoveBottom && position == getItemCount() - 1) + || (isRemoveTop && position == 0)) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载完毕"); + viewHolder.itemView.setClickable(false); + viewHolder.lineLeft.setVisibility(View.VISIBLE); + viewHolder.lineRight.setVisibility(View.VISIBLE); + } else { + viewHolder.loading.setVisibility(View.VISIBLE); + viewHolder.hint.setText("加载中..."); + viewHolder.itemView.setClickable(false); + } + } + + private void initGameTestViewHolder(final GameTestViewHolder holder, int position) { + + holder.gameOrder.setVisibility(View.GONE); + + final GameEntity gameEntity = subjectList.get(position); + + ImageUtils.display(holder.gameThumb, gameEntity.getIcon()); + holder.gameName.setText(gameEntity.getName()); + if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { + holder.gameDes.setText(gameEntity.getBrief()); + } else { + holder.gameDes.setText(String.format("%s %s", gameEntity.getApk().get(0).getSize(), gameEntity.getBrief())); + } + + KaiFuUtils.setKaiFuTime( holder.gameTestType, gameEntity.getServerEntity().getTime()); + String type = gameEntity.getServerEntity().getType(); + if ("不删档内测".equals(type) || "删档内测".equals(type)) { + KaiFuUtils.setKaiFuType(holder.gameTestTime, gameEntity.getServerEntity().getType()); + } else if ("公测".equals(type)){ + String note = gameEntity.getServerEntity().getNote(); + if (TextUtils.isEmpty(note)) { + KaiFuUtils.setKaiFuType(holder.gameTestTime, gameEntity.getServerEntity().getType()); + } else { + KaiFuUtils.setKaiFuType(holder.gameTestTime, gameEntity.getServerEntity().getType() + ":" + note); + } + } else { + KaiFuUtils.setKaiFuType(holder.gameTestTime, gameEntity.getServerEntity().getNote()); + } + + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Map kv = new HashMap<>(); + kv.put("名字", gameEntity.getName()); + kv.put("位置", String.valueOf(holder.getPosition() + 1)); + DataUtils.onEvent(context, "点击", "开服表", kv); + + DataCollectionUtils.uploadClick(context, "列表", "开服表", gameEntity.getName()); + + GameUtils.startGameDetailActivity(context, gameEntity, "主页-游戏" + "+(" + "开服表" + "[" + (holder.getPosition()) + "])"); + } + }); + + DownloadItemUtils.setOnClickListener(context, + holder.gameDownloadBtn, gameEntity, position, + KaiFuAdapter.this, "主页游戏" + "+(" + "开服表" + "[" + (holder.getPosition()) + "])", "开服表 :" + gameEntity.getName(), false); + + DownloadItemUtils.updateItem(context, gameEntity, holder, true); + } + + public List getSubjectList() { + return subjectList; + } + + public ArrayMap> getLocationMap() { + return locationMap; + } + + public boolean isLoadedBottom(){ + return isLoadedBottom; + } + + public boolean isLoadedTop(){ + return isLoadedTop; + } + + public int loadCountTop() { + return loadCountTop; + } + + public int loadCountBottom() { + return loadCountBottom; + } + + public class KaiFuIndexViewHolder extends RecyclerView.ViewHolder { + + public KaiFuIndexViewHolder(View itemView) { + super(itemView); + } + } + + public interface OnScrollToKaiFuIndex { + void onScroll(int scrollPosition); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/adapter/KaiFuDialogAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/KaiFuDialogAdapter.java new file mode 100644 index 0000000000..2374f19e6d --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/adapter/KaiFuDialogAdapter.java @@ -0,0 +1,130 @@ +package com.gh.gamecenter.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.support.v7.widget.RecyclerView; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.gh.common.util.DisplayUtils; +import com.gh.gamecenter.KaiFuActivity; +import com.gh.gamecenter.R; +import com.gh.gamecenter.adapter.viewholder.StrategyDialogViewHolder; +import com.gh.gamecenter.db.info.ConcernInfo; +import com.gh.gamecenter.manager.ConcernManager; + +import java.util.List; + +/** + * Created by khy on 2016/12/5. + */ +public class KaiFuDialogAdapter extends RecyclerView.Adapter { + + private Context mContext; + + private OnKaiFuDialogCallBackListener callBackListener; + + private List mConcernGame; + + private int mSelectPosition; + + private String[] arrKaiFuTag = {"全部", "删档内测", "不删档内测" , "公测", "新服"}; + + public KaiFuDialogAdapter(KaiFuActivity kaiFuActivity, int selectPosition) { + this.mContext = kaiFuActivity; + this.mSelectPosition = selectPosition; + this.callBackListener = kaiFuActivity; + + ConcernManager concernManager = new ConcernManager(kaiFuActivity); + List concernGame = concernManager.getConcernGame(); + for (int i = 0; i < concernGame.size(); i++) { + if ("5618b86e8ab49e17088b4575".equals(concernGame.get(i).getId())) { + concernGame.remove(i); + } + } + mConcernGame = concernGame; + } + + @Override + public int getItemViewType(int position) { + if (!mConcernGame.isEmpty() && position == 5) { + return 0; + } + return 1; + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (viewType == 0) { + TextView textView = new TextView(mContext); + textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT + , DisplayUtils.dip2px(mContext, 25))); + textView.setText("以下是已关注的游戏"); + textView.setBackgroundColor(Color.parseColor("#ededed")); + textView.setGravity(Gravity.CENTER); + return new TitleViewHolder(textView); + } else { + View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_strategy_item, parent, false); + return new StrategyDialogViewHolder(view); + } + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) { + if (holder instanceof StrategyDialogViewHolder) { + StrategyDialogViewHolder viewHolder = ((StrategyDialogViewHolder) holder); + + if (position <= 5) { + viewHolder.gameName.setText(arrKaiFuTag[position]); + } else { + viewHolder.gameName.setText(mConcernGame.get(position - 6).getGameName()); + } + + if (position == mSelectPosition) { + viewHolder.selectIcon.setImageResource(R.drawable.strategy_game_select); + } else { + viewHolder.selectIcon.setImageDrawable(new ColorDrawable(0)); + } + + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String tag; + String gameName = null; + if (position <= 5) { + tag = arrKaiFuTag[position]; + } else { + tag = mConcernGame.get(position - 6).getId(); + gameName = mConcernGame.get(position - 6).getGameName(); + } + + callBackListener.selectPosition(position, tag, gameName); + } + }); + } + } + + @Override + public int getItemCount() { + if (mConcernGame.isEmpty()) { + return 5; + } + return mConcernGame.size() + 6; + } + + public class TitleViewHolder extends RecyclerView.ViewHolder { + + public TitleViewHolder(View itemView) { + super(itemView); + } + } + + public interface OnKaiFuDialogCallBackListener{ + void selectPosition(int position, String tag, String gameName); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/adapter/KcSelectGameAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/KcSelectGameAdapter.java index 44413b93d4..1256208fdb 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/KcSelectGameAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/KcSelectGameAdapter.java @@ -24,7 +24,6 @@ import com.gh.common.constant.ItemViewType; import com.gh.common.util.BitmapUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.Utils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.KcSelectGameActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; @@ -271,23 +270,23 @@ public class KcSelectGameAdapter extends RecyclerView.Adapter position - mHotCommentList.size() - index) { commentPosition = position - mHotCommentList.size() - index; commentEntity = mNormalCommentList.get(position - mHotCommentList.size() - index); isHotComment = false; - if ( mNormalCommentList.size() == position - mHotCommentList.size() - index + 1) { - ((CardLinearLayout) holder.itemView).setmBottom(DisplayUtils.dip2px(mContext, 4)); - } else { - ((CardLinearLayout) holder.itemView).setmBottom(0); - } +// if ( mNormalCommentList.size() == position - mHotCommentList.size() - index + 1) { +// ((CardLinearLayout) holder.itemView).setmBottom(DisplayUtils.dip2px(mContext, 4)); +// } else { +// ((CardLinearLayout) holder.itemView).setmBottom(0); +// } } if (commentEntity == null) { diff --git a/app/src/main/java/com/gh/gamecenter/adapter/NewsNormalAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/NewsNormalAdapter.java new file mode 100644 index 0000000000..e582b8f04f --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/adapter/NewsNormalAdapter.java @@ -0,0 +1,445 @@ +package com.gh.gamecenter.adapter; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.util.DisplayMetrics; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.Toast; + +import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; +import com.gh.common.util.DataUtils; +import com.gh.common.util.DisplayUtils; +import com.gh.common.util.ImageUtils; +import com.gh.common.util.NewsUtils; +import com.gh.gamecenter.NewsNormalActivity; +import com.gh.gamecenter.R; +import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; +import com.gh.gamecenter.adapter.viewholder.NewsImage1ViewHolder; +import com.gh.gamecenter.adapter.viewholder.NewsImage2ViewHolder; +import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder; +import com.gh.gamecenter.entity.NewsEntity; +import com.gh.gamecenter.entity.ViewsEntity; +import com.gh.gamecenter.listener.OnCallBackListener; +import com.gh.gamecenter.manager.VisitManager; +import com.gh.gamecenter.retrofit.JSONObjectResponse; +import com.gh.gamecenter.retrofit.ObservableUtil; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import retrofit2.adapter.rxjava.HttpException; +import rx.Observable; +import rx.Subscriber; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; +import rx.functions.Func1; +import rx.schedulers.Schedulers; + +/** + * Created by khy on 2017/3/15. + */ +public class NewsNormalAdapter extends RecyclerView.Adapter { + + private NewsNormalActivity activity; + private Context context; + private OnCallBackListener listener; + + private List newsList; + + private String mNewsType; + + private int itemCount; + private int cardMargin; + + private boolean isLoading; + private boolean isOver; + private boolean isNetworkError; + + public NewsNormalAdapter(NewsNormalActivity activity, String newsType) { + + this.activity = activity; + this.context = activity; + this.listener = activity; + this.mNewsType = newsType; + + newsList = new ArrayList<>(); + + itemCount = 0; + + isLoading = false; + isOver = false; + isNetworkError = false; + + cardMargin = (int)context.getResources().getDimension(R.dimen.cardview_margin); + + addList(0); + } + + // 加载数据 + public void addList(final int offset) { + if (isLoading) { + return; + } + isLoading = true; + Observable> observable; + + if ("yuanchuang".equals(mNewsType)) { + observable = RetrofitManager.getApi().getYuanChuang(offset); + } else { + observable = RetrofitManager.getApi().getZiXun(offset); + } + + observable.map(new Func1, List>() { + @Override + public List call(List list) { + // 去掉重复数据 + return NewsUtils.removeDuplicateData(newsList, list); + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>(){ + @Override + public void onResponse(List response) { + isLoading = false; + + if (response.size() != 0) { + newsList.addAll(response); + itemCount += response.size(); + notifyItemRangeInserted(newsList.size() - response.size(), response.size()); + } else { + isOver = true; + notifyItemChanged(getItemCount() - 1); + } + + if (offset == 0 && listener != null) { + listener.loadDone(); + } + + // 获取新闻阅读量 + getNewsViews(response, offset); + } + + @Override + public void onFailure(HttpException e) { + isLoading = false; + // 网络错误 + if (offset == 0) { + if (listener != null) { + listener.loadError(); + } + } else { + Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + isNetworkError = true; + notifyItemChanged(getItemCount() - 1); + } + } + }); + } + + // 获取新闻阅读量 + private void getNewsViews(final List list, final int start) { + if (list == null || list.isEmpty()) { + return; + } + ObservableUtil.computation(new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + StringBuilder builder = new StringBuilder(); + for (int i = 0, size = list.size(); i < size; i++) { + builder.append(list.get(i).getId()); + builder.append("-"); + } + builder.deleteCharAt(builder.length() - 1); + String ids = builder.toString(); + VisitManager.getInstance().addUrl(ids); + subscriber.onNext(ids); + subscriber.onCompleted(); + } + }, new Action1() { + @Override + public void call(String ids) { + RetrofitManager.getData() + .getNewsViews(ids) + .map(new Func1, String>() { + @Override + public String call(List list) { + for (ViewsEntity viewsEntity : list) { + for (NewsEntity newsEntity : newsList) { + if (viewsEntity.getId().equals(newsEntity.getId())) { + newsEntity.setViews(viewsEntity.getViews()); + break; + } + } + } + return null; + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(String response) { + notifyItemRangeChanged(start, list.size()); + } + }); + } + }); + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (viewType == ItemViewType.NEWS_IMAGE1) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.news_image1_item, parent, false); + return new NewsImage1ViewHolder(view); + } else if (viewType == ItemViewType.NEWS_IMAGE2) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.news_image2_item, parent, false); + return new NewsImage2ViewHolder(view); + } else if (viewType == ItemViewType.NEWS_IMAGE3) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.news_image3_item, parent, false); + return new NewsImage3ViewHolder(view); + } else if (viewType == ItemViewType.LOADING) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.refresh_footerview, parent, false); + return new FooterViewHolder(view); + } + return null; + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + if (holder instanceof NewsImage1ViewHolder) { + initNewsImage1ViewHolder((NewsImage1ViewHolder) holder, position); + } else if (holder instanceof NewsImage2ViewHolder) { + initNewsImage2ViewHolder((NewsImage2ViewHolder) holder, position); + } else if (holder instanceof NewsImage3ViewHolder) { + initNewsImage3ViewHolder((NewsImage3ViewHolder) holder, position); + } else if (holder instanceof FooterViewHolder) { + initFooterViewHolder((FooterViewHolder) holder); + } + } + + private void initNewsImage1ViewHolder(final NewsImage1ViewHolder viewHolder, int position) { + + final NewsEntity newsEntity = newsList.get(position); + + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Map kv = new HashMap<>(); + kv.put("名字", newsEntity.getTitle()); + kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); + DataUtils.onEvent(context, "点击", "资讯-资讯", kv); + + DataCollectionUtils.uploadClick(context, "列表", "资讯-资讯", newsEntity.getTitle()); + + //统计阅读量 + statNewsViews(newsEntity, viewHolder.getPosition()); + NewsUtils.startNewsDetailActivity(context, newsEntity, "(资讯-资讯)"); + } + }); +// viewHolder.thumb.setImageURI(newsEntity.getThumbnail().getUrl().get(0)); + ImageUtils.display(viewHolder.thumb, newsEntity.getThumbnail().getUrl().get(0)); + viewHolder.title.setText(newsEntity.getTitle()); + int views = newsEntity.getViews(); + if (views == 0) { + viewHolder.read.setVisibility(View.GONE); + } else { + viewHolder.read.setVisibility(View.VISIBLE); + viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views)); + } + NewsUtils.setNewsType(viewHolder.type, newsEntity.getType()); + } + + private void initNewsImage2ViewHolder(final NewsImage2ViewHolder viewHolder, int position) { + + final NewsEntity newsEntity = newsList.get(position); + + DisplayMetrics outMetrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics); + int width = (outMetrics.widthPixels - DisplayUtils.dip2px(context, 56)) / 3; + int height = (int) (width * 3 / 4f); + + LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(width, height); + viewHolder.thumb1.setLayoutParams(lparams1); + + LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams(width, height); + lparams2.leftMargin = DisplayUtils.dip2px(context, 8); + viewHolder.thumb2.setLayoutParams(lparams2); + + LinearLayout.LayoutParams lparams3 = new LinearLayout.LayoutParams(width, height); + lparams3.leftMargin = DisplayUtils.dip2px(context, 8); + viewHolder.thumb3.setLayoutParams(lparams3); + + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Map kv = new HashMap<>(); + kv.put("名字", newsEntity.getTitle()); + kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); + DataUtils.onEvent(context, "点击", "资讯-资讯", kv); + + DataCollectionUtils.uploadClick(context, "列表", "资讯-资讯", newsEntity.getTitle()); + + //统计阅读量 + statNewsViews(newsEntity, viewHolder.getPosition()); + NewsUtils.startNewsDetailActivity(context, newsEntity, "(资讯-资讯)"); + } + }); + viewHolder.title.setText(newsEntity.getTitle()); +// viewHolder.thumb1.setImageURI(newsEntity.getThumbnail().getUrl().get(0)); +// viewHolder.thumb2.setImageURI(newsEntity.getThumbnail().getUrl().get(1)); +// viewHolder.thumb3.setImageURI(newsEntity.getThumbnail().getUrl().get(2)); + ImageUtils.display(viewHolder.thumb1, newsEntity.getThumbnail().getUrl().get(0)); + ImageUtils.display(viewHolder.thumb2, newsEntity.getThumbnail().getUrl().get(1)); + ImageUtils.display(viewHolder.thumb3, newsEntity.getThumbnail().getUrl().get(2)); + int views = newsEntity.getViews(); + if (views == 0) { + viewHolder.read.setVisibility(View.GONE); + } else { + viewHolder.read.setVisibility(View.VISIBLE); + viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views)); + } + NewsUtils.setNewsType(viewHolder.type, newsEntity.getType()); + } + + private void initNewsImage3ViewHolder(final NewsImage3ViewHolder viewHolder, int position) { + + final NewsEntity newsEntity = newsList.get(position); + + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Map kv = new HashMap<>(); + kv.put("名字", newsEntity.getTitle()); + kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); + DataUtils.onEvent(context, "点击", "资讯-资讯", kv); + + DataCollectionUtils.uploadClick(context, "列表", "资讯-资讯", newsEntity.getTitle()); + + //统计阅读量 + statNewsViews(newsEntity, viewHolder.getPosition()); + NewsUtils.startNewsDetailActivity(context, newsEntity, "(资讯-资讯)"); + } + }); + viewHolder.title.setText(newsEntity.getTitle()); + ImageUtils.getInstance().display(viewHolder.thumb, newsEntity.getThumbnail().getUrl().get(0), + context.getResources().getDisplayMetrics().widthPixels - DisplayUtils.dip2px(context, 40)); + int views = newsEntity.getViews(); + if (views == 0) { + viewHolder.read.setVisibility(View.GONE); + } else { + viewHolder.read.setVisibility(View.VISIBLE); + viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views)); + } + NewsUtils.setNewsType(viewHolder.type, newsEntity.getType()); + } + + private void initFooterViewHolder(FooterViewHolder viewHolder) { + if (isNetworkError) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载失败,点击重试"); + viewHolder.itemView.setClickable(true); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isNetworkError = false; + notifyItemChanged(getItemCount() - 1); + addList(newsList.size()); + } + }); + } else if (isOver) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载完毕"); + viewHolder.itemView.setClickable(false); + } else { + viewHolder.loading.setVisibility(View.VISIBLE); + viewHolder.hint.setText("加载中..."); + viewHolder.itemView.setClickable(false); + } + } + + @Override + public int getItemCount() { + if (itemCount == 0) { + return 0; + } + return itemCount + 1; + } + + @Override + public int getItemViewType(int position) { + if (position == newsList.size()) { + return ItemViewType.LOADING; + } + NewsEntity newsEntity = newsList.get(position); + if ("4x3".equals(newsEntity.getThumbnail().getType()) && newsEntity.getThumbnail().getUrl().size() == 3){ + return ItemViewType.NEWS_IMAGE2; + } + if ("3x1".equals(newsEntity.getThumbnail().getType())) { + return ItemViewType.NEWS_IMAGE3; + } + return ItemViewType.NEWS_IMAGE1; + } + + // 统计新闻阅读量 + private void statNewsViews(final NewsEntity newsEntity, final int position) { + RetrofitManager.getData().postNewsViews(newsEntity.getId()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new JSONObjectResponse(){ + @Override + public void onResponse(JSONObject response) { + if (response.length() != 0) { + try { + if ("success".equals(response.getString("status"))) { + newsEntity.setViews(newsEntity.getViews() + 1); + + notifyItemChanged(position); + + // 更新okhttp缓存数据 + VisitManager.updateOkhttpCache(newsEntity.getId()); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + }); + } + + public boolean isOver() { + return isOver; + } + + public boolean isLoading() { + return isLoading; + } + + public boolean isNetworkError() { + return isNetworkError; + } + + public void setNetworkError(boolean networkError) { + isNetworkError = networkError; + } + + public int getNewsListSize() { + return newsList.size(); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java index e3273d4543..806b7171ee 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java @@ -9,13 +9,11 @@ import android.view.ViewGroup; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; import com.gh.common.util.GameUtils; import com.gh.common.util.GameViewUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.PlatformUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.download.DownloadManager; import com.gh.gamecenter.PluginActivity; import com.gh.gamecenter.R; @@ -139,19 +137,6 @@ public class PluginAdapter extends RecyclerView.Adapter if (holder instanceof GameNormalViewHolder) { final GameNormalViewHolder viewHolder = (GameNormalViewHolder) holder; - // 第一个 - if (position == 0) { - ((CardLinearLayout) viewHolder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); - } else { - ((CardLinearLayout) viewHolder.itemView).setmTop(0); - } - - // 最后一个 - if (position == pluginList.size() - 1) { - ((CardLinearLayout) viewHolder.itemView).setBottom(true); - } else { - ((CardLinearLayout) viewHolder.itemView).setBottom(false); - } final GameEntity gameEntity = pluginList.get(position); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/StrategyAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/StrategyAdapter.java index 8b19be6055..30eefa76c0 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/StrategyAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/StrategyAdapter.java @@ -7,9 +7,7 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import com.gh.common.util.DataUtils; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.NewsUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.R; import com.gh.gamecenter.StrategyActivity; import com.gh.gamecenter.adapter.viewholder.NewsFooterViewHolder; @@ -149,27 +147,6 @@ public class StrategyAdapter extends RecyclerView.Adapter(); isLoaded = false; isNetworkError = false; + isRemove = false; initList(1); } public void initList(final int page) { -// if (isLoaded) { //TODO 无法分页 -// return; -// } + isLoaded = false; RetrofitManager.getApi().getColumn(id, page) .map(new Func1, List>() { @@ -111,10 +109,21 @@ public class SubjectAdapter extends RecyclerView.Adapter { + + private Context mContext; + private OnSelectTypeListener listener; + private ArrayList mGameType; + private String mCurType; + + + public SubjectTypeAdapter(SubjectActivity subjectActivity, ArrayList gameType) { + this.mContext = subjectActivity; + this.listener = subjectActivity; + + mGameType = gameType; + mCurType = "全部"; + } + + public StateListDrawable selectorBg(){ + + StateListDrawable bg_install = new StateListDrawable(); + + bg_install.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, + new ColorDrawable(Color.parseColor("#59d3ff"))); + bg_install.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_enabled }, + new ColorDrawable(Color.parseColor("#00B7FA"))); + bg_install.addState(new int[] {}, new ColorDrawable(Color.WHITE)); + + return bg_install; + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + RelativeLayout relativeLayout = new RelativeLayout(mContext); + relativeLayout.setBackgroundColor(Color.parseColor("#ededed")); + TextView textView = new TextView(mContext); + textView.setTextSize(13); + textView.setBackgroundDrawable(selectorBg()); + textView.setTextColor(mContext.getResources().getColor(R.color.title)); + textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT + , DisplayUtils.dip2px(mContext, 36))); + textView.setGravity(Gravity.CENTER); +// textView.setBackgroundColor(Color.WHITE); + relativeLayout.addView(textView); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) textView.getLayoutParams(); + int dp = DisplayUtils.dip2px(mContext, 1); + int dp2 = DisplayUtils.dip2px(mContext, 0.5f); + layoutParams.setMargins(dp2, dp, dp2, 0); + return new GameTypeViewHolder(relativeLayout); + } + + @Override + public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) { + if (holder instanceof GameTypeViewHolder) { + final GameTypeViewHolder viewHolder = (GameTypeViewHolder) holder; + viewHolder.type.setText(mGameType.get(position)); + + if (!TextUtils.isEmpty(mCurType) && mCurType.equals(mGameType.get(position))) { + viewHolder.type.setSelected(true); + viewHolder.type.setTextColor(Color.WHITE); + + } else { + viewHolder.type.setSelected(false); + viewHolder.type.setTextColor(mContext.getResources().getColor(R.color.title)); + } + + ((GameTypeViewHolder) holder).type.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Utils.toast(mContext, mGameType.get(position)); + viewHolder.type.setSelected(true); + listener.onSelectType(mGameType.get(position)); + mCurType = mGameType.get(position); + notifyItemRangeChanged(0, getItemCount()); + } + }); + } + } + + @Override + public int getItemCount() { + return mGameType.size(); + } + + public class GameTypeViewHolder extends RecyclerView.ViewHolder { + private TextView type; + + public GameTypeViewHolder(View itemView) { + super(itemView); + type = (TextView) ((RelativeLayout)itemView).getChildAt(0); + } + } + + public interface OnSelectTypeListener { + void onSelectType(String type); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDownloadViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDownloadViewHolder.java index 7631396664..95824b8b31 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDownloadViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDownloadViewHolder.java @@ -21,6 +21,7 @@ public class GameDownloadViewHolder extends RecyclerView.ViewHolder { public TextView dm_item_tv_speed; public ProgressBar dm_item_progressbar; public TextView dm_item_tv_startorpause; + public View dm_item_line; public GameDownloadViewHolder(View itemView) { super(itemView); @@ -32,6 +33,7 @@ public class GameDownloadViewHolder extends RecyclerView.ViewHolder { dm_item_tv_speed = (TextView) itemView.findViewById(R.id.dm_item_tv_speed); dm_item_progressbar = (ProgressBar) itemView.findViewById(R.id.dm_item_progressbar); dm_item_tv_startorpause = (TextView) itemView.findViewById(R.id.dm_item_tv_startorpause); + dm_item_line = itemView.findViewById(R.id.dm_item_line); } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameHeadViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameHeadViewHolder.java index 4a0c915ac7..62fd5d44b4 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameHeadViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameHeadViewHolder.java @@ -3,7 +3,6 @@ package com.gh.gamecenter.adapter.viewholder; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -16,22 +15,20 @@ public class GameHeadViewHolder extends RecyclerView.ViewHolder { public ImageView thumb; public TextView title; - public LinearLayout link; public TextView more; public ProgressBar progressBar; - public ImageView moreIcon; public View line; + public View lineTop; public GameHeadViewHolder(View itemView) { super(itemView); this.thumb = (ImageView) itemView.findViewById(R.id.head_thumb); this.title = (TextView) itemView.findViewById(R.id.head_title); - this.link = (LinearLayout) itemView.findViewById(R.id.head_link); this.more = (TextView) itemView.findViewById(R.id.head_more); this.progressBar = (ProgressBar) itemView.findViewById(R.id.head_pb); - this.moreIcon = (ImageView) itemView.findViewById(R.id.head_more_icon); this.line = itemView.findViewById(R.id.head_line); + this.lineTop = itemView.findViewById(R.id.head_line_top); } } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameNormalSwipeViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameNormalSwipeViewHolder.java index afe2397acf..c14d5cfb11 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameNormalSwipeViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameNormalSwipeViewHolder.java @@ -7,7 +7,6 @@ import android.widget.ProgressBar; import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; -import com.gh.common.view.CardLinearLayout; import com.gh.common.view.SwipeLayout; import com.gh.gamecenter.R; @@ -18,7 +17,7 @@ import static com.gh.gamecenter.R.id.home1_game_order; */ public class GameNormalSwipeViewHolder extends GameViewHolder { - public CardLinearLayout cardView; + public LinearLayout cardView; public SwipeLayout swipeLayout; public TextView swipeText; public TextView swipeShareText; @@ -37,7 +36,7 @@ public class GameNormalSwipeViewHolder extends GameViewHolder { gameProgressbar = (ProgressBar) itemView.findViewById(R.id.home1_game_progressbar); gameDownloadSpeed = (TextView) itemView.findViewById(R.id.home1_download_speed); gameDownloadPercentage = (TextView) itemView.findViewById(R.id.home1_download_percentage); - cardView = (CardLinearLayout) itemView.findViewById(R.id.home1_game_card); + cardView = (LinearLayout) itemView.findViewById(R.id.home1_game_card); swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipeLayout); swipeText = (TextView) itemView.findViewById(R.id.swipe_text); swipeShareText = (TextView) itemView.findViewById(R.id.swipe_share_text); diff --git a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java index dbaac06ec7..74e442a9a4 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java @@ -20,15 +20,12 @@ import com.gh.common.constant.Constants; import com.gh.common.util.BitmapUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.FileUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.SpeedUtils; -import com.gh.common.view.CardLinearLayout; -import com.gh.common.view.CardRelativeLayout; import com.gh.download.DownloadEntity; import com.gh.download.DownloadManager; import com.gh.download.DownloadStatus; @@ -112,58 +109,22 @@ class GameDownloadFragmentAdapter extends RecyclerView.Adapter 0 && position <= doneList.size()) { downloadEntity = doneList.get(position - 1); -// // 第一个 -// if (position == 1) { -// ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); -// } else { -// ((CardLinearLayout) holder.itemView).setmTop(0); -// } - // 最后一个 if (position == doneList.size() && downloadingList.size() != 0) { - ((CardLinearLayout) holder.itemView).setBottom(false); - ((CardLinearLayout) holder.itemView).setmBottom(0); + viewHolder.dm_item_line.setVisibility(View.GONE); } else { - ((CardLinearLayout) holder.itemView).setBottom(true); - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); + viewHolder.dm_item_line.setVisibility(View.VISIBLE); } } else if (doneList.isEmpty()) { downloadEntity = downloadingList.get(position - 1); -// // 第一个 -// if (position == 1) { -// ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); -// } else { -// ((CardLinearLayout) holder.itemView).setmTop(0); -// } - - // 最后一个 - if (position == downloadingList.size()) { - ((CardLinearLayout) holder.itemView).setBottom(true); - } else { - ((CardLinearLayout) holder.itemView).setBottom(false); - } - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); + viewHolder.dm_item_line.setVisibility(View.VISIBLE); } else { downloadEntity = downloadingList.get(position - doneList.size() - 2); - -// // 第一个 -// if (position - doneList.size() - 2 == 0) { -// ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); -// } else { -// ((CardLinearLayout) holder.itemView).setmTop(0); -// } - - // 最后一个 - if (position - doneList.size() - 1 == downloadingList.size()) { - ((CardLinearLayout) holder.itemView).setBottom(true); - } else { - ((CardLinearLayout) holder.itemView).setBottom(false); - } - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); + viewHolder.dm_item_line.setVisibility(View.VISIBLE); } String icon = downloadEntity.getIcon(); - if (icon.contains("KuaiChuanIcon")) { // 来自快传的apk + if (!TextUtils.isEmpty(icon) && icon.contains("KuaiChuanIcon")) { // 来自快传的apk try { JSONObject jsonObject = new JSONObject(icon); String apkPath = jsonObject.getString("KuaiChuanIcon"); @@ -398,18 +359,18 @@ class GameDownloadFragmentAdapter extends RecyclerView.Adapter private boolean isInitPlugin; private boolean isAutoScroll; private int topHeight; - private int topHeightOld; GameFragmentAdapter(GameFragment fragment, SwipeRefreshLayout refreshLayout) { @@ -141,10 +138,8 @@ class GameFragmentAdapter extends RecyclerView.Adapter DisplayMetrics outMetrics = new DisplayMetrics(); fragment.getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); -// topHeight = (int) (outMetrics.widthPixels / 16f * 10f); //TODO 盖住轮播图比例 - topHeightOld = (int) (outMetrics.widthPixels / 16f * 10f); // 盖住轮播图比例时,记录初始大小 - topHeight = (int) (outMetrics.widthPixels / 16f * 11.4f); //TODO 不盖住轮播图比例 + topHeight = (int) (outMetrics.widthPixels / 16f * 10.5f); cardMargin = (int) context.getResources().getDimension(R.dimen.cardview_margin); @@ -521,7 +516,6 @@ class GameFragmentAdapter extends RecyclerView.Adapter R.layout.game_viewpager_item, parent, false); DisplayMetrics outMetrics = new DisplayMetrics(); fragment.getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); -// topHeight = (int) (outMetrics.widthPixels / 16f * 10f); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, topHeight); //整个头部大小16:10 viewpager大小16:7 view.setLayoutParams(params); @@ -531,17 +525,16 @@ class GameFragmentAdapter extends RecyclerView.Adapter ViewGroup.LayoutParams.MATCH_PARENT, (int) (outMetrics.widthPixels / 16f * 7f)); viewPager.setLayoutParams(vpParams); - CardRelativeLayout subjectRl = (CardRelativeLayout) view.findViewById(R.id.home_subject_rl); + RelativeLayout subjectRl = (RelativeLayout) view.findViewById(R.id.home_subject_rl); RelativeLayout.LayoutParams subjectParams = new RelativeLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, (int) (outMetrics.widthPixels / 16f * 4.4f)); + ViewGroup.LayoutParams.MATCH_PARENT, (int) (outMetrics.widthPixels / 16f * 3.5f)); subjectParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); subjectRl.setLayoutParams(subjectParams); LinearLayout hint = (LinearLayout) view.findViewById(R.id.viewpager_ll_hint); RelativeLayout.LayoutParams hintParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); -// hintParams.setMargins(0, (int) (outMetrics.widthPixels / 16f * 5.3f), 0, 0); // TODO 盖住轮播图点 比例 - hintParams.setMargins(0, (int) (outMetrics.widthPixels / 16f * 6.5f), DisplayUtils.dip2px(context, 010), 0); + hintParams.setMargins(0, (int) (outMetrics.widthPixels / 16f * 6.5f), DisplayUtils.dip2px(context, 10), 0); hintParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); hint.setLayoutParams(hintParams); @@ -685,7 +678,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter //初始化专题入口 viewHolder.subjectLl.removeAllViews(); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 6; i++) { final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); View contentView = View.inflate(context, R.layout.home_subject_entrance_item, null); TextView subjectName = (TextView) contentView.findViewById(R.id.home_subject_name); @@ -696,12 +689,15 @@ class GameFragmentAdapter extends RecyclerView.Adapter viewHolder.subjectLl.addView(contentView); if (subjectDigestList.size() == 3 && i < 3) { -// subjectIcon.setImageURI(subjectDigestList.get(i).getIcon()); ImageUtils.display(subjectIcon, subjectDigestList.get(i).getIcon()); subjectName.setText(subjectDigestList.get(i).getName()); } if (i == 3) { + + } + + if (i == 4) { subjectName.setText("礼包"); subjectIcon.setImageURI(Uri.parse("res:///" + R.drawable.home_entrance_libao)); if (sp.getBoolean("showGiftNewIcon", true)) { @@ -709,31 +705,31 @@ class GameFragmentAdapter extends RecyclerView.Adapter } } - if (i == 4) { - subjectName.setText("攻略"); - subjectIcon.setImageURI(Uri.parse("res:///" + R.drawable.home_entrance_strategy)); + if (i == 5) { + subjectName.setText("开服表"); + subjectIcon.setImageURI(Uri.parse("res:///" + R.drawable.home_entrance_kaifu)); } final int finalI = i; contentView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (finalI < 3 && !isSubjectDigestError) { + if (finalI < 4 && !isSubjectDigestError) { Intent intent = new Intent(context, SubjectActivity.class); intent.putExtra("id", subjectDigestList.get(finalI).getColumnId()); intent.putExtra("name", subjectDigestList.get(finalI).getColumnName()); intent.putExtra("order", subjectDigestList.get(finalI).getOrder()); intent.putExtra("entrance", "(游戏-专题:" + subjectDigestList.get(finalI).getName() + ")"); context.startActivity(intent); - } else if (finalI == 3) { + } else if (finalI == 4) { subjectNewIcon.setVisibility(View.GONE); sp.edit().putBoolean("showGiftNewIcon", false).apply(); Intent intent = new Intent(context, LibaoActivity.class); intent.putExtra("entrance", "(游戏-专题:礼包)"); context.startActivity(intent); - } else if (finalI == 4){ - Intent intent = new Intent(context, StrategyActivity.class); - intent.putExtra("entrance", "(游戏-专题:攻略)"); + } else if (finalI == 5){ + Intent intent = new Intent(context, KaiFuActivity.class); + intent.putExtra("entrance", "(游戏-专题:开服表)"); context.startActivity(intent); } else { Utils.toast(context, "数据异常"); @@ -757,7 +753,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter if (subjectList.get(i).getData().get(0).getImage() != null) { order--; } - initGameTest(holder, gameEntity, order, subjectList.get(i), i + 1 == size); + initGameTest(holder, gameEntity, order, subjectList.get(i)); break; } } @@ -766,23 +762,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter } private void initGameTest(GameTestViewHolder holder, final GameEntity gameEntity, - final int i, final SubjectEntity subjectEntity, boolean isBottom) { - - // 最后一个 - ((CardLinearLayout) holder.itemView).setBottom(isBottom); - if (TextUtils.isEmpty(subjectEntity.getData().get(0).getImage())) { - if (i + 1 == subjectEntity.getData().size()) { - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); - } else { - ((CardLinearLayout) holder.itemView).setmBottom(0); - } - } else { - if (i + 2 == subjectEntity.getData().size()) { - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); - } else { - ((CardLinearLayout) holder.itemView).setmBottom(0); - } - } + final int i, final SubjectEntity subjectEntity) { if (subjectEntity.isOrder()) { holder.gameOrder.setVisibility(View.VISIBLE); @@ -791,7 +771,6 @@ class GameFragmentAdapter extends RecyclerView.Adapter holder.gameOrder.setVisibility(View.GONE); } -// holder.gameThumb.setImageURI(gameEntity.getIcon()); ImageUtils.display(holder.gameThumb, gameEntity.getIcon()); holder.gameName.setText(gameEntity.getName()); if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { @@ -846,7 +825,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter subjectEntity.setOrder(false); subjectEntity.setName("插件化"); subjectEntity.setData(pluginList); - initGameNormal(holder, gameEntity, position - 2, subjectEntity, false); + initGameNormal(holder, gameEntity, position - 2, subjectEntity); return; } @@ -866,7 +845,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter if (subjectList.get(i).getData().get(0).getImage() != null) { order--; } - initGameNormal(holder, gameEntity, order, subjectList.get(i), i + 1 == size); + initGameNormal(holder, gameEntity, order, subjectList.get(i)); break; } } @@ -875,23 +854,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter } private void initGameNormal(GameNormalViewHolder holder, final GameEntity gameEntity, - final int i, final SubjectEntity subjectEntity, boolean isBottom) { - - // 最后一个 - ((CardLinearLayout) holder.itemView).setBottom(isBottom); - if (TextUtils.isEmpty(subjectEntity.getData().get(0).getImage())) { - if (i + 1 == subjectEntity.getData().size()) { - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); - } else { - ((CardLinearLayout) holder.itemView).setmBottom(0); - } - } else { - if (i + 2 == subjectEntity.getData().size()) { - ((CardLinearLayout) holder.itemView).setmBottom(cardMargin); - } else { - ((CardLinearLayout) holder.itemView).setmBottom(0); - } - } + final int i, final SubjectEntity subjectEntity) { if (subjectEntity.isOrder()) { holder.gameOrder.setVisibility(View.VISIBLE); @@ -899,7 +862,7 @@ class GameFragmentAdapter extends RecyclerView.Adapter } else { holder.gameOrder.setVisibility(View.GONE); } -// holder.gameThumb.setImageURI(gameEntity.getIcon()); + ImageUtils.display(holder.gameThumb, gameEntity.getIcon()); if (gameEntity.isPluggable()) { holder.gameName.setText(String.format("%s - %s", gameEntity.getName(), @@ -954,11 +917,6 @@ class GameFragmentAdapter extends RecyclerView.Adapter } gameEntity = subjectList.get(i).getData().get(index); if (position == offset && !TextUtils.isEmpty(gameEntity.getImage())) { - if (i == 0 && position != 1 && pluginList.isEmpty()) { - ((CardLinearLayout) holder.itemView).setmTop(cardMargin); - } else { - ((CardLinearLayout) holder.itemView).setmTop(0); - } final GameEntity entity = gameEntity; final String name = subjectList.get(i).getName(); @@ -1004,17 +962,16 @@ class GameFragmentAdapter extends RecyclerView.Adapter private void initGameHeadViewHolder(final GameHeadViewHolder holder, int position) { if (!pluginList.isEmpty() && position == 1) { -// ((CardLinearLayout) holder.itemView).setmTop(cardMargin); holder.title.setTextColor(context.getResources().getColor(R.color.theme)); holder.thumb.setVisibility(View.VISIBLE); holder.line.setVisibility(View.GONE); holder.thumb.setImageResource(R.drawable.home_plug_upgrade); holder.title.setText(String.format(Locale.getDefault(), "你有%d个游戏可以升级插件版", pluginSize)); if (pluginSize <= 2) { - holder.link.setVisibility(View.GONE); + holder.more.setVisibility(View.GONE); } else { - holder.link.setVisibility(View.VISIBLE); - holder.link.setOnClickListener(new View.OnClickListener() { + holder.more.setVisibility(View.VISIBLE); + holder.more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, PluginActivity.class); @@ -1037,36 +994,35 @@ class GameFragmentAdapter extends RecyclerView.Adapter if (index < 0){ index = 0; } + + if (TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())) { + holder.lineTop.setVisibility(View.VISIBLE); + } else { + holder.lineTop.setVisibility(View.GONE); + } + gameEntity = subjectList.get(i).getData().get(index); if (position == offset && TextUtils.isEmpty(gameEntity.getImage()) || position == offset + 1 && !TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())) { - if (TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage()) - && pluginList.isEmpty() && i == 0 && position != 1) { - ((CardLinearLayout) holder.itemView).setmTop(cardMargin); - } else { - ((CardLinearLayout) holder.itemView).setmTop(0); - } holder.thumb.setVisibility(View.GONE); holder.line.setVisibility(View.VISIBLE); holder.title.setText(subjectList.get(i).getName()); holder.title.setTextColor(Color.BLACK); final int ii = i; if (subjectList.get(i).getData().size() >= Integer.parseInt(subjectList.get(i).getMore())){ - holder.link.setVisibility(View.GONE); + holder.more.setVisibility(View.GONE); }else { - holder.link.setVisibility(View.VISIBLE); + holder.more.setVisibility(View.VISIBLE); if (subjectList.get(i).getHome().equals("change")) { holder.more.setText("换一批"); holder.more.setTextColor(context.getResources().getColor(R.color.theme)); - holder.moreIcon.setVisibility(View.GONE); } else { holder.more.setText("全部"); holder.more.setTextColor(Color.parseColor("#676767")); - holder.moreIcon.setVisibility(View.VISIBLE); } } - holder.link.setOnClickListener(new View.OnClickListener() { + holder.more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SubjectEntity subjectEntity = subjectList.get(ii); @@ -1184,34 +1140,6 @@ class GameFragmentAdapter extends RecyclerView.Adapter } } - //轮播图和入口刷新 - void stretchTop(int offset, boolean isInit) { - if (isInit) { - while (true) { - if (topHeight > topHeightOld) { - topHeight = topHeight - 2; - notifyItemChanged(0); - } else { - return; - } - } - } - - topHeight = topHeight + offset; - if (topHeight > topHeightOld) { - notifyItemChanged(0); - } else { - topHeight = topHeight - offset; - } - - } - - float getDragPercent() { - int offset = topHeight - topHeightOld; - float distance = (float) (offset * 3) / (float) topHeightOld; - return (float) (1.0 - distance); - } - void startAutoScroll() { isAutoScroll = true; notifyItemChanged(0); diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java index 616ef0f633..e89f6f99b9 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java @@ -62,7 +62,6 @@ import java.util.Map; import okhttp3.ResponseBody; import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; import rx.functions.Func1; import rx.schedulers.Schedulers; @@ -210,9 +209,10 @@ public class GameDetailAdapter extends RecyclerView.Adapter { }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Action1() { + .subscribe(new Response(){ @Override - public void call(Object o) { + public void onResponse(Object response) { + super.onResponse(response); notifyDataSetChanged(); } }); diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java b/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java index ce7bcde81c..1922ca4461 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java @@ -13,6 +13,7 @@ import android.widget.TextView; import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.BaseFragment; import com.gh.common.view.SwipeLayout; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.R; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBUISwitch; @@ -76,6 +77,7 @@ public class Libao1Fragment extends BaseFragment implements SwipeRefreshLayout.O mRecyclerView.setLayoutManager(mLayoutManager); adapter = new Libao1FragmentAdapter(Libao1Fragment.this, mIsSearch, mSearckKey); mNormalAdapter = adapter; + mRecyclerView.addItemDecoration(new VerticalItemDecoration(getContext(), 8, false)); mRecyclerView.setAdapter(adapter); historyAdapter = new LibaoHistoryAdapter(this); diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java index 206b3b207e..563dbdfe96 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java @@ -11,12 +11,10 @@ import android.view.inputmethod.InputMethodManager; import com.gh.base.AppController; import com.gh.common.constant.ItemViewType; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.LibaoUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.Utils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.LibaoDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; @@ -312,12 +310,6 @@ class Libao1FragmentAdapter extends RecyclerView.Adapter list = dao.getClickData(); - if (!list.isEmpty()) { + if (list != null && !list.isEmpty()) { List ids = new ArrayList<>(); List data = new ArrayList<>(); try { @@ -184,7 +184,7 @@ public class DataCollectionManager { public void upload() { statClickData(); List list = dao.getAll(); - if (!list.isEmpty()) { + if (list != null && !list.isEmpty()) { try { upload(list, true); } catch (JSONException e) { diff --git a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java index 945d6066d1..80b6e90698 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java @@ -324,7 +324,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter) response; + libaoStatusList.addAll((List)response); notifyDataSetChanged(); } diff --git a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java index b0cb32fb96..6000829e64 100644 --- a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java @@ -33,7 +33,6 @@ import com.gh.common.util.NewsUtils; import com.gh.common.util.PostCommentUtils; import com.gh.common.util.RandomUtils; import com.gh.common.util.Utils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.MessageDetailActivity; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; @@ -310,9 +309,6 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { for (final CommentEntity commentEntity : commentList) { View contentView = View.inflate(context, R.layout.comment_item, null); - ((CardLinearLayout)contentView).setmLeft(0); - ((CardLinearLayout)contentView).setmRight(0); - final TextView likeCount = (TextView) contentView.findViewById(R.id.comment_like_count); TextView content = (TextView) contentView.findViewById(R.id.comment_content); TextView time = (TextView) contentView.findViewById(R.id.comment_time); diff --git a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragment.java b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragment.java index e28b799147..03483c6315 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragment.java @@ -10,6 +10,7 @@ import android.widget.TextView; import com.gh.base.BaseFragment; import com.gh.common.util.DownloadItemUtils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.download.DataWatcher; import com.gh.download.DownloadEntity; import com.gh.download.DownloadManager; @@ -73,6 +74,7 @@ public class ConcernFragment extends BaseFragment { }); fm_concern_rv_show.setHasFixedSize(true); + fm_concern_rv_show.addItemDecoration(new VerticalItemDecoration(getActivity(), 8, true)); fm_concern_rv_show.setLayoutManager(new LinearLayoutManager(getActivity())); adapter = new ConcernFragmentAdapter(this); fm_concern_rv_show.setAdapter(adapter); diff --git a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java index 6aae1932a2..8830fa478d 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java @@ -14,7 +14,6 @@ import com.gh.common.util.DownloadItemUtils; import com.gh.common.util.GameUtils; import com.gh.common.util.GameViewUtils; import com.gh.common.util.ImageUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.download.DownloadManager; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; @@ -190,21 +189,6 @@ class ConcernFragmentAdapter extends RecyclerView.Adapter> getSearchHints(); // 获取搜索关键字 + Observable> getSearchHints(); // 获取搜索关键字 @GET("support/upgrade") Observable getUpdate(@Query("version") String version, @Query("channel") String channel); // 获取助手更新 @@ -164,4 +165,12 @@ public interface ApiService { @GET("game/digest/tags") Observable> getTags(); //获取游戏的所有标签 + @GET("search/game/remen") + Observable getHotSearch(); // 获取热门搜索 + + @GET("game/server/offset") + Observable getKaiFuOffset(@Query("type") String type); // 获取开服表偏移量 + + @GET("game/server") + Observable> getKaiFuData(@Query("type") String type, @Query("offset") int offset, @Query("limit") int limit); // 获取开服表数据 } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragment.java b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragment.java index 604b298792..91ccde3f8e 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragment.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragment.java @@ -1,15 +1,20 @@ package com.gh.gamecenter.search; +import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.gh.base.BaseFragment; +import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; +import com.gh.common.util.Utils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.download.DataWatcher; import com.gh.download.DownloadEntity; import com.gh.download.DownloadManager; @@ -57,10 +62,31 @@ public class SearchGameDetailFragment extends BaseFragment implements OnCallBack init(R.layout.fm_search); + LinearLayout reuse_none_data = (LinearLayout) view.findViewById(R.id.reuse_none_data); + TextView skip_tv = new TextView(getContext()); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DisplayUtils.dip2px(getContext(), 140) + , DisplayUtils.dip2px(getContext(), 40)); + params.setMargins(0, DisplayUtils.dip2px(getContext(), 40), 0, 0); + skip_tv.setLayoutParams(params); + skip_tv.setGravity(Gravity.CENTER); + skip_tv.setText("告诉小编"); + skip_tv.setTextColor(Color.WHITE); + skip_tv.setBackgroundResource(R.drawable.textview_blue_style); + reuse_none_data.addView(skip_tv); + + skip_tv.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Utils.toast(getContext(), "跳转"); + } + }); + + TextView reuse_tv_none_data = (TextView) view.findViewById(R.id.reuse_tv_none_data); reuse_tv_none_data.setText("搜索结果为空"); search_detail.setHasFixedSize(true); + search_detail.addItemDecoration(new VerticalItemDecoration(getContext(), 8, true)); search_detail.setLayoutManager(new LinearLayoutManager(getActivity())); adapter = new SearchGameDetailFragmentAdapter(SearchGameDetailFragment.this, key); search_detail.setAdapter(adapter); diff --git a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java index 178e3ce7a7..686a36d3a9 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java @@ -11,12 +11,10 @@ import android.view.ViewGroup; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; import com.gh.common.util.GameUtils; import com.gh.common.util.GameViewUtils; import com.gh.common.util.ImageUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder; import com.gh.gamecenter.entity.ApkEntity; @@ -132,21 +130,6 @@ class SearchGameDetailFragmentAdapter extends RecyclerView.Adapter mHistorylist; + + private List mHotlist; + + private SearchHistoryFragmentAdapter mHistoryadapter; + + private boolean isDestroy; + + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - view = View.inflate(getActivity(), R.layout.fm_search_history, null); + ButterKnife.bind(this, view); - RecyclerView search_history = (RecyclerView) view.findViewById(R.id.search_history); - search_history.setHasFixedSize(true); - search_history.setLayoutManager(new LinearLayoutManager(getActivity())); - search_history.setAdapter(new SearchHistoryFragmentAdapter(getActivity())); + isDestroy = false; + mHotlist = new ArrayList<>(); + + dao = new SearchHistoryDao(getContext()); + mHistorylist = dao.getAll(); + if (mHistorylist == null) { + mHistorylist = new ArrayList<>(); + } else if (mHistorylist != null && mHistorylist.size() > 0) { + mSearchHistoryRl.setVisibility(View.VISIBLE); + } + + mSearchHistoryRv.setHasFixedSize(true); + mSearchHistoryRv.setLayoutManager(new GridLayoutManager(getActivity(), 3){ + @Override + public boolean canScrollVertically() { + return false; + } + }); + mHistoryadapter = new SearchHistoryFragmentAdapter(getActivity(), mHistorylist, dao, true); + mSearchHistoryRv.setAdapter(mHistoryadapter); + ViewGroup.LayoutParams params = mSearchHistoryRv.getLayoutParams(); + params.height = (int) Math.ceil(mHistorylist.size() / 3f) * DisplayUtils.dip2px(getContext(), 42); + mSearchHistoryRv.setLayoutParams(params); + + mSearchHotRv.setHasFixedSize(true); + mSearchHotRv.setLayoutManager(new GridLayoutManager(getActivity(), 3){ + @Override + public boolean canScrollVertically() { + return false; + } + }); + mSearchHotRv.setAdapter(new SearchHistoryFragmentAdapter(getActivity(), mHotlist, dao, false)); + ViewGroup.LayoutParams params2 = mSearchHotRv.getLayoutParams(); + params2.height = (int) Math.ceil(mHotlist.size() / 3f) * DisplayUtils.dip2px(getContext(), 42); + mSearchHotRv.setLayoutParams(params2); + + loadSearchHotData(); + } + + private void loadSearchHotData() { + + RetrofitManager + .getApi() + .getHotSearch().subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new JSONArrayResponse(){ + @Override + public void onResponse(JSONArray response) { + super.onResponse(response); + + JSONArray jsonArray = response; + for (int i = 0; i < jsonArray.length(); i++) { + try { + mHotlist.add((String) jsonArray.get(i)); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + if (mHotlist.size() == 0 || isDestroy) return; + + mSearchHotTv.setVisibility(View.VISIBLE); + mSearchHotRv.setAdapter(new SearchHistoryFragmentAdapter(getActivity(), mHotlist, dao, false)); + ViewGroup.LayoutParams params2 = mSearchHotRv.getLayoutParams(); + params2.height = (int) Math.ceil(mHotlist.size() / 3f) * DisplayUtils.dip2px(getContext(), 42); + mSearchHotRv.setLayoutParams(params2); + } + }); } @Nullable @@ -37,4 +136,26 @@ public class SearchHistoryFragment extends Fragment { return view; } + @OnClick(R.id.search_history_clean) + public void onDeleteClick() { + DialogUtils.showWarningDialog(getActivity(), "清空记录", "确定清空历史搜索记录?", + new DialogUtils.ConfiremListener() { + @Override + public void onConfirem() { + dao.deleteAll(); + mHistoryadapter.clearSearchResult(); + mSearchHistoryRl.setVisibility(View.GONE); + mSearchHistoryRv.setAdapter(mHistoryadapter); + ViewGroup.LayoutParams params = mSearchHistoryRv.getLayoutParams(); + params.height = 0; + mSearchHistoryRv.setLayoutParams(params); + } + }); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + isDestroy = true; + } } diff --git a/app/src/main/java/com/gh/gamecenter/search/SearchHistoryFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/search/SearchHistoryFragmentAdapter.java index 16de20cb1d..677658f82c 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchHistoryFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchHistoryFragmentAdapter.java @@ -1,24 +1,21 @@ package com.gh.gamecenter.search; import android.content.Context; +import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; -import android.view.LayoutInflater; +import android.text.TextUtils; +import android.view.Gravity; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; -import com.gh.common.constant.ItemViewType; -import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; -import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.R; -import com.gh.gamecenter.adapter.viewholder.ReuseViewHolder; -import com.gh.gamecenter.adapter.viewholder.SearchHistoryViewHolder; import com.gh.gamecenter.db.SearchHistoryDao; import com.gh.gamecenter.eventbus.EBSearch; -import java.util.ArrayList; import java.util.List; import de.greenrobot.event.EventBus; @@ -31,18 +28,18 @@ class SearchHistoryFragmentAdapter extends RecyclerView.Adapter { private List historyList; - SearchHistoryFragmentAdapter(Context context) { + private boolean mIsHistory; + + SearchHistoryFragmentAdapter(Context context, List list, SearchHistoryDao dao, boolean isHistory) { this.context = context; + this.dao = dao; + this.historyList = list; + this.mIsHistory = isHistory; - dao = new SearchHistoryDao(context); - historyList = dao.getAll(); - if (historyList == null) { - historyList = new ArrayList<>(); - } } - private void clearSearchResult() { + public void clearSearchResult() { if (historyList != null) { historyList.clear(); } @@ -54,79 +51,58 @@ class SearchHistoryFragmentAdapter extends RecyclerView.Adapter { if (historyList.isEmpty()) { return 0; } - return historyList.size() + 1; + return historyList.size(); } - @Override - public int getItemViewType(int position) { - if (position == historyList.size()) { - return ItemViewType.SEARCH_DELETE; - } else { - return ItemViewType.SEARCH_NORMAL; - } - } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - if (viewType == ItemViewType.SEARCH_DELETE) { - View itemView = LayoutInflater.from(context).inflate( - R.layout.fm_search_history_delete_item, viewGroup, false); - return new ReuseViewHolder(itemView); - } else if (viewType == ItemViewType.SEARCH_NORMAL) { - View view = LayoutInflater.from(context).inflate( - R.layout.fm_search_history_item, viewGroup, false); - return new SearchHistoryViewHolder(view); - } - return null; + TextView textView = new TextView(context); + textView.setSingleLine(); + textView.setEllipsize(TextUtils.TruncateAt.END); + textView.setTextSize(13); + textView.setPadding(DisplayUtils.dip2px(context, 10), 0, DisplayUtils.dip2px(context, 10), 0); + textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT + , DisplayUtils.dip2px(context, 42))); + textView.setGravity(Gravity.CENTER_VERTICAL); + textView.setBackgroundResource(R.drawable.reuse_listview_item_style); + return new TextViewHolder(textView); } @Override - public void onBindViewHolder(ViewHolder holder, int position) { - if (holder instanceof SearchHistoryViewHolder) { - final SearchHistoryViewHolder viewHolder = (SearchHistoryViewHolder) holder; + public void onBindViewHolder(final ViewHolder holder, int position) { - // 第一个 - if (position == 0) { - ((CardLinearLayout) viewHolder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); - viewHolder.search_history_line.setVisibility(View.GONE); + if (holder instanceof TextViewHolder) { + final TextViewHolder viewHolder = (TextViewHolder) holder; + viewHolder.textView.setText(historyList.get(position)); + + if (!mIsHistory && position < 3) { + viewHolder.textView.setTextColor(Color.parseColor("#FDA34D")); } else { - ((CardLinearLayout) viewHolder.itemView).setmTop(0); - viewHolder.search_history_line.setVisibility(View.VISIBLE); + viewHolder.textView.setTextColor(context.getResources().getColor(R.color.title)); } - // 最后一个 - if (position + 1 == historyList.size()) { - ((CardLinearLayout) viewHolder.itemView).setmBottom(DisplayUtils.dip2px(context, 8)); - ((CardLinearLayout) viewHolder.itemView).setBottom(false); - } else { - ((CardLinearLayout) viewHolder.itemView).setmBottom(0); - ((CardLinearLayout) viewHolder.itemView).setBottom(false); - } - - viewHolder.search_history_name.setText(historyList.get(position)); - viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - String key = viewHolder.search_history_name.getText().toString(); + String key = (viewHolder.textView.getText().toString()); EventBus.getDefault().post(new EBSearch(key, true)); - dao.add(viewHolder.search_history_name.getText().toString()); - } - }); - } else if (holder instanceof ReuseViewHolder) { - holder.itemView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DialogUtils.showWarningDialog(context, "清空记录", "确定清空历史搜索记录?", - new DialogUtils.ConfiremListener() { - @Override - public void onConfirem() { - dao.deleteAll(); - clearSearchResult(); - } - }); + if (!mIsHistory) { + dao.add(key); + } } }); } } + public class TextViewHolder extends RecyclerView.ViewHolder { + + private TextView textView; + + public TextViewHolder(View itemView) { + super(itemView); + textView = (TextView) itemView; + } + } + } diff --git a/app/src/main/java/com/gh/gamecenter/zixun/ZiXunAdapter.java b/app/src/main/java/com/gh/gamecenter/zixun/ZiXunAdapter.java new file mode 100644 index 0000000000..881b8546c4 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/zixun/ZiXunAdapter.java @@ -0,0 +1,826 @@ +package com.gh.gamecenter.zixun; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.widget.RecyclerView; +import android.text.Html; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import com.gh.base.AppController; +import com.gh.common.constant.ItemViewType; +import com.gh.common.util.ConcernContentUtils; +import com.gh.common.util.ConcernUtils; +import com.gh.common.util.DataCollectionUtils; +import com.gh.common.util.DataUtils; +import com.gh.common.util.DisplayUtils; +import com.gh.common.util.ImageUtils; +import com.gh.common.util.LibaoUtils; +import com.gh.common.util.MD5Utils; +import com.gh.common.util.NewsUtils; +import com.gh.common.util.PlatformUtils; +import com.gh.common.util.Utils; +import com.gh.gamecenter.LibaoDetailActivity; +import com.gh.gamecenter.MessageDetailActivity; +import com.gh.gamecenter.NewsDetailActivity; +import com.gh.gamecenter.NewsNormalActivity; +import com.gh.gamecenter.R; +import com.gh.gamecenter.ShareCardActivity; +import com.gh.gamecenter.ShareCardPicActivity; +import com.gh.gamecenter.StrategyActivity; +import com.gh.gamecenter.WebActivity; +import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; +import com.gh.gamecenter.adapter.viewholder.NewsDigestViewHolder; +import com.gh.gamecenter.db.LibaoDao; +import com.gh.gamecenter.db.info.ConcernInfo; +import com.gh.gamecenter.db.info.LibaoInfo; +import com.gh.gamecenter.entity.CommentnumEntity; +import com.gh.gamecenter.entity.ConcernEntity; +import com.gh.gamecenter.entity.LibaoEntity; +import com.gh.gamecenter.entity.LibaoStatusEntity; +import com.gh.gamecenter.entity.ViewsEntity; +import com.gh.gamecenter.listener.OnCallBackListener; +import com.gh.gamecenter.manager.CommentManager; +import com.gh.gamecenter.manager.ConcernManager; +import com.gh.gamecenter.manager.VisitManager; +import com.gh.gamecenter.retrofit.JSONObjectResponse; +import com.gh.gamecenter.retrofit.ObservableUtil; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import retrofit2.adapter.rxjava.HttpException; +import rx.Observable; +import rx.Subscriber; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; +import rx.functions.Func1; +import rx.schedulers.Schedulers; + +/** + * Created by khy on 2017/3/15. + */ +public class ZiXunAdapter extends RecyclerView.Adapter { + + + private ZiXunFragment fragment; + private Context context; + + private OnCallBackListener listener; + + private List concernList; + private List gameIdList; + private List libaoStatusList; + + private List libaoInfo; + private LibaoDao libaoDao; + + private String key; + private String ids; + + private int itemCount; + private int skipPosition; + + private int cardMargin; + + private boolean isLoading; + private boolean isOver; + private boolean isNetworkError; + + public ZiXunAdapter(ZiXunFragment fragment) { + this.fragment = fragment; + this.context = fragment.getActivity(); + this.listener = fragment; + + concernList = new ArrayList<>(); + gameIdList = new ArrayList<>(); + libaoStatusList = new ArrayList<>(); + + itemCount = 0; + skipPosition = -1; + + isNetworkError = false; + isOver = false; + isLoading = false; + + libaoDao = new LibaoDao(context); + libaoInfo = libaoDao.getAll(); + + cardMargin = (int) context.getResources().getDimension(R.dimen.cardview_margin); + + addList(0); + } + + // 加载数据 + public void addList(final int offset) { + if (isLoading) { + return; + } + isLoading = true; + if (TextUtils.isEmpty(key) || TextUtils.isEmpty(ids)) { + ObservableUtil.computation(new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + ConcernManager concernManager = new ConcernManager(context); + List concernList = concernManager.getConcernGame(); + if (concernList == null || concernList.isEmpty()) { + subscriber.onNext(null); + } else { + for (ConcernInfo concernInfo : concernList) { + gameIdList.add(concernInfo.getId()); + } + + // 对数据进行排序 + Collections.sort(gameIdList, new Comparator() { + @Override + public int compare(String lhs, String rhs) { + return lhs.compareTo(rhs); + } + }); + + StringBuilder keyBuilder = new StringBuilder(); + StringBuilder idsBuilder = new StringBuilder(); + for (int i = 0; i < gameIdList.size(); i++) { + keyBuilder.append(gameIdList.get(i)); + if (i < 5) { + idsBuilder.append(gameIdList.get(i)); + idsBuilder.append("-"); + } + } + key = MD5Utils.getContentMD5(keyBuilder.toString()); + ids = idsBuilder.substring(0, idsBuilder.length() - 1); + subscriber.onNext(""); + } + subscriber.onCompleted(); + } + }, new Action1() { + @Override + public void call(String s) { + if (s == null) { + listener.loadEmpty(); + } else { + loadDataByKey(offset); + } + } + }); + } else { + loadDataByKey(offset); + } + } + + private void loadDataByKey(final int offset) { + RetrofitManager.getApi() + .getGuanZhuByKey(key, offset) + .map(new Func1, List>() { + @Override + public List call(List list) { + // 去除重复数据 + return removeDuplicateData(concernList, list); + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + isLoading = false; + + if (response.size() != 0) { + concernList.addAll(response); + itemCount += response.size(); + if (!fragment.isHidden() && !fragment.isEverpause()) { + notifyItemRangeInserted(concernList.size() - response.size() + 1, response.size()); + } else { + notifyDataSetChanged(); + } + + getLibaoStatus(response); + getNewsViews(response, offset); + getNewsCommentnum(response, offset); + + } else { + isOver = true; + notifyItemChanged(getItemCount() - 1); + } + + if (offset == 0 && listener != null) { + if (concernList.isEmpty()) { + listener.loadEmpty(); + } else { + listener.loadDone(); + } + } + } + + @Override + public void onFailure(HttpException e) { + if (e != null && e.code() == 409) { + loadDataByGameId(offset); + ConcernUtils.updateConcernData(context, new JSONArray(gameIdList)); + return; + } + + isLoading = false; + + // 网络错误 + if (offset == 0) { + if (listener != null) { + listener.loadError(); + } + } else { + Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + isNetworkError = true; + notifyItemChanged(getItemCount() - 1); + } + } + }); + } + + private void loadDataByGameId(final int offset) { + RetrofitManager.getApi() + .getGuanZhuById(ids, offset) + .map(new Func1, List>() { + @Override + public List call(List list) { + // 去除重复数据 + return removeDuplicateData(concernList, list); + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + isLoading = false; + + if (response.size() != 0) { + concernList.addAll(response); + itemCount += response.size(); + if (!fragment.isHidden() && !fragment.isEverpause()) { + notifyItemRangeInserted(concernList.size() - response.size() + 1, response.size()); + } else { + notifyDataSetChanged(); + } + + getNewsViews(response, offset); + getNewsCommentnum(response, offset); + getLibaoStatus(response); + } else { + isOver = true; + notifyItemChanged(getItemCount() - 1); + } + + if (offset == 0 && listener != null) { + if (concernList.isEmpty()) { + listener.loadEmpty(); + } else { + listener.loadDone(); + } + } + } + + @Override + public void onFailure(HttpException e) { + isLoading = false; + + // 网络错误 + if (offset == 0) { + if (listener != null) { + listener.loadError(); + } + } else { + Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + isNetworkError = true; + notifyItemChanged(getItemCount() - 1); + } + } + }); + } + + //获取礼包状态 + private void getLibaoStatus(List response) { + StringBuilder builder = new StringBuilder(); + for (int i = 0, size = response.size(); i < size; i++) { + if ("libao".equals(response.get(i).getType())){ + builder.append(response.get(i).getId()); + builder.append("-"); + } + } + if (builder.length() == 0) return; + builder.deleteCharAt(builder.length() - 1); + String ids = builder.toString(); + + LibaoUtils.getLibaoStatus(ids, new LibaoUtils.PostLibaoListener() { + @Override + public void postSucced(Object response) { + libaoStatusList.addAll((List) response); + notifyDataSetChanged(); + } + + @Override + public void postFailed(Throwable error) { + + } + }); + } + + + // 去除重复数据 + private static List removeDuplicateData(List sourceList, List rawList) { + if (sourceList == null || sourceList.isEmpty() + || rawList == null || rawList.isEmpty()) { + return rawList; + } + String id; + for (int i = 0; i < rawList.size(); i++) { + id = rawList.get(i).getId(); + for (ConcernEntity concernEntity : sourceList) { + if (id.equals(concernEntity.getId())) { + rawList.remove(i); + i--; + break; + } + } + } + return rawList; + } + + // 获取新闻阅读量 + private void getNewsViews(final List list, final int start) { + if (list == null || list.isEmpty()) { + return; + } + ObservableUtil.computation(new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + StringBuilder builder = new StringBuilder(); + for (int i = 0, size = list.size(); i < size; i++) { + builder.append(list.get(i).getId()); + builder.append("-"); + } + builder.deleteCharAt(builder.length() - 1); + String ids = builder.toString(); + VisitManager.getInstance().addUrl(ids); + subscriber.onNext(ids); + subscriber.onCompleted(); + } + }, new Action1() { + @Override + public void call(String ids) { + RetrofitManager.getData() + .getNewsViews(ids) + .map(new Func1, String>() { + @Override + public String call(List list) { + for (ViewsEntity viewsEntity : list) { + for (ConcernEntity concernEntity : concernList) { + if (viewsEntity.getId().equals(concernEntity.getId())) { + concernEntity.setViews(viewsEntity.getViews()); + break; + } + } + } + return null; + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(String response) { + notifyItemRangeChanged(start, list.size()); + } + }); + } + }); + } + + // 获取新闻评论数 + private void getNewsCommentnum(final List list, final int start) { + if (list == null || list.isEmpty()) { + return; + } + ObservableUtil.computation(new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + StringBuilder builder = new StringBuilder(); + for (int i = 0, size = list.size(); i < size; i++) { + builder.append(list.get(i).getId()); + builder.append("-"); + } + builder.deleteCharAt(builder.length() - 1); + CommentManager.getInstance().addUrl(builder.toString()); + subscriber.onNext(builder.toString()); + subscriber.onCompleted(); + } + }, new Action1() { + @Override + public void call(String ids) { + RetrofitManager.getComment() + .getNewsCommentnum(ids) + .map(new Func1, String>() { + @Override + public String call(List list) { + for (CommentnumEntity commentnumEntity : list) { + for (ConcernEntity concernEntity : concernList) { + if (commentnumEntity.getId().equals(concernEntity.getId())) { + concernEntity.setCommentnum(commentnumEntity.getNum()); + break; + } + } + } + return null; + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(String response) { + notifyItemRangeChanged(start, list.size()); + } + }); + } + }); + } + + // 统计新闻阅读量 + private void statNewsViews(final ConcernEntity concernEntity, final int position) { + RetrofitManager.getData().postNewsViews(concernEntity.getId()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new JSONObjectResponse(){ + @Override + public void onResponse(JSONObject response) { + if (response.length() != 0) { + try { + if ("success".equals(response.getString("status"))) { + concernEntity.setViews(concernEntity.getViews() + 1); + + notifyItemChanged(position); + + // 更新okhttp缓存数据 + VisitManager.updateOkhttpCache(concernEntity.getId()); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + }); + } + + @Override + public int getItemViewType(int position) { + + if (position == 0){ + return ItemViewType.ZIXUNTOP_TOP; + } else if (position - 1 == concernList.size()) { + return ItemViewType.LOADING; + } else { + return ItemViewType.NEWS_DIGEST; + } + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (viewType == ItemViewType.NEWS_DIGEST) { + View view = LayoutInflater.from(parent.getContext()). + inflate(R.layout.news_digest_item, parent, false); + return new NewsDigestViewHolder(view); + } else if (viewType == ItemViewType.LOADING) { + View view = LayoutInflater.from(parent.getContext()). + inflate(R.layout.refresh_footerview, parent, false); + return new FooterViewHolder(view); + } else if (viewType == ItemViewType.ZIXUNTOP_TOP) { + View view = LayoutInflater.from(parent.getContext()). + inflate(R.layout.zixun_top_item, parent, false); + return new ZiXunTopViewHolder(view); + } + return null; + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + if (holder instanceof NewsDigestViewHolder) { + initNewsDigestViewHolder((NewsDigestViewHolder) holder, position); + } else if (holder instanceof FooterViewHolder) { + initFooterViewHolder((FooterViewHolder) holder); + } else if (holder instanceof ZiXunTopViewHolder) { + initYouLiaoTopViewHolder((ZiXunTopViewHolder)holder); + } + } + + private void initYouLiaoTopViewHolder(ZiXunTopViewHolder holder) { + holder.entranceYuanchuang.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, NewsNormalActivity.class); + intent.putExtra("newsType", "yuanchuang"); + context.startActivity(intent); + } + }); + + holder.entranceZixun.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, NewsNormalActivity.class); + intent.putExtra("newsType", "zixun"); + context.startActivity(intent); + } + }); + + holder.entranceGonglve.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, StrategyActivity.class); + intent.putExtra("entrance", "(有料-专题:攻略)"); + context.startActivity(intent); + } + }); + } + + private void initNewsDigestViewHolder(final NewsDigestViewHolder viewHolder, int position) { + + final ConcernEntity concernEntity = concernList.get(position - 1); + + ImageUtils.display(viewHolder.thumb, concernEntity.getGameIcon()); + viewHolder.title.setText(concernEntity.getGameName()); + NewsUtils.setNewsPublishOn(viewHolder.time, concernEntity.getTime()); + + if ("libao".equals(concernEntity.getType())) { + String content ; + if (concernEntity.getContent().contains("
")) { + content = concernEntity.getContent().replaceAll("
", " "); + } else { + content = concernEntity.getContent(); + } + + String libaoCode = null; + viewHolder.imgLayout.removeAllViews(); + + if (TextUtils.isEmpty(concernEntity.getPlatform())) { + viewHolder.content.setText(concernEntity.getName() + "\n礼包内容:" + content ); + } else { + viewHolder.content.setText(concernEntity.getName() + "(限" + PlatformUtils.getInstance(context) + .getPlatformName(concernEntity.getPlatform()) + "版)\n礼包内容:" + content ); + } + viewHolder.comment.setVisibility(View.GONE); + viewHolder.share.setVisibility(View.GONE); + viewHolder.link.setImageResource(R.drawable.ic_libao); + + for (LibaoStatusEntity libaoStatusEntity : libaoStatusList) { + if (libaoStatusEntity.getId().equals(concernEntity.getId())) { + + if ("finish".equals(libaoStatusEntity.getStatus())) { + viewHolder.read.setText("已结束"); + } else { + viewHolder.read.setText("点击查看"); + } + + if (libaoInfo != null) { + for (LibaoInfo info : libaoInfo) { + if (info.getLibaoId().equals(concernEntity.getId())) { + if ("ling".equals(info.getStatus())) { + viewHolder.read.setText("已领取"); + } else { + viewHolder.read.setText("已淘号"); + } + + libaoCode = info.getCode(); + break; + } + } + } + } + } + + final String finalLibaoCode = libaoCode; + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + for (LibaoStatusEntity libaoStatusEntity : libaoStatusList) { + Utils.log(libaoStatusEntity.getId() + "=============" + concernEntity.getName() + "==" + libaoStatusList.size()); + if (concernEntity.getId().equals(libaoStatusEntity.getId())) { + AppController.put("libaoEntity", LibaoEntity.createLibaoEntity( + concernEntity, libaoStatusEntity, finalLibaoCode)); + } + } + skipPosition = viewHolder.getPosition(); + Intent intent = new Intent(context, LibaoDetailActivity.class); + intent.putExtra("entrance", "(资讯-关注)"); + fragment.startActivityForResult(intent, 0x122); + } + }); + return; + } + + viewHolder.comment.setVisibility(View.VISIBLE); + viewHolder.share.setVisibility(View.VISIBLE); + + if (concernEntity.getBrief() != null) { + viewHolder.content.setText(Html.fromHtml(concernEntity.getBrief())); + viewHolder.content.setMaxLines(100); + } else { + viewHolder.content.setText(Html.fromHtml(concernEntity.getContent())); + viewHolder.content.setMaxLines(5); + } + + if (concernEntity.getImg().isEmpty()) { + viewHolder.imgLayout.setVisibility(View.GONE); + viewHolder.imgLayout.removeAllViews(); + } else { + viewHolder.imgLayout.setVisibility(View.VISIBLE); + viewHolder.imgLayout.removeAllViews(); + ConcernContentUtils.addContentPic(context, viewHolder.imgLayout, concernEntity.getImg(), "(资讯-关注)", + context.getResources().getDisplayMetrics().widthPixels - DisplayUtils.dip2px(context, 34)); + } + + int views = concernEntity.getViews(); + if (views == 0) { + viewHolder.read.setVisibility(View.GONE); + } else { + viewHolder.read.setVisibility(View.VISIBLE); + viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views)); + } + + int commentnum = concernEntity.getCommentnum(); + if (commentnum == 0) { + viewHolder.commentnum.setVisibility(View.GONE); + } else { + viewHolder.commentnum.setVisibility(View.VISIBLE); + if (commentnum > 999) { + viewHolder.commentnum.setText(R.string.thousand); + } else { + viewHolder.commentnum.setText(String.valueOf(commentnum)); + } + } + + if (concernEntity.getLink() != null) { + viewHolder.link.setImageResource(R.drawable.ic_link); + } else { + viewHolder.link.setImageResource(R.drawable.concern_message_icon); + } + + viewHolder.comment.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + skipPosition = viewHolder.getPosition(); + concernEntity.setItemHeight(viewHolder.itemView.getHeight()); + AppController.put("ConcernEntity", concernEntity); + Intent intent = new Intent(context, MessageDetailActivity.class); + intent.putExtra("entrance", "(资讯-关注)"); + fragment.startActivityForResult(intent, 0x125); + } + }); + + viewHolder.share.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String shareContent; + if (concernEntity.getBrief() != null) { + shareContent = concernEntity.getBrief(); + } else { + shareContent = concernEntity.getContent(); + } + if (concernEntity.getImg() != null && concernEntity.getImg().size() > 0) { + Intent intent = new Intent(context, ShareCardPicActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("gameName", concernEntity.getGameName()); + bundle.putString("gameIconUrl", concernEntity.getGameIcon()); + bundle.putString("shareContent", shareContent); + if (concernEntity.getLink() == null){ + bundle.putString("newsId", concernEntity.getId()); + } + bundle.putStringArrayList("shareArrImg", (ArrayList) concernEntity.getImg()); + intent.putExtras(bundle); + intent.putExtra("entrance", "(资讯-关注)"); + context.startActivity(intent); + } else { + Intent intent = new Intent(context, ShareCardActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("gameName", concernEntity.getGameName()); + bundle.putString("gameIconUrl", concernEntity.getGameIcon()); + bundle.putString("shareContent", shareContent); + if (concernEntity.getLink() == null){ + bundle.putString("newsId", concernEntity.getId()); + } + intent.putExtras(bundle); + intent.putExtra("entrance", "(资讯-关注)"); + context.startActivity(intent); + } + } + }); + + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Map kv = new HashMap<>(); + kv.put("名字", concernEntity.getTitle()); + kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); + DataUtils.onEvent(context, "点击", "资讯-关注", kv); + + DataCollectionUtils.uploadClick(context, "列表", "资讯-关注", concernEntity.getTitle()); + + //统计阅读量 + statNewsViews(concernEntity, viewHolder.getPosition()); + AppController.put("ConcernEntity", concernEntity); + skipPosition = viewHolder.getPosition(); + if (concernEntity.getLink() != null){ + Intent intent = new Intent(context, WebActivity.class); + intent.putExtra("url", concernEntity.getLink()); + intent.putExtra("gameName", concernEntity.getGameName()); + intent.putExtra("newsId", concernEntity.getId()); + intent.putExtra("entrance", "(资讯-关注)"); + fragment.startActivityForResult(intent, 0x125); + }else { + Intent intent = new Intent(context, NewsDetailActivity.class); + intent.putExtra("newsId", concernEntity.getId()); + intent.putExtra("entrance", "(资讯-关注)"); + fragment.startActivityForResult(intent, 0x125); + } + + } + }); + } + + private void initFooterViewHolder(FooterViewHolder viewHolder) { + if (isNetworkError) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载失败,点击重试"); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isNetworkError = false; + notifyItemChanged(getItemCount() - 1); + loadDataByKey(concernList.size()); + } + }); + } else if (isOver) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载完毕"); + viewHolder.itemView.setClickable(false); + } else { + viewHolder.loading.setVisibility(View.VISIBLE); + viewHolder.hint.setText("加载中..."); + viewHolder.itemView.setClickable(false); + } + } + + @Override + public int getItemCount() { + if (itemCount == 0){ + return 1; + } + return itemCount + 2; + } + + //初始化获取数据库的列表 + public void initLibaoDao() { + libaoDao = new LibaoDao(context); + libaoInfo = libaoDao.getAll(); + } + + public int getConcernListSize() { + return concernList.size(); + } + + public boolean isNetworkError() { + return isNetworkError; + } + + public void setNetworkError(boolean networkError) { + isNetworkError = networkError; + } + + public boolean isOver() { + return isOver; + } + + public boolean isLoading() { + return isLoading; + } + + public int getSkipPosition() { + return skipPosition; + } + + public void setSkipPosition(int skipPosition) { + this.skipPosition = skipPosition; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/zixun/ZiXunFragment.java b/app/src/main/java/com/gh/gamecenter/zixun/ZiXunFragment.java new file mode 100644 index 0000000000..7cc66e8688 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/zixun/ZiXunFragment.java @@ -0,0 +1,440 @@ +package com.gh.gamecenter.zixun; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.util.ArrayMap; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.facebook.drawee.view.SimpleDraweeView; +import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; +import com.gh.base.HomeFragment; +import com.gh.common.util.ImageUtils; +import com.gh.common.util.PackageUtils; +import com.gh.common.view.VerticalItemDecoration; +import com.gh.gamecenter.R; +import com.gh.gamecenter.db.info.ConcernInfo; +import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.eventbus.EBConcernChanged; +import com.gh.gamecenter.eventbus.EBNetworkState; +import com.gh.gamecenter.listener.OnCallBackListener; +import com.gh.gamecenter.manager.ConcernManager; +import com.gh.gamecenter.retrofit.ObservableUtil; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import butterknife.ButterKnife; +import butterknife.OnClick; +import rx.Observable; +import rx.Subscriber; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; +import rx.functions.Func1; +import rx.schedulers.Schedulers; + +/** + * Created by khy on 2017/3/15. + */ +public class ZiXunFragment extends HomeFragment implements SwipeRefreshLayout.OnRefreshListener, OnCallBackListener { + + private SwipeRefreshLayout refreshLayout; + private RecyclerView recyclerView; + private ProgressBarCircularIndeterminate loadingLayout; + private LinearLayout noConnectionLayout; +// private LinearLayout emptyLayout; + private TextView concern; + private LinearLayout concernLayout; + private LinearLayout concernListLayout; + + private ZiXunAdapter adapter; + private LinearLayoutManager layoutManager; + + private List recommendGameList; // 推荐关注的游戏 + private List installGameList; // 安装的游戏 + + private Map concernMap; // 记录选择关注 + + private ConcernManager concernManager; + + protected boolean isEverpause; + + Runnable runnable = new Runnable() { + @Override + public void run() { + adapter = new ZiXunAdapter(ZiXunFragment.this); + recyclerView.setAdapter(adapter); + } + }; + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 0x125 && adapter.getSkipPosition() != -1) { + // 更新对应位置 + adapter.notifyItemChanged(adapter.getSkipPosition()); + adapter.setSkipPosition(-1); + } else if (requestCode == 0x122 && adapter.getSkipPosition() != -1) { + adapter.initLibaoDao(); + adapter.notifyItemChanged(adapter.getSkipPosition()); + adapter.setSkipPosition(-1); + } + } + + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ((LinearLayout) view).addView(View.inflate(getActivity(), R.layout.fragment_zixun, null)); + ButterKnife.bind(this, view); + + refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.zixun_srl_refresh); + recyclerView = (RecyclerView) view.findViewById(R.id.zixun_rv_list); + loadingLayout = (ProgressBarCircularIndeterminate) view.findViewById(R.id.zixun_pb_loading); + noConnectionLayout = (LinearLayout) view.findViewById(R.id.reuse_no_connection); +// emptyLayout = (LinearLayout) view.findViewById(R.id.zixun_ll_empty); + concern = (TextView) view.findViewById(R.id.zixun_tv_concern); + concernLayout = (LinearLayout) view.findViewById(R.id.zixun_ll_concern); + concernListLayout = (LinearLayout) view.findViewById(R.id.zixun_ll_concern_list); + + recommendGameList = new ArrayList<>(); + installGameList = new ArrayList<>(); + concernManager = new ConcernManager(getActivity()); + concernMap = new ArrayMap<>(); + + refreshLayout.setColorSchemeResources(R.color.theme); + refreshLayout.setOnRefreshListener(this); + + recyclerView.setHasFixedSize(true); + layoutManager = new LinearLayoutManager(getActivity()); + recyclerView.setLayoutManager(layoutManager); + recyclerView.addItemDecoration(new VerticalItemDecoration(getContext(), 8, false)); + adapter = new ZiXunAdapter(ZiXunFragment.this); + recyclerView.setAdapter(adapter); + recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + if (newState == RecyclerView.SCROLL_STATE_IDLE + && layoutManager.findLastVisibleItemPosition() + 1 == adapter.getItemCount()) { + if (!adapter.isOver() && !adapter.isLoading() && !adapter.isNetworkError()) { + adapter.addList(adapter.getConcernListSize()); + } + } + } + }); + + } + + @OnClick(R.id.zixun_tv_concern) + public void concern() { // 关注 推荐关注的游戏 + ArrayList list = new ArrayList<>(); + for (int key : concernMap.keySet()) { + if (concernMap.get(key)) { + list.add(recommendGameList.get(key)); + } + } + if (list.size() != 0) { + if (list.size() == 1) { + concernManager.addByEntity(list.get(0)); + } else { + concernManager.addByList(list); + } + } + } + + @OnClick(R.id.reuse_no_connection) + public void reconnection() { // 重新连接 + refreshLayout.setRefreshing(true); + recyclerView.setVisibility(View.VISIBLE); + loadingLayout.setVisibility(View.VISIBLE); + noConnectionLayout.setVisibility(View.GONE); + handler.postDelayed(runnable, 1000); + } + + @Override + public void loadDone() { // 数据加载成功回调 + refreshLayout.setRefreshing(false); +// emptyLayout.setVisibility(View.GONE); + concernLayout.setVisibility(View.GONE); + loadingLayout.setVisibility(View.GONE); + recyclerView.setVisibility(View.VISIBLE); + } + + @Override + public void loadDone(Object obj) { + + } + + @Override + public void loadError() { // 数据加载失败回调 + refreshLayout.setRefreshing(false); + loadingLayout.setVisibility(View.GONE); + recyclerView.setVisibility(View.GONE); + noConnectionLayout.setVisibility(View.VISIBLE); + } + + @Override + public void loadEmpty() { // 数据为空回调 + refreshLayout.setRefreshing(false); + loadingLayout.setVisibility(View.GONE); +// recyclerView.setVisibility(View.GONE); +// emptyLayout.setVisibility(View.VISIBLE); + refreshLayout.setEnabled(false); + + initInstallGame(); + } + + // 连接上网络事件 + public void onEventMainThread(EBNetworkState busNetworkState) { + if (busNetworkState.isNetworkConnected()) { + if (noConnectionLayout.getVisibility() == View.VISIBLE) { + reconnection(); + } else if (adapter.isNetworkError()) { + adapter.setNetworkError(false); + adapter.notifyItemChanged(adapter.getItemCount() - 1); + adapter.addList(adapter.getConcernListSize()); + } + } + } + + // 关注事件 + public void onEventMainThread(EBConcernChanged changed) { +// emptyLayout.setVisibility(View.GONE); + refreshLayout.setEnabled(true); + refreshLayout.setRefreshing(true); + recyclerView.setVisibility(View.VISIBLE); + loadingLayout.setVisibility(View.VISIBLE); + adapter = new ZiXunAdapter(ZiXunFragment.this); + recyclerView.setAdapter(adapter); + } + + + @Override + public void onRefresh() { + handler.postDelayed(runnable, 1000); + } + + // 推荐关注改为手机安装的游戏+光环助手 + private void initInstallGame() { + recommendGameList.clear();//清除上一次记录 + concern.setEnabled(true);//防止上一次关注按钮不可以,导致重新刷新后也不可用 + + ObservableUtil.computation(new Observable.OnSubscribe>() { + @Override + public void call(Subscriber> subscriber) { + List installedList = concernManager.getInstalledGame(); + // 获取第一次安装时间 + HashMap packageNames; + for (ConcernInfo concernInfo : installedList) { + long time = 0; + packageNames = concernInfo.getPackageNames(); + for (String packageName : packageNames.keySet()) { + long installedTime = PackageUtils.getInstalledTime(getActivity(), packageName); + if (installedTime > time) { // 多版本获取最近安装版本时间 + time = installedTime; + } + } + concernInfo.setTime(time); + } + + // 对已安装的游戏排序 + Collections.sort(installedList, new Comparator() { + @Override + public int compare(ConcernInfo lhs, ConcernInfo rhs) { + return lhs.getTime() < rhs.getTime() ? -1 : (lhs.getTime() == rhs.getTime() ? 0 : 1); + } + }); + + subscriber.onNext(installedList); + subscriber.onCompleted(); + } + }, new Action1>() { + @Override + public void call(final List installedList) { + final List gameList = new ArrayList<>(); + + List> sequences = new ArrayList<>(); + for (int i = 0, size = installedList.size() + 1; i < size; i++) { + if (i == size - 1) { + sequences.add(RetrofitManager.getApi().getGameDigest("5618b86e8ab49e17088b4575"));// 光环助手ID + } else { + sequences.add(RetrofitManager.getApi().getGameDigest(installedList.get(i).getId())); + } + } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + if (response.getId().equals("5618b86e8ab49e17088b4575")) { + recommendGameList.add(response); + } else { + gameList.add(response); + } + } + + @Override + public void onCompleted() { + initRecommendConcern(installedList, gameList); + } + }); + } + }); + } + + private void initRecommendConcern(List list, List gameList) { + for (ConcernInfo info : list) { + for (int i = 0; i < gameList.size(); i++) { + if (info.getId().equals(gameList.get(i).getId())) { + installGameList.add(gameList.get(i)); + break; + } + } + } + + RetrofitManager.getApi() + .getRemenkapai() + .map(new Func1, String>() { + @Override + public String call(List list) { + // 根据热门卡牌顺序进行排序 + for (int i = 0; i < installGameList.size(); i++) { + if (recommendGameList.size() >= 4) { + break; + } + for (int j = 0; j < list.size(); j++) { + if (list.get(j).getId().equals(installGameList.get(i).getId())) { + recommendGameList.add(installGameList.get(i)); + installGameList.remove(i); + i--; + break; + } + } + } + + // 推荐关注列表不足4个时,剩下的从已安装列表选取 + if (recommendGameList.size() < 4) { + for (GameEntity gameEntity : installGameList) { + if (recommendGameList.size() < 4 + && !concernManager.isConcern(gameEntity.getId())) { + recommendGameList.add(gameEntity); + } + } + } + + return null; + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response(){ + @Override + public void onResponse(String response) { + initRecommendConcernView(); + } + }); + } + + private void initRecommendConcernView() { + if (recommendGameList.isEmpty()) { + return; + } + concernLayout.setVisibility(View.VISIBLE); + concernListLayout.removeAllViews(); + + SimpleDraweeView icon; + TextView name; + ImageView concern; + + GameEntity gameEntity; + for (int i = 0, size = recommendGameList.size(); i < size; i++) { + concernMap.put(i, true); + + gameEntity = recommendGameList.get(i); + + View view = View.inflate(getActivity(), R.layout.concern_item, null); + + icon = (SimpleDraweeView) view.findViewById(R.id.concern_item_icon); + name = (TextView) view.findViewById(R.id.concern_item_name); + concern = (ImageView) view.findViewById(R.id.concern_item_concern_iv); + view.findViewById(R.id.concern_item_concern).setVisibility(View.GONE); + + concern.setVisibility(View.VISIBLE); +// icon.setImageURI(gameEntity.getIcon()); + ImageUtils.display(icon, gameEntity.getIcon()); + name.setText(gameEntity.getName()); + concern.setImageResource(R.drawable.concern_select_true); + + final int finalI = i; + concern.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (concernMap.get(finalI)){ + ((ImageView) v).setImageResource(R.drawable.concern_select_false); + concernMap.put(finalI, false); + } else { + ((ImageView) v).setImageResource(R.drawable.concern_select_true); + concernMap.put(finalI, true); + } + + // 判断关注按钮是否可用 + isConcernAvailable(); + } + }); + + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + 0, ViewGroup.LayoutParams.MATCH_PARENT); + params.weight = 1; + concernListLayout.addView(view, params); + } + + concernListLayout.setVisibility(View.VISIBLE); + } + + // 判断关注按钮是否可用 + private void isConcernAvailable() { + boolean isEnabled = false; + for (int key : concernMap.keySet()) { + if (concernMap.get(key)){ + isEnabled = true; + break; + } + } + if (isEnabled) { + concern.setTextColor(getResources().getColor(R.color.theme)); + concern.setEnabled(true); + } else { + concern.setTextColor(getResources().getColor(R.color.btn_pause)); + concern.setEnabled(false); + } + } + + public boolean isEverpause() { + return isEverpause; + } + + @Override + public void onPause() { + super.onPause(); + isEverpause = true; + } + + @Override + public void onResume() { + super.onResume(); + isEverpause = false; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/zixun/ZiXunTopViewHolder.java b/app/src/main/java/com/gh/gamecenter/zixun/ZiXunTopViewHolder.java new file mode 100644 index 0000000000..ac7edee94c --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/zixun/ZiXunTopViewHolder.java @@ -0,0 +1,29 @@ +package com.gh.gamecenter.zixun; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; + +import com.gh.gamecenter.R; + +import butterknife.BindView; +import butterknife.ButterKnife; + +/** + * Created by khy on 2017/3/15. + */ +public class ZiXunTopViewHolder extends RecyclerView.ViewHolder{ + + @BindView(R.id.zixun_entrance_yuanchuang) + LinearLayout entranceYuanchuang; + @BindView(R.id.zixun_entrance_gonglve) + LinearLayout entranceGonglve; + @BindView(R.id.zixun_entrance_zixun) + LinearLayout entranceZixun; + + + public ZiXunTopViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_concern.png b/app/src/main/res/drawable-hdpi/ic_concern.png index 9366981bf0..f8b2925053 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_concern.png and b/app/src/main/res/drawable-hdpi/ic_concern.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_download.png b/app/src/main/res/drawable-hdpi/ic_download.png index 4827b83960..b3e8414844 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_download.png and b/app/src/main/res/drawable-hdpi/ic_download.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_game_select.png b/app/src/main/res/drawable-hdpi/ic_game_select.png index 9f0a5a70aa..53f5d61a44 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_game_select.png and b/app/src/main/res/drawable-hdpi/ic_game_select.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_game_unselect.png b/app/src/main/res/drawable-hdpi/ic_game_unselect.png index 39028c812c..86843a3de6 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_game_unselect.png and b/app/src/main/res/drawable-hdpi/ic_game_unselect.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_news_select.png b/app/src/main/res/drawable-hdpi/ic_news_select.png index d9c35db3be..62b7c06ac0 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_news_select.png and b/app/src/main/res/drawable-hdpi/ic_news_select.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_news_unselect.png b/app/src/main/res/drawable-hdpi/ic_news_unselect.png index 8e3ff01544..603f2257fa 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_news_unselect.png and b/app/src/main/res/drawable-hdpi/ic_news_unselect.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_search_grey.png b/app/src/main/res/drawable-hdpi/ic_search_grey.png index 78926bbe31..ee85e1b93e 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_search_grey.png and b/app/src/main/res/drawable-hdpi/ic_search_grey.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_user_select.png b/app/src/main/res/drawable-hdpi/ic_user_select.png index da2e45b37c..13b74c1343 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_user_select.png and b/app/src/main/res/drawable-hdpi/ic_user_select.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_user_unselect.png b/app/src/main/res/drawable-hdpi/ic_user_unselect.png index dea32b84ed..4c47e30c8e 100644 Binary files a/app/src/main/res/drawable-hdpi/ic_user_unselect.png and b/app/src/main/res/drawable-hdpi/ic_user_unselect.png differ diff --git a/app/src/main/res/drawable-hdpi/reuse_btn_back.png b/app/src/main/res/drawable-hdpi/reuse_btn_back.png index 02cb05971d..6b2b7fcb09 100644 Binary files a/app/src/main/res/drawable-hdpi/reuse_btn_back.png and b/app/src/main/res/drawable-hdpi/reuse_btn_back.png differ diff --git a/app/src/main/res/drawable-hdpi/zixun_entrance_gonglve.png b/app/src/main/res/drawable-hdpi/zixun_entrance_gonglve.png new file mode 100644 index 0000000000..2071e1644d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/zixun_entrance_gonglve.png differ diff --git a/app/src/main/res/drawable-hdpi/zixun_entrance_yuanchuang.png b/app/src/main/res/drawable-hdpi/zixun_entrance_yuanchuang.png new file mode 100644 index 0000000000..2f5e9c86e6 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/zixun_entrance_yuanchuang.png differ diff --git a/app/src/main/res/drawable-hdpi/zixun_entrance_zixun.png b/app/src/main/res/drawable-hdpi/zixun_entrance_zixun.png new file mode 100644 index 0000000000..4bdb65e9a2 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/zixun_entrance_zixun.png differ diff --git a/app/src/main/res/drawable-xhdpi/home_entrance_kaifu.png b/app/src/main/res/drawable-xhdpi/home_entrance_kaifu.png new file mode 100644 index 0000000000..8b676d5993 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/home_entrance_kaifu.png differ diff --git a/app/src/main/res/drawable/actionbar_search_bg.xml b/app/src/main/res/drawable/actionbar_search_bg.xml index eae02df297..92a3fc2576 100644 --- a/app/src/main/res/drawable/actionbar_search_bg.xml +++ b/app/src/main/res/drawable/actionbar_search_bg.xml @@ -2,7 +2,7 @@ - + diff --git a/app/src/main/res/drawable/kaifu_time_tag_gray.xml b/app/src/main/res/drawable/kaifu_time_tag_gray.xml new file mode 100644 index 0000000000..d5a4578394 --- /dev/null +++ b/app/src/main/res/drawable/kaifu_time_tag_gray.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 2e80146b18..e6c2242e3e 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -42,7 +42,7 @@ - - + @@ -47,24 +46,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - + android:padding="8dp"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bbfd5e75f4..3ee2d42e25 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -26,8 +26,8 @@ android:background="@android:color/white" android:orientation="horizontal" android:gravity="center_vertical" - android:paddingTop="10dp" - android:paddingBottom="8dp"> + android:paddingTop="8dp" + android:paddingBottom="10dp"> @@ -49,7 +49,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="游戏" - android:layout_marginTop="3dp" + android:layout_marginTop="5dp" android:textColor="@color/theme" android:textSize="10sp" /> @@ -64,8 +64,8 @@ @@ -74,8 +74,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="资讯" - android:layout_marginTop="3dp" - android:textColor="#a7a8b2" + android:layout_marginTop="5dp" + android:textColor="#aaaaaa" android:textSize="10sp" /> @@ -89,8 +89,8 @@ @@ -99,8 +99,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我的光环" - android:layout_marginTop="3dp" - android:textColor="#a7a8b2" + android:layout_marginTop="5dp" + android:textColor="#aaaaaa" android:textSize="10sp" /> diff --git a/app/src/main/res/layout/activity_newsnormal.xml b/app/src/main/res/layout/activity_newsnormal.xml new file mode 100644 index 0000000000..5e9a9147f3 --- /dev/null +++ b/app/src/main/res/layout/activity_newsnormal.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 29db5045d0..35c24c2bad 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -1,6 +1,5 @@ @@ -16,7 +15,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:layout_margin="8dp"> - + - + android:layout_marginRight="8dp" + android:layout_marginLeft="8dp" + android:layout_marginTop="8dp" + android:layout_marginBottom="4dp"> - + - + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="5dp"> - + - + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="5dp"> - + - + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="5dp"> - + - + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="8dp"> - + diff --git a/app/src/main/res/layout/activity_subject.xml b/app/src/main/res/layout/activity_subject.xml index 8ba43ea168..ee2048bf77 100644 --- a/app/src/main/res/layout/activity_subject.xml +++ b/app/src/main/res/layout/activity_subject.xml @@ -4,18 +4,29 @@ android:layout_height="match_parent" android:orientation="vertical" > - - + + + - + android:layout_height="match_parent" + android:layout_below="@+id/subject_type_list"/> + + - + - + android:layout_marginTop="10dp" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="8dp"> - + - + android:layout_margin="8dp"> - + - + android:layout_margin="8dp"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/comment_head_item.xml b/app/src/main/res/layout/comment_head_item.xml index 741505e557..4107d41635 100644 --- a/app/src/main/res/layout/comment_head_item.xml +++ b/app/src/main/res/layout/comment_head_item.xml @@ -1,15 +1,13 @@ - + android:layout_marginTop="8dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/comment_item.xml b/app/src/main/res/layout/comment_item.xml index 867073ff60..141557b3da 100644 --- a/app/src/main/res/layout/comment_item.xml +++ b/app/src/main/res/layout/comment_item.xml @@ -1,14 +1,12 @@ - + android:background="@drawable/reuse_listview_item_style"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_kaifu_select_game.xml b/app/src/main/res/layout/dialog_kaifu_select_game.xml new file mode 100644 index 0000000000..a5528d8514 --- /dev/null +++ b/app/src/main/res/layout/dialog_kaifu_select_game.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/downloadmanager_item_head.xml b/app/src/main/res/layout/downloadmanager_item_head.xml index 0fbc797888..e18b4ff81b 100644 --- a/app/src/main/res/layout/downloadmanager_item_head.xml +++ b/app/src/main/res/layout/downloadmanager_item_head.xml @@ -1,11 +1,9 @@ - + android:padding="8dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fm_downloadmanager_item.xml b/app/src/main/res/layout/fm_downloadmanager_item.xml index 4619fafa14..22665c5f24 100644 --- a/app/src/main/res/layout/fm_downloadmanager_item.xml +++ b/app/src/main/res/layout/fm_downloadmanager_item.xml @@ -1,96 +1,105 @@ - - - + android:clickable="true"> + android:orientation="horizontal" + android:padding="12dp"> - + + android:layout_weight="1" + android:orientation="vertical" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp"> + android:textColor="@color/title" + android:textSize="16sp" + android:lineSpacingMultiplier="0.9" + android:includeFontPadding="false"/> - - - + android:gravity="center_vertical" + android:layout_marginTop="8dp" + android:orientation="horizontal" > + + + + + + + + + - + + - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fm_search_history.xml b/app/src/main/res/layout/fm_search_history.xml index f408cd1ac7..e0b61e1125 100644 --- a/app/src/main/res/layout/fm_search_history.xml +++ b/app/src/main/res/layout/fm_search_history.xml @@ -2,13 +2,89 @@ + android:orientation="vertical"> - - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fm_search_history_delete_item.xml b/app/src/main/res/layout/fm_search_history_delete_item.xml index d108b9fe7c..985410208a 100644 --- a/app/src/main/res/layout/fm_search_history_delete_item.xml +++ b/app/src/main/res/layout/fm_search_history_delete_item.xml @@ -1,16 +1,12 @@ - + android:background="@drawable/reuse_listview_item_style"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fm_search_history_item.xml b/app/src/main/res/layout/fm_search_history_item.xml index 5996bc6081..072ab428d2 100644 --- a/app/src/main/res/layout/fm_search_history_item.xml +++ b/app/src/main/res/layout/fm_search_history_item.xml @@ -1,12 +1,9 @@ - + android:background="@drawable/reuse_listview_item_style"> - + diff --git a/app/src/main/res/layout/fm_update_item.xml b/app/src/main/res/layout/fm_update_item.xml index 7463677d79..631453f7fd 100644 --- a/app/src/main/res/layout/fm_update_item.xml +++ b/app/src/main/res/layout/fm_update_item.xml @@ -1,6 +1,5 @@ - + android:layout_marginBottom="8dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_news1.xml b/app/src/main/res/layout/fragment_news1.xml index 75c3ea7f5c..7f9e9fc7d4 100644 --- a/app/src/main/res/layout/fragment_news1.xml +++ b/app/src/main/res/layout/fragment_news1.xml @@ -29,11 +29,12 @@ android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" - android:visibility="gone"> + android:visibility="visible"> + android:layout_marginTop="17dp" + android:visibility="invisible"/> - + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="8dp"/> diff --git a/app/src/main/res/layout/fragment_zixun.xml b/app/src/main/res/layout/fragment_zixun.xml new file mode 100644 index 0000000000..dd3b0067c4 --- /dev/null +++ b/app/src/main/res/layout/fragment_zixun.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/game_head_item.xml b/app/src/main/res/layout/game_head_item.xml index 24a240cb3f..e1e68eab56 100644 --- a/app/src/main/res/layout/game_head_item.xml +++ b/app/src/main/res/layout/game_head_item.xml @@ -1,20 +1,23 @@ - + android:orientation="vertical"> + + + android:gravity="center_vertical" + android:paddingLeft="10dp" + android:paddingRight="10dp"> - - - - - - + android:layout_height="match_parent" + android:text="全部" + android:gravity="center" + android:textColor="#676767" + android:textSize="12sp" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/game_image_item.xml b/app/src/main/res/layout/game_image_item.xml index 0fc6e91e85..fe5641a998 100644 --- a/app/src/main/res/layout/game_image_item.xml +++ b/app/src/main/res/layout/game_image_item.xml @@ -1,12 +1,14 @@ - + android:layout_height="match_parent"> + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/game_normal_item.xml b/app/src/main/res/layout/game_normal_item.xml index c090d03713..f19899a302 100644 --- a/app/src/main/res/layout/game_normal_item.xml +++ b/app/src/main/res/layout/game_normal_item.xml @@ -1,19 +1,17 @@ - + android:background="@drawable/reuse_listview_item_style"> @@ -153,6 +150,6 @@ android:gravity="center" android:text="下载" android:textColor="@android:color/white" - android:textSize="14sp" /> + android:textSize="13sp" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/game_normal_item_swipe.xml b/app/src/main/res/layout/game_normal_item_swipe.xml index 42937df9ac..0d65017367 100644 --- a/app/src/main/res/layout/game_normal_item_swipe.xml +++ b/app/src/main/res/layout/game_normal_item_swipe.xml @@ -1,7 +1,6 @@ @@ -38,7 +37,7 @@ android:text="放手发给好友\n免流量安装"/> - + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="8dp"> - + diff --git a/app/src/main/res/layout/game_test_item.xml b/app/src/main/res/layout/game_test_item.xml index f548d74374..bbab34e6bd 100644 --- a/app/src/main/res/layout/game_test_item.xml +++ b/app/src/main/res/layout/game_test_item.xml @@ -1,6 +1,6 @@ - + android:background="@drawable/reuse_listview_item_style"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/game_viewpager_item.xml b/app/src/main/res/layout/game_viewpager_item.xml index e19782edfb..5511873db2 100644 --- a/app/src/main/res/layout/game_viewpager_item.xml +++ b/app/src/main/res/layout/game_viewpager_item.xml @@ -1,6 +1,5 @@ @@ -20,7 +19,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" - android:orientation="horizontal"> + android:layout_alignParentBottom="true" + android:orientation="horizontal" + android:layout_marginRight="10dp"> - + android:layout_height="98dp"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_intro.xml b/app/src/main/res/layout/gamedetail_item_intro.xml index 25dc874111..0c374243d3 100644 --- a/app/src/main/res/layout/gamedetail_item_intro.xml +++ b/app/src/main/res/layout/gamedetail_item_intro.xml @@ -1,6 +1,5 @@ - + android:paddingTop="12dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_libao.xml b/app/src/main/res/layout/gamedetail_item_libao.xml index 97a11ad493..1e2a2f6f84 100644 --- a/app/src/main/res/layout/gamedetail_item_libao.xml +++ b/app/src/main/res/layout/gamedetail_item_libao.xml @@ -1,5 +1,6 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_libao_rv.xml b/app/src/main/res/layout/gamedetail_item_libao_rv.xml index ad4ee5c9bb..e3ca627173 100644 --- a/app/src/main/res/layout/gamedetail_item_libao_rv.xml +++ b/app/src/main/res/layout/gamedetail_item_libao_rv.xml @@ -1,16 +1,11 @@ - + android:paddingTop="12dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_news.xml b/app/src/main/res/layout/gamedetail_item_news.xml index 6434ff1e63..3bc197ef04 100644 --- a/app/src/main/res/layout/gamedetail_item_news.xml +++ b/app/src/main/res/layout/gamedetail_item_news.xml @@ -1,6 +1,5 @@ - + android:paddingTop="12dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_newsserver.xml b/app/src/main/res/layout/gamedetail_item_newsserver.xml index 3d9793fac1..aaee4f76be 100644 --- a/app/src/main/res/layout/gamedetail_item_newsserver.xml +++ b/app/src/main/res/layout/gamedetail_item_newsserver.xml @@ -1,15 +1,10 @@ - + android:padding="8dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_plugin.xml b/app/src/main/res/layout/gamedetail_item_plugin.xml index fa51d963f9..12f14c330d 100644 --- a/app/src/main/res/layout/gamedetail_item_plugin.xml +++ b/app/src/main/res/layout/gamedetail_item_plugin.xml @@ -1,6 +1,5 @@ - + android:paddingTop="12dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_skin.xml b/app/src/main/res/layout/gamedetail_item_skin.xml index 2a1d4e8341..7f56cf1e56 100644 --- a/app/src/main/res/layout/gamedetail_item_skin.xml +++ b/app/src/main/res/layout/gamedetail_item_skin.xml @@ -1,6 +1,5 @@ - + android:paddingTop="12dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_top.xml b/app/src/main/res/layout/gamedetail_item_top.xml index 50c9751ec0..3ed7e7e0a6 100644 --- a/app/src/main/res/layout/gamedetail_item_top.xml +++ b/app/src/main/res/layout/gamedetail_item_top.xml @@ -1,6 +1,5 @@ - + android:paddingTop="15dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/home_actionbar.xml b/app/src/main/res/layout/home_actionbar.xml index 77378476d0..95046fd9ea 100644 --- a/app/src/main/res/layout/home_actionbar.xml +++ b/app/src/main/res/layout/home_actionbar.xml @@ -2,85 +2,93 @@ + android:background="@android:color/black"> - + - - - - - - - - - - + android:layout_marginLeft="5dp" + android:layout_weight="1" > - + - + + - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/home_subject_entrance_item.xml b/app/src/main/res/layout/home_subject_entrance_item.xml index 4a897fc59e..4edff65868 100644 --- a/app/src/main/res/layout/home_subject_entrance_item.xml +++ b/app/src/main/res/layout/home_subject_entrance_item.xml @@ -5,15 +5,15 @@ android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> - + + android:layout_width="49dp" + android:layout_height="44dp"> @@ -30,6 +30,7 @@ android:id="@+id/home_subject_name" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textSize="13sp" + android:textSize="11sp" + android:textColor="@color/title" android:text="插件" /> \ No newline at end of file diff --git a/app/src/main/res/layout/kc_game_select_item.xml b/app/src/main/res/layout/kc_game_select_item.xml index ff2bb374bd..c050aadd5c 100644 --- a/app/src/main/res/layout/kc_game_select_item.xml +++ b/app/src/main/res/layout/kc_game_select_item.xml @@ -1,6 +1,5 @@ - + android:background="@drawable/reuse_listview_item_style"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/libao_item.xml b/app/src/main/res/layout/libao_item.xml index 004e80c25c..9035caff7e 100644 --- a/app/src/main/res/layout/libao_item.xml +++ b/app/src/main/res/layout/libao_item.xml @@ -1,6 +1,5 @@ - + android:paddingTop="15dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/libaodetail_item_top.xml b/app/src/main/res/layout/libaodetail_item_top.xml index 119420fc80..53cd2ea440 100644 --- a/app/src/main/res/layout/libaodetail_item_top.xml +++ b/app/src/main/res/layout/libaodetail_item_top.xml @@ -1,6 +1,5 @@ - + android:paddingTop="15dp"> - + diff --git a/app/src/main/res/layout/news_detail_comment.xml b/app/src/main/res/layout/news_detail_comment.xml index 6985bc5653..f3243529cc 100644 --- a/app/src/main/res/layout/news_detail_comment.xml +++ b/app/src/main/res/layout/news_detail_comment.xml @@ -1,15 +1,10 @@ - + android:paddingBottom="3dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/news_digest_item.xml b/app/src/main/res/layout/news_digest_item.xml index 7c966c4aaa..e4fa6b7cfe 100644 --- a/app/src/main/res/layout/news_digest_item.xml +++ b/app/src/main/res/layout/news_digest_item.xml @@ -1,6 +1,5 @@ - + android:paddingTop="15dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/news_image1_item.xml b/app/src/main/res/layout/news_image1_item.xml index 619694fa8e..9cf8ffe02e 100644 --- a/app/src/main/res/layout/news_image1_item.xml +++ b/app/src/main/res/layout/news_image1_item.xml @@ -1,6 +1,6 @@ - + android:paddingBottom="15dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/news_image2_item.xml b/app/src/main/res/layout/news_image2_item.xml index 5ed3d06153..5fcb9ec069 100644 --- a/app/src/main/res/layout/news_image2_item.xml +++ b/app/src/main/res/layout/news_image2_item.xml @@ -1,6 +1,6 @@ - + android:paddingBottom="15dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/news_image3_item.xml b/app/src/main/res/layout/news_image3_item.xml index eaf0ba8fc1..044418faf5 100644 --- a/app/src/main/res/layout/news_image3_item.xml +++ b/app/src/main/res/layout/news_image3_item.xml @@ -1,6 +1,6 @@ - + android:paddingBottom="10dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/news_image_item.xml b/app/src/main/res/layout/news_image_item.xml index 8d95aa8101..172d6c3e1e 100644 --- a/app/src/main/res/layout/news_image_item.xml +++ b/app/src/main/res/layout/news_image_item.xml @@ -1,13 +1,10 @@ - + android:padding="8dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/news_text_item.xml b/app/src/main/res/layout/news_text_item.xml index 5a6374efa1..4756af4b6e 100644 --- a/app/src/main/res/layout/news_text_item.xml +++ b/app/src/main/res/layout/news_text_item.xml @@ -1,14 +1,11 @@ - + android:paddingRight="8dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/newsdetail_item_news_more.xml b/app/src/main/res/layout/newsdetail_item_news_more.xml index f2402bbc44..3b74866610 100644 --- a/app/src/main/res/layout/newsdetail_item_news_more.xml +++ b/app/src/main/res/layout/newsdetail_item_news_more.xml @@ -1,6 +1,5 @@ - + android:paddingTop="15dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/reuse_actionbar.xml b/app/src/main/res/layout/reuse_actionbar.xml index fa260578a8..8ee0eea3d7 100644 --- a/app/src/main/res/layout/reuse_actionbar.xml +++ b/app/src/main/res/layout/reuse_actionbar.xml @@ -3,7 +3,7 @@ android:id="@+id/reuse_actionbar" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/theme" > + android:background="@android:color/white" > @@ -24,7 +24,7 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" - android:textColor="@android:color/white" - android:textSize="20sp" /> + android:textColor="@color/title" + android:textSize="17sp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/search_actionbar.xml b/app/src/main/res/layout/search_actionbar.xml index a082e9d5a4..2d9ad469a3 100644 --- a/app/src/main/res/layout/search_actionbar.xml +++ b/app/src/main/res/layout/search_actionbar.xml @@ -2,7 +2,7 @@ @@ -62,7 +62,7 @@ android:layout_weight="1.5" android:gravity="center" android:text="搜索" - android:textColor="@android:color/white" + android:textColor="@color/title" android:textSize="16sp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/zixun_top_item.xml b/app/src/main/res/layout/zixun_top_item.xml new file mode 100644 index 0000000000..ec8bd78250 --- /dev/null +++ b/app/src/main/res/layout/zixun_top_item.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file