diff --git a/app/build.gradle b/app/build.gradle index f16558e7c..a53aebe20 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -122,9 +122,6 @@ dependencies { /* Room */ kapt libs.room.compiler implementation libs.room - - /* View binding */ - implementation libs.viewBindingPropertyDelegate } static def getUnixTime() { diff --git a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt index dc558d02a..354a129b3 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt @@ -7,7 +7,6 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Handler import android.os.Looper -import androidx.appcompat.app.AppCompatActivity import androidx.core.os.bundleOf import androidx.core.os.postDelayed import androidx.fragment.app.commitNow @@ -31,7 +30,7 @@ object NavigationHelper { ) { if (channelId == null) return - val activity = unwrap(context) + val activity = unwrapActivity(context) val bundle = bundleOf(IntentData.channelId to channelId) activity.navController.navigate(R.id.channelFragment, bundle) try { @@ -45,7 +44,7 @@ object NavigationHelper { } } - private fun unwrap(context: Context): MainActivity { + private fun unwrapActivity(context: Context): MainActivity { var correctContext: Context? = context while (correctContext !is MainActivity && correctContext is ContextWrapper) { correctContext = correctContext.baseContext @@ -92,7 +91,7 @@ object NavigationHelper { IntentData.timeStamp to timeStamp ) - val activity = context as AppCompatActivity + val activity = unwrapActivity(context) activity.supportFragmentManager.commitNow { replace(R.id.container, args = bundle) } @@ -105,7 +104,7 @@ object NavigationHelper { ) { if (playlistId == null) return - val activity = unwrap(context) + val activity = unwrapActivity(context) val bundle = bundleOf( IntentData.playlistId to playlistId, IntentData.playlistType to playlistType @@ -117,7 +116,7 @@ object NavigationHelper { * Start the audio player fragment */ fun startAudioPlayer(context: Context) { - val activity = unwrap(context) + val activity = unwrapActivity(context) activity.supportFragmentManager.commitNow { replace(R.id.container) } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt index 57d90e6ef..69ad6fa99 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SearchFragment.kt @@ -2,13 +2,13 @@ package com.github.libretube.ui.fragments import android.os.Bundle import android.util.Log +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager -import by.kirich1409.viewbindingdelegate.viewBinding -import com.github.libretube.R import com.github.libretube.api.RetrofitInstance import com.github.libretube.databinding.FragmentSearchBinding import com.github.libretube.db.DatabaseHolder.Database @@ -21,8 +21,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class SearchFragment : Fragment(R.layout.fragment_search) { - private val binding by viewBinding(FragmentSearchBinding::bind) +class SearchFragment : Fragment() { + private var _binding: FragmentSearchBinding? = null + private val binding get() = _binding!! private val viewModel: SearchViewModel by activityViewModels() @@ -33,6 +34,15 @@ class SearchFragment : Fragment(R.layout.fragment_search) { query = arguments?.getString("query") } + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentSearchBinding.inflate(layoutInflater) + return binding.root + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -93,4 +103,10 @@ class SearchFragment : Fragment(R.layout.fragment_search) { } } } + + override fun onDestroy() { + super.onDestroy() + + _binding = null + } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt index 2b2c84e3e..52860e169 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt @@ -2,12 +2,13 @@ package com.github.libretube.ui.fragments import android.os.Bundle import android.util.Log +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager -import by.kirich1409.viewbindingdelegate.viewBinding import com.github.libretube.R import com.github.libretube.api.RetrofitInstance import com.github.libretube.constants.PreferenceKeys @@ -24,8 +25,9 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import retrofit2.HttpException -class SearchResultFragment : Fragment(R.layout.fragment_search_result) { - private val binding by viewBinding(FragmentSearchResultBinding::bind) +class SearchResultFragment : Fragment() { + private var _binding: FragmentSearchResultBinding? = null + private val binding get() = _binding!! private var nextPage: String? = null private var query: String = "" @@ -38,6 +40,15 @@ class SearchResultFragment : Fragment(R.layout.fragment_search_result) { query = arguments?.getString("query").toString() } + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentSearchResultBinding.inflate(layoutInflater) + return binding.root + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -132,4 +143,10 @@ class SearchResultFragment : Fragment(R.layout.fragment_search_result) { } } } + + override fun onDestroy() { + super.onDestroy() + + _binding = null + } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fe96d9f61..4302074be 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,7 +20,6 @@ room = "2.5.1" kotlinxSerialization = "1.5.0" kotlinxDatetime = "0.4.0" kotlinxRetrofit = "0.8.0" -viewBindingDelegate = "1.5.8" [libraries] androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } @@ -51,5 +50,4 @@ room = { group = "androidx.room", name="room-ktx", version.ref = "room" } room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } kotlinx-serialization = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerialization" } kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinxDatetime" } -kotlinx-serialization-retrofit = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "kotlinxRetrofit" } -viewBindingPropertyDelegate = { group = "com.github.kirich1409", name = "viewbindingpropertydelegate-noreflection", version.ref = "viewBindingDelegate" } \ No newline at end of file +kotlinx-serialization-retrofit = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "kotlinxRetrofit" } \ No newline at end of file