@@ -8,6 +8,8 @@ public final class BoxUrlContainer {
|
||
| 8 | 8 |
|
| 9 | 9 |
public static final String SESSION_END_URL = BASE_URL+"session_end"; |
| 10 | 10 |
|
| 11 |
+ public static final String DELETE_PHOTO_URL = BASE_URL+"delete"; |
|
| 12 |
+ |
|
| 11 | 13 |
public static final String FETCH_THUMBNAIL_URL = BASE_URL+"fetch_thumbnail"; |
| 12 | 14 |
|
| 13 | 15 |
public static final String PHOTO_PATH_PREFIX_URL = BASE_URL+"static/"; |
@@ -2,6 +2,7 @@ package ai.pai.lensman.session; |
||
| 2 | 2 |
|
| 3 | 3 |
import android.app.Activity; |
| 4 | 4 |
import android.content.Intent; |
| 5 |
+import android.graphics.Canvas; |
|
| 5 | 6 |
import android.os.Bundle; |
| 6 | 7 |
import android.support.v7.widget.LinearLayoutManager; |
| 7 | 8 |
import android.support.v7.widget.RecyclerView; |
@@ -32,6 +33,17 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
| 32 | 33 |
|
| 33 | 34 |
private ItemTouchHelper.Callback mCallback = new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, |
| 34 | 35 |
ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT) {
|
| 36 |
+ |
|
| 37 |
+ @Override |
|
| 38 |
+ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
|
| 39 |
+ super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); |
|
| 40 |
+ if(actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
|
|
| 41 |
+ final float alpha = 1 - Math.abs(dX) / (float)viewHolder.itemView.getWidth(); |
|
| 42 |
+ viewHolder.itemView.setAlpha(alpha); |
|
| 43 |
+ viewHolder.itemView.setTranslationX(dX); |
|
| 44 |
+ } |
|
| 45 |
+ } |
|
| 46 |
+ |
|
| 35 | 47 |
@Override |
| 36 | 48 |
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
| 37 | 49 |
return false; |
@@ -40,6 +52,7 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
| 40 | 52 |
@Override |
| 41 | 53 |
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
| 42 | 54 |
int position = viewHolder.getAdapterPosition(); |
| 55 |
+ presenter.swipeToDeletePhoto(position); |
|
| 43 | 56 |
adapter.removePhotoAtIndex(position); |
| 44 | 57 |
} |
| 45 | 58 |
}; |
@@ -17,6 +17,6 @@ public class SessionContract {
|
||
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
interface Presenter extends BasePresenter{
|
| 20 |
- |
|
| 20 |
+ void swipeToDeletePhoto(int index); |
|
| 21 | 21 |
} |
| 22 | 22 |
} |
@@ -251,6 +251,14 @@ public class SessionInteractor {
|
||
| 251 | 251 |
listener.onSessionEnd(sessionBean.sessionId); |
| 252 | 252 |
} |
| 253 | 253 |
|
| 254 |
+ public void deletePhoto(){
|
|
| 255 |
+ HashMap<String,String> params = new HashMap<>(); |
|
| 256 |
+ params.put("lensman",sessionBean.lensmanId);
|
|
| 257 |
+ params.put("session",sessionBean.sessionId);
|
|
| 258 |
+ HttpPostTask deleteTask = new HttpPostTask(params); |
|
| 259 |
+ deleteTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.DELETE_PHOTO_URL); |
|
| 260 |
+ } |
|
| 261 |
+ |
|
| 254 | 262 |
private void cancelTask(HttpPostTask task){
|
| 255 | 263 |
if(task==null){
|
| 256 | 264 |
return; |
@@ -1,33 +1,52 @@ |
||
| 1 | 1 |
package ai.pai.lensman.session; |
| 2 | 2 |
|
| 3 |
+import android.os.SystemClock; |
|
| 4 |
+ |
|
| 3 | 5 |
import java.util.ArrayList; |
| 4 | 6 |
|
| 5 | 7 |
import ai.pai.lensman.bean.PhotoBean; |
| 6 | 8 |
import ai.pai.lensman.bean.SessionBean; |
| 7 | 9 |
import ai.pai.lensman.db.DBService; |
| 8 | 10 |
|
| 9 |
-public class SessionPresenter implements SessionContract.Presenter,SessionInteractor.SessionListener{
|
|
| 11 |
+public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener {
|
|
| 10 | 12 |
|
| 11 | 13 |
private SessionInteractor interactor; |
| 12 | 14 |
private ArrayList<PhotoBean> photoList; |
| 13 | 15 |
private SessionContract.View sessionView; |
| 14 | 16 |
private SessionBean sessionBean; |
| 15 | 17 |
|
| 16 |
- public SessionPresenter(SessionBean sessionBean, SessionContract.View view){
|
|
| 18 |
+ public SessionPresenter(SessionBean sessionBean, SessionContract.View view) {
|
|
| 17 | 19 |
this.sessionView = view; |
| 18 | 20 |
this.sessionBean = sessionBean; |
| 19 |
- interactor = new SessionInteractor(sessionBean,this); |
|
| 21 |
+ interactor = new SessionInteractor(sessionBean, this); |
|
| 20 | 22 |
} |
| 21 | 23 |
|
| 22 | 24 |
@Override |
| 23 | 25 |
public void start() {
|
| 24 | 26 |
photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId); |
| 25 |
- if(photoList.size()==0){
|
|
| 27 |
+ //TODO for test |
|
| 28 |
+ for (int k = 0; k < 10; k++) {
|
|
| 29 |
+ PhotoBean bean = new PhotoBean(); |
|
| 30 |
+ long milisec = System.currentTimeMillis(); |
|
| 31 |
+ bean.photoName = milisec + ".jpg"; |
|
| 32 |
+ bean.photoId = milisec; |
|
| 33 |
+ bean.photoPath = "http://e.hiphotos.baidu.com/image/h%3D200/sign=31e61d6532f33a87816d071af65d1018/95eef01f3a292df504213240b4315c6035a87381.jpg"; |
|
| 34 |
+ bean.captureTime = bean.photoId; |
|
| 35 |
+ bean.isRawPhoto = false; |
|
| 36 |
+ bean.isUploaded = false; |
|
| 37 |
+ bean.sessionId = sessionBean.sessionId; |
|
| 38 |
+ bean.lensmanId = sessionBean.lensmanId; |
|
| 39 |
+ bean.sessionSeq = sessionBean.sessionSeq; |
|
| 40 |
+ bean.sessionDate = sessionBean.sessionDate; |
|
| 41 |
+ photoList.add(bean); |
|
| 42 |
+ SystemClock.sleep(10); |
|
| 43 |
+ } |
|
| 44 |
+ if (photoList.size() == 0) {
|
|
| 26 | 45 |
sessionView.showEmptyView(); |
| 27 |
- }else{
|
|
| 46 |
+ } else {
|
|
| 28 | 47 |
sessionView.showPhotoRecyclerView(); |
| 29 |
- for(PhotoBean bean : photoList){
|
|
| 30 |
- sessionView.addNewPhoto(bean); |
|
| 48 |
+ for (PhotoBean photoBean : photoList) {
|
|
| 49 |
+ sessionView.addNewPhoto(photoBean); |
|
| 31 | 50 |
} |
| 32 | 51 |
} |
| 33 | 52 |
interactor.startSession(); |
@@ -59,4 +78,12 @@ public class SessionPresenter implements SessionContract.Presenter,SessionIntera |
||
| 59 | 78 |
public void onSessionEnd(String session) {
|
| 60 | 79 |
|
| 61 | 80 |
} |
| 81 |
+ |
|
| 82 |
+ @Override |
|
| 83 |
+ public void swipeToDeletePhoto(int index) {
|
|
| 84 |
+ PhotoBean photoBean = photoList.get(index); |
|
| 85 |
+ photoList.remove(photoBean); |
|
| 86 |
+ DBService.getInstance().deletePhotoBean(photoBean); |
|
| 87 |
+ interactor.deletePhoto(); |
|
| 88 |
+ } |
|
| 62 | 89 |
} |