@@ -0,0 +1,9 @@ |
||
1 |
+package ai.pai.lensman.bean; |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * Created by chengzhenyu on 2016/8/24. |
|
5 |
+ */ |
|
6 |
+ |
|
7 |
+public class BriefsBean { |
|
8 |
+ |
|
9 |
+} |
@@ -3,21 +3,35 @@ package ai.pai.lensman.briefs; |
||
3 | 3 |
import android.content.Intent; |
4 | 4 |
import android.os.Bundle; |
5 | 5 |
import android.support.annotation.Nullable; |
6 |
+import android.widget.TextView; |
|
6 | 7 |
|
7 | 8 |
import ai.pai.lensman.R; |
8 | 9 |
import ai.pai.lensman.base.BaseActivity; |
10 |
+import ai.pai.lensman.bean.BriefsBean; |
|
9 | 11 |
import ai.pai.lensman.settings.SettingsActivity; |
12 |
+import butterknife.BindView; |
|
10 | 13 |
import butterknife.ButterKnife; |
11 | 14 |
import butterknife.OnClick; |
12 | 15 |
|
13 | 16 |
public class BriefsActivity extends BaseActivity implements BriefsContract.View{ |
14 | 17 |
|
18 |
+ @BindView(R.id.tv_upload_photo_num) TextView uploadPhotoNumText; |
|
19 |
+ @BindView(R.id.tv_today_capture_num) TextView captureNumText; |
|
20 |
+ @BindView(R.id.tv_average_money_amount) TextView averageMoneyText; |
|
21 |
+ @BindView(R.id.tv_today_incoming_account) TextView todayIncomingText; |
|
22 |
+ @BindView(R.id.tv_total_incoming_account) TextView totalIncomingText; |
|
23 |
+ @BindView(R.id.tv_today_capture_hours_account) TextView todayCaptureHoursText; |
|
24 |
+ |
|
25 |
+ private BriefsPresenter presenter; |
|
26 |
+ |
|
15 | 27 |
@Override |
16 | 28 |
protected void onCreate(@Nullable Bundle savedInstanceState) { |
17 | 29 |
super.onCreate(savedInstanceState); |
18 | 30 |
setContentView(R.layout.activity_briefs); |
19 |
- |
|
20 | 31 |
unbinder = ButterKnife.bind(this); |
32 |
+ |
|
33 |
+ presenter = new BriefsPresenter(this); |
|
34 |
+ presenter.start(); |
|
21 | 35 |
} |
22 | 36 |
|
23 | 37 |
@OnClick(R.id.title_bar_back_layout) |
@@ -30,4 +44,16 @@ public class BriefsActivity extends BaseActivity implements BriefsContract.View{ |
||
30 | 44 |
startActivity(new Intent(this, SettingsActivity.class)); |
31 | 45 |
} |
32 | 46 |
|
47 |
+ |
|
48 |
+ @Override |
|
49 |
+ protected void onDestroy() { |
|
50 |
+ super.onDestroy(); |
|
51 |
+ presenter.stop(); |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ @Override |
|
55 |
+ public void updateUserInfo(BriefsBean bean) { |
|
56 |
+ |
|
57 |
+ } |
|
58 |
+ |
|
33 | 59 |
} |
@@ -2,6 +2,7 @@ package ai.pai.lensman.briefs; |
||
2 | 2 |
|
3 | 3 |
import ai.pai.lensman.base.BasePresenter; |
4 | 4 |
import ai.pai.lensman.base.BaseView; |
5 |
+import ai.pai.lensman.bean.BriefsBean; |
|
5 | 6 |
|
6 | 7 |
/** |
7 | 8 |
* Created by chengzhenyu on 2016/8/22. |
@@ -9,7 +10,7 @@ import ai.pai.lensman.base.BaseView; |
||
9 | 10 |
public class BriefsContract { |
10 | 11 |
|
11 | 12 |
public interface View extends BaseView{ |
12 |
- |
|
13 |
+ void updateUserInfo(BriefsBean bean); |
|
13 | 14 |
} |
14 | 15 |
|
15 | 16 |
public interface Presenter extends BasePresenter{ |
@@ -0,0 +1,81 @@ |
||
1 |
+package ai.pai.lensman.briefs; |
|
2 |
+ |
|
3 |
+import android.os.AsyncTask; |
|
4 |
+ |
|
5 |
+import com.android.common.executors.ThreadExecutor; |
|
6 |
+ |
|
7 |
+import org.json.JSONObject; |
|
8 |
+ |
|
9 |
+import java.util.HashMap; |
|
10 |
+ |
|
11 |
+import ai.pai.lensman.base.BaseInteractor; |
|
12 |
+import ai.pai.lensman.bean.BriefsBean; |
|
13 |
+import ai.pai.lensman.db.Preferences; |
|
14 |
+import ai.pai.lensman.utils.HttpPostTask; |
|
15 |
+import ai.pai.lensman.utils.UrlContainer; |
|
16 |
+ |
|
17 |
+/** |
|
18 |
+ * Created by chengzhenyu on 2016/8/24. |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+public class BriefsInteractor implements BaseInteractor { |
|
22 |
+ |
|
23 |
+ private HttpPostTask fetchInfoTask; |
|
24 |
+ private InteractorListener<BriefsBean> listener; |
|
25 |
+ |
|
26 |
+ public BriefsInteractor(InteractorListener<BriefsBean> listener){ |
|
27 |
+ this.listener = listener; |
|
28 |
+ } |
|
29 |
+ |
|
30 |
+ @Override |
|
31 |
+ public void startJob() { |
|
32 |
+ HashMap<String,String> params = new HashMap<>(); |
|
33 |
+ params.put("user_id", Preferences.getInstance().getLensManId()); |
|
34 |
+ fetchInfoTask = new HttpPostTask(params){ |
|
35 |
+ |
|
36 |
+ String message; |
|
37 |
+ BriefsBean bean; |
|
38 |
+ |
|
39 |
+ @Override |
|
40 |
+ protected boolean parseResponse(String response) { |
|
41 |
+ try{ |
|
42 |
+ JSONObject json = new JSONObject(response); |
|
43 |
+ int status = json.getInt("status"); |
|
44 |
+ if(status == 200){ |
|
45 |
+ bean = new BriefsBean(); |
|
46 |
+ return true; |
|
47 |
+ }else{ |
|
48 |
+ message = json.getString("message"); |
|
49 |
+ } |
|
50 |
+ }catch (Exception e){ |
|
51 |
+ e.printStackTrace(); |
|
52 |
+ } |
|
53 |
+ return false; |
|
54 |
+ } |
|
55 |
+ |
|
56 |
+ @Override |
|
57 |
+ protected void onPostFail() { |
|
58 |
+ super.onPostFail(); |
|
59 |
+ listener.onInteractFail(message); |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ @Override |
|
63 |
+ protected void onPostSuccess() { |
|
64 |
+ super.onPostSuccess(); |
|
65 |
+ listener.onInteractSuccess(bean); |
|
66 |
+ } |
|
67 |
+ }; |
|
68 |
+ fetchInfoTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.SESSION_IDS_CREATE); |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ @Override |
|
72 |
+ public void cancelJob() { |
|
73 |
+ if(fetchInfoTask==null){ |
|
74 |
+ return; |
|
75 |
+ } |
|
76 |
+ if(fetchInfoTask.getStatus()== AsyncTask.Status.RUNNING){ |
|
77 |
+ fetchInfoTask.cancel(true); |
|
78 |
+ } |
|
79 |
+ fetchInfoTask = null; |
|
80 |
+ } |
|
81 |
+} |
@@ -1,18 +1,44 @@ |
||
1 | 1 |
package ai.pai.lensman.briefs; |
2 | 2 |
|
3 |
+import com.android.common.utils.NetworkUtil; |
|
4 |
+ |
|
5 |
+import ai.pai.lensman.App; |
|
6 |
+import ai.pai.lensman.base.BaseInteractor; |
|
7 |
+import ai.pai.lensman.bean.BriefsBean; |
|
8 |
+ |
|
3 | 9 |
/** |
4 | 10 |
* Created by chengzhenyu on 2016/8/22. |
5 | 11 |
*/ |
6 |
-public class BriefsPresenter implements BriefsContract.Presenter { |
|
12 |
+public class BriefsPresenter implements BriefsContract.Presenter,BaseInteractor.InteractorListener<BriefsBean> { |
|
13 |
+ |
|
14 |
+ private BriefsContract.View briefsView; |
|
15 |
+ private BriefsInteractor interactor; |
|
16 |
+ |
|
17 |
+ public BriefsPresenter(BriefsContract.View briefsView){ |
|
18 |
+ this.briefsView = briefsView; |
|
19 |
+ interactor = new BriefsInteractor(this); |
|
20 |
+ } |
|
7 | 21 |
|
8 | 22 |
@Override |
9 | 23 |
public void start() { |
10 |
- |
|
24 |
+ interactor.startJob(); |
|
11 | 25 |
} |
12 | 26 |
|
13 | 27 |
@Override |
14 | 28 |
public void stop() { |
29 |
+ interactor.cancelJob(); |
|
30 |
+ } |
|
15 | 31 |
|
32 |
+ @Override |
|
33 |
+ public void onInteractSuccess(BriefsBean bean) { |
|
34 |
+ briefsView.updateUserInfo(bean); |
|
35 |
+ } |
|
36 |
+ |
|
37 |
+ @Override |
|
38 |
+ public void onInteractFail(String errorMsg) { |
|
39 |
+ if(NetworkUtil.isWifiConnected(App.getAppContext())){ |
|
40 |
+ interactor.startJob(); |
|
41 |
+ } |
|
16 | 42 |
} |
17 | 43 |
|
18 | 44 |
} |