mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
migrate more tokens to prefhelper
This commit is contained in:
parent
96ca250e48
commit
d1418650d1
@ -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.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -82,7 +81,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 token = PreferenceHelper.getString(holder.v.context, "token", "")!!
|
val token = PreferenceHelper.getToken(holder.v.context)
|
||||||
removeFromPlaylist(token, position)
|
removeFromPlaylist(token, position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import com.github.libretube.MainActivity
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.Subscribe
|
import com.github.libretube.obj.Subscribe
|
||||||
import com.github.libretube.obj.Subscription
|
import com.github.libretube.obj.Subscription
|
||||||
|
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
|
||||||
@ -70,10 +71,9 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
|||||||
fun run() {
|
fun run() {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context
|
val token = PreferenceHelper.getToken(context)
|
||||||
.getSharedPreferences("token", Context.MODE_PRIVATE)
|
|
||||||
RetrofitInstance.api.subscribe(
|
RetrofitInstance.api.subscribe(
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
Subscribe(channelId)
|
Subscribe(channelId)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@ -93,10 +93,9 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
|||||||
fun run() {
|
fun run() {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref =
|
val token = PreferenceHelper.getToken(context)
|
||||||
context.getSharedPreferences("token", Context.MODE_PRIVATE)
|
|
||||||
RetrofitInstance.api.unsubscribe(
|
RetrofitInstance.api.unsubscribe(
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
Subscribe(channelId)
|
Subscribe(channelId)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.dialogs
|
package com.github.libretube.dialogs
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.dialogs
|
package com.github.libretube.dialogs
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.dialogs
|
package com.github.libretube.dialogs
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
@ -40,11 +40,7 @@ class LoginDialog : DialogFragment() {
|
|||||||
view.findViewById<TextView>(R.id.user).text.toString() + " (" + user + ")"
|
view.findViewById<TextView>(R.id.user).text.toString() + " (" + user + ")"
|
||||||
view.findViewById<Button>(R.id.logout).setOnClickListener {
|
view.findViewById<Button>(R.id.logout).setOnClickListener {
|
||||||
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
PreferenceHelper.setToken(requireContext(), "")
|
||||||
with(sharedPref!!.edit()) {
|
|
||||||
putString("token", "")
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -105,17 +101,8 @@ class LoginDialog : DialogFragment() {
|
|||||||
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
|
||||||
} else if (response.token != null) {
|
} else if (response.token != null) {
|
||||||
Toast.makeText(context, R.string.loggedIn, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.loggedIn, Toast.LENGTH_SHORT).show()
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
PreferenceHelper.setToken(requireContext(), response.token!!)
|
||||||
with(sharedPref!!.edit()) {
|
PreferenceHelper.setUsername(requireContext(), login.username!!)
|
||||||
putString("token", response.token)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
val sharedPref2 =
|
|
||||||
context?.getSharedPreferences("username", Context.MODE_PRIVATE)
|
|
||||||
with(sharedPref2!!.edit()) {
|
|
||||||
putString("username", login.username)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,24 +125,15 @@ class LoginDialog : DialogFragment() {
|
|||||||
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "dafaq?" + e.toString())
|
Log.e(TAG, "dafaq?$e")
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
if (response.error != null) {
|
if (response.error != null) {
|
||||||
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
|
||||||
} else if (response.token != null) {
|
} else if (response.token != null) {
|
||||||
Toast.makeText(context, R.string.registered, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.registered, Toast.LENGTH_SHORT).show()
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
PreferenceHelper.setToken(requireContext(), response.token!!)
|
||||||
with(sharedPref!!.edit()) {
|
PreferenceHelper.setUsername(requireContext(), login.username!!)
|
||||||
putString("token", response.token)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
val sharedPref2 =
|
|
||||||
context?.getSharedPreferences("username", Context.MODE_PRIVATE)
|
|
||||||
with(sharedPref2!!.edit()) {
|
|
||||||
putString("username", login.username)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.ChannelAdapter
|
import com.github.libretube.adapters.ChannelAdapter
|
||||||
import com.github.libretube.obj.Subscribe
|
import com.github.libretube.obj.Subscribe
|
||||||
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.github.libretube.util.formatShort
|
import com.github.libretube.util.formatShort
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
@ -63,9 +64,8 @@ class ChannelFragment : Fragment() {
|
|||||||
val refreshChannel = {
|
val refreshChannel = {
|
||||||
refreshLayout?.isRefreshing = true
|
refreshLayout?.isRefreshing = true
|
||||||
fetchChannel(view)
|
fetchChannel(view)
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
|
||||||
val subButton = view.findViewById<MaterialButton>(R.id.channel_subscribe)
|
val subButton = view.findViewById<MaterialButton>(R.id.channel_subscribe)
|
||||||
if (sharedPref?.getString("token", "") != "") {
|
if (PreferenceHelper.getToken(requireContext()) != "") {
|
||||||
isSubscribed(subButton)
|
isSubscribed(subButton)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,10 +95,10 @@ class ChannelFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
RetrofitInstance.api.isSubscribed(
|
RetrofitInstance.api.isSubscribed(
|
||||||
channel_id!!,
|
channel_id!!,
|
||||||
sharedPref?.getString("token", "")!!
|
token
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
@ -135,9 +135,9 @@ class ChannelFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
RetrofitInstance.api.subscribe(
|
RetrofitInstance.api.subscribe(
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
Subscribe(channel_id)
|
Subscribe(channel_id)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@ -158,9 +158,9 @@ class ChannelFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
RetrofitInstance.api.unsubscribe(
|
RetrofitInstance.api.unsubscribe(
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
Subscribe(channel_id)
|
Subscribe(channel_id)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.fragments
|
package com.github.libretube.fragments
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -34,7 +34,6 @@ import androidx.core.os.bundleOf
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -679,8 +678,8 @@ class PlayerFragment : Fragment() {
|
|||||||
activity.findViewById<MotionLayout>(R.id.mainMotionLayout).transitionToEnd()
|
activity.findViewById<MotionLayout>(R.id.mainMotionLayout).transitionToEnd()
|
||||||
view.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
|
view.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
|
||||||
}
|
}
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
if (sharedPref?.getString("token", "") != "") {
|
if (token != "") {
|
||||||
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
||||||
val subButton = view.findViewById<MaterialButton>(R.id.player_subscribe)
|
val subButton = view.findViewById<MaterialButton>(R.id.player_subscribe)
|
||||||
isSubscribed(subButton, channelId!!)
|
isSubscribed(subButton, channelId!!)
|
||||||
@ -940,10 +939,10 @@ class PlayerFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
RetrofitInstance.api.isSubscribed(
|
RetrofitInstance.api.isSubscribed(
|
||||||
channel_id,
|
channel_id,
|
||||||
sharedPref?.getString("token", "")!!
|
token
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
@ -980,9 +979,9 @@ class PlayerFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
RetrofitInstance.api.subscribe(
|
RetrofitInstance.api.subscribe(
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
Subscribe(channel_id)
|
Subscribe(channel_id)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@ -1003,9 +1002,9 @@ class PlayerFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
RetrofitInstance.api.unsubscribe(
|
RetrofitInstance.api.unsubscribe(
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
Subscribe(channel_id)
|
Subscribe(channel_id)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.fragments
|
package com.github.libretube.fragments
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.fragments
|
package com.github.libretube.fragments
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -15,7 +14,6 @@ import android.widget.Toast
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
@ -39,9 +39,7 @@ class AdvancedSettings : PreferenceFragmentCompat() {
|
|||||||
PreferenceHelper.clearPreferences(requireContext())
|
PreferenceHelper.clearPreferences(requireContext())
|
||||||
|
|
||||||
// clear login token
|
// clear login token
|
||||||
val sharedPrefToken =
|
PreferenceHelper.setToken(requireContext(), "")
|
||||||
context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
|
||||||
sharedPrefToken?.edit()?.clear()?.commit()
|
|
||||||
|
|
||||||
requireMainActivityRestart = true
|
requireMainActivityRestart = true
|
||||||
activity?.recreate()
|
activity?.recreate()
|
||||||
|
@ -309,11 +309,10 @@ class InstanceSettings : PreferenceFragmentCompat() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
val sharedPref =
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
|
||||||
RetrofitInstance.api.importSubscriptions(
|
RetrofitInstance.api.importSubscriptions(
|
||||||
false,
|
false,
|
||||||
sharedPref?.getString("token", "")!!,
|
token,
|
||||||
channels
|
channels
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user