添加调试信息
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package cc.winboll.gallery;
|
package cc.winboll.gallery;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class Album {
|
public class Album {
|
||||||
public static final String TAG = "Album";
|
public static final String TAG = "Album";
|
||||||
@@ -10,6 +11,7 @@ public class Album {
|
|||||||
private int imageCount;
|
private int imageCount;
|
||||||
|
|
||||||
public Album(String name, String path, Uri coverUri, int imageCount) {
|
public Album(String name, String path, Uri coverUri, int imageCount) {
|
||||||
|
LogUtils.d(TAG, "Album created: " + name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.coverUri = coverUri;
|
this.coverUri = coverUri;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.gallery.ImageAdapter.OnImageClickListener;
|
import cc.winboll.gallery.ImageAdapter.OnImageClickListener;
|
||||||
|
|
||||||
public class AlbumActivity extends AppCompatActivity {
|
public class AlbumActivity extends AppCompatActivity {
|
||||||
@@ -34,6 +35,7 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
LogUtils.d(TAG, "onCreate");
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@@ -91,6 +93,7 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadImages() {
|
private void loadImages() {
|
||||||
|
LogUtils.d(TAG, "loadImages");
|
||||||
ArrayList<Uri> imageUrls = new ArrayList<>();
|
ArrayList<Uri> imageUrls = new ArrayList<>();
|
||||||
ArrayList<String> imagePaths = new ArrayList<>();
|
ArrayList<String> imagePaths = new ArrayList<>();
|
||||||
ContentResolver contentResolver = getContentResolver();
|
ContentResolver contentResolver = getContentResolver();
|
||||||
@@ -117,8 +120,10 @@ public class AlbumActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (imageUrls.isEmpty()) {
|
if (imageUrls.isEmpty()) {
|
||||||
Toast.makeText(this, R.string.no_images_found, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.no_images_found, Toast.LENGTH_SHORT).show();
|
||||||
|
LogUtils.i(TAG, "No images found");
|
||||||
}
|
}
|
||||||
adapter.setData(imageUrls, imagePaths);
|
adapter.setData(imageUrls, imagePaths);
|
||||||
|
LogUtils.d(TAG, "Loaded " + imageUrls.size() + " images");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder> {
|
public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder> {
|
||||||
public static final String TAG = "AlbumAdapter";
|
public static final String TAG = "AlbumAdapter";
|
||||||
private ArrayList<Album> albums = new ArrayList<>();
|
private ArrayList<Album> albums = new ArrayList<>();
|
||||||
@@ -26,6 +28,7 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||||||
|
|
||||||
public void setData(ArrayList<Album> albums) {
|
public void setData(ArrayList<Album> albums) {
|
||||||
this.albums = albums;
|
this.albums = albums;
|
||||||
|
LogUtils.d(TAG, "setData: " + albums.size() + " albums");
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cc.winboll.gallery;
|
|||||||
|
|
||||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.ToastUtils;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,13 +14,14 @@ public class GlobalWinBoLLApplication extends GlobalApplication {
|
|||||||
public static final String TAG = "GlobalWinBoLLApplication";
|
public static final String TAG = "GlobalWinBoLLApplication";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
setIsDebugging(BuildConfig.DEBUG);
|
LogUtils.d(TAG, "onCreate");
|
||||||
//setIsDebugging(false);
|
setIsDebugging(BuildConfig.DEBUG);
|
||||||
|
//setIsDebugging(false);
|
||||||
|
|
||||||
WinBoLLActivityManager.init(this);
|
WinBoLLActivityManager.init(this);
|
||||||
|
|
||||||
// 初始化 Toast 框架
|
// 初始化 Toast 框架
|
||||||
ToastUtils.init(this);
|
ToastUtils.init(this);
|
||||||
@@ -32,10 +34,11 @@ public class GlobalWinBoLLApplication extends GlobalApplication {
|
|||||||
//CrashHandler.getInstance().registerPart(this);
|
//CrashHandler.getInstance().registerPart(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTerminate() {
|
public void onTerminate() {
|
||||||
super.onTerminate();
|
super.onTerminate();
|
||||||
ToastUtils.release();
|
LogUtils.d(TAG, "onTerminate");
|
||||||
}
|
ToastUtils.release();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
|
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
|
||||||
public static final String TAG = "ImageAdapter";
|
public static final String TAG = "ImageAdapter";
|
||||||
private ArrayList<Uri> imageUrls = new ArrayList<>();
|
private ArrayList<Uri> imageUrls = new ArrayList<>();
|
||||||
@@ -28,6 +30,7 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder>
|
|||||||
public void setData(ArrayList<Uri> urls, ArrayList<String> paths) {
|
public void setData(ArrayList<Uri> urls, ArrayList<String> paths) {
|
||||||
this.imageUrls = urls;
|
this.imageUrls = urls;
|
||||||
this.imagePaths = paths;
|
this.imagePaths = paths;
|
||||||
|
LogUtils.d(TAG, "setData: " + urls.size() + " images");
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,15 @@ import com.bumptech.glide.Glide;
|
|||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class ImagePagerAdapter extends PagerAdapter {
|
public class ImagePagerAdapter extends PagerAdapter {
|
||||||
public static final String TAG = "ImagePagerAdapter";
|
public static final String TAG = "ImagePagerAdapter";
|
||||||
private ArrayList<Uri> imageUrls;
|
private ArrayList<Uri> imageUrls;
|
||||||
|
|
||||||
public ImagePagerAdapter(ArrayList<Uri> imageUrls) {
|
public ImagePagerAdapter(ArrayList<Uri> imageUrls) {
|
||||||
this.imageUrls = imageUrls;
|
this.imageUrls = imageUrls;
|
||||||
|
LogUtils.d(TAG, "ImagePagerAdapter created with " + imageUrls.size() + " images");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import androidx.viewpager.widget.ViewPager;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class ImageViewerActivity extends Activity implements ViewPager.OnPageChangeListener {
|
public class ImageViewerActivity extends Activity implements ViewPager.OnPageChangeListener {
|
||||||
public static final String TAG = "ImageViewerActivity";
|
public static final String TAG = "ImageViewerActivity";
|
||||||
public static final String EXTRA_IMAGE_URLS = "image_urls";
|
public static final String EXTRA_IMAGE_URLS = "image_urls";
|
||||||
@@ -39,6 +41,7 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
|||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
setContentView(R.layout.activity_image_viewer);
|
setContentView(R.layout.activity_image_viewer);
|
||||||
|
LogUtils.d(TAG, "onCreate");
|
||||||
|
|
||||||
imageUrls = getIntent().getParcelableArrayListExtra(EXTRA_IMAGE_URLS);
|
imageUrls = getIntent().getParcelableArrayListExtra(EXTRA_IMAGE_URLS);
|
||||||
imagePaths = getIntent().getStringArrayListExtra(EXTRA_POSITIONS);
|
imagePaths = getIntent().getStringArrayListExtra(EXTRA_POSITIONS);
|
||||||
@@ -116,6 +119,7 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void moveToTrash() {
|
private void moveToTrash() {
|
||||||
|
LogUtils.d(TAG, "moveToTrash");
|
||||||
if (currentPosition >= 0 && currentPosition < imageUrls.size()) {
|
if (currentPosition >= 0 && currentPosition < imageUrls.size()) {
|
||||||
String imagePath = "";
|
String imagePath = "";
|
||||||
if (imagePaths != null && currentPosition < imagePaths.size()) {
|
if (imagePaths != null && currentPosition < imagePaths.size()) {
|
||||||
@@ -138,6 +142,7 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
android.widget.Toast.makeText(this, "Moved to trash", android.widget.Toast.LENGTH_SHORT).show();
|
android.widget.Toast.makeText(this, "Moved to trash", android.widget.Toast.LENGTH_SHORT).show();
|
||||||
|
LogUtils.i(TAG, "Moved to trash");
|
||||||
removeCurrentImage();
|
removeCurrentImage();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import androidx.core.content.ContextCompat;
|
|||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import cc.winboll.gallery.AlbumAdapter.OnAlbumClickListener;
|
import cc.winboll.gallery.AlbumAdapter.OnAlbumClickListener;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.LogActivity;
|
import cc.winboll.studio.libappbase.LogActivity;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
@@ -39,6 +40,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
LogUtils.d(TAG, "onCreate");
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@@ -64,6 +66,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkAndRequestPermissions() {
|
private void checkAndRequestPermissions() {
|
||||||
|
LogUtils.i(TAG, "checkAndRequestPermissions");
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (!Environment.isExternalStorageManager()) {
|
if (!Environment.isExternalStorageManager()) {
|
||||||
try {
|
try {
|
||||||
@@ -127,6 +130,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadAlbums() {
|
private void loadAlbums() {
|
||||||
|
LogUtils.d(TAG, "loadAlbums");
|
||||||
String folderPath = prefs.getFolderPath();
|
String folderPath = prefs.getFolderPath();
|
||||||
File baseFolder = new File(folderPath);
|
File baseFolder = new File(folderPath);
|
||||||
|
|
||||||
@@ -160,8 +164,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (albums.isEmpty()) {
|
if (albums.isEmpty()) {
|
||||||
Toast.makeText(this, R.string.no_images_found, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.no_images_found, Toast.LENGTH_SHORT).show();
|
||||||
|
LogUtils.i(TAG, "No albums found");
|
||||||
}
|
}
|
||||||
adapter.setData(albums);
|
adapter.setData(albums);
|
||||||
|
LogUtils.d(TAG, "Loaded " + albums.size() + " albums");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Uri> getImagesInFolder(String folderPath) {
|
private ArrayList<Uri> getImagesInFolder(String folderPath) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cc.winboll.gallery;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class Preferences {
|
public class Preferences {
|
||||||
public static final String TAG = "Preferences";
|
public static final String TAG = "Preferences";
|
||||||
@@ -20,10 +21,13 @@ public class Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getFolderPath() {
|
public String getFolderPath() {
|
||||||
return prefs.getString(KEY_FOLDER_PATH, DEFAULT_PATH);
|
String path = prefs.getString(KEY_FOLDER_PATH, DEFAULT_PATH);
|
||||||
|
LogUtils.d(TAG, "getFolderPath: " + path);
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFolderPath(String path) {
|
public void setFolderPath(String path) {
|
||||||
|
LogUtils.d(TAG, "setFolderPath: " + path);
|
||||||
prefs.edit().putString(KEY_FOLDER_PATH, path).apply();
|
prefs.edit().putString(KEY_FOLDER_PATH, path).apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class SettingsActivity extends AppCompatActivity {
|
public class SettingsActivity extends AppCompatActivity {
|
||||||
public static final String TAG = "SettingsActivity";
|
public static final String TAG = "SettingsActivity";
|
||||||
@@ -18,6 +19,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_settings);
|
setContentView(R.layout.activity_settings);
|
||||||
|
LogUtils.d(TAG, "onCreate");
|
||||||
|
|
||||||
prefs = new Preferences(this);
|
prefs = new Preferences(this);
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class TrashActivity extends AppCompatActivity {
|
public class TrashActivity extends AppCompatActivity {
|
||||||
public static final String TAG = "TrashActivity";
|
public static final String TAG = "TrashActivity";
|
||||||
private static final int PERMISSION_REQUEST_CODE = 102;
|
private static final int PERMISSION_REQUEST_CODE = 102;
|
||||||
@@ -31,6 +33,7 @@ public class TrashActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
LogUtils.d(TAG, "onCreate");
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@@ -87,6 +90,7 @@ public class TrashActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadTrash() {
|
private void loadTrash() {
|
||||||
|
LogUtils.d(TAG, "loadTrash");
|
||||||
Cursor cursor = trashManager.getTrashList();
|
Cursor cursor = trashManager.getTrashList();
|
||||||
ArrayList<TrashItem> items = new ArrayList<TrashItem>();
|
ArrayList<TrashItem> items = new ArrayList<TrashItem>();
|
||||||
ArrayList<Uri> uris = new ArrayList<Uri>();
|
ArrayList<Uri> uris = new ArrayList<Uri>();
|
||||||
@@ -129,12 +133,14 @@ public class TrashActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void restoreImage(int position) {
|
private void restoreImage(int position) {
|
||||||
|
LogUtils.d(TAG, "restoreImage: " + position);
|
||||||
long id = adapter.getItemId(position);
|
long id = adapter.getItemId(position);
|
||||||
String fileName = adapter.getFileName(position);
|
String fileName = adapter.getFileName(position);
|
||||||
String originalPath = adapter.getOriginalPath(position);
|
String originalPath = adapter.getOriginalPath(position);
|
||||||
|
|
||||||
if (trashManager.restore(id, fileName, originalPath)) {
|
if (trashManager.restore(id, fileName, originalPath)) {
|
||||||
Toast.makeText(this, "Image restored", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Image restored", Toast.LENGTH_SHORT).show();
|
||||||
|
LogUtils.i(TAG, "Image restored");
|
||||||
loadTrash();
|
loadTrash();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "Restore failed", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Restore failed", Toast.LENGTH_SHORT).show();
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class TrashAdapter extends RecyclerView.Adapter<TrashAdapter.ViewHolder> {
|
public class TrashAdapter extends RecyclerView.Adapter<TrashAdapter.ViewHolder> {
|
||||||
public static final String TAG = "TrashAdapter";
|
public static final String TAG = "TrashAdapter";
|
||||||
private ArrayList<TrashActivity.TrashItem> trashItems = new ArrayList<TrashActivity.TrashItem>();
|
private ArrayList<TrashActivity.TrashItem> trashItems = new ArrayList<TrashActivity.TrashItem>();
|
||||||
@@ -29,6 +31,7 @@ public class TrashAdapter extends RecyclerView.Adapter<TrashAdapter.ViewHolder>
|
|||||||
public void setData(ArrayList<TrashActivity.TrashItem> items, ArrayList<Uri> uris) {
|
public void setData(ArrayList<TrashActivity.TrashItem> items, ArrayList<Uri> uris) {
|
||||||
this.trashItems = items;
|
this.trashItems = items;
|
||||||
this.imageUrls = uris;
|
this.imageUrls = uris;
|
||||||
|
LogUtils.d(TAG, "setData: " + items.size() + " items");
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class TrashDbHelper extends SQLiteOpenHelper {
|
public class TrashDbHelper extends SQLiteOpenHelper {
|
||||||
public static final String TAG = "TrashDbHelper";
|
public static final String TAG = "TrashDbHelper";
|
||||||
private static final String DB_NAME = "trash.db";
|
private static final String DB_NAME = "trash.db";
|
||||||
@@ -25,6 +27,7 @@ public class TrashDbHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
LogUtils.d(TAG, "onCreate");
|
||||||
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +
|
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +
|
||||||
COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
COL_FILE_NAME + " TEXT, " +
|
COL_FILE_NAME + " TEXT, " +
|
||||||
@@ -35,6 +38,7 @@ public class TrashDbHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
LogUtils.i(TAG, "onUpgrade: " + oldVersion + " -> " + newVersion);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,21 @@ import android.provider.MediaStore;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class TrashManager {
|
public class TrashManager {
|
||||||
public static final String TAG = "TrashManager";
|
public static final String TAG = "TrashManager";
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final TrashDbHelper dbHelper;
|
private final TrashDbHelper dbHelper;
|
||||||
|
|
||||||
public TrashManager(Context context) {
|
public TrashManager(Context context) {
|
||||||
|
LogUtils.d(TAG, "TrashManager created");
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.dbHelper = new TrashDbHelper(context);
|
this.dbHelper = new TrashDbHelper(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long addToTrash(String imagePath) {
|
public long addToTrash(String imagePath) {
|
||||||
|
LogUtils.d(TAG, "addToTrash: " + imagePath);
|
||||||
File sourceFile = new File(imagePath);
|
File sourceFile = new File(imagePath);
|
||||||
if (!sourceFile.exists()) {
|
if (!sourceFile.exists()) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -32,8 +36,10 @@ public class TrashManager {
|
|||||||
if (sourceFile.renameTo(destFile)) {
|
if (sourceFile.renameTo(destFile)) {
|
||||||
String originalFolder = sourceFile.getParent();
|
String originalFolder = sourceFile.getParent();
|
||||||
long result = dbHelper.insert(newFileName, imagePath, originalFolder);
|
long result = dbHelper.insert(newFileName, imagePath, originalFolder);
|
||||||
|
LogUtils.i(TAG, "Added to trash: " + newFileName);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
LogUtils.e(TAG, "Failed to move to trash");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +48,7 @@ public class TrashManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean restore(long id, String fileName, String originalPath) {
|
public boolean restore(long id, String fileName, String originalPath) {
|
||||||
|
LogUtils.i(TAG, "restore: " + fileName + " -> " + originalPath);
|
||||||
File trashFile = new File(TrashDbHelper.getTrashPath(), fileName);
|
File trashFile = new File(TrashDbHelper.getTrashPath(), fileName);
|
||||||
if (!trashFile.exists()) {
|
if (!trashFile.exists()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -58,9 +65,11 @@ public class TrashManager {
|
|||||||
|
|
||||||
if (trashFile.renameTo(restoreFile)) {
|
if (trashFile.renameTo(restoreFile)) {
|
||||||
dbHelper.delete(id);
|
dbHelper.delete(id);
|
||||||
|
LogUtils.i(TAG, "Restored: " + fileName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogUtils.e(TAG, "Failed to restore: " + fileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user