on.SessionActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -34,9 +33,9 @@ public class UploadActivity extends BaseActivity implements UploadContract.View
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
- ButterKnife.bind(this);
+ unbinder = ButterKnife.bind(this);
- presenter = new UploadPresenter(this,Preferences.getInstance().getLensManId());
+ presenter = new UploadPresenter(this);
adapter = new SessionRecyclerAdapter(this);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this,2,LinearLayoutManager.VERTICAL,false);
sessionsRecyclerView.setLayoutManager(layoutManager);
@@ -1,6 +1,10 @@ |
||
1 | 1 |
package ai.pai.lensman.upload; |
2 | 2 |
|
3 |
+import android.content.ComponentName; |
|
4 |
+import android.content.Context; |
|
3 | 5 |
import android.content.Intent; |
6 |
+import android.content.ServiceConnection; |
|
7 |
+import android.os.IBinder; |
|
4 | 8 |
|
5 | 9 |
import java.text.SimpleDateFormat; |
6 | 10 |
import java.util.ArrayList; |
@@ -8,11 +12,13 @@ import java.util.Date; |
||
8 | 12 |
|
9 | 13 |
import ai.pai.lensman.App; |
10 | 14 |
import ai.pai.lensman.base.BaseInteractor; |
15 |
+import ai.pai.lensman.bean.PhotoBean; |
|
11 | 16 |
import ai.pai.lensman.bean.SessionBean; |
12 | 17 |
import ai.pai.lensman.db.DBService; |
18 |
+import ai.pai.lensman.db.Preferences; |
|
13 | 19 |
import ai.pai.lensman.service.UploadService; |
14 | 20 |
|
15 |
-public class UploadPresenter implements UploadContract.Presenter,BaseInteractor.InteractorListener<ArrayList<String>> { |
|
21 |
+public class UploadPresenter implements UploadContract.Presenter,BaseInteractor.InteractorListener<ArrayList<String>>,UploadService.PhotoUploadListener { |
|
16 | 22 |
|
17 | 23 |
private UploadContract.View uploadView; |
18 | 24 |
private ArrayList<SessionBean> sessionList; |
@@ -20,12 +26,25 @@ public class UploadPresenter implements UploadContract.Presenter,BaseInteractor. |
||
20 | 26 |
private int sessionSeq; |
21 | 27 |
private ArrayList<String> sessionIds; |
22 | 28 |
private FetchSessionIdsInteractor interactor; |
29 |
+ private ServiceConnection serviceConnection; |
|
23 | 30 |
|
24 |
- public UploadPresenter(UploadContract.View view,String lensmanId){ |
|
31 |
+ public UploadPresenter(UploadContract.View view){ |
|
25 | 32 |
this.uploadView = view; |
26 |
- this.lensmanId = lensmanId; |
|
33 |
+ this.lensmanId = Preferences.getInstance().getLensManId(); |
|
27 | 34 |
sessionIds = new ArrayList<>(); |
28 | 35 |
interactor = new FetchSessionIdsInteractor(lensmanId,100,this); |
36 |
+ serviceConnection = new ServiceConnection() { |
|
37 |
+ @Override |
|
38 |
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { |
|
39 |
+ UploadService.MyBinder binder = (UploadService.MyBinder)iBinder; |
|
40 |
+ ((UploadService.MyBinder) iBinder).getService().setPhotoUploadListener(UploadPresenter.this); |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ @Override |
|
44 |
+ public void onServiceDisconnected(ComponentName componentName) { |
|
45 |
+ |
|
46 |
+ } |
|
47 |
+ }; |
|
29 | 48 |
} |
30 | 49 |
|
31 | 50 |
|
@@ -49,11 +68,12 @@ public class UploadPresenter implements UploadContract.Presenter,BaseInteractor. |
||
49 | 68 |
sessionSeq = sessionList.size(); |
50 | 69 |
|
51 | 70 |
App.getAppContext().startService(new Intent(App.getAppContext(), UploadService.class)); |
71 |
+ App.getAppContext().bindService(new Intent(App.getAppContext(),UploadService.class),serviceConnection, Context.BIND_AUTO_CREATE); |
|
52 | 72 |
} |
53 | 73 |
|
54 | 74 |
@Override |
55 | 75 |
public void stop() { |
56 |
- |
|
76 |
+ App.getAppContext().unbindService(serviceConnection); |
|
57 | 77 |
} |
58 | 78 |
|
59 | 79 |
@Override |
@@ -83,7 +103,13 @@ public class UploadPresenter implements UploadContract.Presenter,BaseInteractor. |
||
83 | 103 |
|
84 | 104 |
@Override |
85 | 105 |
public void onInteractFail(String errorMsg) { |
86 |
-// interactor.startJob(); |
|
106 |
+ interactor.startJob(); |
|
87 | 107 |
} |
88 | 108 |
|
109 |
+ |
|
110 |
+ @Override |
|
111 |
+ public void onPhotoUploaded(PhotoBean bean) { |
|
112 |
+ |
|
113 |
+ uploadView.updateSessionUploadView(null); |
|
114 |
+ } |
|
89 | 115 |
} |