Skip to content

Commit

Permalink
Currency Format in PayFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
whyfoo committed Jan 4, 2022
1 parent c420acd commit 8c76c9c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/com/trolle/trolleapp/PayFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class PayFragment : Fragment() {
private var _binding: FragmentPayBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -63,8 +59,14 @@ class PayFragment : Fragment() {
viewModel.getSearchItems().observe(viewLifecycleOwner, {
if (it!=null){
showLoading(true)
var totalPrice = -100000000
for (i in 0..it.size-1){
totalPrice += it.get(i).id
}
adapter.setList(it)
showLoading(false)
totalPrice /= 10000
binding.textViewSubTotalPrice.text = getString(R.string.sub_total_price_dummy, totalPrice)
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.trolle.trolleapp.data.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.trolle.trolleapp.data.Item
import com.trolle.trolleapp.databinding.ItemRowListBinding
import java.text.NumberFormat
import java.util.*

class ItemAdapter: RecyclerView.Adapter<ItemAdapter.ItemViewHolder>() {
Expand All @@ -19,10 +19,14 @@ class ItemAdapter: RecyclerView.Adapter<ItemAdapter.ItemViewHolder>() {

inner class ItemViewHolder(val binding: ItemRowListBinding) : RecyclerView.ViewHolder(binding.root){
fun bind(item: Item){
val price = item.id/100
binding.tvItemName.text = item.login
binding.tvItemCount.text = item.type
binding.tvItemPrice.text = item.id.toString()
binding.tvItemCount.text = "x${price%10+1}"

val localeID = Locale("in", "ID")
val rupiah = NumberFormat.getCurrencyInstance(localeID)

binding.tvItemPrice.text = rupiah.format(price)
}

}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/fragment_pay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@
/>

<LinearLayout
android:id="@+id/layout_subtotal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_below="@id/rv_items">

<LinearLayout
android:id="@+id/layout_subtotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="15dp"
android:visibility="gone">
android:layout_margin="15dp">

<TextView
android:id="@+id/text_view_sub_total"
Expand Down
27 changes: 14 additions & 13 deletions app/src/main/res/layout/item_row_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
android:orientation="horizontal"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="12dp"
android:padding="18dp"
android:paddingHorizontal="12dp"
android:paddingVertical="18dp"
android:background="@drawable/rounded_items">

<TextView
Expand All @@ -16,7 +17,7 @@
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginEnd="4dp"
android:textSize="16sp"
android:textStyle="bold"
tools:text="Item Name"
Expand All @@ -25,25 +26,25 @@
<TextView
android:id="@+id/tv_item_count"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="2dp"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="end"
tools:text="x1" />
android:layout_marginEnd="4dp"
android:textSize="14sp"
android:gravity="start"
tools:text="x11"
android:maxLines="1"/>

<TextView
android:id="@+id/tv_item_price"
android:textColor="@color/white"
android:layout_width="120dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="2dp"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="center"
tools:text="Rp 10.000,-"
android:gravity="left"
tools:text="10.000,-"
android:maxLines="1"
/>

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<string name="dana">Dana</string>
<string name="payment_summary">Payment Summary</string>
<string name="sub_total">Sub-Total</string>
<string name="sub_total_price_dummy">Rp 103.000,-</string>
<string name="sub_total_price_dummy">Rp. %d</string>
<string name="admin_fee">Admin Fee</string>
<string name="admin_fee_price_dummy">Rp 6.500,-</string>
<string name="grand_total">GRAND TOTAL</string>
Expand Down

0 comments on commit 8c76c9c

Please sign in to comment.