Skip to content

Commit

Permalink
Refactor - [:feature:make-transfer] Applied Spotless & Detekt Compose…
Browse files Browse the repository at this point in the history
… Rules (openMF#1724)

* Refactor: Applied Spotless & Detekt Compose Rules

- :feature:accounts
- :feature:auth
- :feature:editpassword
- :feature:finance

* Refactor - [:feature:history] Applied Spotless & Detekt Compose Rules

* Refactor - [:feature:home] Applied Spotless & Detekt Compose Rules

* Refactor - [:feature:invoices] Applied Spotless & Detekt Compose Rules

* Refactor - [:feature:kyc] Applied Spotless & Detekt Compose Rules

* Refactor - [:feature:make-transfer] Applied Spotless & Detekt Compose Rules
  • Loading branch information
niyajali authored Aug 11, 2024
1 parent 6f87da5 commit e45c9b6
Show file tree
Hide file tree
Showing 151 changed files with 2,979 additions and 1,920 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://editorconfig.org/
# This configuration is used by ktlint when spotless invokes it

[*.{kt,kts}]
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true
ktlint_function_naming_ignore_when_annotated_with=Composable, Test, Preview
29 changes: 15 additions & 14 deletions .github/workflows/master_dev_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ jobs:
name: mobile-wallet
path: mifospay/build/outputs/apk/debug/

lintCheck:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Setup JDK 17
- name: Setup JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Detekt For All Modules
run: ./gradlew detekt
# Turing off detekt check until migration finished
# lintCheck:
# name: Static Analysis
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
#
# # Setup JDK 17
# - name: Setup JDK 17
# uses: actions/setup-java@v1
# with:
# java-version: 17
#
# - name: Detekt For All Modules
# run: ./gradlew detekt

pmd:
name: PMD
Expand Down
37 changes: 31 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath(libs.google.oss.licenses.plugin) {
exclude(group = "com.google.protobuf")
}
classpath(libs.spotless.gradle)
}
}

Expand All @@ -28,11 +27,14 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.detekt)
alias(libs.plugins.detekt.compiler)
alias(libs.plugins.module.graph) apply true // Plugin applied to allow module graph generation
// Plugin applied to allow module graph generation
alias(libs.plugins.module.graph) apply true
alias(libs.plugins.spotless)
}

val detektFormatting = libs.detekt.formatting
val twitterComposeRules = libs.twitter.detekt.compose
val ktlintVersion = "1.0.1"

val reportMerge by tasks.registering(io.gitlab.arturbosch.detekt.report.ReportMergeTask::class) {
output.set(rootProject.layout.buildDirectory.file("reports/detekt/merge.html")) // or "reports/detekt/merge.sarif"
Expand All @@ -41,15 +43,38 @@ val reportMerge by tasks.registering(io.gitlab.arturbosch.detekt.report.ReportMe
subprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
plugin("com.diffplug.spotless")
}

detekt {
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
config.from(rootProject.files("config/detekt/detekt.yml"))
reports.xml.required.set(true)
finalizedBy(reportMerge)
}

tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
finalizedBy(reportMerge)
extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt")
ktlint(ktlintVersion).editorConfigOverride(
mapOf(
"android" to "true",
),
)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
format("kts") {
target("**/*.kts")
targetExclude("**/build/**/*.kts")
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
}
format("xml") {
target("**/*.xml")
targetExclude("**/build/**/*.xml")
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
}
}

