|
|
@@ -16,6 +16,7 @@ import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
@@ -34,6 +35,7 @@ import com.jiuyan.sheep_children.net.Url;
|
|
|
import com.jiuyan.sheep_children.page.adapter.TaskAdapter;
|
|
|
import com.jiuyan.sheep_children.page.entry.Task;
|
|
|
import com.jiuyan.sheep_children.page.entry.TaskPublish;
|
|
|
+import com.jiuyan.sheep_children.page.entry.User;
|
|
|
import com.jiuyan.sheep_children.utils.DeviceInfo;
|
|
|
import com.jiuyan.sheep_children.utils.GsonUtil;
|
|
|
import com.jiuyan.sheep_children.utils.PremissUtils;
|
|
|
@@ -47,6 +49,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
import okhttp3.Call;
|
|
|
@@ -58,6 +61,12 @@ 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 mHostry;
|
|
|
+ private TextView mToday;
|
|
|
+ private ImageView mDown;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -75,6 +84,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
mTvWithdraw.setOnClickListener(this);
|
|
|
+ mDown.setOnClickListener(this);
|
|
|
if (BuildConfig.DEBUG)
|
|
|
mTvWithdraw.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
|
@@ -90,12 +100,20 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
- NetManager.get(Url.PUBLISH_TASKS, null, getApplicationContext(), new SheepCallback<List<TaskPublish>>(this) {
|
|
|
+ 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) {
|
|
|
mAdapter.setData(tasks);
|
|
|
mAdapter.notifyDataSetChanged();
|
|
|
- mRecyclerView.refreshComplete();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ NetManager.get(Url.USER_INFO, map, getApplicationContext(), new SheepCallback<User>(this) {
|
|
|
+ @Override
|
|
|
+ public void success(User user) {
|
|
|
+ mMoney.setText(user.getMoney().getBalance());
|
|
|
+ mToday.setText(String.format("今日收入:%s", user.getMoney().getToday()));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -114,11 +132,11 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
mRecyclerView.setLayoutManager(layoutManager);
|
|
|
mAdapter = new TaskAdapter(new ArrayList<TaskPublish>(), MainActivity.this);
|
|
|
- mAdapter.setClickCallBack(new TaskAdapter.ItemClickCallBack<String>() {
|
|
|
+ mAdapter.setClickCallBack(new TaskAdapter.ItemClickCallBack<TaskPublish>() {
|
|
|
@Override
|
|
|
- public void onItemClick(String pos) {
|
|
|
+ public void onItemClick(TaskPublish pos) {
|
|
|
Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
|
|
|
- intent.putExtra("data", pos);
|
|
|
+ intent.putExtra("data", pos.getTask().getDownLoadUrl());
|
|
|
startActivity(intent);
|
|
|
}
|
|
|
});
|
|
|
@@ -127,6 +145,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
@Override
|
|
|
public void onRefresh() {
|
|
|
initData();
|
|
|
+ mRecyclerView.refreshComplete();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -151,6 +170,11 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
|
|
|
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);
|
|
|
+ mHostry = (TextView) head.findViewById(R.id.hostry);
|
|
|
+ mToday = (TextView) head.findViewById(R.id.today);
|
|
|
+ mDown = head.findViewById(R.id.img_down);
|
|
|
}
|
|
|
|
|
|
private void findviews() {
|
|
|
@@ -180,16 +204,23 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
+ Intent intent;
|
|
|
switch (v.getId()) {
|
|
|
case R.id.tv_withdraw:
|
|
|
- Intent intent;
|
|
|
if (SpUtils.isLogin(getApplicationContext())) {
|
|
|
intent = new Intent(MainActivity.this, UserCenterActivity.class);
|
|
|
} else {
|
|
|
intent = new Intent(MainActivity.this, LoginActivity.class);
|
|
|
}
|
|
|
startActivity(intent);
|
|
|
-
|
|
|
+ break;
|
|
|
+ case R.id.img_down:
|
|
|
+ if (SpUtils.isLogin(getApplicationContext())) {
|
|
|
+ intent = new Intent(MainActivity.this, UserCenterActivity.class);
|
|
|
+ } else {
|
|
|
+ intent = new Intent(MainActivity.this, DownloadActivity.class);
|
|
|
+ }
|
|
|
+ startActivity(intent);
|
|
|
break;
|
|
|
}
|
|
|
}
|