mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-24 09:45:53 +08:00
已置顶相册长按菜单新增“置顶”功能,支持再次置顶到最前
PinnedAlbumDbHelper 新增 repinAlbumToFront():将当前相册集 排序号置为1,其余置顶记录整体后移一位;并新增 normalizeSortOrders() 按现有顺序把所有排序号重排为连续的 1..n,修正数据库中可能出现的序号空洞或重复。 AlbumAdapter 中已置顶相册的弹出菜单扩展为「取消置顶」「置顶」 两项,点击「置顶」即重新置顶到最前并刷新列表。
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Aug 23 08:17:44 HKT 2026
|
||||
#Sun Aug 23 08:40:51 HKT 2026
|
||||
stageCount=20
|
||||
libraryProject=
|
||||
baseVersion=15.0
|
||||
publishVersion=15.0.19
|
||||
buildCount=0
|
||||
buildCount=1
|
||||
baseBetaVersion=15.0.20
|
||||
|
||||
@@ -119,7 +119,12 @@ private void showContextMenu(View view, final Album album) {
|
||||
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(view.getContext());
|
||||
builder.setTitle(album.getName());
|
||||
final boolean isPinned = pinnedDbHelper != null && pinnedDbHelper.isPinned(album.getPath());
|
||||
String[] items = isPinned ? new String[]{"取消置顶"} : new String[]{"置顶"};
|
||||
String[] items = null;
|
||||
if (isPinned) {
|
||||
items = new String[]{"取消置顶", "置顶"};
|
||||
} else {
|
||||
items = new String[]{"置顶"};
|
||||
}
|
||||
builder.setItems(items, new android.content.DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(android.content.DialogInterface dialog, int which) {
|
||||
@@ -130,8 +135,10 @@ private void showContextMenu(View view, final Album album) {
|
||||
} else {
|
||||
pinnedDbHelper.pinAlbum(album.getPath());
|
||||
}
|
||||
refreshPinned();
|
||||
} else if (which == 1 && isPinned) {
|
||||
pinnedDbHelper.repinAlbumToFront(album.getPath());
|
||||
}
|
||||
refreshPinned();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -123,6 +123,63 @@ public class PinnedAlbumDbHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public void repinAlbumToFront(String albumPath) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
// 获取要再次置顶的相册的排序号
|
||||
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_SORT_ORDER},
|
||||
COLUMN_PATH + " = ?", new String[]{albumPath}, null, null, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
int sortNumber = cursor.getInt(0);
|
||||
cursor.close();
|
||||
|
||||
if (sortNumber > 1) {
|
||||
// 将排序号小于该记录的记录全部加1(整体后移)
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + COLUMN_SORT_ORDER + " = " + COLUMN_SORT_ORDER + " + 1 WHERE " + COLUMN_SORT_ORDER + " < ?", new Object[]{sortNumber});
|
||||
|
||||
// 该相册置顶到排序号1
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_SORT_ORDER, 1);
|
||||
db.update(TABLE_NAME, values, COLUMN_PATH + " = ?", new String[]{albumPath});
|
||||
|
||||
LogUtils.d(TAG, "repinAlbumToFront: " + albumPath + ", sort number was: " + sortNumber);
|
||||
}
|
||||
|
||||
// 按当前顺序将排序号重排为连续的1..n
|
||||
normalizeSortOrders(db);
|
||||
|
||||
// 查询所有置顶相册的排序号并输出调试信息
|
||||
Cursor debugCursor = db.query(TABLE_NAME, new String[]{COLUMN_PATH, COLUMN_SORT_ORDER},
|
||||
null, null, null, null, COLUMN_SORT_ORDER + " ASC");
|
||||
StringBuilder sb = new StringBuilder("All pinned albums after repin:\n");
|
||||
while (debugCursor.moveToNext()) {
|
||||
sb.append(" [").append(debugCursor.getInt(1)).append("] ").append(debugCursor.getString(0)).append("\n");
|
||||
}
|
||||
debugCursor.close();
|
||||
LogUtils.d(TAG, sb.toString());
|
||||
} else {
|
||||
cursor.close();
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
// 按排序号升序将所有记录重排为连续的1..n,修正可能出现的序号空洞或重复
|
||||
private void normalizeSortOrders(SQLiteDatabase db) {
|
||||
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_PATH}, null, null, null, null,
|
||||
COLUMN_SORT_ORDER + " ASC");
|
||||
int sortOrder = 1;
|
||||
while (cursor.moveToNext()) {
|
||||
String path = cursor.getString(0);
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + COLUMN_SORT_ORDER + " = ? WHERE " + COLUMN_PATH + " = ?",
|
||||
new Object[]{sortOrder++, path});
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
public boolean isPinned(String albumPath) {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
Cursor cursor = db.query(TABLE_NAME, null, COLUMN_PATH + " = ?",
|
||||
|
||||
Reference in New Issue
Block a user