diff --git a/app/src/main/java/com/gh/base/BaseActivity.java b/app/src/main/java/com/gh/base/BaseActivity.java index 6a0e5c4ada..a0501a7629 100644 --- a/app/src/main/java/com/gh/base/BaseActivity.java +++ b/app/src/main/java/com/gh/base/BaseActivity.java @@ -218,6 +218,11 @@ public class BaseActivity extends Activity implements OnCallBackListener { @Override public void loadDone() { + + } + + @Override + public void loadDone(Object obj) { } diff --git a/app/src/main/java/com/gh/base/BaseFragment.java b/app/src/main/java/com/gh/base/BaseFragment.java index 9a1769a67c..ceb4874c2a 100644 --- a/app/src/main/java/com/gh/base/BaseFragment.java +++ b/app/src/main/java/com/gh/base/BaseFragment.java @@ -76,6 +76,11 @@ public class BaseFragment extends Fragment implements OnCallBackListener { } + @Override + public void loadDone(Object obj) { + + } + @Override public void loadError() { diff --git a/app/src/main/java/com/gh/common/util/NewsUtils.java b/app/src/main/java/com/gh/common/util/NewsUtils.java index 2ee01bcafe..5808d80f3f 100644 --- a/app/src/main/java/com/gh/common/util/NewsUtils.java +++ b/app/src/main/java/com/gh/common/util/NewsUtils.java @@ -9,7 +9,6 @@ import com.android.volley.VolleyError; import com.gh.base.AppController; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; -import com.gh.gamecenter.entity.NewsDetailEntity; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; @@ -45,12 +44,9 @@ public class NewsUtils { */ public static void startNewsActivity(Context context, NewsEntity newsEntity, String entrance) { Intent intent = new Intent(context, NewsDetailActivity.class); - NewsDetailEntity entity = new NewsDetailEntity(); - entity.setId(newsEntity.getId()); - entity.setTitle(newsEntity.getTitle()); - entity.setType(newsEntity.getType()); - entity.setTime(newsEntity.getPublishOn()); - intent.putExtra("entity", entity); + intent.putExtra("id", newsEntity.getId()); + intent.putExtra("title", newsEntity.getTitle()); + intent.putExtra("type", newsEntity.getType()); intent.putExtra("entrance", entrance); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); 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 5faa982c61..844de48d19 100644 --- a/app/src/main/java/com/gh/common/util/PlatformUtils.java +++ b/app/src/main/java/com/gh/common/util/PlatformUtils.java @@ -270,8 +270,7 @@ public class PlatformUtils { } isUpdate = true; JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST - + "v1d45/support/setting/platform", + TimestampUtils.addTimestamp(Config.HOST + "v1d45/support/setting/platform", Constants.PLATFORM_CD), new Response.Listener() { @Override diff --git a/app/src/main/java/com/gh/common/util/TimestampUtils.java b/app/src/main/java/com/gh/common/util/TimestampUtils.java index 5d234b5a55..7af137365b 100644 --- a/app/src/main/java/com/gh/common/util/TimestampUtils.java +++ b/app/src/main/java/com/gh/common/util/TimestampUtils.java @@ -18,30 +18,44 @@ public class TimestampUtils { */ public static long getTimestamp(String url, int cd) { if (map == null){ - map = new ArrayMap(); - map.put("^" + Config.HOST + "v1d45/index/kapaitoutiao" + "$", 5); - map.put("^" + Config.HOST + "v1d45/index/remenkapai" + "$", 10); - map.put("^" + Config.HOST + "v1d45/index/xincekapai" + "$", 15); - map.put("^" + Config.HOST + "v1d45/index/yuedujingxuan" + "$", 20); - map.put("^" + Config.HOST + "v1d45/index/zuixinchajian" + "$", 25); - map.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", 30); - map.put("^" + Config.HOST + "v1d45/plugin/slide" + "$", 40); - map.put("^" + Config.HOST + "v1d45/plugin/jingpin\\?limit=20\\&offset=.+" + "$", 35); - map.put("^" + Config.HOST + "v1d45/plugin/zuixin\\?limit=20\\&offset=.+" + "$", 45); - map.put("^" + Config.HOST + "v1d45/plugin/danji\\?limit=20\\&offset=.+" + "$", 50); - map.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", 60); - map.put("^" + Config.HOST + "v1d45/game/youxituijian" + "$", 85); - map.put("^" + Config.HOST + "v1d45/game/xincekapai\\?limit=10\\&offset=.+" + "$", 90); - map.put("^" + Config.HOST + "v1d45/game/.+/digest" + "$", 55); - map.put("^" + Config.HOST + "v1d45/game/.+/digest" + "$", 65); - map.put("^" + Config.HOST + "v1d45/game/.+/news_digest" + "$", 70); - map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3\\&offset=0\\&type_group=.+" + "$", 75); - map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=5\\&offset=0\\&type_group=.+" + "$", 80); - map.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", 95); - map.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 100); - map.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", 105); - map.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", 110); - map.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", 115); + map = new ArrayMap<>(); + map.put("^" + Config.HOST + "v2/version" + "$", 5); + map.put("^" + Config.HOST + "v2/disclaimer" + "$", 10); + map.put("^" + Config.HOST + "v2/stat/download" + "$", 15); + map.put("^" + Config.HOST + "v2/version\\?version_name=.+\\&channel=.+" + "$", 20); + map.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 25); + map.put("^" + Config.HOST + "v1d45/news/.+/digest" + "$", 30); + map.put("^" + Config.HOST + "v1d45/news/.+/detail" + "$", 35); + map.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", 40); + map.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", 45); + map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3" + "$", 50); + map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+" + "$", 55); + map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 60); + map.put("^" + Config.HOST + "v1d45/search/game/default" + "$", 65); + map.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", 70); + map.put("^" + Config.HOST + "v1d45/search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 75); + map.put("^" + Config.HOST + "v1d45/support/setting/ui" + "$", 80); + map.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", 85); + map.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", 90); + map.put("^" + Config.HOST + "v1d45/support/package/unused\\?skip=.+" + "$", 95); + map.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", 100); + map.put("^" + Config.HOST + "v1d45/support/package/latest\\?package=.+" + "$", 105); + map.put("^" + Config.HOST + "v1d45/support/setting/download/.+/switch2\\?version=.+" + "$", 110); + map.put("^" + Config.HOST + "v1d46/support/suggestion" + "$", 115); + map.put("^" + Config.HOST + "v1d50/index/slides" + "$", 120); + map.put("^" + Config.HOST + "v1d50/game/chajian" + "$", 125); + map.put("^" + Config.HOST + "v1d50/game/tuijian" + "$", 130); + map.put("^" + Config.HOST + "v1d50/game/column/.+\\?page=.+" + "$", 135); + map.put("^" + Config.HOST + "v1d50/game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 140); + map.put("^" + Config.HOST + "v1d50/news/zixun\\?limit=10\\&offset=.+" + "$", 145); + map.put("^" + Config.HOST + "v1d50/news/yuanchuang\\?limit=10\\&offset=.+" + "$", 150); + map.put("^" + Config.HOST + "v2d0/game/.+/digest" + "$", 155); + map.put("^" + Config.HOST + "v2d0/game/.+/detail" + "$", 160); + map.put("^" + Config.HOST + "v2d0/game/.+/news_digest" + "$", 165); + map.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?key=.+\\&limit=10\\&offset=.+" + "$", 170); + map.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?game_id=.+\\&limit=10\\&offset=.+" + "$", 175); + map.put("^" + Config.HOST + "v2d0/device/.+/concern" + "$", 180); + map.put("^" + Config.HOST + "v2d0/device/.+/concern/.+" + "$", 185); } long base = BASE; for (String key : map.keySet()){ diff --git a/app/src/main/java/com/gh/gamecenter/ConcernActivity.java b/app/src/main/java/com/gh/gamecenter/ConcernActivity.java index 8e972195a9..3e3e2325ae 100644 --- a/app/src/main/java/com/gh/gamecenter/ConcernActivity.java +++ b/app/src/main/java/com/gh/gamecenter/ConcernActivity.java @@ -112,8 +112,8 @@ public class ConcernActivity extends BaseActivity implements OnClickListener { private void initRecommendGame() { JsonArrayExtendedRequest recommendRequest = new JsonArrayExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST - + "v1d45/game/remenkapai", Constants.GAME_CD), + TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/remenkapai", + Constants.GAME_CD), new Response.Listener() { @Override public void onResponse(JSONArray response) { @@ -161,8 +161,9 @@ public class ConcernActivity extends BaseActivity implements OnClickListener { cCount = 0; for (int i = 0, size = list.size(); i < size; i++) { JsonObjectExtendedRequest concernObjectRequest = new JsonObjectExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/" - + list.get(i).getId() + "/digest", Constants.GAME_CD), + TimestampUtils.addTimestamp( + Config.HOST + "v2d0/game/" + list.get(i).getId() + "/digest", + Constants.GAME_CD), new Response.Listener() { @Override public void onResponse(JSONObject response) { diff --git a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java index de0d74313e..86b3a1c144 100644 --- a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java @@ -18,6 +18,7 @@ import com.android.volley.VolleyError; import com.gh.base.AppController; import com.gh.base.BaseActivity; import com.gh.common.constant.Config; +import com.gh.common.constant.Constants; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; @@ -26,15 +27,16 @@ import com.gh.common.util.MD5Utils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; +import com.gh.common.util.TimestampUtils; import com.gh.common.view.DownloadDialog; import com.gh.download.DataWatcher; import com.gh.download.DownloadEntity; 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.gamedetail.GameDetailAdapter; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; @@ -161,6 +163,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList @Override public void loadError() { if (!isDestroy) { + gamedetail_ll_loading.setVisibility(View.GONE); reuse_no_connection.setVisibility(View.VISIBLE); } } @@ -404,7 +407,8 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList // 获取游戏摘要 private void getGameDigest() { - String url = Config.HOST + "v1d45/game/" + gameId + "/digest"; + String url = TimestampUtils.addTimestamp(Config.HOST + "v2d0/game/" + gameId + "/digest", + Constants.GAME_CD); JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url, new Response.Listener() { @Override diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 5f15bdbcb9..8083e04ed6 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -470,9 +470,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (builder.length() != 0) { packages = builder.substring(0, builder.length() - 1); JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( - Config.HOST + "v1d45/support/package/update?package=" -// Config.HOST + "v1d45/support/package/latest?package=" - + packages, new Response.Listener() { + Config.HOST + "v1d45/support/package/update?package=" + packages +// Config.HOST + "v1d45/support/package/latest?package=" + packages + , new Response.Listener() { @Override public void onResponse(JSONArray response) { @@ -537,8 +537,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene count = 0; for (ConcernInfo info : infos) { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/" - + info.getId() + "/digest", Constants.GAME_CD), + TimestampUtils.addTimestamp( + Config.HOST + "v2d0/game/" + info.getId() + "/digest", + Constants.GAME_CD), new Response.Listener() { @Override public void onResponse(JSONObject response) { diff --git a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java index 211701c766..c5bc831a3a 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java @@ -1,30 +1,20 @@ package com.gh.gamecenter; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.support.v4.view.MotionEventCompat; -import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.util.DisplayMetrics; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; -import android.view.ViewGroup; import android.view.Window; -import android.webkit.JavascriptInterface; -import android.webkit.WebSettings; -import android.webkit.WebSettings.LayoutAlgorithm; -import android.webkit.WebView; -import android.webkit.WebViewClient; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -40,53 +30,38 @@ import com.gh.base.AppController; import com.gh.base.BaseActivity; import com.gh.common.constant.Config; import com.gh.common.constant.Constants; -import com.gh.common.util.ConcernUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.FileUtils; -import com.gh.common.util.ImageUtils; import com.gh.common.util.MD5Utils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.TimestampUtils; -import com.gh.common.util.Utils; import com.gh.common.view.DownloadDialog; import com.gh.download.DataWatcher; import com.gh.download.DownloadEntity; import com.gh.download.DownloadManager; 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.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.manager.ConcernManager; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; -import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; +import com.gh.gamecenter.newsdetail.NewsDetailAdapter; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import org.json.JSONArray; import org.json.JSONObject; -import java.lang.reflect.Type; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; -import java.util.Date; import java.util.HashMap; -import java.util.List; -import java.util.Locale; import java.util.Map; -import java.util.Random; import de.greenrobot.event.EventBus; @@ -97,16 +72,15 @@ import de.greenrobot.event.EventBus; */ public class NewsDetailActivity extends BaseActivity implements OnClickListener { - private LinearLayout essaydetail_ll_loading, essaydetail_ll_bottom, + private LinearLayout newsdetail_ll_loading, newsdetail_ll_bottom, reuse_no_connection; - private NewsDetailEntity entity; - private TextView actionbar_tv_title, essaydetail_tv_download, - essaydetail_tv_per; - private ProgressBar essaydetail_progressbar; + private TextView actionbar_tv_title, newsdetail_tv_download, + newsdetail_tv_per; + private ProgressBar newsdetail_progressbar; private GameEntity gameEntity; private DownloadEntity mDownloadEntity; - private RecyclerView essaydetail_rv_show; - private NewsAdapter adapter; + private RecyclerView newsdetail_rv_show; + private NewsDetailAdapter adapter; private LinearLayoutManager linearLayoutManager; private ImageView iv_share; @@ -117,18 +91,12 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener private boolean isSentReport = false; - private ConcernManager concernManager; - private Handler handler = new Handler(); - private float Y11, Y12, Y21, Y22; private float X11, X12, X21, X22; private boolean isSecondDown = false; private double R11; - private int mActivePointerId; - private WebSettings webSettings; - private int defaultTextZoom = 85; private int scrollSize = 300;//滑动距离超过300触发事件(放大缩小字体) private SharedPreferences sp; private int fontsize; @@ -155,9 +123,9 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener View contentView = View.inflate(this, R.layout.activity_newsdetail, null); - iv_share = new ImageView(this); iv_share.setImageResource(R.drawable.share_icon); + iv_share.setVisibility(View.GONE); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( DisplayUtils.dip2px(this, 20), DisplayUtils.dip2px(this, 20)); @@ -166,69 +134,54 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener params.setMargins(0, 0, DisplayUtils.dip2px(this, 10), 0); RelativeLayout reuse_actionbar = (RelativeLayout) contentView.findViewById(R.id.reuse_actionbar); - reuse_actionbar.addView(iv_share,params); + reuse_actionbar.addView(iv_share, params); init(contentView); - concernManager = new ConcernManager(getApplicationContext()); - DisplayMetrics outMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(outMetrics); + iv_share.setOnClickListener(this); + reuse_no_connection.setOnClickListener(this); + newsdetail_tv_per.setOnClickListener(this); + newsdetail_progressbar.setOnClickListener(this); + newsdetail_tv_download.setOnClickListener(this); + newsdetail_ll_bottom.setOnClickListener(this); + entrance = (String) getIntent().getExtras().get("entrance"); + + newsdetail_rv_show.setHasFixedSize(true); + linearLayoutManager = new LinearLayoutManager(this); + newsdetail_rv_show.setLayoutManager(linearLayoutManager); + adapter = new NewsDetailAdapter(this, entrance); + newsdetail_rv_show.setAdapter(adapter); + newsId = getIntent().getStringExtra("newsId"); if (newsId == null) { - entity = (NewsDetailEntity) getIntent().getExtras().get("entity"); - if (entity != null && entity.getType() != null) { - actionbar_tv_title.setText(entity.getType()); + String id = getIntent().getStringExtra("id"); + String type = getIntent().getStringExtra("type"); + String title = getIntent().getStringExtra("title"); + if (type != null) { + actionbar_tv_title.setText(type); } - } + adapter.setId(id); + adapter.setType(type); + adapter.setTitle(title); + adapter.getNewsDetail(); -// WebView essaydetail_webView = (WebView) findViewById(R.id.essaydetail_webView); -// -// if (NetworkUtils.isWifiConnected(this)) { -// essaydetail_webView.setVisibility(View.INVISIBLE); -// if (newsId != null) { -// essaydetail_webView.loadUrl("http://news.ghzhushou.com/" + newsId + ".html"); -// } else { -// essaydetail_webView.loadUrl("http://news.ghzhushou.com/" + entity.getId() + ".html"); -// } -// } else { -// essaydetail_webView.setVisibility(View.GONE); -// } - - essaydetail_ll_bottom.setOnClickListener(this); - - reuse_no_connection.setOnClickListener(this); - - essaydetail_tv_download.setOnClickListener(this); - - iv_share.setOnClickListener(this); - - essaydetail_progressbar.setOnClickListener(this); - - essaydetail_tv_per.setOnClickListener(this); - - essaydetail_rv_show.setHasFixedSize(true); - linearLayoutManager = new LinearLayoutManager(this); - essaydetail_rv_show.setLayoutManager(linearLayoutManager); - adapter = new NewsAdapter(); - essaydetail_rv_show.setAdapter(adapter); - - if (newsId != null) { - getNewDigest(newsId); + iv_share.setVisibility(View.VISIBLE); } else { - getContent(); + getNewsDigest(newsId); } start = Calendar.getInstance().getTimeInMillis(); if (Config.isShow(this)) { - essaydetail_ll_bottom.setVisibility(View.VISIBLE); - essaydetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); + newsdetail_ll_bottom.setVisibility(View.VISIBLE); + newsdetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); } else { - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); } View view = getWindow().findViewById(Window.ID_ANDROID_CONTENT); @@ -239,22 +192,35 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1); mHits[mHits.length - 1] = SystemClock.uptimeMillis(); if (mHits[0] >= (SystemClock.uptimeMillis() - 1000)) { - essaydetail_rv_show.scrollToPosition(0); + newsdetail_rv_show.scrollToPosition(0); } } }); } + sp = getSharedPreferences(Config.PREFERENCE, Activity.MODE_PRIVATE); fontsize = sp.getInt("fontsize", 1); - if (fontsize == 0){ + if (fontsize == 0) { fontsize = 1; } } - private void saveFontSize(int size) { - SharedPreferences.Editor edit = sp.edit(); - edit.putInt("fontsize", size); - edit.apply(); + @Override + public void loadDone(Object obj) { + if (newsdetail_ll_loading != null) { + newsdetail_ll_loading.setVisibility(View.GONE); + newsdetail_rv_show.setVisibility(View.VISIBLE); + } + getGameDetail((String) obj); + } + + @Override + public void loadError() { + newsdetail_rv_show.setVisibility(View.GONE); + newsdetail_ll_loading.setVisibility(View.GONE); + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); + reuse_no_connection.setVisibility(View.VISIBLE); } private String getFontSize(int i) { @@ -279,39 +245,36 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener */ @Override public boolean dispatchTouchEvent(MotionEvent ev) { - switch (ev.getAction() & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: isSecondDown = false; - mActivePointerId = MotionEventCompat.getPointerId(ev, 0); - int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); + int pointerIndex = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, 0)); Y11 = MotionEventCompat.getY(ev, pointerIndex); X11 = MotionEventCompat.getX(ev, pointerIndex); break; case MotionEvent.ACTION_UP: final int actionUpIndex = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, actionUpIndex); - int pointerIndex2 = MotionEventCompat.findPointerIndex(ev, mActivePointerId); + int pointerIndex2 = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, actionUpIndex)); Y12 = MotionEventCompat.getY(ev, pointerIndex2); X12 = MotionEventCompat.getX(ev, pointerIndex2); float X2 = Math.abs(X12 - X22); float Y2 = Math.abs(Y12 - Y22); float R2 = (X2 * X2) + (Y2 * Y2); double R12 = Math.sqrt(R2); - if (isSecondDown && webSettings != null) { - if ((R11 - R12) > scrollSize&&fontsize>1) { - fontsize --; - webSettings.setTextZoom(defaultTextZoom+15*fontsize); - saveFontSize(fontsize); + if (isSecondDown) { + if ((R11 - R12) > scrollSize && fontsize > 1) { + fontsize--; + adapter.setFontSize(fontsize); + sp.edit().putInt("fontsize", fontsize).apply(); String fontSizeText = getFontSize(fontsize); - Toast.makeText(this,fontSizeText,Toast.LENGTH_SHORT).show(); + Toast.makeText(this, fontSizeText, Toast.LENGTH_SHORT).show(); } - if ((R11 - R12) < -scrollSize&&fontsize<4) { + if ((R11 - R12) < -scrollSize && fontsize < 4) { fontsize ++; - webSettings.setTextZoom(defaultTextZoom+15*fontsize); - saveFontSize(fontsize); + adapter.setFontSize(fontsize); + sp.edit().putInt("fontsize", fontsize).apply(); String fontSizeText = getFontSize(fontsize); - Toast.makeText(this,fontSizeText,Toast.LENGTH_SHORT).show(); + Toast.makeText(this, fontSizeText, Toast.LENGTH_SHORT).show(); } } break; @@ -323,8 +286,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener case MotionEventCompat.ACTION_POINTER_DOWN: isSecondDown = true; final int pointerIndexDown = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndexDown); - int pointerIndex1 = MotionEventCompat.findPointerIndex(ev, mActivePointerId); + int pointerIndex1 = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, pointerIndexDown)); Y21 = MotionEventCompat.getY(ev, pointerIndex1); X21 = MotionEventCompat.getX(ev, pointerIndex1); float X1 = Math.abs(X11 - X21); @@ -334,8 +296,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener break; case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndexUp = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndexUp); - int pointerIndex21 = MotionEventCompat.findPointerIndex(ev, mActivePointerId); + int pointerIndex21 = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, pointerIndexUp)); Y22 = MotionEventCompat.getY(ev, pointerIndex21); X22 = MotionEventCompat.getX(ev, pointerIndex21); break; @@ -343,22 +304,25 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener return super.dispatchTouchEvent(ev); } - private void getNewDigest(final String news_id) { + private void getNewsDigest(final String news_id) { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - Config.HOST + "v1d45/news/" + news_id + "/digest", + TimestampUtils.addTimestamp( + Config.HOST + "v1d45/news/" + news_id + "/digest", Constants.NEWS_CD), new Response.Listener() { @Override public void onResponse(JSONObject response) { Gson gson = new Gson(); - NewsEntity newsEntity = gson.fromJson( - response.toString(), NewsEntity.class); - NewsDetailEntity essayEntity = new NewsDetailEntity(); - essayEntity.setTitle(newsEntity.getTitle()); - essayEntity.setType(newsEntity.getType()); - essayEntity.setId(news_id); - entity = essayEntity; - actionbar_tv_title.setText(entity.getType()); - getContent(); + NewsEntity newsEntity = gson.fromJson(response.toString(), NewsEntity.class); + if (newsEntity.getType() != null) { + actionbar_tv_title.setText(newsEntity.getType()); + } + + adapter.setId(news_id); + adapter.setType(newsEntity.getType()); + adapter.setTitle(newsEntity.getTitle()); + adapter.getNewsDetail(); + + iv_share.setVisibility(View.VISIBLE); } }, new Response.ErrorListener() { @@ -368,10 +332,10 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener if (error.getClass().equals(NoConnectionError.class) || error.getClass().equals(TimeoutError.class)) { if (!isDestroy) { - essaydetail_rv_show.setVisibility(View.GONE); - essaydetail_ll_loading.setVisibility(View.GONE); - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); + newsdetail_rv_show.setVisibility(View.GONE); + newsdetail_ll_loading.setVisibility(View.GONE); + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); reuse_no_connection.setVisibility(View.VISIBLE); } } @@ -384,23 +348,23 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener @Override public void onClick(final View v) { - if (v == essaydetail_tv_download) { + if (v == newsdetail_tv_download) { if (gameEntity != null && !gameEntity.getApk().isEmpty()) { if (gameEntity.getApk().size() == 1) { if (NetworkUtils.isWifiConnected(this)) { - download(v); + download(); } else { DialogUtils.showDownloadDialog(this, new DialogUtils.ConfiremListener() { @Override public void onConfirem() { - download(v); + download(); } }); } } else { DownloadDialog.getInstance(NewsDetailActivity.this) .showPopupWindow(v, gameEntity, entrance + "-文章详情", - "新闻详情:" + entity.getTitle()); + "新闻详情:" + adapter.getNewsDetailEntity().getTitle()); } } else { toast("稍等片刻~!游戏正在上传中..."); @@ -409,21 +373,21 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener Map map = new HashMap<>(); map.put("location", "分享"); map.put("createOn", System.currentTimeMillis() / 1000); - map.put("news", entity.getTitle()); + map.put("news", adapter.getNewsDetailEntity().getTitle()); map.put("page", "新闻详情"); DataCollectionManager.onEvent(this, "click-item", map); - String url = "http://news.ghzhushou.com/" + entity.getId() + String url = "http://news.ghzhushou.com/" + adapter.getNewsDetailEntity().getId() + ".html"; if (gameEntity == null){ - showShare(url, entity.getTitle(), "http://image.ghzhushou.com/pic/56976f928ab49edc6e8b45f1.png",entity.getTitle() - , null, entrance, "新闻"); + showShare(url, adapter.getNewsDetailEntity().getTitle(), "http://image.ghzhushou.com/pic/56976f928ab49edc6e8b45f1.png", + adapter.getNewsDetailEntity().getTitle(), null, entrance, "新闻"); }else { - showShare(url, gameEntity.getName(), gameEntity.getIcon(), entity.getTitle(), gameEntity.getTag(), entrance + showShare(url, gameEntity.getName(), gameEntity.getIcon(), adapter.getNewsDetailEntity().getTitle(), gameEntity.getTag(), entrance , "新闻"); } - } else if (v == essaydetail_progressbar || v == essaydetail_tv_per) { - String str = essaydetail_tv_per.getText().toString(); + } else if (v == newsdetail_progressbar || v == newsdetail_tv_per) { + String str = newsdetail_tv_per.getText().toString(); if ("下载中".equals(str)) { startActivity(new Intent(this, DownloadManagerActivity.class)); } else if ("安装".equals(str)) { @@ -445,20 +409,20 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener } } } else if (v == reuse_no_connection) { - essaydetail_rv_show.setVisibility(View.VISIBLE); - essaydetail_ll_loading.setVisibility(View.VISIBLE); - essaydetail_ll_bottom.setVisibility(View.VISIBLE); - essaydetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); + newsdetail_rv_show.setVisibility(View.VISIBLE); + newsdetail_ll_loading.setVisibility(View.VISIBLE); + newsdetail_ll_bottom.setVisibility(View.VISIBLE); + newsdetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); reuse_no_connection.setVisibility(View.GONE); handler.postDelayed(runnable, 1000); } } - private void download(View v) { - if (essaydetail_tv_download.getText().toString() + private void download() { + if (newsdetail_tv_download.getText().toString() .contains("启动")) { - Map kv = new HashMap(); + Map kv = new HashMap<>(); kv.put("版本", gameEntity.getApk().get(0) .getPlatform()); DataUtils.onEvent(NewsDetailActivity.this, "游戏启动", @@ -472,26 +436,26 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener String msg = FileUtils.isCanDownload(apkEntity .getSize()); if (TextUtils.isEmpty(msg)) { - Map kv = new HashMap(); + Map kv = new HashMap<>(); kv.put("版本", apkEntity.getPlatform()); kv.put("状态", "下载开始"); DataUtils.onEvent(NewsDetailActivity.this, "游戏下载", gameEntity.getName(), kv); - Map kv2 = new HashMap(); + Map kv2 = new HashMap<>(); kv2.put("版本", apkEntity.getPlatform()); kv2.put("状态", "下载开始"); kv2.put("位置", entrance + "-文章详情-开始"); DataUtils.onEvent(NewsDetailActivity.this, "游戏下载位置", gameEntity.getName(), kv2); - Map kv3 = new HashMap(); + Map kv3 = new HashMap<>(); kv3.put(entrance, "下载数"); kv3.put(entrance, "下载开始"); DataUtils.onEvent(NewsDetailActivity.this, "应用数据", gameEntity.getName(), kv3); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("game", gameEntity.getName()); map.put("method", "正常"); map.put("platform", @@ -502,7 +466,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener .get(0) .getPlatform())); map.put("status", "开始"); - map.put("location", "新闻详情:" + entity.getTitle()); + map.put("location", "新闻详情:" + adapter.getNewsDetailEntity().getTitle()); map.put("from", entrance); map.put("network", NetworkUtils.getConnectedType(this)); @@ -522,18 +486,18 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener downloadEntity.setPlatform(apkEntity.getPlatform()); downloadEntity.setGameId(gameEntity.getId()); downloadEntity.setEntrance(entrance + "-文章详情"); - downloadEntity.setLocation("新闻详情:" + entity.getTitle()); + downloadEntity.setLocation("新闻详情:" + adapter.getNewsDetailEntity().getTitle()); DownloadManager.getInstance( getApplicationContext()).add(downloadEntity); - essaydetail_tv_download + newsdetail_tv_download .setVisibility(View.GONE); - essaydetail_progressbar + newsdetail_progressbar .setVisibility(View.VISIBLE); - essaydetail_tv_per.setVisibility(View.VISIBLE); - essaydetail_progressbar.setProgress(0); - essaydetail_tv_per.setText("0.0%"); + newsdetail_tv_per.setVisibility(View.VISIBLE); + newsdetail_progressbar.setProgress(0); + newsdetail_tv_per.setText("0.0%"); DownloadManager.getInstance(NewsDetailActivity.this).putStatus(downloadEntity.getUrl(), "downloading"); @@ -547,543 +511,108 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener @Override public void run() { if (newsId != null) { - getNewDigest(newsId); + getNewsDigest(newsId); } else { - getContent(); + String id = getIntent().getStringExtra("id"); + String type = getIntent().getStringExtra("type"); + String title = getIntent().getStringExtra("title"); + if (type != null) { + actionbar_tv_title.setText(type); + } + adapter.setId(id); + adapter.setType(type); + adapter.setTitle(title); + adapter.getNewsDetail(); } } }; - private void getContent() { - JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - Config.HOST + "v1d45/news/" + entity.getId() + "/detail", - new Response.Listener() { - - @Override - public void onResponse(JSONObject response) { - - if (!isDestroy) { - Gson gson = new Gson(); - NewsDetailEntity essayEntity = gson.fromJson(response.toString(), NewsDetailEntity.class); - essayEntity.setTitle(entity.getTitle()); - if (entity.getTime() != null) { - essayEntity.setTime(entity.getTime()); - } - essayEntity.setType(entity.getType()); - if (entity.getId() != null) { - essayEntity.setId(entity.getId()); - } - entity = essayEntity; - - adapter.notifyDataSetChanged(); - - // 获取相关推荐 - getNewsMore(); - - // 获取游戏数据 - getGameDetail(entity.getGame()); - } - } - - }, new Response.ErrorListener() { - - @Override - public void onErrorResponse(VolleyError error) { - Utils.log(error.toString()); - if (error.networkResponse != null) { - Utils.log(new String(error.networkResponse.data)); - } - // 无网络连接和访问超时 - if (error.getClass().equals(NoConnectionError.class) - || error.getClass().equals(TimeoutError.class)) { - if (!isDestroy) { - essaydetail_rv_show.setVisibility(View.GONE); - essaydetail_ll_loading.setVisibility(View.GONE); - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); - reuse_no_connection.setVisibility(View.VISIBLE); - } - } - } - }); - AppController.addToRequestQueue(request, NewsDetailActivity.class); - } - - private void getNewsMore() { - JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" - + entity.getId() + "/suggestion", Constants.NEWS_CD), - new Response.Listener() { - @Override - public void onResponse(JSONArray response) { - Utils.log(response); - if (!isDestroy) { - Type listType = new TypeToken>() { - }.getType(); - Gson gson = new Gson(); - List list = gson.fromJson( - response.toString(), listType); - // 去除与当前文章重复的文章 - for (int i = 0, size = list.size(); i < size; i++) { - if (entity.getId().equals(list.get(i).getId())) { - list.remove(i); - break; - } - } - List more = new ArrayList(); - // TODO 随机三篇文章 - int[] index = new int[list.size() > 3 ? 3 : list - .size()]; - Random random = new Random(System - .currentTimeMillis()); - for (int i = 0; i < index.length; i++) { - if (i == 0) { - index[i] = random.nextInt(list.size()); - } else { - index[i] = random(random, index, i, - list.size()); - } - } - for (int i = 0; i < index.length; i++) { - more.add(list.get(index[i])); - } - entity.setMore(more); - adapter.notifyItemChanged(0); - adapter.notifyItemChanged(1); - } - } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Utils.log(error); - } - }); - AppController.addToRequestQueue(request, NewsDetailActivity.class); - } - - private int random(Random random, int[] index, int i, int size) { - int seed = random.nextInt(size); - for (int j = 0; j < i; j++) { - if (index[j] == seed) { - return random(random, index, i, size); - } - } - return seed; - } - - private void getGameDetail(String game_id) { - if (TextUtils.isEmpty(game_id)) { - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); + private void getGameDetail(String gameId) { + if (TextUtils.isEmpty(gameId)) { + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); return; } JsonObjectExtendedRequest gameRequest = new JsonObjectExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST + "v2d0/game/"//版本号修改了 - + game_id + "/news_digest", Constants.GAME_CD), + TimestampUtils.addTimestamp( + Config.HOST + "v2d0/game/" + gameId + "/news_digest", + Constants.GAME_CD), new Response.Listener() { @Override public void onResponse(JSONObject response) { - if (!isDestroy) { - processingGameData(response.toString()); - } + Gson gson = new Gson(); + gameEntity = gson.fromJson(response.toString(), GameEntity.class); + adapter.setGameEntity(gameEntity); + adapter.notifyDataSetChanged(); + initDownload(); } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { - } - }); + } + }); AppController.addToRequestQueue(gameRequest, NewsDetailActivity.class); } - private void processingGameData(String data) { - Gson gson = new Gson(); - gameEntity = gson.fromJson(data, GameEntity.class); - boolean isInstalled = false; - if (gameEntity.getApk() != null - && gameEntity.getApk().size() == 1 - && PackageManager.isInstalled(gameEntity.getApk().get(0) - .getPackageName())) { - isInstalled = true; - } - if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); - if (isInstalled) { - essaydetail_tv_download.setText("启动《" + gameEntity.getName() + "》"); - } else { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》"); - } + private void initDownload() { + if (gameEntity == null || "光环助手".equals(gameEntity.getName())) { + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); } else { - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); - if (isInstalled) { - essaydetail_tv_download.setText("启动《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); - } else { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); + boolean isInstalled = false; + if (gameEntity.getApk() != null + && gameEntity.getApk().size() == 1 + && PackageManager.isInstalled(gameEntity.getApk().get(0) + .getPackageName())) { + isInstalled = true; } - } - if (gameEntity.getApk() == null) { - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); - } else if (gameEntity.getApk().isEmpty()) { - essaydetail_ll_bottom.setVisibility(View.VISIBLE); - essaydetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); - essaydetail_tv_download.setText("暂无下载"); - essaydetail_tv_download.setBackgroundResource(R.drawable.progressbar_normal_radius_style); - essaydetail_tv_download.setTextColor(getResources().getColor(R.color.btn_gray)); - essaydetail_tv_download.setClickable(false); - } else if (Config.isShow(this)) { - essaydetail_ll_bottom.setVisibility(View.VISIBLE); - essaydetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); - String url = gameEntity.getApk().get(0).getUrl(); - for (DownloadEntity entry : DownloadManager.getInstance(getApplicationContext()).getAll()) { - if (url.equals(entry.getUrl())) { - mDownloadEntity = entry; - essaydetail_tv_download.setVisibility(View.GONE); - essaydetail_progressbar.setVisibility(View.VISIBLE); - essaydetail_tv_per.setVisibility(View.VISIBLE); - invalidate(); - break; - } - } - } - if (gameEntity != null && "光环助手".equals(gameEntity.getName())) { - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); - } - adapter.notifyItemChanged(0); - } - - public class JsInterface { - private Context context; - private ArrayList imgs = new ArrayList(); - - public JsInterface(Context context) { - this.context = context; - } - - @JavascriptInterface - public void openImage(String url) { - int current = 0; - for (int i = 0, size = imgs.size(); i < size; i++) { - if (url.equals(imgs.get(i))) { - current = i; - } - } - Intent checkIntent = new Intent(context, ViewImageActivity.class); - checkIntent.putExtra("urls", imgs); - checkIntent.putExtra("current", current); - checkIntent.putExtra("ScaleType", "FIT_CENTER"); - context.startActivity(checkIntent); - } - - @JavascriptInterface - public void addImage(String url) { - if (!imgs.contains(url)) { - imgs.add(url); - } - } - - @JavascriptInterface - public void skip(String id, String type) { - if ("game".equals(type)) { - Intent intent = new Intent(NewsDetailActivity.this, - GameDetailActivity.class); - intent.putExtra("gameId", id); - intent.putExtra("entrance", entrance); - startActivity(intent); - } else if ("news".equals(type)) { - Intent intent = new Intent(NewsDetailActivity.this, - NewsDetailActivity.class); - intent.putExtra("newsId", id); - intent.putExtra("entrance", entrance); - startActivity(intent); - } - } - - } - - private class NewsViewHolder extends RecyclerView.ViewHolder implements OnClickListener { - - private LinearLayout essaydetail_ll_top; - private ImageView essaydetail_icon; - private TextView essaydetail_name, essaydetail_info, - essaydetail_attention, essaydetail_title, essaydetail_time, - essaydetail_author, essaydetail_tv_more; - private WebView essaydetail_wv_content; - - private LinearLayout news_item_ll; - private TextView news_type, news_title; - private CardView cardView; - - public NewsViewHolder(View view, int viewType) { - super(view); - - if (viewType == 0) { - essaydetail_ll_top = (LinearLayout) view.findViewById(R.id.essaydetail_ll_top); - essaydetail_ll_top.setOnClickListener(this); - essaydetail_icon = (ImageView) view.findViewById(R.id.essaydetail_icon); - essaydetail_name = (TextView) view.findViewById(R.id.essaydetail_name); - essaydetail_info = (TextView) view.findViewById(R.id.essaydetail_info); - essaydetail_attention = (TextView) view.findViewById(R.id.essaydetail_attention); - essaydetail_attention.setOnClickListener(this); - essaydetail_title = (TextView) view.findViewById(R.id.essaydetail_title); - essaydetail_time = (TextView) view.findViewById(R.id.essaydetail_time); - essaydetail_author = (TextView) view.findViewById(R.id.essaydetail_author); - essaydetail_wv_content = (WebView) view.findViewById(R.id.essaydetail_wv_content); - essaydetail_wv_content.setBackgroundColor(0); - cardView = (CardView) view.findViewById(R.id.essaydetail_cv); - } else if (viewType == 1) { - news_item_ll = (LinearLayout) view.findViewById(R.id.essaydetail_more_news_item_ll); - } - } - - @Override - public void onClick(View v) { - if (v == essaydetail_ll_top) { - Intent intent = new Intent(NewsDetailActivity.this, - GameDetailActivity.class); - intent.putExtra("gameId", gameEntity.getId()); - intent.putExtra("entrance", entrance); - startActivity(intent); - } else if (v == essaydetail_attention) { - if ("关注".equals(essaydetail_attention.getText().toString())) { - - Map kv = new HashMap(); - kv.put("状态", "关注"); - DataUtils.onEvent(NewsDetailActivity.this, "游戏关注", gameEntity.getName(), kv); - - Map kv2 = new HashMap(); - kv2.put("点击", "关注"); - DataUtils.onEvent(NewsDetailActivity.this, "插件数据", gameEntity.getName(), kv2); - - 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.addByEntity(gameEntity); - essaydetail_attention.setText("取消关注"); - essaydetail_attention.setBackgroundResource(R.drawable.border_red_bg); - essaydetail_attention.setTextColor(0xffbc2132); - - 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("关注提交失败==游戏详情"); - } - }); + if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); + if (isInstalled) { + newsdetail_tv_download.setText(String.format("启动《%s》", gameEntity.getName())); } else { - Map kv2 = new HashMap<>(); - kv2.put("点击", "取消关注"); - DataUtils.onEvent(NewsDetailActivity.this, "插件数据", gameEntity.getName(), kv2); - - 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("删除提交失败==游戏详情"); - } - }); - } - }); + newsdetail_tv_download.setText(String.format("下载《%s》", gameEntity.getName())); } - } - } - } - - private class NewsAdapter extends RecyclerView.Adapter { - - @Override - public NewsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view; - if (viewType == 0) { - view = LayoutInflater.from(parent.getContext()).inflate( - R.layout.newsdetail_item_top, parent, false); } else { - view = LayoutInflater.from(parent.getContext()).inflate( - R.layout.newsdetail_more_news_item, parent, false); - } - return new NewsViewHolder(view, viewType); - } - - @Override - public void onBindViewHolder(NewsViewHolder holder, int position) { - if (position == 0) { - if (gameEntity != null && gameEntity.getName() != null && !gameEntity.getName().contains("光环助手")) { - holder.essaydetail_ll_top.setVisibility(View.VISIBLE); - holder.cardView.setVisibility(View.VISIBLE); - ImageUtils.getInstance(getApplicationContext()).displayFile(gameEntity.getIcon(), holder.essaydetail_icon); - holder.essaydetail_name.setText(gameEntity.getName()); - - if (concernManager.isConcern(gameEntity.getId())) { - holder.essaydetail_attention.setText("取消关注"); - holder.essaydetail_attention.setBackgroundResource(R.drawable.border_red_bg); - holder.essaydetail_attention.setTextColor(0xffbc2132); - } else { - holder.essaydetail_attention.setText("关注"); - holder.essaydetail_attention.setBackgroundResource(R.drawable.textview_red_style); - holder.essaydetail_attention.setTextColor(Color.WHITE); - } - if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) { - for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) { - ApkEntity apkEntity = gameEntity.getApk().get(i); - if ("9u".equals(apkEntity.getPlatform())) { - holder.essaydetail_info.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize())); - break; - } - if (i == size - 1) { - holder.essaydetail_info.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize())); - } - } - } + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); + if (isInstalled) { + newsdetail_tv_download.setText(String.format("启动《%s》%s", gameEntity.getName(), gameEntity.getDownloadAddWord())); } else { - holder.essaydetail_ll_top.setVisibility(View.GONE); - holder.cardView.setVisibility(View.GONE); + newsdetail_tv_download.setText(String.format("下载《%s》%s", gameEntity.getName(), gameEntity.getDownloadAddWord())); } - - holder.essaydetail_title.setText(entity.getTitle()); - SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - try { - long today = format.parse(format.format(new Date())).getTime(); - long day = Long.valueOf(entity.getTime() + "000"); - if (day >= today && day < today + 86400 * 1000) { - format.applyPattern("HH:mm"); - holder.essaydetail_time.setText("今天 " + format.format(day)); - } else if (day >= today - 86400 * 1000 && day < today) { - format.applyPattern("HH:mm"); - holder.essaydetail_time.setText("昨天 " + format.format(day)); - } else { - format.applyPattern("yyyy年MM月dd日 HH:mm"); - holder.essaydetail_time.setText(format.format(day)); + } + if (gameEntity.getApk() == null) { + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); + } else if (gameEntity.getApk().isEmpty()) { + newsdetail_ll_bottom.setVisibility(View.VISIBLE); + newsdetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); + newsdetail_tv_download.setText("暂无下载"); + newsdetail_tv_download.setBackgroundResource(R.drawable.progressbar_normal_radius_style); + newsdetail_tv_download.setTextColor(getResources().getColor(R.color.btn_gray)); + newsdetail_tv_download.setClickable(false); + } else if (Config.isShow(this)) { + newsdetail_ll_bottom.setVisibility(View.VISIBLE); + newsdetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); + String url = gameEntity.getApk().get(0).getUrl(); + for (DownloadEntity entry : DownloadManager.getInstance(getApplicationContext()).getAll()) { + if (url.equals(entry.getUrl())) { + mDownloadEntity = entry; + newsdetail_tv_download.setVisibility(View.GONE); + newsdetail_progressbar.setVisibility(View.VISIBLE); + newsdetail_tv_per.setVisibility(View.VISIBLE); + invalidate(); + break; } - } catch (ParseException e) { - e.printStackTrace(); - format.applyPattern("yyyy年MM月dd日 HH:mm"); - holder.essaydetail_time.setText(format.format(Long.valueOf(entity.getTime() + "000"))); - } - if (entity.getAuthor() != null) { - holder.essaydetail_author.setText(entity.getAuthor()); - } - if (holder.essaydetail_wv_content.getTag() == null) { - holder.essaydetail_wv_content.addJavascriptInterface(new JsInterface(NewsDetailActivity.this), "imagelistener"); - webSettings = holder.essaydetail_wv_content.getSettings(); - webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); - webSettings.setJavaScriptEnabled(true); - webSettings.setTextZoom(defaultTextZoom+fontsize * 15); - holder.essaydetail_wv_content.loadDataWithBaseURL(null, entity.getContent(), "text/html", "utf-8", null); - holder.essaydetail_wv_content.setWebViewClient(new WebViewClient() { - @Override - public void onPageFinished(WebView view, - String url) { - view.loadUrl("javascript:(function(){" - + "var imgs = document.getElementsByTagName(\"img\");" - + "for (var i = 0; i < imgs.length - 1; i++) {" - + " window.imagelistener.addImage(imgs[i].src);" - + "}" - + "for (var i = 0; i < imgs.length - 1; i++) {" - + " imgs[i].onclick = function() {" - + " window.imagelistener.openImage(this.src);" - + " }" - + "}" - + "var as = document.getElementsByTagName(\"a\");" - + "for (var i = 0; i < as.length; i++) {" - + " as[i].onclick = function() {" - + " window.imagelistener.skip(this.id, this.type);" - + " }" - + "}" - + "})()"); - super.onPageFinished(view, url); - if (essaydetail_ll_loading != null) { - essaydetail_ll_loading.setVisibility(View.GONE); - essaydetail_rv_show.setVisibility(View.VISIBLE); - } - } - }); - holder.essaydetail_wv_content.setTag("show"); - } - - } else if (entity.getMore() != null && position == 1) { - LinearLayout news_item_ll = holder.news_item_ll; - for (int i = 0; i < entity.getMore().size(); i++) { - RelativeLayout rlChild = (RelativeLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.gamedetail_news_item,null); - TextView tv_tag = (TextView) rlChild.findViewById(R.id.gamedetail_news_item_tag); - TextView tv_title = (TextView) rlChild.findViewById(R.id.gamedetail_news_item_title); - tv_tag.setText(entity.getMore().get(i).getType()); - tv_title.setText(entity.getMore().get(i).getTitle()); - tv_title.setTextColor(Color.parseColor("#3a3a3a")); - news_item_ll.addView(rlChild); - final int finalI = i; - rlChild.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(NewsDetailActivity.this, - NewsDetailActivity.class); - intent.putExtra("newsId", entity.getMore().get(finalI).getId()); - intent.putExtra("entrance", entrance); - startActivity(intent); - } - }); } } } - - @Override - public int getItemCount() { - if (entity == null || entity.getAuthor() == null) { - return 0; - } - if (entity.getMore() != null && entity.getMore().size() >= 1){ - return 2; - } - return 1; - } - - @Override - public int getItemViewType(int position) { - return position; - } } //接收下载被删除消息 @@ -1092,13 +621,13 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener 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); + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》"); + newsdetail_tv_download.setText(String.format("下载《%s》", gameEntity.getName())); } else { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); + newsdetail_tv_download.setText(String.format("下载《%s》%s", gameEntity.getName(), gameEntity.getDownloadAddWord())); } } } @@ -1117,15 +646,15 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener String packageName = gameEntity.getApk().get(0).getPackageName(); if (packageName.equals(busFour.getPackageName())) { if ("安装".equals(busFour.getType())) { - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); - essaydetail_tv_download.setText("启动《" + gameEntity.getName() + "》"); + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); + newsdetail_tv_download.setText(String.format("启动《%s》", gameEntity.getName())); } else if ("卸载".equals(busFour.getType())) { - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》"); + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); + newsdetail_tv_download.setText(String.format("下载《%s》", gameEntity.getName())); } } } @@ -1134,10 +663,10 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener public void onEventMainThread(EBNetworkState busNetworkState) { if (busNetworkState.isNetworkConnected()) { if (reuse_no_connection.getVisibility() == View.VISIBLE) { - essaydetail_rv_show.setVisibility(View.VISIBLE); - essaydetail_ll_loading.setVisibility(View.VISIBLE); - essaydetail_ll_bottom.setVisibility(View.VISIBLE); - essaydetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); + newsdetail_rv_show.setVisibility(View.VISIBLE); + newsdetail_ll_loading.setVisibility(View.VISIBLE); + newsdetail_ll_bottom.setVisibility(View.VISIBLE); + newsdetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44)); reuse_no_connection.setVisibility(View.GONE); handler.postDelayed(runnable, 1000); } @@ -1145,31 +674,31 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener } private void invalidate() { - essaydetail_progressbar.setProgress((int) (mDownloadEntity.getPercent() * 10)); - essaydetail_tv_per.setTextColor(0xFFFFFFFF); + newsdetail_progressbar.setProgress((int) (mDownloadEntity.getPercent() * 10)); + newsdetail_tv_per.setTextColor(0xFFFFFFFF); switch (mDownloadEntity.getStatus()) { case downloading: case pause: case timeout: case neterror: case waiting: - essaydetail_tv_per.setText("下载中"); + newsdetail_tv_per.setText("下载中"); break; case done: EventBus.getDefault().post( new EBPutUrl(gameEntity.getApk().get(0).getPackageName(), mDownloadEntity.getUrl())); - essaydetail_tv_per.setText("安装"); + newsdetail_tv_per.setText("安装"); break; case cancel: case hijack: - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》"); + newsdetail_tv_download.setText(String.format("下载《%s》", gameEntity.getName())); } else { - essaydetail_tv_download.setText("下载《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); + newsdetail_tv_download.setText(String.format("下载《%s》%s", gameEntity.getName(), gameEntity.getDownloadAddWord())); } break; default: @@ -1182,22 +711,22 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener super.onResume(); if (gameEntity != null && gameEntity.getApk().size() == 1) { if (PackageManager.isInstalled(gameEntity.getApk().get(0).getPackageName())) { - essaydetail_tv_download.setVisibility(View.VISIBLE); - essaydetail_progressbar.setVisibility(View.GONE); - essaydetail_tv_per.setVisibility(View.GONE); + newsdetail_tv_download.setVisibility(View.VISIBLE); + newsdetail_progressbar.setVisibility(View.GONE); + newsdetail_tv_per.setVisibility(View.GONE); if (TextUtils.isEmpty(gameEntity.getDownloadAddWord())) { - essaydetail_tv_download.setText("启动《" + gameEntity.getName() + "》"); + newsdetail_tv_download.setText(String.format("启动《%s》", gameEntity.getName())); } else { - essaydetail_tv_download.setText("启动《" + gameEntity.getName() + "》" + gameEntity.getDownloadAddWord()); + newsdetail_tv_download.setText(String.format("启动《%s》%s", gameEntity.getName(), gameEntity.getDownloadAddWord())); } } else { String url = gameEntity.getApk().get(0).getUrl(); for (DownloadEntity entry : DownloadManager.getInstance(getApplicationContext()).getAll()) { if (url.equals(entry.getUrl())) { mDownloadEntity = entry; - essaydetail_tv_download.setVisibility(View.GONE); - essaydetail_progressbar.setVisibility(View.VISIBLE); - essaydetail_tv_per.setVisibility(View.VISIBLE); + newsdetail_tv_download.setVisibility(View.GONE); + newsdetail_progressbar.setVisibility(View.VISIBLE); + newsdetail_tv_per.setVisibility(View.VISIBLE); invalidate(); break; } @@ -1205,8 +734,8 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener } } if (gameEntity != null && "光环助手".equals(gameEntity.getName())) { - essaydetail_ll_bottom.setVisibility(View.GONE); - essaydetail_rv_show.setPadding(0, 0, 0, 0); + newsdetail_ll_bottom.setVisibility(View.GONE); + newsdetail_rv_show.setPadding(0, 0, 0, 0); } DownloadManager.getInstance(this).addObserver(dataWatcher); } @@ -1215,12 +744,12 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener protected void onPause() { super.onPause(); DownloadManager.getInstance(this).removeObserver(dataWatcher); - if (!isSentReport && entity != null) { + if (!isSentReport && adapter.getNewsDetailEntity() != null) { long end = Calendar.getInstance().getTimeInMillis(); int seconds = (int) ((end - start) / 1000); - String cost = ""; + String cost; if (seconds < 5) { cost = "小于5秒"; } else if (seconds < 30) { @@ -1232,33 +761,33 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener } // 阅读报告 - Map kv = new HashMap(); + Map kv = new HashMap<>(); kv.put("用时", cost); - DataUtils.onEvent(NewsDetailActivity.this, "阅读文章", entity.getTitle(), kv); + DataUtils.onEvent(NewsDetailActivity.this, "阅读文章", adapter.getNewsDetailEntity().getTitle(), kv); // 阅读报告 - Map kv1 = new HashMap(); + Map kv1 = new HashMap<>(); kv1.put(entrance, "阅读数"); kv1.put(entrance, "用时:" + cost); - DataUtils.onEvent(NewsDetailActivity.this, "文章数据", entity.getTitle(), kv1); + DataUtils.onEvent(NewsDetailActivity.this, "文章数据", adapter.getNewsDetailEntity().getTitle(), kv1); if ("主页-卡牌头条".equals(entrance)) { - Map kv2 = new HashMap(); - kv2.put(entity.getTitle(), "阅读数"); - kv2.put(entity.getTitle(), "用时:" + cost); + Map kv2 = new HashMap<>(); + kv2.put(adapter.getNewsDetailEntity().getTitle(), "阅读数"); + kv2.put(adapter.getNewsDetailEntity().getTitle(), "用时:" + cost); DataUtils.onEvent(this, "主页数据", "卡牌头条", kv2); } else if ("主页-卡牌攻略".equals(entrance)) { - Map kv2 = new HashMap(); - kv2.put(entity.getTitle(), "阅读数"); - kv2.put(entity.getTitle(), "用时:" + cost); + Map kv2 = new HashMap<>(); + kv2.put(adapter.getNewsDetailEntity().getTitle(), "阅读数"); + kv2.put(adapter.getNewsDetailEntity().getTitle(), "用时:" + cost); DataUtils.onEvent(this, "主页数据", "卡牌攻略", kv2); } if (seconds > 0) { - Map map = new HashMap(); - map.put("title", entity.getTitle()); - map.put("type", entity.getType()); - map.put("author", entity.getAuthor()); + Map map = new HashMap<>(); + map.put("title", adapter.getNewsDetailEntity().getTitle()); + map.put("type", adapter.getNewsDetailEntity().getType()); + map.put("author", adapter.getNewsDetailEntity().getAuthor()); if (gameEntity != null) { map.put("game", gameEntity.getName()); } @@ -1276,17 +805,16 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener protected void onDestroy() { super.onDestroy(); AppController.canclePendingRequests(NewsDetailActivity.class); - essaydetail_ll_loading = null; - essaydetail_ll_bottom = null; + newsdetail_ll_loading = null; + newsdetail_ll_bottom = null; reuse_no_connection = null; - entity = null; actionbar_tv_title = null; - essaydetail_tv_download = null; - essaydetail_tv_per = null; - essaydetail_progressbar = null; + newsdetail_tv_download = null; + newsdetail_tv_per = null; + newsdetail_progressbar = null; gameEntity = null; mDownloadEntity = null; - essaydetail_rv_show = null; + newsdetail_rv_show = null; adapter = null; linearLayoutManager = null; entrance = null; diff --git a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java index b3eb0fcc3c..af8aa9cda3 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java @@ -165,7 +165,8 @@ public class NewsSearchActivity extends BaseActivity { } private void loadNewsData(final int page) { - String url = Config.HOST+"v1d45/search/news?game_id="+ gameId+ "&keyword="+ Uri.encode(searchKey)+ "&page="+ page+ "&limit=20"; + String url = Config.HOST + "v1d45/search/news?game_id=" + gameId + + "&keyword=" + Uri.encode(searchKey) + "&page="+ page + "&limit=20"; final JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url, new Response.Listener() { @Override diff --git a/app/src/main/java/com/gh/gamecenter/SearchActivity.java b/app/src/main/java/com/gh/gamecenter/SearchActivity.java index 035455a9ca..2c17916f9a 100644 --- a/app/src/main/java/com/gh/gamecenter/SearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SearchActivity.java @@ -32,7 +32,7 @@ import com.gh.gamecenter.eventbus.EBSearch; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.SystemBarTintManager; import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig; -import com.gh.gamecenter.search.SearchDetailFragment; +import com.gh.gamecenter.search.SearchGameDetailFragment; import com.gh.gamecenter.search.SearchGameListFragment; import com.gh.gamecenter.search.SearchHistoryFragment; @@ -43,7 +43,7 @@ import java.util.Map; public class SearchActivity extends BaseFragmentActivity { - private SearchDetailFragment game_detail_fragment; + private SearchGameDetailFragment game_detail_fragment; private SearchGameListFragment game_list_fragment; private SearchHistoryFragment search_history_fragment; @@ -301,7 +301,7 @@ public class SearchActivity extends BaseFragmentActivity { List list = getSupportFragmentManager().getFragments(); if (list != null) { for (Fragment fragment : list) { - if (fragment.getClass().equals(SearchDetailFragment.class)) { + if (fragment.getClass().equals(SearchGameDetailFragment.class)) { transaction.remove(fragment); break; } @@ -310,7 +310,7 @@ public class SearchActivity extends BaseFragmentActivity { } else { transaction.remove(game_detail_fragment); } - game_detail_fragment = new SearchDetailFragment(); + game_detail_fragment = new SearchGameDetailFragment(); game_detail_fragment.setKey(searchKey); transaction.add(R.id.search_result, game_detail_fragment); currentTab = 2; diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index 8631e15322..36f759c383 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -315,7 +315,8 @@ public class SplashScreenActivity extends BaseActivity { private void getPlatform() { JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST + "v1d45/support/setting/platform", + TimestampUtils.addTimestamp( + Config.HOST + "v1d45/support/setting/platform", Constants.PLATFORM_CD), new Response.Listener() { @Override @@ -436,7 +437,7 @@ public class SplashScreenActivity extends BaseActivity { final int count = concernId.size(); for (int i = 0, size = concernId.size(); i < size; i++) { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - Config.HOST + "v1d45/game/" + concernId.get(i) + "/digest", + Config.HOST + "v2d0/game/" + concernId.get(i) + "/digest", new Response.Listener() { @Override diff --git a/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java index 404e037fe8..98c1a4a849 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java @@ -97,8 +97,9 @@ public class PluginAdapter extends RecyclerView.Adapter count = 0; for (ConcernInfo info : infos) { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/" - + info.getId() + "/digest", Constants.GAME_CD), + TimestampUtils.addTimestamp( + Config.HOST + "v2d0/game/" + info.getId() + "/digest", + Constants.GAME_CD), new Response.Listener() { @Override public void onResponse(JSONObject response) { diff --git a/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java index 1b1a118afa..1f681aab84 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java @@ -103,8 +103,9 @@ public class SubjectAdapter extends RecyclerView.Adapter more; - - //用户对新闻的反馈 - private String action; - - //新闻反馈 - private long up; - private long down; public String getId() { return id; @@ -78,12 +68,12 @@ public class NewsDetailEntity implements Serializable { this.type = type; } - public String getGame() { - return game; + public String getGameId() { + return gameId; } - public void setGame(String game) { - this.game = game; + public void setGameId(String gameId) { + this.gameId = gameId; } public List getMore() { @@ -94,28 +84,4 @@ public class NewsDetailEntity implements Serializable { this.more = more; } - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public long getUp() { - return up; - } - - public void setUp(long up) { - this.up = up; - } - - public long getDown() { - return down; - } - - public void setDown(long down) { - this.down = down; - } - } 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 6589817fe4..490e7bb6a4 100644 --- a/app/src/main/java/com/gh/gamecenter/game/Game1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/game/Game1Fragment.java @@ -106,11 +106,27 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On fm_game_rv_list.setHasFixedSize(true); fm_game_rv_list.setLayoutManager(new LinearLayoutManager(getActivity())); - adapter = new Game1FragmentAdapter(Game1Fragment.this, fm_game_rv_list, fm_game_swipe_refresh, - reuse_no_connection, fm_game_pb_loading, false); + adapter = new Game1FragmentAdapter(Game1Fragment.this, fm_game_swipe_refresh, false); fm_game_rv_list.setAdapter(adapter); } + @Override + public void loadDone() { + if (fm_game_swipe_refresh != null && fm_game_swipe_refresh.isRefreshing()) { + fm_game_swipe_refresh.setRefreshing(false); + } + if (fm_game_pb_loading != null && fm_game_pb_loading.getVisibility() == View.VISIBLE) { + fm_game_pb_loading.setVisibility(View.GONE); + } + } + + @Override + public void loadError() { + fm_game_rv_list.setVisibility(View.GONE); + fm_game_pb_loading.setVisibility(View.GONE); + reuse_no_connection.setVisibility(View.VISIBLE); + } + //下载被删除事件 public void onEventMainThread(EBDownloadStatus status) { if ("delete".equals(status.getStatus())) { @@ -145,9 +161,9 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On } } } else if ("plugin".equals(status.getStatus())) { - if (adapter.getPluginList().isEmpty()) { - adapter.initPlugin(); - } +// if (adapter.getPluginList().isEmpty()) { +// adapter.initPlugin(); +// } } } @@ -311,8 +327,7 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On @Override public void run() { if (!isDestroy) { - adapter = new Game1FragmentAdapter(Game1Fragment.this, fm_game_rv_list, fm_game_swipe_refresh, - reuse_no_connection, fm_game_pb_loading, true); + adapter = new Game1FragmentAdapter(Game1Fragment.this, fm_game_swipe_refresh, true); fm_game_rv_list.setAdapter(adapter); } } 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 1269093749..9e6bde2288 100644 --- a/app/src/main/java/com/gh/gamecenter/game/Game1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/game/Game1FragmentAdapter.java @@ -21,7 +21,6 @@ import com.android.volley.NoConnectionError; import com.android.volley.Response; import com.android.volley.TimeoutError; import com.android.volley.VolleyError; -import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.AppController; import com.gh.common.constant.Config; import com.gh.common.constant.Constants; @@ -51,6 +50,7 @@ import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; import com.gh.gamecenter.entity.SlideEntity; import com.gh.gamecenter.entity.SubjectEntity; +import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.manager.PackageManager; import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; @@ -82,11 +82,9 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter slideList; private List pluginList; @@ -104,19 +102,14 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter(); pluginList = new ArrayList<>(); @@ -248,13 +241,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter subjectList; private ArrayMap> locationMap; private ArrayMap nameMap; - public Game2FragmentAdapter(Game2Fragment fragment, - SwipeRefreshLayout refreshLayout, - RecyclerView rView, - LinearLayout linearLayout, - ProgressBarCircularIndeterminate pbLoading, - boolean isLoad) { + public Game2FragmentAdapter(Game2Fragment fragment, boolean isLoad) { this.fragment = fragment; this.context = fragment.getActivity(); - - recyclerview = rView; - game_swipe_refresh = refreshLayout; - reuse_no_connection = linearLayout; - game_pb_loading = pbLoading; + this.listener = fragment; subjectList = new ArrayList<>(); @@ -171,13 +156,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter { +public class Game3FragmentAdapter extends RecyclerView.Adapter { private Game3Fragment fragment; private Context context; - - private RecyclerView recyclerView; - private SwipeRefreshLayout game_swipe_refresh; - private LinearLayout reuse_no_connection; - private ProgressBarCircularIndeterminate game_pb_loading; + private OnCallBackListener listener; private boolean isRemove; private boolean isLoading; @@ -78,20 +71,11 @@ public class Game3FragmentAdapter extends private ArrayMap nameMap; // 黄壮华 获取引用 修改2015/8/15 - public Game3FragmentAdapter(Game3Fragment fment, - SwipeRefreshLayout swipeRefreshLayout, - RecyclerView rView, - LinearLayout linearLayout, - ProgressBarCircularIndeterminate pbLoading, - boolean isLoad) { + public Game3FragmentAdapter(Game3Fragment fment, boolean isLoad) { this.fragment = fment; this.context = fment.getActivity(); - - game_swipe_refresh = swipeRefreshLayout; - recyclerView = rView; - reuse_no_connection = linearLayout; - game_pb_loading = pbLoading; + this.listener = fment; locationMap = new ArrayMap<>(); nameMap = new ArrayMap<>(); @@ -151,14 +135,7 @@ public class Game3FragmentAdapter extends if (error.getClass().equals(NoConnectionError.class) || error.getClass().equals(TimeoutError.class)) { if (offset == 0) { - if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) { - game_swipe_refresh.setRefreshing(false); - } - if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) { - game_pb_loading.setVisibility(View.GONE); - } - recyclerView.setVisibility(View.GONE); - reuse_no_connection.setVisibility(View.VISIBLE); + listener.loadError(); } else { Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); isNetworkError = true; @@ -205,13 +182,7 @@ public class Game3FragmentAdapter extends notifyDataSetChanged(); } - if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) { - game_swipe_refresh.setRefreshing(false); - } - - if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) { - game_pb_loading.setVisibility(View.GONE); - } + listener.loadDone(); if (gameList == null || gameList.isEmpty() || (offset == 0 && gameList.size() < 20)) { isRemove = true; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java similarity index 91% rename from app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java index 6d6d563d5b..e40df10f04 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/GameDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter; +package com.gh.gamecenter.gamedetail; import android.content.Context; import android.content.Intent; @@ -31,10 +31,6 @@ import com.gh.gamecenter.GameDetailActivity; import com.gh.gamecenter.GameNewsActivity; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; -import com.gh.gamecenter.adapter.viewholder.GameDetailIntroViewHolder; -import com.gh.gamecenter.adapter.viewholder.GameDetailNewsViewHolder; -import com.gh.gamecenter.adapter.viewholder.GameDetailPluginViewHolder; -import com.gh.gamecenter.adapter.viewholder.GameDetailTopViewHolder; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameDetailEntity; import com.gh.gamecenter.entity.GameEntity; @@ -140,7 +136,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { } initPosition(); if (position_news != -1) { - notifyItemInserted(position_news); +// notifyItemInserted(position_news); + notifyDataSetChanged(); } } }, @@ -262,12 +259,6 @@ public class GameDetailAdapter extends RecyclerView.Adapter { private void initPluginViewHolder(final GameDetailPluginViewHolder viewHolder) { ArrayList tags = gameDetailEntity.getTag(); - if (!TextUtils.isEmpty(gameDetailEntity.getRemind())) { - TagEntity tagEntity = new TagEntity(); - tagEntity.setName("温馨提示"); - tagEntity.setDes(gameDetailEntity.getRemind()); - tags.add(0,tagEntity); - } viewHolder.gamedetail_ll_plugin.setVisibility(View.GONE); viewHolder.open_plugin_detail_ll.setOnClickListener(new View.OnClickListener() { @@ -292,43 +283,47 @@ public class GameDetailAdapter extends RecyclerView.Adapter { ImageView iv_hint; TextView tv_hint; TextView tv_content; - for (int i = 0, size = tags.size(); i < size; i++) { + TagEntity tagEntity; + for (int i = 0, size = tags.size() + 1; i < size; i++) { view = View.inflate(context, R.layout.gamedetail_plugin_item, null); iv_hint = (ImageView) view.findViewById(R.id.gamedetail_iv_hint); tv_hint = (TextView) view.findViewById(R.id.gamedetail_tv_hint); tv_content = (TextView) view.findViewById(R.id.gamedetail_tv_content); - tv_content.setText(tags.get(i).getDes()); - tv_hint.setText(tags.get(i).getName()); - - if (i == 0){ + if (i == 0) { tv_hint.setTextColor(Color.parseColor("#00B7FA")); + if (TextUtils.isEmpty(gameDetailEntity.getRemind())) { + tv_content.setText("无需root尽享插件功能"); + } else { + tv_content.setText(gameDetailEntity.getRemind()); + } + } else { + tagEntity = tags.get(i - 1); + tv_content.setText(tagEntity.getDes()); + tv_hint.setText(tagEntity.getName()); + ImageUtils.getInstance(context).display(tagEntity.getIcon(), iv_hint); } - if (!TextUtils.isEmpty(tags.get(i).getIcon())) { - ImageUtils.getInstance(context).display(tags.get(i).getIcon(), iv_hint); - } - viewHolder.gamedetail_ll_plugin.addView(view); } view = View.inflate(context, R.layout.gamedetail_plugin_item, null); - iv_hint = (ImageView) view.findViewById(R.id.gamedetail_iv_hint); tv_hint = (TextView) view.findViewById(R.id.gamedetail_tv_hint); tv_content = (TextView) view.findViewById(R.id.gamedetail_tv_content); - tv_content.setText(tags.get(0).getDes()); - tv_hint.setText(tags.get(0).getName()); + if (TextUtils.isEmpty(gameDetailEntity.getRemind())) { + tv_content.setText("无需root尽享插件功能"); + } else { + tv_content.setText(gameDetailEntity.getRemind()); + } + tv_hint.setText("温馨提示"); tv_hint.setTextColor(Color.parseColor("#00B7FA")); - if (!TextUtils.isEmpty(tags.get(0).getIcon())) { - ImageUtils.getInstance(context).display(tags.get(0).getIcon(), iv_hint); - } viewHolder.gamedetail_ll_plugin_colse.addView(view); RecyclerView recyclerView = new RecyclerView(context); recyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - int index = (int) Math.ceil((tags.size()-1) / 3.0); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT - , DisplayUtils.dip2px(context, index * 28)); + int index = (int) Math.ceil(tags.size() / 3.0); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(context, index * 28)); params.setMargins(0, DisplayUtils.dip2px(context, index * 3), 0, 0); recyclerView.setLayoutParams(params); @@ -336,6 +331,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { viewHolder.gamedetail_ll_plugin_colse.addView(recyclerView); } } + private class PluginAdapter extends RecyclerView.Adapter{ private ArrayList tags; @@ -355,7 +351,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(context, 28)); linearLayout.setLayoutParams(llParams); - switch (viewType%3) { + switch (viewType % 3) { case 0: linearLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); break; @@ -382,13 +378,13 @@ public class GameDetailAdapter extends RecyclerView.Adapter { @Override public void onBindViewHolder(PluginAdapter.ViewHolder holder, int position) { - holder.pluginTitle.setText(tags.get(position+1).getName()); - ImageUtils.getInstance(context).display(tags.get(position+1).getIcon(), holder.pluginIcon); + holder.pluginTitle.setText(tags.get(position).getName()); + ImageUtils.getInstance(context).display(tags.get(position).getIcon(), holder.pluginIcon); } @Override public int getItemCount() { - return tags.size()-1; + return tags.size(); } public class ViewHolder extends RecyclerView.ViewHolder{ @@ -453,7 +449,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { //添加关注 String uuid = ConcernUtils.uuid(context); - ConcernUtils.postConcernGameId(gameId, Config.HOST + "v2d0/device/" + uuid + "/concern", new ConcernUtils.DownJsonListener() { + ConcernUtils.postConcernGameId(gameId, Config.HOST + "v2d0/device/" + uuid + "/concern", + new ConcernUtils.DownJsonListener() { @Override public void downSucced(String str) { Utils.log("关注提交成功==游戏详情"); @@ -489,7 +486,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { //取消关注 String uuid = ConcernUtils.uuid(context); - ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameId, new ConcernUtils.DownJsonListener() { + ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameId, + new ConcernUtils.DownJsonListener() { @Override public void downSucced(String str) { Utils.log("删除提交成功==游戏详情"); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailIntroViewHolder.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailIntroViewHolder.java similarity index 93% rename from app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailIntroViewHolder.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailIntroViewHolder.java index 32a0738481..f811bf3618 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailIntroViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailIntroViewHolder.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter.viewholder; +package com.gh.gamecenter.gamedetail; import android.support.v7.widget.RecyclerView; import android.view.View; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailNewsViewHolder.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsViewHolder.java similarity index 93% rename from app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailNewsViewHolder.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsViewHolder.java index 39e53af654..fc202f5094 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailNewsViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsViewHolder.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter.viewholder; +package com.gh.gamecenter.gamedetail; import android.support.v7.widget.RecyclerView; import android.view.View; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailPluginViewHolder.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailPluginViewHolder.java similarity index 95% rename from app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailPluginViewHolder.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailPluginViewHolder.java index cfe60240dd..b9fcca5796 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailPluginViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailPluginViewHolder.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter.viewholder; +package com.gh.gamecenter.gamedetail; import android.support.v7.widget.RecyclerView; import android.view.View; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailTopViewHolder.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailTopViewHolder.java similarity index 94% rename from app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailTopViewHolder.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailTopViewHolder.java index d5d1ea4c85..2929f009a8 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameDetailTopViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailTopViewHolder.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter.viewholder; +package com.gh.gamecenter.gamedetail; import android.support.v7.widget.RecyclerView; import android.view.View; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/GameGalleryAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java similarity index 93% rename from app/src/main/java/com/gh/gamecenter/adapter/GameGalleryAdapter.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java index 7214c5c23b..b57b9ab694 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/GameGalleryAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter; +package com.gh.gamecenter.gamedetail; import android.content.Context; import android.content.Intent; @@ -10,7 +10,6 @@ import android.view.ViewGroup; import com.gh.common.util.ImageUtils; import com.gh.gamecenter.R; import com.gh.gamecenter.ViewImageActivity; -import com.gh.gamecenter.adapter.viewholder.GameGalleryViewHolder; import java.util.ArrayList; diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameGalleryViewHolder.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryViewHolder.java similarity index 90% rename from app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameGalleryViewHolder.java rename to app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryViewHolder.java index d01ef1f6f9..f0ed0315c4 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/GameGalleryViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryViewHolder.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.adapter.viewholder; +package com.gh.gamecenter.gamedetail; import android.support.v7.widget.RecyclerView; import android.view.View; diff --git a/app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java b/app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java index 10079b7dd8..a80132d2fa 100644 --- a/app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java +++ b/app/src/main/java/com/gh/gamecenter/listener/OnCallBackListener.java @@ -6,6 +6,7 @@ package com.gh.gamecenter.listener; public interface OnCallBackListener { void loadDone(); + void loadDone(Object obj); void loadError(); void loadEmpty(); diff --git a/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java b/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java index f1af031602..87f9c73eea 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java @@ -53,8 +53,8 @@ public class FilterManager { public void getFilterFromServer(final String today) { long skip = dao.getCount(); JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( - Request.Method.GET, Config.HOST - + "v1d45/support/package/unused?skip=" + skip, + Request.Method.GET, + Config.HOST + "v1d45/support/package/unused?skip=" + skip, new JSONArray(), new Response.Listener() { @Override diff --git a/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java b/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java index 3f3a9d3b73..2bc558ab81 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java @@ -54,8 +54,7 @@ public class News1Fragment extends BaseFragment implements SwipeRefreshLayout.On original_list.setHasFixedSize(true); layoutManager = new LinearLayoutManager(getActivity()); original_list.setLayoutManager(layoutManager); - adapter = new News1FragmentAdapter(News1Fragment.this, original_list, original_swipe_refresh, - original_pb_loading, reuse_no_connection, false); + adapter = new News1FragmentAdapter(News1Fragment.this, false); original_list.setAdapter(adapter); original_list.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override @@ -72,6 +71,28 @@ public class News1Fragment extends BaseFragment implements SwipeRefreshLayout.On }); } + @Override + public void loadDone() { + if (original_swipe_refresh != null && original_swipe_refresh.isRefreshing()) { + original_swipe_refresh.setRefreshing(false); + } + if (original_pb_loading != null && original_pb_loading.getVisibility() == View.VISIBLE) { + original_pb_loading.setVisibility(View.GONE); + } + } + + @Override + public void loadError() { + if (original_swipe_refresh != null && original_swipe_refresh.isRefreshing()) { + original_swipe_refresh.setRefreshing(false); + } + if (original_pb_loading != null && original_pb_loading.getVisibility() == View.VISIBLE) { + original_pb_loading.setVisibility(View.GONE); + } + original_list.setVisibility(View.GONE); + reuse_no_connection.setVisibility(View.VISIBLE); + } + //连接上网络事件 public void onEventMainThread(EBNetworkState busNetworkState) { if (busNetworkState.isNetworkConnected()) { @@ -102,8 +123,7 @@ public class News1Fragment extends BaseFragment implements SwipeRefreshLayout.On @Override public void run() { if (!isDestroy) { - adapter = new News1FragmentAdapter(News1Fragment.this, original_list, original_swipe_refresh, - original_pb_loading, reuse_no_connection, true); + adapter = new News1FragmentAdapter(News1Fragment.this, true); original_list.setAdapter(adapter); } } diff --git a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java index add01f295c..98aa9c8e4c 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java @@ -3,13 +3,11 @@ package com.gh.gamecenter.news; import android.content.Context; import android.graphics.Color; import android.support.v4.util.ArrayMap; -import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.RecyclerView; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -19,7 +17,6 @@ import com.android.volley.Response; import com.android.volley.TimeoutError; import com.android.volley.VolleyError; import com.android.volley.toolbox.DiskBasedCache; -import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.AppController; import com.gh.common.constant.Config; import com.gh.common.constant.Constants; @@ -37,6 +34,7 @@ import com.gh.gamecenter.adapter.viewholder.NewsImage1ViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsImage2ViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder; import com.gh.gamecenter.entity.NewsEntity; +import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest; import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest; import com.google.gson.Gson; @@ -67,10 +65,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter newsList; private ArrayMap viewsMap; @@ -80,19 +75,11 @@ public class News1FragmentAdapter extends RecyclerView.Adapter(); viewsMap = new ArrayMap<>(); @@ -140,12 +127,8 @@ public class News1FragmentAdapter extends RecyclerView.Adapter newsList; private ArrayMap viewsMap; @@ -80,23 +76,15 @@ public class News2FragmentAdapter extends RecyclerView.Adapter(); - viewsMap = new ArrayMap(); - urlList = new ArrayList(); + newsList = new ArrayList<>(); + viewsMap = new ArrayMap<>(); + urlList = new ArrayList<>(); isLoading = false; isRemove = false; @@ -140,12 +128,8 @@ public class News2FragmentAdapter extends RecyclerView.Adapter todayNewsList; @@ -83,20 +78,14 @@ public class News3FragmentAdapter extends private boolean isLoading; private boolean isNetworkError; - public News3FragmentAdapter(Context context, - RecyclerView recyclerView, - ProgressBarCircularIndeterminate loading, - LinearLayout noconnection, - SwipeRefreshLayout swipeRefreshLayout, + public News3FragmentAdapter(News3Fragment fregment, TextView tlabel, boolean isLoad) { - this.context = context; - news_list = recyclerView; - news_swipe_refresh = swipeRefreshLayout; + this.context = fregment.getActivity(); + this.listener = fregment; + news_tv_label = tlabel; - news_pb_loading = loading; - ll_noconnection = noconnection; todayNewsList = new ArrayList<>(); beforeNewsList = new ArrayList<>(); @@ -120,8 +109,8 @@ public class News3FragmentAdapter extends } isLoading = true; JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( - TimestampUtils.addTimestamp(Config.HOST - + "v1d45/news?type_group=" + Uri.encode("攻略") + TimestampUtils.addTimestamp( + Config.HOST + "v1d45/news?type_group=" + Uri.encode("攻略") + "&offset=" + offset + "&limit=20", Constants.NEWS_CD), new Response.Listener() { @@ -151,10 +140,6 @@ public class News3FragmentAdapter extends } refreshCount(); - - if (news_swipe_refresh.isRefreshing()) { - news_swipe_refresh.setRefreshing(false); - } } else { for (int i = 0, size = list.size(); i < size; i++) { int day = Integer.valueOf(format.format(new Date(Long.valueOf(list @@ -185,9 +170,7 @@ public class News3FragmentAdapter extends notifyItemChanged(getItemCount() - list.size() - 2); } - if (news_pb_loading != null && news_pb_loading.getVisibility() == View.VISIBLE) { - news_pb_loading.setVisibility(View.GONE); - } + listener.loadDone(); if (list.size() < 20) { isRemove = true; @@ -205,15 +188,7 @@ public class News3FragmentAdapter extends if (error.getClass().equals(NoConnectionError.class) || error.getClass().equals(TimeoutError.class)) { if (offset == 0) { - Toast.makeText(context, "获取攻略失败", Toast.LENGTH_SHORT).show(); - if (news_pb_loading != null && news_pb_loading.getVisibility() == View.VISIBLE) { - news_pb_loading.setVisibility(View.GONE); - } - news_list.setVisibility(View.GONE); - ll_noconnection.setVisibility(View.VISIBLE); - if (news_swipe_refresh.isRefreshing()) { - news_swipe_refresh.setRefreshing(false); - } + listener.loadError(); } else { Toast.makeText(context, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); isNetworkError = true; 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 eee3c92b91..66f5ce2af0 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java @@ -76,8 +76,7 @@ public class News4FragmentAdapter extends RecyclerView.Adapter() { + @Override + public void onResponse(JSONObject response) { + + Gson gson = new Gson(); + newsDetailEntity = gson.fromJson(response.toString(), NewsDetailEntity.class); + newsDetailEntity.setId(id); + newsDetailEntity.setType(type); + newsDetailEntity.setTitle(title); + + notifyDataSetChanged(); + + // 获取相关推荐 + getNewsMore(); + } + + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + // 无网络连接和访问超时 + if (error.getClass().equals(NoConnectionError.class) + || error.getClass().equals(TimeoutError.class)) { + listener.loadError(); + } + } + }); + AppController.addToRequestQueue(request, NewsDetailActivity.class); + } + + private void getNewsMore() { + JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( + TimestampUtils.addTimestamp( + Config.HOST + "v1d45/news/" + newsDetailEntity.getId() + "/suggestion", + Constants.NEWS_CD), + new Response.Listener() { + @Override + public void onResponse(JSONArray response) { + Type listType = new TypeToken>() {}.getType(); + Gson gson = new Gson(); + List list = gson.fromJson(response.toString(), listType); + // 去除与当前文章重复的文章 + for (int i = 0, size = list.size(); i < size; i++) { + if (newsDetailEntity.getId().equals(list.get(i).getId())) { + list.remove(i); + break; + } + } + List more = new ArrayList<>(); + // TODO 随机三篇文章 + int[] index = RandomUtils.getRandomArray(list.size() > 3 ? 3 : list.size(), list.size()); + for (int i : index) { + more.add(list.get(i)); + } + newsDetailEntity.setMore(more); + notifyDataSetChanged(); + } + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + + } + }); + AppController.addToRequestQueue(request, NewsDetailActivity.class); + } + + @Override + public int getItemCount() { + if (newsDetailEntity == null) { + return 0; + } + int count = 1; + if (gameEntity != null) { + count++; + } + if (newsDetailEntity.getMore() != null && newsDetailEntity.getMore().size() != 0) { + count++; + } + return count; + } + + @Override + public int getItemViewType(int position) { + if (gameEntity != null && position == 1) { + return 1; + } else if (gameEntity == null && position == 1) { + return 2; + } + return position; + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (viewType == 0) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.newsdetail_item_content, parent, false); + return new NewsDetailContentViewHolder(view); + } else if (viewType == 1) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.gamedetail_item_top, parent, false); + return new GameDetailTopViewHolder(view); + } else if (viewType == 2) { + View view = LayoutInflater.from(parent.getContext()).inflate( + R.layout.newsdetail_item_news_more, parent, false); + return new NewsDetailNewsMoreViewHolder(view); + } + return null; + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + if (holder instanceof NewsDetailContentViewHolder) { + initNewsDetailContentViewHolder((NewsDetailContentViewHolder) holder); + } else if (holder instanceof GameDetailTopViewHolder) { + initGameDetailTopViewHolder((GameDetailTopViewHolder) holder); + } else if (holder instanceof NewsDetailNewsMoreViewHolder) { + initNewsDetailNewsMoreViewHolder((NewsDetailNewsMoreViewHolder) holder); + } + } + + private void initNewsDetailNewsMoreViewHolder(NewsDetailNewsMoreViewHolder viewHolder) { + if (viewHolder.newsdetail_item_ll_news_more.getTag() == null) { + NewsEntity newsEntity; + for (int i = 0; i < newsDetailEntity.getMore().size(); i++) { + newsEntity = newsDetailEntity.getMore().get(i); + View view = View.inflate(context, R.layout.gamedetail_news_item, null); + TextView tv_tag = (TextView) view.findViewById(R.id.gamedetail_news_item_tag); + TextView tv_title = (TextView) view.findViewById(R.id.gamedetail_news_item_title); + tv_tag.setText(newsEntity.getType()); + tv_title.setText(newsEntity.getTitle()); + tv_title.setTextColor(Color.parseColor("#3a3a3a")); + final String newsId = newsEntity.getId(); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, NewsDetailActivity.class); + intent.putExtra("newsId", newsId); + intent.putExtra("entrance", entrance); + context.startActivity(intent); + } + }); + viewHolder.newsdetail_item_ll_news_more.addView(view); + } + viewHolder.newsdetail_item_ll_news_more.setTag("done"); + } + } + + private void initGameDetailTopViewHolder(GameDetailTopViewHolder viewHolder) { + ImageUtils.getInstance(context).displayFile(gameEntity.getIcon(), viewHolder.gamedetail_iv_thumb); + viewHolder.gamedetail_tv_name.setText(gameEntity.getName()); + if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) { + for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) { + ApkEntity apkEntity = gameEntity.getApk().get(i); + if ("9u".equals(apkEntity.getPlatform())) { + viewHolder.gamedetail_tv_info.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize())); + break; + } + if (i == size - 1) { + viewHolder.gamedetail_tv_info.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize())); + } + } + } + if (concernManager.isConcern(gameEntity.getId())) { + viewHolder.gamedetail_tv_concern.setText("取消关注"); + viewHolder.gamedetail_tv_concern.setBackgroundResource(R.drawable.border_red_bg); + viewHolder.gamedetail_tv_concern.setTextColor(0xffbc2132); + } else { + viewHolder.gamedetail_tv_concern.setText("关注"); + viewHolder.gamedetail_tv_concern.setBackgroundResource(R.drawable.textview_red_style); + viewHolder.gamedetail_tv_concern.setTextColor(Color.WHITE); + } + viewHolder.gamedetail_tv_concern.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final TextView concern = ((TextView) v); + String str = concern.getText().toString(); + if ("关注".equals(str)) { + + Map kv = new HashMap<>(); + kv.put("状态", "关注"); + DataUtils.onEvent(context, "游戏关注", gameEntity.getName(), kv); + + Map kv2 = new HashMap<>(); + kv2.put("点击", "关注"); + DataUtils.onEvent(context, "插件数据", gameEntity.getName(), kv2); + + Map map = new HashMap<>(); + map.put("game", gameEntity.getName()); + map.put("type", "关注"); + map.put("createdOn", System.currentTimeMillis() / 1000); + DataCollectionManager.onEvent(context, "concern", map); + + concernManager.addByEntity(gameEntity); + concern.setText("取消关注"); + concern.setBackgroundResource(R.drawable.border_red_bg); + concern.setTextColor(0xffbc2132); + + Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show(); + + //添加关注 + String uuid = ConcernUtils.uuid(context); + 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<>(); + kv2.put("点击", "取消关注"); + DataUtils.onEvent(context, "插件数据", gameEntity.getName(), kv2); + + 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(Color.WHITE); + + //取消关注 + String uuid = ConcernUtils.uuid(context); + 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("删除提交失败==游戏详情"); + } + }); + } + }); + } + } + }); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, GameDetailActivity.class); + intent.putExtra("gameId", gameEntity.getId()); + intent.putExtra("entrance", entrance); + context.startActivity(intent); + } + }); + } + + private void initNewsDetailContentViewHolder(NewsDetailContentViewHolder viewHolder) { + viewHolder.newsdetail_item_tv_title.setText(newsDetailEntity.getTitle()); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); + try { + long today = format.parse(format.format(new Date())).getTime(); + long day = Long.valueOf(newsDetailEntity.getTime() + "000"); + if (day >= today && day < today + 86400 * 1000) { + format.applyPattern("HH:mm"); + viewHolder.newsdetail_item_tv_time.setText("今天 " + format.format(day)); + } else if (day >= today - 86400 * 1000 && day < today) { + format.applyPattern("HH:mm"); + viewHolder.newsdetail_item_tv_time.setText("昨天 " + format.format(day)); + } else { + format.applyPattern("yyyy年MM月dd日 HH:mm"); + viewHolder.newsdetail_item_tv_time.setText(format.format(day)); + } + } catch (ParseException e) { + e.printStackTrace(); + format.applyPattern("yyyy年MM月dd日 HH:mm"); + viewHolder.newsdetail_item_tv_time.setText(format.format(Long.valueOf(newsDetailEntity.getTime() + "000"))); + } + if (!TextUtils.isEmpty(newsDetailEntity.getAuthor())) { + viewHolder.newsdetail_item_tv_author.setText(newsDetailEntity.getAuthor()); + } + + if (viewHolder.newsdetail_item_wv_content.getTag() == null) { + viewHolder.newsdetail_item_wv_content.setBackgroundColor(0); + viewHolder.newsdetail_item_wv_content.addJavascriptInterface(new JsInterface(context), "imagelistener"); + webSettings = viewHolder.newsdetail_item_wv_content.getSettings(); + webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); + webSettings.setJavaScriptEnabled(true); + SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Activity.MODE_PRIVATE); + webSettings.setTextZoom(defaultTextZoom + sp.getInt("fontsize", 1) * 15); + viewHolder.newsdetail_item_wv_content.loadDataWithBaseURL(null, newsDetailEntity.getContent(), "text/html", "utf-8", null); + viewHolder.newsdetail_item_wv_content.setWebViewClient(new WebViewClient() { + @Override + public void onPageFinished(WebView view, String url) { + view.loadUrl("javascript:(function(){" + + "var imgs = document.getElementsByTagName(\"img\");" + + "for (var i = 0; i < imgs.length - 1; i++) {" + + " window.imagelistener.addImage(imgs[i].src);" + + "}" + + "for (var i = 0; i < imgs.length - 1; i++) {" + + " imgs[i].onclick = function() {" + + " window.imagelistener.openImage(this.src);" + + " }" + + "}" + + "var as = document.getElementsByTagName(\"a\");" + + "for (var i = 0; i < as.length; i++) {" + + " as[i].onclick = function() {" + + " window.imagelistener.skip(this.id, this.type);" + + " }" + + "}" + + "})()"); + super.onPageFinished(view, url); + listener.loadDone(newsDetailEntity.getGameId()); + } + }); + viewHolder.newsdetail_item_wv_content.setTag("show"); + } + } + + public class JsInterface { + private Context context; + private ArrayList imgs = new ArrayList<>(); + + public JsInterface(Context context) { + this.context = context; + } + + @JavascriptInterface + public void openImage(String url) { + int current = 0; + for (int i = 0, size = imgs.size(); i < size; i++) { + if (url.equals(imgs.get(i))) { + current = i; + } + } + Intent checkIntent = new Intent(context, ViewImageActivity.class); + checkIntent.putExtra("urls", imgs); + checkIntent.putExtra("current", current); + checkIntent.putExtra("ScaleType", "FIT_CENTER"); + context.startActivity(checkIntent); + } + + @JavascriptInterface + public void addImage(String url) { + if (!imgs.contains(url)) { + imgs.add(url); + } + } + + @JavascriptInterface + public void skip(String id, String type) { + if ("game".equals(type)) { + Intent intent = new Intent(context, GameDetailActivity.class); + intent.putExtra("gameId", id); + intent.putExtra("entrance", entrance); + context.startActivity(intent); + } else if ("news".equals(type)) { + Intent intent = new Intent(context, NewsDetailActivity.class); + intent.putExtra("newsId", id); + intent.putExtra("entrance", entrance); + context.startActivity(intent); + } + } + + } + + public void setId(String id) { + this.id = id; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setType(String type) { + this.type = type; + } + + public void setGameEntity(GameEntity gameEntity) { + this.gameEntity = gameEntity; + } + + public NewsDetailEntity getNewsDetailEntity() { + return newsDetailEntity; + } + + private int defaultTextZoom = 85; + + public void setFontSize(int fontsize) { + webSettings.setTextZoom(defaultTextZoom + 15 * fontsize); + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailContentViewHolder.java b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailContentViewHolder.java new file mode 100644 index 0000000000..7cfe6b2aa3 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailContentViewHolder.java @@ -0,0 +1,29 @@ +package com.gh.gamecenter.newsdetail; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.webkit.WebView; +import android.widget.TextView; + +import com.gh.gamecenter.R; + +/** + * Created by LGT on 2016/9/13. + */ +public class NewsDetailContentViewHolder extends RecyclerView.ViewHolder { + + public TextView newsdetail_item_tv_title; + public TextView newsdetail_item_tv_time; + public TextView newsdetail_item_tv_author; + public WebView newsdetail_item_wv_content; + + public NewsDetailContentViewHolder(View itemView) { + super(itemView); + + newsdetail_item_tv_title = (TextView) itemView.findViewById(R.id.newsdetail_item_tv_title); + newsdetail_item_tv_time = (TextView) itemView.findViewById(R.id.newsdetail_item_tv_time); + newsdetail_item_tv_author = (TextView) itemView.findViewById(R.id.newsdetail_item_tv_author); + newsdetail_item_wv_content = (WebView) itemView.findViewById(R.id.newsdetail_item_wv_content); + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailNewsMoreViewHolder.java b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailNewsMoreViewHolder.java new file mode 100644 index 0000000000..7aa685584f --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailNewsMoreViewHolder.java @@ -0,0 +1,22 @@ +package com.gh.gamecenter.newsdetail; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; + +import com.gh.gamecenter.R; + +/** + * Created by LGT on 2016/9/13. + */ +public class NewsDetailNewsMoreViewHolder extends RecyclerView.ViewHolder { + + public LinearLayout newsdetail_item_ll_news_more; + + public NewsDetailNewsMoreViewHolder(View itemView) { + super(itemView); + + newsdetail_item_ll_news_more = (LinearLayout) itemView.findViewById(R.id.newsdetail_item_ll_news_more); + } + +} 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 769ff8a9c8..dd916aa460 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java @@ -106,8 +106,9 @@ public class ConcernFragmentAdapter extends RecyclerView.Adapter() { @Override public void onResponse(JSONObject response) { @@ -175,14 +176,14 @@ public class ConcernFragmentAdapter extends RecyclerView.Adapter() { @Override public void onResponse(JSONObject response) { @@ -313,14 +314,14 @@ public class InstallFragmentAdapter extends RecyclerView.Adapter { +public class SearchGameDetailFragmentAdapter extends RecyclerView.Adapter { private Context context; @@ -52,12 +52,12 @@ public class SearchDetailFragmentAdapter extends RecyclerView.Adapter gameList; - public SearchDetailFragmentAdapter(Context context, - RecyclerView search_detail, - LinearLayout search_loading, - LinearLayout search_nogame, - LinearLayout search_connection, - String key) { + public SearchGameDetailFragmentAdapter(Context context, + RecyclerView search_detail, + LinearLayout search_loading, + LinearLayout search_nogame, + LinearLayout search_connection, + String key) { this.context = context; this.search_detail = search_detail; diff --git a/app/src/main/res/drawable-xhdpi/user_default_icon.png b/app/src/main/res/drawable-xhdpi/user_default_icon.png new file mode 100644 index 0000000000..5c1282859b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/user_default_icon.png differ diff --git a/app/src/main/res/layout/activity_newsdetail.xml b/app/src/main/res/layout/activity_newsdetail.xml index 4753a64c8d..9021d1b07f 100644 --- a/app/src/main/res/layout/activity_newsdetail.xml +++ b/app/src/main/res/layout/activity_newsdetail.xml @@ -10,13 +10,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - - - - - + app:cardBackgroundColor="@android:color/white"> + app:contentPaddingTop="15dp" + app:cardBackgroundColor="@android:color/white"> + app:contentPaddingBottom="3dp" + app:cardBackgroundColor="@android:color/white"> + app:contentPaddingTop="15dp" + app:cardBackgroundColor="@android:color/white"> + app:cardUseCompatPadding="true"> - + android:layout_height="wrap_content" + android:orientation="horizontal" + android:gravity="center_vertical" + android:background="@drawable/reuse_listview_item_style" + android:paddingLeft="12dp" + android:paddingTop="15dp" + android:paddingRight="12dp" + android:paddingBottom="15dp"> + - + + \ No newline at end of file diff --git a/app/src/main/res/layout/home3_fragment.xml b/app/src/main/res/layout/home3_fragment.xml index 8291ce4c0d..2d48017b80 100644 --- a/app/src/main/res/layout/home3_fragment.xml +++ b/app/src/main/res/layout/home3_fragment.xml @@ -10,32 +10,53 @@ android:overScrollMode="never"> - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> + android:layout_height="230dp" + android:background="@color/theme"> + + + + + + + + + + - - - + + android:layout_height="40dp"> - - diff --git a/app/src/main/res/layout/newsdetail_item_content.xml b/app/src/main/res/layout/newsdetail_item_content.xml new file mode 100644 index 0000000000..03bfa535e0 --- /dev/null +++ b/app/src/main/res/layout/newsdetail_item_content.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/newsdetail_more_news_item.xml b/app/src/main/res/layout/newsdetail_item_news_more.xml similarity index 81% rename from app/src/main/res/layout/newsdetail_more_news_item.xml rename to app/src/main/res/layout/newsdetail_item_news_more.xml index c2599c113f..266645b61d 100644 --- a/app/src/main/res/layout/newsdetail_more_news_item.xml +++ b/app/src/main/res/layout/newsdetail_item_news_more.xml @@ -5,27 +5,28 @@ android:layout_height="wrap_content" android:layout_marginLeft="@dimen/cardview_mar_left" android:layout_marginRight="@dimen/cardview_mar_left" - android:clickable="true" - android:foreground="?android:attr/selectableItemBackground" app:cardCornerRadius="0dp" app:cardElevation="1dp" app:cardUseCompatPadding="true" app:contentPaddingLeft="12dp" app:contentPaddingRight="12dp" - app:contentPaddingTop="15dp"> + app:contentPaddingTop="15dp" + app:cardBackgroundColor="@android:color/white"> + + \ No newline at end of file