num-new">
@@ -32,10 +29,11 @@ public class PhotoRecyclerAdapter extends RecyclerView.Adapter<PhotoRecyclerAdap
|
|
32
|
29
|
private int width;
|
|
33
|
30
|
private Context context;
|
|
34
|
31
|
private LayoutInflater mInflater;
|
|
35
|
|
- private DisplayImageOptions options;
|
|
|
32
|
+ private DisplayImageOptions options;
|
|
36
|
33
|
private ArrayList<PhotoBean> photoList;
|
|
37
|
34
|
private int delay = 10;
|
|
38
|
|
- public PhotoRecyclerAdapter(Context context){
|
|
|
35
|
+
|
|
|
36
|
+ public PhotoRecyclerAdapter(Context context) {
|
|
39
|
37
|
this.context = context;
|
|
40
|
38
|
width = DeviceUtils.getScreenWidth(context);
|
|
41
|
39
|
mInflater = LayoutInflater.from(context);
|
|
|
|
@@ -43,108 +41,120 @@ public class PhotoRecyclerAdapter extends RecyclerView.Adapter<PhotoRecyclerAdap
|
|
43
|
41
|
delay = Preferences.getInstance().getUploadDelay();
|
|
44
|
42
|
}
|
|
45
|
43
|
|
|
46
|
|
- public PhotoBean getPhotoAt(int position){
|
|
47
|
|
- if(photoList==null|| photoList.size()<=position ||position<0){
|
|
|
44
|
+ public PhotoBean getPhotoAt(int position) {
|
|
|
45
|
+ if (photoList == null || photoList.size() <= position || position < 0) {
|
|
48
|
46
|
return null;
|
|
49
|
47
|
}
|
|
50
|
48
|
return photoList.get(position);
|
|
51
|
49
|
}
|
|
52
|
50
|
|
|
53
|
|
- public synchronized void addPhotoBean(PhotoBean item){
|
|
54
|
|
- if(photoList==null){
|
|
|
51
|
+ public synchronized void addPhotoBean(PhotoBean item) {
|
|
|
52
|
+ if (photoList == null) {
|
|
55
|
53
|
photoList = new ArrayList<>();
|
|
56
|
54
|
}
|
|
57
|
|
- if(!photoList.contains(item)){
|
|
58
|
|
- photoList.add(0,item);
|
|
|
55
|
+ if (!photoList.contains(item)) {
|
|
|
56
|
+ photoList.add(0, item);
|
|
59
|
57
|
notifyItemInserted(0);
|
|
60
|
|
- notifyItemRangeChanged(0,photoList.size());
|
|
|
58
|
+ notifyItemRangeChanged(0, photoList.size());
|
|
61
|
59
|
}
|
|
62
|
60
|
}
|
|
63
|
61
|
|
|
64
|
|
- public synchronized void addPreviousPhotos(ArrayList<PhotoBean> photos){
|
|
65
|
|
- if(photos==null||photos.size()==0){
|
|
|
62
|
+ public synchronized void addPreviousPhotos(ArrayList<PhotoBean> photos) {
|
|
|
63
|
+ if (photos == null || photos.size() == 0) {
|
|
66
|
64
|
return;
|
|
67
|
65
|
}
|
|
68
|
|
- if(photoList==null){
|
|
|
66
|
+ if (photoList == null) {
|
|
69
|
67
|
photoList = new ArrayList<>();
|
|
70
|
68
|
}
|
|
71
|
|
- if(photoList.size()==0){
|
|
|
69
|
+ if (photoList.size() == 0) {
|
|
72
|
70
|
photoList.addAll(photos);
|
|
73
|
71
|
notifyDataSetChanged();
|
|
74
|
72
|
}
|
|
75
|
73
|
}
|
|
76
|
74
|
|
|
77
|
|
- public synchronized void removePhotoAtIndex(int index){
|
|
78
|
|
- if(photoList==null || photoList.size()<=index){
|
|
|
75
|
+ public synchronized void removePhotoAtIndex(int index) {
|
|
|
76
|
+ if (photoList == null || photoList.size() <= index) {
|
|
79
|
77
|
return;
|
|
80
|
78
|
}
|
|
81
|
79
|
photoList.remove(index);
|
|
82
|
80
|
notifyItemRemoved(index);
|
|
83
|
|
- notifyItemRangeChanged(0,photoList.size());
|
|
|
81
|
+ notifyItemRangeChanged(0, photoList.size());
|
|
84
|
82
|
}
|
|
85
|
83
|
|
|
86
|
84
|
@Override
|
|
87
|
85
|
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
88
|
|
- return new MyViewHolder(mInflater.inflate(R.layout.photo_item,parent,false));
|
|
|
86
|
+ return new MyViewHolder(mInflater.inflate(R.layout.photo_item, parent, false));
|
|
89
|
87
|
}
|
|
90
|
88
|
|
|
91
|
89
|
@Override
|
|
92
|
90
|
public void onBindViewHolder(final MyViewHolder holder, final int position) {
|
|
93
|
|
- if(photoList==null){
|
|
|
91
|
+ if (photoList == null) {
|
|
94
|
92
|
return;
|
|
95
|
93
|
}
|
|
96
|
94
|
final PhotoBean item = photoList.get(position);
|
|
97
|
95
|
ImageLoaderUtils.displayLocalImage(item.photoPath, holder.photo, options);
|
|
98
|
|
- int height = width*10/16;
|
|
99
|
|
- ViewGroup.LayoutParams lp=holder.photo.getLayoutParams();
|
|
|
96
|
+ int height = width * 10 / 16;
|
|
|
97
|
+ ViewGroup.LayoutParams lp = holder.photo.getLayoutParams();
|
|
100
|
98
|
lp.width = width;
|
|
101
|
99
|
lp.height = height;
|
|
102
|
100
|
holder.photo.setLayoutParams(lp);
|
|
103
|
|
- if(item.uploadStatus == PhotoBean.UploadStatus.STATUS_ERROR){
|
|
|
101
|
+ if (item.uploadStatus == PhotoBean.UploadStatus.STATUS_ERROR) {
|
|
104
|
102
|
holder.errorLayout.setVisibility(View.VISIBLE);
|
|
105
|
|
- holder.retryImg.setOnClickListener(new View.OnClickListener(){
|
|
|
103
|
+ holder.retryImg.setOnClickListener(new View.OnClickListener() {
|
|
106
|
104
|
@Override
|
|
107
|
105
|
public void onClick(View view) {
|
|
108
|
106
|
Intent intent = new Intent(App.getAppContext(), UploadService.class);
|
|
109
|
|
- intent.putExtra("photo",item);
|
|
|
107
|
+ intent.putExtra("photo", item);
|
|
110
|
108
|
App.getAppContext().startService(intent);
|
|
111
|
109
|
item.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN;
|
|
112
|
110
|
notifyItemChanged(position);
|
|
113
|
|
- Toast.makeText(context,R.string.add_to_upload_queue,Toast.LENGTH_SHORT).show();
|
|
|
111
|
+ Toast.makeText(context, R.string.add_to_upload_queue, Toast.LENGTH_SHORT).show();
|
|
114
|
112
|
}
|
|
115
|
113
|
});
|
|
116
|
|
- }else{
|
|
|
114
|
+ } else {
|
|
117
|
115
|
holder.errorLayout.setVisibility(View.GONE);
|
|
118
|
116
|
}
|
|
119
|
|
- long timeLeft = delay-(System.currentTimeMillis()-item.captureTime)/1000;
|
|
|
117
|
+ long timeLeft = delay - (System.currentTimeMillis() - item.captureTime) / 1000;
|
|
120
|
118
|
|
|
121
|
|
- if(timeLeft<0|| DBService.getInstance().isPhotoUploaded(item.photoId)){
|
|
|
119
|
+ if (timeLeft < 0) {
|
|
122
|
120
|
item.canDelete = false;
|
|
123
|
|
- holder.autoUploadHintText.setVisibility(View.GONE);
|
|
124
|
|
- }else{
|
|
|
121
|
+ if (item.uploadStatus == PhotoBean.UploadStatus.STATUS_ERROR) {
|
|
|
122
|
+ holder.uploadStatusText.setText(context.getString(R.string.upload_error));
|
|
|
123
|
+ } else if (item.uploadStatus == PhotoBean.UploadStatus.STATUS_SUCCESS) {
|
|
|
124
|
+ holder.uploadStatusText.setText(context.getString(R.string.upload_success));
|
|
|
125
|
+ } else if (item.uploadStatus == PhotoBean.UploadStatus.STATUS_NO_BEGIN) {
|
|
|
126
|
+ holder.uploadStatusText.setText(context.getString(R.string.upload_in_waiting));
|
|
|
127
|
+ } else if (item.uploadStatus == PhotoBean.UploadStatus.STATUS_UPLOADING) {
|
|
|
128
|
+ holder.uploadStatusText.setText(context.getString(R.string.upload_processing));
|
|
|
129
|
+ }
|
|
|
130
|
+ } else {
|
|
125
|
131
|
item.canDelete = true;
|
|
126
|
|
- holder.autoUploadHintText.setVisibility(View.VISIBLE);
|
|
127
|
|
- holder.autoUploadHintText.setText(context.getString(R.string.auto_upload_after_seconds,timeLeft));
|
|
|
132
|
+ holder.uploadStatusText.setText(context.getString(R.string.auto_upload_after_seconds, timeLeft));
|
|
128
|
133
|
}
|
|
129
|
134
|
}
|
|
130
|
135
|
|
|
131
|
136
|
@Override
|
|
132
|
137
|
public int getItemCount() {
|
|
133
|
|
- if(photoList==null){
|
|
|
138
|
+ if (photoList == null) {
|
|
134
|
139
|
return 0;
|
|
135
|
140
|
}
|
|
136
|
141
|
return photoList.size();
|
|
137
|
142
|
}
|
|
138
|
143
|
|
|
139
|
|
- class MyViewHolder extends RecyclerView.ViewHolder{
|
|
|
144
|
+ class MyViewHolder extends RecyclerView.ViewHolder {
|
|
|
145
|
+
|
|
|
146
|
+ @BindView(R.id.iv_session_photo_item)
|
|
|
147
|
+ ImageView photo;
|
|
|
148
|
+ @BindView(R.id.layout_upload_fail)
|
|
|
149
|
+ View errorLayout;
|
|
|
150
|
+ @BindView(R.id.iv_upload_retry)
|
|
|
151
|
+ ImageView retryImg;
|
|
|
152
|
+ @BindView(R.id.tv_upload_status)
|
|
|
153
|
+ TextView uploadStatusText;
|
|
140
|
154
|
|
|
141
|
|
- @BindView(R.id.iv_session_photo_item) ImageView photo;
|
|
142
|
|
- @BindView(R.id.layout_upload_fail) View errorLayout;
|
|
143
|
|
- @BindView(R.id.iv_upload_retry) ImageView retryImg;
|
|
144
|
|
- @BindView(R.id.tv_auto_upload_hint) TextView autoUploadHintText;
|
|
145
|
|
- public MyViewHolder(View view){
|
|
|
155
|
+ public MyViewHolder(View view) {
|
|
146
|
156
|
super(view);
|
|
147
|
|
- ButterKnife.bind(this,view);
|
|
|
157
|
+ ButterKnife.bind(this, view);
|
|
148
|
158
|
}
|
|
149
|
159
|
}
|
|
150
|
160
|
}
|
|
|
|
@@ -209,7 +209,7 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
|
|
209
|
209
|
|
|
210
|
210
|
|
|
211
|
211
|
@Override
|
|
212
|
|
- public void refreshUploadTimeHint() {
|
|
|
212
|
+ public void refreshRecyclerView() {
|
|
213
|
213
|
if(adapter!=null && photosRecyclerView!=null && photosRecyclerView.getVisibility()==View.VISIBLE){
|
|
214
|
214
|
photosRecyclerView.post(new Runnable() {
|
|
215
|
215
|
@Override
|
|
|
|
@@ -16,7 +16,7 @@ public class SessionContract {
|
|
16
|
16
|
void showPhotoRecyclerView();
|
|
17
|
17
|
void showEmptyView();
|
|
18
|
18
|
void showToast(String toast);
|
|
19
|
|
- void refreshUploadTimeHint();
|
|
|
19
|
+ void refreshRecyclerView();
|
|
20
|
20
|
void addPhotos(ArrayList<PhotoBean> photoList);
|
|
21
|
21
|
void refreshCameraStatus(String status);
|
|
22
|
22
|
}
|
|
|
|
@@ -1,6 +1,10 @@
|
|
1
|
1
|
package ai.pai.lensman.session;
|
|
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 com.android.common.utils.LogHelper;
|
|
6
|
10
|
|
|
|
|
@@ -16,7 +20,7 @@ import ai.pai.lensman.db.DBService;
|
|
16
|
20
|
import ai.pai.lensman.service.UploadService;
|
|
17
|
21
|
|
|
18
|
22
|
|
|
19
|
|
-public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener{
|
|
|
23
|
+public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener,UploadService.PhotoUploadListener{
|
|
20
|
24
|
|
|
21
|
25
|
private SessionInteractor interactor;
|
|
22
|
26
|
private ArrayList<PhotoBean> photoList;
|
|
|
|
@@ -25,12 +29,24 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
|
|
25
|
29
|
private boolean isWorking;
|
|
26
|
30
|
private String groupId;
|
|
27
|
31
|
private Timer refreshTimer;
|
|
|
32
|
+ private ServiceConnection uploadServiceConnection;
|
|
28
|
33
|
|
|
29
|
34
|
private static final String TAG = "SessionPresenter";
|
|
30
|
35
|
|
|
31
|
36
|
public SessionPresenter(SessionBean sessionBean, SessionContract.View view) {
|
|
32
|
37
|
this.sessionView = view;
|
|
33
|
38
|
this.sessionBean = sessionBean;
|
|
|
39
|
+ uploadServiceConnection = new ServiceConnection() {
|
|
|
40
|
+ @Override
|
|
|
41
|
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
|
|
42
|
+ ((UploadService.MyBinder) iBinder).getService().setPhotoUploadListener(SessionPresenter.this);
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ @Override
|
|
|
46
|
+ public void onServiceDisconnected(ComponentName componentName) {
|
|
|
47
|
+
|
|
|
48
|
+ }
|
|
|
49
|
+ };
|
|
34
|
50
|
}
|
|
35
|
51
|
|
|
36
|
52
|
@Override
|
|
|
|
@@ -55,16 +71,22 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
|
|
55
|
71
|
refreshTimer.schedule(new TimerTask() {
|
|
56
|
72
|
@Override
|
|
57
|
73
|
public void run() {
|
|
58
|
|
- sessionView.refreshUploadTimeHint();
|
|
|
74
|
+ sessionView.refreshRecyclerView();
|
|
59
|
75
|
}
|
|
60
|
76
|
},1000,1000);
|
|
61
|
|
-
|
|
|
77
|
+ App.getAppContext().bindService(new Intent(App.getAppContext(),UploadService.class),
|
|
|
78
|
+ uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
|
62
|
79
|
}
|
|
63
|
80
|
|
|
64
|
81
|
@Override
|
|
65
|
82
|
public void stop() {
|
|
66
|
83
|
interactor.endSession();
|
|
67
|
84
|
refreshTimer.cancel();
|
|
|
85
|
+ try{
|
|
|
86
|
+ App.getAppContext().unbindService(uploadServiceConnection);
|
|
|
87
|
+ }catch (Exception e){
|
|
|
88
|
+ e.printStackTrace();
|
|
|
89
|
+ }
|
|
68
|
90
|
isWorking = false;
|
|
69
|
91
|
LogHelper.d(TAG,"stop");
|
|
70
|
92
|
}
|
|
|
|
@@ -136,4 +158,25 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
|
|
136
|
158
|
this.groupId = groupId;
|
|
137
|
159
|
}
|
|
138
|
160
|
|
|
|
161
|
+ @Override
|
|
|
162
|
+ public void onPhotoUploaded(PhotoBean bean) {
|
|
|
163
|
+ for(PhotoBean photoBean : photoList){
|
|
|
164
|
+ if(photoBean.photoId == bean.photoId){
|
|
|
165
|
+ photoBean.uploadStatus = PhotoBean.UploadStatus.STATUS_SUCCESS;
|
|
|
166
|
+ sessionView.refreshRecyclerView();
|
|
|
167
|
+ break;
|
|
|
168
|
+ }
|
|
|
169
|
+ }
|
|
|
170
|
+ }
|
|
|
171
|
+
|
|
|
172
|
+ @Override
|
|
|
173
|
+ public void onPhotoUploadError(PhotoBean bean) {
|
|
|
174
|
+ for(PhotoBean photoBean : photoList){
|
|
|
175
|
+ if(photoBean.photoId == bean.photoId){
|
|
|
176
|
+ photoBean.uploadStatus = PhotoBean.UploadStatus.STATUS_ERROR;
|
|
|
177
|
+ sessionView.refreshRecyclerView();
|
|
|
178
|
+ break;
|
|
|
179
|
+ }
|
|
|
180
|
+ }
|
|
|
181
|
+ }
|
|
139
|
182
|
}
|
|
|
|
@@ -12,7 +12,7 @@
|
|
12
|
12
|
android:scaleType="centerCrop"/>
|
|
13
|
13
|
|
|
14
|
14
|
<TextView
|
|
15
|
|
- android:id="@+id/tv_auto_upload_hint"
|
|
|
15
|
+ android:id="@+id/tv_upload_status"
|
|
16
|
16
|
android:layout_width="match_parent"
|
|
17
|
17
|
android:layout_height="48dp"
|
|
18
|
18
|
android:gravity="center"
|
|
|
|
@@ -46,7 +46,7 @@
|
|
46
|
46
|
android:layout_height="wrap_content"
|
|
47
|
47
|
android:layout_below="@id/iv_upload_retry"
|
|
48
|
48
|
android:layout_centerHorizontal="true"
|
|
49
|
|
- android:text="@string/upload_error"
|
|
|
49
|
+ android:text="@string/click_to_retry"
|
|
50
|
50
|
android:textSize="16sp"
|
|
51
|
51
|
android:textColor="@color/white"/>
|
|
52
|
52
|
|
|
|
|
@@ -3,7 +3,7 @@
|
|
3
|
3
|
<string name="bar_app_name">拍爱摄影师版</string>
|
|
4
|
4
|
|
|
5
|
5
|
<string name="version_text">拍爱 V1.0</string>
|
|
6
|
|
- <string name="copyright">Copyright © 2016 </string>
|
|
|
6
|
+ <string name="copyright">Copyright © 2017 </string>
|
|
7
|
7
|
<string name="company_name">北京佳艺徕经贸有限责任公司</string>
|
|
8
|
8
|
|
|
9
|
9
|
<string name="bt_connected">已连接</string>
|
|
|
|
@@ -20,12 +20,6 @@
|
|
20
|
20
|
<string name="login_fail">登录失败</string>
|
|
21
|
21
|
<string name="please_wait">请稍候</string>
|
|
22
|
22
|
|
|
23
|
|
- <string name="upload_processing">上传中</string>
|
|
24
|
|
- <string name="upload_error">上传失败</string>
|
|
25
|
|
- <string name="upload_success">上传成功</string>
|
|
26
|
|
-
|
|
27
|
|
- <string name="add_to_upload_queue">已加入上传任务列表,尝试中...</string>
|
|
28
|
|
-
|
|
29
|
23
|
<string name="network_disconnect">当前无网络连接</string>
|
|
30
|
24
|
|
|
31
|
25
|
<string name="qr_scan_hint">将取景框对准二维码,\n即可自动扫码</string>
|
|
|
|
@@ -113,10 +107,6 @@
|
|
113
|
107
|
|
|
114
|
108
|
<string name="box_status_error">盒子状态错误,请检查</string>
|
|
115
|
109
|
|
|
116
|
|
- <string name="auto_upload_after_seconds">距自动上传还有%d秒</string>
|
|
117
|
|
-
|
|
118
|
|
- <string name="can_not_delete">该照片已在上传队列,无法删除</string>
|
|
119
|
|
-
|
|
120
|
110
|
<string name="sdcard_fail">手机sd卡错误</string>
|
|
121
|
111
|
|
|
122
|
112
|
<string name="upload_setting">上传延时设置</string>
|
|
|
|
@@ -153,4 +143,13 @@
|
|
153
|
143
|
|
|
154
|
144
|
<string name="upload_in_mobile_network">运营商网络下自动上传</string>
|
|
155
|
145
|
|
|
|
146
|
+ <string name="can_not_delete">该照片已在上传队列,无法删除</string>
|
|
|
147
|
+ <string name="auto_upload_after_seconds">距加入上传队列还有%d秒</string>
|
|
|
148
|
+ <string name="upload_in_waiting">等待上传</string>
|
|
|
149
|
+ <string name="upload_processing">上传中</string>
|
|
|
150
|
+ <string name="upload_error">上传失败</string>
|
|
|
151
|
+ <string name="upload_success">上传成功</string>
|
|
|
152
|
+
|
|
|
153
|
+ <string name="click_to_retry">点击重试</string>
|
|
|
154
|
+ <string name="add_to_upload_queue">已加入上传任务列表,尝试中...</string>
|
|
156
|
155
|
</resources>
|