-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
4159 migrate help fragment to compose #4217
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ buildscript { | |
} | ||
plugins { | ||
`android-library` | ||
id("org.jetbrains.kotlin.android") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rebase on the main branch, there we have added the support for compose in a proper way. |
||
id("org.jetbrains.kotlin.plugin.compose") version Versions.org_jetbrains_kotlin_plugin_compose | ||
} | ||
plugins.apply(KiwixConfigurationPlugin::class) | ||
apply(plugin = "io.objectbox") | ||
|
@@ -26,6 +28,12 @@ android { | |
isMinifyEnabled = false | ||
} | ||
} | ||
buildFeatures { | ||
compose = true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = Versions.kotlin_compiler_extension_version | ||
} | ||
} | ||
|
||
fun shouldUseLocalVersion() = File(projectDir, "libs").exists() | ||
|
@@ -63,4 +71,17 @@ dependencies { | |
implementation(Libs.kotlinx_coroutines_android) | ||
implementation(Libs.kotlinx_coroutines_rx3) | ||
implementation(Libs.zxing) | ||
|
||
implementation(Libs.androidx_compose_material3) | ||
implementation(Libs.androidx_activity_compose) | ||
|
||
implementation(Libs.androidx_compose_ui) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we have added
|
||
implementation(platform(Libs.androidx_compose_bom)) | ||
implementation(Libs.androidx_compose_ui_tooling) | ||
implementation(Libs.androidx_compose_runtime_livedata) | ||
implementation(Libs.androidx_compose_runtime_rxjava2) | ||
|
||
// For Compose UI Testing | ||
androidTestImplementation(Libs.androidx_compose_ui_test_junit4) | ||
debugImplementation(Libs.androidx_compose_ui_tooling) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,83 +17,91 @@ | |
*/ | ||
package org.kiwix.kiwixmobile.core.help | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.appcompat.widget.Toolbar | ||
import androidx.recyclerview.widget.DividerItemDecoration | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.navigation.Navigation | ||
import org.kiwix.kiwixmobile.core.R | ||
import org.kiwix.kiwixmobile.core.base.BaseActivity | ||
import org.kiwix.kiwixmobile.core.base.BaseFragment | ||
import org.kiwix.kiwixmobile.core.databinding.FragmentHelpBinding | ||
import org.kiwix.kiwixmobile.core.error.DiagnosticReportActivity | ||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start | ||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity | ||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil | ||
import javax.inject.Inject | ||
|
||
@Suppress("UnnecessaryAbstractClass") | ||
abstract class HelpFragment : BaseFragment() { | ||
|
||
@Inject | ||
lateinit var sharedPreferenceUtil: SharedPreferenceUtil | ||
private var fragmentHelpBinding: FragmentHelpBinding? = null | ||
protected open fun rawTitleDescriptionMap(): List<Pair<Int, Any>> = emptyList() | ||
override val fragmentToolbar: Toolbar? by lazy { | ||
fragmentHelpBinding?.root?.findViewById(R.id.toolbar) | ||
} | ||
override val fragmentTitle: String? by lazy { getString(R.string.menu_help) } | ||
|
||
private val titleDescriptionMap by lazy { | ||
rawTitleDescriptionMap().associate { (title, description) -> | ||
val descriptionValue = when (description) { | ||
is String -> description | ||
is Int -> resources.getStringArray(description).joinToString(separator = "\n") | ||
else -> { | ||
throw IllegalArgumentException("Invalid description resource type for title: $title") | ||
} | ||
} | ||
protected abstract val navHostFragmentId: Int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is |
||
|
||
getString(title) to descriptionValue | ||
// Instead of keeping the XML binding, we now directly return a ComposeView. | ||
protected open fun createFragmentView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup? | ||
): View { | ||
return ComposeView(requireContext()).apply { | ||
setContent { | ||
// Create the helpScreen data using your rawTitleDescriptionMap. | ||
val helpScreenData = transformToHelpScreenData( | ||
requireContext(), | ||
rawTitleDescriptionMap() | ||
) | ||
// Retrieve the NavController if your composable needs it. | ||
val navController = Navigation.findNavController(requireActivity(), navHostFragmentId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the already defined val navController = (requireActivity() as CoreMainActivity).navController After using this, you don't need to define this: protected abstract val navHostFragmentId: Int So remove this from |
||
// Call your HelpScreen composable. | ||
HelpScreen(data = helpScreenData, navController = navController) | ||
} | ||
} | ||
} | ||
|
||
// Each subclass is responsible for providing its own raw data. | ||
protected open fun rawTitleDescriptionMap(): List<Pair<Int, Any>> = emptyList() | ||
|
||
// The following properties are now optional β if no longer use an XML toolbar or title, | ||
// we can remove or update these accordingly. | ||
override val fragmentToolbar: Toolbar? by lazy { | ||
// Already Applied ad TopAppBAr in scaffold in composable | ||
null | ||
} | ||
override val fragmentTitle: String? by lazy { getString(R.string.menu_help) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove these |
||
|
||
override fun inject(baseActivity: BaseActivity) { | ||
(baseActivity as CoreMainActivity).cachedComponent.inject(this) | ||
} | ||
|
||
// Remove or adjust onViewCreated if you no longer need to manipulate XML-based views. | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val activity = requireActivity() as AppCompatActivity | ||
fragmentHelpBinding?.activityHelpDiagnosticImageView?.setOnClickListener { | ||
sendDiagnosticReport() | ||
} | ||
fragmentHelpBinding?.activityHelpDiagnosticTextView?.setOnClickListener { | ||
sendDiagnosticReport() | ||
} | ||
fragmentHelpBinding?.activityHelpRecyclerView?.addItemDecoration( | ||
DividerItemDecoration(activity, DividerItemDecoration.VERTICAL) | ||
) | ||
fragmentHelpBinding?.activityHelpRecyclerView?.adapter = HelpAdapter(titleDescriptionMap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After moving |
||
// Any additional logic that is independent of the XML layout can be kept here. | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
fragmentHelpBinding = | ||
FragmentHelpBinding.inflate(inflater, container, false) | ||
return fragmentHelpBinding?.root | ||
} | ||
|
||
private fun sendDiagnosticReport() { | ||
requireActivity().start<DiagnosticReportActivity>() | ||
} | ||
): View? = createFragmentView(inflater, container) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
fragmentHelpBinding = null | ||
// Util function to modify the data accordingly | ||
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) | ||
} | ||
} |
There was a problem hiding this comment.
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 adding both the
bom
and the normal version of dependencies? We should only add and manage the dependencies. See how we done in https://github.com/kiwix/kiwix-android/pull/4253/files#diff-df8b4af8cccf28e19228317a74d3fba23fed6c067665f72670b7d4986515ad39.