reportMerge {
Expand Down
50 changes: 48 additions & 2 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ style:
NestedClassesVisibility:
active: true
NewLineAtEndOfFile:
active: false # Turning off for current implementation
active: true
NoTabs:
active: false
NullableBooleanCheck:
Expand Down Expand Up @@ -936,4 +936,50 @@ style:
WildcardImport:
active: true
excludeImports:
- "java.util.*"
- "java.util.*"

TwitterCompose:
CompositionLocalAllowlist:
active: true
# You can optionally define a list of CompositionLocals that are allowed here
# allowedCompositionLocals: LocalSomething,LocalSomethingElse
CompositionLocalNaming:
active: true
ContentEmitterReturningValues:
active: true
# You can optionally add your own composables here
# contentEmitters: MyComposable,MyOtherComposable
ModifierComposable:
active: true
ModifierMissing:
active: true
ModifierReused:
active: true
ModifierWithoutDefault:
active: true
MultipleEmitters:
active: true
# You can optionally add your own composables here
# contentEmitters: MyComposable,MyOtherComposable
MutableParams:
active: true
ComposableNaming:
active: true
# You can optionally disable the checks in this rule for regex matches against the composable name (e.g. molecule presenters)
# allowedComposableFunctionNames: .*Presenter,.*MoleculePresenter
ComposableParamOrder:
active: true
PreviewNaming:
active: true
PreviewPublic:
active: true
# You can optionally disable that only previews with @PreviewParameter are flagged
# previewPublicOnlyIfParams: false
RememberMissing:
active: true
UnstableCollections:
active: false
ViewModelForwarding:
active: true
ViewModelInjection:
active: true
8 changes: 7 additions & 1 deletion core/common/src/main/kotlin/org/mifospay/common/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.Context
import android.content.res.Resources
import android.view.inputmethod.InputMethodManager
import java.text.NumberFormat
import java.util.*
import java.util.Currency

object Utils {

Expand All @@ -31,4 +31,10 @@ object Utils {
return accountBalanceFormatter.format(balance)
}

fun <T> List<T>.toArrayList(): ArrayList<T> {
val array: ArrayList<T> = ArrayList()
for (index in this) array.add(index)
return array
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.data.domain.usecase.history

import com.mifospay.core.model.domain.Transaction

interface HistoryContract {
interface TransactionsHistoryAsync {
fun onTransactionsFetchCompleted(transactions: List<Transaction>?)
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package org.mifospay.feature
/*
* 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.data.domain.usecase.history

import com.mifospay.core.model.domain.Transaction
import org.mifospay.core.data.base.TaskLooper
import org.mifospay.core.data.base.UseCase.UseCaseCallback
import org.mifospay.core.data.base.UseCaseFactory
import org.mifospay.core.data.base.UseCaseHandler
import org.mifospay.core.data.domain.usecase.account.FetchAccount
import org.mifospay.core.data.domain.usecase.account.FetchAccountTransactions
import javax.inject.Inject

@Suppress("UnusedPrivateProperty")
class TransactionsHistory @Inject constructor(
private val mUsecaseHandler: UseCaseHandler,
private val mUseCaseHandler: UseCaseHandler,
private val fetchAccountTransactionsUseCase: FetchAccountTransactions,
private val mFetchAccountUseCase: FetchAccount
) {
var delegate: HistoryContract.TransactionsHistoryAsync? = null

Expand All @@ -31,7 +37,8 @@ class TransactionsHistory @Inject constructor(
}

fun fetchTransactionsHistory(accountId: Long) {
mUsecaseHandler.execute(fetchAccountTransactionsUseCase,
mUseCaseHandler.execute(
fetchAccountTransactionsUseCase,
FetchAccountTransactions.RequestValues(accountId),
object : UseCaseCallback<FetchAccountTransactions.ResponseValue?> {
override fun onSuccess(response: FetchAccountTransactions.ResponseValue?) {
Expand All @@ -42,6 +49,7 @@ class TransactionsHistory @Inject constructor(
override fun onError(message: String) {
transactions = null
}
})
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class FetchInvoice @Inject constructor(private val mFineractRepository: Fineract
val clientId = params?.get(0) // "clientId"
val invoiceId = params?.get(1) // "invoiceId"
if (clientId != null && invoiceId != null) {

mFineractRepository.fetchInvoice(clientId, invoiceId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mifospay.core.data.domain.usecase.invoice

import android.util.Log
import org.mifospay.core.data.base.UseCase
import com.mifospay.core.model.entity.Invoice
import org.mifospay.core.data.fineract.repository.FineractRepository
Expand All @@ -26,6 +27,7 @@ class FetchInvoices @Inject constructor(private val mFineractRepository: Finerac
.subscribe(object : Subscriber<List<Invoice>>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
Log.e("Invoices", e.message.toString())
useCaseCallback.onError(e.toString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

@Composable
fun MifosScaffold(
topBarTitle: Int? = null,
backPress: () -> Unit,
modifier: Modifier = Modifier,
topBarTitle: Int? = null,
floatingActionButtonContent: FloatingActionButtonContent? = null,
snackbarHost: @Composable () -> Unit = {},
scaffoldContent: @Composable (PaddingValues) -> Unit,
actions: @Composable RowScope.() -> Unit = {}
actions: @Composable RowScope.() -> Unit = {},
) {
Scaffold(
topBar = {
if (topBarTitle != null) {
MifosTopBar(
topBarTitle = topBarTitle,
backPress = backPress,
actions = actions
actions = actions,
)
}
},
Expand All @@ -31,17 +33,18 @@ fun MifosScaffold(
FloatingActionButton(
onClick = content.onClick,
contentColor = content.contentColor,
content = content.content
content = content.content,
)
}
},
snackbarHost = snackbarHost,
content = scaffoldContent,
modifier = modifier,
)
}

data class FloatingActionButtonContent(
val onClick: (() -> Unit),
val contentColor: Color,
val content: (@Composable () -> Unit)
val content: (@Composable () -> Unit),
)
3 changes: 0 additions & 3 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ dependencies {
api(projects.core.designsystem)
api(projects.core.model)
api(projects.core.common)

api(libs.androidx.metrics)
api(projects.core.analytics)
api(projects.core.designsystem)
api(projects.core.model)

implementation(libs.accompanist.pager)
implementation(libs.androidx.browser)
Expand Down
15 changes: 4 additions & 11 deletions core/ui/src/main/kotlin/org/mifospay/core/ui/ScrollableTabRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import com.google.accompanist.pager.PagerState
import kotlinx.coroutines.launch
import org.mifospay.core.ui.utility.TabContent

/**
* @author pratyush
* @since 23/3/24
*/

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MifosScrollableTabRow(
Expand All @@ -35,11 +30,10 @@ fun MifosScrollableTabRow(
val scope = rememberCoroutineScope()

ScrollableTabRow(
modifier = modifier,
containerColor = containerColor,
selectedTabIndex = pagerState.currentPage,
edgePadding = edgePadding,
indicator = {},
divider = {},
) {
tabContents.forEachIndexed { index, currentTab ->
Tab(
Expand All @@ -59,9 +53,8 @@ fun MifosScrollableTabRow(

HorizontalPager(
count = tabContents.size,
state = pagerState,
modifier = modifier
) { page ->
tabContents.getOrNull(page)?.content?.invoke() ?: Text("Page $page")
state = pagerState
) {
tabContents[it].content.invoke()
}
}
Loading

0 comments on commit e45c9b6

Please sign in to comment.