Skip to content

Commit

Permalink
Final Cleanup - Refactor Deprecated Libraries & Apply Custom Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali committed Aug 25, 2024
1 parent 2a6dafe commit c5a80ff
Show file tree
Hide file tree
Showing 206 changed files with 8,521 additions and 3,960 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/master_dev_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
distribution: 'zulu'
java-version: 17
- name: Run ${{ matrix.check }}
id: run_check
id: run_check_${{ matrix.check }}
run: |
if [ "${{ matrix.check }}" = "build_logic" ]; then
./gradlew check -p build-logic
Expand All @@ -54,7 +54,7 @@ jobs:
fi
- name: Upload Detekt Reports
if: ${{ matrix.check }} == 'detekt' && steps.run_check.outcome == 'success'
if: ${{ matrix.check == 'detekt' && steps.run_check_detekt.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: detekt-reports
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
java-version: 17
- name: Run tests
run: |
./gradlew testDemoDebug lintProdRelease
./gradlew testDemoDebug :lint:test :mifospay:lintProdRelease :lint:lint
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,23 @@ Before you begin, you should have already downloaded the Android Studio SDK and
4. **Perform a Gradle Check**
All your pull requests must pass the CI build only then, it will be allowed to merge. Sometimes, when the build doesn't pass you can use these commands in your local terminal and check for the errors,</br>
All your pull requests must pass the CI build only then, it will be allowed to merge.
Sometimes, when the build doesn't pass you can use these commands in your local terminal and check for the errors,</br>
For Mac OS, you can use the following commands:
**We've commited to use Material3 design in our project. And added lint check for not to use any M2 libraries in our project.</br>**
**And when adding new library, please make sure to follow the naming convention and place in sequential order(A->Z).**
* `./gradlew check` quality checks on your project’s code using Checkstyle and generates reports from these checks.</br>
* `./gradlew spotlessApply` an check and apply formatting to any plain-text file.</br>
* `./gradlew build` provides a command line to execute build script.</br>
In MacOS, Windows or Linux, you should run the following commands before opening a PR, and make sure to pass all the commands:
* `./gradlew check -p build-logic` this checks build-logic configured properly.</br>
* `./gradlew spotlessApply --no-configuration-cache` an check and apply formatting to any file.</br>
* `./gradlew dependencyGuardBaseline` to generate dependency-guard baseline.</br>
* `./gradlew detekt` to check detekt error.</br>
* `./gradlew testDemoDebug :lint:test :mifospay:lintProdRelease :lint:lint` to check lint and test error.</br>
* `./gradlew build` to build the project.</br>
* `./gradlew updateProdReleaseBadging` to update the badging for the project.</br>
For Windows, you can use the following commands:
* `gradlew check` quality checks on your project’s code using Checkstyle and generates reports from these checks.</br>
* `gradlew spotlessApply` an check and apply formatting to any plain-text file.</br>
* `gradlew build` provides a command line to execute build script.</br>
*Or Run the `ci-prebuild.sh` or `ci-prebuild.bat` script to run all the above commands in one go.*
### **Committing Your Changes**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin
import org.mifospay.libs

class AndroidFeatureConventionPlugin : Plugin<Project> {
Expand All @@ -24,16 +25,25 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
dependencies {
add("implementation", project(":core:ui"))
add("implementation", project(":core:designsystem"))
add("implementation", project(":shared"))
add("implementation", project(":desktop"))

add("implementation", libs.findLibrary("androidx.material.navigation").get())
add("implementation", project(":libs:material3-navigation"))

add("implementation", libs.findLibrary("kotlinx.collections.immutable").get())
add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())

add("androidTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())

add("testImplementation", kotlin("test"))
add("testImplementation", libs.findLibrary("hilt.android.testing").get())

add("debugImplementation", libs.findLibrary("androidx.compose.ui.test.manifest").get())
add("androidTestImplementation", libs.findLibrary("androidx.navigation.testing").get())
add("androidTestImplementation", libs.findLibrary("androidx.compose.ui.test").get())
add("androidTestImplementation", libs.findLibrary("hilt.android.testing").get())
add("androidTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.android.build.api.dsl.Lint
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import java.io.File

class AndroidLintConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
Expand All @@ -27,4 +28,8 @@ class AndroidLintConventionPlugin : Plugin<Project> {
private fun Lint.configure() {
xmlReport = true
checkDependencies = true
abortOnError = false
baseline = File("lint-baseline.xml")
explainIssues = true
htmlReport = true
}
3 changes: 1 addition & 2 deletions ci-prebuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ call :run_gradle_task "check -p build-logic"
call :run_gradle_task "spotlessApply --no-configuration-cache"
call :run_gradle_task "dependencyGuardBaseline"
call :run_gradle_task "detekt"
call :run_gradle_task "testDemoDebug"
call :run_gradle_task "lintProdRelease"
call :run_gradle_task "testDemoDebug :lint:test :mifospay:lintProdRelease :lint:lint"
call :run_gradle_task "build"
call :run_gradle_task "updateProdReleaseBadging"

Expand Down
55 changes: 42 additions & 13 deletions ci-prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,52 @@ fi

echo "Starting all checks and tests..."

failed_tasks=()
successful_tasks=()

run_gradle_task() {
echo "Running: $1"
"./gradlew" $1
if [ $? -ne 0 ]; then
echo "Error: Task $1 failed"
exit 1
echo "Warning: Task $1 failed"
failed_tasks+=("$1")
else
echo "Task $1 completed successfully"
successful_tasks+=("$1")
fi
}

run_gradle_task "check -p build-logic"
run_gradle_task "spotlessApply --no-configuration-cache"
run_gradle_task "dependencyGuardBaseline"
run_gradle_task "detekt"
run_gradle_task "testDemoDebug"
run_gradle_task "lintProdRelease"
run_gradle_task "build"
run_gradle_task "updateProdReleaseBadging"

echo "All checks and tests completed successfully."
exit 0
tasks=(
"check -p build-logic"
"spotlessApply --no-configuration-cache"
"dependencyGuardBaseline"
"detekt"
"testDemoDebug :lint:test :mifospay:lintProdRelease :lint:lint"
"build"
"updateProdReleaseBadging"
)

for task in "${tasks[@]}"; do
run_gradle_task "$task"
done

echo "All tasks have finished."

echo "Successful tasks:"
for task in "${successful_tasks[@]}"; do
echo "- $task"
done

if [ ${#failed_tasks[@]} -eq 0 ]; then
echo "All checks and tests completed successfully."
else
echo "Failed tasks:"
for task in "${failed_tasks[@]}"; do
echo "- $task"
done
echo "Please review the output above for more details on the failures."
fi

echo "Total tasks: ${#tasks[@]}"
echo "Successful tasks: ${#successful_tasks[@]}"
echo "Failed tasks: ${#failed_tasks[@]}"
9 changes: 1 addition & 8 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,4 @@ android {
namespace = "org.mifospay.common"
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}
dependencies {}
24 changes: 5 additions & 19 deletions core/common/src/main/kotlin/org/mifospay/common/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,17 @@
*/
package org.mifospay.common

import android.app.Activity
import android.content.Context
import android.content.res.Resources
import android.view.inputmethod.InputMethodManager
import java.text.NumberFormat
import java.util.Currency

object Utils {

@JvmStatic
fun hideSoftKeyboard(activity: Activity) {
val view = activity.currentFocus
val inputMethodManager =
activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view?.windowToken, 0)
}

@JvmStatic
fun Int.dp2px() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()

@JvmStatic
fun String.isBlank() = this.isEmpty() || indices.all { this[it].isWhitespace() }

@JvmStatic
fun getFormattedAccountBalance(balance: Double?, currencyCode: String?, maximumFractionDigits: Int? = 0): String {
fun getFormattedAccountBalance(
balance: Double?,
currencyCode: String?,
maximumFractionDigits: Int? = 0,
): String {
val accountBalanceFormatter = NumberFormat.getCurrencyInstance()
accountBalanceFormatter.maximumFractionDigits = maximumFractionDigits ?: 0
accountBalanceFormatter.currency = Currency.getInstance(currencyCode)
Expand Down
3 changes: 3 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ android {
}

dependencies {
lintPublish(projects.lint)

implementation(projects.core.model)

api(libs.androidx.compose.ui)
api(libs.androidx.compose.foundation)
api(libs.androidx.compose.foundation.layout)
api(libs.androidx.compose.material.iconsExtended)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ButtonElevation
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
Expand All @@ -27,6 +29,7 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp
import org.mifospay.core.designsystem.icon.MifosIcons
import org.mifospay.core.designsystem.theme.MifosTheme
Expand Down Expand Up @@ -61,6 +64,29 @@ fun MifosButton(
)
}

@Composable
fun MifosButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = ButtonDefaults.shape,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
colors: ButtonColors = ButtonDefaults.buttonColors(),
content: @Composable RowScope.() -> Unit = {},
) {
Button(
onClick = onClick,
modifier = modifier,
enabled = enabled,
colors = colors,
shape = shape,
elevation = elevation,
contentPadding = contentPadding,
content = content,
)
}

/**
* Mifos Wallet filled button with text and icon content slots.
*
Expand Down Expand Up @@ -114,26 +140,19 @@ fun MifosOutlinedButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = ButtonDefaults.outlinedShape,
border: BorderStroke? = ButtonDefaults.outlinedButtonBorder,
colors: ButtonColors = ButtonDefaults.outlinedButtonColors(),
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
content: @Composable RowScope.() -> Unit = {},
) {
OutlinedButton(
onClick = onClick,
modifier = modifier,
enabled = enabled,
colors = ButtonDefaults.outlinedButtonColors(
contentColor = MaterialTheme.colorScheme.onBackground,
),
border = BorderStroke(
width = MifosButtonDefaults.OutlinedButtonBorderWidth,
color = if (enabled) {
MaterialTheme.colorScheme.outline
} else {
MaterialTheme.colorScheme.onSurface.copy(
alpha = MifosButtonDefaults.DISABLED_OUTLINED_BUTTON_BORDER_ALPHA,
)
},
),
shape = shape,
colors = colors,
border = border,
contentPadding = contentPadding,
content = content,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.core.designsystem.component

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

@Composable
fun MifosTab(
text: String,
selected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
selectedContentColor: Color = MaterialTheme.colorScheme.onSurface,
unselectedContentColor: Color = Color.LightGray,
) {
Tab(
text = {
Text(
text = text,
color = MaterialTheme.colorScheme.onSurface,
)
},
selected = selected,
modifier = modifier,
selectedContentColor = selectedContentColor,
unselectedContentColor = unselectedContentColor,
onClick = onClick,
)
}
Loading

0 comments on commit c5a80ff

Please sign in to comment.