fix minor bugs

This commit is contained in:
Bnyro 2022-06-26 19:21:54 +02:00
parent 31c71d3002
commit 2e9238a512
2 changed files with 10 additions and 11 deletions

View File

@ -28,7 +28,6 @@ class Library : Fragment() {
lateinit var token: String lateinit var token: String
private lateinit var playlistRecyclerView: RecyclerView private lateinit var playlistRecyclerView: RecyclerView
private lateinit var refreshLayout: SwipeRefreshLayout private lateinit var refreshLayout: SwipeRefreshLayout
private lateinit var createPlaylistButton: FloatingActionButton
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -57,10 +56,9 @@ class Library : Fragment() {
fetchPlaylists(view) fetchPlaylists(view)
refreshLayout.isEnabled = true refreshLayout.isEnabled = true
refreshLayout.setOnRefreshListener { refreshLayout.setOnRefreshListener {
Log.d(TAG, "hmm")
fetchPlaylists(view) fetchPlaylists(view)
} }
createPlaylistButton = view.findViewById<FloatingActionButton>(R.id.create_playlist) val createPlaylistButton = view.findViewById<FloatingActionButton>(R.id.create_playlist)
createPlaylistButton.setOnClickListener { createPlaylistButton.setOnClickListener {
val newFragment = CreatePlaylistDialog() val newFragment = CreatePlaylistDialog()
newFragment.show(childFragmentManager, "Create Playlist") newFragment.show(childFragmentManager, "Create Playlist")
@ -75,10 +73,11 @@ class Library : Fragment() {
} }
override fun onResume() { override fun onResume() {
// optimize CreatePlaylistFab bottom margin // optimize CreatePlaylistFab bottom margin if miniPlayer active
val layoutParams = createPlaylistButton.layoutParams as ViewGroup.MarginLayoutParams val createPlaylistButton = view?.findViewById<FloatingActionButton>(R.id.create_playlist)
val layoutParams = createPlaylistButton?.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.bottomMargin = if (isMiniPlayerVisible) 180 else 64 layoutParams.bottomMargin = if (isMiniPlayerVisible) 180 else 64
createPlaylistButton.layoutParams = layoutParams createPlaylistButton?.layoutParams = layoutParams
super.onResume() super.onResume()
} }

View File

@ -56,13 +56,13 @@ object PreferenceHelper {
fun clearPreferences(context: Context) { fun clearPreferences(context: Context) {
val editor = getDefaultSharedPreferencesEditor(context) val editor = getDefaultSharedPreferencesEditor(context)
editor.clear() editor.clear()
editor.commit() editor.apply()
} }
fun removePreference(context: Context, value: String?) { fun removePreference(context: Context, value: String?) {
val editor = getDefaultSharedPreferencesEditor(context) val editor = getDefaultSharedPreferencesEditor(context)
editor.remove(value) editor.remove(value)
editor.commit() editor.apply()
} }
fun getToken(context: Context): String { fun getToken(context: Context): String {
@ -72,7 +72,7 @@ object PreferenceHelper {
fun setToken(context: Context, newValue: String) { fun setToken(context: Context, newValue: String) {
val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit() val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit()
editor.putString("token", newValue) editor.putString("token", newValue).apply()
} }
fun getUsername(context: Context): String { fun getUsername(context: Context): String {
@ -82,7 +82,7 @@ object PreferenceHelper {
fun setUsername(context: Context, newValue: String) { fun setUsername(context: Context, newValue: String) {
val editor = context.getSharedPreferences("username", Context.MODE_PRIVATE).edit() val editor = context.getSharedPreferences("username", Context.MODE_PRIVATE).edit()
editor.putString("username", newValue) editor.putString("username", newValue).apply()
} }
fun saveCustomInstance(context: Context, customInstance: CustomInstance) { fun saveCustomInstance(context: Context, customInstance: CustomInstance) {
@ -93,7 +93,7 @@ object PreferenceHelper {
customInstancesList += customInstance customInstancesList += customInstance
val json = gson.toJson(customInstancesList) val json = gson.toJson(customInstancesList)
editor.putString("customInstances", json).commit() editor.putString("customInstances", json).apply()
} }
fun getCustomInstances(context: Context): ArrayList<CustomInstance> { fun getCustomInstances(context: Context): ArrayList<CustomInstance> {