diff --git a/app/src/main/java/com/github/libretube/fragments/Library.kt b/app/src/main/java/com/github/libretube/fragments/Library.kt index d0dbf7736..d459a85d2 100644 --- a/app/src/main/java/com/github/libretube/fragments/Library.kt +++ b/app/src/main/java/com/github/libretube/fragments/Library.kt @@ -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(R.id.create_playlist) + val createPlaylistButton = view.findViewById(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(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() } diff --git a/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt index 950d17d13..79f67e39f 100644 --- a/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/util/PreferenceHelper.kt @@ -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 {