Skip to content

Commit

Permalink
Rework the cart system and add checkout activity
Browse files Browse the repository at this point in the history
  • Loading branch information
andraantariksa committed Apr 21, 2022
1 parent 89e6bbd commit 2ef18e8
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 114 deletions.
4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:725480389193:android:e80fbcb1661541e8eb1d98",
"mobilesdk_app_id": "1:725480389193:android:ffd9b326bff04b61eb1d98",
"android_client_info": {
"package_name": "id.shaderboi.koffie"
}
},
"oauth_client": [
{
"client_id": "725480389193-mfihmtgvhb6qoebab9r84v97n3v7jd9c.apps.googleusercontent.com",
"client_type": 3
"client_id": "725480389193-t71fd4jnardjuhvkbojck9qhsr7ha1i2.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "id.shaderboi.koffie",
"certificate_hash": "0c1aaaf0613b5146f68fcd1c02209c3f6f27121f"
}
}
],
"api_key": [
{
"current_key": "AIzaSyCdjwYHL7TIpqmz_ONbGICRdPVHHY14kFY"
"current_key": "AIzaSyCbCI0afslh5sjouwS4ah3xo3JUDXS2bUI"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "725480389193-mfihmtgvhb6qoebab9r84v97n3v7jd9c.apps.googleusercontent.com",
"client_type": 3
}
]
"other_platform_oauth_client": []
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
android:name=".ui.coupons.CouponsActivity"
android:exported="false" />
<activity
android:name=".ui.product.ProductFragment"
android:name=".ui.checkout.CheckoutActivity"
android:exported="false" />
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package id.shaderboi.koffie.ui.auth.registration

import IntentExtra
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
Expand Down Expand Up @@ -81,16 +82,16 @@ class RegistrationFragment : Fragment() {
.datePicker()
.build()

binding.editTextBirthDate.setOnClickListener {
datePicker.show(parentFragmentManager, null)
}

binding.buttonSubmit.setOnClickListener {
val displayName = binding.editTextName.text.toString()
val birthDate = binding.editTextBirthDate.text.toString()
val selectedGender = binding.spinnerGender.selectedItemPosition
binding.apply {
editTextBirthDate.setOnClickListener {
datePicker.show(parentFragmentManager, null)
}

registrationViewModel.onEvent(RegistrationEvent.Register(displayName))
buttonSubmit.setOnClickListener {
val displayName = editTextName.text.toString()
val birthDate = editTextBirthDate.text.toString()
val selectedGender = spinnerGender.selectedItemPosition
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package id.shaderboi.koffie.ui.checkout

import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity

class CheckoutActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
13 changes: 7 additions & 6 deletions app/src/main/kotlin/id/shaderboi/koffie/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setupAuthentication()
setupSplashScreen()

_binding = ActivityMainBinding.inflate(layoutInflater)

setupView()

setContentView(binding.root)
setupAuthentication()
}

override fun onDestroy() {
Expand Down Expand Up @@ -79,6 +74,12 @@ class MainActivity : AppCompatActivity() {
user?.isRegistered
if (user?.isRegistered == false || user == null) {
onNotAuthenticated()
} else {
_binding = ActivityMainBinding.inflate(layoutInflater)

setContentView(binding.root)

setupView()
}
}.launchIn(lifecycleScope)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import id.shaderboi.koffie.R
import id.shaderboi.koffie.core.domain.model.common.Coordinate
import id.shaderboi.koffie.core.util.Resource
import id.shaderboi.koffie.databinding.FragmentStoreBinding
import id.shaderboi.koffie.ui.checkout.CheckoutActivity
import id.shaderboi.koffie.ui.coupons.CouponsActivity
import id.shaderboi.koffie.ui.location.LocationActivity
import id.shaderboi.koffie.ui.main.store.adapter.CategorizedProductAdapter
Expand Down Expand Up @@ -176,10 +177,25 @@ class StoreFragment : Fragment() {

launch {
cartViewModel.cartFlow.collectLatest { cartItems ->
showCheckoutBar(cartItems.isNotEmpty())
val isShowCheckoutBar = cartItems.isNotEmpty()
showCheckoutBar(isShowCheckoutBar)

val estimatedTotalPrice =
cartItems.sumOf { cartItem ->
cartItem.product.price - (cartItem.product.discount ?: 0)
}

binding.apply {
textViewCheckoutItems.text = "${cartItems.size} items"
textViewCheckoutPrice.text = "Rp ${numberFormatter.format(12000)}"
textViewCheckoutPrice.text =
"Rp ${numberFormatter.format(estimatedTotalPrice)}"

linearLayoutCheckout.setOnClickListener {
if (!isShowCheckoutBar) return@setOnClickListener

val intent = Intent(requireContext(), CheckoutActivity::class.java)
startActivity(intent)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package id.shaderboi.koffie.ui.main.store.view_model

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import id.shaderboi.koffie.core.domain.repository.CartRepository
import javax.inject.Inject

@HiltViewModel
class CartViewModel @Inject constructor(
private val cartRepository: CartRepository
): ViewModel() {
val cartFlow = cartRepository.cartItemsFlow
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package id.shaderboi.koffie.ui.product.view_model

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import id.shaderboi.koffie.core.domain.model.store.products.Product
import id.shaderboi.koffie.core.domain.repository.CartRepository
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ProductViewModel @Inject constructor() : ViewModel() {
class ProductViewModel @Inject constructor(
private val cartRepository: CartRepository
) : ViewModel() {
fun onEvent(event: ProductEvent) {
when(event) {
is ProductEvent.AddProductToCart -> {
event.product
}
// is ProductEvent.
is ProductEvent.AddProductToCart -> addProductToCart(event.product)
}
}

private fun addProductToCart(product: Product) = viewModelScope.launch {
cartRepository.addCartItem(product)
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_add_circle_outline_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http:https://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M13,7h-2v4L7,11v2h4v4h2v-4h4v-2h-4L13,7zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_remove_circle_outline_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http:https://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7,11v2h10v-2L7,11zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_signin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@
tools:visibility="visible" />

<TextView
android:id="@+id/textViewPrivacyPolicy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="32dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="@string/signin_signup_agreement"
tools:text="@string/signin_signup_agreement"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_verify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
tools:visibility="visible" />

<TextView
android:id="@+id/textViewPrivacyPolicy"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="@string/signin_signup_agreement"
tools:text="@string/signin_signup_agreement"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Loading

0 comments on commit 2ef18e8

Please sign in to comment.