Browse Source

move showFragment to ActivityUtils

pull/28/head
Jannik 1 year ago
parent
commit
c6874d0e54
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 13
      app/src/main/java/org/mosad/teapod/activity/main/MainActivity.kt
  2. 3
      app/src/main/java/org/mosad/teapod/activity/main/fragments/AccountFragment.kt
  3. 16
      app/src/main/java/org/mosad/teapod/activity/main/fragments/HomeFragment.kt
  4. 3
      app/src/main/java/org/mosad/teapod/activity/main/fragments/LibraryFragment.kt
  5. 3
      app/src/main/java/org/mosad/teapod/activity/main/fragments/SearchFragment.kt
  6. 4
      app/src/main/java/org/mosad/teapod/activity/onboarding/OnboardingActivity.kt
  7. 19
      app/src/main/java/org/mosad/teapod/util/ActivityUtils.kt

13
app/src/main/java/org/mosad/teapod/activity/main/MainActivity.kt

@ -189,19 +189,6 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
finish()
}
/**
* Show a fragment on top of the current fragment.
* The current fragment is replaced and the new one is added
* to the back stack.
*/
fun showFragment(fragment: Fragment) {
supportFragmentManager.commit {
replace(R.id.nav_host_fragment, fragment, fragment.javaClass.simpleName)
addToBackStack(fragment.javaClass.name)
show(fragment)
}
}
/**
* start the player as new activity
*/

3
app/src/main/java/org/mosad/teapod/activity/main/fragments/AccountFragment.kt

@ -17,6 +17,7 @@ import org.mosad.teapod.preferences.EncryptedPreferences
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.ui.components.LoginDialog
import org.mosad.teapod.util.DataTypes.Theme
import org.mosad.teapod.util.showFragment
class AccountFragment : Fragment() {
@ -53,7 +54,7 @@ class AccountFragment : Fragment() {
}
binding.linearInfo.setOnClickListener {
(activity as MainActivity).showFragment(AboutFragment())
activity?.showFragment(AboutFragment())
}
binding.switchSecondary.setOnClickListener {

16
app/src/main/java/org/mosad/teapod/activity/main/fragments/HomeFragment.kt

@ -22,6 +22,7 @@ import org.mosad.teapod.util.ItemMedia
import org.mosad.teapod.util.StorageController
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.showFragment
class HomeFragment : Fragment() {
@ -79,9 +80,6 @@ class HomeFragment : Fragment() {
}
}
adapterMyList = MediaItemAdapter(myListMedia)
adapterMyList.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
}
binding.recyclerMyList.adapter = adapterMyList
// new episodes
@ -122,19 +120,23 @@ class HomeFragment : Fragment() {
}
binding.textHighlightInfo.setOnClickListener {
(activity as MainActivity).showFragment(MediaFragment(highlightMedia.id))
activity?.showFragment(MediaFragment(highlightMedia.id))
}
adapterMyList.onItemClick = { mediaId, _ ->
activity?.showFragment(MediaFragment(mediaId))
}
adapterNewEpisodes.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
adapterNewSimulcasts.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
adapterNewTitles.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
}

3
app/src/main/java/org/mosad/teapod/activity/main/fragments/LibraryFragment.kt

@ -14,6 +14,7 @@ import org.mosad.teapod.databinding.FragmentLibraryBinding
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.showFragment
class LibraryFragment : Fragment() {
@ -35,7 +36,7 @@ class LibraryFragment : Fragment() {
context?.let {
adapter = MediaItemAdapter(AoDParser.itemMediaList)
adapter.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
binding.recyclerMediaLibrary.adapter = adapter

3
app/src/main/java/org/mosad/teapod/activity/main/fragments/SearchFragment.kt

@ -12,6 +12,7 @@ import org.mosad.teapod.databinding.FragmentSearchBinding
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.showFragment
class SearchFragment : Fragment() {
@ -33,7 +34,7 @@ class SearchFragment : Fragment() {
adapter = MediaItemAdapter(AoDParser.itemMediaList)
adapter!!.onItemClick = { mediaId, _ ->
binding.searchText.clearFocus()
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
binding.recyclerMediaSearch.adapter = adapter

4
app/src/main/java/org/mosad/teapod/activity/onboarding/OnboardingActivity.kt

@ -26,9 +26,7 @@ class OnboardingActivity : AppCompatActivity() {
pagerAdapter = ScreenSlidePagerAdapter(this)
binding.viewPager.adapter = pagerAdapter
TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
}.attach()
TabLayoutMediator(binding.tabLayout, binding.viewPager) { _, _ -> }.attach()
// we don't use the skip button, instead we use the start button to skip the last fragment
binding.buttonSkip.visibility = View.GONE

19
app/src/main/java/org/mosad/teapod/util/ActivityUtils.kt

@ -8,6 +8,25 @@ import android.os.Build
import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.commit
import org.mosad.teapod.R
/**
* Show a fragment on top of the current fragment.
* The current fragment is replaced and the new one is added
* to the back stack.
*/
fun FragmentActivity.showFragment(fragment: Fragment) {
supportFragmentManager.commit {
replace(R.id.nav_host_fragment, fragment, fragment.javaClass.simpleName)
addToBackStack(fragment.javaClass.name)
show(fragment)
}
}
/**
* hide the status and navigation bar

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close