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

Fix migrations 1 #1446

Merged
merged 5 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
272 changes: 272 additions & 0 deletions app/schemas/com.jerboa.db.AppDB/32.json
@@ -0,0 +1,272 @@
{
"formatVersion": 1,
"database": {
"version": 32,
"identityHash": "99bc8f49ded581785ce3c6aba1422623",
"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, `is_admin` INTEGER NOT NULL, `is_mod` INTEGER NOT NULL, 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"
},
{
"fieldPath": "isAdmin",
"columnName": "is_admin",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isMod",
"columnName": "is_mod",
"affinity": "INTEGER",
"notNull": true
}
],
"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, `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 0, `last_version_code_viewed` INTEGER NOT NULL DEFAULT 0)",
"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": "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": "0"
},
{
"fieldPath": "lastVersionCodeViewed",
"columnName": "last_version_code_viewed",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"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, '99bc8f49ded581785ce3c6aba1422623')"
]
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/jerboa/Utils.kt
Expand Up @@ -1544,3 +1544,5 @@ fun Context.getVersionCode(): Int =
@Suppress("DEPRECATION")
getPackageInfo().versionCode
}

fun Int.toBool() = if (this > 0) true else false
78 changes: 53 additions & 25 deletions app/src/main/java/com/jerboa/db/AppDB.kt
Expand Up @@ -11,41 +11,69 @@ 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 com.jerboa.toBool
import com.jerboa.ui.theme.DEFAULT_FONT_SIZE
import java.util.concurrent.Executors

// Warning: Be careful about changing any of these defaults, as it will mean you'll need to
// regenerate the database
// Unfortunately can't use enum ordinals here, because Room's compile time annotations
// don't allow it
//
// Use Int for Bools
const val DEFAULT_THEME = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

I really wanted to be able to use the Enums and ordinals here, but Room makes you use constants for their currentValue annotations.

const val DEFAULT_THEME_COLOR = 0
const val DEFAULT_LAST_VERSION_CODE_VIEWED = 0
const val DEFAULT_POST_VIEW_MODE = 0
const val DEFAULT_POST_NAVIGATION_GESTURE_MODE = 0
const val DEFAULT_SHOW_BOTTOM_NAV = 1
const val DEFAULT_SHOW_COLLAPSED_COMMENT_CONTENT = 0
const val DEFAULT_SHOW_COMMENT_ACTION_BAR_BY_DEFAULT = 1
const val DEFAULT_SHOW_VOTING_ARROWS_IN_LIST_VIEW = 1
const val DEFAULT_SHOW_PARENT_COMMENT_NAVIGATION_BUTTONS = 0
const val DEFAULT_NAVIGATE_PARENT_COMMENTS_WITH_VOLUME_BUTTONS = 0
const val DEFAULT_USE_CUSTOM_TABS = 1
const val DEFAULT_USE_PRIVATE_TABS = 0
const val DEFAULT_SECURE_WINDOW = 0
const val DEFAULT_BLUR_NSFW = 1
const val DEFAULT_SHOW_TEXT_DESCRIPTIONS_IN_NAVBAR = 1
const val DEFAULT_BACK_CONFIRMATION_MODE = 1
const val DEFAULT_MARK_AS_READ_ON_SCROLL = 0
const val DEFAULT_SHOW_POST_LINK_PREVIEWS = 1
const val DEFAULT_POST_ACTION_BAR_MODE = 0
const val DEFAULT_AUTO_PLAY_GIFS = 0
const val DEFAULT_SWIPE_TO_ACTION_PRESET = 0

val APP_SETTINGS_DEFAULT =
AppSettings(
id = 1,
fontSize = DEFAULT_FONT_SIZE,
theme = 0,
themeColor = 0,
viewedChangelog = 0,
lastVersionCodeViewed = 0,
postViewMode = 0,
postNavigationGestureMode = 0,
showBottomNav = true,
showCollapsedCommentContent = false,
showCommentActionBarByDefault = true,
showVotingArrowsInListView = true,
showParentCommentNavigationButtons = false,
navigateParentCommentsWithVolumeButtons = false,
useCustomTabs = true,
usePrivateTabs = false,
secureWindow = false,
blurNSFW = 1,
showTextDescriptionsInNavbar = true,
backConfirmationMode = 1,
markAsReadOnScroll = false,
showPostLinkPreviews = true,
postActionBarMode = 0,
autoPlayGifs = false,
swipeToActionPreset = SwipeToActionPreset.DISABLED.ordinal,
theme = DEFAULT_THEME,
themeColor = DEFAULT_THEME_COLOR,
lastVersionCodeViewed = DEFAULT_LAST_VERSION_CODE_VIEWED,
postViewMode = DEFAULT_POST_VIEW_MODE,
postNavigationGestureMode = DEFAULT_POST_NAVIGATION_GESTURE_MODE,
showBottomNav = DEFAULT_SHOW_BOTTOM_NAV.toBool(),
showCollapsedCommentContent = DEFAULT_SHOW_COLLAPSED_COMMENT_CONTENT.toBool(),
showCommentActionBarByDefault = DEFAULT_SHOW_COMMENT_ACTION_BAR_BY_DEFAULT.toBool(),
showVotingArrowsInListView = DEFAULT_SHOW_VOTING_ARROWS_IN_LIST_VIEW.toBool(),
showParentCommentNavigationButtons = DEFAULT_SHOW_PARENT_COMMENT_NAVIGATION_BUTTONS.toBool(),
navigateParentCommentsWithVolumeButtons = DEFAULT_NAVIGATE_PARENT_COMMENTS_WITH_VOLUME_BUTTONS.toBool(),
useCustomTabs = DEFAULT_USE_CUSTOM_TABS.toBool(),
usePrivateTabs = DEFAULT_USE_PRIVATE_TABS.toBool(),
secureWindow = DEFAULT_SECURE_WINDOW.toBool(),
blurNSFW = DEFAULT_BLUR_NSFW,
showTextDescriptionsInNavbar = DEFAULT_SHOW_TEXT_DESCRIPTIONS_IN_NAVBAR.toBool(),
backConfirmationMode = DEFAULT_BACK_CONFIRMATION_MODE,
markAsReadOnScroll = DEFAULT_MARK_AS_READ_ON_SCROLL.toBool(),
showPostLinkPreviews = DEFAULT_SHOW_POST_LINK_PREVIEWS.toBool(),
postActionBarMode = DEFAULT_POST_ACTION_BAR_MODE,
autoPlayGifs = DEFAULT_AUTO_PLAY_GIFS.toBool(),
swipeToActionPreset = DEFAULT_SWIPE_TO_ACTION_PRESET,
)

@Database(
version = 31,
version = 32,
entities = [Account::class, AppSettings::class],
exportSchema = true,
)
Expand Down