|
|
@@ -1,17 +1,33 @@
|
|
|
package com.sheep.jiuyan.samllsheep.page;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
+import android.text.Html;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
+import android.webkit.WebChromeClient;
|
|
|
+import android.webkit.WebResourceRequest;
|
|
|
import android.webkit.WebView;
|
|
|
+import android.webkit.WebViewClient;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.NetManager;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.Url;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
/**
|
|
|
* Created by kemllor on 2018/1/16.
|
|
|
* 游戏详情
|
|
|
@@ -19,22 +35,12 @@ import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
public class GameDetailActivity extends BaseActivity {
|
|
|
|
|
|
- private TextView mTvTitle;
|
|
|
- private View mBack;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected int getLayoutId() {
|
|
|
- return R.layout.game_detail_activity;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void initView() {
|
|
|
- findViews();
|
|
|
- }
|
|
|
|
|
|
+ private final static String HTML_FORMAT = "任务数量:<font color=\"#ef712c\">当前数量</font>/总数";
|
|
|
+ private TaskPublish mTask;
|
|
|
private RelativeLayout mDingwei1;
|
|
|
private ImageView mImgIcon;
|
|
|
- private TextView mTxtBaseactivityTitle;
|
|
|
+ private TextView mTxtTitle;
|
|
|
private TextView mTvCount;
|
|
|
private TextView mTvTime;
|
|
|
private TextView mTvBouns;
|
|
|
@@ -44,10 +50,21 @@ public class GameDetailActivity extends BaseActivity {
|
|
|
private WebView mWebText;
|
|
|
private LinearLayout mLlInfos;
|
|
|
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.game_detail_activity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ findViews();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void findViews() {
|
|
|
mDingwei1 = (RelativeLayout) findViewById(R.id.dingwei1);
|
|
|
mImgIcon = (ImageView) findViewById(R.id.img_icon);
|
|
|
- mTxtBaseactivityTitle = (TextView) findViewById(R.id.txt_baseactivity_title);
|
|
|
+ mTxtTitle = (TextView) findViewById(R.id.tv_game_name);
|
|
|
mTvCount = (TextView) findViewById(R.id.tv_count);
|
|
|
mTvTime = (TextView) findViewById(R.id.tv_time);
|
|
|
mTvBouns = (TextView) findViewById(R.id.tv_bouns);
|
|
|
@@ -58,16 +75,111 @@ public class GameDetailActivity extends BaseActivity {
|
|
|
mLlInfos = (LinearLayout) findViewById(R.id.ll_infos);
|
|
|
TitleBarUtils.getInstance().setTitle(this, "任务详情")
|
|
|
.setTitleFinish(this);
|
|
|
- }
|
|
|
+ mWebText.setWebChromeClient(new WebChromeClient() {
|
|
|
|
|
|
+ });
|
|
|
+ mWebText.getSettings().setJavaScriptEnabled(true);
|
|
|
+ mWebText.setWebViewClient(new WebViewClient() {
|
|
|
+ @Override
|
|
|
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
|
+ view.loadUrl(request.getUrl().toString());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
-
|
|
|
+ mBtnTaskItem.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, mTask.getTask().getPkg())) {
|
|
|
+ PackageUtil.startApp(SheepApp.mContext, mTask.getTask().getPkg());
|
|
|
+ } else {
|
|
|
+ Intent intent = new Intent(GameDetailActivity.this, DownloadActivity.class);
|
|
|
+ intent.putExtra("task", mTask.getTask());
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
+ Intent intent = getIntent();
|
|
|
+ mTask = (TaskPublish) intent.getSerializableExtra("data");
|
|
|
+ if (mTask != null) {
|
|
|
+ mTvTime.setText(String.format("截止日期:%s", mTask.getOverTime()));
|
|
|
+ mTvBouns.setText(mTask.getTask().getBonus());
|
|
|
+ mTvMoney.setText(mTask.getTask().getPrice());
|
|
|
+ Glide.with(SheepApp.mContext)
|
|
|
+ .load(mTask.getTask().getIcon())
|
|
|
+ .placeholder(R.drawable.icon)
|
|
|
+ .dontAnimate()
|
|
|
+ .into(mImgIcon);
|
|
|
+ mTxtTitle.setText(mTask.getTask().getTitle());
|
|
|
+ mWebText.loadUrl(mTask.getTask().getGuide());
|
|
|
+ mTvCount.setText(Html.fromHtml(HTML_FORMAT.replace("当前数量", mTask.getSurplusCount() + "")
|
|
|
+ .replace("总数", mTask.getTotalCouont() + "")));
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, mTask.getTask().getPkg())) {
|
|
|
+ mBtnTaskItem.setText("开始游戏");
|
|
|
+ } else {
|
|
|
+ mBtnTaskItem.setText("下载游戏");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(SheepApp.mContext));
|
|
|
+ NetManager.get(Url.USER_PULL_TASK, map, SheepApp.mContext, new SheepCallback<TaskPublish>(GameDetailActivity.this) {
|
|
|
+ @Override
|
|
|
+ public void success(final TaskPublish taskPublish) {
|
|
|
+ if (taskPublish != null) {
|
|
|
+ int thisId = mTask.getTask().getId();
|
|
|
+ int pullId = taskPublish.getTask().getId();
|
|
|
+ if (thisId == pullId) {
|
|
|
+ mLlInfos.addView(getStep("领取任务", "已完成", 0));
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, mTask.getTask().getPkg())) {
|
|
|
+ mLlInfos.addView(getStep("下载游戏", "已完成", 0));
|
|
|
+ mLlInfos.addView(getStep("完成任务", "进行中", 1));
|
|
|
+ } else {
|
|
|
+ mLlInfos.addView(getStep("下载游戏", "待完成", 2));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mLlInfos.addView(getStep("领取任务", "待完成", 2));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mLlInfos.addView(getStep("领取任务", "待完成", 2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void otherCode(int code, String string) {
|
|
|
+ mLlInfos.addView(getStep("领取任务", "待完成", 2));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private View getStep(String step, String state, int color) {
|
|
|
+ View view = View.inflate(this, R.layout.task_step_info, null);
|
|
|
+ ImageView img = view.findViewById(R.id.img_tab);
|
|
|
+ TextView tvStep = view.findViewById(R.id.tv_step);
|
|
|
+ TextView tvStatus = view.findViewById(R.id.tv_status);
|
|
|
+ if (color == 0) {
|
|
|
+ img.setImageResource(R.drawable.garden_green);
|
|
|
+ tvStep.setTextColor(getResources().getColor(R.color.green));
|
|
|
+ tvStatus.setTextColor(getResources().getColor(R.color.green));
|
|
|
+ } else if (color == 1) {
|
|
|
+ img.setImageResource(R.drawable.garden_yellow);
|
|
|
+ tvStep.setTextColor(getResources().getColor(R.color.yellow_text_light));
|
|
|
+ tvStatus.setTextColor(getResources().getColor(R.color.yellow_text_light));
|
|
|
+ } else {
|
|
|
+ img.setImageResource(R.drawable.garden_gray);
|
|
|
+ tvStep.setTextColor(getResources().getColor(R.color.black_text_gray));
|
|
|
+ tvStatus.setTextColor(getResources().getColor(R.color.black_text_gray));
|
|
|
+ }
|
|
|
|
|
|
+ tvStep.setText(step);
|
|
|
+ tvStatus.setText(state);
|
|
|
+ return view;
|
|
|
}
|
|
|
}
|