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