mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Convert CoreReaderFragment.java into kotlin
This commit is contained in:
parent
8671578e82
commit
367d3ec695
@ -78,20 +78,20 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val activity = activity as CoreMainActivity
|
val activity = activity as CoreMainActivity
|
||||||
noOpenBookButton.setOnClickListener {
|
noOpenBookButton?.setOnClickListener {
|
||||||
activity.navigate(
|
activity.navigate(
|
||||||
KiwixReaderFragmentDirections.actionNavigationReaderToNavigationLibrary()
|
KiwixReaderFragmentDirections.actionNavigationReaderToNavigationLibrary()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
activity.supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
activity.setupDrawerToggle(toolbar)
|
toolbar?.let(activity::setupDrawerToggle)
|
||||||
setFragmentContainerBottomMarginToSizeOfNavBar()
|
setFragmentContainerBottomMarginToSizeOfNavBar()
|
||||||
openPageInBookFromNavigationArguments()
|
openPageInBookFromNavigationArguments()
|
||||||
|
|
||||||
requireActivity().observeNavigationResult<String>(
|
requireActivity().observeNavigationResult<String>(
|
||||||
FIND_IN_PAGE_SEARCH_STRING,
|
FIND_IN_PAGE_SEARCH_STRING,
|
||||||
viewLifecycleOwner,
|
viewLifecycleOwner,
|
||||||
Observer(this::findInPage)
|
Observer(::findInPage)
|
||||||
)
|
)
|
||||||
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
||||||
TAG_FILE_SEARCHED,
|
TAG_FILE_SEARCHED,
|
||||||
@ -101,11 +101,11 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openSearchItem(item: SearchItemToOpen) {
|
private fun openSearchItem(item: SearchItemToOpen) {
|
||||||
zimReaderContainer.titleToUrl(item.pageTitle)?.let {
|
zimReaderContainer?.titleToUrl(item.pageTitle)?.let {
|
||||||
if (item.shouldOpenInNewTab) {
|
if (item.shouldOpenInNewTab) {
|
||||||
createNewTab()
|
createNewTab()
|
||||||
}
|
}
|
||||||
loadUrlWithCurrentWebview(zimReaderContainer.urlSuffixToParsableUrl(it))
|
loadUrlWithCurrentWebview(zimReaderContainer?.urlSuffixToParsableUrl(it))
|
||||||
}
|
}
|
||||||
requireActivity().consumeObservable<SearchItemToOpen>(TAG_FILE_SEARCHED)
|
requireActivity().consumeObservable<SearchItemToOpen>(TAG_FILE_SEARCHED)
|
||||||
}
|
}
|
||||||
@ -147,15 +147,15 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
|
|
||||||
private fun exitBook() {
|
private fun exitBook() {
|
||||||
showNoBookOpenViews()
|
showNoBookOpenViews()
|
||||||
bottomToolbar.visibility = GONE
|
bottomToolbar?.visibility = GONE
|
||||||
actionBar.title = getString(R.string.reader)
|
actionBar?.title = getString(R.string.reader)
|
||||||
contentFrame.visibility = GONE
|
contentFrame?.visibility = GONE
|
||||||
mainMenu?.hideBookSpecificMenuItems()
|
mainMenu?.hideBookSpecificMenuItems()
|
||||||
closeZimBook()
|
closeZimBook()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeZimBook() {
|
private fun closeZimBook() {
|
||||||
zimReaderContainer.setZimFile(null)
|
zimReaderContainer?.setZimFile(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openHomeScreen() {
|
override fun openHomeScreen() {
|
||||||
@ -167,23 +167,21 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hideTabSwitcher() {
|
override fun hideTabSwitcher() {
|
||||||
if (actionBar != null) {
|
actionBar?.let { actionBar ->
|
||||||
actionBar.setDisplayShowTitleEnabled(true)
|
actionBar.setDisplayShowTitleEnabled(true)
|
||||||
activity?.setupDrawerToggle(toolbar)
|
toolbar?.let { activity?.setupDrawerToggle(it) }
|
||||||
|
|
||||||
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
||||||
|
|
||||||
closeAllTabsButton.setImageDrawableCompat(R.drawable.ic_close_black_24dp)
|
closeAllTabsButton?.setImageDrawableCompat(R.drawable.ic_close_black_24dp)
|
||||||
if (tabSwitcherRoot.visibility == View.VISIBLE) {
|
if (tabSwitcherRoot?.visibility == View.VISIBLE) {
|
||||||
tabSwitcherRoot.visibility = GONE
|
tabSwitcherRoot?.visibility = GONE
|
||||||
startAnimation(tabSwitcherRoot, anim.slide_up)
|
startAnimation(tabSwitcherRoot, anim.slide_up)
|
||||||
progressBar.visibility = View.GONE
|
progressBar?.visibility = View.GONE
|
||||||
progressBar.progress = 0
|
progressBar?.progress = 0
|
||||||
contentFrame.visibility = View.VISIBLE
|
contentFrame?.visibility = View.VISIBLE
|
||||||
}
|
|
||||||
if (mainMenu != null) {
|
|
||||||
mainMenu.showWebViewOptions(true)
|
|
||||||
}
|
}
|
||||||
|
mainMenu?.showWebViewOptions(true)
|
||||||
if (webViewList.isEmpty()) {
|
if (webViewList.isEmpty()) {
|
||||||
exitBook()
|
exitBook()
|
||||||
} else {
|
} else {
|
||||||
@ -213,7 +211,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
super.onCreateOptionsMenu(menu, menuInflater)
|
super.onCreateOptionsMenu(menu, menuInflater)
|
||||||
if (zimReaderContainer.zimFileReader == null) {
|
if (zimReaderContainer?.zimFileReader == null) {
|
||||||
mainMenu?.hideBookSpecificMenuItems()
|
mainMenu?.hideBookSpecificMenuItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,7 +223,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (zimReaderContainer.zimFile == null) {
|
if (zimReaderContainer?.zimFile == null) {
|
||||||
exitBook()
|
exitBook()
|
||||||
}
|
}
|
||||||
if (isFullScreenVideo) {
|
if (isFullScreenVideo) {
|
||||||
@ -239,15 +237,15 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun restoreViewStateOnValidJSON(
|
override fun restoreViewStateOnValidJSON(
|
||||||
zimArticles: String,
|
zimArticles: String?,
|
||||||
zimPositions: String,
|
zimPositions: String?,
|
||||||
currentTab: Int
|
currentTab: Int
|
||||||
) {
|
) {
|
||||||
val settings = requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
|
val settings = requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
|
||||||
val zimFile = settings.getString(TAG_CURRENT_FILE, null)
|
val zimFile = settings.getString(TAG_CURRENT_FILE, null)
|
||||||
|
|
||||||
if (zimFile != null && File(zimFile).exists()) {
|
if (zimFile != null && File(zimFile).exists()) {
|
||||||
if (zimReaderContainer.zimFile == null) {
|
if (zimReaderContainer?.zimFile == null) {
|
||||||
openZimFile(File(zimFile))
|
openZimFile(File(zimFile))
|
||||||
Log.d(
|
Log.d(
|
||||||
TAG_KIWIX,
|
TAG_KIWIX,
|
||||||
@ -255,16 +253,16 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentWebView().snack(R.string.zim_not_opened)
|
getCurrentWebView()?.snack(R.string.zim_not_opened)
|
||||||
}
|
}
|
||||||
restoreTabs(zimArticles, zimPositions, currentTab)
|
restoreTabs(zimArticles, zimPositions, currentTab)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createWebView(attrs: AttributeSet): ToolbarScrollingKiwixWebView {
|
override fun createWebView(attrs: AttributeSet?): ToolbarScrollingKiwixWebView {
|
||||||
return ToolbarScrollingKiwixWebView(
|
return ToolbarScrollingKiwixWebView(
|
||||||
requireContext(), this, attrs, activityMainRoot as ViewGroup, videoView,
|
requireContext(), this, attrs!!, activityMainRoot as ViewGroup, videoView!!,
|
||||||
CoreWebViewClient(this, zimReaderContainer, sharedPreferenceUtil),
|
CoreWebViewClient(this, zimReaderContainer!!, sharedPreferenceUtil!!),
|
||||||
toolbarContainer, bottomToolbar, sharedPreferenceUtil = sharedPreferenceUtil,
|
toolbarContainer!!, bottomToolbar!!, sharedPreferenceUtil = sharedPreferenceUtil!!,
|
||||||
parentNavigationBar = requireActivity().bottom_nav_view
|
parentNavigationBar = requireActivity().bottom_nav_view
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -292,7 +290,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
|||||||
private fun hideNavBar() {
|
private fun hideNavBar() {
|
||||||
requireActivity().bottom_nav_view.visibility = GONE
|
requireActivity().bottom_nav_view.visibility = GONE
|
||||||
setParentFragmentsBottomMarginTo(0)
|
setParentFragmentsBottomMarginTo(0)
|
||||||
getCurrentWebView().translationY = 0f
|
getCurrentWebView()?.translationY = 0f
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showNavBar() {
|
private fun showNavBar() {
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -64,8 +64,11 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
baseActivity.customActivityComponent.inject(this)
|
baseActivity.customActivityComponent.inject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject lateinit var customFileValidator: CustomFileValidator
|
@Inject
|
||||||
@Inject lateinit var dialogShower: DialogShower
|
lateinit var customFileValidator: CustomFileValidator
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var dialogShower: DialogShower
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
if (enforcedLanguage()) {
|
if (enforcedLanguage()) {
|
||||||
@ -80,14 +83,14 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
}
|
}
|
||||||
with(activity as AppCompatActivity) {
|
with(activity as AppCompatActivity) {
|
||||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||||
setupDrawerToggle(toolbar)
|
toolbar?.let { setupDrawerToggle(it) }
|
||||||
}
|
}
|
||||||
loadPageFromNavigationArguments()
|
loadPageFromNavigationArguments()
|
||||||
|
|
||||||
requireActivity().observeNavigationResult<String>(
|
requireActivity().observeNavigationResult<String>(
|
||||||
FIND_IN_PAGE_SEARCH_STRING,
|
FIND_IN_PAGE_SEARCH_STRING,
|
||||||
viewLifecycleOwner,
|
viewLifecycleOwner,
|
||||||
Observer(this::findInPage)
|
Observer(::findInPage)
|
||||||
)
|
)
|
||||||
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
requireActivity().observeNavigationResult<SearchItemToOpen>(
|
||||||
TAG_FILE_SEARCHED,
|
TAG_FILE_SEARCHED,
|
||||||
@ -103,11 +106,11 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openSearchItem(item: SearchItemToOpen) {
|
private fun openSearchItem(item: SearchItemToOpen) {
|
||||||
zimReaderContainer.titleToUrl(item.pageTitle)?.apply {
|
zimReaderContainer?.titleToUrl(item.pageTitle)?.apply {
|
||||||
if (item.shouldOpenInNewTab) {
|
if (item.shouldOpenInNewTab) {
|
||||||
createNewTab()
|
createNewTab()
|
||||||
}
|
}
|
||||||
loadUrlWithCurrentWebview(zimReaderContainer.urlSuffixToParsableUrl(this))
|
loadUrlWithCurrentWebview(zimReaderContainer?.urlSuffixToParsableUrl(this))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +130,8 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun restoreViewStateOnValidJSON(
|
override fun restoreViewStateOnValidJSON(
|
||||||
zimArticles: String,
|
zimArticles: String?,
|
||||||
zimPositions: String,
|
zimPositions: String?,
|
||||||
currentTab: Int
|
currentTab: Int
|
||||||
) {
|
) {
|
||||||
restoreTabs(zimArticles, zimPositions, currentTab)
|
restoreTabs(zimArticles, zimPositions, currentTab)
|
||||||
@ -159,7 +162,7 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
requireActivity(),
|
requireActivity(),
|
||||||
READ_EXTERNAL_STORAGE
|
READ_EXTERNAL_STORAGE
|
||||||
) == PERMISSION_DENIED &&
|
) == PERMISSION_DENIED &&
|
||||||
!sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove()
|
sharedPreferenceUtil?.isPlayStoreBuildWithAndroid11OrAbove() == false
|
||||||
) {
|
) {
|
||||||
requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB)
|
requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB)
|
||||||
} else {
|
} else {
|
||||||
@ -171,7 +174,7 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
|
|
||||||
override fun onRequestPermissionsResult(
|
override fun onRequestPermissionsResult(
|
||||||
requestCode: Int,
|
requestCode: Int,
|
||||||
permissions: Array<out String>,
|
permissions: Array<String>,
|
||||||
grantResults: IntArray
|
grantResults: IntArray
|
||||||
) {
|
) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
@ -209,7 +212,7 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
val currentLocaleCode = Locale.getDefault().toString()
|
val currentLocaleCode = Locale.getDefault().toString()
|
||||||
if (BuildConfig.ENFORCED_LANG.isNotEmpty() && BuildConfig.ENFORCED_LANG != currentLocaleCode) {
|
if (BuildConfig.ENFORCED_LANG.isNotEmpty() && BuildConfig.ENFORCED_LANG != currentLocaleCode) {
|
||||||
LanguageUtils.handleLocaleChange(requireActivity(), BuildConfig.ENFORCED_LANG)
|
LanguageUtils.handleLocaleChange(requireActivity(), BuildConfig.ENFORCED_LANG)
|
||||||
sharedPreferenceUtil.putPrefLanguage(BuildConfig.ENFORCED_LANG)
|
sharedPreferenceUtil?.putPrefLanguage(BuildConfig.ENFORCED_LANG)
|
||||||
activity?.recreate()
|
activity?.recreate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -221,8 +224,8 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
tableDrawerRightContainer = requireActivity().findViewById(R.id.activity_main_nav_view)
|
tableDrawerRightContainer = requireActivity().findViewById(R.id.activity_main_nav_view)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createMainMenu(menu: Menu?): MainMenu {
|
override fun createMainMenu(menu: Menu?): MainMenu? {
|
||||||
return menuFactory.create(
|
return menuFactory?.create(
|
||||||
menu!!,
|
menu!!,
|
||||||
webViewList,
|
webViewList,
|
||||||
urlIsValid(),
|
urlIsValid(),
|
||||||
@ -232,7 +235,7 @@ class CustomReaderFragment : CoreReaderFragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showOpenInNewTabDialog(url: String?) {
|
override fun showOpenInNewTabDialog(url: String) {
|
||||||
if (BuildConfig.DISABLE_TABS) return
|
if (BuildConfig.DISABLE_TABS) return
|
||||||
super.showOpenInNewTabDialog(url)
|
super.showOpenInNewTabDialog(url)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user