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
private lateinit var playlistRecyclerView: RecyclerView
private lateinit var refreshLayout: SwipeRefreshLayout
private lateinit var createPlaylistButton: FloatingActionButton
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -57,10 +56,9 @@ class Library : Fragment() {
fetchPlaylists(view)
refreshLayout.isEnabled = true
refreshLayout.setOnRefreshListener {
Log.d(TAG, "hmm")
fetchPlaylists(view)
}
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")
@ -75,10 +73,11 @@ 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()
}

View File

@ -56,13 +56,13 @@ object PreferenceHelper {
fun clearPreferences(context: Context) {
val editor = getDefaultSharedPreferencesEditor(context)
editor.clear()
editor.commit()
editor.apply()
}
fun removePreference(context: Context, value: String?) {
val editor = getDefaultSharedPreferencesEditor(context)
editor.remove(value)
editor.commit()
editor.apply()
}
fun getToken(context: Context): String {
@ -72,7 +72,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 +82,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 +93,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> {