Skip to content

Commit

Permalink
Added comments on CoreReaderFragment method that are implemented in…
Browse files Browse the repository at this point in the history
… `CustomReaderFragment`.
  • Loading branch information
MohitMaliDeveloper committed Nov 16, 2023
1 parent cbb161c commit 51ce43b
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ abstract class CoreReaderFragment :
return FragmentActivityExtensions.Super.ShouldCall
}

/**
* Configures the selection handler for the WebView.
* Subclasses like CustomReaderFragment override this method to customize
* the behavior of the selection handler menu. In this specific implementation,
* it sets up a menu item for reading aloud selected text.
* If the custom app is set to disable the read-aloud feature,
* the menu item will be hidden by CustomReaderFragment.
* it provides additional customization for custom apps.
*
* WARNING: If modifying this method, ensure thorough testing with custom apps
* to verify proper functionality.
*/
protected open fun configureWebViewSelectionHandler(menu: Menu?) {
menu?.findItem(R.id.menu_speak_text)?.setOnMenuItemClickListener {
if (tts?.isInitialized == false) {
Expand Down Expand Up @@ -551,6 +563,12 @@ abstract class CoreReaderFragment :
}
}

/**
* Abstract method to be implemented by subclasses for loading drawer-related views.
* Subclasses like CustomReaderFragment and KiwixReaderFragment should override this method
* to set up specific views for both the left and right drawers, such as custom containers
* or navigation views.
*/
protected abstract fun loadDrawerViews()
override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -768,6 +786,14 @@ abstract class CoreReaderFragment :
setTopMarginToWebViews(0)
}

/**
* Sets the lock mode for the drawer, controlling whether the drawer can be opened or closed.
* Subclasses like CustomReaderFragment override this method to provide custom
* behavior, such as disabling the sidebar when configured not to show it.
*
* WARNING: If modifying this method, ensure thorough testing with custom apps
* to verify proper functionality.
*/
protected open fun setDrawerLockMode(lockMode: Int) {
drawerLayout?.setDrawerLockMode(lockMode)
}
Expand Down Expand Up @@ -1313,6 +1339,12 @@ abstract class CoreReaderFragment :
}
}

/**
* Abstract method to be implemented by (KiwixReaderFragment, CustomReaderFragment)
* for creating a new tab.
* Subclasses like CustomReaderFragment, KiwixReaderFragment override this method
* to define the specific behavior for creating a new tab.
*/
protected abstract fun createNewTab()

/** Creates the full screen AddNoteDialog, which is a DialogFragment */
Expand Down Expand Up @@ -1814,6 +1846,15 @@ abstract class CoreReaderFragment :
}
}

/**
* Creates the main menu for the reader.
* Subclasses may override this method to customize the main menu creation process.
* For custom apps like CustomReaderFragment, this method dynamically generates the menu
* based on the app's configuration, considering features like "read aloud" and "tabs."
*
* WARNING: If modifying this method, ensure thorough testing with custom apps
* to verify proper functionality.
*/
protected open fun createMainMenu(menu: Menu?): MainMenu? =
menu?.let {
menuFactory?.create(
Expand Down Expand Up @@ -1999,6 +2040,17 @@ abstract class CoreReaderFragment :
}
}

/**
* Displays a dialog prompting the user to open the provided URL in a new tab.
* CustomReaderFragment override this method to customize the
* behavior of the "Open in New Tab" dialog. In this specific implementation,
* If the custom app is set to disable the tabs feature,
* it will not show the dialog with the ability to open the URL in a new tab,
* it provide additional customization for custom apps.
*
* WARNING: If modifying this method, ensure thorough testing with custom apps
* to verify proper functionality.
*/
protected open fun showOpenInNewTabDialog(url: String) {
alertDialogShower?.show(
KiwixDialog.YesNoDialog.OpenInNewTab,
Expand Down Expand Up @@ -2143,11 +2195,27 @@ abstract class CoreReaderFragment :
}
}

/**
* Restores the view state after successfully reading valid JSON from shared preferences.
* Developers modifying this method in subclasses, such as CustomReaderFragment and
* KiwixReaderFragment, should review and consider the implementations in those subclasses
* (e.g., CustomReaderFragment.restoreViewStateOnValidJSON,
* KiwixReaderFragment.restoreViewStateOnValidJSON) to ensure consistent behavior
* when handling valid JSON scenarios.
*/
protected abstract fun restoreViewStateOnValidJSON(
zimArticles: String?,
zimPositions: String?,
currentTab: Int
)

/**
* Restores the view state when the attempt to read JSON from shared preferences fails
* due to invalid or corrupted data. Developers modifying this method in subclasses, such as
* CustomReaderFragment and KiwixReaderFragment, should review and consider the implementations
* in those subclasses (e.g., CustomReaderFragment.restoreViewStateOnInvalidJSON,
* KiwixReaderFragment.restoreViewStateOnInvalidJSON) to ensure consistent behavior
* when handling invalid JSON scenarios.
*/
abstract fun restoreViewStateOnInvalidJSON()
}

0 comments on commit 51ce43b

Please sign in to comment.