From f858ba0b70211693c3eea06c241dfc7257ad1d49 Mon Sep 17 00:00:00 2001 From: huangzhuanghua <401742778@qq.com> Date: Fri, 9 Sep 2016 18:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gh/base/BaseActivity.java | 17 +- .../main/java/com/gh/base/BaseFragment.java | 18 +- .../main/java/com/gh/base/HomeFragment.java | 239 +++++++++++ .../com/gh/common/util/DownloadItemUtils.java | 5 - .../java/com/gh/common/util/ImageUtils.java | 5 - .../com/gh/common/util/PlatformUtils.java | 6 +- .../gh/common/view/CardRelativeLayout.java | 98 +++++ .../com/gh/common/view/DownloadDialog.java | 39 +- .../java/com/gh/download/DownloadManager.java | 12 +- .../java/com/gh/download/DownloadService.java | 11 + .../com/gh/gamecenter/ConcernActivity.java | 7 +- .../com/gh/gamecenter/GameDetailActivity.java | 55 ++- .../java/com/gh/gamecenter/MainActivity.java | 14 +- .../com/gh/gamecenter/NewsDetailActivity.java | 166 ++++---- .../com/gh/gamecenter/SettingActivity.java | 4 +- .../gh/gamecenter/SplashScreenActivity.java | 30 +- .../gamecenter/adapter/GameDetailAdapter.java | 112 +++-- .../download/GameDownloadAdapter.java | 71 ++-- .../download/GameUpdateAdapter.java | 16 +- .../download/GameUpdateFragment.java | 44 +- .../gamecenter/entity/GameDetailEntity.java | 1 + .../com/gh/gamecenter/eventbus/EBConcern.java | 7 - .../gamecenter/eventbus/EBConcernChanged.java | 16 +- ...nloadDelete.java => EBDownloadStatus.java} | 30 +- .../com/gh/gamecenter/eventbus/EBImage.java | 23 - .../eventbus/EBPlatformChanged.java | 5 - .../com/gh/gamecenter/eventbus/EBRedDot.java | 19 - .../com/gh/gamecenter/eventbus/EBRefresh.java | 8 - .../com/gh/gamecenter/eventbus/EBReuse.java | 17 + .../{EBTopState.java => EBTopStatus.java} | 4 +- .../com/gh/gamecenter/game/Game1Fragment.java | 52 +-- .../gamecenter/game/Game1FragmentAdapter.java | 2 +- .../com/gh/gamecenter/game/Game2Fragment.java | 34 +- .../com/gh/gamecenter/game/Game3Fragment.java | 32 +- .../com/gh/gamecenter/game/GameFragment.java | 358 ++++------------ ...kListener.java => OnCallBackListener.java} | 2 +- .../gh/gamecenter/manager/ConcernManager.java | 47 +-- .../gamecenter/news/News3FragmentAdapter.java | 3 + .../com/gh/gamecenter/news/News4Fragment.java | 13 +- .../gamecenter/news/News4FragmentAdapter.java | 5 +- .../com/gh/gamecenter/news/NewsFragment.java | 396 ++++-------------- .../gamecenter/personal/ConcernFragment.java | 22 +- .../personal/ConcernFragmentAdapter.java | 2 +- .../gamecenter/personal/InstallFragment.java | 6 +- .../search/SearchHistoryFragmentAdapter.java | 20 +- app/src/main/res/layout/activity_main.xml | 6 +- .../res/layout/downloadmanager_item_head.xml | 10 +- .../res/layout/fm_downloadmanager_item.xml | 5 +- app/src/main/res/layout/fragment_home.xml | 38 ++ app/src/main/res/layout/fragment_news.xml | 71 ---- app/src/main/res/layout/home_actionbar.xml | 6 +- .../res/layout/image_card_game_head_item.xml | 117 ------ .../image_card_home_game_image_item.xml | 64 --- .../image_card_home_game_normal_item.xml | 165 -------- .../layout/image_card_home_game_test_item.xml | 198 --------- app/src/main/res/layout/menu_popwindow.xml | 25 -- .../res/layout/personal_footer_none_head.xml | 51 --- .../res/layout/plugin_container_fragments.xml | 63 --- 58 files changed, 1038 insertions(+), 1874 deletions(-) create mode 100644 app/src/main/java/com/gh/base/HomeFragment.java create mode 100644 app/src/main/java/com/gh/common/view/CardRelativeLayout.java delete mode 100644 app/src/main/java/com/gh/gamecenter/eventbus/EBConcern.java rename app/src/main/java/com/gh/gamecenter/eventbus/{EBDownloadDelete.java => EBDownloadStatus.java} (62%) delete mode 100644 app/src/main/java/com/gh/gamecenter/eventbus/EBImage.java delete mode 100644 app/src/main/java/com/gh/gamecenter/eventbus/EBPlatformChanged.java delete mode 100644 app/src/main/java/com/gh/gamecenter/eventbus/EBRedDot.java delete mode 100644 app/src/main/java/com/gh/gamecenter/eventbus/EBRefresh.java create mode 100644 app/src/main/java/com/gh/gamecenter/eventbus/EBReuse.java rename app/src/main/java/com/gh/gamecenter/eventbus/{EBTopState.java => EBTopStatus.java} (83%) rename app/src/main/java/com/gh/gamecenter/listener/{AdapterCallBackListener.java => OnCallBackListener.java} (78%) create mode 100644 app/src/main/res/layout/fragment_home.xml delete mode 100644 app/src/main/res/layout/fragment_news.xml delete mode 100644 app/src/main/res/layout/image_card_game_head_item.xml delete mode 100644 app/src/main/res/layout/image_card_home_game_image_item.xml delete mode 100644 app/src/main/res/layout/image_card_home_game_normal_item.xml delete mode 100644 app/src/main/res/layout/image_card_home_game_test_item.xml delete mode 100644 app/src/main/res/layout/menu_popwindow.xml delete mode 100644 app/src/main/res/layout/personal_footer_none_head.xml delete mode 100644 app/src/main/res/layout/plugin_container_fragments.xml diff --git a/app/src/main/java/com/gh/base/BaseActivity.java b/app/src/main/java/com/gh/base/BaseActivity.java index 98ed5596c4..6a0e5c4ada 100644 --- a/app/src/main/java/com/gh/base/BaseActivity.java +++ b/app/src/main/java/com/gh/base/BaseActivity.java @@ -27,6 +27,7 @@ import com.gh.download.DownloadManager; import com.gh.gamecenter.MainActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.eventbus.EBShowDialog; +import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.SystemBarTintManager; import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig; @@ -36,7 +37,7 @@ import java.util.ArrayList; import cn.sharesdk.framework.ShareSDK; import de.greenrobot.event.EventBus; -public class BaseActivity extends Activity { +public class BaseActivity extends Activity implements OnCallBackListener { private SystemBarTintManager tintManager; @@ -215,4 +216,18 @@ public class BaseActivity extends Activity { DownloadManager.getInstance(this).initGameMap(); } + @Override + public void loadDone() { + + } + + @Override + public void loadError() { + + } + + @Override + public void loadEmpty() { + + } } diff --git a/app/src/main/java/com/gh/base/BaseFragment.java b/app/src/main/java/com/gh/base/BaseFragment.java index e2bc77b364..9a1769a67c 100644 --- a/app/src/main/java/com/gh/base/BaseFragment.java +++ b/app/src/main/java/com/gh/base/BaseFragment.java @@ -8,6 +8,7 @@ import android.view.View; import android.view.ViewGroup; import com.gh.common.util.Utils; +import com.gh.gamecenter.listener.OnCallBackListener; import java.lang.reflect.Field; @@ -16,7 +17,7 @@ import de.greenrobot.event.EventBus; /** * Created by LGT on 2016/9/4. */ -public class BaseFragment extends Fragment { +public class BaseFragment extends Fragment implements OnCallBackListener { protected View view; @@ -69,4 +70,19 @@ public class BaseFragment extends Fragment { isDestroy = true; EventBus.getDefault().unregister(this); } + + @Override + public void loadDone() { + + } + + @Override + public void loadError() { + + } + + @Override + public void loadEmpty() { + + } } diff --git a/app/src/main/java/com/gh/base/HomeFragment.java b/app/src/main/java/com/gh/base/HomeFragment.java new file mode 100644 index 0000000000..752005707a --- /dev/null +++ b/app/src/main/java/com/gh/base/HomeFragment.java @@ -0,0 +1,239 @@ +package com.gh.base; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v4.view.ViewPager; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.gh.common.constant.Config; +import com.gh.common.util.DataUtils; +import com.gh.common.util.DisplayUtils; +import com.gh.download.DownloadManager; +import com.gh.gamecenter.ConcernActivity; +import com.gh.gamecenter.DownloadManagerActivity; +import com.gh.gamecenter.MainActivity; +import com.gh.gamecenter.R; +import com.gh.gamecenter.SearchActivity; +import com.gh.gamecenter.eventbus.EBDownloadStatus; +import com.gh.gamecenter.eventbus.EBTopStatus; +import com.gh.gamecenter.manager.DataCollectionManager; +import com.gh.gamecenter.manager.PackageManager; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.greenrobot.event.EventBus; + +/** + * Created by LGT on 2016/9/9. + */ +public class HomeFragment extends Fragment implements View.OnClickListener { + + protected View view; + protected LinearLayout home_ll_top; + protected View home_slide_line; + protected ViewPager home_vp_content; + + protected LinearLayout.LayoutParams lparams; + + protected Handler handler = new Handler(); + + private TextView downloadHint; + private TextView searchHint; + + private String hint; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + 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))); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + int top = DisplayUtils.getInternalDimensionSize(getResources(), + "status_bar_height"); + home_actionbar.setPadding(0, top, 0, 0); + lparams.height += top; + } + home_actionbar.setLayoutParams(lparams); + + initActionBar(); + + home_ll_top = (LinearLayout) view.findViewById(R.id.home_ll_top); + home_slide_line = view.findViewById(R.id.home_slide_line); + home_vp_content = (ViewPager) view.findViewById(R.id.home_vp_content); + + EventBus.getDefault().register(this); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + if (container != null) { + container.removeView(view); + } + return view; + } + + private void initActionBar() { + 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); + + if (Config.isShow(getActivity())) { + view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE); + } else { + view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE); + } + + downloadHint = (TextView) view.findViewById(R.id.action_tip); + int updateSize = PackageManager.getUpdateListSize(); + int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); + if (downloadSize != 0) { + downloadHint.setVisibility(View.VISIBLE); + downloadHint.setText(String.valueOf(downloadSize)); + } else if (updateSize != 0) { + downloadHint.setVisibility(View.VISIBLE); + downloadHint.setText(String.valueOf(updateSize)); + } else { + downloadHint.setVisibility(View.GONE); + } + + searchHint = (TextView) view.findViewById(R.id.actionbar_search_input); + searchHint.setOnClickListener(this); + if (!TextUtils.isEmpty(MainActivity.searchHint)) { + hint = MainActivity.searchHint; + searchHint.setHint(hint); + } + } + + @Override + public void onClick(View v) { + final int id = v.getId(); + if (id == R.id.actionbar_notification) { + DataUtils.onEvent(getActivity(), "主页", "关注图标"); + + Map map = new HashMap<>(); + map.put("location", "关注图标"); + map.put("createOn", System.currentTimeMillis() / 1000); + map.put("page", "主页"); + DataCollectionManager.onEvent(getActivity(), "click-item", map); + + startActivity(new Intent(getActivity(), ConcernActivity.class)); + } else if (id == R.id.actionbar_rl_download) { + DataUtils.onEvent(getActivity(), "主页", "下载图标"); + + Map map = new HashMap<>(); + map.put("location", "下载图标"); + map.put("createOn", System.currentTimeMillis() / 1000); + map.put("page", "主页"); + DataCollectionManager.onEvent(getActivity(), "click-item", map); + + startActivity(new Intent(getActivity(), DownloadManagerActivity.class)); + } else if (id == R.id.actionbar_search_input) { + DataUtils.onEvent(getActivity(), "主页", "搜索框"); + + Map map = new HashMap<>(); + map.put("location", "搜索框"); + map.put("createOn", System.currentTimeMillis() / 1000); + map.put("page", "主页"); + DataCollectionManager.onEvent(getActivity(), "click-item", map); + + Intent goSearch = new Intent(getActivity(), SearchActivity.class); + goSearch.putExtra("clicked", false); + goSearch.putExtra("hint", hint); + startActivity(goSearch); + } else if (id == R.id.actionbar_iv_search) { + DataUtils.onEvent(getActivity(), "主页", "搜索图标"); + + Map map = new HashMap<>(); + map.put("location", "搜索图标"); + map.put("createOn", System.currentTimeMillis() / 1000); + map.put("page", "主页"); + DataCollectionManager.onEvent(getActivity(), "click-item", map); + + Intent searchIntent = new Intent(getActivity(), + SearchActivity.class); + searchIntent.putExtra("clicked", true); + searchIntent.putExtra("hint", hint); + startActivity(searchIntent); + } + } + + public void onEventMainThread(EBTopStatus status) { + if (!TextUtils.isEmpty(status.getSearchHint())) { + hint = status.getSearchHint(); + searchHint.setHint(hint); + } + } + + public void onEventMainThread(EBDownloadStatus status) { + downloadHint = (TextView) view.findViewById(R.id.action_tip); + int updateSize = PackageManager.getUpdateListSize(); + int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); + if (downloadSize != 0) { + downloadHint.setVisibility(View.VISIBLE); + downloadHint.setText(String.valueOf(downloadSize)); + } else if (updateSize != 0) { + downloadHint.setVisibility(View.VISIBLE); + downloadHint.setText(String.valueOf(updateSize)); + } else { + downloadHint.setVisibility(View.GONE); + } + } + + @Override + public void onHiddenChanged(boolean hidden) { + super.onHiddenChanged(hidden); + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + List list = getChildFragmentManager().getFragments(); + if (list != null) { + if (hidden) { + for (Fragment fragment : getChildFragmentManager().getFragments()) { + transaction.hide(fragment); + } + } else { + for (Fragment fragment : getChildFragmentManager().getFragments()) { + transaction.show(fragment); + } + } + } + transaction.commit(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + EventBus.getDefault().unregister(this); + view = null; + home_ll_top = null; + home_slide_line = null; + home_vp_content = null; + lparams = null; + handler = null; + downloadHint = null; + searchHint = null; + hint = null; + } +} diff --git a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java index 86d9eccd5c..c8f3eb6192 100644 --- a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java +++ b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java @@ -25,7 +25,6 @@ import com.gh.gamecenter.MainActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; -import com.gh.gamecenter.eventbus.EBRedDot; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; @@ -34,8 +33,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.LinkedBlockingQueue; -import de.greenrobot.event.EventBus; - public class DownloadItemUtils { // 初始化gameMap @@ -557,7 +554,6 @@ public class DownloadItemUtils { downloadBtn.setText("下载中"); downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); downloadBtn.setTextColor(btn_sl); - EventBus.getDefault().post(new EBRedDot(1)); DownloadManager.getInstance(context).putStatus(entity.getApk().get(0).getUrl(), "downloading"); } else { @@ -627,7 +623,6 @@ public class DownloadItemUtils { downloadBtn.setText("下载中"); downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); downloadBtn.setTextColor(btn_sl); - EventBus.getDefault().post(new EBRedDot(1)); DownloadManager.getInstance(context).putStatus(entity.getApk().get(0).getUrl(), "downloading"); } else { diff --git a/app/src/main/java/com/gh/common/util/ImageUtils.java b/app/src/main/java/com/gh/common/util/ImageUtils.java index 09b8d7d73e..d3140f2165 100644 --- a/app/src/main/java/com/gh/common/util/ImageUtils.java +++ b/app/src/main/java/com/gh/common/util/ImageUtils.java @@ -12,7 +12,6 @@ import android.widget.ImageView.ScaleType; import com.gh.common.view.CircleImageView; import com.gh.gamecenter.R; -import com.gh.gamecenter.eventbus.EBImage; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; @@ -24,8 +23,6 @@ import java.lang.ref.WeakReference; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import de.greenrobot.event.EventBus; - public class ImageUtils { private static ImageUtils singleton; private static ImageLoader imageLoader; @@ -168,8 +165,6 @@ public class ImageUtils { imageView.setLayoutParams(layoutParams); } - EventBus.getDefault().post(new EBImage(imageUri, newHeight)); - if (imageView instanceof CircleImageView) { imageView.setScaleType(ScaleType.CENTER_CROP); } else { diff --git a/app/src/main/java/com/gh/common/util/PlatformUtils.java b/app/src/main/java/com/gh/common/util/PlatformUtils.java index 4d9a7b5cfa..5faa982c61 100644 --- a/app/src/main/java/com/gh/common/util/PlatformUtils.java +++ b/app/src/main/java/com/gh/common/util/PlatformUtils.java @@ -14,7 +14,7 @@ import com.gh.common.constant.Config; import com.gh.common.constant.Constants; import com.gh.gamecenter.R; import com.gh.gamecenter.SplashScreenActivity; -import com.gh.gamecenter.eventbus.EBPlatformChanged; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; import org.apache.http.HttpStatus; @@ -189,7 +189,7 @@ public class PlatformUtils { handler.post(new Runnable() { @Override public void run() { - EventBus.getDefault().post(new EBPlatformChanged()); + EventBus.getDefault().post(new EBReuse("PlatformChanged")); } }); } @@ -295,7 +295,7 @@ public class PlatformUtils { editor.putStringSet("platform", pset); editor.apply(); initMap(); - EventBus.getDefault().post(new EBPlatformChanged()); + EventBus.getDefault().post(new EBReuse("PlatformChanged")); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/gh/common/view/CardRelativeLayout.java b/app/src/main/java/com/gh/common/view/CardRelativeLayout.java new file mode 100644 index 0000000000..a685d1856c --- /dev/null +++ b/app/src/main/java/com/gh/common/view/CardRelativeLayout.java @@ -0,0 +1,98 @@ +package com.gh.common.view; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +import com.gh.gamecenter.R; + +/** + * Created by LGT on 2016/9/9. + */ +public class CardRelativeLayout extends RelativeLayout { + + private Drawable topDrawable, bottomDrawable; + private Drawable leftTopDrawable, rightTopDrawable, leftBottomDrawable, rightBottomDrawable; + + private int mLeft, mTop, mRight, mBottom; + + public CardRelativeLayout(Context context) { + this(context, null); + } + + public CardRelativeLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public CardRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + topDrawable = getContext().getResources().getDrawable(R.drawable.frame_top); + bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom); + + leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square); + rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square); + leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square); + rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square); + + if (attrs != null) { + TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout); + mLeft = ta.getDimensionPixelSize(R.styleable.CardLayout_left, 0); + mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0); + mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0); + mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0); + ta.recycle(); + } + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (mTop != 0) { + if (leftBottomDrawable != null) { + leftBottomDrawable.setBounds(0, 0, mLeft, mTop); + leftBottomDrawable.draw(canvas); + } + + if (bottomDrawable != null) { + bottomDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop); + bottomDrawable.draw(canvas); + } + + if (rightBottomDrawable != null) { + rightBottomDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop); + rightBottomDrawable.draw(canvas); + } + } + if (mBottom != 0) { + if (leftTopDrawable != null) { + leftTopDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight()); + leftTopDrawable.draw(canvas); + } + + if (topDrawable != null) { + topDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight()); + topDrawable.draw(canvas); + } + + if (rightTopDrawable != null) { + rightTopDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight()); + rightTopDrawable.draw(canvas); + } + } + } + + public void setmBottom(int mBottom) { + this.mBottom = mBottom; + } + + public void setmTop(int mTop) { + this.mTop = mTop; + } +} diff --git a/app/src/main/java/com/gh/common/view/DownloadDialog.java b/app/src/main/java/com/gh/common/view/DownloadDialog.java index 0a108211d6..99a56b25e7 100644 --- a/app/src/main/java/com/gh/common/view/DownloadDialog.java +++ b/app/src/main/java/com/gh/common/view/DownloadDialog.java @@ -53,11 +53,10 @@ import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameCollectionEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; -import com.gh.gamecenter.eventbus.EBDownloadDelete; +import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.eventbus.EBPlatformChanged; import com.gh.gamecenter.eventbus.EBPutUrl; -import com.gh.gamecenter.eventbus.EBRedDot; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; @@ -519,23 +518,27 @@ public class DownloadDialog { } //接收下载被删除消息 - public void onEvent(EBDownloadDelete delete) { - String url = delete.getUrl(); - Integer location = locationMap.get(url); - DownloadManager.getInstance(context).putStatus(url, "delete"); - entryMap.remove(url); - int position = (int) Math.ceil((location + 1) / (double) (row * column)); - adapterMap.get(position - 1).notifyItemChanged(location % (row * column)); - if (collectionAdapterMap != null && collectionAdapterMap.size() >= position - 1 && collectionAdapterMap.size() >= 1){ - collectionAdapterMap.get(position - 1).notifyItemChanged(location % (row * column)); + public void onEvent(EBDownloadStatus status) { + if ("delete".equals(status.getStatus())) { + String url = status.getUrl(); + Integer location = locationMap.get(url); + DownloadManager.getInstance(context).putStatus(url, "delete"); + entryMap.remove(url); + int position = (int) Math.ceil((location + 1) / (double) (row * column)); + adapterMap.get(position - 1).notifyItemChanged(location % (row * column)); + if (collectionAdapterMap != null && collectionAdapterMap.size() >= position - 1 && collectionAdapterMap.size() >= 1){ + collectionAdapterMap.get(position - 1).notifyItemChanged(location % (row * column)); + } } } // 接收platform数据改变消息,更新界面 - public void onEvent(EBPlatformChanged platformChanged) { - DownloadManager.getInstance(context).removeObserver(dataWatcher); - init(new ArrayList(gameApk)); - DownloadManager.getInstance(context).addObserver(dataWatcher); + public void onEvent(EBReuse reuse) { + if ("PlatformChanged".equals(reuse.getType())) { + DownloadManager.getInstance(context).removeObserver(dataWatcher); + init(new ArrayList<>(gameApk)); + DownloadManager.getInstance(context).addObserver(dataWatcher); + } } private class PlatformAdapter extends PagerAdapter { @@ -1066,8 +1069,6 @@ public class DownloadDialog { DownloadManager.getInstance(context).add(entry); - EventBus.getDefault().post(new EBRedDot(1)); - DownloadManager.getInstance(context).putStatus(entry.getUrl(), "downloading"); GameUpdateEntity game = new GameUpdateEntity(); @@ -1160,8 +1161,6 @@ public class DownloadDialog { download_item_tv_status.setText("0.0%"); - EventBus.getDefault().post(new EBRedDot(1)); - DownloadManager.getInstance(context).putStatus(entry.getUrl(), "downloading"); } else { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 7aa70d82e2..58bec9d44d 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -239,23 +239,19 @@ public class DownloadManager { } public void cancel(String url, boolean isDeleteFile) { - - DownloadEntry temp = DownloadDao.getInstance(context).get(url); - if (temp != null) { + DownloadEntry entry = DownloadDao.getInstance(context).get(url); + if (entry != null) { if (isDeleteFile) { - FileUtils.deleteFile(temp.getPath()); + FileUtils.deleteFile(entry.getPath()); } DownloadDao.getInstance(context).delete(url); Utils.log(DownloadManager.class.getSimpleName(), "cancle==>file and record were deleted!"); } - - DownloadEntry entry = DataChanger.getInstance().getDownloadEntries() - .get(url); +// DownloadEntry entry = DataChanger.getInstance().getDownloadEntries().get(url); if (entry != null) { context.startService(getIntent(entry, DownloadStatus.cancel)); Utils.log(DownloadManager.class.getSimpleName(), "cancel"); } - } /** diff --git a/app/src/main/java/com/gh/download/DownloadService.java b/app/src/main/java/com/gh/download/DownloadService.java index 6063ea65b2..00f1030156 100644 --- a/app/src/main/java/com/gh/download/DownloadService.java +++ b/app/src/main/java/com/gh/download/DownloadService.java @@ -8,9 +8,12 @@ import android.os.IBinder; import com.gh.common.constant.Constants; import com.gh.common.util.Utils; +import com.gh.gamecenter.eventbus.EBDownloadStatus; import java.util.Map.Entry; +import de.greenrobot.event.EventBus; + public class DownloadService extends Service { @Override @@ -73,6 +76,7 @@ public class DownloadService extends Service { startDownload(entry); } Utils.log(DownloadService.class.getSimpleName(), "addDownload==>" + entry); + EventBus.getDefault().post(new EBDownloadStatus("download")); } private synchronized void startDownload(DownloadEntry entry) { @@ -127,6 +131,13 @@ public class DownloadService extends Service { DataChanger.getInstance().notifyDataChanged(entry); } Utils.log(DownloadService.class.getSimpleName(), "cancelDownload==>" + entry); + EBDownloadStatus status = new EBDownloadStatus("delete", entry.getName(), + entry.getMeta().get("platform"), entry.getUrl()); + String PluginPlatform = entry.getMeta().get("PluginPlatform"); + if (PluginPlatform != null) { + status.setPluginPlatform(PluginPlatform); + } + EventBus.getDefault().post(status); } @SuppressLint("HandlerLeak") diff --git a/app/src/main/java/com/gh/gamecenter/ConcernActivity.java b/app/src/main/java/com/gh/gamecenter/ConcernActivity.java index 620ee24ab9..8e972195a9 100644 --- a/app/src/main/java/com/gh/gamecenter/ConcernActivity.java +++ b/app/src/main/java/com/gh/gamecenter/ConcernActivity.java @@ -28,6 +28,7 @@ import com.gh.common.util.Utils; import com.gh.common.view.Concern_LinearLayout; import com.gh.gamecenter.db.info.ConcernInfo; import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.manager.ConcernManager; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; @@ -66,7 +67,6 @@ public class ConcernActivity extends BaseActivity implements OnClickListener { manager = new ConcernManager(getApplicationContext()); list = manager.getConcernGame(); - if (list == null) { list = new ArrayList<>(); } @@ -105,6 +105,11 @@ public class ConcernActivity extends BaseActivity implements OnClickListener { } } + // 关注事件 + public void onEventMainThread(EBConcernChanged changed) { + + } + private void initRecommendGame() { JsonArrayExtendedRequest recommendRequest = new JsonArrayExtendedRequest( TimestampUtils.addTimestamp(Config.HOST diff --git a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java index d925a27979..02e4dc22aa 100644 --- a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java @@ -33,8 +33,8 @@ import com.gh.download.DownloadManager; import com.gh.gamecenter.adapter.GameDetailAdapter; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.eventbus.EBPutUrl; -import com.gh.gamecenter.eventbus.EBRedDot; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; @@ -61,6 +61,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList private TextView gamedetail_tv_per; private TextView actionbar_tv_title; private ProgressBar gamedetail_progressbar; + private ImageView iv_share; private GameEntity gameEntity; private DownloadEntry mDownloadEntry; @@ -99,7 +100,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList View contentView = View.inflate(this, R.layout.activity_gamedetail, null); // 添加分享图标 - ImageView iv_share = new ImageView(this); + iv_share = new ImageView(this); iv_share.setImageResource(R.drawable.share_icon); iv_share.setOnClickListener(this); iv_share.setVisibility(View.GONE); @@ -121,7 +122,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList init(contentView); - adapter = new GameDetailAdapter(this, reuse_no_connection, gamedetail_ll_loading, iv_share, gameId, entrance); + adapter = new GameDetailAdapter(this, gameId, entrance); gamedetail_rv_show.setLayoutManager(new LinearLayoutManager(this)); gamedetail_rv_show.setAdapter(adapter); @@ -137,12 +138,33 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList } if (gameEntity != null) { - initDownload(); + adapter.setGameEntity(gameEntity); + adapter.getGameDetail(); } else { getGameDigest(); } } + @Override + public void loadDone() { + if (!isDestroy) { + if (gamedetail_ll_loading.getVisibility() == View.VISIBLE) { + gamedetail_ll_loading.setVisibility(View.GONE); + } + if (!TextUtils.isEmpty(adapter.getGameDetailEntity().getShareCode())) { + iv_share.setVisibility(View.VISIBLE); + } + initDownload(); + } + } + + @Override + public void loadError() { + if (!isDestroy) { + reuse_no_connection.setVisibility(View.VISIBLE); + } + } + // 初始化bottom private void initDownload() { if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { @@ -160,25 +182,25 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList isInstalled = true; } if (isInstalled) { - if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { + if (adapter.getGameDetailEntity() == null + || TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) { gamedetail_tv_download.setText(String.format("启动《%s》", gameEntity.getName())); } else { gamedetail_tv_download.setText(String.format("启动《%s》%s", - gameEntity.getName(), gameEntity.getDownloadAddWord())); + gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord())); } } else { - if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { + if (adapter.getGameDetailEntity() == null + || TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) { gamedetail_tv_download.setText(String.format("下载《%s》", gameEntity.getName())); } else { gamedetail_tv_download.setText(String.format("下载《%s》%s", - gameEntity.getName(), gameEntity.getDownloadAddWord())); + gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord())); } } } - adapter.setGameEntity(gameEntity); - adapter.getGameDetail(); } @Override @@ -365,8 +387,6 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList DownloadManager.getInstance(this).add(entry); - EventBus.getDefault().post(new EBRedDot(1)); - gamedetail_tv_download.setVisibility(View.GONE); gamedetail_progressbar.setVisibility(View.VISIBLE); gamedetail_tv_per.setVisibility(View.VISIBLE); @@ -381,6 +401,13 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList } } + // 关注事件 + public void onEventMainThread(EBConcernChanged changed) { + if (!TextUtils.isEmpty(gameId) && changed.getGameId().equals(gameId)) { + adapter.notifyItemChanged(0); + } + } + // 获取游戏摘要 private void getGameDigest() { String url = Config.HOST + "v1d45/game/" + gameId + "/digest"; @@ -391,7 +418,8 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList if (!isDestroy) { Gson gson = new Gson(); gameEntity = gson.fromJson(response.toString(), GameEntity.class); - initDownload(); + adapter.setGameEntity(gameEntity); + adapter.getGameDetail(); } } }, @@ -452,6 +480,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList gamedetail_progressbar = null; mDownloadEntry = null; handler = null; + iv_share = null; } } diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index adfa454b47..12d96220b4 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -57,10 +57,9 @@ import com.gh.gamecenter.entity.AppEntity; import com.gh.gamecenter.entity.GameUpdateEntity; import com.gh.gamecenter.eventbus.EBPackage; import com.gh.gamecenter.eventbus.EBPutUrl; -import com.gh.gamecenter.eventbus.EBRedDot; import com.gh.gamecenter.eventbus.EBShowDialog; import com.gh.gamecenter.eventbus.EBSkip; -import com.gh.gamecenter.eventbus.EBTopState; +import com.gh.gamecenter.eventbus.EBTopStatus; import com.gh.gamecenter.eventbus.EBUISwitch; import com.gh.gamecenter.game.GameFragment; import com.gh.gamecenter.manager.ConcernManager; @@ -287,6 +286,8 @@ public class MainActivity extends BaseFragmentActivity implements if (downloadEntry.getMeta().get("isPlugin") != null) { EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntry .getPath())); + } else if (platform.equals("官方版")) { + toast(downloadEntry.getName() + " - 下载完成"); } else { toast(downloadEntry.getName() + " - " + platform + " - 下载完成"); @@ -383,8 +384,6 @@ public class MainActivity extends BaseFragmentActivity implements setContentView(contentView); - Utils.log(findViewById(R.id.main_ll_bottom).getMeasuredHeight()); - initViews(); setTabSelection(currentTab); @@ -670,7 +669,7 @@ public class MainActivity extends BaseFragmentActivity implements searchHint = searchHintList.get(RandomUtils.nextInt(searchHintList.size())); } EventBus.getDefault().post( - new EBTopState("搜索", searchHintList + new EBTopStatus("搜索", searchHintList .get(0))); } } @@ -717,8 +716,6 @@ public class MainActivity extends BaseFragmentActivity implements game.setUrl(appEntity.getUrl()); game.setPlatform("官方版"); PackageManager.addUpdate(0, game); - EventBus.getDefault() - .post(new EBRedDot(-1)); String updateMD5 = MD5Utils.getUpdateMD5( appEntity.getUrl(), @@ -1102,7 +1099,6 @@ public class MainActivity extends BaseFragmentActivity implements // 添加进已安装map中 if ("安装".equals(busFour.getType())) { PackageManager.addInstalled(packageName); - EventBus.getDefault().post(new EBRedDot(-1)); } else if ("卸载".equals(busFour.getType())) { PackageManager.removeInstalled(packageName); } @@ -1155,7 +1151,7 @@ public class MainActivity extends BaseFragmentActivity implements if (gameEntity != null) { ConcernManager concernManager = new ConcernManager( getApplicationContext()); - concernManager.updateByEntity(gameEntity, true); + concernManager.updateByEntity(gameEntity); } else { FilterManager filterManager = new FilterManager( getApplicationContext()); diff --git a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java index 5b2a4cd5f5..0f6b9518cd 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java @@ -60,11 +60,11 @@ import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.NewsDetailEntity; import com.gh.gamecenter.entity.NewsEntity; -import com.gh.gamecenter.eventbus.EBDownloadDelete; +import com.gh.gamecenter.eventbus.EBConcernChanged; +import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBPackage; import com.gh.gamecenter.eventbus.EBPutUrl; -import com.gh.gamecenter.eventbus.EBRedDot; import com.gh.gamecenter.manager.ConcernManager; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; @@ -132,8 +132,6 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener private int scrollSize = 300;//滑动距离超过300触发事件(放大缩小字体) private SharedPreferences sp; private int fontsize; - private boolean isConcern = false; - private int concernCode = 0;//0关注不做操作,1添加关注,2删除关注 private DataWatcher dataWatcher = new DataWatcher() { @Override @@ -536,8 +534,6 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener DownloadManager.getInstance( getApplicationContext()).add(entry); - EventBus.getDefault().post(new EBRedDot(1)); - essaydetail_tv_download .setVisibility(View.GONE); essaydetail_progressbar @@ -768,36 +764,6 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener adapter.notifyItemChanged(0); } - private void showSuccessDialog() { - Toast.makeText(this,"关注成功",Toast.LENGTH_SHORT).show(); - } - - private void showCancelDialog(final TextView attention) { - DialogUtils.showCancelDialog(this, new DialogUtils.ConfiremListener() { - @Override - public void onConfirem() { - Map kv = new HashMap(); - kv.put("状态", "取消关注"); - DataUtils.onEvent(NewsDetailActivity.this, "游戏关注", - gameEntity.getName(), kv); - - Map map = new HashMap(); - map.put("game", gameEntity.getName()); - map.put("type", "关注"); - map.put("createdOn", System.currentTimeMillis() / 1000); - DataCollectionManager.onEvent(NewsDetailActivity.this, - "concern", map); - - concernManager.deleteConcern(gameEntity.getId()); - concernCode = 2; - attention.setText("关注"); - attention - .setBackgroundResource(R.drawable.textview_red_style); - attention.setTextColor(Color.WHITE); - } - }); - } - public class JsInterface { private Context context; private ArrayList imgs = new ArrayList(); @@ -908,17 +874,67 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener DataCollectionManager.onEvent(NewsDetailActivity.this, "concern", map); concernManager.addByEntity(gameEntity); - concernCode = 1; essaydetail_attention.setText("取消关注"); essaydetail_attention.setBackgroundResource(R.drawable.border_red_bg); essaydetail_attention.setTextColor(0xffbc2132); - showSuccessDialog(); + + toast("关注成功"); + + //添加关注 + String uuid = ConcernUtils.uuid(NewsDetailActivity.this); + ConcernUtils.postConcernGameId(gameEntity.getId(), Config.HOST + "v2d0/device/" + uuid + "/concern", + new ConcernUtils.DownJsonListener() { + @Override + public void downSucced(String str) { + Utils.log("关注提交成功==游戏详情"); + } + + @Override + public void downFailed() { + Utils.log("关注提交失败==游戏详情"); + } + }); } else { - Map kv2 = new HashMap(); + Map kv2 = new HashMap<>(); kv2.put("点击", "取消关注"); DataUtils.onEvent(NewsDetailActivity.this, "插件数据", gameEntity.getName(), kv2); - showCancelDialog(essaydetail_attention); + DialogUtils.showCancelDialog(NewsDetailActivity.this, new DialogUtils.ConfiremListener() { + @Override + public void onConfirem() { + Map kv = new HashMap<>(); + kv.put("状态", "取消关注"); + DataUtils.onEvent(NewsDetailActivity.this, "游戏关注", + gameEntity.getName(), kv); + + Map map = new HashMap<>(); + map.put("game", gameEntity.getName()); + map.put("type", "关注"); + map.put("createdOn", System.currentTimeMillis() / 1000); + DataCollectionManager.onEvent(NewsDetailActivity.this, + "concern", map); + + concernManager.deleteConcern(gameEntity.getId()); + essaydetail_attention.setText("关注"); + essaydetail_attention.setBackgroundResource(R.drawable.textview_red_style); + essaydetail_attention.setTextColor(Color.WHITE); + + //取消关注 + String uuid = ConcernUtils.uuid(NewsDetailActivity.this); + ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameEntity.getId(), + new ConcernUtils.DownJsonListener() { + @Override + public void downSucced(String str) { + Utils.log("删除提交成功==游戏详情"); + } + + @Override + public void downFailed() { + Utils.log("删除提交失败==游戏详情"); + } + }); + } + }); } } } @@ -947,12 +963,8 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener holder.cardView.setVisibility(View.VISIBLE); ImageUtils.getInstance(getApplicationContext()).displayFile(gameEntity.getIcon(), holder.essaydetail_icon); holder.essaydetail_name.setText(gameEntity.getName()); - for (int i = 0; i < concernManager.getConcernGame().size(); i++) { - if (concernManager.getConcernGame().get(i).getId().equals(gameEntity.getId())){ - isConcern = true; - } - } - if (isConcern) { + + if (concernManager.isConcern(gameEntity.getId())) { holder.essaydetail_attention.setText("取消关注"); holder.essaydetail_attention.setBackgroundResource(R.drawable.border_red_bg); holder.essaydetail_attention.setTextColor(0xffbc2132); @@ -1082,22 +1094,31 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener } //接收下载被删除消息 - public void onEvent(EBDownloadDelete delete) { - if (gameEntity != null && gameEntity.getApk().size() == 1) { - String url = gameEntity.getApk().get(0).getUrl(); - if (url.equals(delete.getUrl())) { - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); - if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》"); - } else { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); + public void onEvent(EBDownloadStatus status) { + if ("delete".equals(status.getStatus())) { + if (gameEntity != null && gameEntity.getApk().size() == 1) { + String url = gameEntity.getApk().get(0).getUrl(); + if (url.equals(status.getUrl())) { + essaydetail_tv_download.setVisibility(View.VISIBLE); + essaydetail_progressbar.setVisibility(View.GONE); + essaydetail_tv_per.setVisibility(View.GONE); + if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { + essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》"); + } else { + essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); + } } } } } + // 关注事件 + public void onEventMainThread(EBConcernChanged changed) { + if (gameEntity != null && changed.getGameId().equals(gameEntity.getId())) { + adapter.notifyItemChanged(0); + } + } + public void onEventMainThread(EBPackage busFour) { if (gameEntity != null && gameEntity.getApk().size() == 1) { String packageName = gameEntity.getApk().get(0).getPackageName(); @@ -1261,37 +1282,6 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener @Override protected void onDestroy() { super.onDestroy(); - String uuid = ConcernUtils.uuid(this); - if (isConcern && concernCode == 2 && gameEntity.getId() != null) { - //取消关注 - ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameEntity.getId(), new ConcernUtils.DownJsonListener() { - @Override - public void downSucced(String str) { - Utils.log("删除提交成功==游戏详情"); - } - - @Override - public void downFailed() { - Utils.log("删除提交失败==游戏详情"); - } - }); - - } else if (!isConcern && concernCode == 1 && gameEntity.getId() != null) { - //添加关注 - ConcernUtils.postConcernGameId(gameEntity.getId(), Config.HOST + "v2d0/device/" + uuid + "/concern", new ConcernUtils.DownJsonListener() { - @Override - public void downSucced(String str) { - Utils.log("关注提交成功==游戏详情"); - } - - @Override - public void downFailed() { - Utils.log("关注提交失败==游戏详情"); - } - }); - } else { - Utils.log("无关注操作==游戏详情"); - } AppController.canclePendingRequests(NewsDetailActivity.class); essaydetail_ll_loading = null; essaydetail_ll_bottom = null; diff --git a/app/src/main/java/com/gh/gamecenter/SettingActivity.java b/app/src/main/java/com/gh/gamecenter/SettingActivity.java index b38715e8bc..9f86ecc1d7 100644 --- a/app/src/main/java/com/gh/gamecenter/SettingActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SettingActivity.java @@ -37,7 +37,7 @@ import com.gh.download.DownloadManager; import com.gh.download.DownloadStatus; import com.gh.gamecenter.entity.AppEntity; import com.gh.gamecenter.entity.GameUpdateEntity; -import com.gh.gamecenter.eventbus.EBRefresh; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.manager.PackageManager; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; import com.google.gson.Gson; @@ -212,7 +212,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener { case R.id.setting_cv_fix_download: sp.edit().putBoolean("isShow", true).apply(); toast("修复成功,快去首页看看吧"); - EventBus.getDefault().post(new EBRefresh()); + EventBus.getDefault().post(new EBReuse("Refresh")); break; case R.id.setting_rl_autoinstall: setting_sb_autoinstall.performClick(); diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index 7567fa0345..11b682b8b4 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -412,7 +412,7 @@ public class SplashScreenActivity extends BaseActivity { GameInfo gameEntity = new GameInfo(); gameEntity.setId(gameDigestEntity.getId()); gameEntity.setPackageName(useParams.get(i)); - concernManager.updateByEntity(gameEntity, false); + concernManager.updateByEntity(gameEntity); list.add(useParams.get(i)); } @@ -431,33 +431,7 @@ public class SplashScreenActivity extends BaseActivity { Comparator comparator = new Comparator() { @Override public int compare(String lhs, String rhs) { - - char[] clhs = lhs.toCharArray(); - char[] crhs = rhs.toCharArray(); - int length; - if (clhs.length < crhs.length) { - length = clhs.length; - } else if (clhs.length > crhs.length) { - length = crhs.length; - } else { - length = clhs.length; - } - for (int i = 0; i < length; i++) { - if (clhs[i] > crhs[i]) { - return 1; - } else if (clhs[i] < crhs[i]) { - return -1; - } else if (i == length - 1) { - if (clhs.length < crhs.length) { - return -1; - } else if (clhs.length > crhs.length) { - return 1; - } else { - return 0; - } - } - } - return 0; + return lhs.compareTo(rhs); } }; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java index d21e190b1c..07c7ca8398 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java @@ -9,7 +9,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -36,6 +35,7 @@ import com.gh.gamecenter.entity.GameDetailEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.entity.TagEntity; +import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; @@ -56,10 +56,7 @@ import java.util.Map; public class GameDetailAdapter extends RecyclerView.Adapter { private Context context; - - private LinearLayout reuse_no_connection; - private LinearLayout gamedetail_ll_loading; - private ImageView iv_share; + private OnCallBackListener listener; private ConcernManager concernManager; @@ -74,17 +71,11 @@ public class GameDetailAdapter extends RecyclerView.Adapter { private int position_news = -1; private int position_intro = -1; - public GameDetailAdapter(Context context, - LinearLayout noConnection, - LinearLayout bottom, - ImageView share, + public GameDetailAdapter(GameDetailActivity activity, String gameId, String entrance) { - this.context = context; - - reuse_no_connection = noConnection; - gamedetail_ll_loading = bottom; - iv_share = share; + this.context = activity; + this.listener = activity; this.gameId = gameId; this.entrance = entrance; @@ -113,17 +104,15 @@ public class GameDetailAdapter extends RecyclerView.Adapter { initPosition(); notifyItemRangeInserted(0, getItemCount()); - if (!TextUtils.isEmpty(gameDetailEntity.getShareCode())) { - iv_share.setVisibility(View.VISIBLE); - } - getGameNews(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - reuse_no_connection.setVisibility(View.VISIBLE); + if (listener != null) { + listener.loadError(); + } } }); AppController.addToRequestQueue(request, GameDetailActivity.class); @@ -141,8 +130,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { new TypeToken>() {}.getType()); gameDetailEntity.setNews(news); - if (gamedetail_ll_loading.getVisibility() == View.VISIBLE) { - gamedetail_ll_loading.setVisibility(View.GONE); + if (listener != null) { + listener.loadDone(); } initPosition(); if (position_news != -1) { @@ -153,8 +142,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - if (gamedetail_ll_loading.getVisibility() == View.VISIBLE) { - gamedetail_ll_loading.setVisibility(View.GONE); + if (listener != null) { + listener.loadDone(); } } }); @@ -308,7 +297,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { viewHolder.gamedetail_tv_name.setText(gameEntity.getName()); ImageUtils.getInstance(context).display(gameEntity.getIcon(), viewHolder.gamedetail_iv_thumb); - if (gameEntity.getApk() == null) { + if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { viewHolder.gamedetail_tv_info.setText(""); } else { ApkEntity apkEntity = gameEntity.getApk().get(0); @@ -317,7 +306,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { viewHolder.gamedetail_tv_concern.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - TextView concern = (TextView) v; + final TextView concern = (TextView) v; if ("关注".equals(concern.getText().toString())) { Map kv = new HashMap<>(); @@ -337,7 +326,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { concern.setText("取消关注"); concern.setBackgroundResource(R.drawable.border_red_bg); concern.setTextColor(0xffbc2132); - Toast.makeText(context,"关注成功",Toast.LENGTH_SHORT).show(); + + Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show(); //添加关注 String uuid = ConcernUtils.uuid(context); @@ -357,49 +347,45 @@ public class GameDetailAdapter extends RecyclerView.Adapter { kv2.put("点击", "取消关注"); DataUtils.onEvent(context, "插件数据", gameEntity.getName(), kv2); - showCancelDialog(concern); + DialogUtils.showCancelDialog(context, new DialogUtils.ConfiremListener() { + @Override + public void onConfirem() { + Map kv = new HashMap<>(); + kv.put("状态", "取消关注"); + DataUtils.onEvent(context, "游戏关注", gameEntity.getName(), kv); + + Map map = new HashMap<>(); + map.put("game", gameEntity.getName()); + map.put("type", "关注"); + map.put("createdOn", System.currentTimeMillis() / 1000); + DataCollectionManager.onEvent(context, "concern", map); + + concernManager.deleteConcern(gameEntity.getId()); + concern.setText("关注"); + concern.setBackgroundResource(R.drawable.textview_red_style); + concern.setTextColor(0xffffffff); + + //取消关注 + String uuid = ConcernUtils.uuid(context); + ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameId, new ConcernUtils.DownJsonListener() { + @Override + public void downSucced(String str) { + Utils.log("删除提交成功==游戏详情"); + } + + @Override + public void downFailed() { + Utils.log("删除提交失败==游戏详情"); + } + }); + } + }); } } }); } - private void showCancelDialog(final TextView attention) { - DialogUtils.showCancelDialog(context, new DialogUtils.ConfiremListener() { - @Override - public void onConfirem() { - Map kv = new HashMap<>(); - kv.put("状态", "取消关注"); - DataUtils.onEvent(context, "游戏关注", gameEntity.getName(), kv); - - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("type", "关注"); - map.put("createdOn", System.currentTimeMillis() / 1000); - DataCollectionManager.onEvent(context, "concern", map); - - concernManager.deleteConcern(gameEntity.getId()); - attention.setText("关注"); - attention.setBackgroundResource(R.drawable.textview_red_style); - attention.setTextColor(0xffffffff); - - //取消关注 - String uuid = ConcernUtils.uuid(context); - ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameId, new ConcernUtils.DownJsonListener() { - @Override - public void downSucced(String str) { - Utils.log("删除提交成功==游戏详情"); - } - - @Override - public void downFailed() { - Utils.log("删除提交失败==游戏详情"); - } - }); - } - }); - } - private void initPosition() { if (gameDetailEntity.getTag() != null && gameDetailEntity.getTag().size() > 0) { diff --git a/app/src/main/java/com/gh/gamecenter/download/GameDownloadAdapter.java b/app/src/main/java/com/gh/gamecenter/download/GameDownloadAdapter.java index 0e37b40b7b..c68ab3fc0e 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameDownloadAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameDownloadAdapter.java @@ -23,13 +23,13 @@ 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.DownloadEntry; import com.gh.download.DownloadManager; import com.gh.download.DownloadStatus; import com.gh.gamecenter.MainActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.eventbus.EBDownloadChanged; -import com.gh.gamecenter.eventbus.EBDownloadDelete; import com.gh.gamecenter.manager.PackageManager; import java.util.ArrayList; @@ -98,27 +98,29 @@ public class GameDownloadAdapter extends RecyclerView.Adapter 0 && position <= doneList.size()) { entry = doneList.get(position - 1); - // 第一个 - if (position == 1) { - ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); - } else { - ((CardLinearLayout) holder.itemView).setmTop(0); - } +// // 第一个 +// if (position == 1) { +// ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); +// } else { +// ((CardLinearLayout) holder.itemView).setmTop(0); +// } // 最后一个 if (position == doneList.size()) { ((CardLinearLayout) holder.itemView).setBottom(true); + ((CardLinearLayout) holder.itemView).setmBottom(0); } else { ((CardLinearLayout) holder.itemView).setBottom(false); + ((CardLinearLayout) holder.itemView).setmBottom(DisplayUtils.dip2px(context, 8)); } } else if (doneList.isEmpty()) { entry = downloadingList.get(position - 1); - // 第一个 - if (position == 1) { - ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); - } else { - ((CardLinearLayout) holder.itemView).setmTop(0); - } +// // 第一个 +// if (position == 1) { +// ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8)); +// } else { +// ((CardLinearLayout) holder.itemView).setmTop(0); +// } // 最后一个 if (position == downloadingList.size()) { @@ -129,12 +131,12 @@ public class GameDownloadAdapter extends RecyclerView.Adapter news; private ArrayList gallery; private String des; + @SerializedName("d_button_add_word") private String downloadAddWord; @SerializedName("article_types") private ArrayList articleTypes; diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBConcern.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBConcern.java deleted file mode 100644 index 452b102860..0000000000 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBConcern.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.gh.gamecenter.eventbus; - -/** - * Created by LGT on 2016/9/8. - */ -public class EBConcern { -} diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBConcernChanged.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBConcernChanged.java index cfbf3dc549..9298d0005d 100644 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBConcernChanged.java +++ b/app/src/main/java/com/gh/gamecenter/eventbus/EBConcernChanged.java @@ -2,18 +2,20 @@ package com.gh.gamecenter.eventbus; public class EBConcernChanged { - private String id; + private String gameId; + private boolean isConcern; - public EBConcernChanged(String id) { - this.id = id; + public EBConcernChanged(String gameId, boolean isConcern) { + this.gameId = gameId; + this.isConcern = isConcern; } - public String getId() { - return id; + public String getGameId() { + return gameId; } - public void setId(String id) { - this.id = id; + public boolean isConcern() { + return isConcern; } } diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBDownloadDelete.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBDownloadStatus.java similarity index 62% rename from app/src/main/java/com/gh/gamecenter/eventbus/EBDownloadDelete.java rename to app/src/main/java/com/gh/gamecenter/eventbus/EBDownloadStatus.java index 6e7a25311c..966ba35c13 100644 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBDownloadDelete.java +++ b/app/src/main/java/com/gh/gamecenter/eventbus/EBDownloadStatus.java @@ -1,43 +1,43 @@ package com.gh.gamecenter.eventbus; -public class EBDownloadDelete { +/** + * Created by LGT on 2016/9/9. + */ +public class EBDownloadStatus { + private String status; private String name; private String platform; private String url; private String PluginPlatform; - public EBDownloadDelete(String name, String platform, String url) { - super(); + public EBDownloadStatus(String status) { + this.status = status; + } + + public EBDownloadStatus(String status, String name, String platform, String url) { + this.status = status; this.name = name; this.platform = platform; this.url = url; } + public String getStatus() { + return status; + } + public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public String getPlatform() { return platform; } - public void setPlatform(String platform) { - this.platform = platform; - } - public String getUrl() { return url; } - public void setUrl(String url) { - this.url = url; - } - public String getPluginPlatform() { return PluginPlatform; } diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBImage.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBImage.java deleted file mode 100644 index aae2cd7c71..0000000000 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBImage.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.gh.gamecenter.eventbus; - -/** - * Created by LGT on 2016/8/18. - */ -public class EBImage { - - private String url; - private int height; - - public EBImage(String url, int height) { - this.url = url; - this.height = height; - } - - public String getUrl() { - return url; - } - - public int getHeight() { - return height; - } -} diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBPlatformChanged.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBPlatformChanged.java deleted file mode 100644 index fe9e06a264..0000000000 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBPlatformChanged.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.gh.gamecenter.eventbus; - -public class EBPlatformChanged { - -} diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBRedDot.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBRedDot.java deleted file mode 100644 index cb8e313351..0000000000 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBRedDot.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.gh.gamecenter.eventbus; - -public class EBRedDot { - - private int type; - - public EBRedDot(int type) { - this.type = type; - } - - public int getType() { - return type; - } - - public void setType(int type) { - this.type = type; - } - -} diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBRefresh.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBRefresh.java deleted file mode 100644 index 7ac136dd20..0000000000 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBRefresh.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.gh.gamecenter.eventbus; - -/** - * Created by LGT on 2016/9/6. - */ -public class EBRefresh { - -} diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBReuse.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBReuse.java new file mode 100644 index 0000000000..71bb8905b1 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/eventbus/EBReuse.java @@ -0,0 +1,17 @@ +package com.gh.gamecenter.eventbus; + +/** + * Created by LGT on 2016/9/9. + */ +public class EBReuse { + + private String type; + + public EBReuse(String type) { + this.type = type; + } + + public String getType() { + return type; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBTopState.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBTopStatus.java similarity index 83% rename from app/src/main/java/com/gh/gamecenter/eventbus/EBTopState.java rename to app/src/main/java/com/gh/gamecenter/eventbus/EBTopStatus.java index 5c34996f2e..7ffbbbc2ef 100644 --- a/app/src/main/java/com/gh/gamecenter/eventbus/EBTopState.java +++ b/app/src/main/java/com/gh/gamecenter/eventbus/EBTopStatus.java @@ -1,11 +1,11 @@ package com.gh.gamecenter.eventbus; -public class EBTopState { +public class EBTopStatus { private String type; private String searchHint; - public EBTopState(String type, String searchHint) { + public EBTopStatus(String type, String searchHint) { super(); this.type = type; this.searchHint = searchHint; diff --git a/app/src/main/java/com/gh/gamecenter/game/Game1Fragment.java b/app/src/main/java/com/gh/gamecenter/game/Game1Fragment.java index f793f69910..db6af10b9f 100644 --- a/app/src/main/java/com/gh/gamecenter/game/Game1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/game/Game1Fragment.java @@ -21,10 +21,10 @@ import com.gh.gamecenter.R; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.SubjectEntity; -import com.gh.gamecenter.eventbus.EBDownloadDelete; +import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.eventbus.EBRefresh; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBUISwitch; import java.util.ArrayList; @@ -112,36 +112,38 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On } //下载被删除事件 - public void onEventMainThread(EBDownloadDelete busThree) { - DownloadManager.getInstance(getActivity()).removePlatform(busThree.getName(), busThree.getPlatform()); + public void onEventMainThread(EBDownloadStatus status) { + if ("delete".equals(status.getStatus())) { + DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform()); - ArrayList locationList = adapter.getLocationMap().get(busThree.getName()); - GameEntity detailedEntity; - if (locationList != null && locationList.size() != 0) { - for (int location : locationList) { - detailedEntity = getEntityByLocation(location); - if (detailedEntity != null) { - if (TextUtils.isEmpty(busThree.getPlatform())) { - detailedEntity.getEntryMap().remove("官方版"); - } else { - detailedEntity.getEntryMap().remove(busThree.getPlatform()); - } - } - adapter.notifyItemChanged(location); - } - } - //特殊 插件化update - if (busThree.getPluginPlatform() != null) { - locationList = adapter.getLocationMap().get(busThree.getName() + " - " + busThree.getPluginPlatform()); + ArrayList locationList = adapter.getLocationMap().get(status.getName()); + GameEntity detailedEntity; if (locationList != null && locationList.size() != 0) { for (int location : locationList) { detailedEntity = getEntityByLocation(location); if (detailedEntity != null) { - detailedEntity.setEntryMap(null); + if (TextUtils.isEmpty(status.getPlatform())) { + detailedEntity.getEntryMap().remove("官方版"); + } else { + detailedEntity.getEntryMap().remove(status.getPlatform()); + } } adapter.notifyItemChanged(location); } } + //特殊 插件化update + if (status.getPluginPlatform() != null) { + locationList = adapter.getLocationMap().get(status.getName() + " - " + status.getPluginPlatform()); + if (locationList != null && locationList.size() != 0) { + for (int location : locationList) { + detailedEntity = getEntityByLocation(location); + if (detailedEntity != null) { + detailedEntity.setEntryMap(null); + } + adapter.notifyItemChanged(location); + } + } + } } } @@ -217,8 +219,8 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On } // 打开下载按钮事件 - public void onEventMainThread(EBRefresh refresh) { - if (adapter != null) { + public void onEventMainThread(EBReuse reuse) { + if ("Refresh".equals(reuse.getType()) && adapter != null) { adapter.notifyItemRangeChanged(0, adapter.getItemCount()); } } diff --git a/app/src/main/java/com/gh/gamecenter/game/Game1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/game/Game1FragmentAdapter.java index bf2e156dd2..b72792a1c9 100644 --- a/app/src/main/java/com/gh/gamecenter/game/Game1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/game/Game1FragmentAdapter.java @@ -542,7 +542,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter locationList = adapter.getLocationMap().get(busThree.getName()); - if (locationList != null && locationList.size() != 0) { - for (int location : locationList) { - GameEntity detailedEntity = getEntityByLocation(location); - if (detailedEntity != null) { - if (TextUtils.isEmpty(busThree.getPlatform())) { - detailedEntity.getEntryMap().remove("官方版"); - } else { - detailedEntity.getEntryMap().remove(busThree.getPlatform()); + ArrayList locationList = adapter.getLocationMap().get(status.getName()); + if (locationList != null && locationList.size() != 0) { + for (int location : locationList) { + GameEntity detailedEntity = getEntityByLocation(location); + if (detailedEntity != null) { + if (TextUtils.isEmpty(status.getPlatform())) { + detailedEntity.getEntryMap().remove("官方版"); + } else { + detailedEntity.getEntryMap().remove(status.getPlatform()); + } } + adapter.notifyItemChanged(location); } - adapter.notifyItemChanged(location); } } } // 打开下载按钮事件 - public void onEventMainThread(EBRefresh refresh) { - if (adapter != null) { + public void onEventMainThread(EBReuse reuse) { + if ("Refresh".equals(reuse.getType()) && adapter != null) { adapter.notifyItemRangeChanged(0, adapter.getItemCount()); } } diff --git a/app/src/main/java/com/gh/gamecenter/game/Game3Fragment.java b/app/src/main/java/com/gh/gamecenter/game/Game3Fragment.java index 9f08976696..5482e58d51 100644 --- a/app/src/main/java/com/gh/gamecenter/game/Game3Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/game/Game3Fragment.java @@ -21,10 +21,10 @@ import com.gh.download.DownloadManager; import com.gh.gamecenter.R; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; -import com.gh.gamecenter.eventbus.EBDownloadDelete; +import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.eventbus.EBRefresh; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBUISwitch; /** @@ -111,26 +111,28 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener { } //下载被删除事件 - public void onEventMainThread(EBDownloadDelete busThree) { - DownloadManager.getInstance(getActivity()).removePlatform(busThree.getName(), busThree.getPlatform()); + public void onEventMainThread(EBDownloadStatus status) { + if ("delete".equals(status.getStatus())) { + DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform()); - Integer location = adapter.getLocationMap().get(busThree.getName()); - if (location != null) { - int index = location; + Integer location = adapter.getLocationMap().get(status.getName()); + if (location != null) { + int index = location; - GameEntity detailedEntity = adapter.getList().get(index); - if (TextUtils.isEmpty(busThree.getPlatform())) { - detailedEntity.getEntryMap().remove("官方版"); - } else { - detailedEntity.getEntryMap().remove(busThree.getPlatform()); + GameEntity detailedEntity = adapter.getList().get(index); + if (TextUtils.isEmpty(status.getPlatform())) { + detailedEntity.getEntryMap().remove("官方版"); + } else { + detailedEntity.getEntryMap().remove(status.getPlatform()); + } + adapter.notifyItemChanged(index); } - adapter.notifyItemChanged(index); } } // 打开下载按钮事件 - public void onEventMainThread(EBRefresh refresh) { - if (adapter != null) { + public void onEventMainThread(EBReuse reuse) { + if ("Refresh".equals(reuse.getType()) && adapter != null) { adapter.notifyItemRangeChanged(0, adapter.getItemCount()); } } diff --git a/app/src/main/java/com/gh/gamecenter/game/GameFragment.java b/app/src/main/java/com/gh/gamecenter/game/GameFragment.java index 7175163115..541a915109 100644 --- a/app/src/main/java/com/gh/gamecenter/game/GameFragment.java +++ b/app/src/main/java/com/gh/gamecenter/game/GameFragment.java @@ -1,48 +1,22 @@ package com.gh.gamecenter.game; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.app.FragmentTransaction; -import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; -import android.text.TextUtils; import android.util.DisplayMetrics; -import android.view.LayoutInflater; +import android.view.Gravity; import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; -import android.widget.RelativeLayout; import android.widget.TextView; -import com.gh.common.constant.Config; -import com.gh.common.util.DataUtils; +import com.gh.base.HomeFragment; import com.gh.common.util.DisplayUtils; -import com.gh.download.DownloadManager; -import com.gh.gamecenter.ConcernActivity; -import com.gh.gamecenter.DownloadManagerActivity; -import com.gh.gamecenter.MainActivity; import com.gh.gamecenter.R; -import com.gh.gamecenter.SearchActivity; -import com.gh.gamecenter.eventbus.EBRedDot; import com.gh.gamecenter.eventbus.EBSkip; -import com.gh.gamecenter.eventbus.EBTopState; import com.gh.gamecenter.eventbus.EBUISwitch; -import com.gh.gamecenter.manager.DataCollectionManager; -import com.gh.gamecenter.manager.PackageManager; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; import de.greenrobot.event.EventBus; @@ -52,26 +26,15 @@ import de.greenrobot.event.EventBus; * @email 294299195@qq.com * @date 2015-8-8 主页fragment3页面 */ -public class GameFragment extends Fragment implements OnClickListener, OnPageChangeListener { +public class GameFragment extends HomeFragment implements OnPageChangeListener { - private View view; - private View slideLine; - private ViewPager viewPager; - private TextView jingpinText; - private TextView zuixinText; - private TextView danjiText; - private TextView downloadHint; - private TextView searchHint; - - private RelativeLayout.LayoutParams rparams; - - private String hint; + private TextView tv_chajian; + private TextView tv_tuijian; + private TextView tv_danji; private int width; private int currentItem; - private Handler handler = new Handler(); - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -82,121 +45,63 @@ public class GameFragment extends Fragment implements OnClickListener, OnPageCha public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - view = View.inflate(getActivity(), R.layout.plugin_container_fragments, null); + initTextView(); - SharedPreferences sp = getActivity().getSharedPreferences( - Config.PREFERENCE, Context.MODE_PRIVATE); - - LinearLayout home_actionbar = (LinearLayout) view.findViewById(R.id.home_actionbar); - LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, - sp.getInt("actionbar_height", DisplayUtils.dip2px(getActivity(), 48))); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - int top = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height"); - home_actionbar.setPadding(0, top, 0, 0); - params.height += top; - } - - home_actionbar.setLayoutParams(params); - - initActionBar(); - - jingpinText = (TextView) view.findViewById(R.id.jingpin_text); - zuixinText = (TextView) view.findViewById(R.id.zuixin_text); - danjiText = (TextView) view.findViewById(R.id.danji_text); - - jingpinText.setOnClickListener(this); - zuixinText.setOnClickListener(this); - danjiText.setOnClickListener(this); - - slideLine = view.findViewById(R.id.slide_line); - DisplayMetrics outMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); - width = outMetrics.widthPixels / 3; - rparams = new RelativeLayout.LayoutParams(width / 2, - DisplayUtils.dip2px(getActivity(), 2)); - rparams.addRule(RelativeLayout.BELOW, R.id.plugin_ll_top); - - viewPager = (ViewPager) view.findViewById(R.id.pager); - viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager())); - viewPager.addOnPageChangeListener(this); + home_vp_content.setAdapter(new FragmentAdapter(getChildFragmentManager())); + home_vp_content.addOnPageChangeListener(this); currentItem = 0; if (savedInstanceState != null) { currentItem = savedInstanceState.getInt("currentItem"); } - viewPager.setCurrentItem(currentItem); + home_vp_content.setCurrentItem(currentItem); - rparams.leftMargin = width * currentItem + width / 4; - slideLine.setLayoutParams(rparams); - - EventBus.getDefault().register(this); + DisplayMetrics outMetrics = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); + width = outMetrics.widthPixels / 3; + lparams = new LinearLayout.LayoutParams(width / 2, + DisplayUtils.dip2px(getActivity(), 2)); + lparams.leftMargin = width * currentItem + width / 4; + home_slide_line.setLayoutParams(lparams); handler.postDelayed(new Runnable() { @Override public void run() { - EventBus.getDefault().post(new EBUISwitch("GameFragment", viewPager.getCurrentItem())); + EventBus.getDefault().post(new EBUISwitch("GameFragment", home_vp_content.getCurrentItem())); } }, 100); } - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - if (container != null) { - container.removeView(view); - } - return view; - } + private void initTextView() { + tv_chajian = new TextView(getActivity()); + tv_chajian.setText("插件"); + tv_chajian.setTextColor(getResources().getColor(R.color.theme)); + tv_chajian.setGravity(Gravity.CENTER); + tv_chajian.setOnClickListener(this); + LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams1.weight = 1; + home_ll_top.addView(tv_chajian, lparams1); - private void initActionBar() { - view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this); + tv_tuijian = new TextView(getActivity()); + tv_tuijian.setText("推荐"); + tv_tuijian.setTextColor(getResources().getColor(R.color.title)); + tv_tuijian.setGravity(Gravity.CENTER); + tv_tuijian.setOnClickListener(this); + LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams2.weight = 1; + home_ll_top.addView(tv_tuijian, lparams2); - view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this); - - if (Config.isShow(getActivity())) { - view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE); - } else { - view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE); - } - - downloadHint = (TextView) view.findViewById(R.id.action_tip); - int updateSize = PackageManager.getUpdateListSize(); - int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); - if (downloadSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize)); - int width = DisplayUtils.dip2px(getActivity(), 12); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( - width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else if (updateSize != 0) { - downloadHint.setText(""); - int width = DisplayUtils.dip2px(getActivity(), 10); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( - width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else { - downloadHint.setVisibility(View.GONE); - } - - searchHint = (TextView) view.findViewById(R.id.actionbar_search_input); - searchHint.setOnClickListener(this); - if (!TextUtils.isEmpty(MainActivity.searchHint)) { - hint = MainActivity.searchHint; - searchHint.setHint(hint); - } - - view.findViewById(R.id.actionbar_notification).setOnClickListener(this); - - if (downloadSize != 0 || updateSize != 0) { - EventBus.getDefault().post(new EBTopState("显示", null)); - } + tv_danji = new TextView(getActivity()); + tv_danji.setText("单机"); + tv_danji.setTextColor(getResources().getColor(R.color.title)); + tv_danji.setGravity(Gravity.CENTER); + tv_danji.setOnClickListener(this); + LinearLayout.LayoutParams lparams3 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams3.weight = 1; + home_ll_top.addView(tv_danji, lparams3); } private class FragmentAdapter extends FragmentPagerAdapter { @@ -225,77 +130,30 @@ public class GameFragment extends Fragment implements OnClickListener, OnPageCha @Override public void onClick(View v) { - final int id = v.getId(); - if (id == R.id.actionbar_notification) { - DataUtils.onEvent(getActivity(), "主页", "关注图标"); - - Map map = new HashMap(); - map.put("location", "关注图标"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - startActivity(new Intent(getActivity(), ConcernActivity.class)); - } else if (id == R.id.actionbar_rl_download) { - DataUtils.onEvent(getActivity(), "主页", "下载图标"); - - Map map = new HashMap(); - map.put("location", "下载图标"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - startActivity(new Intent(getActivity(), DownloadManagerActivity.class)); - } else if (id == R.id.actionbar_search_input) { - DataUtils.onEvent(getActivity(), "主页", "搜索框"); - - Map map = new HashMap(); - map.put("location", "搜索框"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - Intent goSearch = new Intent(getActivity(), SearchActivity.class); - goSearch.putExtra("clicked", false); - goSearch.putExtra("hint", hint); - startActivity(goSearch); - } else if (id == R.id.actionbar_iv_search) { - DataUtils.onEvent(getActivity(), "主页", "搜索图标"); - - Map map = new HashMap(); - map.put("location", "搜索图标"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - Intent searchIntent = new Intent(getActivity(), - SearchActivity.class); - searchIntent.putExtra("clicked", true); - searchIntent.putExtra("hint", hint); - startActivity(searchIntent); - } else if (id == R.id.jingpin_text) { - viewPager.setCurrentItem(0); - } else if (id == R.id.zuixin_text) { - viewPager.setCurrentItem(1); - } else if (id == R.id.danji_text) { - viewPager.setCurrentItem(2); + super.onClick(v); + if (v == tv_chajian) { + home_vp_content.setCurrentItem(0); + } else if (v == tv_tuijian) { + home_vp_content.setCurrentItem(1); + } else if (v == tv_danji) { + home_vp_content.setCurrentItem(2); } } @Override public void onPageSelected(int position) { if (position == 0) { - jingpinText.setTextColor(getResources().getColor(R.color.theme)); - zuixinText.setTextColor(getResources().getColor(R.color.title)); - danjiText.setTextColor(getResources().getColor(R.color.title)); + tv_chajian.setTextColor(getResources().getColor(R.color.theme)); + tv_tuijian.setTextColor(getResources().getColor(R.color.title)); + tv_danji.setTextColor(getResources().getColor(R.color.title)); } else if (position == 1) { - jingpinText.setTextColor(getResources().getColor(R.color.title)); - zuixinText.setTextColor(getResources().getColor(R.color.theme)); - danjiText.setTextColor(getResources().getColor(R.color.title)); + tv_chajian.setTextColor(getResources().getColor(R.color.title)); + tv_tuijian.setTextColor(getResources().getColor(R.color.theme)); + tv_danji.setTextColor(getResources().getColor(R.color.title)); } else if (position == 2) { - jingpinText.setTextColor(getResources().getColor(R.color.title)); - zuixinText.setTextColor(getResources().getColor(R.color.title)); - danjiText.setTextColor(getResources().getColor(R.color.theme)); + tv_chajian.setTextColor(getResources().getColor(R.color.title)); + tv_tuijian.setTextColor(getResources().getColor(R.color.title)); + tv_danji.setTextColor(getResources().getColor(R.color.theme)); } } @@ -303,11 +161,11 @@ public class GameFragment extends Fragment implements OnClickListener, OnPageCha public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (positionOffset != 0) { - rparams.leftMargin = (int) (width * (position + positionOffset) + width / 4); - slideLine.setLayoutParams(rparams); + lparams.leftMargin = (int) (width * (position + positionOffset) + width / 4); + home_slide_line.setLayoutParams(lparams); } else { - if (currentItem != viewPager.getCurrentItem()) { - currentItem = viewPager.getCurrentItem(); + if (currentItem != home_vp_content.getCurrentItem()) { + currentItem = home_vp_content.getCurrentItem(); EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem)); } } @@ -322,97 +180,23 @@ public class GameFragment extends Fragment implements OnClickListener, OnPageCha if ("MainActivity".equals(busNine.getFrom())) { if (busNine.getPosition() == 0) { EventBus.getDefault().post( - new EBUISwitch("GameFragment", viewPager.getCurrentItem())); + new EBUISwitch("GameFragment", home_vp_content.getCurrentItem())); } } } public void onEventMainThread(EBSkip skip) { if ("MainActivity".equals(skip.getType())) { - viewPager.setCurrentItem(skip.getCurrentItem()); + home_vp_content.setCurrentItem(skip.getCurrentItem()); } } - public void onEventMainThread(EBTopState busTen) { - if ("搜索".equals(busTen.getType())) { - hint = busTen.getSearchHint(); - searchHint.setHint(busTen.getSearchHint()); - } else if ("隐藏".equals(busTen.getType())) { - if (downloadHint != null) { - downloadHint.setVisibility(View.GONE); - } - } - } - - public void onEventMainThread(EBRedDot busEight) { - updateRedDot(busEight.getType()); - } - - public void updateRedDot(int type) { - int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); - if (type == 1 && downloadSize == 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize + type)); - int width = DisplayUtils.dip2px(getActivity(), 12); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else if (type == -1 && (downloadSize == 0 || downloadSize == 1)) { - int updateSize = PackageManager.getUpdateList().size(); - if (updateSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(""); - int width = DisplayUtils.dip2px(getActivity(), 10); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else { - downloadHint.setVisibility(View.GONE); - } - } else if (downloadSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize + type)); - } - } - - @Override - public void onHiddenChanged(boolean hidden) { - super.onHiddenChanged(hidden); - FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); - List list = getChildFragmentManager().getFragments(); - if (list != null) { - if (hidden) { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.hide(fragment); - } - } else { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.show(fragment); - } - } - } - transaction.commit(); - } - @Override public void onDestroy() { super.onDestroy(); - EventBus.getDefault().unregister(this); - view = null; - slideLine = null; - viewPager = null; - jingpinText = null; - zuixinText = null; - danjiText = null; - downloadHint = null; - searchHint = null; - rparams = null; - hint = null; - handler = null; + tv_chajian = null; + tv_tuijian = null; + tv_danji = null; } } diff --git a/app/src/main/java/com/gh/gamecenter/listener/AdapterCallBackListener.java b/app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java similarity index 78% rename from app/src/main/java/com/gh/gamecenter/listener/AdapterCallBackListener.java rename to app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java index ebdde961c9..10079b7dd8 100644 --- a/app/src/main/java/com/gh/gamecenter/listener/AdapterCallBackListener.java +++ b/app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java @@ -3,7 +3,7 @@ package com.gh.gamecenter.listener; /** * Created by Administrator on 2016/9/8. */ -public interface AdapterCallBackListener { +public interface OnCallBackListener { void loadDone(); void loadError(); diff --git a/app/src/main/java/com/gh/gamecenter/manager/ConcernManager.java b/app/src/main/java/com/gh/gamecenter/manager/ConcernManager.java index ae93a3396f..915332e0ed 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/ConcernManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/ConcernManager.java @@ -32,10 +32,7 @@ public class ConcernManager { */ public boolean isConcern(String id) { ConcernInfo concernEntity = dao.find(id); - if (concernEntity != null) { - return concernEntity.isConcern(); - } - return false; + return concernEntity != null && concernEntity.isConcern(); } /** @@ -54,7 +51,7 @@ public class ConcernManager { concernEntity.setGameName(entity.getName()); concernEntity.setConcern(true); String tag = "已关注"; - HashMap packageNames = new HashMap(); + HashMap packageNames = new HashMap<>(); int weight = 1; int quantity = 0; for (ApkEntity apkEntity : entity.getApk()) { @@ -70,13 +67,12 @@ public class ConcernManager { tag = "已关注,已安装"; } concernEntity.setInstalledQuantity(quantity); - concernEntity.setInstalled(weight == 1 ? false : true); + concernEntity.setInstalled(weight != 1); concernEntity.setTag(tag); concernEntity.setPackageNames(packageNames); long traffic = TrafficUtils .getInstance(context) - .getTraffic( - new ArrayList(packageNames.keySet())); + .getTraffic(new ArrayList<>(packageNames.keySet())); concernEntity.setTraffic(traffic); if (traffic > 0) { weight++; @@ -87,7 +83,7 @@ public class ConcernManager { concernEntity.setTime(System.currentTimeMillis()); concernEntity.setIcon(entity.getIcon()); concernEntity.setConcern(true); - HashMap packageNames = new HashMap(); + HashMap packageNames = new HashMap<>(); int quantity = 0; for (ApkEntity apkEntity : entity.getApk()) { if (PackageManager.isInstalled(apkEntity.getPackageName())) { @@ -102,8 +98,7 @@ public class ConcernManager { concernEntity.setPackageNames(packageNames); long traffic = TrafficUtils .getInstance(context) - .getTraffic( - new ArrayList(packageNames.keySet())); + .getTraffic(new ArrayList<>(packageNames.keySet())); concernEntity.setTraffic(traffic); int weight = 2; if (traffic > 0) { @@ -112,8 +107,7 @@ public class ConcernManager { concernEntity.setWeight(weight); updateByConcern(concernEntity); } - EventBus.getDefault() - .post(new EBConcernChanged(entity.getId())); + EventBus.getDefault().post(new EBConcernChanged(entity.getId(), true)); } }.start(); } @@ -121,8 +115,7 @@ public class ConcernManager { /** * 根据GameEntity更新关注 */ - public void updateByEntity(com.gh.gamecenter.db.info.GameInfo gameEntity, - boolean flag) { + public void updateByEntity(com.gh.gamecenter.db.info.GameInfo gameEntity) { String packageName = gameEntity.getPackageName(); ConcernInfo concernEntity = findConcernById(gameEntity.getId()); if (concernEntity != null) { @@ -134,10 +127,6 @@ public class ConcernManager { concernEntity.setInstalledQuantity(concernEntity .getInstalledQuantity() + 1); updateByConcern(concernEntity); - if (flag) { - EventBus.getDefault().post( - new EBConcernChanged(concernEntity.getId())); - } } else if (concernEntity.isConcern() && !concernEntity.isInstalled()) { concernEntity.setTag("已关注,已安装"); @@ -147,16 +136,12 @@ public class ConcernManager { int weight = concernEntity.getWeight() + 1; concernEntity.setWeight(weight); updateByConcern(concernEntity); - if (flag) { - EventBus.getDefault().post( - new EBConcernChanged(concernEntity.getId())); - } } } else { concernEntity = new ConcernInfo(); concernEntity.setId(gameEntity.getId()); concernEntity.setTime(System.currentTimeMillis()); - HashMap packageNames = new HashMap(); + HashMap packageNames = new HashMap<>(); packageNames.put(packageName, true); concernEntity.setPackageNames(packageNames); concernEntity.setInstalled(true); @@ -171,10 +156,6 @@ public class ConcernManager { context, packageName)); } addConcern(concernEntity); - if (flag) { - EventBus.getDefault().post( - new EBConcernChanged(concernEntity.getId())); - } } } @@ -217,16 +198,12 @@ public class ConcernManager { concernEntity.setWeight(concernEntity.getWeight() - 1); updateByConcern(concernEntity); } - EventBus.getDefault().post( - new EBConcernChanged(concernEntity.getId())); } else if (concernEntity.getInstalledQuantity() - 1 > 0) { concernEntity.setTime(System.currentTimeMillis()); concernEntity.setInstalledQuantity(concernEntity .getInstalledQuantity() - 1); concernEntity.getPackageNames().put(packageName, false); updateByConcern(concernEntity); - EventBus.getDefault().post( - new EBConcernChanged(concernEntity.getId())); } break; } @@ -245,7 +222,7 @@ public class ConcernManager { * * @param number * 数量 - * @return + * @return list */ public List getConcern(int number) { return dao.get(number); @@ -272,7 +249,7 @@ public class ConcernManager { } else { dao.delete(id); } - EventBus.getDefault().post(new EBConcernChanged(id)); + EventBus.getDefault().post(new EBConcernChanged(id, false)); } /** @@ -293,7 +270,7 @@ public class ConcernManager { * 获取关注map */ public ArrayMap getConcernMap() { - ArrayMap map = new ArrayMap(); + ArrayMap map = new ArrayMap<>(); for (ConcernInfo entity : dao.getAll()) { map.put(entity.getId(), entity); } diff --git a/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java index 57858c0c3d..374c8ca501 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java @@ -295,6 +295,9 @@ public class News3FragmentAdapter extends if (position_before != -1) { head++; } + if (head == 0) { + return 0; + } return head + todayNewsList.size() + beforeNewsList.size() + 1; } diff --git a/app/src/main/java/com/gh/gamecenter/news/News4Fragment.java b/app/src/main/java/com/gh/gamecenter/news/News4Fragment.java index 14c91bba5a..69a8af13eb 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News4Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/news/News4Fragment.java @@ -12,15 +12,14 @@ import android.widget.LinearLayout; import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.BaseFragment; import com.gh.gamecenter.R; -import com.gh.gamecenter.eventbus.EBConcern; +import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBUISwitch; -import com.gh.gamecenter.listener.AdapterCallBackListener; /** * Created by khy on 2016/8/15. */ -public class News4Fragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, AdapterCallBackListener { +public class News4Fragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout news_swipe_refresh; private RecyclerView news_rv_show; @@ -76,7 +75,7 @@ public class News4Fragment extends BaseFragment implements SwipeRefreshLayout.On } // 关注事件 - public void onEventMainThread(EBConcern concern) { + public void onEventMainThread(EBConcernChanged changed) { if (reuse_none_data.getVisibility() == View.VISIBLE) { reuse_none_data.setVisibility(View.GONE); } @@ -87,9 +86,9 @@ public class News4Fragment extends BaseFragment implements SwipeRefreshLayout.On } //Fragment界面切换事件 - public void onEventMainThread(EBUISwitch busNine) { - if ("NewsFragment".equals(busNine.getFrom())) { - if (busNine.getPosition() == 3) { + public void onEventMainThread(EBUISwitch swith) { + if ("NewsFragment".equals(swith.getFrom())) { + if (swith.getPosition() == 3) { if (news_pb_loading.getVisibility() == View.VISIBLE) { adapter.loadDataByKey(0); } diff --git a/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java index 3fdfc19a6b..eee3c92b91 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java @@ -10,7 +10,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; import com.android.volley.NoConnectionError; @@ -33,7 +32,7 @@ import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; import com.gh.gamecenter.db.info.ConcernInfo; import com.gh.gamecenter.entity.ConcernEntity; -import com.gh.gamecenter.listener.AdapterCallBackListener; +import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; @@ -63,7 +62,7 @@ public class News4FragmentAdapter extends RecyclerView.Adapter concernList; private ArrayMap viewsMap; diff --git a/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java b/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java index 3c31be8fff..94fb9fe58b 100644 --- a/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java +++ b/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java @@ -1,71 +1,37 @@ package com.gh.gamecenter.news; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; -import android.text.TextUtils; import android.util.DisplayMetrics; -import android.view.LayoutInflater; +import android.view.Gravity; import android.view.View; -import android.view.ViewGroup; import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.TextView; -import com.gh.common.constant.Config; -import com.gh.common.util.DataUtils; +import com.gh.base.HomeFragment; import com.gh.common.util.DisplayUtils; -import com.gh.download.DownloadManager; -import com.gh.gamecenter.ConcernActivity; -import com.gh.gamecenter.DownloadManagerActivity; -import com.gh.gamecenter.MainActivity; import com.gh.gamecenter.R; -import com.gh.gamecenter.SearchActivity; -import com.gh.gamecenter.eventbus.EBRedDot; -import com.gh.gamecenter.eventbus.EBTopState; import com.gh.gamecenter.eventbus.EBUISwitch; -import com.gh.gamecenter.manager.DataCollectionManager; -import com.gh.gamecenter.manager.PackageManager; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; import de.greenrobot.event.EventBus; /** * Created by khy on 2016/6/29. */ -public class NewsFragment extends Fragment implements View.OnClickListener, ViewPager.OnPageChangeListener { +public class NewsFragment extends HomeFragment implements View.OnClickListener, ViewPager.OnPageChangeListener { - private View view; - private View slideLine; - private ViewPager viewPager; - private TextView tvZixun; - private TextView tvYuanchuang; - private TextView tvGonglve; - private TextView tvGuanzhu; - private TextView downloadHint; - private TextView searchHint; - - private RelativeLayout.LayoutParams rparams; - - private String hint; + private TextView tv_zixun; + private TextView tv_yuanchuang; + private TextView tv_gonglve; + private TextView tv_guanzhu; private int width; private int currentItem; - private Handler handler = new Handler(); - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -76,127 +42,74 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - view = View.inflate(getActivity(), R.layout.fragment_news, null); + initTextView(); - 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))); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - int top = DisplayUtils.getInternalDimensionSize(getResources(), - "status_bar_height"); - home_actionbar.setPadding(0, top, 0, 0); - lparams.height += top; - } - home_actionbar.setLayoutParams(lparams); - - initActionBar(); - - tvZixun = (TextView) view.findViewById(R.id.zixun_text); - tvYuanchuang = (TextView) view.findViewById(R.id.yuanchuang_text); - tvGonglve = (TextView) view.findViewById(R.id.gonglue_text); - tvGuanzhu = (TextView) view.findViewById(R.id.guanzhu_text); - - tvZixun.setOnClickListener(this); - tvYuanchuang.setOnClickListener(this); - tvGonglve.setOnClickListener(this); - tvGuanzhu.setOnClickListener(this); - - slideLine = view.findViewById(R.id.slide_line); - DisplayMetrics outMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay() - .getMetrics(outMetrics); - width = outMetrics.widthPixels / 4; - rparams = new RelativeLayout.LayoutParams(width / 2, - DisplayUtils.dip2px(getActivity(), 2)); - rparams.addRule(RelativeLayout.BELOW, R.id.plugin_ll_top); - - viewPager = (ViewPager) view.findViewById(R.id.news_vp); - viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager())); - viewPager.addOnPageChangeListener(this); + home_vp_content.setAdapter(new FragmentAdapter(getChildFragmentManager())); + home_vp_content.addOnPageChangeListener(this); currentItem = 0; if (savedInstanceState != null) { currentItem = savedInstanceState.getInt("currentItem"); } - viewPager.setCurrentItem(currentItem); + home_vp_content.setCurrentItem(currentItem); - rparams.leftMargin = width * currentItem + width / 4; - slideLine.setLayoutParams(rparams); - - EventBus.getDefault().register(this); + DisplayMetrics outMetrics = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay() + .getMetrics(outMetrics); + width = outMetrics.widthPixels / 4; + lparams = new LinearLayout.LayoutParams(width / 2, + DisplayUtils.dip2px(getActivity(), 2)); + lparams.leftMargin = width * currentItem + width / 4; + home_slide_line.setLayoutParams(lparams); handler.postDelayed(new Runnable() { @Override public void run() { - EventBus.getDefault().post(new EBUISwitch("NewsFragment", viewPager.getCurrentItem())); + EventBus.getDefault().post(new EBUISwitch("NewsFragment", home_vp_content.getCurrentItem())); } }, 100); } - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - if (container != null){ - container.removeView(view); - } - return view; - } + private void initTextView() { + tv_zixun = new TextView(getActivity()); + tv_zixun.setText("资讯"); + tv_zixun.setTextColor(getResources().getColor(R.color.theme)); + tv_zixun.setGravity(Gravity.CENTER); + tv_zixun.setOnClickListener(this); + LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams1.weight = 1; + home_ll_top.addView(tv_zixun, lparams1); - private void initActionBar() { - view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this); + tv_yuanchuang = new TextView(getActivity()); + tv_yuanchuang.setText("原创"); + tv_yuanchuang.setTextColor(getResources().getColor(R.color.title)); + tv_yuanchuang.setGravity(Gravity.CENTER); + tv_yuanchuang.setOnClickListener(this); + LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams2.weight = 1; + home_ll_top.addView(tv_yuanchuang, lparams2); - view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this); + tv_gonglve = new TextView(getActivity()); + tv_gonglve.setText("攻略"); + tv_gonglve.setTextColor(getResources().getColor(R.color.title)); + tv_gonglve.setGravity(Gravity.CENTER); + tv_gonglve.setOnClickListener(this); + LinearLayout.LayoutParams lparams3 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams3.weight = 1; + home_ll_top.addView(tv_gonglve, lparams3); - if (Config.isShow(getActivity())) { - view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE); - } else { - view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE); - } - - downloadHint = (TextView) view.findViewById(R.id.action_tip); - int updateSize = PackageManager.getUpdateListSize(); - int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); - if (downloadSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize)); - int width = DisplayUtils.dip2px(getActivity(), 12); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( - width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else if (updateSize != 0) { - downloadHint.setText(""); - int width = DisplayUtils.dip2px(getActivity(), 10); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( - width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else { - downloadHint.setVisibility(View.GONE); - } - - searchHint = (TextView) view.findViewById(R.id.actionbar_search_input); - searchHint.setOnClickListener(this); - if (!TextUtils.isEmpty(MainActivity.searchHint)) { - hint = MainActivity.searchHint; - searchHint.setHint(hint); - } - - view.findViewById(R.id.actionbar_notification).setOnClickListener(this); - - if (downloadSize != 0 || updateSize != 0) { - EventBus.getDefault().post(new EBTopState("显示", null)); - } + tv_guanzhu = new TextView(getActivity()); + tv_guanzhu.setText("关注"); + tv_guanzhu.setTextColor(getResources().getColor(R.color.title)); + tv_guanzhu.setGravity(Gravity.CENTER); + tv_guanzhu.setOnClickListener(this); + LinearLayout.LayoutParams lparams4 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams4.weight = 1; + home_ll_top.addView(tv_guanzhu, lparams4); } public class FragmentAdapter extends FragmentPagerAdapter{ @@ -226,62 +139,15 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View @Override public void onClick(View v) { - final int id = v.getId(); - if (id == R.id.actionbar_notification) { - DataUtils.onEvent(getActivity(), "主页", "关注图标"); - - Map map = new HashMap<>(); - map.put("location", "关注图标"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - startActivity(new Intent(getActivity(), ConcernActivity.class)); - } else if (id == R.id.actionbar_rl_download) { - DataUtils.onEvent(getActivity(), "主页", "下载图标"); - - Map map = new HashMap<>(); - map.put("location", "下载图标"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - startActivity(new Intent(getActivity(), DownloadManagerActivity.class)); - } else if (id == R.id.actionbar_search_input) { - DataUtils.onEvent(getActivity(), "主页", "搜索框"); - - Map map = new HashMap<>(); - map.put("location", "搜索框"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - Intent goSearch = new Intent(getActivity(), SearchActivity.class); - goSearch.putExtra("clicked", false); - goSearch.putExtra("hint", hint); - startActivity(goSearch); - } else if (id == R.id.actionbar_iv_search) { - DataUtils.onEvent(getActivity(), "主页", "搜索图标"); - - Map map = new HashMap<>(); - map.put("location", "搜索图标"); - map.put("createOn", System.currentTimeMillis() / 1000); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - Intent searchIntent = new Intent(getActivity(), - SearchActivity.class); - searchIntent.putExtra("clicked", true); - searchIntent.putExtra("hint", hint); - startActivity(searchIntent); - } else if (id == R.id.zixun_text) { - viewPager.setCurrentItem(0); - } else if (id == R.id.yuanchuang_text) { - viewPager.setCurrentItem(1); - } else if (id == R.id.gonglue_text) { - viewPager.setCurrentItem(2); - } else if (id == R.id.guanzhu_text) { - viewPager.setCurrentItem(3); + super.onClick(v); + if (v == tv_zixun) { + home_vp_content.setCurrentItem(0); + } else if (v == tv_yuanchuang) { + home_vp_content.setCurrentItem(1); + } else if (v == tv_gonglve) { + home_vp_content.setCurrentItem(2); + } else if (v == tv_guanzhu) { + home_vp_content.setCurrentItem(3); } } @@ -289,11 +155,11 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (positionOffset != 0) { - rparams.leftMargin = (int) (width * (position + positionOffset) + width / 4); - slideLine.setLayoutParams(rparams); + lparams.leftMargin = (int) (width * (position + positionOffset) + width / 4); + home_slide_line.setLayoutParams(lparams); } else { - if (currentItem != viewPager.getCurrentItem()) { - currentItem = viewPager.getCurrentItem(); + if (currentItem != home_vp_content.getCurrentItem()) { + currentItem = home_vp_content.getCurrentItem(); EventBus.getDefault().post(new EBUISwitch("NewsFragment", currentItem)); } } @@ -302,25 +168,25 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View @Override public void onPageSelected(int position) { if (position == 0) { - tvZixun.setTextColor(getResources().getColor(R.color.theme)); - tvYuanchuang.setTextColor(getResources().getColor(R.color.title)); - tvGonglve.setTextColor(getResources().getColor(R.color.title)); - tvGuanzhu.setTextColor(getResources().getColor(R.color.title)); + tv_zixun.setTextColor(getResources().getColor(R.color.theme)); + tv_yuanchuang.setTextColor(getResources().getColor(R.color.title)); + tv_gonglve.setTextColor(getResources().getColor(R.color.title)); + tv_guanzhu.setTextColor(getResources().getColor(R.color.title)); } else if (position == 1) { - tvZixun.setTextColor(getResources().getColor(R.color.title)); - tvYuanchuang.setTextColor(getResources().getColor(R.color.theme)); - tvGonglve.setTextColor(getResources().getColor(R.color.title)); - tvGuanzhu.setTextColor(getResources().getColor(R.color.title)); + tv_zixun.setTextColor(getResources().getColor(R.color.title)); + tv_yuanchuang.setTextColor(getResources().getColor(R.color.theme)); + tv_gonglve.setTextColor(getResources().getColor(R.color.title)); + tv_guanzhu.setTextColor(getResources().getColor(R.color.title)); } else if (position == 2) { - tvZixun.setTextColor(getResources().getColor(R.color.title)); - tvYuanchuang.setTextColor(getResources().getColor(R.color.title)); - tvGonglve.setTextColor(getResources().getColor(R.color.theme)); - tvGuanzhu.setTextColor(getResources().getColor(R.color.title)); + tv_zixun.setTextColor(getResources().getColor(R.color.title)); + tv_yuanchuang.setTextColor(getResources().getColor(R.color.title)); + tv_gonglve.setTextColor(getResources().getColor(R.color.theme)); + tv_guanzhu.setTextColor(getResources().getColor(R.color.title)); }else if (position == 3){ - tvZixun.setTextColor(getResources().getColor(R.color.title)); - tvYuanchuang.setTextColor(getResources().getColor(R.color.title)); - tvGonglve.setTextColor(getResources().getColor(R.color.title)); - tvGuanzhu.setTextColor(getResources().getColor(R.color.theme)); + tv_zixun.setTextColor(getResources().getColor(R.color.title)); + tv_yuanchuang.setTextColor(getResources().getColor(R.color.title)); + tv_gonglve.setTextColor(getResources().getColor(R.color.title)); + tv_guanzhu.setTextColor(getResources().getColor(R.color.theme)); } } @@ -334,98 +200,18 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View if ("MainActivity".equals(busNine.getFrom())) { if (busNine.getPosition() == 1) { EventBus.getDefault().post( - new EBUISwitch("NewsFragment", viewPager.getCurrentItem())); + new EBUISwitch("NewsFragment", home_vp_content.getCurrentItem())); } } } - public void onEventMainThread(EBTopState busTen) { - if ("搜索".equals(busTen.getType())) { - hint = busTen.getSearchHint(); - searchHint.setHint(busTen.getSearchHint()); - } else if ("显示".equals(busTen.getType())) { - if (downloadHint != null) { - downloadHint.setVisibility(View.VISIBLE); - } - } else { - if (downloadHint != null) { - downloadHint.setVisibility(View.GONE); - } - } - } - - public void onEventMainThread(EBRedDot busEight) { - updateRedDot(busEight.getType()); - } - - public void updateRedDot(int type) { - int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); - if (type == 1 && downloadSize == 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize + type)); - int width = DisplayUtils.dip2px(getActivity(), 12); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( - width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else if (type == -1 && (downloadSize == 0 || downloadSize == 1)) { - int updateSize = PackageManager.getUpdateList().size(); - if (updateSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(""); - int width = DisplayUtils.dip2px(getActivity(), 10); - RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( - width, width); - rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8); - rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3); - rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - downloadHint.setLayoutParams(rparams); - } else { - downloadHint.setVisibility(View.GONE); - } - } else if (downloadSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize + type)); - } - } - - @Override - public void onHiddenChanged(boolean hidden) { - super.onHiddenChanged(hidden); - FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); - List list = getChildFragmentManager().getFragments(); - if (list != null) { - if (hidden) { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.hide(fragment); - } - } else { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.show(fragment); - } - } - } - transaction.commit(); - } - @Override public void onDestroy() { super.onDestroy(); - EventBus.getDefault().unregister(this); - view = null; - slideLine = null; - viewPager = null; - tvZixun = null; - tvYuanchuang = null; - tvGonglve = null; - tvGuanzhu = null; - downloadHint = null; - searchHint = null; - rparams = null; - hint = null; - handler = null; + tv_zixun = null; + tv_yuanchuang = null; + tv_gonglve = null; + tv_guanzhu = null; } } 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 6988e6d27b..4deade37d0 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragment.java @@ -16,10 +16,11 @@ import com.gh.download.DownloadEntry; import com.gh.download.DownloadManager; import com.gh.gamecenter.R; import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.eventbus.EBMoveTop; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.eventbus.EBRefresh; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBSlide; import de.greenrobot.event.EventBus; @@ -130,6 +131,21 @@ public class ConcernFragment extends BaseFragment { } } + // 关注事件 + public void onEventMainThread(EBConcernChanged changed) { + if (changed.isConcern()) { + + } else { + for (int i = 0; i < adapter.getGameList().size(); i++) { + if (adapter.getGameList().get(i).getId().equals(changed.getGameId())) { + adapter.getGameList().remove(i); + adapter.notifyDataSetChanged(); + break; + } + } + } + } + //连接上网络事件 public void onEventMainThread(EBNetworkState busNetworkState) { if (busNetworkState.isNetworkConnected()) { @@ -138,8 +154,8 @@ public class ConcernFragment extends BaseFragment { } // 打开下载按钮事件 - public void onEventMainThread(EBRefresh refresh) { - if (adapter != null) { + public void onEventMainThread(EBReuse reuse) { + if ("Refresh".equals(reuse.getType()) && adapter != null) { adapter.notifyItemRangeChanged(0, adapter.getItemCount()); } } 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 c8f174cefb..2045924c9c 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java @@ -209,7 +209,7 @@ public class ConcernFragmentAdapter extends RecyclerView.Adapter position - 2) { initGameNormal((GameNormalViewHolder) holder, gameList.get(position - 2), position - 2); } else if (holder instanceof ReuseViewHolder && position == getItemCount() - 1) { ReuseViewHolder viewHolder = (ReuseViewHolder) holder; diff --git a/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java b/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java index e8b4e5a7ea..99dcd69338 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java @@ -18,7 +18,7 @@ import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.eventbus.EBMoveTop; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.eventbus.EBRefresh; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBSlide; import de.greenrobot.event.EventBus; @@ -118,8 +118,8 @@ public class InstallFragment extends BaseFragment { } // 打开下载按钮事件 - public void onEventMainThread(EBRefresh refresh) { - if (adapter != null) { + public void onEventMainThread(EBReuse reuse) { + if ("Refresh".equals(reuse.getType()) && adapter != null) { adapter.notifyItemRangeChanged(0, adapter.getItemCount()); } } 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 386c2c84b8..b5e1de735e 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchHistoryFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchHistoryFragmentAdapter.java @@ -122,21 +122,17 @@ public class SearchHistoryFragmentAdapter extends RecyclerView.Adapter + android:layout_height="match_parent"> + android:paddingBottom="5dp"> - + android:background="@color/background" + android:padding="8dp" + app:left="8dp" + app:right="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 c88bca7589..35917a2baa 100644 --- a/app/src/main/res/layout/fm_downloadmanager_item.xml +++ b/app/src/main/res/layout/fm_downloadmanager_item.xml @@ -7,6 +7,7 @@ android:padding="12dp" android:orientation="horizontal" android:background="@drawable/reuse_listview_item_style" + android:clickable="true" app:left="8dp" app:bottom="8dp" app:right="8dp"> @@ -54,9 +55,9 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_news.xml b/app/src/main/res/layout/fragment_news.xml deleted file mode 100644 index b4c8915dd6..0000000000 --- a/app/src/main/res/layout/fragment_news.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ 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 8ee4e6df9c..59db919f78 100644 --- a/app/src/main/res/layout/home_actionbar.xml +++ b/app/src/main/res/layout/home_actionbar.xml @@ -24,10 +24,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/image_card_home_game_image_item.xml b/app/src/main/res/layout/image_card_home_game_image_item.xml deleted file mode 100644 index 583ce96cbc..0000000000 --- a/app/src/main/res/layout/image_card_home_game_image_item.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/image_card_home_game_normal_item.xml b/app/src/main/res/layout/image_card_home_game_normal_item.xml deleted file mode 100644 index 8484279359..0000000000 --- a/app/src/main/res/layout/image_card_home_game_normal_item.xml +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/image_card_home_game_test_item.xml b/app/src/main/res/layout/image_card_home_game_test_item.xml deleted file mode 100644 index 21a6eb05f1..0000000000 --- a/app/src/main/res/layout/image_card_home_game_test_item.xml +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/menu_popwindow.xml b/app/src/main/res/layout/menu_popwindow.xml deleted file mode 100644 index fc46fbf3b6..0000000000 --- a/app/src/main/res/layout/menu_popwindow.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/personal_footer_none_head.xml b/app/src/main/res/layout/personal_footer_none_head.xml deleted file mode 100644 index 7507b10387..0000000000 --- a/app/src/main/res/layout/personal_footer_none_head.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/plugin_container_fragments.xml b/app/src/main/res/layout/plugin_container_fragments.xml deleted file mode 100644 index 3b15cfe82c..0000000000 --- a/app/src/main/res/layout/plugin_container_fragments.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file