diff --git a/mygallery/build.properties b/mygallery/build.properties index df1ad0b..8e7da2e 100644 --- a/mygallery/build.properties +++ b/mygallery/build.properties @@ -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 diff --git a/mygallery/src/main/java/cc/winboll/studio/mygallery/AlbumAdapter.java b/mygallery/src/main/java/cc/winboll/studio/mygallery/AlbumAdapter.java index 38aa076..88927f2 100644 --- a/mygallery/src/main/java/cc/winboll/studio/mygallery/AlbumAdapter.java +++ b/mygallery/src/main/java/cc/winboll/studio/mygallery/AlbumAdapter.java @@ -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(); } } }); diff --git a/mygallery/src/main/java/cc/winboll/studio/mygallery/PinnedAlbumDbHelper.java b/mygallery/src/main/java/cc/winboll/studio/mygallery/PinnedAlbumDbHelper.java index df33376..1418f11 100644 --- a/mygallery/src/main/java/cc/winboll/studio/mygallery/PinnedAlbumDbHelper.java +++ b/mygallery/src/main/java/cc/winboll/studio/mygallery/PinnedAlbumDbHelper.java @@ -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 + " = ?",