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
8 changes: 5 additions & 3 deletions app/src/main/java/com/malopieds/innertune/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ class MainActivity : ComponentActivity() {

setContent {
LaunchedEffect(Unit) {
if (System.currentTimeMillis() - Updater.lastCheckTime > 1.days.inWholeMilliseconds) {
Updater.getLatestVersionName().onSuccess {
val checkForUpdates = dataStore.get(CheckForUpdatesKey, false)
if (checkForUpdates && System.currentTimeMillis() - Updater.lastCheckTime > 1.days.inWholeMilliseconds) {
val checkForPrereleases = dataStore.get(CheckForPrereleasesKey, false)
Updater.getLatestVersionName(checkForPrereleases).onSuccess {
latestVersionName = it
}
}
Expand Down Expand Up @@ -689,7 +691,7 @@ class MainActivity : ComponentActivity() {
) {
BadgedBox(
badge = {
if (latestVersionName != "v${BuildConfig.VERSION_NAME}") {
if (latestVersionName != "v${BuildConfig.VERSION_NAME}" && latestVersionName != "${BuildConfig.VERSION_NAME}") {
Badge()
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ val QuickPicksKey = stringPreferencesKey("discover")
val PreferredLyricsProviderKey = stringPreferencesKey("lyricsProvider")
val QueueEditLockKey = booleanPreferencesKey("queueEditLock")

val CheckForUpdatesKey = booleanPreferencesKey("checkForUpdates")
val CheckForPrereleasesKey = booleanPreferencesKey("checkForPrereleases")

enum class LibraryViewType {
LIST,
GRID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ import com.malopieds.innertune.LocalPlayerAwareWindowInsets
import com.malopieds.innertune.R
import com.malopieds.innertune.ui.component.IconButton
import com.malopieds.innertune.ui.utils.backToMain
import com.malopieds.innertune.constants.CheckForUpdatesKey
import com.malopieds.innertune.constants.CheckForPrereleasesKey
import com.malopieds.innertune.ui.component.SwitchPreference
import com.malopieds.innertune.utils.rememberPreference
import androidx.compose.animation.AnimatedVisibility

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AboutScreen(
navController: NavController,
scrollBehavior: TopAppBarScrollBehavior,
) {

val (checkForUpdates, onCheckForUpdatesChange) = rememberPreference(key = CheckForUpdatesKey, defaultValue = true)
val (checkForPrereleases, onCheckForPrereleasesChange) = rememberPreference(key = CheckForPrereleasesKey, defaultValue = false)

val uriHandler = LocalUriHandler.current

Column(
Expand Down Expand Up @@ -150,6 +159,22 @@ fun AboutScreen(
)
}
}

SwitchPreference(
title = { Text(stringResource(R.string.check_for_updates)) },
icon = { Icon(painterResource(R.drawable.update), null) },
checked = checkForUpdates,
onCheckedChange = onCheckForUpdatesChange,
)

AnimatedVisibility(checkForUpdates) {
SwitchPreference(
title = { Text(stringResource(R.string.check_for_prereleases)) },
icon = { Icon(painterResource(R.drawable.fast_forward), null) },
checked = checkForPrereleases,
onCheckedChange = onCheckForPrereleasesChange,
)
}
}

TopAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.malopieds.innertune.constants.ProxyTypeKey
import com.malopieds.innertune.constants.ProxyUrlKey
import com.malopieds.innertune.constants.QuickPicks
import com.malopieds.innertune.constants.QuickPicksKey
import com.malopieds.innertune.constants.StopMusicOnTaskClearKey
import com.malopieds.innertune.constants.SYSTEM_DEFAULT
import com.malopieds.innertune.constants.SimilarContent
import com.malopieds.innertune.constants.TopSize
Expand Down Expand Up @@ -88,6 +89,7 @@ fun ContentSettings(
val (defaultChip, onDefaultChipChange) = rememberEnumPreference(key = ChipSortTypeKey, defaultValue = LibraryFilter.LIBRARY)
val (quickPicks, onQuickPicksChange) = rememberEnumPreference(key = QuickPicksKey, defaultValue = QuickPicks.QUICK_PICKS)
val (similarContentEnabled, similarContentEnabledChange) = rememberPreference(key = SimilarContent, defaultValue = true)
val (stopMusicOnTaskClear, onStopMusicOnTaskClearChange) = rememberPreference(key = StopMusicOnTaskClearKey, defaultValue = false)

Column(
Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fun SettingsScreen(
icon = { Icon(painterResource(R.drawable.info), null) },
onClick = { navController.navigate("settings/about") },
)
if (latestVersionName != "v${BuildConfig.VERSION_NAME}") {
if (latestVersionName != "v${BuildConfig.VERSION_NAME}" && latestVersionName != "${BuildConfig.VERSION_NAME}") {
PreferenceEntry(
title = {
Text(
Expand All @@ -99,7 +99,7 @@ fun SettingsScreen(
}
},
onClick = {
uriHandler.openUri("https://github.com/Malopieds/InnerTune/releases/latest")
uriHandler.openUri("https://github.com/Malopieds/InnerTune/releases/tag/$latestVersionName")
},
)
}
Expand Down
33 changes: 29 additions & 4 deletions app/src/main/java/com/malopieds/innertune/utils/Updater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,42 @@ import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import org.json.JSONObject
import org.json.JSONArray

object Updater {
private val client = HttpClient()
var lastCheckTime = -1L
private set

suspend fun getLatestVersionName(): Result<String> =
suspend fun getLatestVersionName(checkForPrereleases: Boolean): Result<String> =
runCatching {
val response = client.get("https://api.github.com/repos/Malopieds/InnerTune/releases/latest").bodyAsText()
val json = JSONObject(response)
val versionName = json.getString("name")
val latestResponse = client.get("https://api.github.com/repos/Malopieds/InnerTune/releases/latest").bodyAsText()
val latestJson = JSONObject(latestResponse)

if (checkForPrereleases) {
val latestPublishedTime = latestJson.getString("published_at")

val releasesResponse = client.get("https://api.github.com/repos/Malopieds/InnerTune/releases").bodyAsText()
val releasesJson = JSONArray(releasesResponse)

repeat(releasesJson.length()) { index ->
val currentReleaseJson = releasesJson.getJSONObject(index)
val publishedTime = currentReleaseJson.getString("published_at")
if (publishedTime.compareTo(latestPublishedTime) > 0) {
val isPrerelease = currentReleaseJson.getBoolean("prerelease")
if (isPrerelease) {
val versionName = currentReleaseJson.getString("name")
lastCheckTime = System.currentTimeMillis()
return Result.success(versionName)
}
} else {
return@repeat
}
}
}

val versionName = latestJson.getString("name")

lastCheckTime = System.currentTimeMillis()
versionName
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@

<string name="about">About</string>
<string name="app_version">App version</string>
<string name="check_for_updates">Check for updates</string>
<string name="check_for_prereleases">Check for pre-releases</string>

<string name="new_version_available">New version available</string>
<string name="translation_models">Translation Models</string>
Expand Down