From cf53ffd5a249302f83935ad288f297f58ada7f1a Mon Sep 17 00:00:00 2001 From: Zion Huang Date: Fri, 21 Jul 2023 11:48:46 +0800 Subject: [PATCH] Remove import from Google Takeout --- .../ui/screens/settings/BackupAndRestore.kt | 13 ---- .../viewmodels/BackupRestoreViewModel.kt | 69 ------------------- app/src/main/res/values-DE/strings.xml | 5 -- app/src/main/res/values-cs/strings.xml | 5 -- app/src/main/res/values-es-rUS/strings.xml | 5 -- app/src/main/res/values-es/strings.xml | 5 -- app/src/main/res/values-fa-rIR/strings.xml | 5 -- app/src/main/res/values-fi-rFI/strings.xml | 5 -- app/src/main/res/values-fr-rFR/strings.xml | 5 -- app/src/main/res/values-hu/strings.xml | 5 -- app/src/main/res/values-id/strings.xml | 5 -- app/src/main/res/values-it/strings.xml | 5 -- app/src/main/res/values-ja-rJP/strings.xml | 5 -- app/src/main/res/values-ko-rKR/strings.xml | 5 -- app/src/main/res/values-ml-rIN/strings.xml | 5 -- app/src/main/res/values-nl/strings.xml | 5 -- app/src/main/res/values-or-rIN/strings.xml | 5 -- app/src/main/res/values-pa/strings.xml | 5 -- app/src/main/res/values-pt-rBR/strings.xml | 5 -- app/src/main/res/values-ru-rRU/strings.xml | 5 -- app/src/main/res/values-sv-rSE/strings.xml | 5 -- app/src/main/res/values-tr/strings.xml | 5 -- app/src/main/res/values-uk-rUA/strings.xml | 5 -- app/src/main/res/values-zh-rCN/strings.xml | 5 -- app/src/main/res/values-zh-rTW/strings.xml | 4 -- app/src/main/res/values/strings.xml | 5 -- 26 files changed, 201 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/settings/BackupAndRestore.kt b/app/src/main/java/com/zionhuang/music/ui/screens/settings/BackupAndRestore.kt index c3adc8ac7..2d8123902 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/settings/BackupAndRestore.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/settings/BackupAndRestore.kt @@ -39,11 +39,6 @@ fun BackupAndRestore( viewModel.restore(context, uri) } } - val importLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri -> - if (uri != null) { - viewModel.import(context, uri) - } - } Column( Modifier @@ -65,14 +60,6 @@ fun BackupAndRestore( restoreLauncher.launch(arrayOf("application/octet-stream")) } ) - PreferenceEntry( - title = stringResource(R.string.import_playlist), - description = stringResource(R.string.choose_csv_file_from_google_takeout), - icon = R.drawable.input, - onClick = { - importLauncher.launch(arrayOf("*/*")) - } - ) } TopAppBar( diff --git a/app/src/main/java/com/zionhuang/music/viewmodels/BackupRestoreViewModel.kt b/app/src/main/java/com/zionhuang/music/viewmodels/BackupRestoreViewModel.kt index a1483f963..60b92321f 100644 --- a/app/src/main/java/com/zionhuang/music/viewmodels/BackupRestoreViewModel.kt +++ b/app/src/main/java/com/zionhuang/music/viewmodels/BackupRestoreViewModel.kt @@ -3,31 +3,20 @@ package com.zionhuang.music.viewmodels import android.content.Context import android.content.Intent import android.net.Uri -import android.provider.OpenableColumns import android.widget.Toast import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.zionhuang.innertube.YouTube -import com.zionhuang.innertube.YouTube.MAX_GET_QUEUE_SIZE -import com.zionhuang.innertube.models.SongItem import com.zionhuang.music.MainActivity import com.zionhuang.music.R import com.zionhuang.music.db.InternalDatabase import com.zionhuang.music.db.MusicDatabase -import com.zionhuang.music.db.entities.PlaylistEntity -import com.zionhuang.music.db.entities.PlaylistEntity.Companion.generatePlaylistId -import com.zionhuang.music.db.entities.PlaylistSongMap import com.zionhuang.music.extensions.div import com.zionhuang.music.extensions.zipInputStream import com.zionhuang.music.extensions.zipOutputStream -import com.zionhuang.music.models.toMediaMetadata import com.zionhuang.music.playback.MusicService import com.zionhuang.music.playback.MusicService.Companion.PERSISTENT_QUEUE_FILE import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withContext import java.io.FileInputStream import java.io.FileOutputStream import java.util.zip.ZipEntry @@ -100,64 +89,6 @@ class BackupRestoreViewModel @Inject constructor( } } - fun import(context: Context, uri: Uri) { - runCatching { - val videoIds = mutableListOf() - context.applicationContext.contentResolver.openInputStream(uri)?.use { inputStream -> - val br = inputStream.bufferedReader() - repeat(8) { - br.readLine() - } - var line = br.readLine() - while (line != null) { - line.split(",").firstOrNull() - ?.takeIf { it.isNotEmpty() } - ?.let { - videoIds.add(it.trim()) - } - line = br.readLine() - } - } - val playlistName = context.contentResolver.query(uri, null, null, null, null)?.use { cursor -> - val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) - cursor.moveToFirst() - cursor.getString(nameIndex) - }?.removeSuffix(".csv") ?: context.getString(R.string.imported_playlist) - viewModelScope.launch { - val songs = videoIds.chunked(MAX_GET_QUEUE_SIZE).flatMap { - withContext(Dispatchers.IO) { - YouTube.queue(videoIds = it) - }.getOrNull().orEmpty() - } - database.transaction { - val playlistId = generatePlaylistId() - var position = 0 - insert( - PlaylistEntity( - id = playlistId, - name = playlistName - ) - ) - songs.map(SongItem::toMediaMetadata) - .onEach(::insert) - .forEach { - insert( - PlaylistSongMap( - playlistId = playlistId, - songId = it.id, - position = position++ - ) - ) - } - } - Toast.makeText(context, context.resources.getQuantityString(R.plurals.import_success, songs.size, playlistName, songs.size), Toast.LENGTH_SHORT).show() - } - }.onFailure { - it.printStackTrace() - Toast.makeText(context, R.string.restore_failed, Toast.LENGTH_SHORT).show() - } - } - companion object { const val SETTINGS_FILENAME = "settings.preferences_pb" } diff --git a/app/src/main/res/values-DE/strings.xml b/app/src/main/res/values-DE/strings.xml index 91956d310..6ab52387a 100644 --- a/app/src/main/res/values-DE/strings.xml +++ b/app/src/main/res/values-DE/strings.xml @@ -245,12 +245,7 @@ Sichern und Wiederherstellen Datensicherung Wiederherstellen - Wählen Sie eine csv-Datei von Google Takeout Importierte Wiedergabeliste - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Sicherung erfolgreich erstellt Konnte keine Sicherung erstellen Wiederherstellung der Sicherung fehlgeschlagen diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index ac442eef0..9bfaadd4b 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -256,12 +256,7 @@ Záloha a obnovení Zálohovat Obnovit - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Záloha úspěšně vytvořena Nepodařilo se vytvořit zálohu Nepodařilo se obnovit zálohu diff --git a/app/src/main/res/values-es-rUS/strings.xml b/app/src/main/res/values-es-rUS/strings.xml index 72f6d0757..94fbae973 100644 --- a/app/src/main/res/values-es-rUS/strings.xml +++ b/app/src/main/res/values-es-rUS/strings.xml @@ -245,12 +245,7 @@ Backup and restore Backup Restore - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup created successfully Couldn\'t create backup Failed to restore backup diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6f5acecfe..74f3e23ce 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -245,12 +245,7 @@ Copias de seguridad y restauración Hacer copia de seguridad Restaurar - Selecciona un archivo csv de Google Takeout Lista de reproducción importada - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Copia de seguridad creada con éxito No se ha podido crear la copia de seguridad Error al restaurar la copia de seguridad diff --git a/app/src/main/res/values-fa-rIR/strings.xml b/app/src/main/res/values-fa-rIR/strings.xml index 6119ae183..5f61dcbdf 100644 --- a/app/src/main/res/values-fa-rIR/strings.xml +++ b/app/src/main/res/values-fa-rIR/strings.xml @@ -245,12 +245,7 @@ پشتیبان‌گیری و بازگردانی پشتیبان‌گیری بازگردانی - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - پشتیبان باموفقیت ایجادشد پشتیبان ایجاد نشد بازیابی پشتیبان انجام‌نشد diff --git a/app/src/main/res/values-fi-rFI/strings.xml b/app/src/main/res/values-fi-rFI/strings.xml index 3e10ad5ab..850b0421b 100644 --- a/app/src/main/res/values-fi-rFI/strings.xml +++ b/app/src/main/res/values-fi-rFI/strings.xml @@ -245,12 +245,7 @@ Backup and restore Backup Restore - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup created successfully Couldn\'t create backup Failed to restore backup diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index ef0a46350..e6a268f3a 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -251,12 +251,7 @@ Backup and restore Backup Restore - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup created successfully Couldn\'t create backup Failed to restore backup diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index d3e6e5a1b..98b4c4caf 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -245,12 +245,7 @@ Bizt.mentés és visszaállítás Bizt.mentés Visszaállítás - Válasszon egy csv-fájlt a Google Takeout-ból Importált lejátszási lista - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - A bizt.mentés sikeresen létrehozva Nem sikerült biztonsági mentést készíteni Nem sikerült visszaállítani a biztonsági másolatot diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 7bd3e5aab..0ddad030f 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -239,12 +239,7 @@ Cadangkan dan pulihkan Cadangkan Pulihkan - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Cadangan berhasil dibuat Tidak dapat membuat cadangan Gagal untuk memulihkan cadangan diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 769ebf631..e83c2e89d 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -245,12 +245,7 @@ Backup e ripristino Backup Ripristina - Scegli un file csv da Google Takeout Playlist importata - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup creato con successo Impossibile eseguire il backup Impossibile eseguire il ripristino dal backup diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 6864ad314..f8ac56ecd 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -239,12 +239,7 @@ バックアップとリストア バックアップ リストア - Google TakeoutからCSVファイルを選択してください インポートしたプレイリスト - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - バックアップの作成に成功しました バックアップを作成できませんでした バックアップのリストアに失敗しました diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index 91832347e..389c5c058 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -239,12 +239,7 @@ Backup and restore Backup Restore - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup created successfully Couldn\'t create backup Failed to restore backup diff --git a/app/src/main/res/values-ml-rIN/strings.xml b/app/src/main/res/values-ml-rIN/strings.xml index fb805bb0f..5e639018d 100644 --- a/app/src/main/res/values-ml-rIN/strings.xml +++ b/app/src/main/res/values-ml-rIN/strings.xml @@ -245,12 +245,7 @@ ബാക്കപ്പും വീണ്ടെടുക്കലും ബാക്കപ്പ് വീണ്ടെടുക്കൽ - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - ബാക്കപ്പ് സൃഷ്‌ടിച്ചു ബാക്കപ്പ് സൃഷ്ടിക്കാൻ കഴിഞ്ഞില്ല ബാക്കപ്പ് പുനഃസ്ഥാപിക്കാൻ കഴിഞ്ഞില്ല diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 19ba9e86c..3bcd12365 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -245,12 +245,7 @@ Backup en herstel Backup Herstellen - Kies een csv-bestand van Google Takeout Afspeellijst geimporteerd - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Back-up succesvol gemaakt. Back-up maken mislukt. Fout bij terugzetten back-up. diff --git a/app/src/main/res/values-or-rIN/strings.xml b/app/src/main/res/values-or-rIN/strings.xml index dcc217e37..415e34cea 100644 --- a/app/src/main/res/values-or-rIN/strings.xml +++ b/app/src/main/res/values-or-rIN/strings.xml @@ -245,12 +245,7 @@ ନକଲ ସଂରକ୍ଷଣ ଏବଂ ପୁନରୁଦ୍ଧାର କରନ୍ତୁ ନକଲ ସଂରକ୍ଷଣ ପୁନରୁଦ୍ଧାର କରନ୍ତୁ - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - ବ୍ୟାକଅପ୍ ସଫଳତାର ସହିତ ସୃଷ୍ଟି ହେଲା ବ୍ୟାକଅପ୍ ସୃଷ୍ଟି କରିପାରିବ ନାହିଁ ବ୍ୟାକଅପ୍ ପୁନରୁଦ୍ଧାର କରିବାରେ ବିଫଳ diff --git a/app/src/main/res/values-pa/strings.xml b/app/src/main/res/values-pa/strings.xml index 1f3bc0015..c5a24cd3b 100644 --- a/app/src/main/res/values-pa/strings.xml +++ b/app/src/main/res/values-pa/strings.xml @@ -245,12 +245,7 @@ ਬੈਕਅੱਪ ਅਤੇ ਰੀਸਟੋਰ ਬੈਕਅੱਪ ਰੀਸਟੋਰ - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - ਬੈਕਅੱਪ ਸਫਲਤਾਪੂਰਵਕ ਬਣਾਇਆ ਗਿਆ ਬੈਕਅੱਪ ਨਹੀਂ ਬਣਾਇਆ ਜਾ ਸਕਿਆ ਬੈਕਅੱਪ ਰੀਸਟੋਰ ਕਰਨਾ ਅਸਫਲ ਰਿਹਾ diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index a68bc7db3..f605cf80a 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -245,12 +245,7 @@ Backup e restauração Backup Restaurar - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup criado com sucesso Não foi possível criar o backup Falha ao restaurar o backup diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index 7a93d09f9..c3c47e457 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -257,12 +257,7 @@ Резервное копирование Создать резервную копию Восстановить из резервной копии - Выбрать csv-файл из Google Takeout Импортированный плейлист - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Резервная копия создана успешно Не удалось создать резервную копию Не удалось восстановить резервную копию diff --git a/app/src/main/res/values-sv-rSE/strings.xml b/app/src/main/res/values-sv-rSE/strings.xml index 56ff8e4b5..c9baa8d75 100644 --- a/app/src/main/res/values-sv-rSE/strings.xml +++ b/app/src/main/res/values-sv-rSE/strings.xml @@ -245,12 +245,7 @@ Backup and restore Backup Restore - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup created successfully Couldn\'t create backup Failed to restore backup diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 674f8ea9a..1cea87bd7 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -245,12 +245,7 @@ Yedekleme ve geri yükleme Yedekle Geri yükle - Google Takeout\'tan bir csv dosyası seçin Çalma listesi içe aktarıldı - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Yedekleme başarıyla oluşturuldu Yedekleme oluşturulamadı Yedekleme geri yüklenemedi diff --git a/app/src/main/res/values-uk-rUA/strings.xml b/app/src/main/res/values-uk-rUA/strings.xml index 38dc763f8..ac0bfcb27 100644 --- a/app/src/main/res/values-uk-rUA/strings.xml +++ b/app/src/main/res/values-uk-rUA/strings.xml @@ -257,12 +257,7 @@ Резервне копіювання Створити резервну копію Відновити з резервної копії - Вибрати csv-файл із Google Takeout Імпортований плейлист - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Резервну копію створено успішно Не вдалося створити резервну копію Не вдалося відновити з резервної копії diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 39536f960..164fe8dd8 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -239,12 +239,7 @@ 备份与还原 备份 还原 - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - 成功新建备份 无法新建备份 无法还原备份 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index f3330bd9d..00bca50c4 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -236,11 +236,7 @@ 備份與還原 備份 還原 - 選擇從 Google Takeout 匯出的 csv 檔 已匯入的播放清單 - - 已匯入「%s」,有%d首歌曲 - 成功建立備份 無法建立備份 無法還原備份 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7101979dc..1eca7e5a7 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -244,12 +244,7 @@ Backup and restore Backup Restore - Choose a csv file from Google Takeout Imported playlist - - Imported \"%s\" with %d song - Imported \"%s\" with %d songs - Backup created successfully Couldn\'t create backup Failed to restore backup