Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swipe post/comment to upvote/downvote/reply/save #1327

Merged
merged 25 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b1ef785
SwipeToAction composable
Snow4DV Jan 20, 2024
2d6c045
Merge branch 'dessalines:main' into main
Snow4DV Jan 21, 2024
65e94bb
Merge branch 'dessalines:main' into main
Snow4DV Jan 22, 2024
109337d
Swipe to downvote/upvote feature implemented with preset-based custom…
Snow4DV Jan 22, 2024
e81c863
Merge branch 'main' into main
Snow4DV Jan 22, 2024
edd1b7e
Fix kotlin format
Snow4DV Jan 22, 2024
b121bd3
fix string resource
Snow4DV Jan 22, 2024
fabdd5c
Do not use SwipeToAction when it is disabled
Snow4DV Jan 22, 2024
899171c
Improve scrolling experience
Snow4DV Jan 22, 2024
8a33f41
Increase color shift animation speed
Snow4DV Jan 22, 2024
38388da
Improve ranges
Snow4DV Jan 22, 2024
30e807c
new preset: only votes
Snow4DV Jan 22, 2024
ee9515e
fix deltas & rename resources
Snow4DV Jan 29, 2024
d89d49d
Merge to upstream
Snow4DV Jan 29, 2024
0444477
SwipeToAction implemented correctly, SwipeToDismiss replaced with Swi…
Snow4DV Jan 29, 2024
45ea9e2
Kotlin format
Snow4DV Jan 29, 2024
23e8540
use ordinal of enum in AppDB instead of int
Snow4DV Jan 29, 2024
93e5c5e
Fixed behaviour when downvotes disables/when not logged in
Snow4DV Feb 4, 2024
b5c0222
Fix formatting
Snow4DV Feb 4, 2024
8ac5f47
Remove default param for enableDownVotes in SwipeToAction
Snow4DV Feb 4, 2024
707990a
Fix colors for swipe actions
Snow4DV Feb 5, 2024
b936b56
Fixed lambda caching in rememberSwipeActionState
Snow4DV Feb 5, 2024
5d677b8
Merge to dessalines/jerboa (main)
Snow4DV Feb 5, 2024
eed2dfd
Format kotlin
Snow4DV Feb 5, 2024
ceb18b3
Merge branch 'main' into main
dessalines Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 260 additions & 0 deletions app/schemas/com.jerboa.db.AppDB/27.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
{
"formatVersion": 1,
"database": {
"version": 27,
"identityHash": "8e8aa32b002a7ce0d76dfb82e9309bd0",
"entities": [
{
"tableName": "Account",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `current` INTEGER NOT NULL, `instance` TEXT NOT NULL, `name` TEXT NOT NULL, `jwt` TEXT NOT NULL, `default_listing_type` INTEGER NOT NULL DEFAULT 0, `default_sort_type` INTEGER NOT NULL DEFAULT 0, `verification_state` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "current",
"columnName": "current",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "instance",
"columnName": "instance",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "jwt",
"columnName": "jwt",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "defaultListingType",
"columnName": "default_listing_type",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "defaultSortType",
"columnName": "default_sort_type",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "verificationState",
"columnName": "verification_state",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "AppSettings",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `font_size` INTEGER NOT NULL DEFAULT 16, `theme` INTEGER NOT NULL DEFAULT 0, `theme_color` INTEGER NOT NULL DEFAULT 0, `viewed_changelog` INTEGER NOT NULL DEFAULT 0, `post_view_mode` INTEGER NOT NULL DEFAULT 0, `show_bottom_nav` INTEGER NOT NULL DEFAULT 1, `post_navigation_gesture_mode` INTEGER NOT NULL DEFAULT 0, `show_collapsed_comment_content` INTEGER NOT NULL DEFAULT 0, `show_comment_action_bar_by_default` INTEGER NOT NULL DEFAULT 1, `show_voting_arrows_in_list_view` INTEGER NOT NULL DEFAULT 1, `show_parent_comment_navigation_buttons` INTEGER NOT NULL DEFAULT 0, `navigate_parent_comments_with_volume_buttons` INTEGER NOT NULL DEFAULT 0, `use_custom_tabs` INTEGER NOT NULL DEFAULT 1, `use_private_tabs` INTEGER NOT NULL DEFAULT 0, `secure_window` INTEGER NOT NULL DEFAULT 0, `blur_nsfw` INTEGER NOT NULL DEFAULT 1, `show_text_descriptions_in_navbar` INTEGER NOT NULL DEFAULT 1, `markAsReadOnScroll` INTEGER NOT NULL DEFAULT 0, `backConfirmationMode` INTEGER NOT NULL DEFAULT 1, `show_post_link_previews` INTEGER NOT NULL DEFAULT 1, `post_actionbar_mode` INTEGER NOT NULL DEFAULT 0, `auto_play_gifs` INTEGER NOT NULL DEFAULT 0, `swipe_to_action_preset` INTEGER NOT NULL DEFAULT 1)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "fontSize",
"columnName": "font_size",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "16"
},
{
"fieldPath": "theme",
"columnName": "theme",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "themeColor",
"columnName": "theme_color",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "viewedChangelog",
"columnName": "viewed_changelog",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "postViewMode",
"columnName": "post_view_mode",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "showBottomNav",
"columnName": "show_bottom_nav",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "postNavigationGestureMode",
"columnName": "post_navigation_gesture_mode",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "showCollapsedCommentContent",
"columnName": "show_collapsed_comment_content",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "showCommentActionBarByDefault",
"columnName": "show_comment_action_bar_by_default",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "showVotingArrowsInListView",
"columnName": "show_voting_arrows_in_list_view",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "showParentCommentNavigationButtons",
"columnName": "show_parent_comment_navigation_buttons",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "navigateParentCommentsWithVolumeButtons",
"columnName": "navigate_parent_comments_with_volume_buttons",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "useCustomTabs",
"columnName": "use_custom_tabs",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "usePrivateTabs",
"columnName": "use_private_tabs",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "secureWindow",
"columnName": "secure_window",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "blurNSFW",
"columnName": "blur_nsfw",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "showTextDescriptionsInNavbar",
"columnName": "show_text_descriptions_in_navbar",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "markAsReadOnScroll",
"columnName": "markAsReadOnScroll",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "backConfirmationMode",
"columnName": "backConfirmationMode",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "showPostLinkPreviews",
"columnName": "show_post_link_previews",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "postActionbarMode",
"columnName": "post_actionbar_mode",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "autoPlayGifs",
"columnName": "auto_play_gifs",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "swipeToActionPreset",
"columnName": "swipe_to_action_preset",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8e8aa32b002a7ce0d76dfb82e9309bd0')"
]
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class MainActivity : AppCompatActivity() {
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}

Expand Down Expand Up @@ -280,6 +281,7 @@ class MainActivity : AppCompatActivity() {
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}

Expand Down Expand Up @@ -320,6 +322,7 @@ class MainActivity : AppCompatActivity() {
onBack = appState::popBackStack,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}

Expand Down Expand Up @@ -357,6 +360,7 @@ class MainActivity : AppCompatActivity() {
drawerState = drawerState,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}

Expand Down Expand Up @@ -468,6 +472,7 @@ class MainActivity : AppCompatActivity() {
blurNSFW = appSettings.blurNSFW,
showPostLinkPreview = appSettings.showPostLinkPreviews,
postActionbarMode = appSettings.postActionbarMode,
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
}
Expand Down Expand Up @@ -501,6 +506,7 @@ class MainActivity : AppCompatActivity() {
blurNSFW = appSettings.blurNSFW,
showPostLinkPreview = appSettings.showPostLinkPreviews,
postActionbarMode = appSettings.postActionbarMode,
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/jerboa/db/AppDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.jerboa.db.dao.AccountDao
import com.jerboa.db.dao.AppSettingsDao
import com.jerboa.db.entity.Account
import com.jerboa.db.entity.AppSettings
import com.jerboa.feat.SwipeToActionPreset
import java.util.concurrent.Executors

val APP_SETTINGS_DEFAULT =
Expand Down Expand Up @@ -39,10 +40,11 @@ val APP_SETTINGS_DEFAULT =
showPostLinkPreviews = true,
postActionbarMode = 0,
autoPlayGifs = false,
swipeToActionPreset = SwipeToActionPreset.DEFAULT.ordinal,
)

@Database(
version = 26,
version = 27,
entities = [Account::class, AppSettings::class],
exportSchema = true,
)
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/jerboa/db/AppDBMigrations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,25 @@ val MIGRATION_26_25 =
}
}

