diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index 848ba6ce1e..719e1ef267 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -6,7 +6,7 @@ import android.content.SharedPreferences; public class Config { - public static final String HOST = "http://api.ghzhushou.com/v2d3/"; + public static final String HOST = "http://api.ghzhushou.com/v2d4/"; public static final String USER_HOST = "http://user.ghzhushou.com/v1d1/"; public static final String COMMENT_HOST = "http://comment.ghzhushou.com/v1d1/"; public static final String DATA_HOST = "http://data.ghzhushou.com/"; diff --git a/app/src/main/java/com/gh/common/util/GameViewUtils.java b/app/src/main/java/com/gh/common/util/GameViewUtils.java index ada0c1ff04..ef60d279aa 100644 --- a/app/src/main/java/com/gh/common/util/GameViewUtils.java +++ b/app/src/main/java/com/gh/common/util/GameViewUtils.java @@ -1,7 +1,11 @@ package com.gh.common.util; import android.content.Context; +import android.graphics.Color; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.ShapeDrawable; import android.util.TypedValue; +import android.view.View; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; @@ -31,17 +35,24 @@ public class GameViewUtils { if (tag == null || tag.isEmpty()) { labelLayout.addView(getGameTagView(context, "官方版", 0)); } else { - for (int i = 0, size = tag.size() > 3 ? 3 : tag.size(); i < size; i++) { + for (int i = 0, size = tag.size(); i < size; i++) { + View view; if (i == size - 1) { - labelLayout.addView(getGameTagView(context, tag.get(i), 0)); + view = getGameTagView(context, tag.get(i), 0); } else { - labelLayout.addView(getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 5))); + view = getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 5)); + } + if (view != null) { + labelLayout.addView(view); + } + if (labelLayout.getChildCount() == 3) { + break; } } } } - public static TextView getGameTagView(Context context, String tagStr, int rightMargin) { + private static TextView getGameTagView(Context context, String tagStr, int rightMargin) { LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lparams.rightMargin = rightMargin; @@ -53,8 +64,17 @@ public class GameViewUtils { tag.setBackgroundResource(R.drawable.border_green_bg); tag.setTextColor(context.getResources().getColor(R.color.tag_green)); } else { - tag.setBackgroundResource(R.drawable.border_blue_bg); - tag.setTextColor(context.getResources().getColor(R.color.theme)); + String colorStr = TagUtils.getInstance(context).getColor(tagStr); + if (colorStr == null) { + return null; + } + int color = Color.parseColor(colorStr); + GradientDrawable gradientDrawable = new GradientDrawable(); + gradientDrawable.setColor(Color.TRANSPARENT); + gradientDrawable.setStroke(DisplayUtils.dip2px(context, 0.6f), color); + tag.setBackgroundDrawable(gradientDrawable); +// tag.setBackgroundResource(R.drawable.border_blue_bg); + tag.setTextColor(color); } tag.setLayoutParams(lparams); tag.setPadding(DisplayUtils.dip2px(context, 3), 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 da62db7eb6..cb3deb01a8 100644 --- a/app/src/main/java/com/gh/common/util/PlatformUtils.java +++ b/app/src/main/java/com/gh/common/util/PlatformUtils.java @@ -254,7 +254,7 @@ public class PlatformUtils { return platformName; } - boolean isUpdate = false; + private boolean isUpdate = false; public void getPlatform() { if (isUpdate) { diff --git a/app/src/main/java/com/gh/common/util/TagUtils.java b/app/src/main/java/com/gh/common/util/TagUtils.java new file mode 100644 index 0000000000..b56a84971f --- /dev/null +++ b/app/src/main/java/com/gh/common/util/TagUtils.java @@ -0,0 +1,94 @@ +package com.gh.common.util; + + +import android.content.Context; +import android.content.SharedPreferences; +import android.support.v4.util.ArrayMap; + +import com.gh.gamecenter.entity.TagEntity; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import retrofit2.adapter.rxjava.HttpException; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + +public class TagUtils { + + private static TagUtils mInstance; + + private Context context; + + private ArrayMap colorMap; + + private TagUtils(Context con) { + this.context = con.getApplicationContext(); + initTag(); + } + + public static TagUtils getInstance(Context context) { + if (mInstance == null) { + mInstance = new TagUtils(context); + } + return mInstance; + } + + private void initTag() { + colorMap = new ArrayMap<>(); + + SharedPreferences sharedPreferences = context.getSharedPreferences("gh_tag", Context.MODE_PRIVATE); + Set set = sharedPreferences.getStringSet("tag", null); + if (set == null) { + getTag(); + } else { + for (String str : set) { + String[] platform = str.split("="); + colorMap.put(platform[0], platform[1]); + } + } + } + + public String getColor(String tag) { + String color = colorMap.get(tag); + if (color == null) { + getTag(); + } + return color; + } + + private boolean isUpdate = false; + + public void getTag() { + if (isUpdate) { + return; + } + isUpdate = true; + RetrofitManager.getApi().getTags() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + Set tagSet = new HashSet<>(); + for (TagEntity tagEntity : response) { + tagSet.add(tagEntity.getName() + "=" + tagEntity.getColor()); + } + SharedPreferences sp = context.getSharedPreferences("gh_tag", Context.MODE_PRIVATE); + sp.edit().putStringSet("tag", tagSet).apply(); + initTag(); + + isUpdate = false; + } + + @Override + public void onFailure(HttpException e) { + isUpdate = false; + } + }); + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index e4ec228e49..b425c18f9a 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -23,6 +23,7 @@ import com.gh.common.constant.Config; import com.gh.common.util.FileUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; +import com.gh.common.util.TagUtils; import com.gh.common.util.TimestampUtils; import com.gh.common.util.TokenUtils; import com.gh.common.util.Utils; @@ -195,6 +196,7 @@ public class SplashScreenActivity extends BaseActivity { if (!today.equals(time)) { // 获取版本代码、名称 PlatformUtils.getInstance(getApplicationContext()).getPlatform(); + TagUtils.getInstance(getApplicationContext()).getTag(); } // 获取下载按钮状态、开启or关闭 diff --git a/app/src/main/java/com/gh/gamecenter/entity/GameDetailEntity.java b/app/src/main/java/com/gh/gamecenter/entity/GameDetailEntity.java index 22e5c0edca..1fa355808e 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/GameDetailEntity.java +++ b/app/src/main/java/com/gh/gamecenter/entity/GameDetailEntity.java @@ -9,7 +9,7 @@ public class GameDetailEntity { private List serverInfo; private ArrayList tag; - private String remind; + private TipsEntity tips; private List news; private ArrayList gallery; private String des; @@ -64,14 +64,6 @@ public class GameDetailEntity { this.tag = tag; } - public String getRemind() { - return remind; - } - - public void setRemind(String remind) { - this.remind = remind; - } - public List getNews() { return news; } @@ -112,4 +104,11 @@ public class GameDetailEntity { this.shareCode = shareCode; } + public TipsEntity getTips() { + return tips; + } + + public void setTips(TipsEntity tips) { + this.tips = tips; + } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/TagEntity.java b/app/src/main/java/com/gh/gamecenter/entity/TagEntity.java index 7949c5d2b4..6fd526c666 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/TagEntity.java +++ b/app/src/main/java/com/gh/gamecenter/entity/TagEntity.java @@ -6,6 +6,7 @@ public class TagEntity { private String name; private String icon; private String des; + private String color; public String getName() { return name; @@ -31,4 +32,11 @@ public class TagEntity { this.des = des; } + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/TipsEntity.java b/app/src/main/java/com/gh/gamecenter/entity/TipsEntity.java new file mode 100644 index 0000000000..a340c76308 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/entity/TipsEntity.java @@ -0,0 +1,33 @@ +package com.gh.gamecenter.entity; + + +public class TipsEntity { + + private String icon; + private TitleEntity title; + private String content; + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public TitleEntity getTitle() { + return title; + } + + public void setTitle(TitleEntity title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/entity/TitleEntity.java b/app/src/main/java/com/gh/gamecenter/entity/TitleEntity.java new file mode 100644 index 0000000000..80b9c26dee --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/entity/TitleEntity.java @@ -0,0 +1,24 @@ +package com.gh.gamecenter.entity; + + +public class TitleEntity { + + private String color; + private String value; + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java index 57b046dd14..e2f50c53af 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java @@ -567,12 +567,12 @@ public class GameDetailAdapter extends RecyclerView.Adapter { viewHolder.open_plugin_detail_ll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (viewHolder.gamedetail_ll_plugin.getVisibility() == View.GONE){ + if (viewHolder.gamedetail_ll_plugin.getVisibility() == View.GONE) { viewHolder.gamedetail_ll_plugin.setVisibility(View.VISIBLE); viewHolder.gamedetail_ll_plugin_colse.setVisibility(View.GONE); viewHolder.open_plugin_detail_img.setImageResource(R.drawable.up_img); viewHolder.open_plugin_detail_tv.setText("收起"); - }else { + } else { viewHolder.gamedetail_ll_plugin.setVisibility(View.GONE); viewHolder.gamedetail_ll_plugin_colse.setVisibility(View.VISIBLE); viewHolder.open_plugin_detail_img.setImageResource(R.drawable.down_img); @@ -587,41 +587,40 @@ public class GameDetailAdapter extends RecyclerView.Adapter { TextView tv_hint; TextView tv_content; TagEntity tagEntity; - for (int i = 0, size = tags.size() + 1; i < size; i++) { + if (gameDetailEntity.getTips() != null && !TextUtils.isEmpty(gameDetailEntity.getTips().getContent())) { view = View.inflate(context, R.layout.gamedetail_plugin_item, null); iv_hint = (SimpleDraweeView) 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); - 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.display(iv_hint, gameDetailEntity.getTips().getIcon()); + tv_hint.setTextColor(Color.parseColor(gameDetailEntity.getTips().getTitle().getColor())); + tv_hint.setText(gameDetailEntity.getTips().getTitle().getValue()); + tv_content.setText(gameDetailEntity.getTips().getContent()); + viewHolder.gamedetail_ll_plugin.addView(view); + + view = View.inflate(context, R.layout.gamedetail_plugin_item, null); + iv_hint = (SimpleDraweeView) 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); + ImageUtils.display(iv_hint, gameDetailEntity.getTips().getIcon()); + tv_hint.setTextColor(Color.parseColor(gameDetailEntity.getTips().getTitle().getColor())); + tv_hint.setText(gameDetailEntity.getTips().getTitle().getValue()); + tv_content.setText(gameDetailEntity.getTips().getContent()); + viewHolder.gamedetail_ll_plugin_colse.addView(view); + } + for (int i = 0, size = tags.size(); i < size; i++) { + view = View.inflate(context, R.layout.gamedetail_plugin_item, null); + iv_hint = (SimpleDraweeView) 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); + tagEntity = tags.get(i); + tv_content.setText(tagEntity.getDes()); + tv_hint.setText(tagEntity.getName()); // iv_hint.setImageURI(tagEntity.getIcon()); - ImageUtils.display(iv_hint, tagEntity.getIcon()); - } + ImageUtils.display(iv_hint, tagEntity.getIcon()); viewHolder.gamedetail_ll_plugin.addView(view); } - view = View.inflate(context, R.layout.gamedetail_plugin_item, null); - tv_hint = (TextView) view.findViewById(R.id.gamedetail_tv_hint); - tv_content = (TextView) view.findViewById(R.id.gamedetail_tv_content); - if (TextUtils.isEmpty(gameDetailEntity.getRemind())) { - tv_content.setText("无需root尽享插件功能"); - } else { - tv_content.setText(gameDetailEntity.getRemind()); - } - tv_hint.setText("温馨提示"); - tv_hint.setTextColor(Color.parseColor("#00B7FA")); - - viewHolder.gamedetail_ll_plugin_colse.addView(view); - RecyclerView recyclerView = new RecyclerView(context); recyclerView.setLayoutManager(new GridLayoutManager(context, 3)); diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java index c8a9f66133..22a3f4a032 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java @@ -13,6 +13,7 @@ import com.gh.gamecenter.entity.PlatformEntity; import com.gh.gamecenter.entity.SlideEntity; import com.gh.gamecenter.entity.SubjectDigestEntity; import com.gh.gamecenter.entity.SubjectEntity; +import com.gh.gamecenter.entity.TagEntity; import java.util.List; @@ -163,4 +164,7 @@ public interface ApiService { @GET("column/{column_id}/name") Observable getSubjectName(@Path("column_id") String column_id); //根据专题ID获取专题名称 + @GET("game/digest/tags") + Observable> getTags(); //获取游戏的所有标签 + } \ No newline at end of file