Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
281 changes: 281 additions & 0 deletions app/schemas/com.jerboa.db.AppDB/35.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
{
"formatVersion": 1,
"database": {
"version": 35,
"identityHash": "d5e8f8b3a1c9e2f4d6b7a0c3e5f1d2b4",
"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"
]
}
},
{
"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, `disable_video_autoplay` INTEGER NOT NULL DEFAULT 0, `low_bandwidth_mode` 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"
},
{
"fieldPath": "disableVideoAutoplay",
"columnName": "disable_video_autoplay",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "lowBandwidthMode",
"columnName": "low_bandwidth_mode",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
}
],
"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, 'd5e8f8b3a1c9e2f4d6b7a0c3e5f1d2b4')"
]
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jerboa

import android.content.Intent
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand All @@ -23,6 +24,7 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.getSystemService
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
Expand All @@ -34,6 +36,7 @@ import com.jerboa.feat.BackConfirmation.addConfirmationDialog
import com.jerboa.feat.BackConfirmation.addConfirmationToast
import com.jerboa.feat.BackConfirmation.disposeConfirmation
import com.jerboa.feat.BackConfirmationMode
import com.jerboa.feat.LowBandwidthMode
import com.jerboa.feat.ShowConfirmationDialog
import com.jerboa.model.AccountSettingsViewModel
import com.jerboa.model.AccountSettingsViewModelFactory
Expand Down Expand Up @@ -107,6 +110,10 @@ class MainActivity : AppCompatActivity() {
triggerRebirth(ctx)
}

val connectivityManager = ctx.getSystemService<ConnectivityManager>()
val lowBandwidthMode =
appSettings.lowBandwidthMode.toEnum<LowBandwidthMode>().isActive(connectivityManager)

if (appSettings.autoPlayGifs) {
Coil.setImageLoader((ctx.applicationContext as JerboaApplication).imageGifLoader)
} else {
Expand Down Expand Up @@ -152,6 +159,7 @@ class MainActivity : AppCompatActivity() {
appState,
appSettings.useCustomTabs,
appSettings.usePrivateTabs,
lowBandwidthMode,
object : BetterLinkMovementMethod.OnLinkLongClickListener {
override fun onLongClick(
textView: TextView,
Expand Down Expand Up @@ -230,6 +238,7 @@ class MainActivity : AppCompatActivity() {
appSettingsViewModel = appSettingsViewModel,
appSettings = appSettings,
drawerState = drawerState,
lowBandwidthMode = lowBandwidthMode,
)
}

Expand Down Expand Up @@ -259,6 +268,7 @@ class MainActivity : AppCompatActivity() {
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
disableVideoAutoplay = appSettings.disableVideoAutoplay.toBool(),
lowBandwidthMode = lowBandwidthMode,
)
}

Expand Down Expand Up @@ -304,6 +314,7 @@ class MainActivity : AppCompatActivity() {
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
disableVideoAutoplay = appSettings.disableVideoAutoplay.toBool(),
lowBandwidthMode = lowBandwidthMode,
)
}

Expand Down Expand Up @@ -347,6 +358,7 @@ class MainActivity : AppCompatActivity() {
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
disableVideoAutoplay = appSettings.disableVideoAutoplay.toBool(),
lowBandwidthMode = lowBandwidthMode,
)
}

Expand Down Expand Up @@ -387,6 +399,7 @@ class MainActivity : AppCompatActivity() {
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
disableVideoAutoplay = appSettings.disableVideoAutoplay.toBool(),
lowBandwidthMode = lowBandwidthMode,
)
}

Expand Down Expand Up @@ -535,6 +548,7 @@ class MainActivity : AppCompatActivity() {
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
disableVideoAutoplay = appSettings.disableVideoAutoplay.toBool(),
lowBandwidthMode = lowBandwidthMode,
)
}
}
Expand Down Expand Up @@ -570,6 +584,7 @@ class MainActivity : AppCompatActivity() {
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
disableVideoAutoplay = appSettings.disableVideoAutoplay.toBool(),
lowBandwidthMode = lowBandwidthMode,
)
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,17 @@ fun ConnectivityManager?.isCurrentlyConnected(): Boolean =
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
?: true

fun ConnectivityManager?.isConnectionMetered(): Boolean =
this
?.activeNetwork
?.let(::getNetworkCapabilities)
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
?.not()
?: false

fun ConnectivityManager?.isDataSaverEnabled(): Boolean =
this?.restrictBackgroundStatus == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED

/**
* When calling this, you must call ActivityResultLauncher.unregister()
* on the returned ActivityResultLauncher when the launcher is no longer
Expand Down
Loading