"> 8
import com.android.common.executors.ThreadExecutor;
-import com.android.common.utils.LogHelper;
-import ai.pai.lensman.bean.PhotoBean;
-import ai.pai.lensman.db.DBService;
+import java.util.HashMap;
-public class OrderDealService extends Service implements UploadTask.OnPhotoUploadListener{
+import ai.pai.lensman.bean.OrderBean;
+import ai.pai.lensman.db.Preferences;
+import ai.pai.lensman.utils.HttpPostTask;
- private PhotoBean currentPhoto;
- private PhotoUploadListener listener;
+public class OrderDealService extends Service{
@Override
public IBinder onBind(Intent intent) {
- return new MyBinder();
+ return new OrderServiceBinder();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- if(intent!=null && intent.getSerializableExtra("photo")!=null){
- PhotoBean bean = (PhotoBean) intent.getSerializableExtra("photo");
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN;
- DBService.getInstance().updatePhotoBean(bean);
- }
- startUpload();
- return super.onStartCommand(intent, flags, startId);
+ startQuery();
+ return START_STICKY;
}
- private synchronized void startUpload(){
- if(currentPhoto!=null){
- LogHelper.d("czy","当前有图片正在上传"+currentPhoto);
- return;
- }
- currentPhoto = DBService.getInstance().getNextUploadPhoto();
- if(currentPhoto==null){
- LogHelper.d("czy","本地图片已全部上传");
- return;
- }
- LogHelper.d("czy","即将上传的照片是"+currentPhoto);
- new UploadTask(currentPhoto,this).executeOnExecutor(ThreadExecutor.getInstance().getExecutor());
- }
+ private void startQuery(){
+ HashMap<String,String> params = new HashMap<>();
+ params.put("user_id", Preferences.getInstance().getLensManId());
+ new HttpPostTask(params){
+ OrderBean orderBean;
+ @Override
+ protected boolean parseResponse(String response) {
+ orderBean = new OrderBean();
- @Override
- public void onPhotoUploadSucceed(PhotoBean bean) {
- if(bean.equals(currentPhoto)){
- currentPhoto.uploadStatus = PhotoBean.UploadStatus.STATUS_SUCCESS;
- DBService.getInstance().updatePhotoBean(currentPhoto);
- if(listener!=null){
- listener.onPhotoUploaded(currentPhoto);
+ return super.parseResponse(response);
}
- currentPhoto = null;
- }
- startUpload();
- }
- @Override
- public void onPhotoUploadFail(PhotoBean bean) {
- if(bean.equals(currentPhoto)){
- currentPhoto.uploadStatus = PhotoBean.UploadStatus.STATUS_ERROR;
- DBService.getInstance().updatePhotoBean(currentPhoto);
- if(listener!=null){
- listener.onPhotoUploadError(currentPhoto);
+ @Override
+ protected void onPostSuccess() {
+ super.onPostSuccess();
+ onNewOrderArrived(orderBean);
}
- currentPhoto = null;
- }
- startUpload();
- }
- public void setPhotoUploadListener(PhotoUploadListener listener){
- this.listener = listener;
+ @Override
+ protected void onPostFail() {
+ super.onPostFail();
+ }
+ }.executeOnExecutor(ThreadExecutor.getInstance().getExecutor());
+
}
- public interface PhotoUploadListener{
- void onPhotoUploaded(PhotoBean bean);
- void onPhotoUploadError(PhotoBean bean);
+ private void onNewOrderArrived(OrderBean bean){
+
}
- public class MyBinder extends Binder {
+ public class OrderServiceBinder extends Binder {
public OrderDealService getService(){
return OrderDealService.this;
@@ -37,6 +37,7 @@ public class UrlContainer {
|
||
| 37 | 37 |
|
| 38 | 38 |
public static final String BRIEFS_URL = HOST_URL+"l/brief"; |
| 39 | 39 |
|
| 40 |
+ public static final String QUERY_ORDER_URL = HOST_URL+"l/query"; |
|
| 40 | 41 |
|
| 41 | 42 |
|
| 42 | 43 |
} |