From 1218eb53d5602e810ac6f666f976243d033784e2 Mon Sep 17 00:00:00 2001 From: XelXen <78258352+XelXen@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:33:41 +0530 Subject: [PATCH 001/115] Build Bot API --- .github/tg.py | 14 +++++----- .github/workflows/api-compiler.yml | 41 ++++++++++++++++++++++++++++++ .github/workflows/tg-bot.yml | 6 ++++- 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/api-compiler.yml diff --git a/.github/tg.py b/.github/tg.py index befaab722..08536fb55 100644 --- a/.github/tg.py +++ b/.github/tg.py @@ -1,21 +1,21 @@ import telegram -from tgconfig import TG_TOKEN +from tgconfig import * from json import load f = open('commit.json') data = load(f) f.close() -TG_CHAT_ID = "-1001537505605" +TG_POST_ID = "-1001537505605" bot = telegram.Bot(TG_TOKEN) -bot.send_photo(TG_CHAT_ID, open('alpha.png', 'rb'), f'''*Libretube {data['sha'][0:7]} // Alpha* +bot.send_photo(TG_POST_ID, open('alpha.png', 'rb'), f'''*Libretube {data['sha'][0:7]} // Alpha* {data['commit']['message']} Signed-off-by: {data['commit']['author']['name']} ''', parse_mode=telegram.ParseMode.MARKDOWN) -bot.send_document(TG_CHAT_ID, open('app-arm64-v8a-debug.apk', 'rb')) -bot.send_document(TG_CHAT_ID, open('app-armeabi-v7a-debug.apk', 'rb')) -bot.send_document(TG_CHAT_ID, open('app-x86_64-debug.apk', 'rb')) -bot.send_document(TG_CHAT_ID, open('app-x86-debug.apk', 'rb')) +bot.send_document(TG_POST_ID, open('app-arm64-v8a-debug.apk', 'rb')) +bot.send_document(TG_POST_ID, open('app-armeabi-v7a-debug.apk', 'rb')) +bot.send_document(TG_POST_ID, open('app-x86_64-debug.apk', 'rb')) +bot.send_document(TG_POST_ID, open('app-x86-debug.apk', 'rb')) diff --git a/.github/workflows/api-compiler.yml b/.github/workflows/api-compiler.yml new file mode 100644 index 000000000..62e2906c3 --- /dev/null +++ b/.github/workflows/api-compiler.yml @@ -0,0 +1,41 @@ +name: Bot API Compiler + +on: + workflow_dispatch: + +jobs: + debug-builds: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Prepare for Compilation + run: | + sudo apt-get update + sudo apt-get upgrade + sudo apt-get install make git zlib1g-dev libssl-dev gperf cmake g++ + git config --global user.name "XelXen" + git config --global user.email "78258352+XelXen@users.noreply.github.com" + git config --global credential.helper store + echo "https://XelXen:${{ secrets.GH_TOKEN }}@github.com" > ~/.git-credentials + git clone --recursive https://github.com/tdlib/telegram-bot-api.git + cd telegram-bot-api + rm -rf build + mkdir build + cd build + + - name: Patch and Compile + run: | + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=.. .. + cmake --build . --target install + + - name: Binary Archive + run: | + cd ../.. + git clone https://github.com/LibreTubeAlpha/Telegram-BotAPI bot-api + rm -rf bot-api/* + mv ./telegram-bot-api/bin/telegram-bot-api ./bot-api/exec + cd bot-api + git add -f * + git commit -m "WORKFLOW: BUILD BINARIES" + git push -u \ No newline at end of file diff --git a/.github/workflows/tg-bot.yml b/.github/workflows/tg-bot.yml index ef6e1bbf9..401fccef8 100644 --- a/.github/workflows/tg-bot.yml +++ b/.github/workflows/tg-bot.yml @@ -1,4 +1,4 @@ -name: Telegram Builder +name: Telegram Bot on: workflow_dispatch: @@ -39,7 +39,11 @@ jobs: mv ./app/build/outputs/apk/debug/*.apk .github/ cd .github curl https://libre-tube.github.io/assets/LibreAlpha.png --output alpha.png + curl https://raw.githubusercontent.com/LibreTubeAlpha/Telegram-BotAPI/main/bin/telegram-bot-api --output bot-api echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" > tgconfig.py + echo "TG_POST_ID = '${{ secrets.TG_POST_ID }}'" >> tgconfig.py + echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py + echo "TG_API_HASH = '${{ secrets.TG_API_HASH }}'" >> tgconfig.py curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json python -m pip install --upgrade pip pip install python-telegram-bot From 72a97574b7b182744277208ce61c531cbc97c011 Mon Sep 17 00:00:00 2001 From: XelXen <78258352+XelXen@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:46:07 +0530 Subject: [PATCH 002/115] Seperate Compiler Script --- .github/compiler.sh | 12 ++++++++++++ .github/workflows/api-compiler.yml | 14 +++----------- 2 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 .github/compiler.sh diff --git a/.github/compiler.sh b/.github/compiler.sh new file mode 100644 index 000000000..7a65710f8 --- /dev/null +++ b/.github/compiler.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +cd ~ +sudo apt-get update -y +sudo apt-get upgrade -y +sudo apt-get install -y make git zlib1g-dev libssl-dev gperf cmake clang-10 libc++-dev libc++abi-dev +git clone --recursive https://github.com/tdlib/telegram-bot-api.git +rm -rf telegram-bot-api/build +mkdir -p telegram-bot-api/build +cd telegram-bot-api/build +CXXFLAGS="-stdlib=libc++" CC=/usr/bin/clang-10 CXX=/usr/bin/clang++-10 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=.. .. +cmake --build . --target install \ No newline at end of file diff --git a/.github/workflows/api-compiler.yml b/.github/workflows/api-compiler.yml index 62e2906c3..f534b8f47 100644 --- a/.github/workflows/api-compiler.yml +++ b/.github/workflows/api-compiler.yml @@ -11,23 +11,15 @@ jobs: - name: Prepare for Compilation run: | - sudo apt-get update - sudo apt-get upgrade - sudo apt-get install make git zlib1g-dev libssl-dev gperf cmake g++ git config --global user.name "XelXen" git config --global user.email "78258352+XelXen@users.noreply.github.com" git config --global credential.helper store echo "https://XelXen:${{ secrets.GH_TOKEN }}@github.com" > ~/.git-credentials - git clone --recursive https://github.com/tdlib/telegram-bot-api.git - cd telegram-bot-api - rm -rf build - mkdir build - cd build - - name: Patch and Compile + - name: Run Script run: | - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=.. .. - cmake --build . --target install + chmod 755 .github/compiler.sh + .github/compiler.sh - name: Binary Archive run: | From bfae793ad61a4b60487e1f1a62fb50716d7d3790 Mon Sep 17 00:00:00 2001 From: XelXen <78258352+XelXen@users.noreply.github.com> Date: Fri, 17 Jun 2022 14:30:48 +0530 Subject: [PATCH 003/115] Seperate Compiler Script --- .github/workflows/api-compiler.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/api-compiler.yml b/.github/workflows/api-compiler.yml index f534b8f47..0424edc91 100644 --- a/.github/workflows/api-compiler.yml +++ b/.github/workflows/api-compiler.yml @@ -23,10 +23,9 @@ jobs: - name: Binary Archive run: | - cd ../.. git clone https://github.com/LibreTubeAlpha/Telegram-BotAPI bot-api rm -rf bot-api/* - mv ./telegram-bot-api/bin/telegram-bot-api ./bot-api/exec + mv telegram-bot-api bot-api/exec cd bot-api git add -f * git commit -m "WORKFLOW: BUILD BINARIES" From 44dd1d6c2a5cf7a878e6dd07edef70ef2d2a30ac Mon Sep 17 00:00:00 2001 From: XelXen <78258352+XelXen@users.noreply.github.com> Date: Fri, 17 Jun 2022 14:35:15 +0530 Subject: [PATCH 004/115] Switch to private channel --- .github/workflows/tg-bot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tg-bot.yml b/.github/workflows/tg-bot.yml index 401fccef8..1e092e6eb 100644 --- a/.github/workflows/tg-bot.yml +++ b/.github/workflows/tg-bot.yml @@ -41,7 +41,7 @@ jobs: curl https://libre-tube.github.io/assets/LibreAlpha.png --output alpha.png curl https://raw.githubusercontent.com/LibreTubeAlpha/Telegram-BotAPI/main/bin/telegram-bot-api --output bot-api echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" > tgconfig.py - echo "TG_POST_ID = '${{ secrets.TG_POST_ID }}'" >> tgconfig.py + echo "TG_POST_ID = '-1001797185102'" >> tgconfig.py echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py echo "TG_API_HASH = '${{ secrets.TG_API_HASH }}'" >> tgconfig.py curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json From 85e074b35122e8b29468ca9956d9011a0849084a Mon Sep 17 00:00:00 2001 From: XelXen <78258352+XelXen@users.noreply.github.com> Date: Fri, 17 Jun 2022 15:32:00 +0530 Subject: [PATCH 005/115] Fix More stuff --- .github/tg.py | 2 -- .github/workflows/api-compiler.yml | 2 +- .github/workflows/tg-bot.yml | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/tg.py b/.github/tg.py index 08536fb55..d5063221f 100644 --- a/.github/tg.py +++ b/.github/tg.py @@ -6,9 +6,7 @@ f = open('commit.json') data = load(f) f.close() -TG_POST_ID = "-1001537505605" bot = telegram.Bot(TG_TOKEN) - bot.send_photo(TG_POST_ID, open('alpha.png', 'rb'), f'''*Libretube {data['sha'][0:7]} // Alpha* {data['commit']['message']} diff --git a/.github/workflows/api-compiler.yml b/.github/workflows/api-compiler.yml index 0424edc91..176c2d079 100644 --- a/.github/workflows/api-compiler.yml +++ b/.github/workflows/api-compiler.yml @@ -25,7 +25,7 @@ jobs: run: | git clone https://github.com/LibreTubeAlpha/Telegram-BotAPI bot-api rm -rf bot-api/* - mv telegram-bot-api bot-api/exec + mv ~/telegram-bot-api/bin/telegram-bot-api bot-api/exec cd bot-api git add -f * git commit -m "WORKFLOW: BUILD BINARIES" diff --git a/.github/workflows/tg-bot.yml b/.github/workflows/tg-bot.yml index 1e092e6eb..3845c98a1 100644 --- a/.github/workflows/tg-bot.yml +++ b/.github/workflows/tg-bot.yml @@ -41,8 +41,8 @@ jobs: curl https://libre-tube.github.io/assets/LibreAlpha.png --output alpha.png curl https://raw.githubusercontent.com/LibreTubeAlpha/Telegram-BotAPI/main/bin/telegram-bot-api --output bot-api echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" > tgconfig.py - echo "TG_POST_ID = '-1001797185102'" >> tgconfig.py echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py + echo "TG_POST_ID = '${{ secrets.TG_POST_ID }}'" >> tgconfig.py echo "TG_API_HASH = '${{ secrets.TG_API_HASH }}'" >> tgconfig.py curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json python -m pip install --upgrade pip From bf2ac255670943ccd08d57b34e09b0d9dba46e26 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 17 Jun 2022 16:32:24 +0200 Subject: [PATCH 006/115] fix colors --- app/src/main/res/layout/channel_subscription_row.xml | 2 +- app/src/main/res/layout/fragment_channel.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/channel_subscription_row.xml b/app/src/main/res/layout/channel_subscription_row.xml index 9085e93b2..746ef9fd9 100644 --- a/app/src/main/res/layout/channel_subscription_row.xml +++ b/app/src/main/res/layout/channel_subscription_row.xml @@ -36,6 +36,6 @@ android:backgroundTint="?attr/colorOnPrimary" android:text="@string/unsubscribe" android:textSize="11dp" - android:textColor="@android:color/white" + android:textColor="?android:attr/textColorPrimary" app:cornerRadius="20dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index a594e3de8..d37bc0a14 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -83,7 +83,7 @@ android:textColor="@android:color/white" android:textSize="11sp" android:drawableLeft="@drawable/ic_bell_small" - android:drawableTint="@android:color/white" /> + android:drawableTint="?android:attr/textColorPrimary" /> From fc9fbb0db2887daa062b7b0157cbe4094fc9cf19 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 17 Jun 2022 16:39:05 +0200 Subject: [PATCH 007/115] added missing translations --- .../java/com/github/libretube/DownloadService.kt | 14 +++++++------- .../com/github/libretube/dialogs/DownloadDialog.kt | 4 ++-- app/src/main/res/values/strings.xml | 5 +++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index 217a7f99a..4b3bfb70a 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -113,15 +113,15 @@ class DownloadService : Service() { "mux" -> { audioDir = File(tempDir, "$videoId-audio") videoDir = File(tempDir, "$videoId-video") - downloadId = downloadManagerRequest("Video", "Downloading", videoUrl, videoDir) + downloadId = downloadManagerRequest(getString(R.string.video), getString(R.string.downloading), videoUrl, videoDir) } "video" -> { videoDir = File(libretubeDir, "$videoId-video") - downloadId = downloadManagerRequest("Video", "Downloading", videoUrl, videoDir) + downloadId = downloadManagerRequest(getString(R.string.video), getString(R.string.downloading), videoUrl, videoDir) } "audio" -> { audioDir = File(libretubeDir, "$videoId-audio") - downloadId = downloadManagerRequest("Audio", "Downloading", audioUrl, audioDir) + downloadId = downloadManagerRequest(getString(R.string.audio), getString(R.string.downloading), audioUrl, audioDir) } } } catch (e: IllegalArgumentException) { @@ -136,7 +136,7 @@ class DownloadService : Service() { // Checking if the received broadcast is for our enqueued download by matching download id if (downloadId == id) { if (downloadType == "mux") { - downloadManagerRequest("Audio", "Downloading", audioUrl, audioDir) + downloadManagerRequest(getString(R.string.video), getString(R.string.downloading), audioUrl, audioDir) } else { downloadSucceededNotification() onDestroy() @@ -178,7 +178,7 @@ class DownloadService : Service() { NotificationCompat.Builder(this@DownloadService, "download_service") .setSmallIcon(R.drawable.ic_download) .setContentTitle("LibreTube") - .setContentText("Downloading") + .setContentText(getString(R.string.downloading)) .setPriority(NotificationCompat.PRIORITY_LOW) .setOngoing(true) .setOnlyAlertOnce(true) @@ -192,7 +192,7 @@ class DownloadService : Service() { val builder = NotificationCompat.Builder(this@DownloadService, "download_service") .setSmallIcon(R.drawable.ic_download) .setContentTitle(resources.getString(R.string.downloadfailed)) - .setContentText("failure") + .setContentText(getString(R.string.fail)) .setPriority(NotificationCompat.PRIORITY_HIGH) with(NotificationManagerCompat.from(this@DownloadService)) { // notificationId is a unique int for each notification that you must define @@ -205,7 +205,7 @@ class DownloadService : Service() { val builder = NotificationCompat.Builder(this@DownloadService, "download_service") .setSmallIcon(R.drawable.ic_download) .setContentTitle(resources.getString(R.string.success)) - .setContentText("success") + .setContentText(getString(R.string.fail)) .setPriority(NotificationCompat.PRIORITY_HIGH) with(NotificationManagerCompat.from(this@DownloadService)) { // notificationId is a unique int for each notification that you must define diff --git a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt index d01b2ff1b..7e71a21e7 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt @@ -71,7 +71,7 @@ class DownloadDialog : DialogFragment() { } } var vidName = arrayListOf() - vidName.add("No video") + vidName.add(getString(R.string.no_video)) var vidUrl = arrayListOf() vidUrl.add("") for (vid in streams.videoStreams!!) { @@ -80,7 +80,7 @@ class DownloadDialog : DialogFragment() { vidUrl.add(vid.url!!) } var audioName = arrayListOf() - audioName.add("No audio") + audioName.add(getString(R.string.no_audio)) var audioUrl = arrayListOf() audioUrl.add("") for (audio in streams.audioStreams!!) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 82603e8da..d0b43c9ff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -184,4 +184,9 @@ Preloading Max. amount of seconds of video to buffer. Video format for player + No audio + No video + Audio + Video + Downloading From 9c32112dde51c37258f80c5bb3724de81f942f00 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 17 Jun 2022 16:50:48 +0200 Subject: [PATCH 008/115] ktlint --- .../com/github/libretube/DownloadService.kt | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index 4b3bfb70a..db52515d6 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -113,15 +113,30 @@ class DownloadService : Service() { "mux" -> { audioDir = File(tempDir, "$videoId-audio") videoDir = File(tempDir, "$videoId-video") - downloadId = downloadManagerRequest(getString(R.string.video), getString(R.string.downloading), videoUrl, videoDir) + downloadId = downloadManagerRequest( + getString(R.string.video), + getString(R.string.downloading), + videoUrl, + videoDir + ) } "video" -> { videoDir = File(libretubeDir, "$videoId-video") - downloadId = downloadManagerRequest(getString(R.string.video), getString(R.string.downloading), videoUrl, videoDir) + downloadId = downloadManagerRequest( + getString(R.string.video), + getString(R.string.downloading), + videoUrl, + videoDir + ) } "audio" -> { audioDir = File(libretubeDir, "$videoId-audio") - downloadId = downloadManagerRequest(getString(R.string.audio), getString(R.string.downloading), audioUrl, audioDir) + downloadId = downloadManagerRequest( + getString(R.string.audio), + getString(R.string.downloading), + audioUrl, + audioDir + ) } } } catch (e: IllegalArgumentException) { @@ -136,7 +151,12 @@ class DownloadService : Service() { // Checking if the received broadcast is for our enqueued download by matching download id if (downloadId == id) { if (downloadType == "mux") { - downloadManagerRequest(getString(R.string.video), getString(R.string.downloading), audioUrl, audioDir) + downloadManagerRequest( + getString(R.string.video), + getString(R.string.downloading), + audioUrl, + audioDir + ) } else { downloadSucceededNotification() onDestroy() From 10d15a900a0da2293b899d1843b2a5350de6e85e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 17 Jun 2022 17:03:17 +0200 Subject: [PATCH 009/115] default selection downloads --- .../com/github/libretube/DownloadService.kt | 2 +- .../libretube/dialogs/DownloadDialog.kt | 72 ++++++++----------- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index db52515d6..e13b766b5 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -152,7 +152,7 @@ class DownloadService : Service() { if (downloadId == id) { if (downloadType == "mux") { downloadManagerRequest( - getString(R.string.video), + getString(R.string.audio), getString(R.string.downloading), audioUrl, audioDir diff --git a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt index 7e71a21e7..1cffd8858 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt @@ -10,7 +10,6 @@ import android.os.Environment import android.util.Log import android.util.TypedValue import android.view.View -import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Button import android.widget.Spinner @@ -26,18 +25,23 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class DownloadDialog : DialogFragment() { private val TAG = "DownloadDialog" - var streams: Streams = Streams() - var selectedVideo = 0 - var selectedAudio = 0 - var duration = 0 + + private lateinit var streams: Streams private lateinit var videoId: String + private var duration = 0 + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { streams = arguments?.getParcelable("streams")!! videoId = arguments?.getString("video_id")!! val mainActivity = activity as MainActivity - Log.e(TAG, "download button clicked!") + val builder = MaterialAlertDialogBuilder(it) + // Get the layout inflater + val inflater = requireActivity().layoutInflater + var view: View = inflater.inflate(R.layout.dialog_download, null) + + // request storage permissions if not granted yet if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { Log.d("myz", "" + Build.VERSION.SDK_INT) if (!Environment.isExternalStorageManager()) { @@ -70,50 +74,46 @@ class DownloadDialog : DialogFragment() { ) } } + + var vidName = arrayListOf() - vidName.add(getString(R.string.no_video)) var vidUrl = arrayListOf() + + // add empty selection + vidName.add(getString(R.string.no_video)) vidUrl.add("") + + // add all available video streams for (vid in streams.videoStreams!!) { val name = vid.quality + " " + vid.format vidName.add(name) vidUrl.add(vid.url!!) } + var audioName = arrayListOf() - audioName.add(getString(R.string.no_audio)) var audioUrl = arrayListOf() + + // add empty selection + audioName.add(getString(R.string.no_audio)) audioUrl.add("") + + // add all available audio streams for (audio in streams.audioStreams!!) { val name = audio.quality + " " + audio.format audioName.add(name) audioUrl.add(audio.url!!) } - val builder = MaterialAlertDialogBuilder(it) - // Get the layout inflater - val inflater = requireActivity().layoutInflater - var view: View = inflater.inflate(R.layout.dialog_download, null) val videoSpinner = view.findViewById(R.id.video_spinner) - val videoArrayAdapter = ArrayAdapter( + val videoArrayAdapter = ArrayAdapter( requireContext(), android.R.layout.simple_spinner_item, vidName ) videoArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) videoSpinner.adapter = videoArrayAdapter - videoSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parent: AdapterView<*>, - view: View, - position: Int, - id: Long - ) { - selectedVideo = position - Log.d(TAG, selectedVideo.toString()) - } + videoSpinner.setSelection(1) - override fun onNothingSelected(parent: AdapterView<*>?) {} - } val audioSpinner = view.findViewById(R.id.audio_spinner) val audioArrayAdapter = ArrayAdapter( requireContext(), @@ -122,27 +122,17 @@ class DownloadDialog : DialogFragment() { ) audioArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) audioSpinner.adapter = audioArrayAdapter - audioSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parent: AdapterView<*>, - view: View, - position: Int, - id: Long - ) { - selectedAudio = position - Log.d(TAG, selectedAudio.toString()) - } - - override fun onNothingSelected(parent: AdapterView<*>?) {} - } + audioSpinner.setSelection(1) view.findViewById