|
|
@@ -1,49 +1,32 @@
|
|
|
package com.sheep.jiuyan.samllsheep.page;
|
|
|
|
|
|
import android.Manifest;
|
|
|
-import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
|
-import android.graphics.Point;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
-import android.support.v7.app.AlertDialog;
|
|
|
-import android.support.v7.widget.LinearLayoutManager;
|
|
|
-import android.text.TextUtils;
|
|
|
+import android.support.v4.view.ViewPager;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.ProgressBar;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
-import com.jcodecraeer.xrecyclerview.XRecyclerView;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
|
import com.sheep.jiuyan.samllsheep.floatwindow.FloatWindow;
|
|
|
-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.adapter.TaskAdapter;
|
|
|
-import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
|
|
|
-import com.sheep.jiuyan.samllsheep.page.entry.User;
|
|
|
-import com.sheep.jiuyan.samllsheep.page.entry.WXTask;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.DeviceInfo;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.adapter.AdpMainPageViewPager;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.fragment.FgtMainPageOffline;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.fragment.FgtMainPageTask;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.view.RappTabLayout;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.PremissUtils;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import de.hdodenhof.circleimageview.CircleImageView;
|
|
|
-
|
|
|
|
|
|
/*
|
|
|
* author:kemllor
|
|
|
@@ -52,48 +35,18 @@ import de.hdodenhof.circleimageview.CircleImageView;
|
|
|
* date:2017-12-15
|
|
|
* file: MainActivity.class
|
|
|
*/
|
|
|
-public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
-
|
|
|
- private XRecyclerView mRecyclerView;
|
|
|
- private TaskAdapter mAdapter;
|
|
|
- private TextView mTvWithdraw;
|
|
|
- private TextView mTitle;
|
|
|
- private TextView mMoney;
|
|
|
- private TextView mToday;
|
|
|
- private ImageView mDown;
|
|
|
- private AlertDialog mDialog;
|
|
|
- private TaskPublish mClickItem;
|
|
|
- private ImageView mImgIcon;
|
|
|
- private CircleImageView mImgUser;
|
|
|
- private TextView mTvTitle;
|
|
|
- private TextView mTvTime;
|
|
|
- private TextView mTvCount;
|
|
|
- private TextView mTvMoney;
|
|
|
- private TextView mTvBouns;
|
|
|
- private TextView mTvGuide;
|
|
|
- private LinearLayout mTlDoing;
|
|
|
-
|
|
|
-
|
|
|
- private LinearLayout mLlNewTask;
|
|
|
-
|
|
|
- private RelativeLayout mll_progress;
|
|
|
-
|
|
|
-
|
|
|
- private ProgressBar mMp1;
|
|
|
+public class MainActivity extends BaseActivity {
|
|
|
|
|
|
- private WXTask mWXTask;
|
|
|
- private TextView mNewTaskTitle;
|
|
|
- private TextView mTvNewTaskDesc;
|
|
|
- private TextView mTvNewTaskMoney;
|
|
|
- private TextView mTvNewTaskBouns;
|
|
|
private final int INTENT_GET_PERMISSION = 1;
|
|
|
+ private RappTabLayout mRappTabLayout;
|
|
|
+ private ViewPager mViewPager;
|
|
|
+ private AdpMainPageViewPager mAdpMainPageViewPager;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
Intent intent = new Intent(this, FloatWindow.class);
|
|
|
startActivity(intent);
|
|
|
-
|
|
|
getSA();
|
|
|
}
|
|
|
|
|
|
@@ -114,10 +67,6 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
sa.add(Manifest.permission.READ_PHONE_STATE);
|
|
|
}
|
|
|
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW)
|
|
|
- != PackageManager.PERMISSION_GRANTED) {
|
|
|
- sa.add(Manifest.permission.READ_PHONE_STATE);
|
|
|
- }
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
sa.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
@@ -139,7 +88,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
if (!isOk) {
|
|
|
- Toast.makeText(MainActivity.this, "权限获取失败,部分功能可能无法正常工作。", Toast.LENGTH_SHORT).show();
|
|
|
+ G.showToast("权限获取失败,部分功能可能无法正常工作。");
|
|
|
}
|
|
|
}
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
@@ -153,233 +102,43 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
- mTvWithdraw.setOnClickListener(this);
|
|
|
- mDown.setOnClickListener(this);
|
|
|
- mImgUser.setOnClickListener(this);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
- requestNewPeopleTask();
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
- NetManager.get(Url.PUBLISH_TASKS, map, getApplicationContext(), new SheepCallback<List<TaskPublish>>(this) {
|
|
|
- @Override
|
|
|
- public void success(List<TaskPublish> tasks) {
|
|
|
- if (tasks != null && tasks.size() > 0) {
|
|
|
- mAdapter.setData(tasks);
|
|
|
- mAdapter.notifyDataSetChanged();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- NetManager.get(Url.USER_INFO, map, getApplicationContext(), new SheepCallback<User>(this) {
|
|
|
- @Override
|
|
|
- public void success(User user) {
|
|
|
- if (user != null) {
|
|
|
- mMoney.setText(user.getBalance());
|
|
|
- if (!MainActivity.this.isDestroyed())
|
|
|
- Glide.with(MainActivity.this)
|
|
|
- .load(user.getIcon())
|
|
|
- .placeholder(R.drawable.icon)
|
|
|
- .dontAnimate()
|
|
|
- .into(mImgUser);
|
|
|
- mToday.setText(String.format("今日收入:%s", user.getToday()));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- NetManager.get(Url.USER_PULL_TASK, map, getApplicationContext(), new SheepCallback<TaskPublish>(this) {
|
|
|
- @Override
|
|
|
- public void success(final TaskPublish taskPublish) {
|
|
|
- if (taskPublish != null) {
|
|
|
- mTlDoing.setVisibility(View.VISIBLE);
|
|
|
- if (!MainActivity.this.isDestroyed())
|
|
|
- Glide.with(MainActivity.this)
|
|
|
- .load(taskPublish.getTask().getIcon())
|
|
|
- .placeholder(R.drawable.icon)
|
|
|
- .dontAnimate()
|
|
|
- .into(mImgIcon);
|
|
|
- mTvTitle.setText(taskPublish.getTask().getTitle());
|
|
|
- mTvTime.setText("截止日期:" + taskPublish.getOverTime());
|
|
|
- mTvCount.setText(taskPublish.getSurplusCount() + "/" + taskPublish.getTotalCouont());
|
|
|
- mTvMoney.setText(taskPublish.getTask().getPrice());
|
|
|
- if (!TextUtils.isEmpty(taskPublish.getTask().getPkg())) {
|
|
|
- mTlDoing.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- PackageUtil.startApp(SheepApp.mContext, taskPublish.getTask().getPkg());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- mTvBouns.setText(taskPublish.getTask().getBonus());
|
|
|
- mTvGuide.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- Intent intent = new Intent(MainActivity.this, WebActivity.class);
|
|
|
- intent.putExtra("url", taskPublish.getTask().getGuide());
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- mTlDoing.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void otherCode(int code, String string) {
|
|
|
- mTlDoing.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- });
|
|
|
+ ((TextView) findViewById(R.id.txt_main_activity_money))
|
|
|
+ .setText(G.mUser.getBalance());
|
|
|
+ ((TextView) findViewById(R.id.txt_main_activity_nick))
|
|
|
+ .setText(G.mUser.getNickName());
|
|
|
+ Glide.with(this)
|
|
|
+ .load(G.mUser.getIcon())
|
|
|
+ .placeholder(R.drawable.icon)
|
|
|
+ .dontAnimate()
|
|
|
+ .into((ImageView) findViewById(R.id.img_user));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
- findviews();
|
|
|
- Point deviceSize = DeviceInfo.getDeviceSize(this);
|
|
|
- View head = View.inflate(this, R.layout.task_head, null);
|
|
|
- findViewHead(head);
|
|
|
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(deviceSize.x, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
- head.setLayoutParams(params);
|
|
|
- mRecyclerView.addHeaderView(head);
|
|
|
-
|
|
|
- LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
|
|
- layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
- mRecyclerView.setLayoutManager(layoutManager);
|
|
|
- mAdapter = new TaskAdapter(new ArrayList<TaskPublish>(), MainActivity.this);
|
|
|
- mAdapter.setClickCallBack(new TaskAdapter.ItemClickCallBack<TaskPublish>() {
|
|
|
- @Override
|
|
|
- public void onItemClick(TaskPublish pos) {
|
|
|
- mClickItem = pos;
|
|
|
- checkUserTask();
|
|
|
- }
|
|
|
- });
|
|
|
- mRecyclerView.setAdapter(mAdapter);
|
|
|
- mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
|
|
|
- @Override
|
|
|
- public void onRefresh() {
|
|
|
- initData();
|
|
|
- mRecyclerView.refreshComplete();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLoadMore() {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- mRecyclerView.setLoadingMoreEnabled(false);
|
|
|
- }
|
|
|
-
|
|
|
- private void checkUserTask() {
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
- NetManager.get(Url.USER_CHECK_REGISTER, map, getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
- @Override
|
|
|
- public void success(String ok) {
|
|
|
- if (TextUtils.equals(ok, "ok")) {
|
|
|
- showDialog("是否接受任务?");
|
|
|
- } else {
|
|
|
- showDialog("你有任务正在进行,是否取消,接受新任务?");
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void showDialog(String msg) {
|
|
|
- if (mDialog == null) {
|
|
|
- mDialog = new AlertDialog.Builder(MainActivity.this)
|
|
|
- .setMessage(msg)
|
|
|
- .setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- mDialog.dismiss();
|
|
|
- }
|
|
|
- }).setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- registerTask();
|
|
|
- }
|
|
|
- }).create();
|
|
|
- mDialog.show();
|
|
|
- } else {
|
|
|
- mDialog.setMessage(msg);
|
|
|
- mDialog.show();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //获取任务
|
|
|
- private void registerTask() {
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
- map.put("task_id", mClickItem.getId() + "");
|
|
|
- NetManager.get(Url.USER_REGISTER_TASK, map, getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
- @Override
|
|
|
- public void success(String o) {
|
|
|
- initData();
|
|
|
- String pkg = mClickItem.getTask().getPkg();
|
|
|
- if (!TextUtils.isEmpty(pkg))
|
|
|
- if (PackageUtil.isAppInstalled(getApplicationContext(), pkg)) {
|
|
|
- PackageUtil.startApp(getApplicationContext(), pkg);
|
|
|
- } else {
|
|
|
- Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
|
|
|
- intent.putExtra("task", mClickItem.getTask());
|
|
|
- startActivity(intent);
|
|
|
+ mRappTabLayout = (RappTabLayout) findViewById(R.id.tab_main_activity);
|
|
|
+ mViewPager = (ViewPager) findViewById(R.id.viewpager_main_activity);
|
|
|
+
|
|
|
+ mAdpMainPageViewPager = new AdpMainPageViewPager(getSupportFragmentManager());
|
|
|
+ mAdpMainPageViewPager.add(new FgtMainPageTask());
|
|
|
+ mAdpMainPageViewPager.add(new FgtMainPageOffline());
|
|
|
+ mViewPager.setAdapter(mAdpMainPageViewPager);
|
|
|
+ mRappTabLayout.setLine(G.getRealPix(30), G.getRealPix(4))
|
|
|
+ .setLineMargin(0, G.getRealPix(2), 0, G.getRealPix(4))
|
|
|
+ .setLineColor(getResources().getColor(R.color.black_text_deep))
|
|
|
+ .setupWithViewPager(mViewPager, R.layout.tab_ripple);
|
|
|
+
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setTitleFinish(this)
|
|
|
+ .setRightImgBotton(this, R.drawable.set, new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ G.showToast("点设置");
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void findViewHead(View head) {
|
|
|
- mTvWithdraw = (TextView) head.findViewById(R.id.tv_withdraw);
|
|
|
- mTitle = (TextView) head.findViewById(R.id.title);
|
|
|
- mMoney = (TextView) head.findViewById(R.id.money);
|
|
|
- mToday = (TextView) head.findViewById(R.id.today);
|
|
|
- mDown = head.findViewById(R.id.img_down);
|
|
|
-
|
|
|
- mImgIcon = (ImageView) head.findViewById(R.id.img_icon);
|
|
|
- mTvTitle = (TextView) head.findViewById(R.id.txt_baseactivity_title);
|
|
|
- mTvTime = (TextView) head.findViewById(R.id.tv_time);
|
|
|
- mTvCount = (TextView) head.findViewById(R.id.tv_count);
|
|
|
- mTvMoney = (TextView) head.findViewById(R.id.tv_money);
|
|
|
- mTvBouns = (TextView) head.findViewById(R.id.tv_bouns);
|
|
|
- mTvGuide = (TextView) head.findViewById(R.id.tv_guide);
|
|
|
- mTlDoing = (LinearLayout) head.findViewById(R.id.ll_doing);
|
|
|
- mImgUser = head.findViewById(R.id.img_user);
|
|
|
- mMp1 = (ProgressBar) head.findViewById(R.id.pb_commit);
|
|
|
- mNewTaskTitle = head.findViewById(R.id.tv_new_title);
|
|
|
- mTvNewTaskDesc = head.findViewById(R.id.tv_new_desc);
|
|
|
- mTvNewTaskMoney = head.findViewById(R.id.tv_new_money);
|
|
|
- mTvNewTaskBouns = head.findViewById(R.id.tv_new_bouns);
|
|
|
- mLlNewTask = (LinearLayout) head.findViewById(R.id.ll_new_task);
|
|
|
- mll_progress = head.findViewById(R.id.ll_progress);
|
|
|
- mll_progress.setOnClickListener(this);
|
|
|
- }
|
|
|
-
|
|
|
- private void requestNewPeopleTask() {
|
|
|
- final HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
- NetManager.get(Url.WXTASK, map, this, new SheepCallback<WXTask>(this) {
|
|
|
- @Override
|
|
|
- public void success(WXTask o) {
|
|
|
- // if(mMp1)
|
|
|
- mWXTask = o;
|
|
|
- mLlNewTask.setVisibility(View.VISIBLE);
|
|
|
- mMp1.setProgress((int) (((float) mWXTask.getCommitCount()) / 4 * 100));
|
|
|
- mNewTaskTitle.setText(mWXTask.getTitle());
|
|
|
- mTvNewTaskBouns.setText(mWXTask.getBonus());
|
|
|
- mTvNewTaskDesc.setText(mWXTask.getTaskDesc());
|
|
|
- mTvNewTaskMoney.setText(mWXTask.getPrice());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void otherCode(int code, String string) {
|
|
|
- mLlNewTask.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void findviews() {
|
|
|
- mRecyclerView = (XRecyclerView) findViewById(R.id.tasks);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -403,23 +162,4 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
EventBus.getDefault().post(floatMsg);*/
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- Intent intent;
|
|
|
- int i = v.getId();
|
|
|
- if (i == R.id.tv_withdraw) {
|
|
|
- intent = new Intent(MainActivity.this, WithdrawActivity.class);
|
|
|
- startActivity(intent);
|
|
|
- } else if (i == R.id.img_down) {
|
|
|
- intent = new Intent(MainActivity.this, DownloadActivity.class);
|
|
|
- startActivity(intent);
|
|
|
- } else if (i == R.id.img_user) {
|
|
|
- intent = new Intent(MainActivity.this, UserCenterActivity.class);
|
|
|
- startActivity(intent);
|
|
|
- } else if (i == R.id.ll_progress) {
|
|
|
- intent = new Intent(MainActivity.this, InputWXAccountActivity.class);
|
|
|
- intent.putExtra("count", mWXTask.getCommitCount());
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
- }
|
|
|
}
|