mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
commit
b26d78c502
@ -8,12 +8,11 @@ import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.fragments.Library
|
||||
import com.github.libretube.obj.Playlists
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
@ -87,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()
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ class Library : Fragment() {
|
||||
lateinit var token: String
|
||||
private lateinit var playlistRecyclerView: RecyclerView
|
||||
private lateinit var refreshLayout: SwipeRefreshLayout
|
||||
private lateinit var createPlaylistButton: FloatingActionButton
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -54,20 +53,16 @@ class Library : Fragment() {
|
||||
if (token != "") {
|
||||
view.findViewById<ImageView>(R.id.boogh2).visibility = View.GONE
|
||||
view.findViewById<TextView>(R.id.textLike2).visibility = View.GONE
|
||||
fetchPlaylists(view)
|
||||
fetchPlaylists()
|
||||
refreshLayout.isEnabled = true
|
||||
refreshLayout.setOnRefreshListener {
|
||||
Log.d(TAG, "hmm")
|
||||
fetchPlaylists(view)
|
||||
fetchPlaylists()
|
||||
}
|
||||
createPlaylistButton = view.findViewById<FloatingActionButton>(R.id.create_playlist)
|
||||
val createPlaylistButton = view.findViewById<FloatingActionButton>(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<FloatingActionButton>(R.id.create_playlist).visibility = View.GONE
|
||||
@ -75,14 +70,15 @@ class Library : Fragment() {
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
// optimize CreatePlaylistFab bottom margin
|
||||
val layoutParams = createPlaylistButton.layoutParams as ViewGroup.MarginLayoutParams
|
||||
// optimize CreatePlaylistFab bottom margin if miniPlayer active
|
||||
val createPlaylistButton = view?.findViewById<FloatingActionButton>(R.id.create_playlist)
|
||||
val layoutParams = createPlaylistButton?.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.bottomMargin = if (isMiniPlayerVisible) 180 else 64
|
||||
createPlaylistButton.layoutParams = layoutParams
|
||||
createPlaylistButton?.layoutParams = layoutParams
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
private fun fetchPlaylists(view: View) {
|
||||
fun fetchPlaylists() {
|
||||
fun run() {
|
||||
refreshLayout.isRefreshing = true
|
||||
lifecycleScope.launchWhenCreated {
|
||||
@ -102,12 +98,8 @@ class Library : Fragment() {
|
||||
}
|
||||
if (response.isNotEmpty()) {
|
||||
runOnUiThread {
|
||||
with(view.findViewById<ImageView>(R.id.boogh2)) {
|
||||
visibility = View.GONE
|
||||
}
|
||||
with(view.findViewById<TextView>(R.id.textLike2)) {
|
||||
visibility = View.GONE
|
||||
}
|
||||
view?.findViewById<ImageView>(R.id.boogh2)?.visibility = View.GONE
|
||||
view?.findViewById<TextView>(R.id.textLike2)?.visibility = View.GONE
|
||||
}
|
||||
val playlistsAdapter = PlaylistsAdapter(
|
||||
response.toMutableList(),
|
||||
@ -116,13 +108,13 @@ class Library : Fragment() {
|
||||
playlistRecyclerView.adapter = playlistsAdapter
|
||||
} else {
|
||||
runOnUiThread {
|
||||
with(view.findViewById<ImageView>(R.id.boogh2)) {
|
||||
visibility = View.VISIBLE
|
||||
setImageResource(R.drawable.ic_list)
|
||||
view?.findViewById<ImageView>(R.id.boogh2).apply {
|
||||
this?.visibility = View.VISIBLE
|
||||
this?.setImageResource(R.drawable.ic_list)
|
||||
}
|
||||
with(view.findViewById<TextView>(R.id.textLike2)) {
|
||||
visibility = View.VISIBLE
|
||||
text = getString(R.string.emptyList)
|
||||
view?.findViewById<TextView>(R.id.textLike2).apply {
|
||||
this?.visibility = View.VISIBLE
|
||||
this?.text = getString(R.string.emptyList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,14 +55,12 @@ object PreferenceHelper {
|
||||
|
||||
fun clearPreferences(context: Context) {
|
||||
val editor = getDefaultSharedPreferencesEditor(context)
|
||||
editor.clear()
|
||||
editor.commit()
|
||||
editor.clear().apply()
|
||||
}
|
||||
|
||||
fun removePreference(context: Context, value: String?) {
|
||||
val editor = getDefaultSharedPreferencesEditor(context)
|
||||
editor.remove(value)
|
||||
editor.commit()
|
||||
editor.remove(value).apply()
|
||||
}
|
||||
|
||||
fun getToken(context: Context): String {
|
||||
@ -72,7 +70,7 @@ object PreferenceHelper {
|
||||
|
||||
fun setToken(context: Context, newValue: String) {
|
||||
val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit()
|
||||
editor.putString("token", newValue)
|
||||
editor.putString("token", newValue).apply()
|
||||
}
|
||||
|
||||
fun getUsername(context: Context): String {
|
||||
@ -82,7 +80,7 @@ object PreferenceHelper {
|
||||
|
||||
fun setUsername(context: Context, newValue: String) {
|
||||
val editor = context.getSharedPreferences("username", Context.MODE_PRIVATE).edit()
|
||||
editor.putString("username", newValue)
|
||||
editor.putString("username", newValue).apply()
|
||||
}
|
||||
|
||||
fun saveCustomInstance(context: Context, customInstance: CustomInstance) {
|
||||
@ -93,7 +91,7 @@ object PreferenceHelper {
|
||||
customInstancesList += customInstance
|
||||
|
||||
val json = gson.toJson(customInstancesList)
|
||||
editor.putString("customInstances", json).commit()
|
||||
editor.putString("customInstances", json).apply()
|
||||
}
|
||||
|
||||
fun getCustomInstances(context: Context): ArrayList<CustomInstance> {
|
||||
|
Loading…
Reference in New Issue
Block a user