mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
token pref helper
This commit is contained in:
parent
255677133a
commit
96ca250e48
@ -32,7 +32,6 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.github.libretube.fragments.PlayerFragment
|
import com.github.libretube.fragments.PlayerFragment
|
||||||
import com.github.libretube.fragments.isFullScreen
|
import com.github.libretube.fragments.isFullScreen
|
||||||
import com.github.libretube.util.CronetHelper
|
import com.github.libretube.util.CronetHelper
|
||||||
@ -54,7 +53,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
DynamicColors.applyToActivityIfAvailable(this)
|
DynamicColors.applyToActivityIfAvailable(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
CronetHelper.initCronet(this.applicationContext)
|
CronetHelper.initCronet(this.applicationContext)
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
|
||||||
RetrofitInstance.url =
|
RetrofitInstance.url =
|
||||||
PreferenceHelper.getString(this, "selectInstance", "https://pipedapi.kavin.rocks/")!!
|
PreferenceHelper.getString(this, "selectInstance", "https://pipedapi.kavin.rocks/")!!
|
||||||
|
|
||||||
@ -80,12 +79,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
bottomNavigationView.setupWithNavController(navController)
|
bottomNavigationView.setupWithNavController(navController)
|
||||||
|
|
||||||
// hide the trending page if enabled
|
// 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
|
if (hideTrendingPage) bottomNavigationView.menu.findItem(R.id.home2).isVisible = false
|
||||||
|
|
||||||
// navigate to the default start tab
|
// navigate to the default start tab
|
||||||
val defaultTab = sharedPreferences.getString("default_tab", "home")
|
when (PreferenceHelper.getString(this, "default_tab", "home")) {
|
||||||
when (defaultTab) {
|
|
||||||
"home" -> navController.navigate(R.id.home2)
|
"home" -> navController.navigate(R.id.home2)
|
||||||
"subscriptions" -> navController.navigate(R.id.subscriptions)
|
"subscriptions" -> navController.navigate(R.id.subscriptions)
|
||||||
"library" -> navController.navigate(R.id.library)
|
"library" -> navController.navigate(R.id.library)
|
||||||
|
@ -18,6 +18,7 @@ import com.github.libretube.dialogs.VideoOptionsDialog
|
|||||||
import com.github.libretube.fragments.PlayerFragment
|
import com.github.libretube.fragments.PlayerFragment
|
||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
import com.github.libretube.obj.StreamItem
|
import com.github.libretube.obj.StreamItem
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -81,11 +82,7 @@ class PlaylistAdapter(
|
|||||||
val delete = holder.v.findViewById<ImageView>(R.id.delete_playlist)
|
val delete = holder.v.findViewById<ImageView>(R.id.delete_playlist)
|
||||||
delete.visibility = View.VISIBLE
|
delete.visibility = View.VISIBLE
|
||||||
delete.setOnClickListener {
|
delete.setOnClickListener {
|
||||||
val sharedPref = holder.v.context.getSharedPreferences(
|
val token = PreferenceHelper.getString(holder.v.context, "token", "")!!
|
||||||
"token",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
)
|
|
||||||
val token = sharedPref?.getString("token", "")!!
|
|
||||||
removeFromPlaylist(token, position)
|
removeFromPlaylist(token, position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.adapters
|
package com.github.libretube.adapters
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -14,6 +13,7 @@ import com.github.libretube.MainActivity
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
import com.github.libretube.obj.Playlists
|
import com.github.libretube.obj.Playlists
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
@ -57,11 +57,7 @@ class PlaylistsAdapter(
|
|||||||
builder.setTitle(R.string.deletePlaylist)
|
builder.setTitle(R.string.deletePlaylist)
|
||||||
builder.setMessage(R.string.areYouSure)
|
builder.setMessage(R.string.areYouSure)
|
||||||
builder.setPositiveButton(R.string.yes) { _, _ ->
|
builder.setPositiveButton(R.string.yes) { _, _ ->
|
||||||
val sharedPref = holder.v.context.getSharedPreferences(
|
val token = PreferenceHelper.getToken(holder.v.context)
|
||||||
"token",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
)
|
|
||||||
val token = sharedPref?.getString("token", "")!!
|
|
||||||
deletePlaylist(playlist.id!!, token, position)
|
deletePlaylist(playlist.id!!, token, position)
|
||||||
}
|
}
|
||||||
builder.setNegativeButton(R.string.cancel) { _, _ ->
|
builder.setNegativeButton(R.string.cancel) { _, _ ->
|
||||||
@ -96,10 +92,6 @@ class PlaylistsAdapter(
|
|||||||
playlists.removeAt(position)
|
playlists.removeAt(position)
|
||||||
// FIXME: This needs to run on UI thread?
|
// FIXME: This needs to run on UI thread?
|
||||||
activity.runOnUiThread { notifyDataSetChanged() }
|
activity.runOnUiThread { notifyDataSetChanged() }
|
||||||
|
|
||||||
/*if(playlists.isEmpty()){
|
|
||||||
view.findViewById<ImageView>(R.id.boogh2).visibility=View.VISIBLE
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, e.toString())
|
Log.e(TAG, e.toString())
|
||||||
|
@ -17,6 +17,7 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
@ -34,8 +35,7 @@ class AddtoPlaylistDialog : DialogFragment() {
|
|||||||
val builder = MaterialAlertDialogBuilder(it)
|
val builder = MaterialAlertDialogBuilder(it)
|
||||||
// Get the layout inflater
|
// Get the layout inflater
|
||||||
val inflater = requireActivity().layoutInflater
|
val inflater = requireActivity().layoutInflater
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
token = PreferenceHelper.getToken(requireContext())
|
||||||
token = sharedPref?.getString("token", "")!!
|
|
||||||
var view: View = inflater.inflate(R.layout.dialog_addtoplaylist, null)
|
var view: View = inflater.inflate(R.layout.dialog_addtoplaylist, null)
|
||||||
spinner = view.findViewById(R.id.playlists_spinner)
|
spinner = view.findViewById(R.id.playlists_spinner)
|
||||||
button = view.findViewById(R.id.addToPlaylist)
|
button = view.findViewById(R.id.addToPlaylist)
|
||||||
|
@ -16,6 +16,7 @@ import androidx.fragment.app.setFragmentResult
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.Playlists
|
import com.github.libretube.obj.Playlists
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
@ -46,8 +47,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
|||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
token = PreferenceHelper.getToken(requireContext())
|
||||||
token = sharedPref?.getString("token", "")!!
|
|
||||||
|
|
||||||
val playlistName = view.findViewById<TextInputEditText>(R.id.playlist_name)
|
val playlistName = view.findViewById<TextInputEditText>(R.id.playlist_name)
|
||||||
val createPlaylistBtn = view.findViewById<Button>(R.id.create_new_playlist)
|
val createPlaylistBtn = view.findViewById<Button>(R.id.create_new_playlist)
|
||||||
|
@ -15,6 +15,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.DeleteUserRequest
|
import com.github.libretube.obj.DeleteUserRequest
|
||||||
import com.github.libretube.requireMainActivityRestart
|
import com.github.libretube.requireMainActivityRestart
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
@ -58,8 +59,7 @@ class DeleteAccountDialog : DialogFragment() {
|
|||||||
private fun deleteAccount(password: String) {
|
private fun deleteAccount(password: String) {
|
||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
val token = sharedPref?.getString("token", "")!!
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RetrofitInstance.api.deleteAccount(token, DeleteUserRequest(password))
|
RetrofitInstance.api.deleteAccount(token, DeleteUserRequest(password))
|
||||||
@ -78,13 +78,6 @@ class DeleteAccountDialog : DialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun logout() {
|
private fun logout() {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
PreferenceHelper.setToken(requireContext(), "")
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
if (token != "") {
|
|
||||||
with(sharedPref!!.edit()) {
|
|
||||||
putString("token", "")
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import androidx.fragment.app.DialogFragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.Login
|
import com.github.libretube.obj.Login
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
@ -29,13 +30,11 @@ class LoginDialog : DialogFragment() {
|
|||||||
val builder = MaterialAlertDialogBuilder(it)
|
val builder = MaterialAlertDialogBuilder(it)
|
||||||
// Get the layout inflater
|
// Get the layout inflater
|
||||||
val inflater = requireActivity().layoutInflater
|
val inflater = requireActivity().layoutInflater
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
var view: View
|
var view: View
|
||||||
Log.e("dafaq", token!!)
|
Log.e("dafaq", token!!)
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
val sharedPref2 = context?.getSharedPreferences("username", Context.MODE_PRIVATE)
|
val user = PreferenceHelper.getUsername(requireContext())
|
||||||
val user = sharedPref2?.getString("username", "")
|
|
||||||
view = inflater.inflate(R.layout.dialog_logout, null)
|
view = inflater.inflate(R.layout.dialog_logout, null)
|
||||||
view.findViewById<TextView>(R.id.user).text =
|
view.findViewById<TextView>(R.id.user).text =
|
||||||
view.findViewById<TextView>(R.id.user).text.toString() + " (" + user + ")"
|
view.findViewById<TextView>(R.id.user).text.toString() + " (" + user + ")"
|
||||||
|
@ -9,6 +9,7 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -43,9 +44,7 @@ class PlaylistOptionsDialog(
|
|||||||
when (which) {
|
when (which) {
|
||||||
// Clone the playlist to the users Piped account
|
// Clone the playlist to the users Piped account
|
||||||
0 -> {
|
0 -> {
|
||||||
val sharedPref =
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
importPlaylist(token!!, playlistId)
|
importPlaylist(token!!, playlistId)
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,7 @@ import android.os.Bundle
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
class ShareDialog(
|
class ShareDialog(
|
||||||
@ -56,7 +57,8 @@ class ShareDialog(
|
|||||||
private fun getCustomInstanceFrontendUrl(): String {
|
private fun getCustomInstanceFrontendUrl(): String {
|
||||||
val sharedPreferences =
|
val sharedPreferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
val instancePref = sharedPreferences.getString(
|
val instancePref = PreferenceHelper.getString(
|
||||||
|
requireContext(),
|
||||||
"selectInstance",
|
"selectInstance",
|
||||||
"https://pipedapi.kavin.rocks"
|
"https://pipedapi.kavin.rocks"
|
||||||
)
|
)
|
||||||
|
@ -8,6 +8,7 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.github.libretube.BackgroundMode
|
import com.github.libretube.BackgroundMode
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
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
|
// Add Video to Playlist Dialog
|
||||||
1 -> {
|
1 -> {
|
||||||
val sharedPref = context?.getSharedPreferences(
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
"token",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
)
|
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
val newFragment = AddtoPlaylistDialog()
|
val newFragment = AddtoPlaylistDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
|
@ -17,6 +17,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.PlaylistsAdapter
|
import com.github.libretube.adapters.PlaylistsAdapter
|
||||||
import com.github.libretube.dialogs.CreatePlaylistDialog
|
import com.github.libretube.dialogs.CreatePlaylistDialog
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
@ -47,8 +48,7 @@ class Library : Fragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
playlistRecyclerView = view.findViewById(R.id.playlist_recView)
|
playlistRecyclerView = view.findViewById(R.id.playlist_recView)
|
||||||
playlistRecyclerView.layoutManager = LinearLayoutManager(view.context)
|
playlistRecyclerView.layoutManager = LinearLayoutManager(view.context)
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
token = PreferenceHelper.getToken(requireContext())
|
||||||
token = sharedPref?.getString("token", "")!!
|
|
||||||
refreshLayout = view.findViewById(R.id.playlist_refresh)
|
refreshLayout = view.findViewById(R.id.playlist_refresh)
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
view.findViewById<ImageView>(R.id.boogh2).visibility = View.GONE
|
view.findViewById<ImageView>(R.id.boogh2).visibility = View.GONE
|
||||||
@ -59,8 +59,7 @@ class Library : Fragment() {
|
|||||||
Log.d(TAG, "hmm")
|
Log.d(TAG, "hmm")
|
||||||
fetchPlaylists(view)
|
fetchPlaylists(view)
|
||||||
}
|
}
|
||||||
view.findViewById<com.google.android.material.floatingactionbutton
|
view.findViewById<FloatingActionButton>(R.id.create_playlist).setOnClickListener {
|
||||||
.FloatingActionButton>(R.id.create_playlist).setOnClickListener {
|
|
||||||
val newFragment = CreatePlaylistDialog()
|
val newFragment = CreatePlaylistDialog()
|
||||||
newFragment.show(childFragmentManager, "Create Playlist")
|
newFragment.show(childFragmentManager, "Create Playlist")
|
||||||
}
|
}
|
||||||
|
@ -858,11 +858,10 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createExoPlayer(view: View) {
|
private fun createExoPlayer(view: View) {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val playbackSpeed = PreferenceHelper.getString(requireContext(), "playback_speed", "1F")?.toFloat()
|
||||||
val playbackSpeed = sharedPreferences.getString("playback_speed", "1F")?.toFloat()
|
|
||||||
// multiply by thousand: s -> ms
|
// multiply by thousand: s -> ms
|
||||||
val bufferingGoal = sharedPreferences.getString("buffering_goal", "50")?.toInt()!! * 1000
|
val bufferingGoal = PreferenceHelper.getString(requireContext(), "buffering_goal", "50")?.toInt()!! * 1000
|
||||||
val seekIncrement = sharedPreferences.getString("seek_increment", "5")?.toLong()!! * 1000
|
val seekIncrement = PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000
|
||||||
|
|
||||||
val cronetEngine: CronetEngine = CronetHelper.getCronetEngine()
|
val cronetEngine: CronetEngine = CronetHelper.getCronetEngine()
|
||||||
val cronetDataSourceFactory: CronetDataSource.Factory =
|
val cronetDataSourceFactory: CronetDataSource.Factory =
|
||||||
|
@ -15,6 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.PlaylistAdapter
|
import com.github.libretube.adapters.PlaylistAdapter
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -75,9 +76,7 @@ class PlaylistFragment : Fragment() {
|
|||||||
view.findViewById<TextView>(R.id.playlist_uploader).text = response.uploader
|
view.findViewById<TextView>(R.id.playlist_uploader).text = response.uploader
|
||||||
view.findViewById<TextView>(R.id.playlist_totVideos).text =
|
view.findViewById<TextView>(R.id.playlist_totVideos).text =
|
||||||
getString(R.string.videoCount, response.videos.toString())
|
getString(R.string.videoCount, response.videos.toString())
|
||||||
val sharedPref2 =
|
val user = PreferenceHelper.getUsername(requireContext())
|
||||||
context?.getSharedPreferences("username", Context.MODE_PRIVATE)
|
|
||||||
val user = sharedPref2?.getString("username", "")
|
|
||||||
var isOwner = false
|
var isOwner = false
|
||||||
if (response.uploaderUrl == null && response.uploader.equals(user, true)) {
|
if (response.uploaderUrl == null && response.uploader.equals(user, true)) {
|
||||||
isOwner = true
|
isOwner = true
|
||||||
|
@ -23,6 +23,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.SubscriptionAdapter
|
import com.github.libretube.adapters.SubscriptionAdapter
|
||||||
import com.github.libretube.adapters.SubscriptionChannelAdapter
|
import com.github.libretube.adapters.SubscriptionChannelAdapter
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -50,8 +51,7 @@ class Subscriptions : Fragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
token = PreferenceHelper.getToken(requireContext())
|
||||||
token = sharedPref?.getString("token", "")!!
|
|
||||||
refreshLayout = view.findViewById(R.id.sub_refresh)
|
refreshLayout = view.findViewById(R.id.sub_refresh)
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
view.findViewById<RelativeLayout>(R.id.loginOrRegister).visibility = View.GONE
|
view.findViewById<RelativeLayout>(R.id.loginOrRegister).visibility = View.GONE
|
||||||
@ -63,8 +63,8 @@ class Subscriptions : Fragment() {
|
|||||||
var channelRecView = view.findViewById<RecyclerView>(R.id.sub_channels)
|
var channelRecView = view.findViewById<RecyclerView>(R.id.sub_channels)
|
||||||
|
|
||||||
var feedRecView = view.findViewById<RecyclerView>(R.id.sub_feed)
|
var feedRecView = view.findViewById<RecyclerView>(R.id.sub_feed)
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val grid = PreferenceHelper.getString(
|
||||||
val grid = sharedPreferences.getString(
|
requireContext(),
|
||||||
"grid",
|
"grid",
|
||||||
resources.getInteger(R.integer.grid_items).toString()
|
resources.getInteger(R.integer.grid_items).toString()
|
||||||
)!!
|
)!!
|
||||||
|
@ -152,8 +152,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val deleteAccount = findPreference<Preference>("delete_account")
|
val deleteAccount = findPreference<Preference>("delete_account")
|
||||||
deleteAccount?.setOnPreferenceClickListener {
|
deleteAccount?.setOnPreferenceClickListener {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
val newFragment = DeleteAccountDialog()
|
val newFragment = DeleteAccountDialog()
|
||||||
newFragment.show(childFragmentManager, "DeleteAccountDialog")
|
newFragment.show(childFragmentManager, "DeleteAccountDialog")
|
||||||
@ -165,8 +164,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val importFromYt = findPreference<Preference>("import_from_yt")
|
val importFromYt = findPreference<Preference>("import_from_yt")
|
||||||
importFromYt?.setOnPreferenceClickListener {
|
importFromYt?.setOnPreferenceClickListener {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
// check StorageAccess
|
// check StorageAccess
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
Log.d("myz", "" + Build.VERSION.SDK_INT)
|
Log.d("myz", "" + Build.VERSION.SDK_INT)
|
||||||
@ -255,15 +253,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun logout() {
|
private fun logout() {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
PreferenceHelper.setToken(requireContext(), "")
|
||||||
val token = sharedPref?.getString("token", "")
|
|
||||||
if (token != "") {
|
|
||||||
with(sharedPref!!.edit()) {
|
|
||||||
putString("token", "")
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchInstance() {
|
private fun fetchInstance() {
|
||||||
|
@ -61,9 +61,24 @@ object PreferenceHelper {
|
|||||||
editor.commit()
|
editor.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setPrivateStringPref(context: Context, key: String, newValue: String) {
|
fun getToken(context: Context): String {
|
||||||
val editor = context.getSharedPreferences(key, Context.MODE_PRIVATE).edit()
|
val sharedPref = context.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||||
editor.putString(key, newValue).apply()
|
return sharedPref?.getString("token", "")!!
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setToken(context: Context, newValue: String) {
|
||||||
|
val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit()
|
||||||
|
editor.putString("token", newValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user