Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help fragment migration #4174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SOUMEN-PAL
Copy link

Fixes #4159

###Changes Made

  1. Added necessary Jetpack Compose dependencies and plugins to both the app module and core module build.gradle.kts files.

  2. Created two composable Kotlin files:

    • HelpScreen.kt: Contains the UI for the HelpFragment using LazyColumn and AnimatedVisibility.
    • HelpScreenItem.kt: Handles individual items within the HelpScreen UI.
  3. Created a data class HelpScreenItemDataClass (serving as a replacement for the HelpItem class in the previous HelpAdapter) to define the required data items and strings for the HelpScreen.

  4. Updated KiwixHelpFragment.kt to make it compatible with Jetpack Compose by:

    • Returning a ComposeView instead of inflating XML layouts.
    • Changing its inheritance from HelpFragment to the default Fragment to enable calling composable functions directly.
  5. Fetched the existing navGraph and integrated it with a new navController to support seamless navigation between XML-based UI and Compose-based UI.

Screenshots

Earlier vs New UI

Earlier UI in XML
Screenshot_20250112-011051
New Migrated UI in JC (Jetpack Compose)
composeUi

Demo Video

MigrationHelp.mp4

…wixHelpFragment in app module to run Compossables, with addition of Jetpack compose compatibility in gradel app/core
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SOUMEN-PAL Thanks for the PR. See the review changes.

@@ -1,7 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="USE_SAME_INDENTS" value="true" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SOUMEN-PAL Please do not include automatic changes in the PR.

@@ -51,7 +51,6 @@
<inspection_tool class="AndroidLintExportedPreferenceActivity" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintExportedReceiver" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintExportedService" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AndroidLintExtraText" enabled="true" level="ERROR" enabled_by_default="true" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this as well.

@@ -15,39 +11,56 @@
<string name="menu_read_aloud">Чытаць уголас</string>
<string name="menu_read_aloud_stop">Спыніць чытаньне ўголас</string>
<string name="menu_support_kiwix">Падтрымаць Kiwix</string>
<string name="menu_support_kiwix_for_custom_apps">Падтрымка %s</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this as well.

@@ -2,7 +2,6 @@
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
"_note4": "The IDs of the entities and properties should not be changed unless there is a change in the corresponding entity.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the json file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to some auto imports done by me using Alt+Enter i guess this changes had happen by me by mistake i will fix them right now.
Sorry for the unintended problems.

@@ -11,6 +11,8 @@ import javax.xml.transform.stream.StreamResult
plugins {
android
id("com.github.triplet.play") version Versions.com_github_triplet_play_gradle_plugin
id("org.jetbrains.kotlin.android")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have added this to our core module which is already included in app and custom modules. So why we are again adding this here?

@@ -108,6 +110,13 @@ android {
// is analyzed to provide actionable feedback on potential issues with dependencies.
includeInBundle = true
}

buildFeatures {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out
Initially, I was testing the composable invocation in one module and faced some import-related issues with the other module, which led to this addition. However, I realize now that the business logic resides in the core module, and the issue can be resolved there directly. I'll fix this to avoid duplication and ensure consistency across the project.

@@ -129,6 +138,23 @@ androidComponents {
dependencies {
androidTestImplementation(Libs.leakcanary_android_instrumentation)
testImplementation(Libs.kotlinx_coroutines_test)

implementation("androidx.compose.material3:material3-android:1.3.1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependencies should be included in one place, we are adding same dependencies here and as well as in core module.

The core module is the base for both app and custom apps so whatever is common for both modules we should include that in core module so that it can easily use in both apps. Or you can use the AllProjectConfigure class to declare the dependencies which is common for both modules.

@@ -13,6 +13,8 @@ buildscript {
}
plugins {
`android-library`
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do no hardcode version number here, We are managing all the dependencies in Libs and Versions class, so define all the dependencies related things there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the information I had experience with TOML files thats why I confused my self I will fix them right away.

class KiwixHelpFragment : HelpFragment() {
override fun rawTitleDescriptionMap() =
if (sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove()) {
open class KiwixHelpFragment : Fragment() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SOUMEN-PAL Why are we directly extending the Fragment instead of HelpFragment? HelpFragment is the base for both apps module and we should use that for resusability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decision to extend Fragment directly instead of HelpFragment was intentional to align with Compose's architecture and avoid unnecessary coupling. HelpFragment is tightly tied to XML-based UI with responsibilities like managing a RecyclerView, viewBinding, and toolbar setup, which are better handled in Compose using LazyColumn and TopAppBar.

Using HelpFragment would introduce dependencies irrelevant to Compose and disrupt the clean separation Compose promotes. Extending Fragment allowed for a smoother integration of Compose while minimizing changes to the existing codebase.

Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SOUMEN-PAL We have the same screen for the Custom app(which is missing in this PR so we are only converting the KiwixHelpFragment in compose), and HelpFragment is used as the base class for both screens. The only difference we are showing some additional things in Kiwix app so this is easily achievable by extending the existing HelpFragment. According to the current approach, we have to written the same code for customHelpFragment. Compose also offers reusability and we should make the code reusable. Clean separation is also achieved by extending the HelpFragment for both KiwixHelpFragment, and CustomHelpFragment as the HelpFragment is the base class that shares the common functionality for both screens and any additional things are written in the classes themselves.

HelpFragment is tightly tied to XML-based UI with responsibilities like managing a RecyclerView, viewBinding, and toolbar setup,

That's why we should convert the HelpFragment in the compose, and KiwixHelpFragment, and CustomHelpFragment will be unchanged(as there is no UI logic) and we will provide the additional data to the base class(HelpFragment) and it will render the UI for both app and custom apps.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will do the required changes right away.
what I plan to do Is.
commit Back to prev recent stable heads and changing according to it.

.padding(16.dp)
)
Text(
text = "Send Diagnostic Data",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not hardcode text it prevents translation into other languages. Additionally, it is "Send diagnostic report" not "Send Diagnostic Data".

e3a8eb35-18cc-4b8e-b2c2-9eafab36f4aa

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I would be fetching it from the main strings file and do the changes accordingly.

@MohitMaliFtechiz
Copy link
Collaborator

@SOUMEN-PAL For the lint issue, these are the detekt issues since the project is now starting supporting the compose so the detekt rules were not configured according to compose. Here is the doc of detekt https://detekt.dev/docs/introduction/compose/ how we can configure the rules of detekt for compose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate HelpFragment to jetpack.
2 participants