diff --git a/README.md b/README.md
index 1f9427f71..b5c6894f0 100644
--- a/README.md
+++ b/README.md
@@ -62,3 +62,4 @@ WARNING: THIS IS A BETA VERSION, THEREFORE YOU MAY ENCOUNTER BUGS. IF YOU DO, OP
## Mirrors (read-only)
GitLab
+NotABug
diff --git a/app/build.gradle b/app/build.gradle
index 969e97e7a..90f219fa8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -55,35 +55,35 @@ android {
}
dependencies {
- //debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
+ //debugImplementation libs.square.leakcanary
- implementation 'androidx.appcompat:appcompat:1.4.1'
- implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
- implementation 'com.google.android.material:material:1.6.0'
- implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
- implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
- implementation 'androidx.legacy:legacy-support-v4:1.0.0'
- implementation 'androidx.preference:preference-ktx:1.2.0'
+ implementation libs.androidx.appcompat
+ implementation libs.androidx.constraintlayout
+ implementation libs.androidx.legacySupport
+ implementation libs.androidx.multidex
+ implementation libs.androidx.navigation.fragment
+ implementation libs.androidx.navigation.ui
+ implementation libs.androidx.preference
- androidTestImplementation 'androidx.test.ext:junit:1.1.3'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+ androidTestImplementation libs.androidx.test.junit
+ androidTestImplementation libs.androidx.test.espressoCore
- implementation 'com.squareup.picasso:picasso:2.8'
- implementation 'de.hdodenhof:circleimageview:3.1.0'
- implementation 'com.google.android.exoplayer:exoplayer:2.17.1'
- implementation 'com.google.android.exoplayer:extension-mediasession:2.17.1'
- implementation 'androidx.multidex:multidex:2.0.1'
+ implementation libs.circleimageview
- 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
+ android:theme="@style/Theme.Purple">
+ android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
+ android:supportsPictureInPicture="true">
@@ -44,16 +44,16 @@
+ android:icon="@mipmap/ic_gradient"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_gradient_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
@@ -61,16 +61,16 @@
+ android:icon="@mipmap/ic_fire"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_fire_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
@@ -78,16 +78,16 @@
+ android:icon="@mipmap/ic_flame"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_flame_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
@@ -95,16 +95,16 @@
+ android:icon="@mipmap/ic_shaped"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_shaped_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
@@ -112,16 +112,16 @@
+ android:icon="@mipmap/ic_torch"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_torch_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
@@ -129,16 +129,16 @@
+ android:icon="@mipmap/ic_legacy"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_legacy_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
@@ -146,16 +146,16 @@
+ android:icon="@mipmap/ic_bird"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_bird_round"
+ android:supportsPictureInPicture="true"
+ android:targetActivity=".MainActivity">
diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt
index e13b766b5..eb7b309aa 100644
--- a/app/src/main/java/com/github/libretube/DownloadService.kt
+++ b/app/src/main/java/com/github/libretube/DownloadService.kt
@@ -17,8 +17,8 @@ import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
-import androidx.preference.PreferenceManager
import com.arthenica.ffmpegkit.FFmpegKit
+import com.github.libretube.util.PreferenceHelper
import java.io.File
var IS_DOWNLOAD_RUNNING = false
@@ -48,8 +48,7 @@ class DownloadService : Service() {
videoUrl = intent.getStringExtra("videoUrl")!!
audioUrl = intent.getStringExtra("audioUrl")!!
duration = intent.getIntExtra("duration", 1)
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
- extension = sharedPreferences.getString("video_format", ".mp4")!!
+ extension = PreferenceHelper.getString(this, "video_format", ".mp4")!!
downloadType = if (audioUrl != "" && videoUrl != "") "mux"
else if (audioUrl != "") "audio"
else if (videoUrl != "") "video"
@@ -69,7 +68,6 @@ class DownloadService : Service() {
}
private fun downloadManager() {
-
// create folder for temporary files
tempDir = File(
applicationContext.getExternalFilesDir(DIRECTORY_DOWNLOADS),
@@ -84,9 +82,8 @@ class DownloadService : Service() {
Log.e(TAG, "Directory already have")
}
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
- val downloadLocationPref = sharedPreferences.getString("download_location", "")
- val folderName = sharedPreferences.getString("download_folder", "")
+ val downloadLocationPref = PreferenceHelper.getString(this, "download_location", "")
+ val folderName = PreferenceHelper.getString(this, "download_folder", "LibreTube")
val location = when (downloadLocationPref) {
"downloads" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)
@@ -255,10 +252,11 @@ class DownloadService : Service() {
if (returnCode.toString() != "0") downloadFailedNotification()
else downloadSucceededNotification()
onDestroy()
- }, {
- // CALLED WHEN SESSION PRINTS LOGS
- Log.e(TAG, it.message.toString())
- }
+ },
+ {
+ // CALLED WHEN SESSION PRINTS LOGS
+ Log.e(TAG, it.message.toString())
+ }
) {
// CALLED WHEN SESSION GENERATES STATISTICS
Log.e(TAG + "stat", it.time.toString())
diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt
index e6e7beee0..357250e75 100644
--- a/app/src/main/java/com/github/libretube/MainActivity.kt
+++ b/app/src/main/java/com/github/libretube/MainActivity.kt
@@ -32,12 +32,11 @@ import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
-import androidx.preference.PreferenceManager
import com.github.libretube.fragments.PlayerFragment
import com.github.libretube.fragments.isFullScreen
-import com.github.libretube.preferences.SponsorBlockSettings
import com.github.libretube.util.CronetHelper
import com.github.libretube.util.LocaleHelper
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.ThemeHelper
import com.google.android.material.bottomnavigation.BottomNavigationView
@@ -54,32 +53,12 @@ class MainActivity : AppCompatActivity() {
DynamicColors.applyToActivityIfAvailable(this)
super.onCreate(savedInstanceState)
CronetHelper.initCronet(this.applicationContext)
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
- RetrofitInstance.url =
- sharedPreferences.getString("selectInstance", "https://pipedapi.kavin.rocks/")!!
- SponsorBlockSettings.sponsorBlockEnabled =
- sharedPreferences.getBoolean("sb_enabled_key", true)
- SponsorBlockSettings.sponsorNotificationsEnabled =
- sharedPreferences.getBoolean("sb_notifications_key", true)
- SponsorBlockSettings.introEnabled =
- sharedPreferences.getBoolean("intro_category_key", false)
- SponsorBlockSettings.selfPromoEnabled =
- sharedPreferences.getBoolean("selfpromo_category_key", false)
- SponsorBlockSettings.interactionEnabled =
- sharedPreferences.getBoolean("interaction_category_key", false)
- SponsorBlockSettings.sponsorsEnabled =
- sharedPreferences.getBoolean("sponsors_category_key", true)
- SponsorBlockSettings.outroEnabled =
- sharedPreferences.getBoolean("outro_category_key", false)
- SponsorBlockSettings.fillerEnabled =
- sharedPreferences.getBoolean("filler_category_key", false)
- SponsorBlockSettings.musicOfftopicEnabled =
- sharedPreferences.getBoolean("music_offtopic_category_key", false)
- SponsorBlockSettings.previewEnabled =
- sharedPreferences.getBoolean("preview_category_key", false)
- ThemeHelper().updateTheme(this)
- LocaleHelper().updateLanguage(this)
+ RetrofitInstance.url =
+ PreferenceHelper.getString(this, "selectInstance", "https://pipedapi.kavin.rocks/")!!
+
+ ThemeHelper.updateTheme(this)
+ LocaleHelper.updateLanguage(this)
// show noInternet Activity if no internet available on app startup
if (!isNetworkAvailable(this)) {
@@ -100,12 +79,11 @@ class MainActivity : AppCompatActivity() {
bottomNavigationView.setupWithNavController(navController)
// hide the trending page if enabled
- val hideTrendingPage = sharedPreferences.getBoolean("hide_trending_page", false)
+ val hideTrendingPage = PreferenceHelper.getBoolean(this, "hide_trending_page", false)
if (hideTrendingPage) bottomNavigationView.menu.findItem(R.id.home2).isVisible = false
// navigate to the default start tab
- val defaultTab = sharedPreferences.getString("default_tab", "home")
- when (defaultTab) {
+ when (PreferenceHelper.getString(this, "default_tab", "home")) {
"home" -> navController.navigate(R.id.home2)
"subscriptions" -> navController.navigate(R.id.subscriptions)
"library" -> navController.navigate(R.id.library)
diff --git a/app/src/main/java/com/github/libretube/RouterActivity.kt b/app/src/main/java/com/github/libretube/RouterActivity.kt
index 1292422a3..3033fcfbb 100644
--- a/app/src/main/java/com/github/libretube/RouterActivity.kt
+++ b/app/src/main/java/com/github/libretube/RouterActivity.kt
@@ -21,7 +21,7 @@ class RouterActivity : AppCompatActivity() {
handleSendText(uri!!)
} else {
// start app as normal if URI not in host list
- ThemeHelper().restartMainActivity(this)
+ ThemeHelper.restartMainActivity(this)
}
}
diff --git a/app/src/main/java/com/github/libretube/SettingsActivity.kt b/app/src/main/java/com/github/libretube/SettingsActivity.kt
index 27f6f5046..8e2a3f69b 100644
--- a/app/src/main/java/com/github/libretube/SettingsActivity.kt
+++ b/app/src/main/java/com/github/libretube/SettingsActivity.kt
@@ -19,7 +19,7 @@ class SettingsActivity : AppCompatActivity() {
val TAG = "SettingsActivity"
override fun onCreate(savedInstanceState: Bundle?) {
DynamicColors.applyToActivityIfAvailable(this)
- ThemeHelper().updateTheme(this)
+ ThemeHelper.updateTheme(this)
// makes the preference dialogs use material dialogs
setTheme(R.style.MaterialAlertDialog)
@@ -54,7 +54,7 @@ class SettingsActivity : AppCompatActivity() {
val nManager =
this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
nManager.cancelAll()
- ThemeHelper().restartMainActivity(this)
+ ThemeHelper.restartMainActivity(this)
ActivityCompat.finishAffinity(this)
} else {
super.onBackPressed()
diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt
index efce52157..3ce71ac4a 100644
--- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt
@@ -19,11 +19,11 @@ import com.github.libretube.obj.CommentsPage
import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.formatShort
import com.squareup.picasso.Picasso
-import java.io.IOException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.HttpException
+import java.io.IOException
class CommentsAdapter(
private val videoId: String,
diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt
index bfc1e481a..448060c49 100644
--- a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt
@@ -1,7 +1,6 @@
package com.github.libretube.adapters
import android.app.Activity
-import android.content.Context
import android.os.Bundle
import android.text.format.DateUtils
import android.util.Log
@@ -18,13 +17,14 @@ import com.github.libretube.dialogs.VideoOptionsDialog
import com.github.libretube.fragments.PlayerFragment
import com.github.libretube.obj.PlaylistId
import com.github.libretube.obj.StreamItem
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.squareup.picasso.Picasso
-import java.io.IOException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.HttpException
+import java.io.IOException
class PlaylistAdapter(
private val videoFeed: MutableList,
@@ -81,11 +81,7 @@ class PlaylistAdapter(
val delete = holder.v.findViewById(R.id.delete_playlist)
delete.visibility = View.VISIBLE
delete.setOnClickListener {
- val sharedPref = holder.v.context.getSharedPreferences(
- "token",
- Context.MODE_PRIVATE
- )
- val token = sharedPref?.getString("token", "")!!
+ val token = PreferenceHelper.getToken(holder.v.context)
removeFromPlaylist(token, position)
}
}
diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt
index 1d3c8e5a2..08bdb332c 100644
--- a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt
@@ -1,7 +1,6 @@
package com.github.libretube.adapters
import android.app.Activity
-import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@@ -14,13 +13,14 @@ import com.github.libretube.MainActivity
import com.github.libretube.R
import com.github.libretube.obj.PlaylistId
import com.github.libretube.obj.Playlists
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.squareup.picasso.Picasso
-import java.io.IOException
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import retrofit2.HttpException
+import java.io.IOException
class PlaylistsAdapter(
private val playlists: MutableList,
@@ -57,11 +57,7 @@ class PlaylistsAdapter(
builder.setTitle(R.string.deletePlaylist)
builder.setMessage(R.string.areYouSure)
builder.setPositiveButton(R.string.yes) { _, _ ->
- val sharedPref = holder.v.context.getSharedPreferences(
- "token",
- Context.MODE_PRIVATE
- )
- val token = sharedPref?.getString("token", "")!!
+ val token = PreferenceHelper.getToken(holder.v.context)
deletePlaylist(playlist.id!!, token, position)
}
builder.setNegativeButton(R.string.cancel) { _, _ ->
@@ -96,10 +92,6 @@ class PlaylistsAdapter(
playlists.removeAt(position)
// FIXME: This needs to run on UI thread?
activity.runOnUiThread { notifyDataSetChanged() }
-
- /*if(playlists.isEmpty()){
- view.findViewById(R.id.boogh2).visibility=View.VISIBLE
- }*/
}
} catch (e: Exception) {
Log.e(TAG, e.toString())
diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt
index 33b5c705f..d7a8d465d 100644
--- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt
@@ -85,10 +85,11 @@ class SearchViewHolder(
val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else ""
val uploadDate = if (item.uploadedDate != null) item.uploadedDate else ""
views.text =
- if (viewsString != "" && uploadDate != "")
+ if (viewsString != "" && uploadDate != "") {
"$viewsString • $uploadDate"
- else
+ } else {
viewsString + uploadDate
+ }
val channelName = v.findViewById(R.id.search_channel_name)
channelName.text = item.uploaderName
v.setOnClickListener {
@@ -145,9 +146,10 @@ class SearchViewHolder(
val playlistChannelName = v.findViewById(R.id.search_name)
playlistChannelName.text = item.uploaderName
val playlistVideosNumber = v.findViewById(R.id.search_playlist_videos)
- if (item.videos?.toInt() != -1)
+ if (item.videos?.toInt() != -1) {
playlistVideosNumber.text =
v.context.getString(R.string.videoCount, item.videos.toString())
+ }
v.setOnClickListener {
// playlist clicked
val activity = v.context as MainActivity
diff --git a/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt
index 7dfdeaa72..a25359f30 100644
--- a/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/SearchHistoryAdapter.kt
@@ -5,12 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
+import android.widget.ImageView
import android.widget.TextView
-import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.fragments.SearchFragment
-import com.google.android.material.imageview.ShapeableImageView
+import com.github.libretube.util.PreferenceHelper
class SearchHistoryAdapter(
private val context: Context,
@@ -34,10 +34,9 @@ class SearchHistoryAdapter(
val history = historyList[position]
holder.v.findViewById(R.id.history_text).text = history
- holder.v.findViewById(R.id.delete_history).setOnClickListener {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
+ holder.v.findViewById(R.id.delete_history).setOnClickListener {
historyList = historyList - history
- sharedPreferences.edit().putStringSet("search_history", HashSet(historyList)).apply()
+ PreferenceHelper.saveHistory(context, historyList)
notifyDataSetChanged()
}
diff --git a/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt
index 0db923b83..a05024ce0 100644
--- a/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt
@@ -34,8 +34,9 @@ class SubscriptionAdapter(
fun updateItems() {
// limitedVideoFeed.add("")
i += 10
- if (i > videoFeed.size)
+ if (i > videoFeed.size) {
i = videoFeed.size
+ }
notifyDataSetChanged()
}
diff --git a/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt
index 3ae744511..7ce63a5ba 100644
--- a/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt
+++ b/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt
@@ -13,13 +13,14 @@ import com.github.libretube.MainActivity
import com.github.libretube.R
import com.github.libretube.obj.Subscribe
import com.github.libretube.obj.Subscription
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.squareup.picasso.Picasso
-import java.io.IOException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.HttpException
+import java.io.IOException
class SubscriptionChannelAdapter(private val subscriptions: MutableList) :
RecyclerView.Adapter() {
@@ -70,10 +71,9 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList(R.id.playlist_name)
val createPlaylistBtn = view.findViewById(R.id.create_new_playlist)
@@ -88,8 +86,13 @@ class CreatePlaylistDialog : DialogFragment() {
Toast.makeText(context, getString(R.string.unknown_error), Toast.LENGTH_SHORT)
.show()
}
- // tell the Subscription Activity to fetch the playlists again
- setFragmentResult("fetchPlaylists", bundleOf("" to ""))
+ // refresh the playlists in the library
+ try {
+ val parent = parentFragment as Library
+ parent.fetchPlaylists()
+ } catch (e: Exception) {
+ Log.e(TAG, e.toString())
+ }
dismiss()
}
}
diff --git a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt
index e1f06186a..94df2f77d 100644
--- a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt
+++ b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt
@@ -9,8 +9,9 @@ import android.widget.TextView
import android.widget.Toast
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment
-import androidx.preference.PreferenceManager
import com.github.libretube.R
+import com.github.libretube.obj.CustomInstance
+import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputEditText
import java.net.URL
@@ -36,29 +37,38 @@ class CustomInstanceDialog : DialogFragment() {
}
addInstanceButton.setOnClickListener {
- val instanceName = instanceNameEditText.text.toString()
- val instanceApiUrl = instanceApiUrlEditText.text.toString()
- val instanceFrontendUrl = instanceFrontendUrlEditText.text.toString()
+ val customInstance = CustomInstance()
+ customInstance.name = instanceNameEditText.text.toString()
+ customInstance.apiUrl = instanceApiUrlEditText.text.toString()
+ customInstance.frontendUrl = instanceFrontendUrlEditText.text.toString()
- if (instanceName != "" && instanceApiUrl != "" && instanceFrontendUrl != "") {
+ if (
+ customInstance.name != "" &&
+ customInstance.apiUrl != "" &&
+ customInstance.frontendUrl != ""
+ ) {
try {
// check whether the URL is valid, otherwise catch
- URL(instanceApiUrl).toURI()
- URL(instanceFrontendUrl).toURI()
+ URL(customInstance.apiUrl).toURI()
+ URL(customInstance.frontendUrl).toURI()
- saveCustomInstance(instanceName, instanceApiUrl, instanceFrontendUrl)
+ PreferenceHelper.saveCustomInstance(requireContext(), customInstance)
activity?.recreate()
dismiss()
} catch (e: Exception) {
// invalid URL
Toast.makeText(
- context, getString(R.string.invalid_url), Toast.LENGTH_SHORT
+ context,
+ getString(R.string.invalid_url),
+ Toast.LENGTH_SHORT
).show()
}
} else {
// at least one empty input
Toast.makeText(
- context, context?.getString(R.string.empty_instance), Toast.LENGTH_SHORT
+ context,
+ context?.getString(R.string.empty_instance),
+ Toast.LENGTH_SHORT
).show()
}
}
@@ -76,49 +86,4 @@ class CustomInstanceDialog : DialogFragment() {
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
-
- private fun saveCustomInstance(
- instanceName: String,
- instanceApiUrl: String,
- instanceFrontendApiUrl: String
- ) {
- val sharedPreferences = PreferenceManager
- .getDefaultSharedPreferences(requireContext())
-
- // get the names of the other custom instances
- var customInstancesNames = try {
- sharedPreferences
- .getStringSet("custom_instances_name", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
- }
-
- // get the api urls of the other custom instances
- var customInstancesUrls = try {
- sharedPreferences
- .getStringSet("custom_instances_url", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
- }
-
- // get the frontend urls of the other custom instances
- var customInstancesFrontendUrls = try {
- sharedPreferences
- .getStringSet("custom_instances_url", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
- }
-
- // append new instance to the list
- customInstancesNames += instanceName
- customInstancesUrls += instanceApiUrl
- customInstancesFrontendUrls += instanceFrontendApiUrl
-
- // save them to the shared preferences
- sharedPreferences.edit()
- .putStringSet("custom_instances_name", HashSet(customInstancesNames))
- .putStringSet("custom_instances_url", HashSet(customInstancesUrls))
- .putStringSet("custom_instances_frontend_url", HashSet(customInstancesFrontendUrls))
- .apply()
- }
}
diff --git a/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt
new file mode 100644
index 000000000..a9e0da91d
--- /dev/null
+++ b/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt
@@ -0,0 +1,82 @@
+package com.github.libretube.dialogs
+
+import android.app.Dialog
+import android.os.Bundle
+import android.util.Log
+import android.util.TypedValue
+import android.widget.Button
+import android.widget.EditText
+import android.widget.TextView
+import android.widget.Toast
+import androidx.core.text.HtmlCompat
+import androidx.fragment.app.DialogFragment
+import androidx.lifecycle.lifecycleScope
+import com.github.libretube.R
+import com.github.libretube.obj.DeleteUserRequest
+import com.github.libretube.requireMainActivityRestart
+import com.github.libretube.util.PreferenceHelper
+import com.github.libretube.util.RetrofitInstance
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+
+class DeleteAccountDialog : DialogFragment() {
+ private val TAG = "DeleteAccountDialog"
+ lateinit var username: EditText
+ lateinit var password: EditText
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ return activity?.let {
+ val builder = MaterialAlertDialogBuilder(it)
+ val inflater = requireActivity().layoutInflater
+ val view = inflater.inflate(R.layout.dialog_delete_account, null)
+
+ view.findViewById(R.id.cancel_button).setOnClickListener {
+ dialog?.dismiss()
+ }
+
+ password = view.findViewById(R.id.delete_password)
+ view.findViewById(R.id.delete_account_confirm).setOnClickListener {
+ if (password.text.toString() != "") {
+ deleteAccount(password.text.toString())
+ } else {
+ Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show()
+ }
+ }
+
+ val typedValue = TypedValue()
+ this.requireActivity().theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true)
+ val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data))
+ val appName = HtmlCompat.fromHtml(
+ "LibreTube ",
+ HtmlCompat.FROM_HTML_MODE_COMPACT
+ )
+ view.findViewById(R.id.title).text = appName
+
+ builder.setView(view)
+ builder.create()
+ } ?: throw IllegalStateException("Activity cannot be null")
+ }
+
+ private fun deleteAccount(password: String) {
+ fun run() {
+ lifecycleScope.launchWhenCreated {
+ val token = PreferenceHelper.getToken(requireContext())
+
+ try {
+ RetrofitInstance.api.deleteAccount(token, DeleteUserRequest(password))
+ } catch (e: Exception) {
+ Log.e(TAG, e.toString())
+ Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show()
+ return@launchWhenCreated
+ }
+ requireMainActivityRestart = true
+ Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
+ logout()
+ dialog?.dismiss()
+ }
+ }
+ run()
+ }
+
+ private fun logout() {
+ PreferenceHelper.setToken(requireContext(), "")
+ }
+}
diff --git a/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt b/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt
index ae27c5ca2..466249620 100644
--- a/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt
+++ b/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt
@@ -1,7 +1,6 @@
package com.github.libretube.dialogs
import android.app.Dialog
-import android.content.Context
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
@@ -15,10 +14,11 @@ import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import com.github.libretube.R
import com.github.libretube.obj.Login
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import java.io.IOException
import retrofit2.HttpException
+import java.io.IOException
class LoginDialog : DialogFragment() {
private val TAG = "LoginDialog"
@@ -29,23 +29,17 @@ class LoginDialog : DialogFragment() {
val builder = MaterialAlertDialogBuilder(it)
// Get the layout inflater
val inflater = requireActivity().layoutInflater
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- val token = sharedPref?.getString("token", "")
+ val token = PreferenceHelper.getToken(requireContext())
var view: View
Log.e("dafaq", token!!)
if (token != "") {
- val sharedPref2 = context?.getSharedPreferences("username", Context.MODE_PRIVATE)
- val user = sharedPref2?.getString("username", "")
+ val user = PreferenceHelper.getUsername(requireContext())
view = inflater.inflate(R.layout.dialog_logout, null)
view.findViewById(R.id.user).text =
view.findViewById(R.id.user).text.toString() + " (" + user + ")"
view.findViewById(R.id.logout).setOnClickListener {
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- with(sharedPref!!.edit()) {
- putString("token", "")
- apply()
- }
+ PreferenceHelper.setToken(requireContext(), "")
dialog?.dismiss()
}
} else {
@@ -99,24 +93,15 @@ class LoginDialog : DialogFragment() {
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated
} catch (e: Exception) {
- Log.e(TAG, "dafaq?" + e.toString())
+ Log.e(TAG, "dafaq?$e")
return@launchWhenCreated
}
if (response.error != null) {
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
} else if (response.token != null) {
Toast.makeText(context, R.string.loggedIn, Toast.LENGTH_SHORT).show()
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- with(sharedPref!!.edit()) {
- putString("token", response.token)
- apply()
- }
- val sharedPref2 =
- context?.getSharedPreferences("username", Context.MODE_PRIVATE)
- with(sharedPref2!!.edit()) {
- putString("username", login.username)
- apply()
- }
+ PreferenceHelper.setToken(requireContext(), response.token!!)
+ PreferenceHelper.setUsername(requireContext(), login.username!!)
dialog?.dismiss()
}
}
@@ -139,24 +124,15 @@ class LoginDialog : DialogFragment() {
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated
} catch (e: Exception) {
- Log.e(TAG, "dafaq?" + e.toString())
+ Log.e(TAG, "dafaq?$e")
return@launchWhenCreated
}
if (response.error != null) {
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
} else if (response.token != null) {
Toast.makeText(context, R.string.registered, Toast.LENGTH_SHORT).show()
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- with(sharedPref!!.edit()) {
- putString("token", response.token)
- apply()
- }
- val sharedPref2 =
- context?.getSharedPreferences("username", Context.MODE_PRIVATE)
- with(sharedPref2!!.edit()) {
- putString("username", login.username)
- apply()
- }
+ PreferenceHelper.setToken(requireContext(), response.token!!)
+ PreferenceHelper.setUsername(requireContext(), login.username!!)
dialog?.dismiss()
}
}
diff --git a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt
index 862bf8a4f..a468a2344 100644
--- a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt
+++ b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt
@@ -9,13 +9,14 @@ import android.widget.Toast
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
import com.github.libretube.obj.PlaylistId
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import java.io.IOException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.HttpException
+import java.io.IOException
class PlaylistOptionsDialog(
private val playlistId: String,
@@ -43,9 +44,7 @@ class PlaylistOptionsDialog(
when (which) {
// Clone the playlist to the users Piped account
0 -> {
- val sharedPref =
- context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- val token = sharedPref?.getString("token", "")
+ val token = PreferenceHelper.getToken(requireContext())
if (token != "") {
importPlaylist(token!!, playlistId)
} else {
diff --git a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt
index 45836c26e..8f92e7a8b 100644
--- a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt
+++ b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt
@@ -4,8 +4,8 @@ import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.DialogFragment
-import androidx.preference.PreferenceManager
import com.github.libretube.R
+import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class ShareDialog(
@@ -54,35 +54,19 @@ class ShareDialog(
// get the frontend url if it's a custom instance
private fun getCustomInstanceFrontendUrl(): String {
- val sharedPreferences =
- PreferenceManager.getDefaultSharedPreferences(requireContext())
- val instancePref = sharedPreferences.getString(
+ val instancePref = PreferenceHelper.getString(
+ requireContext(),
"selectInstance",
"https://pipedapi.kavin.rocks"
)
// get the api urls of the other custom instances
- var customInstancesUrls = try {
- sharedPreferences
- .getStringSet("custom_instances_url", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
- }
-
- // get the frontend urls of the other custom instances
- var customInstancesFrontendUrls = try {
- sharedPreferences
- .getStringSet("custom_instances_url", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
- }
+ val customInstances = PreferenceHelper.getCustomInstances(requireContext())
// return the custom instance frontend url if available
- return if (customInstancesUrls.contains(instancePref)) {
- val index = customInstancesUrls.indexOf(instancePref)
- return customInstancesFrontendUrls[index]
- } else {
- ""
+ customInstances.forEach { instance ->
+ if (instance.apiUrl == instancePref) return instance.apiUrl
}
+ return ""
}
}
diff --git a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt
index e5eb2a764..9271af500 100644
--- a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt
+++ b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt
@@ -8,6 +8,7 @@ import android.widget.Toast
import androidx.fragment.app.DialogFragment
import com.github.libretube.BackgroundMode
import com.github.libretube.R
+import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
/**
@@ -50,11 +51,7 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
}
// Add Video to Playlist Dialog
1 -> {
- val sharedPref = context?.getSharedPreferences(
- "token",
- Context.MODE_PRIVATE
- )
- val token = sharedPref?.getString("token", "")
+ val token = PreferenceHelper.getToken(requireContext())
if (token != "") {
val newFragment = AddtoPlaylistDialog()
val bundle = Bundle()
diff --git a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt
index f42f95b69..a45f80c71 100644
--- a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt
+++ b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt
@@ -1,7 +1,6 @@
package com.github.libretube.fragments
import android.annotation.SuppressLint
-import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -18,12 +17,13 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.libretube.R
import com.github.libretube.adapters.ChannelAdapter
import com.github.libretube.obj.Subscribe
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.formatShort
import com.google.android.material.button.MaterialButton
import com.squareup.picasso.Picasso
-import java.io.IOException
import retrofit2.HttpException
+import java.io.IOException
class ChannelFragment : Fragment() {
@@ -63,9 +63,8 @@ class ChannelFragment : Fragment() {
val refreshChannel = {
refreshLayout?.isRefreshing = true
fetchChannel(view)
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
val subButton = view.findViewById(R.id.channel_subscribe)
- if (sharedPref?.getString("token", "") != "") {
+ if (PreferenceHelper.getToken(requireContext()) != "") {
isSubscribed(subButton)
}
}
@@ -95,10 +94,10 @@ class ChannelFragment : Fragment() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.isSubscribed(
channel_id!!,
- sharedPref?.getString("token", "")!!
+ token
)
} catch (e: IOException) {
println(e)
@@ -135,9 +134,9 @@ class ChannelFragment : Fragment() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.subscribe(
- sharedPref?.getString("token", "")!!,
+ token,
Subscribe(channel_id)
)
} catch (e: IOException) {
@@ -158,9 +157,9 @@ class ChannelFragment : Fragment() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.unsubscribe(
- sharedPref?.getString("token", "")!!,
+ token,
Subscribe(channel_id)
)
} catch (e: IOException) {
@@ -201,7 +200,10 @@ class ChannelFragment : Fragment() {
channelName.text = response.name
if (response.verified) {
channelName.setCompoundDrawablesWithIntrinsicBounds(
- 0, 0, R.drawable.ic_verified, 0
+ 0,
+ 0,
+ R.drawable.ic_verified,
+ 0
)
}
view.findViewById(R.id.channel_subs).text = resources.getString(
@@ -231,7 +233,6 @@ class ChannelFragment : Fragment() {
private fun fetchNextPage() {
fun run() {
-
lifecycleScope.launchWhenCreated {
val response = try {
RetrofitInstance.api.getChannelNextPage(channel_id!!, nextPage!!)
diff --git a/app/src/main/java/com/github/libretube/fragments/Home.kt b/app/src/main/java/com/github/libretube/fragments/Home.kt
index 5235e72c7..573d1ad41 100644
--- a/app/src/main/java/com/github/libretube/fragments/Home.kt
+++ b/app/src/main/java/com/github/libretube/fragments/Home.kt
@@ -9,15 +9,15 @@ import android.widget.ProgressBar
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
-import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.libretube.R
import com.github.libretube.adapters.TrendingAdapter
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
-import java.io.IOException
import retrofit2.HttpException
+import java.io.IOException
class Home : Fragment() {
@@ -34,7 +34,6 @@ class Home : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
-
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false)
}
@@ -42,8 +41,8 @@ class Home : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val recyclerView = view.findViewById(R.id.recview)
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- val grid = sharedPreferences.getString(
+ val grid = PreferenceHelper.getString(
+ requireContext(),
"grid",
resources.getInteger(R.integer.grid_items).toString()
)!!
@@ -62,9 +61,8 @@ class Home : Fragment() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPreferences =
- PreferenceManager.getDefaultSharedPreferences(requireContext())
- RetrofitInstance.api.getTrending(sharedPreferences.getString("region", "US")!!)
+ val region = PreferenceHelper.getString(requireContext(), "region", "US")
+ RetrofitInstance.api.getTrending(region!!)
} catch (e: IOException) {
println(e)
Log.e(TAG, "IOException, you might not have internet connection")
diff --git a/app/src/main/java/com/github/libretube/fragments/Library.kt b/app/src/main/java/com/github/libretube/fragments/Library.kt
index 14946625e..4c844066e 100644
--- a/app/src/main/java/com/github/libretube/fragments/Library.kt
+++ b/app/src/main/java/com/github/libretube/fragments/Library.kt
@@ -1,6 +1,5 @@
package com.github.libretube.fragments
-import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -17,10 +16,11 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.libretube.R
import com.github.libretube.adapters.PlaylistsAdapter
import com.github.libretube.dialogs.CreatePlaylistDialog
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.google.android.material.floatingactionbutton.FloatingActionButton
-import java.io.IOException
import retrofit2.HttpException
+import java.io.IOException
class Library : Fragment() {
@@ -28,6 +28,7 @@ class Library : Fragment() {
lateinit var token: String
private lateinit var playlistRecyclerView: RecyclerView
private lateinit var refreshLayout: SwipeRefreshLayout
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
@@ -47,33 +48,37 @@ class Library : Fragment() {
super.onViewCreated(view, savedInstanceState)
playlistRecyclerView = view.findViewById(R.id.playlist_recView)
playlistRecyclerView.layoutManager = LinearLayoutManager(view.context)
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- token = sharedPref?.getString("token", "")!!
+ token = PreferenceHelper.getToken(requireContext())
refreshLayout = view.findViewById(R.id.playlist_refresh)
if (token != "") {
view.findViewById(R.id.boogh2).visibility = View.GONE
view.findViewById(R.id.textLike2).visibility = View.GONE
- fetchPlaylists(view)
+ fetchPlaylists()
refreshLayout.isEnabled = true
refreshLayout.setOnRefreshListener {
- Log.d(TAG, "hmm")
- fetchPlaylists(view)
+ fetchPlaylists()
}
- view.findViewById(R.id.create_playlist).setOnClickListener {
+ val createPlaylistButton = view.findViewById(R.id.create_playlist)
+ createPlaylistButton.setOnClickListener {
val newFragment = CreatePlaylistDialog()
newFragment.show(childFragmentManager, "Create Playlist")
}
- childFragmentManager.setFragmentResultListener("fetchPlaylists", this) { _, _ ->
- fetchPlaylists(view)
- }
} else {
refreshLayout.isEnabled = false
view.findViewById(R.id.create_playlist).visibility = View.GONE
}
}
- private fun fetchPlaylists(view: View) {
+ override fun onResume() {
+ // optimize CreatePlaylistFab bottom margin if miniPlayer active
+ val createPlaylistButton = view?.findViewById(R.id.create_playlist)
+ val layoutParams = createPlaylistButton?.layoutParams as ViewGroup.MarginLayoutParams
+ layoutParams.bottomMargin = if (isMiniPlayerVisible) 180 else 64
+ createPlaylistButton?.layoutParams = layoutParams
+ super.onResume()
+ }
+
+ fun fetchPlaylists() {
fun run() {
refreshLayout.isRefreshing = true
lifecycleScope.launchWhenCreated {
@@ -93,12 +98,8 @@ class Library : Fragment() {
}
if (response.isNotEmpty()) {
runOnUiThread {
- with(view.findViewById(R.id.boogh2)) {
- visibility = View.GONE
- }
- with(view.findViewById(R.id.textLike2)) {
- visibility = View.GONE
- }
+ view?.findViewById(R.id.boogh2)?.visibility = View.GONE
+ view?.findViewById(R.id.textLike2)?.visibility = View.GONE
}
val playlistsAdapter = PlaylistsAdapter(
response.toMutableList(),
@@ -107,13 +108,13 @@ class Library : Fragment() {
playlistRecyclerView.adapter = playlistsAdapter
} else {
runOnUiThread {
- with(view.findViewById(R.id.boogh2)) {
- visibility = View.VISIBLE
- setImageResource(R.drawable.ic_list)
+ view?.findViewById(R.id.boogh2).apply {
+ this?.visibility = View.VISIBLE
+ this?.setImageResource(R.drawable.ic_list)
}
- with(view.findViewById(R.id.textLike2)) {
- visibility = View.VISIBLE
- text = getString(R.string.emptyList)
+ view?.findViewById(R.id.textLike2).apply {
+ this?.visibility = View.VISIBLE
+ this?.text = getString(R.string.emptyList)
}
}
}
diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt
index 54aa2cad5..57755dad2 100644
--- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt
+++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt
@@ -2,6 +2,7 @@ package com.github.libretube.fragments
import android.annotation.SuppressLint
import android.app.NotificationManager
+import android.app.PictureInPictureParams
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
@@ -18,6 +19,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.Button
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.ImageView
@@ -33,7 +35,6 @@ import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
-import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@@ -51,12 +52,13 @@ import com.github.libretube.obj.ChapterSegment
import com.github.libretube.obj.PipedStream
import com.github.libretube.obj.Segment
import com.github.libretube.obj.Segments
+import com.github.libretube.obj.SponsorBlockPrefs
import com.github.libretube.obj.StreamItem
import com.github.libretube.obj.Streams
import com.github.libretube.obj.Subscribe
-import com.github.libretube.preferences.SponsorBlockSettings
import com.github.libretube.util.CronetHelper
import com.github.libretube.util.DescriptionAdapter
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.formatShort
import com.google.android.exoplayer2.C
@@ -84,13 +86,14 @@ import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.squareup.picasso.Picasso
+import org.chromium.net.CronetEngine
+import retrofit2.HttpException
import java.io.IOException
import java.util.concurrent.Executors
import kotlin.math.abs
-import org.chromium.net.CronetEngine
-import retrofit2.HttpException
var isFullScreen = false
+var isMiniPlayerVisible = false
class PlayerFragment : Fragment() {
@@ -118,6 +121,7 @@ class PlayerFragment : Fragment() {
private lateinit var segmentData: Segments
private var relatedStreams: List? = arrayListOf()
private var relatedStreamsEnabled = true
+ private var isPlayerLocked: Boolean = false
private lateinit var relDownloadVideo: LinearLayout
@@ -128,6 +132,7 @@ class PlayerFragment : Fragment() {
private lateinit var title: String
private lateinit var uploader: String
private lateinit var thumbnailUrl: String
+ private val sponsorBlockPrefs = SponsorBlockPrefs()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -149,6 +154,7 @@ class PlayerFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
hideKeyboard()
+ setSponsorBlockPrefs()
initializeTransitionLayout(view)
fetchJsonAndInitPlayer(view)
}
@@ -182,6 +188,7 @@ class PlayerFragment : Fragment() {
val mainMotionLayout =
mainActivity.findViewById(R.id.mainMotionLayout)
mainMotionLayout.progress = abs(progress)
+ exoPlayerView.hideController()
eId = endId
sId = startId
}
@@ -192,13 +199,13 @@ class PlayerFragment : Fragment() {
val mainMotionLayout =
mainActivity.findViewById(R.id.mainMotionLayout)
if (currentId == eId) {
- exoPlayerView.hideController()
+ isMiniPlayerVisible = true
exoPlayerView.useController = false
- mainMotionLayout.progress = 1.toFloat()
+ mainMotionLayout.progress = 1F
} else if (currentId == sId) {
- exoPlayerView.showController()
+ isMiniPlayerVisible = false
exoPlayerView.useController = true
- mainMotionLayout.progress = 0.toFloat()
+ mainMotionLayout.progress = 0F
}
}
@@ -215,6 +222,7 @@ class PlayerFragment : Fragment() {
playerMotionLayout.transitionToStart()
view.findViewById(R.id.close_imageView).setOnClickListener {
+ isMiniPlayerVisible = false
motionLayout.transitionToEnd()
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
@@ -223,6 +231,7 @@ class PlayerFragment : Fragment() {
.commit()
}
view.findViewById(R.id.close_imageButton).setOnClickListener {
+ isMiniPlayerVisible = false
motionLayout.transitionToEnd()
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
@@ -258,30 +267,42 @@ class PlayerFragment : Fragment() {
toggleComments()
}
+ val fullScreenButton = view.findViewById(R.id.fullscreen)
+ val exoTitle = view.findViewById(R.id.exo_title)
+ val mainContainer = view.findViewById(R.id.main_container)
+ val linLayout = view.findViewById(R.id.linLayout)
+
// FullScreen button trigger
- view.findViewById(R.id.fullscreen).setOnClickListener {
- // remember to hide everything when new thing added
+ fullScreenButton.setOnClickListener {
+ exoPlayerView.hideController()
if (!isFullScreen) {
with(motionLayout) {
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
enableTransition(R.id.yt_transition, false)
}
- view.findViewById(R.id.main_container).isClickable = true
- view.findViewById(R.id.linLayout).visibility = View.GONE
+
+ mainContainer.isClickable = true
+ linLayout.visibility = View.GONE
+ fullScreenButton.setImageResource(R.drawable.ic_fullscreen_exit)
+ exoTitle.visibility = View.VISIBLE
+
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
- isFullScreen = true
} else {
with(motionLayout) {
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
enableTransition(R.id.yt_transition, true)
}
- view.findViewById(R.id.main_container).isClickable = false
- view.findViewById(R.id.linLayout).visibility = View.VISIBLE
+
+ mainContainer.isClickable = false
+ linLayout.visibility = View.VISIBLE
+ fullScreenButton.setImageResource(R.drawable.ic_fullscreen)
+ exoTitle.visibility = View.INVISIBLE
+
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
- isFullScreen = false
}
+ isFullScreen = !isFullScreen
}
// switching between original aspect ratio (black bars) and zoomed to fill device screen
@@ -295,6 +316,23 @@ class PlayerFragment : Fragment() {
}
}
+ // lock and unlock the player
+ val lockPlayerButton = view.findViewById(R.id.lock_player)
+ lockPlayerButton.setOnClickListener {
+ // change the locked/unlocked icon
+ if (!isPlayerLocked) {
+ lockPlayerButton.setImageResource(R.drawable.ic_locked)
+ } else {
+ lockPlayerButton.setImageResource(R.drawable.ic_unlocked)
+ }
+
+ // show/hide all the controls
+ lockPlayer(isPlayerLocked)
+
+ // change locked status
+ isPlayerLocked = !isPlayerLocked
+ }
+
val scrollView = view.findViewById(R.id.player_scrollView)
scrollView.viewTreeObserver
.addOnScrollChangedListener {
@@ -326,9 +364,11 @@ class PlayerFragment : Fragment() {
override fun onPause() {
// pause the player if the screen is turned off
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- val pausePlayerOnScreenOffEnabled = sharedPreferences
- .getBoolean("pause_screen_off", false)
+ val pausePlayerOnScreenOffEnabled = PreferenceHelper.getBoolean(
+ requireContext(),
+ "pause_screen_off",
+ false
+ )
// check whether the screen is on
val pm = context?.getSystemService(Context.POWER_SERVICE) as PowerManager
@@ -358,19 +398,20 @@ class PlayerFragment : Fragment() {
}
private fun checkForSegments() {
- if (!exoPlayer.isPlaying || !SponsorBlockSettings.sponsorBlockEnabled) return
+ if (!exoPlayer.isPlaying || !sponsorBlockPrefs.sponsorBlockEnabled) return
exoPlayerView.postDelayed(this::checkForSegments, 100)
- if (!::segmentData.isInitialized || segmentData.segments.isEmpty())
+ if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) {
return
+ }
segmentData.segments.forEach { segment: Segment ->
val segmentStart = (segment.segment!![0] * 1000.0f).toLong()
val segmentEnd = (segment.segment[1] * 1000.0f).toLong()
val currentPosition = exoPlayer.currentPosition
if (currentPosition in segmentStart until segmentEnd) {
- if (SponsorBlockSettings.sponsorNotificationsEnabled) {
+ if (sponsorBlockPrefs.sponsorNotificationsEnabled) {
Toast.makeText(context, R.string.segment_skipped, Toast.LENGTH_SHORT).show()
}
exoPlayer.seekTo(segmentEnd)
@@ -399,27 +440,29 @@ class PlayerFragment : Fragment() {
thumbnailUrl = response.thumbnailUrl!!
// check whether related streams and autoplay are enabled
- val sharedPreferences = PreferenceManager
- .getDefaultSharedPreferences(requireContext())
- autoplay = sharedPreferences.getBoolean("autoplay", false)
- relatedStreamsEnabled = sharedPreferences.getBoolean("related_streams_toggle", true)
+ autoplay = PreferenceHelper.getBoolean(requireContext(), "autoplay", false)
+ relatedStreamsEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "related_streams_toggle", true)
// save related streams for autoplay
relatedStreams = response.relatedStreams
runOnUiThread {
createExoPlayer(view)
prepareExoPlayerView()
if (response.chapters != null) initializeChapters(response.chapters)
+ // set media sources for the player
setResolutionAndSubtitles(view, response)
+ exoPlayer.prepare()
+ initializePlayerView(view, response)
// support for time stamped links
if (arguments?.getLong("timeStamp") != null) {
val position = arguments?.getLong("timeStamp")!! * 1000
exoPlayer.seekTo(position)
}
- exoPlayer.prepare()
exoPlayer.play()
- initializePlayerView(view, response)
+ exoPlayerView.useController = true
initializePlayerNotification(requireContext())
fetchSponsorBlockSegments()
+ // show comments if related streams disabled
if (!relatedStreamsEnabled) toggleComments()
}
}
@@ -427,38 +470,60 @@ class PlayerFragment : Fragment() {
run()
}
+ private fun setSponsorBlockPrefs() {
+ sponsorBlockPrefs.sponsorBlockEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "sb_enabled_key", true)
+ sponsorBlockPrefs.sponsorNotificationsEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "sb_notifications_key", true)
+ sponsorBlockPrefs.introEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "intro_category_key", false)
+ sponsorBlockPrefs.selfPromoEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "selfpromo_category_key", false)
+ sponsorBlockPrefs.interactionEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "interaction_category_key", false)
+ sponsorBlockPrefs.sponsorsEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "sponsors_category_key", true)
+ sponsorBlockPrefs.outroEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "outro_category_key", false)
+ sponsorBlockPrefs.fillerEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "filler_category_key", false)
+ sponsorBlockPrefs.musicOffTopicEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "music_offtopic_category_key", false)
+ sponsorBlockPrefs.previewEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "preview_category_key", false)
+ }
+
private fun fetchSponsorBlockSegments() {
fun run() {
lifecycleScope.launchWhenCreated {
- if (SponsorBlockSettings.sponsorBlockEnabled) {
+ if (sponsorBlockPrefs.sponsorBlockEnabled) {
val categories: ArrayList = arrayListOf()
- if (SponsorBlockSettings.introEnabled) {
+ if (sponsorBlockPrefs.introEnabled) {
categories.add("intro")
}
- if (SponsorBlockSettings.selfPromoEnabled) {
+ if (sponsorBlockPrefs.selfPromoEnabled) {
categories.add("selfpromo")
}
- if (SponsorBlockSettings.interactionEnabled) {
+ if (sponsorBlockPrefs.interactionEnabled) {
categories.add("interaction")
}
- if (SponsorBlockSettings.sponsorsEnabled) {
+ if (sponsorBlockPrefs.sponsorsEnabled) {
categories.add("sponsor")
}
- if (SponsorBlockSettings.outroEnabled) {
+ if (sponsorBlockPrefs.outroEnabled) {
categories.add("outro")
}
- if (SponsorBlockSettings.fillerEnabled) {
+ if (sponsorBlockPrefs.fillerEnabled) {
categories.add("filler")
}
- if (SponsorBlockSettings.musicOfftopicEnabled) {
+ if (sponsorBlockPrefs.musicOffTopicEnabled) {
categories.add("music_offtopic")
}
- if (SponsorBlockSettings.previewEnabled) {
+ if (sponsorBlockPrefs.previewEnabled) {
categories.add("preview")
}
if (categories.size > 0) {
segmentData = try {
-
RetrofitInstance.api.getSegments(
videoId!!,
"[\"" + TextUtils.join("\",\"", categories) + "\"]"
@@ -490,6 +555,7 @@ class PlayerFragment : Fragment() {
setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
// controllerShowTimeoutMs = 1500
controllerHideOnTouch = true
+ useController = false
player = exoPlayer
}
}
@@ -507,10 +573,12 @@ class PlayerFragment : Fragment() {
view.findViewById(R.id.player_title).text = response.title
view.findViewById(R.id.player_description).text = response.description
+ view.findViewById(R.id.exo_title).text = response.title
+
// Listener for play and pause icon change
exoPlayer.addListener(object : Player.Listener {
override fun onIsPlayingChanged(isPlaying: Boolean) {
- if (isPlaying && SponsorBlockSettings.sponsorBlockEnabled) {
+ if (isPlaying && sponsorBlockPrefs.sponsorBlockEnabled) {
exoPlayerView.postDelayed(
this@PlayerFragment::checkForSegments,
100
@@ -523,7 +591,6 @@ class PlayerFragment : Fragment() {
playWhenReady: Boolean,
playbackState: Int
) {
-
exoPlayerView.keepScreenOn = !(
playbackState == Player.STATE_IDLE ||
playbackState == Player.STATE_ENDED ||
@@ -627,15 +694,14 @@ class PlayerFragment : Fragment() {
}
view.findViewById(R.id.player_channel).setOnClickListener {
-
val activity = view.context as MainActivity
val bundle = bundleOf("channel_id" to response.uploaderUrl)
activity.navController.navigate(R.id.channel, bundle)
activity.findViewById(R.id.mainMotionLayout).transitionToEnd()
view.findViewById(R.id.playerMotionLayout).transitionToEnd()
}
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- if (sharedPref?.getString("token", "") != "") {
+ val token = PreferenceHelper.getToken(requireContext())
+ if (token != "") {
val channelId = response.uploaderUrl?.replace("/channel/", "")
val subButton = view.findViewById(R.id.player_subscribe)
isSubscribed(subButton, channelId!!)
@@ -698,14 +764,12 @@ class PlayerFragment : Fragment() {
}
private fun setResolutionAndSubtitles(view: View, response: Streams) {
- val sharedPreferences =
- PreferenceManager.getDefaultSharedPreferences(requireContext())
-
- val videoFormatPreference = sharedPreferences.getString("player_video_format", "WEBM")
- val defres = sharedPreferences.getString("default_res", "")!!
+ val videoFormatPreference =
+ PreferenceHelper.getString(requireContext(), "player_video_format", "WEBM")
+ val defres = PreferenceHelper.getString(requireContext(), "default_res", "")!!
val qualityText = view.findViewById(R.id.quality_text)
- val qualitySelect = view.findViewById(R.id.quality_select)
+ val qualitySelect = view.findViewById(R.id.quality_linLayout)
var videosNameArray: Array = arrayOf()
var videosUrlArray: Array = arrayOf()
@@ -717,7 +781,6 @@ class PlayerFragment : Fragment() {
}
for (vid in response.videoStreams!!) {
- Log.e(TAG, vid.toString())
// append quality to list if it has the preferred format (e.g. MPEG)
if (vid.format.equals(videoFormatPreference)) { // preferred format
videosNameArray += vid.quality!!
@@ -817,11 +880,13 @@ class PlayerFragment : Fragment() {
}
private fun createExoPlayer(view: View) {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- val playbackSpeed = sharedPreferences.getString("playback_speed", "1F")?.toFloat()
+ val playbackSpeed =
+ PreferenceHelper.getString(requireContext(), "playback_speed", "1F")?.toFloat()
// multiply by thousand: s -> ms
- val bufferingGoal = sharedPreferences.getString("buffering_goal", "50")?.toInt()!! * 1000
- val seekIncrement = sharedPreferences.getString("seek_increment", "5")?.toLong()!! * 1000
+ val bufferingGoal =
+ PreferenceHelper.getString(requireContext(), "buffering_goal", "50")?.toInt()!! * 1000
+ val seekIncrement =
+ PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000
val cronetEngine: CronetEngine = CronetHelper.getCronetEngine()
val cronetDataSourceFactory: CronetDataSource.Factory =
@@ -863,7 +928,6 @@ class PlayerFragment : Fragment() {
}
private fun initializePlayerNotification(c: Context) {
-
mediaSession = MediaSessionCompat(c, this.javaClass.name)
mediaSession.apply {
isActive = true
@@ -887,15 +951,26 @@ class PlayerFragment : Fragment() {
}
}
+ private fun lockPlayer(isLocked: Boolean) {
+ val visibility = if (isLocked) View.VISIBLE else View.INVISIBLE
+ exoPlayerView.findViewById(R.id.exo_top_bar_right).visibility = visibility
+ exoPlayerView.findViewById(R.id.exo_play_pause).visibility = visibility
+ exoPlayerView.findViewById(R.id.exo_ffwd_with_amount).visibility = visibility
+ exoPlayerView.findViewById(R.id.exo_rew_with_amount).visibility = visibility
+ exoPlayerView.findViewById(R.id.exo_bottom_bar).visibility = visibility
+ exoPlayerView.findViewById(R.id.exo_title).visibility =
+ if (isLocked && isFullScreen) View.VISIBLE else View.INVISIBLE
+ }
+
private fun isSubscribed(button: MaterialButton, channel_id: String) {
@SuppressLint("ResourceAsColor")
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.isSubscribed(
channel_id,
- sharedPref?.getString("token", "")!!
+ token
)
} catch (e: IOException) {
println(e)
@@ -932,9 +1007,9 @@ class PlayerFragment : Fragment() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.subscribe(
- sharedPref?.getString("token", "")!!,
+ token,
Subscribe(channel_id)
)
} catch (e: IOException) {
@@ -955,9 +1030,9 @@ class PlayerFragment : Fragment() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.unsubscribe(
- sharedPref?.getString("token", "")!!,
+ token,
Subscribe(channel_id)
)
} catch (e: IOException) {
@@ -1072,7 +1147,11 @@ class PlayerFragment : Fragment() {
isFullScreen
)
) {
- requireActivity().enterPictureInPictureMode()
+ activity?.enterPictureInPictureMode(updatePipParams())
}
}
+
+ private fun updatePipParams() = PictureInPictureParams.Builder()
+ .setActions(emptyList())
+ .build()
}
diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt
index 02ac6193a..4e8c20dab 100644
--- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt
+++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt
@@ -1,6 +1,5 @@
package com.github.libretube.fragments
-import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -15,9 +14,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.adapters.PlaylistAdapter
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
-import java.io.IOException
import retrofit2.HttpException
+import java.io.IOException
class PlaylistFragment : Fragment() {
private val TAG = "PlaylistFragment"
@@ -75,9 +75,7 @@ class PlaylistFragment : Fragment() {
view.findViewById(R.id.playlist_uploader).text = response.uploader
view.findViewById(R.id.playlist_totVideos).text =
getString(R.string.videoCount, response.videos.toString())
- val sharedPref2 =
- context?.getSharedPreferences("username", Context.MODE_PRIVATE)
- val user = sharedPref2?.getString("username", "")
+ val user = PreferenceHelper.getUsername(requireContext())
var isOwner = false
if (response.uploaderUrl == null && response.uploader.equals(user, true)) {
isOwner = true
@@ -113,7 +111,6 @@ class PlaylistFragment : Fragment() {
private fun fetchNextPage() {
fun run() {
-
lifecycleScope.launchWhenCreated {
val response = try {
RetrofitInstance.api.getPlaylistNextPage(playlistId!!, nextPage!!)
diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt
index a61714dd8..cfe515d71 100644
--- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt
+++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt
@@ -18,7 +18,6 @@ import android.widget.TextView.OnEditorActionListener
import android.widget.TextView.VISIBLE
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
-import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@@ -27,12 +26,13 @@ import com.github.libretube.adapters.SearchAdapter
import com.github.libretube.adapters.SearchHistoryAdapter
import com.github.libretube.adapters.SearchSuggestionsAdapter
import com.github.libretube.hideKeyboard
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import java.io.IOException
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import retrofit2.HttpException
+import java.io.IOException
class SearchFragment : Fragment() {
private val TAG = "SearchFragment"
@@ -94,7 +94,7 @@ class SearchFragment : Fragment() {
tempSelectedItem = id
}
.setPositiveButton(
- getString(R.string.okay),
+ getString(R.string.okay)
) { _, _ ->
selectedFilter = tempSelectedItem
apiSearchFilter = when (selectedFilter) {
@@ -266,7 +266,7 @@ class SearchFragment : Fragment() {
private fun showHistory() {
searchRecView.visibility = GONE
- val historyList = getHistory()
+ val historyList = PreferenceHelper.getHistory(requireContext())
if (historyList.isNotEmpty()) {
historyRecView.adapter =
SearchHistoryAdapter(requireContext(), historyList, autoTextView, this)
@@ -275,10 +275,10 @@ class SearchFragment : Fragment() {
}
private fun addToHistory(query: String) {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- val searchHistoryEnabled = sharedPreferences.getBoolean("search_history_toggle", true)
+ val searchHistoryEnabled =
+ PreferenceHelper.getBoolean(requireContext(), "search_history_toggle", true)
if (searchHistoryEnabled) {
- var historyList = getHistory()
+ var historyList = PreferenceHelper.getHistory(requireContext())
if ((historyList.isNotEmpty() && historyList.contains(query)) || query == "") {
return
@@ -290,20 +290,7 @@ class SearchFragment : Fragment() {
historyList = historyList.takeLast(10)
}
- val set: Set = HashSet(historyList)
-
- sharedPreferences.edit().putStringSet("search_history", set)
- .apply()
- }
- }
-
- private fun getHistory(): List {
- return try {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- val set: Set = sharedPreferences.getStringSet("search_history", HashSet())!!
- set.toList()
- } catch (e: Exception) {
- emptyList()
+ PreferenceHelper.saveHistory(requireContext(), historyList)
}
}
}
diff --git a/app/src/main/java/com/github/libretube/fragments/Subscriptions.kt b/app/src/main/java/com/github/libretube/fragments/Subscriptions.kt
index 077b5415e..d502a7cf3 100644
--- a/app/src/main/java/com/github/libretube/fragments/Subscriptions.kt
+++ b/app/src/main/java/com/github/libretube/fragments/Subscriptions.kt
@@ -1,6 +1,5 @@
package com.github.libretube.fragments
-import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -15,7 +14,6 @@ import android.widget.Toast
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
-import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@@ -23,9 +21,10 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.libretube.R
import com.github.libretube.adapters.SubscriptionAdapter
import com.github.libretube.adapters.SubscriptionChannelAdapter
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
-import java.io.IOException
import retrofit2.HttpException
+import java.io.IOException
class Subscriptions : Fragment() {
val TAG = "SubFragment"
@@ -50,8 +49,7 @@ class Subscriptions : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- token = sharedPref?.getString("token", "")!!
+ token = PreferenceHelper.getToken(requireContext())
refreshLayout = view.findViewById(R.id.sub_refresh)
if (token != "") {
view.findViewById(R.id.loginOrRegister).visibility = View.GONE
@@ -63,9 +61,10 @@ class Subscriptions : Fragment() {
var channelRecView = view.findViewById(R.id.sub_channels)
var feedRecView = view.findViewById(R.id.sub_feed)
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- val grid = sharedPreferences.getString(
- "grid", resources.getInteger(R.integer.grid_items).toString()
+ val grid = PreferenceHelper.getString(
+ requireContext(),
+ "grid",
+ resources.getInteger(R.integer.grid_items).toString()
)!!
feedRecView.layoutManager = GridLayoutManager(view.context, grid.toInt())
fetchFeed(feedRecView, progressBar, view)
diff --git a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt
index 71e1a830f..4ba48f667 100644
--- a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt
+++ b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt
@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
data class CommentsPage(
val comments: MutableList = arrayListOf(),
val disabled: Boolean? = null,
- val nextpage: String? = "",
+ val nextpage: String? = ""
) {
constructor() : this(arrayListOf(), null, "")
}
diff --git a/app/src/main/java/com/github/libretube/obj/CustomInstance.kt b/app/src/main/java/com/github/libretube/obj/CustomInstance.kt
new file mode 100644
index 000000000..880044448
--- /dev/null
+++ b/app/src/main/java/com/github/libretube/obj/CustomInstance.kt
@@ -0,0 +1,7 @@
+package com.github.libretube.obj
+
+class CustomInstance(
+ var name: String = "",
+ var apiUrl: String = "",
+ var frontendUrl: String = ""
+)
diff --git a/app/src/main/java/com/github/libretube/obj/DeleteUserRequest.kt b/app/src/main/java/com/github/libretube/obj/DeleteUserRequest.kt
new file mode 100644
index 000000000..f48084e46
--- /dev/null
+++ b/app/src/main/java/com/github/libretube/obj/DeleteUserRequest.kt
@@ -0,0 +1,5 @@
+package com.github.libretube.obj
+
+data class DeleteUserRequest(
+ var password: String? = null
+)
diff --git a/app/src/main/java/com/github/libretube/obj/Playlist.kt b/app/src/main/java/com/github/libretube/obj/Playlist.kt
index 02e8dee8b..1c1a054b4 100644
--- a/app/src/main/java/com/github/libretube/obj/Playlist.kt
+++ b/app/src/main/java/com/github/libretube/obj/Playlist.kt
@@ -12,5 +12,5 @@ data class Playlist(
var uploaderUrl: String? = null,
var uploaderAvatar: String? = null,
var videos: Int? = 0,
- var relatedStreams: List? = null,
+ var relatedStreams: List? = null
)
diff --git a/app/src/main/java/com/github/libretube/obj/PlaylistId.kt b/app/src/main/java/com/github/libretube/obj/PlaylistId.kt
index 2db63f2da..93f31488c 100644
--- a/app/src/main/java/com/github/libretube/obj/PlaylistId.kt
+++ b/app/src/main/java/com/github/libretube/obj/PlaylistId.kt
@@ -6,5 +6,5 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
data class PlaylistId(
var playlistId: String? = null,
var videoId: String? = null,
- var index: Int = -1,
+ var index: Int = -1
)
diff --git a/app/src/main/java/com/github/libretube/obj/Playlists.kt b/app/src/main/java/com/github/libretube/obj/Playlists.kt
index b4444cef5..f5dd42a61 100644
--- a/app/src/main/java/com/github/libretube/obj/Playlists.kt
+++ b/app/src/main/java/com/github/libretube/obj/Playlists.kt
@@ -7,5 +7,5 @@ data class Playlists(
var id: String? = null,
var name: String? = null,
var shortDescription: String? = null,
- var thumbnail: String? = null,
+ var thumbnail: String? = null
)
diff --git a/app/src/main/java/com/github/libretube/obj/SponsorBlockPrefs.kt b/app/src/main/java/com/github/libretube/obj/SponsorBlockPrefs.kt
new file mode 100644
index 000000000..73118d5ca
--- /dev/null
+++ b/app/src/main/java/com/github/libretube/obj/SponsorBlockPrefs.kt
@@ -0,0 +1,14 @@
+package com.github.libretube.obj
+
+class SponsorBlockPrefs(
+ var sponsorBlockEnabled: Boolean = false,
+ var sponsorNotificationsEnabled: Boolean = false,
+ var sponsorsEnabled: Boolean = false,
+ var selfPromoEnabled: Boolean = false,
+ var interactionEnabled: Boolean = false,
+ var introEnabled: Boolean = false,
+ var outroEnabled: Boolean = false,
+ var fillerEnabled: Boolean = false,
+ var musicOffTopicEnabled: Boolean = false,
+ var previewEnabled: Boolean = false
+)
diff --git a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt
index 3f0715198..1de88cba5 100644
--- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt
+++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt
@@ -1,15 +1,13 @@
package com.github.libretube.preferences
-import android.content.Context
import android.os.Bundle
import android.widget.TextView
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
-import androidx.preference.PreferenceManager
import com.github.libretube.R
import com.github.libretube.requireMainActivityRestart
+import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import org.chromium.base.CommandLine.reset
class AdvancedSettings : PreferenceFragmentCompat() {
val TAG = "AdvancedSettings"
@@ -22,9 +20,7 @@ class AdvancedSettings : PreferenceFragmentCompat() {
val clearHistory = findPreference("clear_history")
clearHistory?.setOnPreferenceClickListener {
- val sharedPreferences =
- PreferenceManager.getDefaultSharedPreferences(requireContext())
- sharedPreferences.edit().remove("search_history").commit()
+ PreferenceHelper.removePreference(requireContext(), "search_history")
true
}
@@ -39,14 +35,10 @@ class AdvancedSettings : PreferenceFragmentCompat() {
MaterialAlertDialogBuilder(requireContext())
.setPositiveButton(R.string.reset) { _, _ ->
// clear default preferences
- val sharedPreferences =
- PreferenceManager.getDefaultSharedPreferences(requireContext())
- sharedPreferences.edit().clear().commit()
+ PreferenceHelper.clearPreferences(requireContext())
// clear login token
- val sharedPrefToken =
- context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- sharedPrefToken?.edit()?.clear()?.commit()
+ PreferenceHelper.setToken(requireContext(), "")
requireMainActivityRestart = true
activity?.recreate()
diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt
index ea88a50f4..b8a4bd076 100644
--- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt
+++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt
@@ -21,7 +21,7 @@ class AppearanceSettings : PreferenceFragmentCompat() {
val themeToggle = findPreference("theme_togglee")
themeToggle?.setOnPreferenceChangeListener { _, _ ->
requireMainActivityRestart = true
- ThemeHelper().restartMainActivity(requireContext())
+ ThemeHelper.restartMainActivity(requireContext())
true
}
@@ -34,7 +34,7 @@ class AppearanceSettings : PreferenceFragmentCompat() {
val iconChange = findPreference("icon_change")
iconChange?.setOnPreferenceChangeListener { _, newValue ->
- ThemeHelper().changeIcon(requireContext(), newValue.toString())
+ ThemeHelper.changeIcon(requireContext(), newValue.toString())
true
}
diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt
index 430f89944..f34042572 100644
--- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt
+++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt
@@ -2,7 +2,6 @@ package com.github.libretube.preferences
import android.Manifest
import android.content.ContentResolver
-import android.content.Context
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
@@ -19,19 +18,20 @@ import androidx.lifecycle.lifecycleScope
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
-import androidx.preference.PreferenceManager
import com.github.libretube.R
import com.github.libretube.dialogs.CustomInstanceDialog
+import com.github.libretube.dialogs.DeleteAccountDialog
import com.github.libretube.dialogs.LoginDialog
import com.github.libretube.requireMainActivityRestart
+import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.RetrofitInstance
+import org.json.JSONObject
+import org.json.JSONTokener
+import retrofit2.HttpException
import java.io.IOException
import java.io.InputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
-import org.json.JSONObject
-import org.json.JSONTokener
-import retrofit2.HttpException
class InstanceSettings : PreferenceFragmentCompat() {
val TAG = "InstanceSettings"
@@ -59,8 +59,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
val jsonObject = JSONTokener(json).nextValue() as JSONObject
Log.e(TAG, jsonObject.getJSONArray("subscriptions").toString())
for (
- i in 0 until jsonObject.getJSONArray("subscriptions")
- .length()
+ i in 0 until jsonObject.getJSONArray("subscriptions")
+ .length()
) {
var url =
jsonObject.getJSONArray("subscriptions").getJSONObject(i)
@@ -85,8 +85,9 @@ class InstanceSettings : PreferenceFragmentCompat() {
inputStream?.bufferedReader()?.readLines()?.forEach {
if (it.isNotBlank()) {
val channelId = it.substringBefore(",")
- if (channelId.length == 24)
+ if (channelId.length == 24) {
channels.add(channelId)
+ }
}
}
}
@@ -132,11 +133,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
val clearCustomInstances = findPreference("clearCustomInstances")
clearCustomInstances?.setOnPreferenceClickListener {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
- sharedPreferences.edit()
- .remove("custom_instances_name")
- .remove("custom_instances_url")
- .commit()
+ PreferenceHelper.removePreference(requireContext(), "customInstances")
activity?.recreate()
true
}
@@ -149,10 +146,21 @@ class InstanceSettings : PreferenceFragmentCompat() {
true
}
+ val deleteAccount = findPreference("delete_account")
+ deleteAccount?.setOnPreferenceClickListener {
+ val token = PreferenceHelper.getToken(requireContext())
+ if (token != "") {
+ val newFragment = DeleteAccountDialog()
+ newFragment.show(childFragmentManager, "DeleteAccountDialog")
+ } else {
+ Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
+ }
+ true
+ }
+
val importFromYt = findPreference("import_from_yt")
importFromYt?.setOnPreferenceClickListener {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- val token = sharedPref?.getString("token", "")!!
+ val token = PreferenceHelper.getToken(requireContext())
// check StorageAccess
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Log.d("myz", "" + Build.VERSION.SDK_INT)
@@ -204,27 +212,15 @@ class InstanceSettings : PreferenceFragmentCompat() {
}
private fun initCustomInstances() {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
+ val customInstances = PreferenceHelper.getCustomInstances(requireContext())
- // get the names of the custom instances
- val customInstancesNames = try {
- sharedPreferences
- .getStringSet("custom_instances_name", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
+ var instanceNames = resources.getStringArray(R.array.instances)
+ var instanceValues = resources.getStringArray(R.array.instancesValue)
+ customInstances.forEach { instance ->
+ instanceNames += instance.name
+ instanceValues += instance.apiUrl
}
- // get the urls of the custom instances
- val customInstancesUrls = try {
- sharedPreferences
- .getStringSet("custom_instances_url", HashSet())!!.toList()
- } catch (e: Exception) {
- emptyList()
- }
-
- val instanceNames = resources.getStringArray(R.array.instances) + customInstancesNames
- val instanceValues = resources.getStringArray(R.array.instancesValue) + customInstancesUrls
-
// add custom instances to the list preference
val instance = findPreference("selectInstance")
instance?.entries = instanceNames
@@ -241,15 +237,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
}
private fun logout() {
- val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
- val token = sharedPref?.getString("token", "")
- if (token != "") {
- with(sharedPref!!.edit()) {
- putString("token", "")
- apply()
- }
- Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
- }
+ PreferenceHelper.setToken(requireContext(), "")
}
private fun fetchInstance() {
@@ -305,11 +293,10 @@ class InstanceSettings : PreferenceFragmentCompat() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
- val sharedPref =
- context?.getSharedPreferences("token", Context.MODE_PRIVATE)
+ val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.api.importSubscriptions(
false,
- sharedPref?.getString("token", "")!!,
+ token,
channels
)
} catch (e: IOException) {
diff --git a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt
index 6654872d4..a8ceef736 100644
--- a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt
+++ b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt
@@ -31,7 +31,7 @@ class MainSettings : PreferenceFragmentCompat() {
val language = findPreference("language")
language?.setOnPreferenceChangeListener { _, _ ->
- ThemeHelper().restartMainActivity(requireContext())
+ ThemeHelper.restartMainActivity(requireContext())
true
}
diff --git a/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt b/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt
index 1236a8b5c..4d8def0b3 100644
--- a/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt
+++ b/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt
@@ -3,88 +3,15 @@ package com.github.libretube.preferences
import android.os.Bundle
import android.widget.TextView
import androidx.preference.PreferenceFragmentCompat
-import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R
class SponsorBlockSettings : PreferenceFragmentCompat() {
private val TAG = "SponsorBlockSettings"
- companion object {
- var sponsorBlockEnabled: Boolean = false
- var sponsorNotificationsEnabled: Boolean = false
- var sponsorsEnabled: Boolean = false
- var selfPromoEnabled: Boolean = false
- var interactionEnabled: Boolean = false
- var introEnabled: Boolean = false
- var outroEnabled: Boolean = false
- var fillerEnabled: Boolean = false
- var musicOfftopicEnabled: Boolean = false
- var previewEnabled: Boolean = false
- }
-
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey)
val topBarTextView = activity?.findViewById(R.id.topBar_textView)
topBarTextView?.text = getString(R.string.sponsorblock)
-
- val sponsorBlockToggle = findPreference("sb_enabled_key")
- sponsorBlockToggle?.setOnPreferenceChangeListener { _, newValue ->
- sponsorBlockEnabled = newValue as Boolean
- true
- }
-
- val notificationsToggle = findPreference("sb_notifications_key")
- notificationsToggle?.setOnPreferenceChangeListener { _, newValue ->
- sponsorNotificationsEnabled = newValue as Boolean
- true
- }
-
- val sponsorToggle = findPreference("sponsors_category_key")
- sponsorToggle?.setOnPreferenceChangeListener { _, newValue ->
- sponsorsEnabled = newValue as Boolean
- true
- }
- val selfPromoToggle = findPreference("selfpromo_category_key")
- selfPromoToggle?.setOnPreferenceChangeListener { _, newValue ->
- selfPromoEnabled = newValue as Boolean
- true
- }
-
- val interactionToggle = findPreference("interaction_category_key")
- interactionToggle?.setOnPreferenceChangeListener { _, newValue ->
- interactionEnabled = newValue as Boolean
- true
- }
-
- val introToggle = findPreference("intro_category_key")
- introToggle?.setOnPreferenceChangeListener { _, newValue ->
- introEnabled = newValue as Boolean
- true
- }
-
- val outroToggle = findPreference("outro_category_key")
- outroToggle?.setOnPreferenceChangeListener { _, newValue ->
- outroEnabled = newValue as Boolean
- true
- }
-
- val fillerToggle = findPreference("filler_category_key")
- fillerToggle?.setOnPreferenceChangeListener { _, newValue ->
- fillerEnabled = newValue as Boolean
- true
- }
-
- val musicToggle = findPreference("music_offtopic_category_key")
- musicToggle?.setOnPreferenceChangeListener { _, newValue ->
- musicOfftopicEnabled = newValue as Boolean
- true
- }
-
- val previewToggle = findPreference("preview_category_key")
- previewToggle?.setOnPreferenceChangeListener { _, newValue ->
- previewEnabled = newValue as Boolean
- true
- }
}
}
diff --git a/app/src/main/java/com/github/libretube/util/DescriptionAdapter.kt b/app/src/main/java/com/github/libretube/util/DescriptionAdapter.kt
index ad8feb7ae..8f81b6fad 100644
--- a/app/src/main/java/com/github/libretube/util/DescriptionAdapter.kt
+++ b/app/src/main/java/com/github/libretube/util/DescriptionAdapter.kt
@@ -82,7 +82,10 @@ class DescriptionAdapter(
*/
return try {
val resizedBitmap = Bitmap.createScaledBitmap(
- bitmap, 1080, 1080, false
+ bitmap,
+ 1080,
+ 1080,
+ false
)
resizedBitmap
} catch (e: Exception) {
diff --git a/app/src/main/java/com/github/libretube/util/VideoViews.kt b/app/src/main/java/com/github/libretube/util/FormatShort.kt
similarity index 100%
rename from app/src/main/java/com/github/libretube/util/VideoViews.kt
rename to app/src/main/java/com/github/libretube/util/FormatShort.kt
diff --git a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt
index 71a52a542..1c4ec8400 100644
--- a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt
+++ b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt
@@ -2,14 +2,12 @@ package com.github.libretube.util
import android.content.Context
import android.os.Build
-import androidx.preference.PreferenceManager
import java.util.*
-class LocaleHelper {
+object LocaleHelper {
fun updateLanguage(context: Context) {
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
- val languageName = sharedPreferences.getString("language", "sys")
+ val languageName = PreferenceHelper.getString(context, "language", "en")
if (languageName != "") {
setLanguage(context, languageName!!)
}
diff --git a/app/src/main/java/com/github/libretube/util/PipedApi.kt b/app/src/main/java/com/github/libretube/util/PipedApi.kt
index 82b8c67aa..ca0f791a5 100644
--- a/app/src/main/java/com/github/libretube/util/PipedApi.kt
+++ b/app/src/main/java/com/github/libretube/util/PipedApi.kt
@@ -2,6 +2,7 @@ package com.github.libretube.util
import com.github.libretube.obj.Channel
import com.github.libretube.obj.CommentsPage
+import com.github.libretube.obj.DeleteUserRequest
import com.github.libretube.obj.Instances
import com.github.libretube.obj.Login
import com.github.libretube.obj.Message
@@ -86,6 +87,12 @@ interface PipedApi {
@POST("register")
suspend fun register(@Body login: Login): Token
+ @POST("user/delete")
+ suspend fun deleteAccount(
+ @Header("Authorization") token: String,
+ @Body password: DeleteUserRequest
+ )
+
@GET("feed")
suspend fun getFeed(@Query("authToken") token: String?): List
diff --git a/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt
new file mode 100644
index 000000000..310a02578
--- /dev/null
+++ b/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt
@@ -0,0 +1,132 @@
+package com.github.libretube.util
+
+import android.content.Context
+import android.content.SharedPreferences
+import androidx.preference.PreferenceManager
+import com.github.libretube.obj.CustomInstance
+import com.google.common.reflect.TypeToken
+import com.google.gson.Gson
+import java.lang.reflect.Type
+
+object PreferenceHelper {
+ fun setString(context: Context, key: String?, value: String?) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ editor.putString(key, value)
+ editor.apply()
+ }
+
+ fun setInt(context: Context, key: String?, value: Int) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ editor.putInt(key, value)
+ editor.apply()
+ }
+
+ fun setLong(context: Context, key: String?, value: Long) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ editor.putLong(key, value)
+ editor.apply()
+ }
+
+ fun setBoolean(context: Context, key: String?, value: Boolean) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ editor.putBoolean(key, value)
+ editor.apply()
+ }
+
+ fun getString(context: Context, key: String?, defValue: String?): String? {
+ val settings: SharedPreferences = getDefaultSharedPreferences(context)
+ return settings.getString(key, defValue)
+ }
+
+ fun getInt(context: Context, key: String?, defValue: Int): Int {
+ val settings: SharedPreferences = getDefaultSharedPreferences(context)
+ return settings.getInt(key, defValue)
+ }
+
+ fun getLong(context: Context, key: String?, defValue: Long): Long {
+ val settings: SharedPreferences = getDefaultSharedPreferences(context)
+ return settings.getLong(key, defValue)
+ }
+
+ fun getBoolean(context: Context, key: String?, defValue: Boolean): Boolean {
+ val settings: SharedPreferences = getDefaultSharedPreferences(context)
+ return settings.getBoolean(key, defValue)
+ }
+
+ fun clearPreferences(context: Context) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ editor.clear().apply()
+ }
+
+ fun removePreference(context: Context, value: String?) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ editor.remove(value).apply()
+ }
+
+ fun getToken(context: Context): String {
+ val sharedPref = context.getSharedPreferences("token", Context.MODE_PRIVATE)
+ return sharedPref?.getString("token", "")!!
+ }
+
+ fun setToken(context: Context, newValue: String) {
+ val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit()
+ editor.putString("token", newValue).apply()
+ }
+
+ fun getUsername(context: Context): String {
+ val sharedPref = context.getSharedPreferences("username", Context.MODE_PRIVATE)
+ return sharedPref.getString("username", "")!!
+ }
+
+ fun setUsername(context: Context, newValue: String) {
+ val editor = context.getSharedPreferences("username", Context.MODE_PRIVATE).edit()
+ editor.putString("username", newValue).apply()
+ }
+
+ fun saveCustomInstance(context: Context, customInstance: CustomInstance) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ val gson = Gson()
+
+ val customInstancesList = getCustomInstances(context)
+ customInstancesList += customInstance
+
+ val json = gson.toJson(customInstancesList)
+ editor.putString("customInstances", json).apply()
+ }
+
+ fun getCustomInstances(context: Context): ArrayList {
+ val settings = getDefaultSharedPreferences(context)
+ val gson = Gson()
+ val json: String = settings.getString("customInstances", "")!!
+ val type: Type = object : TypeToken?>() {}.type
+ return try {
+ gson.fromJson(json, type)
+ } catch (e: Exception) {
+ arrayListOf()
+ }
+ }
+
+ fun getHistory(context: Context): List {
+ return try {
+ val settings = getDefaultSharedPreferences(context)
+ val set: Set = settings.getStringSet("search_history", HashSet())!!
+ set.toList()
+ } catch (e: Exception) {
+ emptyList()
+ }
+ }
+
+ fun saveHistory(context: Context, historyList: List) {
+ val editor = getDefaultSharedPreferencesEditor(context)
+ val set: Set = HashSet(historyList)
+ editor.putStringSet("search_history", set).apply()
+ }
+
+ private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
+ return PreferenceManager.getDefaultSharedPreferences(context)
+ }
+
+ private fun getDefaultSharedPreferencesEditor(context: Context): SharedPreferences.Editor {
+ return getDefaultSharedPreferences(context).edit()
+ }
+}
diff --git a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt
index 1719be3e7..ca9498685 100644
--- a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt
+++ b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt
@@ -7,20 +7,17 @@ import android.content.Intent
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
-import androidx.preference.PreferenceManager
import com.github.libretube.R
-class ThemeHelper {
+object ThemeHelper {
fun updateTheme(context: Context) {
updateAccentColor(context)
updateThemeMode(context)
}
- fun updateAccentColor(context: Context) {
- val colorAccent =
- PreferenceManager.getDefaultSharedPreferences(context).getString("accent_color", "red")
- when (colorAccent) {
+ private fun updateAccentColor(context: Context) {
+ when (PreferenceHelper.getString(context, "accent_color", "red")) {
"my" -> context.setTheme(R.style.Theme_MY)
"red" -> context.setTheme(R.style.Theme_Red)
"blue" -> context.setTheme(R.style.Theme_Blue)
@@ -30,10 +27,8 @@ class ThemeHelper {
}
}
- fun updateThemeMode(context: Context) {
- val themeMode =
- PreferenceManager.getDefaultSharedPreferences(context).getString("theme_togglee", "A")
- when (themeMode) {
+ private fun updateThemeMode(context: Context) {
+ when (PreferenceHelper.getString(context, "theme_togglee", "A")) {
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
diff --git a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt
index 2c6b9dada..3513a636d 100644
--- a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt
+++ b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt
@@ -7,12 +7,12 @@ import com.github.libretube.GITHUB_API_URL
import com.github.libretube.dialogs.NoUpdateAvailableDialog
import com.github.libretube.dialogs.UpdateAvailableDialog
import com.github.libretube.obj.UpdateInfo
+import org.json.JSONArray
+import org.json.JSONObject
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
import javax.net.ssl.HttpsURLConnection
-import org.json.JSONArray
-import org.json.JSONObject
fun checkUpdate(childFragmentManager: FragmentManager) {
var updateInfo: UpdateInfo? = UpdateInfo("", "")
diff --git a/app/src/main/res/drawable/ic_add.xml b/app/src/main/res/drawable/ic_add.xml
index 0dbf2e57a..9460f4eaa 100644
--- a/app/src/main/res/drawable/ic_add.xml
+++ b/app/src/main/res/drawable/ic_add.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_arrow_down.xml b/app/src/main/res/drawable/ic_arrow_down.xml
index 10cedc2e3..68fd4058e 100644
--- a/app/src/main/res/drawable/ic_arrow_down.xml
+++ b/app/src/main/res/drawable/ic_arrow_down.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_arrow_up_down.xml b/app/src/main/res/drawable/ic_arrow_up_down.xml
index aa33a09e8..4b0da4369 100644
--- a/app/src/main/res/drawable/ic_arrow_up_down.xml
+++ b/app/src/main/res/drawable/ic_arrow_up_down.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="160">
diff --git a/app/src/main/res/drawable/ic_arrow_up_left.xml b/app/src/main/res/drawable/ic_arrow_up_left.xml
new file mode 100644
index 000000000..e5ed20662
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow_up_left.xml
@@ -0,0 +1,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_aspect_ratio.xml b/app/src/main/res/drawable/ic_aspect_ratio.xml
index 4f2bff3ea..e7b7cbba1 100644
--- a/app/src/main/res/drawable/ic_aspect_ratio.xml
+++ b/app/src/main/res/drawable/ic_aspect_ratio.xml
@@ -1,9 +1,9 @@
-
+ android:height="24dp"
+ android:tint="#FFFFFF"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_bell.xml b/app/src/main/res/drawable/ic_bell.xml
index a65a68661..458ed83e0 100644
--- a/app/src/main/res/drawable/ic_bell.xml
+++ b/app/src/main/res/drawable/ic_bell.xml
@@ -4,7 +4,7 @@
android:viewportWidth="18"
android:viewportHeight="20">
+ android:fillType="evenOdd"
+ android:pathData="M8.625,0H9.375C9.5821,0 9.75,0.1679 9.75,0.375C9.75,0.5821 9.9179,0.75 10.125,0.75C10.3321,0.75 10.5,0.9179 10.5,1.125V1.875C10.5,2.4963 11.0088,3.0566 11.5685,3.3265C12.4353,3.7446 13.5132,4.5489 14.0889,5.6503C14.2067,5.8758 14.25,6.1307 14.25,6.3852V12.0512C14.25,12.9156 14.8488,13.6151 15.5614,14.1044C15.8681,14.315 16.102,14.5525 16.3642,14.8462C16.4522,14.9448 16.5,15.0728 16.5,15.2049C16.5,15.506 16.256,15.75 15.955,15.75H2.051C1.7467,15.75 1.5,15.5033 1.5,15.199C1.5,15.0704 1.5445,14.9452 1.6287,14.848C1.8916,14.5448 2.1396,14.3062 2.4619,14.0946C3.1737,13.6273 3.75,12.9293 3.75,12.0778V6.3852C3.75,6.1307 3.7933,5.8758 3.9111,5.6503C4.4868,4.5489 5.5648,3.7446 6.4316,3.3265C6.9912,3.0566 7.5,2.4963 7.5,1.875V1.125C7.5,0.9179 7.6679,0.75 7.875,0.75C8.0821,0.75 8.25,0.5821 8.25,0.375C8.25,0.1679 8.4179,0 8.625,0ZM9,19.4998C7.7574,19.4998 6.7501,18.4925 6.75,17.2499H11.25C11.2499,18.4925 10.2426,19.4998 9,19.4998ZM0.0558,7.5132C-0.1246,6.2857 0.1356,5.034 0.7902,3.9801C1.4447,2.9262 2.4513,2.1382 3.6315,1.7557L3.9552,2.7546C3.0111,3.0605 2.2058,3.691 1.6821,4.5341C1.1585,5.3772 0.9503,6.3786 1.0946,7.3605L0.0558,7.5132ZM17.1808,3.934C16.5153,2.8869 15.5006,2.1094 14.3165,1.7392L14.0032,2.7414C14.9504,3.0375 15.7623,3.6596 16.2946,4.4972C16.827,5.3348 17.0455,6.334 16.9115,7.3174L17.9519,7.4592C18.1194,6.2299 17.8463,4.981 17.1808,3.934Z" />
diff --git a/app/src/main/res/drawable/ic_bell_small.xml b/app/src/main/res/drawable/ic_bell_small.xml
index c9f18e09d..2df32bee1 100644
--- a/app/src/main/res/drawable/ic_bell_small.xml
+++ b/app/src/main/res/drawable/ic_bell_small.xml
@@ -4,7 +4,7 @@
android:viewportWidth="18"
android:viewportHeight="20">
+ android:fillType="evenOdd"
+ android:pathData="M8.625,0H9.375C9.5821,0 9.75,0.1679 9.75,0.375C9.75,0.5821 9.9179,0.75 10.125,0.75C10.3321,0.75 10.5,0.9179 10.5,1.125V1.875C10.5,2.4963 11.0088,3.0566 11.5685,3.3265C12.4353,3.7446 13.5132,4.5489 14.0889,5.6503C14.2067,5.8758 14.25,6.1307 14.25,6.3852V12.0512C14.25,12.9156 14.8488,13.6151 15.5614,14.1044C15.8681,14.315 16.102,14.5525 16.3642,14.8462C16.4522,14.9448 16.5,15.0728 16.5,15.2049C16.5,15.506 16.256,15.75 15.955,15.75H2.051C1.7467,15.75 1.5,15.5033 1.5,15.199C1.5,15.0704 1.5445,14.9452 1.6287,14.848C1.8916,14.5448 2.1396,14.3062 2.4619,14.0946C3.1737,13.6273 3.75,12.9293 3.75,12.0778V6.3852C3.75,6.1307 3.7933,5.8758 3.9111,5.6503C4.4868,4.5489 5.5648,3.7446 6.4316,3.3265C6.9912,3.0566 7.5,2.4963 7.5,1.875V1.125C7.5,0.9179 7.6679,0.75 7.875,0.75C8.0821,0.75 8.25,0.5821 8.25,0.375C8.25,0.1679 8.4179,0 8.625,0ZM9,19.4998C7.7574,19.4998 6.7501,18.4925 6.75,17.2499H11.25C11.2499,18.4925 10.2426,19.4998 9,19.4998ZM0.0558,7.5132C-0.1246,6.2857 0.1356,5.034 0.7902,3.9801C1.4447,2.9262 2.4513,2.1382 3.6315,1.7557L3.9552,2.7546C3.0111,3.0605 2.2058,3.691 1.6821,4.5341C1.1585,5.3772 0.9503,6.3786 1.0946,7.3605L0.0558,7.5132ZM17.1808,3.934C16.5153,2.8869 15.5006,2.1094 14.3165,1.7392L14.0032,2.7414C14.9504,3.0375 15.7623,3.6596 16.2946,4.4972C16.827,5.3348 17.0455,6.334 16.9115,7.3174L17.9519,7.4592C18.1194,6.2299 17.8463,4.981 17.1808,3.934Z" />
diff --git a/app/src/main/res/drawable/ic_block.xml b/app/src/main/res/drawable/ic_block.xml
index bae4d16c2..6dca0e37e 100644
--- a/app/src/main/res/drawable/ic_block.xml
+++ b/app/src/main/res/drawable/ic_block.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_campaign.xml b/app/src/main/res/drawable/ic_campaign.xml
index 9a5eb603d..7f22d42a0 100644
--- a/app/src/main/res/drawable/ic_campaign.xml
+++ b/app/src/main/res/drawable/ic_campaign.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml
index 3b3c877a9..f96401501 100644
--- a/app/src/main/res/drawable/ic_close.xml
+++ b/app/src/main/res/drawable/ic_close.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_color.xml b/app/src/main/res/drawable/ic_color.xml
index a42e26a0a..ae57a36aa 100644
--- a/app/src/main/res/drawable/ic_color.xml
+++ b/app/src/main/res/drawable/ic_color.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml
index 1726235a5..05fc2abd8 100644
--- a/app/src/main/res/drawable/ic_delete.xml
+++ b/app/src/main/res/drawable/ic_delete.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_download_filled.xml b/app/src/main/res/drawable/ic_download_filled.xml
index 4e586a0eb..6d5b1302c 100644
--- a/app/src/main/res/drawable/ic_download_filled.xml
+++ b/app/src/main/res/drawable/ic_download_filled.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="300">
diff --git a/app/src/main/res/drawable/ic_empty_playlist.xml b/app/src/main/res/drawable/ic_empty_playlist.xml
index 3b7371ebc..5e92611a9 100644
--- a/app/src/main/res/drawable/ic_empty_playlist.xml
+++ b/app/src/main/res/drawable/ic_empty_playlist.xml
@@ -1,11 +1,11 @@
+ android:viewportHeight="144">
+ android:strokeWidth="1" />
diff --git a/app/src/main/res/drawable/ic_filter.xml b/app/src/main/res/drawable/ic_filter.xml
index 0761dca14..52d959093 100644
--- a/app/src/main/res/drawable/ic_filter.xml
+++ b/app/src/main/res/drawable/ic_filter.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_frame.xml b/app/src/main/res/drawable/ic_frame.xml
index a665fed39..7f0e915ba 100644
--- a/app/src/main/res/drawable/ic_frame.xml
+++ b/app/src/main/res/drawable/ic_frame.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_fullscreen.xml b/app/src/main/res/drawable/ic_fullscreen.xml
new file mode 100644
index 000000000..bf4ff36cd
--- /dev/null
+++ b/app/src/main/res/drawable/ic_fullscreen.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_fullscreen_exit.xml b/app/src/main/res/drawable/ic_fullscreen_exit.xml
new file mode 100644
index 000000000..12719f5b4
--- /dev/null
+++ b/app/src/main/res/drawable/ic_fullscreen_exit.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_grid.xml b/app/src/main/res/drawable/ic_grid.xml
index add61c29f..c37661f36 100644
--- a/app/src/main/res/drawable/ic_grid.xml
+++ b/app/src/main/res/drawable/ic_grid.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_hd.xml b/app/src/main/res/drawable/ic_hd.xml
index 752aa24d1..7c4595403 100644
--- a/app/src/main/res/drawable/ic_hd.xml
+++ b/app/src/main/res/drawable/ic_hd.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_hearted.xml b/app/src/main/res/drawable/ic_hearted.xml
index 026c4821e..604628cc2 100644
--- a/app/src/main/res/drawable/ic_hearted.xml
+++ b/app/src/main/res/drawable/ic_hearted.xml
@@ -4,6 +4,6 @@
android:viewportWidth="66.911"
android:viewportHeight="66.911">
+ android:fillColor="#E34326"
+ android:pathData="M66.911,22.831c0,-10.563 -8.558,-19.122 -19.118,-19.122c-5.658,0 -10.721,2.473 -14.223,6.377c-0.037,0.043 -0.076,0.085 -0.113,0.128c-3.5,-3.98 -8.618,-6.505 -14.334,-6.505C8.561,3.709 0.005,12.268 0,22.831c0,5.834 2.629,11.059 6.758,14.565H6.751l27.104,25.806l26.308,-25.806h-0.012C64.279,33.89 66.911,28.669 66.911,22.831z" />
diff --git a/app/src/main/res/drawable/ic_history_filled.xml b/app/src/main/res/drawable/ic_history_filled.xml
index b191e731a..253ae05ac 100644
--- a/app/src/main/res/drawable/ic_history_filled.xml
+++ b/app/src/main/res/drawable/ic_history_filled.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_home.xml b/app/src/main/res/drawable/ic_home.xml
index 7eb8f98dd..20c5ae8c5 100644
--- a/app/src/main/res/drawable/ic_home.xml
+++ b/app/src/main/res/drawable/ic_home.xml
@@ -1,9 +1,9 @@
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="48"
+ android:viewportHeight="48">
+ android:viewportHeight="48">
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_library.xml b/app/src/main/res/drawable/ic_library.xml
index f49974c03..e623e5d3c 100644
--- a/app/src/main/res/drawable/ic_library.xml
+++ b/app/src/main/res/drawable/ic_library.xml
@@ -1,9 +1,9 @@
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="48"
+ android:viewportHeight="48">
+ android:viewportHeight="96">
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_list.xml b/app/src/main/res/drawable/ic_list.xml
index 4ca7cd869..ed656a508 100644
--- a/app/src/main/res/drawable/ic_list.xml
+++ b/app/src/main/res/drawable/ic_list.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_locked.xml b/app/src/main/res/drawable/ic_locked.xml
new file mode 100644
index 000000000..a1014afc6
--- /dev/null
+++ b/app/src/main/res/drawable/ic_locked.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_login.xml b/app/src/main/res/drawable/ic_login.xml
index aff40998d..40a327adf 100644
--- a/app/src/main/res/drawable/ic_login.xml
+++ b/app/src/main/res/drawable/ic_login.xml
@@ -1,14 +1,14 @@
+ android:viewportHeight="24">
+ android:strokeLineCap="round"
+ android:strokeLineJoin="round" />
diff --git a/app/src/main/res/drawable/ic_login_filled.xml b/app/src/main/res/drawable/ic_login_filled.xml
index 3446db2fd..a4f99155a 100644
--- a/app/src/main/res/drawable/ic_login_filled.xml
+++ b/app/src/main/res/drawable/ic_login_filled.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_no_wifi.xml b/app/src/main/res/drawable/ic_no_wifi.xml
index b984b8dbc..8d8b7777a 100644
--- a/app/src/main/res/drawable/ic_no_wifi.xml
+++ b/app/src/main/res/drawable/ic_no_wifi.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_pause.xml b/app/src/main/res/drawable/ic_pause.xml
index 7e8a3e2ad..645e31d2c 100644
--- a/app/src/main/res/drawable/ic_pause.xml
+++ b/app/src/main/res/drawable/ic_pause.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_pause_filled.xml b/app/src/main/res/drawable/ic_pause_filled.xml
index 98cc2172d..39b09cf20 100644
--- a/app/src/main/res/drawable/ic_pause_filled.xml
+++ b/app/src/main/res/drawable/ic_pause_filled.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="300">
diff --git a/app/src/main/res/drawable/ic_pinned.xml b/app/src/main/res/drawable/ic_pinned.xml
index e08649fa0..5519b88fa 100644
--- a/app/src/main/res/drawable/ic_pinned.xml
+++ b/app/src/main/res/drawable/ic_pinned.xml
@@ -1,11 +1,11 @@
+ android:viewportHeight="24">
+ android:fillType="evenOdd"
+ android:pathData="M16,9V4l1,0c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1H7C6.45,2 6,2.45 6,3v0c0,0.55 0.45,1 1,1l1,0v5c0,1.66 -1.34,3 -3,3h0v2h5.97v7l1,1l1,-1v-7H19v-2h0C17.34,12 16,10.66 16,9z" />
diff --git a/app/src/main/res/drawable/ic_play_filled.xml b/app/src/main/res/drawable/ic_play_filled.xml
index f3e089124..952f0be6c 100644
--- a/app/src/main/res/drawable/ic_play_filled.xml
+++ b/app/src/main/res/drawable/ic_play_filled.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="485.74">
diff --git a/app/src/main/res/drawable/ic_playlist.xml b/app/src/main/res/drawable/ic_playlist.xml
index 24d17c426..c96251991 100644
--- a/app/src/main/res/drawable/ic_playlist.xml
+++ b/app/src/main/res/drawable/ic_playlist.xml
@@ -1,9 +1,9 @@
-
+ android:height="24dp"
+ android:tint="#FFFFFF"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_region.xml b/app/src/main/res/drawable/ic_region.xml
index c311f9af4..68c610189 100644
--- a/app/src/main/res/drawable/ic_region.xml
+++ b/app/src/main/res/drawable/ic_region.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_save.xml b/app/src/main/res/drawable/ic_save.xml
index 602bb91b5..6a9620b07 100644
--- a/app/src/main/res/drawable/ic_save.xml
+++ b/app/src/main/res/drawable/ic_save.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_search.xml b/app/src/main/res/drawable/ic_search.xml
index 451a03301..f13841ac2 100644
--- a/app/src/main/res/drawable/ic_search.xml
+++ b/app/src/main/res/drawable/ic_search.xml
@@ -1,9 +1,9 @@
-
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_server.xml b/app/src/main/res/drawable/ic_server.xml
index 05c9d5b44..e7cb848fa 100644
--- a/app/src/main/res/drawable/ic_server.xml
+++ b/app/src/main/res/drawable/ic_server.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_share.xml b/app/src/main/res/drawable/ic_share.xml
index 36897c94c..76837ec84 100644
--- a/app/src/main/res/drawable/ic_share.xml
+++ b/app/src/main/res/drawable/ic_share.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_skip.xml b/app/src/main/res/drawable/ic_skip.xml
index d88b792d4..1594f7d64 100644
--- a/app/src/main/res/drawable/ic_skip.xml
+++ b/app/src/main/res/drawable/ic_skip.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="32">
+ android:viewportHeight="512">
diff --git a/app/src/main/res/drawable/ic_sponsorblock.xml b/app/src/main/res/drawable/ic_sponsorblock.xml
index c16db6ea8..afe0e720b 100644
--- a/app/src/main/res/drawable/ic_sponsorblock.xml
+++ b/app/src/main/res/drawable/ic_sponsorblock.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_subscriptions.xml b/app/src/main/res/drawable/ic_subscriptions.xml
index f877314b4..10574772e 100644
--- a/app/src/main/res/drawable/ic_subscriptions.xml
+++ b/app/src/main/res/drawable/ic_subscriptions.xml
@@ -1,9 +1,9 @@
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="48"
+ android:viewportHeight="48">
+ android:viewportHeight="48">
diff --git a/app/src/main/res/drawable/ic_thumb_up.xml b/app/src/main/res/drawable/ic_thumb_up.xml
index f55183f28..146f85cee 100644
--- a/app/src/main/res/drawable/ic_thumb_up.xml
+++ b/app/src/main/res/drawable/ic_thumb_up.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_time.xml b/app/src/main/res/drawable/ic_time.xml
index 120a2b142..fe85b1f50 100644
--- a/app/src/main/res/drawable/ic_time.xml
+++ b/app/src/main/res/drawable/ic_time.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="60">
diff --git a/app/src/main/res/drawable/ic_translate.xml b/app/src/main/res/drawable/ic_translate.xml
index 92291014a..6da4f4e5e 100644
--- a/app/src/main/res/drawable/ic_translate.xml
+++ b/app/src/main/res/drawable/ic_translate.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_trending.xml b/app/src/main/res/drawable/ic_trending.xml
index fbcf2a478..536738d66 100644
--- a/app/src/main/res/drawable/ic_trending.xml
+++ b/app/src/main/res/drawable/ic_trending.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="52">
diff --git a/app/src/main/res/drawable/ic_unlocked.xml b/app/src/main/res/drawable/ic_unlocked.xml
new file mode 100644
index 000000000..157322ca5
--- /dev/null
+++ b/app/src/main/res/drawable/ic_unlocked.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_update.xml b/app/src/main/res/drawable/ic_update.xml
index f175850f5..ca962aa07 100644
--- a/app/src/main/res/drawable/ic_update.xml
+++ b/app/src/main/res/drawable/ic_update.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="420.83">
+ android:viewportHeight="300">
diff --git a/app/src/main/res/drawable/ic_verified.xml b/app/src/main/res/drawable/ic_verified.xml
index d7bd40fba..cc83f3eda 100644
--- a/app/src/main/res/drawable/ic_verified.xml
+++ b/app/src/main/res/drawable/ic_verified.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24">
diff --git a/app/src/main/res/drawable/ic_video.xml b/app/src/main/res/drawable/ic_video.xml
index ca1dce23e..16fefb228 100644
--- a/app/src/main/res/drawable/ic_video.xml
+++ b/app/src/main/res/drawable/ic_video.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="512">
diff --git a/app/src/main/res/drawable/ic_videocam.xml b/app/src/main/res/drawable/ic_videocam.xml
index e91a47788..f3699e8ab 100644
--- a/app/src/main/res/drawable/ic_videocam.xml
+++ b/app/src/main/res/drawable/ic_videocam.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="28">
diff --git a/app/src/main/res/drawable/ic_vlc.xml b/app/src/main/res/drawable/ic_vlc.xml
index db03e26e9..074c57662 100644
--- a/app/src/main/res/drawable/ic_vlc.xml
+++ b/app/src/main/res/drawable/ic_vlc.xml
@@ -1,9 +1,9 @@
-
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="1000"
+ android:viewportHeight="1000">
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index b30527a37..aed494ea4 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -2,21 +2,21 @@
+ tools:context=".MainActivity">
@@ -44,9 +44,9 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:background="@android:color/transparent"
android:elevation="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- android:background="@android:color/transparent" />
+ app:layout_constraintStart_toStartOf="parent" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_player.xml b/app/src/main/res/layout/activity_player.xml
index 35f81a257..c9851ab3f 100644
--- a/app/src/main/res/layout/activity_player.xml
+++ b/app/src/main/res/layout/activity_player.xml
@@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".util.Player"
- android:background="@android:color/black">
+ android:background="@android:color/black"
+ tools:context=".util.Player">
+ android:layout_height="wrap_content"
+ android:paddingVertical="5dp">
@@ -20,16 +22,16 @@
android:id="@+id/topBar_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_marginLeft="25dp"
android:text="@string/settings"
- android:layout_marginLeft="14dp"
- android:textSize="20sp"
- android:layout_gravity="center" />
+ android:textSize="20sp" />
+ android:layout_height="match_parent"
+ android:orientation="vertical" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/channel_search_row.xml b/app/src/main/res/layout/channel_search_row.xml
index bd82790a1..c52c4c0cd 100644
--- a/app/src/main/res/layout/channel_search_row.xml
+++ b/app/src/main/res/layout/channel_search_row.xml
@@ -16,10 +16,10 @@
@@ -29,9 +29,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
- android:textSize="16sp"
+ android:ellipsize="end"
android:maxLines="1"
- android:ellipsize="end" />
+ android:textSize="16sp" />
@@ -35,7 +35,7 @@
android:layout_alignParentEnd="true"
android:backgroundTint="?attr/colorOnPrimary"
android:text="@string/unsubscribe"
- android:textSize="11dp"
android:textColor="?android:attr/textColorPrimary"
+ android:textSize="11dp"
app:cornerRadius="20dp" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/chapter_column.xml b/app/src/main/res/layout/chapter_column.xml
index 4f5171ea4..bc9a2f45d 100644
--- a/app/src/main/res/layout/chapter_column.xml
+++ b/app/src/main/res/layout/chapter_column.xml
@@ -1,9 +1,9 @@
+ android:layout_height="wrap_content"
+ android:layout_marginHorizontal="10dp"
+ android:orientation="vertical">
diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml
index d764f3b71..a694c0029 100644
--- a/app/src/main/res/layout/comments_row.xml
+++ b/app/src/main/res/layout/comments_row.xml
@@ -2,8 +2,8 @@
+ android:layout_height="wrap_content"
+ android:background="?android:attr/selectableItemBackground">
+ android:paddingBottom="16dp"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
+ android:layout_marginTop="4dp"
+ android:visibility="gone"
+ app:srcCompat="@drawable/ic_verified" />
+ android:layout_marginTop="4dp"
+ android:visibility="gone"
+ app:srcCompat="@drawable/ic_pinned" />
+ android:visibility="gone"
+ app:srcCompat="@drawable/ic_hearted" />
diff --git a/app/src/main/res/layout/dialog_addtoplaylist.xml b/app/src/main/res/layout/dialog_addtoplaylist.xml
index c5b01143b..04e3bc172 100644
--- a/app/src/main/res/layout/dialog_addtoplaylist.xml
+++ b/app/src/main/res/layout/dialog_addtoplaylist.xml
@@ -4,7 +4,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
-
+ style="@style/CustomDialogButton"
+ android:layout_marginRight="16dp"
+ android:text="@string/addToPlaylist" />
diff --git a/app/src/main/res/layout/dialog_create_playlist.xml b/app/src/main/res/layout/dialog_create_playlist.xml
index f6a44397a..4a78eb664 100644
--- a/app/src/main/res/layout/dialog_create_playlist.xml
+++ b/app/src/main/res/layout/dialog_create_playlist.xml
@@ -1,17 +1,17 @@
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
@@ -29,18 +29,19 @@
+ android:gravity="right"
+ android:orientation="horizontal">
+ style="@style/CustomDialogButton"
+ android:text="@string/cancel" />
+ style="@style/CustomDialogButton"
+ android:layout_marginRight="16dp"
+ android:text="@string/createPlaylist" />
diff --git a/app/src/main/res/layout/dialog_custom_instance.xml b/app/src/main/res/layout/dialog_custom_instance.xml
index fa7d2a08e..2343e3bf5 100644
--- a/app/src/main/res/layout/dialog_custom_instance.xml
+++ b/app/src/main/res/layout/dialog_custom_instance.xml
@@ -1,17 +1,17 @@
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
@@ -40,28 +40,29 @@
+ android:gravity="end"
+ android:orientation="horizontal">
+ style="@style/CustomDialogButton"
+ android:text="@string/cancel" />
+ style="@style/CustomDialogButton"
+ android:layout_marginRight="16dp"
+ android:text="@string/addInstance" />
diff --git a/app/src/main/res/layout/dialog_delete_account.xml b/app/src/main/res/layout/dialog_delete_account.xml
new file mode 100644
index 000000000..8eee7ae87
--- /dev/null
+++ b/app/src/main/res/layout/dialog_delete_account.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/dialog_download.xml b/app/src/main/res/layout/dialog_download.xml
index a4a3060df..b77541111 100644
--- a/app/src/main/res/layout/dialog_download.xml
+++ b/app/src/main/res/layout/dialog_download.xml
@@ -1,17 +1,17 @@
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+ style="@style/CustomDialogButton"
+ android:layout_marginRight="16dp"
+ android:text="@string/download" />
diff --git a/app/src/main/res/layout/dialog_login.xml b/app/src/main/res/layout/dialog_login.xml
index d9a178b5a..14ff19d95 100644
--- a/app/src/main/res/layout/dialog_login.xml
+++ b/app/src/main/res/layout/dialog_login.xml
@@ -1,17 +1,17 @@
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
@@ -29,10 +29,10 @@
@@ -40,18 +40,19 @@
+ android:gravity="right"
+ android:orientation="horizontal">
+ style="@style/CustomDialogButton"
+ android:text="@string/register" />
+ style="@style/CustomDialogButton"
+ android:layout_marginRight="16dp"
+ android:text="@string/login" />
diff --git a/app/src/main/res/layout/dialog_logout.xml b/app/src/main/res/layout/dialog_logout.xml
index d2a66be03..4d3bb82ad 100644
--- a/app/src/main/res/layout/dialog_logout.xml
+++ b/app/src/main/res/layout/dialog_logout.xml
@@ -1,29 +1,29 @@
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+ android:text="@string/already_logged_in" />
+ style="@style/CustomDialogButton"
+ android:text="@string/logout" />
diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml
index 3e7c5e32a..02d9d5655 100644
--- a/app/src/main/res/layout/exo_styled_player_control_view.xml
+++ b/app/src/main/res/layout/exo_styled_player_control_view.xml
@@ -12,8 +12,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
+