val MIGRATION_26_27 =
object : Migration(26, 27) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED)
db.execSQL(
"ALTER TABLE AppSettings ADD COLUMN swipe_to_action_preset INTEGER NOT NULL DEFAULT 1",
)
}
}

val MIGRATION_27_26 =
object : Migration(27, 26) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"ALTER TABLE AppSettings DROP COLUMN swipe_to_action_preset",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android.database.sqlite.SQLiteException: near "DROP": syntax error (code 1 SQLITE_ERROR): , while compiling: ALTER TABLE AppSettings DROP COLUMN swipe_to_action_preset
                                                                                                    	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                                                    	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1045)

It seems that DROP operations aren't supported

@dessalines should we remove all these downgrade migrations? They don't work anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh. It's a surprise to me that SQLite doesn't support drop column in tables. It can be done via creating a separate table without that column (i looked into it and i guess that's how others do it)

I think separate PR should be created for downgrade migrations fix

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah probably, but the down migrations aren't really used. So it won't be priority

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its totally fine to remove them. One of the worst android bugs in existence: https://stackoverflow.com/questions/8045249/how-do-i-delete-column-from-sqlite-table-in-android

)
}
}

// Don't forget to test your migration with `./gradlew app:connectAndroidTest`
val MIGRATIONS_LIST =
arrayOf(
Expand Down Expand Up @@ -417,4 +436,6 @@ val MIGRATIONS_LIST =
MIGRATION_25_24,
MIGRATION_25_26,
MIGRATION_26_25,
MIGRATION_26_27,
MIGRATION_27_26,
)
5 changes: 5 additions & 0 deletions app/src/main/java/com/jerboa/db/entity/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@ data class AppSettings(
defaultValue = "0",
)
val autoPlayGifs: Boolean,
@ColumnInfo(
name = "swipe_to_action_preset",
defaultValue = "1",
)
val swipeToActionPreset: Int,
)
Loading