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

Migrated the whole app to Jetpack compose #281

Merged
merged 43 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1b700dd
Navigation and bottom bar setup
Saifuddin53 Dec 9, 2024
6af8a4d
Third party screen fragment dependency removed (part 1)
Saifuddin53 Dec 10, 2024
2aa7647
Third party screen fragment dependency removed (part 2)
Saifuddin53 Dec 10, 2024
11149a3
About page child pages navigation and compose setup
Saifuddin53 Dec 10, 2024
14df49b
Removed the dependency of fragments and xml for all the child pages o…
Saifuddin53 Dec 10, 2024
855452f
Removed the dependency of fragments and xml for all the child pages o…
Saifuddin53 Dec 10, 2024
e51f792
Removed the dependency of setting fragment
Saifuddin53 Dec 10, 2024
964870d
Removed the dependency of about fragment
Saifuddin53 Dec 11, 2024
65c4974
Removed the dependency of main fragment
Saifuddin53 Dec 11, 2024
8e0c23f
Scribe Navigation setup
Saifuddin53 Dec 11, 2024
2f0e6ce
Bottom bar UI and functionality added
Saifuddin53 Dec 12, 2024
56038fe
UI changes
Saifuddin53 Dec 12, 2024
f995d43
Stable navigation
Saifuddin53 Dec 16, 2024
5382362
Navigation bugs solve and improved UI
Saifuddin53 Dec 17, 2024
7ae528d
Implemented settings viewmodel
Saifuddin53 Dec 17, 2024
d5b2e24
Installation screen scrolling enabled
Saifuddin53 Dec 17, 2024
9ad8e7f
Hint dialog migrated to compose
Saifuddin53 Dec 18, 2024
8c49a19
Minor ui changes in hint dialog
Saifuddin53 Dec 18, 2024
703c0f9
Dark light mode functionality implemented (part 1)
Saifuddin53 Dec 18, 2024
782d5ad
Dark light mode functionality implemented (part 2)
Saifuddin53 Dec 18, 2024
a7f46d5
Dark light mode functionality implemented (part 3)
Saifuddin53 Dec 18, 2024
1310303
Adapted the app to use material theming (part 1)
Saifuddin53 Dec 19, 2024
b12e1f6
Adapted the app to use material theming (part 2)
Saifuddin53 Dec 19, 2024
e950e1d
Adapted the app to use material theming (part 2)
Saifuddin53 Dec 19, 2024
eb68a18
Improved UI consistency across the app
Saifuddin53 Dec 19, 2024
5aa1fa9
Adapted Hint dialog UI to use material theme
Saifuddin53 Dec 19, 2024
fa98572
Implemented custom dark mode switch
Saifuddin53 Dec 19, 2024
5c9ae8d
Optimized the settings to refresh when the installed keyboard list is…
Saifuddin53 Dec 19, 2024
4c640bb
Handled back navigation of the pager
Saifuddin53 Dec 19, 2024
ac24e27
Merge branch 'main' into compose_migration
Saifuddin53 Dec 19, 2024
b1e5338
Formatted linting errors
Saifuddin53 Dec 19, 2024
e0da79d
Fixed linting issues
Saifuddin53 Dec 19, 2024
d76fe12
Removed commented code
Saifuddin53 Dec 19, 2024
b931ea7
Merge branch 'main' into compose_migration
Saifuddin53 Dec 28, 2024
ba6ab82
Merge branch 'main' into compose_migration
Saifuddin53 Dec 31, 2024
0e12330
Resolved conflicts
Saifuddin53 Dec 31, 2024
f5fc31e
Bottom Bar fixed, custom switch fixed, installation screen composable…
Saifuddin53 Jan 1, 2025
ac86a22
Fragment test cases removed and linting fixed
Saifuddin53 Jan 1, 2025
1edaf3b
Custom switch removed
Saifuddin53 Jan 1, 2025
5569c66
Bottom bar fixed
Saifuddin53 Jan 1, 2025
2d4c8ef
Installation screen spacing changed and linting errors fixed
Saifuddin53 Jan 1, 2025
50eba09
linting error fixed
Saifuddin53 Jan 1, 2025
8286882
Review changes
Saifuddin53 Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ dependencies {
implementation(composeBom)
androidTestImplementation(composeBom)
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material:material:1.7.6")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
Expand All @@ -210,6 +212,9 @@ dependencies {
// Activity Compose
implementation("androidx.activity:activity-compose")

// Navigation Compose
implementation("androidx.navigation:navigation-compose:$2.8.4")

// Testing libraries
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version")
testImplementation("io.mockk:mockk:$mockkVersion")
Expand Down
69 changes: 0 additions & 69 deletions app/src/androidTest/kotlin/be/scri/fragments/MainFragmentTest.kt

This file was deleted.

25 changes: 4 additions & 21 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
android:maxSdkVersion="28" />

<application
android:name=".App"
android:allowBackup="true"
android:appCategory="productivity"
android:icon="@mipmap/ic_launcher"
Expand All @@ -20,18 +19,17 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme.Base">
<activity android:name=".activities.MainActivity"

<!-- Main Activity -->
<activity
android:name=".activities.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".fragments.MainFragment"
android:exported="false" />

<service
android:name=".services.EnglishKeyboardIME"
android:exported="true"
Expand Down Expand Up @@ -136,21 +134,6 @@
android:name="android.view.im"
android:resource="@xml/method_swedish" />
</service>

<activity
android:name=".fragments.SettingsFragment"
android:exported="true"
android:label="@string/app.settings.title"
android:parentActivityName=".fragments.MainFragment" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

</manifest>
231 changes: 218 additions & 13 deletions app/src/main/java/be/scri/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,224 @@

package be.scri

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import be.scri.extensions.config

class App : Application() {
override fun onCreate() {
AppCompatDelegate.setDefaultNightMode(
if (config.darkTheme) {
AppCompatDelegate.MODE_NIGHT_YES
} else {
AppCompatDelegate.MODE_NIGHT_NO
import android.annotation.SuppressLint
import android.content.Context
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import be.scri.navigation.Screen
import be.scri.ui.common.appcomponents.HintDialog
import be.scri.ui.common.bottombar.ScribeBottomBar
import be.scri.ui.screens.InstallationScreen
import be.scri.ui.screens.LanguageSettingsScreen
import be.scri.ui.screens.PrivacyPolicyScreen
import be.scri.ui.screens.ThirdPartyScreen
import be.scri.ui.screens.WikimediaScreen
import be.scri.ui.screens.about.AboutScreen
import be.scri.ui.screens.settings.SettingsScreen
import be.scri.ui.theme.ScribeTheme
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@SuppressLint("ComposeModifierMissing")
@Composable
fun ScribeApp(
pagerState: PagerState,
navController: NavHostController,
onDarkModeChange: (Boolean) -> Unit,
resetHints: () -> Unit,
@SuppressLint("ComposeUnstableCollections") isHintChanged: Map<Int, Boolean>,
onDismiss: (Int) -> Unit,
context: Context,
isDarkTheme: Boolean,
modifier: Modifier = Modifier,
) {
val coroutineScope = rememberCoroutineScope()
val navBackStackEntry by navController.currentBackStackEntryAsState()

ScribeTheme(
useDarkTheme = isDarkTheme,
) {
Scaffold(
bottomBar = {
ScribeBottomBar(
onItemClick = {
coroutineScope.launch {
if (navBackStackEntry?.destination?.route != "pager") {
navController.popBackStack()
}
pagerState.animateScrollToPage(it)
}
},
pagerState = pagerState,
modifier =
Modifier,
)
},
)
super.onCreate()
modifier = modifier.fillMaxSize(),
) { innerPadding ->
NavHost(
navController = navController,
startDestination = "pager",
) {
composable("pager") {
HorizontalPager(
state = pagerState,
beyondViewportPageCount = 3,
modifier = Modifier.padding(innerPadding),
) { page ->
when (page) {
0 -> {
Box(
modifier = Modifier.fillMaxSize(),
) {
InstallationScreen(
isDark = isDarkTheme,
context = context,
)
HintDialog(
pagerState = pagerState,
currentPageIndex = 0,
sharedPrefsKey = "hint_shown_main",
hintMessageResId = R.string.app_installation_app_hint,
isHintChanged = isHintChanged[0] == true,
onDismiss = { onDismiss(it) },
modifier =
Modifier
.fillMaxWidth()
.padding(8.dp),
)
}
HandleBackPress(pagerState, coroutineScope)
}
1 -> {
Box(
modifier = Modifier.fillMaxSize(),
) {
SettingsScreen(
onDarkModeChange = { isDarkMode ->
onDarkModeChange(isDarkMode)
},
onLanguageSettingsClick = { language ->
navController.navigate(
"${Screen.LanguageSettings.route}/$language",
)
},
context = context,
)
HintDialog(
pagerState = pagerState,
currentPageIndex = 1,
sharedPrefsKey = "hint_shown_settings",
hintMessageResId = R.string.app_settings_app_hint,
isHintChanged = isHintChanged[1] == true,
onDismiss = { onDismiss(it) },
modifier = Modifier.padding(8.dp),
)
}
HandleBackPress(pagerState, coroutineScope)
}
2 -> {
Box(
modifier = Modifier.fillMaxSize(),
) {
AboutScreen(
onPrivacyPolicyClick = {
navController.navigate(Screen.PrivacyPolicy.route)
},
onThirdPartyLicensesClick = {
navController.navigate(Screen.ThirdParty.route)
},
onWikiClick = {
navController.navigate(Screen.WikimediaScribe.route)
},
resetHints = { resetHints() },
context = context,
)
HintDialog(
pagerState = pagerState,
currentPageIndex = 2,
sharedPrefsKey = "hint_shown_about",
hintMessageResId = R.string.app_about_app_hint,
isHintChanged = isHintChanged[2] == true,
onDismiss = { onDismiss(it) },
modifier = Modifier.padding(8.dp),
)
}
HandleBackPress(pagerState, coroutineScope)
}
}
}
}

composable(
route = "${Screen.LanguageSettings.route}/{languageName}",
) {
val language = it.arguments?.getString("languageName")
if (language != null) {
LanguageSettingsScreen(
language = language,
onBackNavigation = {
navController.popBackStack()
},
modifier = Modifier.padding(innerPadding),
)
}
}

composable(Screen.WikimediaScribe.route) {
WikimediaScreen(
onBackNavigation = {
navController.popBackStack()
},
modifier = Modifier.padding(innerPadding),
)
}

composable(Screen.PrivacyPolicy.route) {
PrivacyPolicyScreen(
onBackNavigation = {
navController.popBackStack()
},
modifier = Modifier.padding(innerPadding),
)
}

composable(Screen.ThirdParty.route) {
ThirdPartyScreen(
onBackNavigation = {
navController.popBackStack()
},
modifier = Modifier.padding(innerPadding),
)
}
}
}
}
}

@Composable
fun HandleBackPress(
pagerState: PagerState,
coroutineScope: CoroutineScope,
) {
BackHandler(enabled = pagerState.currentPage > 0) {
coroutineScope.launch {
pagerState.animateScrollToPage(pagerState.currentPage - 1)
}
}
}
Loading
Loading