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

refactor: refactor Create new center fragment to compose #2116

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.data.repository.CenterListRepository
import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.data.repository.GroupDetailsRepository
import com.mifos.core.data.repository.GroupsListRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
Expand All @@ -14,6 +15,7 @@ import com.mifos.core.data.repository_imp.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.CreateNewCenterRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
Expand Down Expand Up @@ -56,4 +58,7 @@ abstract class DataModule {

@Binds
internal abstract fun bindPathTrackingRepository(impl: PathTrackingRepositoryImp): PathTrackingRepository

@Binds
internal abstract fun bindCreateNewCenterRepository(impl: CreateNewCenterRepositoryImp): CreateNewCenterRepository
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.mifos.mifosxdroid.online.createnewcenter
package com.mifos.core.data.repository

import com.mifos.core.data.CenterPayload
import com.mifos.core.objects.organisation.Office
import com.mifos.core.objects.response.SaveResponse
import rx.Observable

/**
* Created by Aditya Gupta on 10/08/23.
*/
interface CreateNewCenterRepository {

fun offices(): Observable<List<Office>>

fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mifos.mifosxdroid.online.createnewcenter
package com.mifos.core.data.repository_imp

import com.mifos.core.data.CenterPayload
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.organisation.Office
import com.mifos.core.objects.response.SaveResponse
import rx.Observable
import javax.inject.Inject
Expand All @@ -13,10 +13,6 @@ import javax.inject.Inject
class CreateNewCenterRepositoryImp @Inject constructor(private val dataManagerCenter: DataManagerCenter) :
CreateNewCenterRepository {

override fun offices(): Observable<List<Office>> {
return dataManagerCenter.offices
}

override fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse> {
return dataManagerCenter.createCenter(centerPayload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.ArrowDropUp
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
Expand All @@ -38,7 +34,8 @@ fun MifosTextFieldDropdown(
onValueChanged: (String) -> Unit,
onOptionSelected: (Int, String) -> Unit,
label: Int,
options: List<String>
options: List<String>,
readOnly: Boolean = false
) {
var isExpended by remember { mutableStateOf(false) }

Expand All @@ -63,12 +60,9 @@ fun MifosTextFieldDropdown(
},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
trailingIcon = {
val image =
if (isExpended) Icons.Default.ArrowDropUp else Icons.Default.ArrowDropDown
IconButton(onClick = { isExpended = !isExpended }) {
Icon(imageVector = image, null)
}
}
ExposedDropdownMenuDefaults.TrailingIcon(isExpended)
},
readOnly = readOnly
)

ExposedDropdownMenu(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.CenterPayload
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.objects.response.SaveResponse
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class CreateNewCenterUseCase @Inject constructor(private val repository: CreateNewCenterRepository) {

suspend operator fun invoke(centerPayload: CenterPayload): Flow<Resource<SaveResponse>> =
callbackFlow {
try {
trySend(Resource.Loading())
repository.createCenter(centerPayload)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<SaveResponse>() {
override fun onCompleted() {}

override fun onError(exception: Throwable) {
trySend(Resource.Error(exception.message.toString()))
}

override fun onNext(saveResponse: SaveResponse) {
trySend(Resource.Success(saveResponse))
}
})

awaitClose { channel.close() }

} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}
}
Aditya-gupta99 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.feature.individual_collection_sheet.new_individual_collection_sheet.domain.use_case
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.feature.individual_collection_sheet.new_individual_collection_sheet.domain.use_case
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.feature.individual_collection_sheet.new_individual_collection_sheet.domain.use_case
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
Expand Down
Loading
Loading