Skip to content

Commit

Permalink
chore(inbox): remove deprecated component
Browse files Browse the repository at this point in the history
SUITEDEV-36595

Co-authored-by: davidSchuppa <[email protected]>
Co-authored-by: megamegax <[email protected]>
Co-authored-by: matusekma <[email protected]>
  • Loading branch information
4 people committed Sep 13, 2024
1 parent 14ad3ab commit 84e54bf
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 65 deletions.
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ hms_push = "6.12.0.300"
googleServices = "4.4.2"
google-play-services-location = "21.3.0"
google-play-services-auth = "20.7.0"
google-accompanist-swipetorefresh = "0.34.0"
webkit = "1.11.0"
mockito-android = "5.10.0"
mockito-core = "5.10.0"
Expand Down Expand Up @@ -90,7 +89,6 @@ google-play-services-location = { module = "com.google.android.gms:play-services
google-play-services-auth = { module = "androidx.core:core-ktx", version.ref = "google-play-services-auth" }
google-firebase-messaging = { group = "com.google.firebase", name = "firebase-messaging", version.ref = "fcm" }
google-firebase-common = { group = "com.google.firebase", name = "firebase-common", version.ref = "firebase-common" }
google-accompanist-swipetorefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "google-accompanist-swipetorefresh" }
google-gson = { module = "com.google.code.gson:gson", version.ref = "google-gson" }
huawei-hms-push = { group = "com.huawei.hms", name = "push", version.ref = "hms_push" }
huawei-agconnect-core = { group = "com.huawei.agconnect", name = "agconnect-core", version.ref = "agconnect_core" }
Expand Down
1 change: 0 additions & 1 deletion sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ dependencies {
implementation(libs.google.firebase.common)
implementation(libs.google.firebase.messaging)
implementation(libs.play.services.auth)
implementation(libs.google.accompanist.swipetorefresh)
implementation(libs.google.gson)
debugImplementation(libs.androidx.compose.ui.tooling)

Expand Down
100 changes: 43 additions & 57 deletions sample/src/main/kotlin/com/emarsys/sample/inbox/InboxScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package com.emarsys.sample.inbox

import android.content.Context
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Scaffold
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand All @@ -24,71 +22,59 @@ import com.emarsys.sample.R
import com.emarsys.sample.ui.component.row.RowWithCenteredContent
import com.emarsys.sample.ui.component.screen.DetailScreen
import com.emarsys.sample.ui.component.text.TitleText
import com.emarsys.sample.ui.style.columnWithMaxWidth
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import kotlinx.coroutines.delay
import com.emarsys.sample.ui.style.rowWithMaxWidth

@ExperimentalCoilApi
@ExperimentalMaterialApi
@ExperimentalComposeUiApi
class InboxScreen(
override val context: Context
) : DetailScreen() {

private val viewModel = InboxViewModel()
private val messagePresenter = MessagePresenter(context)

@ExperimentalCoilApi
@ExperimentalComposeUiApi
@Composable
override fun Detail(paddingValues: PaddingValues) {
SwipeRefreshCompose(messagePresenter = messagePresenter, paddingValues)
}

@OptIn(ExperimentalCoilApi::class, androidx.compose.animation.ExperimentalAnimationApi::class)
@Composable
private fun SwipeRefreshCompose(
messagePresenter: MessagePresenter,
innerPadding: PaddingValues
) {
Scaffold(
Modifier
.columnWithMaxWidth(),
topBar = {
TitleText(titleText = stringResource(id = R.string.inbox_title))
})
val pullRefreshState = rememberPullRefreshState(
refreshing = viewModel.refreshing.value,
onRefresh = viewModel::onSwipeFetchMessages
)
Box(
modifier = Modifier
.fillMaxSize()
.rowWithMaxWidth()
.pullRefresh(pullRefreshState),
)
{
it.calculateBottomPadding()
var refreshing by remember { mutableStateOf(false) }
LaunchedEffect(key1 = refreshing) {
if (refreshing) {
delay(1000)
refreshing = false
}
}
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing = refreshing),
onRefresh = {
refreshing = true
viewModel.onSwipeFetchMessages()
})
{
AnimatedVisibility(visible = viewModel.isFetchedMessagesEmpty()) {
RowWithCenteredContent {
Text(text = stringResource(id = R.string.pull_down))
LazyColumn(
modifier = Modifier
.fillMaxSize(1f),
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
RowWithCenteredContent() {
TitleText(titleText = stringResource(id = R.string.inbox_title))
}
}
LazyColumn(
modifier = Modifier
.fillMaxSize(1f)
.padding(bottom = innerPadding.calculateBottomPadding()),
horizontalAlignment = Alignment.CenterHorizontally
) {
items(
items = viewModel.fetchedMessages.toList(),
key = { message -> message.id }) { message ->
messagePresenter.MessageCard(message = message)
item {
AnimatedVisibility(visible = viewModel.isFetchedMessagesEmpty()) {
RowWithCenteredContent {
Text(text = stringResource(id = R.string.pull_down))
}
}
}
items(
items = viewModel.fetchedMessages.toList(),
key = { message -> message.id }) { message ->
messagePresenter.MessageCard(message = message)
}
}

PullRefreshIndicator(
refreshing = viewModel.refreshing.value,
state = pullRefreshState,
modifier = Modifier.align(Alignment.TopCenter)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.emarsys.sample.inbox

import android.util.Log
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import com.emarsys.Emarsys
import com.emarsys.inbox.InboxTag
import com.emarsys.mobileengage.api.inbox.Message

class InboxViewModel : ViewModel() {

val refreshing = mutableStateOf(false)
val fetchedMessages = mutableSetOf<Message>()

fun isFetchedMessagesEmpty(): Boolean {
Expand All @@ -19,6 +20,7 @@ class InboxViewModel : ViewModel() {
}

fun onSwipeFetchMessages() {
refreshing.value = true
Emarsys.messageInbox.fetchMessages {
if (it.errorCause != null) {
Log.e("INBOX", "Inbox Error" + it.errorCause)
Expand All @@ -32,9 +34,10 @@ class InboxViewModel : ViewModel() {
messageId = message.id
)
}
this.addMessageToFetched(message)
addMessageToFetched(message)
}
}
refreshing.value = false
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions sample/src/main/kotlin/com/emarsys/sample/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import androidx.activity.compose.setContent
import androidx.annotation.RequiresApi
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.imePadding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Scaffold
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.fragment.app.FragmentActivity
import coil.annotation.ExperimentalCoilApi
import com.emarsys.sample.dashboard.DashboardViewModel
import com.emarsys.sample.main.navigation.BottomNavigationBar
import com.emarsys.sample.main.navigation.NavigationControllerProvider
Expand All @@ -17,9 +20,10 @@ import com.emarsys.sample.ui.theme.AndroidSampleAppTheme

class MainActivity : FragmentActivity() {

@OptIn(ExperimentalAnimationApi::class, androidx.compose.ui.ExperimentalComposeUiApi::class,
coil.annotation.ExperimentalCoilApi::class
)
@ExperimentalAnimationApi
@ExperimentalComposeUiApi
@ExperimentalCoilApi
@ExperimentalMaterialApi
@RequiresApi(Build.VERSION_CODES.Q)

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.emarsys.sample.main

import android.content.Context
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.lifecycle.ViewModel
import coil.annotation.ExperimentalCoilApi
import com.emarsys.sample.dashboard.DashboardScreen
import com.emarsys.sample.dashboard.DashboardViewModel
import com.emarsys.sample.inapp.InAppScreen
Expand All @@ -11,6 +14,7 @@ import com.emarsys.sample.mobileengage.MobileEngageScreen
import com.emarsys.sample.predict.PredictScreen
import com.emarsys.sample.ui.component.screen.DetailScreen

@OptIn(ExperimentalComposeUiApi::class, ExperimentalMaterialApi::class, ExperimentalCoilApi::class)
class MainViewModel(
context: Context,
dashboardViewModel: DashboardViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.emarsys.sample.main.navigation

import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import coil.annotation.ExperimentalCoilApi
import com.emarsys.sample.main.MainViewModel

class NavigationControllerProvider(private val mainViewModel: MainViewModel) {

@ExperimentalMaterialApi
@ExperimentalComposeUiApi
@ExperimentalCoilApi
@Composable
fun provide(): NavHostController {
val navHostController = rememberNavController()
Expand Down

0 comments on commit 84e54bf

Please sign in to comment.