Skip to content

Commit

Permalink
Migrated HelpFragment from XML to JetPackCompose Issue Id kiwix#4159
Browse files Browse the repository at this point in the history
…with lint checks off
  • Loading branch information
SOUMEN-PAL committed Jan 14, 2025
1 parent 283d845 commit e22d4bf
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 157 deletions.
21 changes: 1 addition & 20 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0"
}
if (hasProperty("testingMinimizedBuild")) {
apply(plugin = "com.slack.keeper")
Expand Down Expand Up @@ -108,6 +110,13 @@ android {
// is analyzed to provide actionable feedback on potential issues with dependencies.
includeInBundle = true
}

buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.15"
}
}

play {
Expand All @@ -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")
implementation("androidx.activity:activity-compose:1.9.3")

implementation("androidx.compose.ui:ui:1.7.6")
implementation("androidx.compose.material:material:1.7.6")

implementation(platform("androidx.compose:compose-bom:2024.12.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material:material")
implementation("androidx.compose.runtime:runtime-livedata")
implementation("androidx.compose.runtime:runtime-rxjava2")

// For testing
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.6")
debugImplementation("androidx.compose.ui:ui-tooling")
}
task("generateVersionCodeAndName") {
val file = File("VERSION_INFO")
Expand Down
78 changes: 65 additions & 13 deletions app/src/main/java/org/kiwix/kiwixmobile/help/KiwixHelpFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,77 @@

package org.kiwix.kiwixmobile.help

import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.help.HelpFragment
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.Navigation
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.help.HelpScreen
import org.kiwix.kiwixmobile.core.help.HelpScreenItemDataClass
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil

class KiwixHelpFragment : HelpFragment() {
override fun rawTitleDescriptionMap() =
if (sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove()) {
open class KiwixHelpFragment : Fragment() {
private lateinit var navController: NavController
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val context = requireContext()
val sharedPrefUtil = SharedPreferenceUtil(context)

val rawData = if (sharedPrefUtil.isPlayStoreBuildWithAndroid11OrAbove()) {
listOf(
R.string.help_2 to R.array.description_help_2,
R.string.help_5 to R.array.description_help_5,
R.string.how_to_update_content to R.array.update_content_description,
R.string.why_copy_move_files_to_app_directory to getString(
R.string.copy_move_files_to_app_directory_description
org.kiwix.kiwixmobile.core.R.string.help_2 to org.kiwix.kiwixmobile.core.R.array
.description_help_2,
org.kiwix.kiwixmobile.core.R.string.help_5 to org.kiwix.kiwixmobile.core.R.array
.description_help_5,
org.kiwix.kiwixmobile.core.R.string.how_to_update_content to org.kiwix.kiwixmobile
.core.R.array.update_content_description,
org.kiwix.kiwixmobile.core.R.string.why_copy_move_files_to_app_directory to getString(
org.kiwix.kiwixmobile.core.R.string.copy_move_files_to_app_directory_description
)
)
} else {
listOf(
R.string.help_2 to R.array.description_help_2,
R.string.help_5 to R.array.description_help_5,
R.string.how_to_update_content to R.array.update_content_description
org.kiwix.kiwixmobile.core.R.string.help_2 to org.kiwix.kiwixmobile.core.R.array
.description_help_2,
org.kiwix.kiwixmobile.core.R.string.help_5 to org.kiwix.kiwixmobile.core.R.array
.description_help_5,
org.kiwix.kiwixmobile.core.R.string.how_to_update_content to org.kiwix.kiwixmobile
.core.R.array.update_content_description
)
}

val helpScreenData: List<HelpScreenItemDataClass> = transformToHelpScreenData(context, rawData)
navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment)

return ComposeView(requireContext()).apply {
setContent {
HelpScreen(data = helpScreenData, navController = navController)
}
}
}
}

fun transformToHelpScreenData(
context: Context,
rawTitleDescriptionMap: List<Pair<Int, Any>>
): List<HelpScreenItemDataClass> {
return rawTitleDescriptionMap.map { (titleResId, description) ->
val title = context.getString(titleResId)
val descriptionValue = when (description) {
is String -> description
is Int -> context.resources.getStringArray(description).joinToString(separator = "\n")
else -> {
throw IllegalArgumentException("Invalid description resource type for title: $titleResId")
}
}
HelpScreenItemDataClass(title, descriptionValue)
}
}
26 changes: 26 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ buildscript {
}
plugins {
`android-library`
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0"
}
plugins.apply(KiwixConfigurationPlugin::class)
apply(plugin = "io.objectbox")
Expand All @@ -26,6 +28,12 @@ android {
isMinifyEnabled = false
}
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.15"
}
}

fun shouldUseLocalVersion() = File(projectDir, "libs").exists()
Expand Down Expand Up @@ -63,4 +71,22 @@ dependencies {
implementation(Libs.kotlinx_coroutines_android)
implementation(Libs.kotlinx_coroutines_rx3)
implementation(Libs.zxing)

// Compose ans Material3 Dependencies
implementation("androidx.compose.material3:material3-android:1.3.1")
implementation("androidx.activity:activity-compose:1.9.3")

implementation("androidx.compose.ui:ui:1.7.6")
implementation("androidx.compose.material:material:1.7.6")

implementation(platform("androidx.compose:compose-bom:2024.12.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material:material")
implementation("androidx.compose.runtime:runtime-livedata")
implementation("androidx.compose.runtime:runtime-rxjava2")

// For testing
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.6")
debugImplementation("androidx.compose.ui:ui-tooling")
}
3 changes: 1 addition & 2 deletions core/objectbox-models/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
"entities": [
{
"id": "3:5536749840871435068",
Expand Down Expand Up @@ -403,4 +402,4 @@
],
"retiredRelationUids": [],
"version": 1
}
}
Loading

0 comments on commit e22d4bf

Please sign in to comment.