@@ -12,6 +12,7 @@ import com.android.views.swipebacklayout.SwipeBackLayout; |
||
12 | 12 |
import com.android.views.swipebacklayout.Utils; |
13 | 13 |
|
14 | 14 |
import ai.pai.lensman.R; |
15 |
+import butterknife.Unbinder; |
|
15 | 16 |
|
16 | 17 |
/** |
17 | 18 |
* Created by chengzhenyu on 2015/12/2. |
@@ -22,6 +23,8 @@ public class BaseActivity extends AppCompatActivity implements SwipeBackActivity |
||
22 | 23 |
|
23 | 24 |
private SwipeBackActivityHelper mHelper; |
24 | 25 |
|
26 |
+ protected Unbinder unbinder; |
|
27 |
+ |
|
25 | 28 |
@Override |
26 | 29 |
protected void onCreate(Bundle savedInstanceState) { |
27 | 30 |
super.onCreate(savedInstanceState); |
@@ -40,6 +43,14 @@ public class BaseActivity extends AppCompatActivity implements SwipeBackActivity |
||
40 | 43 |
} |
41 | 44 |
|
42 | 45 |
@Override |
46 |
+ protected void onDestroy() { |
|
47 |
+ super.onDestroy(); |
|
48 |
+ if(unbinder!=null){ |
|
49 |
+ unbinder.unbind(); |
|
50 |
+ } |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ @Override |
|
43 | 54 |
public View findViewById(int id) { |
44 | 55 |
View v = super.findViewById(id); |
45 | 56 |
if (v == null && mHelper != null) |
@@ -17,7 +17,7 @@ public class BriefsActivity extends BaseActivity{ |
||
17 | 17 |
super.onCreate(savedInstanceState); |
18 | 18 |
setContentView(R.layout.activity_briefs); |
19 | 19 |
|
20 |
- ButterKnife.bind(this); |
|
20 |
+ unbinder = ButterKnife.bind(this); |
|
21 | 21 |
} |
22 | 22 |
|
23 | 23 |
@OnClick(R.id.title_bar_back_layout) |
@@ -99,7 +99,7 @@ public class QRCaptureActivity extends BaseActivity implements SurfaceHolder.Cal |
||
99 | 99 |
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
100 | 100 |
setContentView(R.layout.activity_qrcapture); |
101 | 101 |
|
102 |
- ButterKnife.bind(this); |
|
102 |
+ unbinder = ButterKnife.bind(this); |
|
103 | 103 |
|
104 | 104 |
SystemUtils.setImmerseLayout(this,findViewById(R.id.title_layout)); |
105 | 105 |
TextView title =ButterKnife.findById (this,R.id.title_bar_middle_txt); |
@@ -2,6 +2,7 @@ package ai.pai.lensman.service; |
||
2 | 2 |
|
3 | 3 |
import android.app.Service; |
4 | 4 |
import android.content.Intent; |
5 |
+import android.os.Binder; |
|
5 | 6 |
import android.os.IBinder; |
6 | 7 |
|
7 | 8 |
import com.android.common.executors.ThreadExecutor; |
@@ -13,10 +14,11 @@ import ai.pai.lensman.db.DBService; |
||
13 | 14 |
public class UploadService extends Service implements UploadTask.OnPhotoUploadListener{ |
14 | 15 |
|
15 | 16 |
private PhotoBean currentPhoto; |
17 |
+ private PhotoUploadListener listener; |
|
16 | 18 |
|
17 | 19 |
@Override |
18 | 20 |
public IBinder onBind(Intent intent) { |
19 |
- return null; |
|
21 |
+ return new MyBinder(); |
|
20 | 22 |
} |
21 | 23 |
|
22 | 24 |
@Override |
@@ -44,6 +46,9 @@ public class UploadService extends Service implements UploadTask.OnPhotoUploadLi |
||
44 | 46 |
if(bean.equals(currentPhoto)){ |
45 | 47 |
currentPhoto.isUploaded = true; |
46 | 48 |
DBService.getInstance().updatePhotoBean(currentPhoto); |
49 |
+ if(listener!=null){ |
|
50 |
+ listener.onPhotoUploaded(currentPhoto); |
|
51 |
+ } |
|
47 | 52 |
currentPhoto = null; |
48 | 53 |
} |
49 | 54 |
startUpload(); |
@@ -56,4 +61,21 @@ public class UploadService extends Service implements UploadTask.OnPhotoUploadLi |
||
56 | 61 |
} |
57 | 62 |
startUpload(); |
58 | 63 |
} |
64 |
+ |
|
65 |
+ public void setPhotoUploadListener(PhotoUploadListener listener){ |
|
66 |
+ this.listener = listener; |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ public interface PhotoUploadListener{ |
|
70 |
+ void onPhotoUploaded(PhotoBean bean); |
|
71 |
+ } |
|
72 |
+ |
|
73 |
+ public class MyBinder extends Binder { |
|
74 |
+ |
|
75 |
+ public UploadService getService(){ |
|
76 |
+ return UploadService.this; |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ } |
|
80 |
+ |
|
59 | 81 |
} |
@@ -61,7 +61,7 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
61 | 61 |
protected void onCreate(Bundle savedInstanceState) { |
62 | 62 |
super.onCreate(savedInstanceState); |
63 | 63 |
setContentView(R.layout.activity_session); |
64 |
- ButterKnife.bind(this); |
|
64 |
+ unbinder = ButterKnife.bind(this); |
|
65 | 65 |
sessionBean =(SessionBean)getIntent().getSerializableExtra("session"); |
66 | 66 |
presenter = new SessionPresenter(sessionBean,this); |
67 | 67 |
|
@@ -20,7 +20,7 @@ public class SettingsActivity extends BaseActivity { |
||
20 | 20 |
super.onCreate(savedInstanceState); |
21 | 21 |
setContentView(R.layout.activity_settings); |
22 | 22 |
|
23 |
- ButterKnife.bind(this); |
|
23 |
+ unbinder = ButterKnife.bind(this); |
|
24 | 24 |
} |
25 | 25 |
|
26 | 26 |
@OnClick(R.id.title_bar_back_layout) |
@@ -14,7 +14,6 @@ import ai.pai.lensman.R; |
||
14 | 14 |
import ai.pai.lensman.base.BaseActivity; |
15 | 15 |
import ai.pai.lensman.bean.SessionBean; |
16 | 16 |
import ai.pai.lensman.briefs.BriefsActivity; |
17 |
-import ai.pai.lensman.db.Preferences; |
|
18 | 17 |
import ai.pai.lensman.session.SessionActivity; |
19 | 18 |
import butterknife.BindView; |
20 | 19 |
import butterknife.ButterKnife; |
@@ -34,9 +33,9 @@ public class UploadActivity extends BaseActivity implements UploadContract.View |
||
34 | 33 |
protected void onCreate(Bundle savedInstanceState) { |
35 | 34 |
super.onCreate(savedInstanceState); |
36 | 35 |
setContentView(R.layout.activity_upload); |
37 |
- ButterKnife.bind(this); |
|
36 |
+ unbinder = ButterKnife.bind(this); |
|
38 | 37 |
|
39 |
- presenter = new UploadPresenter(this,Preferences.getInstance().getLensManId()); |
|
38 |
+ presenter = new UploadPresenter(this); |
|
40 | 39 |
adapter = new SessionRecyclerAdapter(this); |
41 | 40 |
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this,2,LinearLayoutManager.VERTICAL,false); |
42 | 41 |
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 |
} |