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

Feat/in app notification #7

Merged
merged 9 commits into from
Sep 26, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.navigation.NavController
import androidx.navigation.NavController.OnDestinationChangedListener
import com.rees46.demo_android.navigation.Destination
import com.rees46.demo_android.navigation.Navigator
import com.rees46.demo_android.navigation.InAppNotifications
import com.rees46.demo_android.navigation.ProductDetails
import com.rees46.demo_android.navigation.ProductsDetails
import rees46.demo_android.app.R
Expand All @@ -15,21 +16,26 @@ import rees46.demo_android.core.settings.NavigationSettings
class AppNavigator(private val navController: NavController) : Navigator {

override fun navigate(destination: Destination) {
when(destination) {
when (destination) {
is ProductDetails -> {
val bundle = bundleOf(NavigationSettings.PRODUCT_ARGUMENT_FIELD to destination.navigationProduct)
val bundle =
bundleOf(NavigationSettings.PRODUCT_ARGUMENT_FIELD to destination.navigationProduct)
navigate(
resId = R.id.productDetailsFragment,
args = bundle
)
}

is ProductsDetails -> {
val bundle = bundleOf(NavigationSettings.PRODUCTS_ARGUMENT_FIELD to destination.navigationProducts)
val bundle =
bundleOf(NavigationSettings.PRODUCTS_ARGUMENT_FIELD to destination.navigationProducts)
navigate(
resId = R.id.productsFragment,
args = bundle
)
}

is InAppNotifications -> navigate(R.id.inAppNotificationsFragment)
else -> {}
}
}
Expand All @@ -42,10 +48,10 @@ class AppNavigator(private val navController: NavController) : Navigator {
navController.popBackStack()
}

override fun getCurrentDestinationId() : Int? =
override fun getCurrentDestinationId(): Int? =
navController.currentDestination?.id

override fun getPreviousDestinationId() : Int? =
override fun getPreviousDestinationId(): Int? =
navController.previousBackStackEntry?.destination?.id

override fun addOnDestinationChangedListener(listener: OnDestinationChangedListener) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@
android:name="rees46.demo_android.feature.search.presentation.view.SearchFragment"
android:label="SearchFragment" >
</fragment>
<fragment
android:id="@+id/inAppNotificationsFragment"
android:name="rees46.demo_android.feature.home.presentation.view.InAppNotificationsFragment"
android:label="InAppNotifications">
</fragment>
</navigation>
10 changes: 5 additions & 5 deletions buildConfig/src/main/kotlin/AppBuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ class AppBuildConfig : Plugin<Project> {

private fun AppExtension.configureJavaAndKotlinOptions() {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_20
targetCompatibility = JavaVersion.VERSION_20
}
}

private fun LibraryExtension.configureJavaAndKotlinOptions() {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_20
targetCompatibility = JavaVersion.VERSION_20
}
}

Expand All @@ -156,7 +156,7 @@ class AppBuildConfig : Plugin<Project> {
private const val TARGET_SDK = 34
private const val VERSION_CODE = 1
private const val VERSION_NAME = "1.0.0"
private const val JVM_TARGET = "17"
private const val JVM_TARGET = "20"

private const val RELEASE_TYPE = "release"
private const val RELEASE_CONFIG = "releaseConfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import rees46.demo_android.databinding.FragmentHomeBinding
import rees46.demo_android.feature.recommendationBlock.presentation.view.RecommendationBlockView
import rees46.demo_android.feature.home.presentation.viewmodel.HomeViewModel
import com.rees46.demo_android.navigation.Navigator
import com.rees46.demo_android.navigation.InAppNotifications
import com.rees46.demo_android.navigation.ProductDetails
import com.rees46.demo_android.navigation.ProductsDetails
import rees46.demo_android.R
Expand Down Expand Up @@ -55,13 +56,7 @@ class HomeFragment : Fragment() {
savedInstanceState: Bundle?
) {
super.onViewCreated(view, savedInstanceState)

// with(binding.stories) {
// setId(1234)
// sdk.initializeStoriesView(this)
// settings.icon_size = 80
// settings.label_font_size = 0
// }
sdk.initializeStoriesView(binding.story)

with(binding) {
setupRecommendationBlockView(
Expand All @@ -76,6 +71,10 @@ class HomeFragment : Fragment() {
recommendationBlockView = youLikeRecommendationBlockView,
title = R.string.recommender_title
)

newFeatures.setOnClickListener {
navigateToInAppNotificationsFragment()
}
}
}

Expand All @@ -96,6 +95,10 @@ class HomeFragment : Fragment() {
}
}

private fun navigateToInAppNotificationsFragment() {
navigator.navigate(InAppNotifications)
}

private fun navigateProductFragment(product: Product) {
val navigationProduct = navigationProductMapper.toNavigationProduct(product)
navigator.navigate(ProductDetails(navigationProduct))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package rees46.demo_android.feature.home.presentation.view

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.personalization.SDK
import org.koin.android.ext.android.inject
import rees46.demo_android.R
import rees46.demo_android.databinding.FragmentInAppNotificationsBinding

class InAppNotificationsFragment : Fragment() {

private lateinit var binding: FragmentInAppNotificationsBinding

private val sdk: SDK by inject()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentInAppNotificationsBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
handleInAppNotifications()
}

private fun handleInAppNotifications() {
with(binding) {

val title = getString(R.string.alert_dialog_title)
val message = getString(R.string.alert_dialog_message)
val buttonAccept = getString(R.string.alert_dialog_button_accept)
val buttonDecline = getString(R.string.alert_dialog_button_decline)
val imageUrl =
"https://ih1.redbubble.net/image.2487413451.3407/fmp,x_small,gloss,study,product,750x1000.jpg"

alertDialogButton.setOnClickListener {
showAlertDialog(title, message, buttonAccept)
}

fullScreenDialogButton.setOnClickListener {
showFullScreenDialog(
title = title,
message = message,
imageUrl = imageUrl,
buttonNegativeText = buttonDecline,
buttonPositiveText = buttonAccept
)
}

bottomSheetDialogButton.setOnClickListener {
showBottomSheetDialog(
title = title,
message = message,
imageUrl = imageUrl,
buttonNegativeText = buttonDecline,
buttonPositiveText = buttonAccept
)
}

snackBarButton.setOnClickListener {
showSnackBar(
message = title,
buttonNegativeText = buttonDecline,
buttonPositiveText = buttonAccept
)
}
}
}

private fun showAlertDialog(title: String, message: String, buttonText: String) {
sdk.inAppNotificationManager.showAlertDialog(
fragmentManager = childFragmentManager,
title = title,
message = message,
buttonText = buttonText
)
}

private fun showFullScreenDialog(
title: String,
message: String,
imageUrl: String,
buttonNegativeText: String,
buttonPositiveText: String
) {
sdk.inAppNotificationManager.showFullScreenDialog(
fragmentManager = childFragmentManager,
title = title,
message = message,
imageUrl = imageUrl,
buttonNegativeText = buttonNegativeText,
buttonPositiveText = buttonPositiveText,
onNegativeClick = { logClick("onNegativeClick") },
onPositiveClick = { logClick("onPositiveClick") }
)
}

private fun showBottomSheetDialog(
title: String,
message: String,
imageUrl: String,
buttonNegativeText: String,
buttonPositiveText: String
) {
sdk.inAppNotificationManager.showBottomSheetDialog(
fragmentManager = childFragmentManager,
title = title,
message = message,
imageUrl = imageUrl,
buttonNegativeText = buttonNegativeText,
buttonPositiveText = buttonPositiveText,
onNegativeClick = { logClick("onNegativeClick") },
onPositiveClick = { logClick("onPositiveClick") }
)
}

private fun showSnackBar(
message: String,
buttonNegativeText: String,
buttonPositiveText: String
) {
sdk.inAppNotificationManager.showSnackBar(
view = requireView(),
message = message,
buttonNegativeText = buttonNegativeText,
buttonPositiveText = buttonPositiveText,
onNegativeClick = { logClick("onNegativeClick") },
onPositiveClick = { logClick("onPositiveClick") }
)
}

private fun logClick(action: String) {
Log.d(InAppNotificationsFragment::class.java.simpleName, action)
}
}
38 changes: 27 additions & 11 deletions feature/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/fragment_home"
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
android:id="@+id/fragment_home"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/margin_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginVertical="@dimen/margin_default">
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="@dimen/margin_default">
android:layout_marginBottom="@dimen/margin_large"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_default"
android:text="@string/stories"
android:textStyle="bold"
android:textColor="@color/text_color_primary"
android:textSize="@dimen/text_size_stories_header"
android:layout_marginHorizontal="@dimen/margin_default" />
android:textStyle="bold" />

<com.personalization.stories.views.StoriesView
android:id="@+id/story"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:code="fcaa8d3168ab7d7346e4b4f1a1c92214"
Expand All @@ -50,6 +50,22 @@
android:id="@+id/you_like_recommendation_block_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/newFeatures"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="@dimen/margin_default"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/new_features_title"
android:textColor="@color/color_blue"
android:textSize="@dimen/text_size_cart_shipping" />

</LinearLayout>

</androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
32 changes: 32 additions & 0 deletions feature/src/main/res/layout/fragment_in_app_notifications.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="@dimen/margin_large">

<Button
android:id="@+id/alertDialogButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Default pop-up" />

<Button
android:id="@+id/fullScreenDialogButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Full screen pop-up" />

<Button
android:id="@+id/bottomSheetDialogButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom sheet pop-up" />

<Button
android:id="@+id/snackBarButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show snack bar" />

</LinearLayout>
Loading