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/сonnect in app notification #10

Merged
merged 3 commits into from
Dec 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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 @@ -18,25 +17,24 @@ class AppNavigator(private val navController: NavController) : Navigator {
override fun navigate(destination: Destination) {
when (destination) {
is ProductDetails -> {
val bundle =
bundleOf(NavigationSettings.PRODUCT_ARGUMENT_FIELD to destination.navigationProduct)
navigate(
resId = R.id.productDetailsFragment,
args = bundle
args = bundleOf(
NavigationSettings.PRODUCT_ARGUMENT_FIELD to destination.navigationProduct
)
)
}

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

is InAppNotifications -> navigate(R.id.inAppNotificationsFragment)
else -> {}
else -> Unit
}
}

Expand All @@ -48,14 +46,16 @@ class AppNavigator(private val navController: NavController) : Navigator {
navController.popBackStack()
}

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

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

override fun addOnDestinationChangedListener(listener: OnDestinationChangedListener) {
navController.addOnDestinationChangedListener(listener)
navController.addOnDestinationChangedListener(listener = listener)
}

private fun navigate(@IdRes resId: Int, args: Bundle?) {
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@
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>
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ object SdkUtils {
sdk.initialize(
context = context,
shopId = shopId,
shopSecretKey = "",
apiUrl = SdkSettings.API_URL,
preferencesKey = SdkSettings.PREFERENCES_KEY,
tag = SdkSettings.TAG,
stream = SdkSettings.STREAM,
notificationType = SdkSettings.NOTIFICATION_TYPE,
notificationId = SdkSettings.NOTIFICATION_ID
needReInitialization = true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.personalization.SDK
import com.rees46.demo_android.navigation.Navigator
import com.rees46.demo_android.navigation.ProductDetails
import com.rees46.demo_android.navigation.ProductsDetails
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import rees46.demo_android.R
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
import rees46.demo_android.feature.productDetails.domain.mappers.NavigationProductMapper
import rees46.demo_android.feature.productDetails.domain.models.Product
import rees46.demo_android.feature.products.presentation.mappers.ProductItemMapper
import rees46.demo_android.feature.recommendationBlock.presentation.view.RecommendationBlockView

class HomeFragment : Fragment() {

Expand Down Expand Up @@ -71,11 +70,12 @@ class HomeFragment : Fragment() {
recommendationBlockView = youLikeRecommendationBlockView,
title = R.string.recommender_title
)

newFeatures.setOnClickListener {
navigateToInAppNotificationsFragment()
}
}
initializeFragmentManager()
}

private fun initializeFragmentManager() {
sdk.initializeFragmentManager(childFragmentManager)
}

private fun setupRecommendationBlockView(
Expand All @@ -95,10 +95,6 @@ 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import rees46.demo_android.feature.productDetails.domain.models.Product

class ProductMapper {

fun toProduct(productDto: ProductDto): Product =
with(productDto) {
Product(
id = id,
name = name,
producerName = producerName,
price = price,
priceFormatted = priceFormatted,
priceFull = priceFull,
priceFullFormatted = priceFullFormatted,
pictureUrl = pictureUrl,
description = description,
rating = rating,
sale = sale
)
fun toProducts(productDtoList: List<ProductDto>): List<Product> {
return productDtoList.map {
with(it) {
Product(
id = id,
name = name,
producerName = producerName.orEmpty(),
price = price,
priceFormatted = priceFormatted,
priceFull = priceFull,
priceFullFormatted = priceFullFormatted,
pictureUrl = pictureUrl,
description = description,
rating = rating,
sale = sale
)
}
}

fun toProducts(productDtoList: List<ProductDto>): List<Product> =
productDtoList.map { toProduct(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.parcelize.Parcelize
data class ProductDto(
val id: String,
val name: String,
val producerName: String,
val producerName: String?,
val price: Double?,
val priceFormatted: String,
val priceFull: Double?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.BundleCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.rees46.demo_android.navigation.Navigator
import com.rees46.demo_android.navigation.models.NavigationProduct
import com.rees46.demo_android.ui.extensions.updateImage
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand All @@ -16,25 +19,29 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import rees46.demo_android.core.settings.NavigationSettings
import rees46.demo_android.databinding.FragmentProductDetailsBinding
import com.rees46.demo_android.navigation.Navigator
import com.rees46.demo_android.navigation.models.NavigationProduct
import rees46.demo_android.feature.productDetails.domain.mappers.NavigationProductMapper
import rees46.demo_android.feature.productDetails.domain.models.Product
import rees46.demo_android.feature.productDetails.presentation.ProductAction
import rees46.demo_android.feature.productDetails.presentation.viewmodel.ProductDetailsViewModel
import rees46.demo_android.feature.productDetails.domain.models.Product
import rees46.demo_android.feature.products.presentation.mappers.ProductItemMapper

class ProductDetailsFragment : Fragment() {

private val viewModel: ProductDetailsViewModel by viewModel {
val navigationProduct = arguments?.getParcelable<NavigationProduct>(NavigationSettings.PRODUCT_ARGUMENT_FIELD)
val navigationProduct = arguments?.let {
BundleCompat.getParcelable(
/* in = */ it,
/* key = */ NavigationSettings.PRODUCT_ARGUMENT_FIELD,
/* clazz = */ NavigationProduct::class.java
)
}
parametersOf(navigationProductMapper.toProduct(navigationProduct))
}

private lateinit var binding: FragmentProductDetailsBinding

private val productItemMapper: ProductItemMapper by inject<ProductItemMapper>()
private val navigationProductMapper: NavigationProductMapper by inject<NavigationProductMapper>()
private val productItemMapper: ProductItemMapper by inject<ProductItemMapper>()

private val navigator by lazy {
get<Navigator> {
Expand Down Expand Up @@ -117,7 +124,7 @@ class ProductDetailsFragment : Fragment() {
}

private fun updateCount(count: Int) {
binding.countCard.setCount(count)
binding.countCard.setCount(count)
}

private fun navigateProductsFragment(products: List<Product>) {
Expand Down
13 changes: 0 additions & 13 deletions feature/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@
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>
Expand Down
Loading