退出群后还能看到以前的照片--系统里有缓存

chengzhenyu преди 8 години
родител
ревизия
9e6fb57cf5

+ 7 - 2
app/src/main/java/ai/pai/client/activity/GroupActivity.java

@@ -40,6 +40,7 @@ public class GroupActivity extends BaseActivity implements View.OnClickListener
40 40
     private GroupPhotoFragment photoFragment;
41 41
     private ImageButton cameraBtn;
42 42
     private static final int TAKE_PHOTO_REQUEST_CODE = 1;
43
+    private static final int EXIT_GROUP_CODE = 2;
43 44
 
44 45
     @Override
45 46
     protected void onCreate(Bundle savedInstanceState) {
@@ -98,7 +99,7 @@ public class GroupActivity extends BaseActivity implements View.OnClickListener
98 99
                 intent.putExtra("group_id", groupId);
99 100
                 intent.putExtra("avatar_id", defaultAvatarId);
100 101
                 intent.putExtra("group_name", groupName);
101
-                startActivity(intent);
102
+                startActivityForResult(intent,EXIT_GROUP_CODE);
102 103
                 break;
103 104
             case R.id.floating_btn_camera:
104 105
                 MobclickAgent.onEvent(this, UmengEvent.group_camera_btn_click);
@@ -133,6 +134,7 @@ public class GroupActivity extends BaseActivity implements View.OnClickListener
133 134
 
134 135
     @Override
135 136
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
137
+        super.onActivityResult(requestCode, resultCode, data);
136 138
         if (resultCode == Activity.RESULT_OK && requestCode == TAKE_PHOTO_REQUEST_CODE) {
137 139
             if (photoFragment != null && photoFragment.isAdded()) {
138 140
 //                Intent intent = new Intent(this,PhotoUploadActivity.class);
@@ -142,7 +144,10 @@ public class GroupActivity extends BaseActivity implements View.OnClickListener
142 144
                 uploadPhoto(photoFile.getAbsolutePath());
143 145
             }
144 146
         }
145
-        super.onActivityResult(requestCode, resultCode, data);
147
+        if (resultCode == Activity.RESULT_OK && requestCode == EXIT_GROUP_CODE) {
148
+            finish();
149
+            return;
150
+        }
146 151
     }
147 152
 
148 153
     private void uploadPhoto(String path) {

+ 2 - 1
app/src/main/java/ai/pai/client/activity/GroupSettingActivity.java

@@ -249,7 +249,8 @@ public class GroupSettingActivity extends BaseActivity implements View.OnClickLi
249 249
                 break;
250 250
             case GroupService.GroupCommand.COMMAND_QUIT_GROUP:
251 251
                 Toast.makeText(getApplicationContext(), R.string.quit_group_success, Toast.LENGTH_SHORT).show();
252
-                DBService.getInstance(getApplicationContext()).deleteGroupByGroupId(groupId);
252
+                DBService.getInstance(getApplicationContext()).deleteGroupRelated(groupId);
253
+                setResult(RESULT_OK);
253 254
                 finish();
254 255
                 break;
255 256
         }

+ 1 - 1
app/src/main/java/ai/pai/client/adapter/HistoryGroupAdapter.java

@@ -85,7 +85,7 @@ public class HistoryGroupAdapter extends RecyclerView.Adapter<HistoryGroupAdapte
85 85
 
86 86
                 groupList.remove(holder.getAdapterPosition());
87 87
                 notifyItemRemoved(holder.getAdapterPosition());
88
-                DBService.getInstance(context).deleteGroupByGroupId(info.groupId);
88
+                DBService.getInstance(context).deleteGroupRelated(info.groupId);
89 89
                 if(listener!=null){
90 90
                     listener.onGroupDeleted(info);
91 91
                 }

+ 62 - 1
app/src/main/java/ai/pai/client/db/DBService.java

@@ -366,7 +366,7 @@ public class DBService {
366 366
         addNewGroup(newGroupInfo);
367 367
     }
368 368
 
369
-    public void deleteGroupByGroupId(String groupId) {
369
+    private void deleteGroupByGroupId(String groupId) {
370 370
         if (TextUtils.isEmpty(groupId)) {
371 371
             return;
372 372
         }
@@ -544,6 +544,67 @@ public class DBService {
544 544
         return photoBean;
545 545
     }
546 546
 
547
+    public void deleteGroupRelated(final String groupId){
548
+        new Thread(new Runnable() {
549
+            @Override
550
+            public void run() {
551
+                deleteGroupByGroupId(groupId);
552
+                deleteGroupPhotos(groupId);
553
+                deleteRecentPhotos(groupId);
554
+            }
555
+        }).start();
556
+    }
557
+
558
+    private void deleteGroupPhotos(String groupId){
559
+        if (TextUtils.isEmpty(groupId)) {
560
+            return;
561
+        }
562
+        SQLiteDatabase db = null;
563
+        synchronized (DB_LOCK) {
564
+            try {
565
+                db = dbHelper.getReadableDatabase();
566
+                db.beginTransaction();
567
+                db.execSQL("delete  from " + DBHelper.PHOTO_INFO_TABLE + " where "
568
+                        + DBHelper.PHOTO_INFO_COLUMNS.PHOTO_GROUP_ID + " = '" + groupId + "'");
569
+                db.setTransactionSuccessful();
570
+            } catch (Exception e) {
571
+                LogHelper.d(TAG, "dbservice deleteGroupPhotos error happen " + e);
572
+            } finally {
573
+                try {
574
+                    db.endTransaction();
575
+                } catch (Exception e) {
576
+                    e.printStackTrace();
577
+                }
578
+                closeCursorAndDB(null, db);
579
+            }
580
+        }
581
+    }
582
+
583
+    private void deleteRecentPhotos(String groupId){
584
+        if (TextUtils.isEmpty(groupId)) {
585
+            return;
586
+        }
587
+        SQLiteDatabase db = null;
588
+        synchronized (DB_LOCK) {
589
+            try {
590
+                db = dbHelper.getReadableDatabase();
591
+                db.beginTransaction();
592
+                db.execSQL("delete  from " + DBHelper.RECENT_PHOTO_TABLE + " where "
593
+                        + DBHelper.PHOTO_INFO_COLUMNS.PHOTO_GROUP_ID + " = '" + groupId + "'");
594
+                db.setTransactionSuccessful();
595
+            } catch (Exception e) {
596
+                LogHelper.d(TAG, "dbservice deleteGroupPhotos error happen " + e);
597
+            } finally {
598
+                try {
599
+                    db.endTransaction();
600
+                } catch (Exception e) {
601
+                    e.printStackTrace();
602
+                }
603
+                closeCursorAndDB(null, db);
604
+            }
605
+        }
606
+    }
607
+
547 608
     public void clearDB(){
548 609
         SQLiteDatabase db = null;
549 610
         try{