Skip to content

Commit

Permalink
refactor:refactor checker inbox screen to compose with multi module
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Apr 6, 2024
1 parent bf1bf8c commit fa7a22a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.mifos.core.designsystem.component

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
import com.mifos.core.designsystem.R
import com.mifos.core.designsystem.theme.Black
import com.mifos.core.designsystem.theme.White

@Composable
fun MifosScaffold(
icon: ImageVector?,
title : String?,
onBackPressed: () -> Unit,
actions: @Composable () -> Unit,
snackbarHostState: SnackbarHostState?,
bottomBar: @Composable () -> Unit,
content: @Composable (PaddingValues) -> Unit
) {

Scaffold(
topBar = {
TopAppBar(
colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White),
navigationIcon = {
if (icon != null) {
IconButton(
onClick = { onBackPressed() },
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = Black,
)
}
}
},
title = {
title?.let {
Text(
text = it,
style = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Medium,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_medium))
),
color = Black,
textAlign = TextAlign.Start
)
}
},
actions = { actions() }
)
},
snackbarHost = { snackbarHostState?.let { SnackbarHost(it) } },
containerColor = White,
bottomBar = bottomBar
) { padding ->
content(padding)
}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions feature/checker-inbox-task/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ dependencies {
// ViewModel utilities for Compose
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("androidx.hilt:hilt-navigation-compose:1.1.0")

// compose lifecycle
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.sparklead.feature.checker_inbox_task.checker_inbox_and_task.di

import com.mifos.core.network.datamanager.DataManagerCheckerInbox
import com.sparklead.feature.checker_inbox_task.checker_inbox_and_task.data.CheckerInboxTasksRepositoryImp
import com.sparklead.feature.checker_inbox_task.checker_inbox_and_task.domain.repository.CheckerInboxTasksRepository
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
class CheckerInboxTasksModule {

@Provides
fun providesCheckerInboxTasksRepository(dataManagerCheckerInbox: DataManagerCheckerInbox): CheckerInboxTasksRepository =
CheckerInboxTasksRepositoryImp(dataManagerCheckerInbox)
abstract class CheckerInboxTasksModule {

@Binds
abstract fun bindCheckerInboxTasksRepository(impl: CheckerInboxTasksRepositoryImp): CheckerInboxTasksRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.sparklead.feature.checker_inbox_task.checker_inbox_and_task.presenta

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -13,15 +12,9 @@ import androidx.compose.material.icons.rounded.ArrowBackIosNew
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -30,18 +23,18 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.AsyncImage
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.mifos.core.designsystem.component.MifosCircularProgress
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosSweetError
import com.mifos.core.designsystem.theme.Black
import com.mifos.core.designsystem.theme.White
import com.sparklead.feature.checker_inbox_task.R

Expand All @@ -50,51 +43,29 @@ import com.sparklead.feature.checker_inbox_task.R
*/

@Composable
fun CheckerInboxTasksScreen(onBackPressed: () -> Unit, checkerInbox: () -> Unit) {

val checkerInboxTasksViewModel: CheckerInboxTasksViewModel = hiltViewModel()
val state = checkerInboxTasksViewModel.checkerInboxTasksUiState.collectAsState().value
val isRefreshing by checkerInboxTasksViewModel.isRefreshing.collectAsState()
fun CheckerInboxTasksScreen(
checkerInboxTasksViewModel: CheckerInboxTasksViewModel = hiltViewModel(),
onBackPressed: () -> Unit,
checkerInbox: () -> Unit
) {

val state =
checkerInboxTasksViewModel.checkerInboxTasksUiState.collectAsStateWithLifecycle().value
val isRefreshing by checkerInboxTasksViewModel.isRefreshing.collectAsStateWithLifecycle()
val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = isRefreshing)

LaunchedEffect(key1 = true) {
checkerInboxTasksViewModel.loadCheckerTasksBadges()
}


Scaffold(
modifier = Modifier.fillMaxSize(),
containerColor = White,
topBar = {
TopAppBar(
colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White),
navigationIcon = {
IconButton(
onClick = { onBackPressed() },
) {
Icon(
imageVector = Icons.Rounded.ArrowBackIosNew,
contentDescription = null,
tint = Black,
)
}
},
title = {
Text(
text = stringResource(id = R.string.checker_inbox_and_pending_tasks),
style = TextStyle(
fontSize = 22.sp,
fontWeight = FontWeight.Medium,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_medium))
),
color = Black,
textAlign = TextAlign.Start
)
},
)
}
) { padding ->
MifosScaffold(
icon = Icons.Rounded.ArrowBackIosNew,
title = stringResource(id = R.string.checker_inbox_and_pending_tasks),
onBackPressed = { onBackPressed() },
actions = { },
snackbarHostState = null,
bottomBar = { })
{ padding ->
SwipeRefresh(
state = swipeRefreshState,
onRefresh = { checkerInboxTasksViewModel.loadCheckerTasksBadges() }
Expand Down Expand Up @@ -207,4 +178,12 @@ fun TaskOptions(leadingIcon: Int, option: String, badge: String, onClick: () ->
}
}
}
}

@Preview
@Composable
private fun PreviewCheckerInboxTaskScreen() {
CheckerInboxTasksScreen(onBackPressed = { }) {

}
}

0 comments on commit fa7a22a

Please sign in to comment.