move showFragment to ActivityUtils
This commit is contained in:
		| @ -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 | ||||
|      */ | ||||
|  | ||||
| @ -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 { | ||||
|  | ||||
| @ -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)) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user