From 1e3e04031bd94c53c435f8a29cc96463dcbbefa9 Mon Sep 17 00:00:00 2001 From: rimthekid Date: Tue, 29 Mar 2022 03:15:51 -0700 Subject: [PATCH 1/9] remove default font --- app/build.gradle | 2 +- app/release/output-metadata.json | 38 ++++++++++++------------ app/src/main/res/values-night/themes.xml | 1 - app/src/main/res/values-v23/themes.xml | 1 - app/src/main/res/values/themes.xml | 1 - 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3e1feb37a..6a2b8e82f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -71,7 +71,7 @@ dependencies { implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-jackson:2.9.0' - implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.2' + implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.1' implementation 'com.arthenica:ffmpeg-kit-min:4.5.1.LTS' diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index dd82e596d..6c783c252 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -16,23 +16,10 @@ } ], "attributes": [], - "versionCode": 5, - "versionName": "0.2.3", + "versionCode": 6, + "versionName": "0.2.4", "outputFile": "app-x86_64-release.apk" }, - { - "type": "ONE_OF_MANY", - "filters": [ - { - "filterType": "ABI", - "value": "x86" - } - ], - "attributes": [], - "versionCode": 5, - "versionName": "0.2.3", - "outputFile": "app-x86-release.apk" - }, { "type": "ONE_OF_MANY", "filters": [ @@ -42,10 +29,23 @@ } ], "attributes": [], - "versionCode": 5, - "versionName": "0.2.3", + "versionCode": 6, + "versionName": "0.2.4", "outputFile": "app-arm64-v8a-release.apk" }, + { + "type": "ONE_OF_MANY", + "filters": [ + { + "filterType": "ABI", + "value": "x86" + } + ], + "attributes": [], + "versionCode": 6, + "versionName": "0.2.4", + "outputFile": "app-x86-release.apk" + }, { "type": "ONE_OF_MANY", "filters": [ @@ -55,8 +55,8 @@ } ], "attributes": [], - "versionCode": 5, - "versionName": "0.2.3", + "versionCode": 6, + "versionName": "0.2.4", "outputFile": "app-armeabi-v7a-release.apk" } ], diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 11084dedb..1d8f3b118 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -31,7 +31,6 @@ @android:color/transparent false @android:color/transparent - @font/roboto \ No newline at end of file diff --git a/app/src/main/res/values-v23/themes.xml b/app/src/main/res/values-v23/themes.xml index 4cd3ad718..a8c3d8000 100644 --- a/app/src/main/res/values-v23/themes.xml +++ b/app/src/main/res/values-v23/themes.xml @@ -32,7 +32,6 @@ @android:color/transparent true @android:color/transparent - @font/roboto \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 5ed353774..4305984cb 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -29,6 +29,5 @@ @color/md_theme_light_primaryInverse @android:color/transparent - @font/roboto \ No newline at end of file From 5c84e204d272dab272e6bf3506c34ceff3bffaaf Mon Sep 17 00:00:00 2001 From: rimthekid Date: Tue, 29 Mar 2022 08:37:52 -0700 Subject: [PATCH 2/9] default quality --- app/build.gradle | 1 + .../main/java/com/github/libretube/PlayerFragment.kt | 10 ++++++++++ app/src/main/res/values/array.xml | 10 ++++++++++ app/src/main/res/xml/settings.xml | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 6a2b8e82f..17038106f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -71,6 +71,7 @@ dependencies { implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-jackson:2.9.0' + //do not update jackson annotations! it does not supports = arrayOf() @@ -267,9 +269,11 @@ class PlayerFragment : Fragment() { val defres = sharedPreferences.getString("default_res", "")!! when { defres!="" -> { + var foundRes = false run lit@ { response.videoStreams!!.forEachIndexed { index, pipedStream -> if (pipedStream.quality!!.contains(defres)){ + foundRes = true val dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory() val videoItem: MediaItem = MediaItem.Builder() @@ -288,6 +292,12 @@ class PlayerFragment : Fragment() { exoPlayer.setMediaSource(mergeSource) view.findViewById(R.id.quality_text).text=videosNameArray[index+1] return@lit + }else if (index+1 == response.videoStreams.size){ + val mediaItem: MediaItem = MediaItem.Builder() + .setUri(response.hls) + .setSubtitleConfigurations(subtitle) + .build() + exoPlayer.setMediaItem(mediaItem) } } } diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index d5d767f4f..1b230abaa 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -417,6 +417,16 @@ D + HLS + 1080p + 720p + 480p + 360p + 240p + 144p + + + 1080p 720p 480p diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 847d7c7b6..614b2e4a3 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -54,7 +54,7 @@ app:title="@string/defres" app:key="default_res" app:entries="@array/defres" - app:entryValues="@array/defres" + app:entryValues="@array/defresValue" app:defaultValue="" android:icon="@drawable/ic_hd" app:useSimpleSummaryProvider="true" From 3f05ce9acb3694e3b40e1481faa7f4ee69311cfa Mon Sep 17 00:00:00 2001 From: rimthekid Date: Tue, 29 Mar 2022 10:02:34 -0700 Subject: [PATCH 3/9] Grid settings --- .../main/java/com/github/libretube/Home.kt | 4 +- .../java/com/github/libretube/Settings.kt | 62 ++++++++++++------- app/src/main/res/drawable/ic_column.xml | 10 +++ app/src/main/res/layout/fragment_player.xml | 8 +-- app/src/main/res/layout/trending_row.xml | 4 +- app/src/main/res/values/array.xml | 7 +++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/settings.xml | 14 +++-- 8 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 app/src/main/res/drawable/ic_column.xml diff --git a/app/src/main/java/com/github/libretube/Home.kt b/app/src/main/java/com/github/libretube/Home.kt index b83725070..4cbec151b 100644 --- a/app/src/main/java/com/github/libretube/Home.kt +++ b/app/src/main/java/com/github/libretube/Home.kt @@ -43,7 +43,9 @@ class Home : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val recyclerView = view.findViewById(R.id.recview) - recyclerView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items)) + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + val grid = sharedPreferences.getString("grid", resources.getInteger(R.integer.grid_items).toString())!! + recyclerView.layoutManager = GridLayoutManager(view.context, grid.toInt()) val progressbar = view.findViewById(R.id.progressBar) fetchJson(progressbar,recyclerView) refreshLayout = view.findViewById(R.id.home_refresh) diff --git a/app/src/main/java/com/github/libretube/Settings.kt b/app/src/main/java/com/github/libretube/Settings.kt index 5638a1d85..f30571c40 100644 --- a/app/src/main/java/com/github/libretube/Settings.kt +++ b/app/src/main/java/com/github/libretube/Settings.kt @@ -26,10 +26,11 @@ import com.github.libretube.obj.Subscribe import retrofit2.HttpException import java.io.ByteArrayOutputStream import java.io.IOException +import java.io.InputStream import java.util.zip.ZipFile class Settings : PreferenceFragmentCompat() { - + val TAG = "Settings" companion object { lateinit var getContent: ActivityResultLauncher } @@ -39,27 +40,34 @@ class Settings : PreferenceFragmentCompat() { getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> if (uri != null) { - var zipfile = ZipFile(UriUtils.uri2File(uri)) + try{ + Log.d(TAG,UriUtils.uri2File(uri).toString()) + val file = UriUtils.uri2File(uri) + var inputStream: InputStream? = null + if (file.extension == "zip") { + var zipfile = ZipFile(file) - var zipentry = - zipfile.getEntry("Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv") + var zipentry = + zipfile.getEntry("Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv") - var inputStream = zipfile.getInputStream(zipentry) - - val baos = ByteArrayOutputStream() - - inputStream.use { it.copyTo(baos) } - - var subscriptions = baos.toByteArray().decodeToString() - - var subscribedCount = 0 - - for (text in subscriptions.lines()) { - if (text.take(24) != "Channel Id,Channel Url,C" && !text.take(24).isEmpty()) { - subscribe(text.take(24)) - subscribedCount++ - Log.d(TAG, "subscribed: " + text + " total: " + subscribedCount) + inputStream = zipfile.getInputStream(zipentry) + }else if(file.extension == "csv"){ + inputStream = file.inputStream() } + val baos = ByteArrayOutputStream() + + inputStream?.use { it.copyTo(baos) } + + var subscriptions = baos.toByteArray().decodeToString() + + var subscribedCount = 0 + + for (text in subscriptions.lines()) { + if (text.take(24) != "Channel Id,Channel Url,C" && text.take(24).isNotEmpty()) { + subscribe(text.take(24)) + subscribedCount++ + Log.d(TAG, "subscribed: " + text + " total: " + subscribedCount) + } } Toast.makeText( @@ -67,7 +75,15 @@ class Settings : PreferenceFragmentCompat() { "Subscribed to " + subscribedCount + " channels.", Toast.LENGTH_SHORT ).show() + }catch (e: Exception){ + Toast.makeText( + context, + R.string.error, + Toast.LENGTH_SHORT + ).show() } + } + } super.onCreate(savedInstanceState) @@ -111,6 +127,8 @@ class Settings : PreferenceFragmentCompat() { Manifest.permission.MANAGE_EXTERNAL_STORAGE ), 1 ) //permission request code is just an int + }else{ + getContent.launch("*/*") } } else { if (ActivityCompat.checkSelfPermission( @@ -129,12 +147,10 @@ class Settings : PreferenceFragmentCompat() { ), 1 ) + }else{ + getContent.launch("*/*") } } - - getContent.launch("application/zip") - - true } diff --git a/app/src/main/res/drawable/ic_column.xml b/app/src/main/res/drawable/ic_column.xml new file mode 100644 index 000000000..7d8a64736 --- /dev/null +++ b/app/src/main/res/drawable/ic_column.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 75abd5a60..f45f0b357 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -192,12 +192,12 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_centerVertical="true" - android:layout_toEndOf="@+id/player_channelImage" android:layout_toStartOf="@+id/player_subscribe" - android:text="" - android:textStyle="bold" + android:layout_toEndOf="@+id/player_channelImage" android:ellipsize="end" - android:maxLines="1"/> + android:maxLines="1" + android:text="" + android:textStyle="bold" /> + app:layout_constraintTop_toBottomOf="@+id/thumbnailcard" + android:ellipsize="end" + android:maxLines="2"/> 240p 144p + + 1 + 2 + 3 + 4 + 5 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bf5c42541..feac3f194 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,7 +33,9 @@ App theme Server countered a problem. Maybe try another instance? Network error! + Something went wrong! Username and Password can\'t be empty! This is not your gmail account! Default Video Resolution + Choose the grid columns \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 614b2e4a3..efcb289e0 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -1,11 +1,6 @@ - - + \ No newline at end of file From 6076598dbd198b1f856cf0ca778a7195f86d7f74 Mon Sep 17 00:00:00 2001 From: rimthekid Date: Tue, 29 Mar 2022 11:46:34 -0700 Subject: [PATCH 4/9] import login check --- app/src/main/java/com/github/libretube/Settings.kt | 11 ++++++++--- .../main/java/com/github/libretube/Subscriptions.kt | 13 +++++-------- app/src/main/res/values/strings.xml | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/Settings.kt b/app/src/main/java/com/github/libretube/Settings.kt index f30571c40..85c729898 100644 --- a/app/src/main/java/com/github/libretube/Settings.kt +++ b/app/src/main/java/com/github/libretube/Settings.kt @@ -116,7 +116,8 @@ class Settings : PreferenceFragmentCompat() { val importFromYt = findPreference("import_from_yt") importFromYt?.setOnPreferenceClickListener { - + val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) + val token = sharedPref?.getString("token","")!! //check StorageAccess if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { Log.d("myz", "" + Build.VERSION.SDK_INT) @@ -127,8 +128,10 @@ class Settings : PreferenceFragmentCompat() { Manifest.permission.MANAGE_EXTERNAL_STORAGE ), 1 ) //permission request code is just an int - }else{ + }else if (token != ""){ getContent.launch("*/*") + }else{ + Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show() } } else { if (ActivityCompat.checkSelfPermission( @@ -147,8 +150,10 @@ class Settings : PreferenceFragmentCompat() { ), 1 ) - }else{ + }else if (token != ""){ getContent.launch("*/*") + }else{ + Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show() } } true diff --git a/app/src/main/java/com/github/libretube/Subscriptions.kt b/app/src/main/java/com/github/libretube/Subscriptions.kt index c01b5b85f..612d06aec 100644 --- a/app/src/main/java/com/github/libretube/Subscriptions.kt +++ b/app/src/main/java/com/github/libretube/Subscriptions.kt @@ -59,7 +59,9 @@ class Subscriptions : Fragment() { fetchChannels(channelRecView) var feedRecView = view.findViewById(R.id.sub_feed) - feedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items)) + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + val grid = sharedPreferences.getString("grid", resources.getInteger(R.integer.grid_items).toString())!! + feedRecView.layoutManager = GridLayoutManager(view.context, grid.toInt()) fetchFeed(feedRecView, progressBar) refreshLayout?.setOnRefreshListener { @@ -137,16 +139,11 @@ class Subscriptions : Fragment() { } run() } - - override fun onStop() { - Log.e(TAG,"Stopped") - subscriptionAdapter = null - view?.findViewById(R.id.sub_feed)?.adapter=null - super.onStop() - } override fun onDestroy() { Log.e(TAG,"Destroyed") super.onDestroy() + subscriptionAdapter = null + view?.findViewById(R.id.sub_feed)?.adapter=null } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index feac3f194..00a1e6b57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,6 +17,7 @@ Logged out successfully! Registered successfully! You may now subscribe to channels you want. You are already logged in, you may logout of your account. + Please login and try again! Choose an instance Add a custom instance Choose a region From 347179b59a5ee517696e96fed5c8356072b159b0 Mon Sep 17 00:00:00 2001 From: rimthekid Date: Wed, 30 Mar 2022 09:42:14 -0700 Subject: [PATCH 5/9] set fullscreen orientation --- app/src/main/java/com/github/libretube/PlayerFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index b6e3b11de..fa4749513 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -191,6 +191,7 @@ class PlayerFragment : Fragment() { view.findViewById(R.id.main_container).isClickable =true view.findViewById(R.id.linLayout).visibility=View.GONE val mainActivity = activity as MainActivity + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED isFullScreen=true From 6688e7a5deb82838015815aaa2b292439c4ce2bf Mon Sep 17 00:00:00 2001 From: rimthekid Date: Thu, 31 Mar 2022 10:34:19 -0700 Subject: [PATCH 6/9] import subscription --- app/build.gradle | 4 +- app/release/output-metadata.json | 38 +++--- app/src/main/AndroidManifest.xml | 1 + .../java/com/github/libretube/MainActivity.kt | 6 + .../java/com/github/libretube/PipedApi.kt | 5 + .../com/github/libretube/SearchFragment.kt | 4 + .../java/com/github/libretube/Settings.kt | 110 +++++++++++------- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/settings.xml | 2 +- 9 files changed, 105 insertions(+), 66 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 17038106f..298d93f81 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId 'com.github.libretube' minSdk 21 targetSdk 31 - versionCode 6 - versionName '0.2.4' + versionCode 7 + versionName '0.2.5' multiDexEnabled true testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' resValue "string", "app_name", "LibreTube" diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 6c783c252..135a379d0 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -16,23 +16,10 @@ } ], "attributes": [], - "versionCode": 6, - "versionName": "0.2.4", + "versionCode": 7, + "versionName": "0.2.5", "outputFile": "app-x86_64-release.apk" }, - { - "type": "ONE_OF_MANY", - "filters": [ - { - "filterType": "ABI", - "value": "arm64-v8a" - } - ], - "attributes": [], - "versionCode": 6, - "versionName": "0.2.4", - "outputFile": "app-arm64-v8a-release.apk" - }, { "type": "ONE_OF_MANY", "filters": [ @@ -42,10 +29,23 @@ } ], "attributes": [], - "versionCode": 6, - "versionName": "0.2.4", + "versionCode": 7, + "versionName": "0.2.5", "outputFile": "app-x86-release.apk" }, + { + "type": "ONE_OF_MANY", + "filters": [ + { + "filterType": "ABI", + "value": "arm64-v8a" + } + ], + "attributes": [], + "versionCode": 7, + "versionName": "0.2.5", + "outputFile": "app-arm64-v8a-release.apk" + }, { "type": "ONE_OF_MANY", "filters": [ @@ -55,8 +55,8 @@ } ], "attributes": [], - "versionCode": 6, - "versionName": "0.2.4", + "versionCode": 7, + "versionName": "0.2.5", "outputFile": "app-armeabi-v7a-release.apk" } ], diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1fe7b6b19..31c00cbde 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + "L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) + "D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + } requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT bottomNavigationView = findViewById(R.id.bottomNav) diff --git a/app/src/main/java/com/github/libretube/PipedApi.kt b/app/src/main/java/com/github/libretube/PipedApi.kt index 600cfec40..f0d2bb31c 100644 --- a/app/src/main/java/com/github/libretube/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/PipedApi.kt @@ -52,8 +52,13 @@ interface PipedApi { @POST("unsubscribe") suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): Message + @POST("import") + suspend fun importSubscriptions(@Header("Authorization") token: String, @Body channels: List): Message + //only for fetching servers list @GET suspend fun getInstances(@Url url: String): List + + } \ No newline at end of file diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 4dd09676f..5bafb6d9b 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -125,4 +125,8 @@ class SearchFragment : Fragment() { requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) } + override fun onStop() { + super.onStop() + hideKeyboard() + } } diff --git a/app/src/main/java/com/github/libretube/Settings.kt b/app/src/main/java/com/github/libretube/Settings.kt index 85c729898..b901d8d53 100644 --- a/app/src/main/java/com/github/libretube/Settings.kt +++ b/app/src/main/java/com/github/libretube/Settings.kt @@ -1,13 +1,12 @@ package com.github.libretube import android.Manifest -import android.content.ContentValues.TAG +import android.content.ContentResolver import android.content.Context import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.os.Bundle -import android.os.Environment import android.text.TextUtils import android.util.Log import android.widget.Toast @@ -15,67 +14,83 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatDelegate import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import androidx.preference.SwitchPreferenceCompat import com.blankj.utilcode.util.UriUtils -import com.github.libretube.obj.Subscribe import retrofit2.HttpException -import java.io.ByteArrayOutputStream -import java.io.IOException -import java.io.InputStream +import java.io.* import java.util.zip.ZipFile + class Settings : PreferenceFragmentCompat() { val TAG = "Settings" companion object { lateinit var getContent: ActivityResultLauncher } - override fun onCreate(savedInstanceState: Bundle?) { getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> if (uri != null) { try{ - Log.d(TAG,UriUtils.uri2File(uri).toString()) - val file = UriUtils.uri2File(uri) - var inputStream: InputStream? = null - if (file.extension == "zip") { - var zipfile = ZipFile(file) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - var zipentry = - zipfile.getEntry("Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv") + // Open a specific media item using ParcelFileDescriptor. + val resolver: ContentResolver = + requireActivity() + .contentResolver - inputStream = zipfile.getInputStream(zipentry) - }else if(file.extension == "csv"){ - inputStream = file.inputStream() - } - val baos = ByteArrayOutputStream() - - inputStream?.use { it.copyTo(baos) } - - var subscriptions = baos.toByteArray().decodeToString() - - var subscribedCount = 0 - - for (text in subscriptions.lines()) { - if (text.take(24) != "Channel Id,Channel Url,C" && text.take(24).isNotEmpty()) { - subscribe(text.take(24)) - subscribedCount++ - Log.d(TAG, "subscribed: " + text + " total: " + subscribedCount) + // "rw" for read-and-write; + // "rwt" for truncating or overwriting existing file contents. + val readOnlyMode = "r" + // uri - I have got from onActivityResult + //uri = data.getData(); + val parcelFile = resolver.openFileDescriptor(uri, readOnlyMode) + val fileReader = FileReader(parcelFile!!.fileDescriptor) + val reader = BufferedReader(fileReader) + var line: String? + while (reader.readLine().also { line = it } != null) { + Log.d(TAG,reader.readLine()) } - } + reader.close() + fileReader.close() + }else{ + Log.d(TAG,UriUtils.uri2File(uri).toString()) + val file = UriUtils.uri2File(uri) + var inputStream: InputStream? = null + if (file.extension == "zip") { + var zipfile = ZipFile(file) - Toast.makeText( - context, - "Subscribed to " + subscribedCount + " channels.", - Toast.LENGTH_SHORT - ).show() + var zipentry = + zipfile.getEntry("Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv") + + inputStream = zipfile.getInputStream(zipentry) + }else if(file.extension == "csv"){ + inputStream = file.inputStream() + } + val baos = ByteArrayOutputStream() + + inputStream?.use { it.copyTo(baos) } + + var subscriptions = baos.toByteArray().decodeToString() + var channels: MutableList = emptyList().toMutableList() + var subscribedCount = 0 + for (text in subscriptions.lines().subList(1,subscriptions.lines().size)) { + if (text.replace(" ","") != "") { + val channel = text.split(",")[0] + channels.add(channel) + subscribedCount++ + Log.d(TAG, "subscribed: " + text + " total: " + subscribedCount) + } + } + subscribe(channels) + } }catch (e: Exception){ + Log.e(TAG,e.toString()) Toast.makeText( context, R.string.error, @@ -121,7 +136,9 @@ class Settings : PreferenceFragmentCompat() { //check StorageAccess if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { Log.d("myz", "" + Build.VERSION.SDK_INT) - if (!Environment.isExternalStorageManager()) { + if (ContextCompat.checkSelfPermission(this.requireContext(), Manifest.permission.READ_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED + ) { ActivityCompat.requestPermissions( this.requireActivity(), arrayOf( Manifest.permission.READ_EXTERNAL_STORAGE, @@ -218,15 +235,12 @@ class Settings : PreferenceFragmentCompat() { } - private fun subscribe(channel_id: String) { + private fun subscribe(channels: List) { fun run() { lifecycleScope.launchWhenCreated { val response = try { val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) - RetrofitInstance.api.subscribe( - sharedPref?.getString("token", "")!!, - Subscribe(channel_id) - ) + RetrofitInstance.api.importSubscriptions(sharedPref?.getString("token", "")!!,channels) } catch (e: IOException) { Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated @@ -234,9 +248,17 @@ class Settings : PreferenceFragmentCompat() { Log.e(TAG, "HttpException, unexpected response$e") return@launchWhenCreated } + if(response.message == "ok"){ + Toast.makeText( + context, + R.string.importsuccess, + Toast.LENGTH_SHORT + ).show() + } } } run() } } + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00a1e6b57..131e9c696 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,6 +23,7 @@ Choose a region Login/Register Please Login or Register from the settings to show your Subscriptions! + Subscribed successfully! Subscribe to some channels first! Can\'t Download this stream! Download is completed! diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index efcb289e0..98495f0af 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -59,7 +59,7 @@ app:key="grid" app:entries="@array/grid" app:entryValues="@array/grid" - app:defaultValue="" + app:defaultValue="@integer/grid_items" android:icon="@drawable/ic_column" app:useSimpleSummaryProvider="true" /> From aaba4f5bfa134499536e8f732cc08c45725bcf12 Mon Sep 17 00:00:00 2001 From: rimthekid Date: Fri, 1 Apr 2022 04:40:46 -0700 Subject: [PATCH 7/9] fix subscriptions import --- app/release/output-metadata.json | 26 +++++++++---------- .../java/com/github/libretube/Settings.kt | 11 +++++++- .../com/github/libretube/Subscriptions.kt | 5 ++-- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 135a379d0..88c88278f 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -20,6 +20,19 @@ "versionName": "0.2.5", "outputFile": "app-x86_64-release.apk" }, + { + "type": "ONE_OF_MANY", + "filters": [ + { + "filterType": "ABI", + "value": "armeabi-v7a" + } + ], + "attributes": [], + "versionCode": 7, + "versionName": "0.2.5", + "outputFile": "app-armeabi-v7a-release.apk" + }, { "type": "ONE_OF_MANY", "filters": [ @@ -45,19 +58,6 @@ "versionCode": 7, "versionName": "0.2.5", "outputFile": "app-arm64-v8a-release.apk" - }, - { - "type": "ONE_OF_MANY", - "filters": [ - { - "filterType": "ABI", - "value": "armeabi-v7a" - } - ], - "attributes": [], - "versionCode": 7, - "versionName": "0.2.5", - "outputFile": "app-armeabi-v7a-release.apk" } ], "elementType": "File" diff --git a/app/src/main/java/com/github/libretube/Settings.kt b/app/src/main/java/com/github/libretube/Settings.kt index b901d8d53..84d9a7d45 100644 --- a/app/src/main/java/com/github/libretube/Settings.kt +++ b/app/src/main/java/com/github/libretube/Settings.kt @@ -53,9 +53,18 @@ class Settings : PreferenceFragmentCompat() { val fileReader = FileReader(parcelFile!!.fileDescriptor) val reader = BufferedReader(fileReader) var line: String? + var channels: MutableList = emptyList().toMutableList() + var subscribedCount = 0 while (reader.readLine().also { line = it } != null) { - Log.d(TAG,reader.readLine()) + if (line!!.replace(" ","") != "" && subscribedCount >0) { + val channel = line!!.split(",")[0] + channels.add(channel) + + Log.d(TAG, "subscribed: " + line + " total: " + subscribedCount) + } + subscribedCount++ } + subscribe(channels) reader.close() fileReader.close() }else{ diff --git a/app/src/main/java/com/github/libretube/Subscriptions.kt b/app/src/main/java/com/github/libretube/Subscriptions.kt index 612d06aec..7f9737ba7 100644 --- a/app/src/main/java/com/github/libretube/Subscriptions.kt +++ b/app/src/main/java/com/github/libretube/Subscriptions.kt @@ -45,7 +45,6 @@ class Subscriptions : Fragment() { super.onViewCreated(view, savedInstanceState) val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) token = sharedPref?.getString("token","")!! - Log.e(TAG,token) refreshLayout = view.findViewById(R.id.sub_refresh) if(token!=""){ view.findViewById(R.id.loginOrRegister).visibility=View.GONE @@ -94,7 +93,7 @@ class Subscriptions : Fragment() { val response = try { RetrofitInstance.api.getFeed(token) }catch(e: IOException) { - println(e) + Log.e(TAG,e.toString()) Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated } catch (e: HttpException) { @@ -121,7 +120,7 @@ class Subscriptions : Fragment() { val response = try { RetrofitInstance.api.subscriptions(token) }catch(e: IOException) { - println(e) + Log.e(TAG,e.toString()) Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated } catch (e: HttpException) { From 12138bd4f4d6e0199b6582209448f005fb208766 Mon Sep 17 00:00:00 2001 From: Surajkumar Gunjal Date: Sat, 2 Apr 2022 16:54:20 +0530 Subject: [PATCH 8/9] Fix fullscreen button --- app/src/main/java/com/github/libretube/PlayerFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index fa4749513..cf94d899f 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -192,7 +192,6 @@ class PlayerFragment : Fragment() { view.findViewById(R.id.linLayout).visibility=View.GONE val mainActivity = activity as MainActivity mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED isFullScreen=true }else{ From 89937f4ef6b1860ea8b215e42ebe70abf854cae2 Mon Sep 17 00:00:00 2001 From: Surajkumar Gunjal Date: Sat, 2 Apr 2022 16:50:58 +0530 Subject: [PATCH 9/9] close AutoCompleteTextView and keyboard for suggestions when search button is pressed --- .../java/com/github/libretube/SearchFragment.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 5bafb6d9b..07031801d 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -9,9 +9,11 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.WindowManager +import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.widget.ArrayAdapter import android.widget.AutoCompleteTextView +import android.widget.TextView.OnEditorActionListener import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager @@ -75,6 +77,17 @@ class SearchFragment : Fragment() { } }) + autoTextView.setOnEditorActionListener(OnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + hideKeyboard(); + autoTextView.dismissDropDown(); + return@OnEditorActionListener true + } + false + }) + autoTextView.setOnDismissListener { + hideKeyboard(); + } } private fun fetchSuggestions(query: String, autoTextView: AutoCompleteTextView){