Skip to content
Closed
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
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@
android:scheme="archivetune" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="archivetune.koiiverse.cloud"
android:path="/share.html"
android:scheme="https" />
</intent-filter>
<!-- Youtube filter -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
Expand Down
68 changes: 17 additions & 51 deletions app/src/main/kotlin/moe/rukamori/archivetune/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ import moe.rukamori.archivetune.ui.theme.extractThemeColor
import moe.rukamori.archivetune.ui.utils.appBarScrollBehavior
import moe.rukamori.archivetune.ui.utils.backToMain
import moe.rukamori.archivetune.ui.utils.resetHeightOffset
import moe.rukamori.archivetune.utils.ArchiveTuneShareLinks
import moe.rukamori.archivetune.utils.PreferenceStore
import moe.rukamori.archivetune.utils.SyncUtils
import moe.rukamori.archivetune.utils.Updater
Expand Down Expand Up @@ -570,47 +571,6 @@ class MainActivity : ComponentActivity() {
val updateChannel by rememberEnumPreference(UpdateChannelKey, defaultValue = defaultUpdateChannel)

LaunchedEffect(Unit) {
while (playerConnection == null) {
delay(100)
}
delay(500)

try {
val redownload = withContext(Dispatchers.IO) {
dataStore.data.first()[moe.rukamori.archivetune.constants.RedownloadOnRestoreKey] ?: false
}
if (redownload) {
val downloaded = withContext(Dispatchers.IO) {
database.downloadedSongsList()
}
if (downloaded.isNotEmpty()) {
downloaded.forEach { song ->
val downloadRequest = androidx.media3.exoplayer.offline.DownloadRequest
.Builder(song.id, song.id.toUri())
.setCustomCacheKey(song.id)
.setData(song.title.toByteArray())
.build()
androidx.media3.exoplayer.offline.DownloadService.sendAddDownload(
this@MainActivity,
moe.rukamori.archivetune.playback.ExoDownloadService::class.java,
downloadRequest,
false,
)
}
withContext(Dispatchers.Main) {
Toast.makeText(this@MainActivity, "Re-downloading ${downloaded.size} offline songs...", Toast.LENGTH_LONG).show()
}
}
withContext(Dispatchers.IO) {
dataStore.edit { prefs ->
prefs[moe.rukamori.archivetune.constants.RedownloadOnRestoreKey] = false
}
}
}
} catch (e: Exception) {
moe.rukamori.archivetune.utils.reportException(e)
}

if (
BuildConfig.UPDATER_AVAILABLE &&
System.currentTimeMillis() - Updater.lastCheckTime > 1.days.inWholeMilliseconds
Expand Down Expand Up @@ -2707,9 +2667,17 @@ class MainActivity : ComponentActivity() {
return
}

when (val path = uri.pathSegments.firstOrNull()) {
val deepLinkUri =
ArchiveTuneShareLinks.toYouTubeMusicUri(uri)
?: if (ArchiveTuneShareLinks.isArchiveTuneShareUri(uri)) {
return
} else {
uri
}

when (val path = deepLinkUri.pathSegments.firstOrNull()) {
"playlist" -> {
uri.getQueryParameter("list")?.let { playlistId ->
deepLinkUri.getQueryParameter("list")?.let { playlistId ->
if (playlistId.startsWith("OLAK5uy_")) {
coroutineScope.launch {
YouTube
Expand All @@ -2727,26 +2695,26 @@ class MainActivity : ComponentActivity() {
}

"browse" -> {
uri.lastPathSegment?.let { browseId ->
deepLinkUri.lastPathSegment?.let { browseId ->
navController.navigate("album/$browseId")
}
}

"channel", "c" -> {
uri.lastPathSegment?.let { artistId ->
deepLinkUri.lastPathSegment?.let { artistId ->
navController.navigate("artist/$artistId")
}
}

else -> {
val videoId =
when {
path == "watch" -> uri.getQueryParameter("v")
uri.host == "youtu.be" -> uri.pathSegments.firstOrNull()
path == "watch" -> deepLinkUri.getQueryParameter("v")
deepLinkUri.host == "youtu.be" -> deepLinkUri.pathSegments.firstOrNull()
else -> null
}
val playlistId = uri.getQueryParameter("list")
val shouldShufflePlaylist = uri.requestsShuffledPlayback()
val playlistId = deepLinkUri.getQueryParameter("list")
val shouldShufflePlaylist = deepLinkUri.requestsShuffledPlayback()

videoId?.let { vid ->
coroutineScope.launch {
Expand Down Expand Up @@ -2886,14 +2854,12 @@ class MainActivity : ComponentActivity() {
BackupCategory.LIBRARY -> R.string.backup_category_library
BackupCategory.ACCOUNT -> R.string.backup_category_account
BackupCategory.SETTINGS -> R.string.backup_category_settings
BackupCategory.DOWNLOADS -> R.string.backup_category_downloads
}
val descRes =
when (category) {
BackupCategory.LIBRARY -> R.string.backup_category_library_desc
BackupCategory.ACCOUNT -> R.string.backup_category_account_desc
BackupCategory.SETTINGS -> R.string.backup_category_settings_desc
BackupCategory.DOWNLOADS -> R.string.backup_category_downloads_desc
}
Surface(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,18 @@ private fun RestoreOptionsDialog(
BackupCategory.LIBRARY -> R.string.backup_category_library
BackupCategory.ACCOUNT -> R.string.backup_category_account
BackupCategory.SETTINGS -> R.string.backup_category_settings
BackupCategory.DOWNLOADS -> R.string.backup_category_downloads
}
val descRes =
when (category) {
BackupCategory.LIBRARY -> R.string.backup_category_library_desc
BackupCategory.ACCOUNT -> R.string.backup_category_account_desc
BackupCategory.SETTINGS -> R.string.backup_category_settings_desc
BackupCategory.DOWNLOADS -> R.string.backup_category_downloads_desc
}
val iconRes =
when (category) {
BackupCategory.LIBRARY -> R.drawable.library_music
BackupCategory.ACCOUNT -> R.drawable.account
BackupCategory.SETTINGS -> R.drawable.settings
BackupCategory.DOWNLOADS -> R.drawable.download
}
Surface(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,4 @@ enum class BackupArchiveCategory {
LIBRARY,
ACCOUNT,
SETTINGS,
DOWNLOADS,
}
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,6 @@ val CanaryReleasesFingerprintKey = stringPreferencesKey("daily_nightly_releases_

val TogetherOnlineEndpointCacheKey = stringPreferencesKey("together_online_endpoint_cache")
val TogetherOnlineEndpointLastCheckedAtKey = longPreferencesKey("together_online_endpoint_last_checked_at")

val RedownloadOnRestoreKey = booleanPreferencesKey("redownloadOnRestore")

enum class UpdateChannel {
STABLE,
CANARY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ import java.util.Locale

@Dao
interface DatabaseDao {
@Transaction
@Query("SELECT song.* FROM song INNER JOIN format ON format.id = song.id WHERE song.isLocal = 0")
fun downloadedSongsList(): List<Song>

@Transaction
@Query("SELECT * FROM song WHERE inLibrary IS NOT NULL ORDER BY rowId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fun shareLyricsAsText(
payload: LyricsSharePayload,
songId: String?,
) {
val songLink = songId?.takeIf { it.isNotBlank() }?.let { "https://music.youtube.com/watch?v=$it" }
val songLink = songId?.takeIf { it.isNotBlank() }?.let { moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildSongShareUrl(it) }
val shareBody =
buildString {
append("\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ fun AlbumMenu(
type = "text/plain"
putExtra(
Intent.EXTRA_TEXT,
"https://music.youtube.com/playlist?list=${album.album.playlistId}",
moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildAlbumShareUrl(album.album.id),
)
}
context.startActivity(Intent.createChooser(intent, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fun ArtistMenu(
type = "text/plain"
putExtra(
Intent.EXTRA_TEXT,
"https://music.youtube.com/channel/${artist.id}",
moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildChannelShareUrl(artist.id),
)
}
context.startActivity(Intent.createChooser(intent, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ fun PlayerMenu(
val clip =
android.content.ClipData.newPlainText(
context.getString(R.string.copy_link),
"https://music.youtube.com/watch?v=${mediaMetadata.id}",
moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildSongShareUrl(mediaMetadata.id),
)
clipboard.setPrimaryClip(clip)
android.widget.Toast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public fun PlaylistMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "https://music.youtube.com/playlist?list=${dbPlaylist?.playlist?.browseId}")
putExtra(Intent.EXTRA_TEXT, dbPlaylist?.playlist?.browseId?.let { moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildPlaylistShareUrl(it) }.orEmpty())
}
context.startActivity(Intent.createChooser(intent, null))
},
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public fun PlaylistMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, shareLink)
putExtra(Intent.EXTRA_TEXT, moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.fromYouTubeMusicShareUrl(shareLink))
}
context.startActivity(Intent.createChooser(intent, null))
onDismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ fun SongMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "https://music.youtube.com/watch?v=${song.id}")
putExtra(Intent.EXTRA_TEXT, moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildSongShareUrl(song.id))
}
context.startActivity(Intent.createChooser(intent, null))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fun YouTubeAlbumMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, albumItem.shareLink)
putExtra(Intent.EXTRA_TEXT, moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildAlbumShareUrl(albumItem.browseId))
}
context.startActivity(Intent.createChooser(intent, null))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fun YouTubeArtistMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, artist.shareLink)
putExtra(Intent.EXTRA_TEXT, moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildChannelShareUrl(artist.id))
}
context.startActivity(Intent.createChooser(intent, null))
onDismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ fun YouTubePlaylistMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, playlist.shareLink)
putExtra(Intent.EXTRA_TEXT, moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildPlaylistShareUrl(playlist.id))
}
context.startActivity(Intent.createChooser(intent, null))
onDismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ fun YouTubeSongMenu(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, song.shareLink)
putExtra(Intent.EXTRA_TEXT, moe.rukamori.archivetune.utils.ArchiveTuneShareLinks.buildSongShareUrl(song.id))
}
context.startActivity(Intent.createChooser(intent, null))
onDismiss()
Expand Down
Loading
Loading