dev
Aji Kamaludin 2 years ago
parent f6e2966e90
commit 79f6cc7f61
No known key found for this signature in database
GPG Key ID: 670E1F26AD5A8099

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/5.4_FWVGA_API_25.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-04-03T13:13:54.894326Z" />
</component>
</project>

@ -3,11 +3,15 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.2595" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/drawable/ic_baseline_account_balance_wallet_24.xml" value="0.2595" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2595" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/layout/activity_main.xml" value="0.36614583333333334" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/layout/fragment_add_transaction.xml" value="0.36614583333333334" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/layout/fragment_transaction_list.xml" value="0.36477987421383645" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/layout/item_transaction.xml" value="0.36614583333333334" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/layout/item_type.xml" value="0.36614583333333334" />
<entry key="../../../media/aji/datautama.NeTv3SD/Development/AndroidStudioProjects/Wallet/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.2595" />
</map>
</option>
</component>

@ -9,7 +9,7 @@ data class Transaction(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
@ColumnInfo(name = "amount")
val amount: Double,
val amount: Int,
@ColumnInfo(name = "description")
val description: String,
@ColumnInfo(name = "type")

@ -18,14 +18,14 @@ interface TransactionDao {
@Query("SELECT * from transactions ORDER BY created_at DESC")
fun getTransactions(): Flow<List<Transaction>>
@Query("SELECT (SELECT SUM(amount) FROM transactions WHERE type = ${ITEM_INCOME}) - (SELECT SUM(amount) FROM transactions WHERE type = ${ITEM_EXPENSE})")
fun getTotalAmount(): Flow<String>
@Query("SELECT (SELECT COALESCE(SUM(amount), 0) FROM transactions WHERE type = ${ITEM_INCOME}) - (SELECT COALESCE(SUM(amount), 0) FROM transactions WHERE type = ${ITEM_EXPENSE})")
fun getTotalAmount(): Flow<Int>
@Query("SELECT SUM(amount) FROM transactions WHERE type = $ITEM_INCOME")
fun getTotalIncome(): Flow<String>
@Query("SELECT COALESCE(SUM(amount), 0) FROM transactions WHERE type = $ITEM_INCOME")
fun getTotalIncome(): Flow<Int>
@Query("SELECT SUM(amount) FROM transactions WHERE type = $ITEM_EXPENSE")
fun getTotalExpense(): Flow<String>
@Query("SELECT COALESCE(SUM(amount), 0) FROM transactions WHERE type = $ITEM_EXPENSE")
fun getTotalExpense(): Flow<Int>
@Query("SELECT * FROM transactions WHERE id = :id")
fun getTransaction(id: Long): Flow<Transaction>

@ -113,11 +113,11 @@ class AddTransactionFragment : Fragment() {
private fun bind(transaction: Transaction) {
binding.apply {
itemAmount.setText(transaction.amount.toString(), TextView.BufferType.SPANNABLE)
itemAmount.setText(transaction.amount.toInt().toString(), TextView.BufferType.SPANNABLE)
itemDescription.setText(transaction.description, TextView.BufferType.SPANNABLE)
when(transaction.type) {
ITEM_INCOME -> itemType.setText(getString(R.string.income), TextView.BufferType.SPANNABLE)
else -> itemType.setText(getString(R.string.expense), TextView.BufferType.SPANNABLE)
ITEM_INCOME -> itemType.setText(getString(R.string.income), false)
else -> itemType.setText(getString(R.string.expense), false)
}
saveAction.setOnClickListener { updateItem() }

@ -35,9 +35,10 @@ class TransactionListAdapter(private val onItemClicked: (Transaction) -> Unit):
fun bind(transaction: Transaction) {
binding.apply {
val amount = transaction.amount.toString()
when(transaction.type) {
ITEM_INCOME -> textAmount.text = transaction.amount.toString()
else -> textAmount.text = "-${transaction.amount.toString()}"
ITEM_INCOME -> textAmount.text = amount
else -> textAmount.text = "-${amount}"
}
textDate.text = transaction.createdAt
textDescription.text = transaction.description

@ -37,9 +37,6 @@ class TransactionListFragment: Fragment() {
findNavController().navigate(action)
}
binding.viewModel = viewModel
binding.lifecycleOwner = viewLifecycleOwner
val adapter = TransactionListAdapter {
val action = TransactionListFragmentDirections.actionTransactionListFragmentToAddTransactionFragment(it.id)
findNavController().navigate(action)
@ -49,5 +46,17 @@ class TransactionListFragment: Fragment() {
viewModel.transactions.observe(viewLifecycleOwner) { items ->
items.let { adapter.submitList(it) }
}
viewModel.amount.observe(viewLifecycleOwner) { amount ->
binding.txtAmount.text = amount.toString()
}
viewModel.income.observe(viewLifecycleOwner) {
binding.txtExpense.text = it.toString()
}
viewModel.expense.observe(viewLifecycleOwner) {
binding.txtIncome.text = it.toString()
}
}
}

@ -9,9 +9,9 @@ import java.util.*
class TransactionViewModel(private val transactionDao: TransactionDao): ViewModel() {
val transactions: LiveData<List<Transaction>> = transactionDao.getTransactions().asLiveData()
val amount: LiveData<String> = transactionDao.getTotalAmount().asLiveData()
val expense: LiveData<String> = transactionDao.getTotalExpense().asLiveData()
val income: LiveData<String> = transactionDao.getTotalIncome().asLiveData()
val amount: LiveData<Int> = transactionDao.getTotalAmount().asLiveData()
val expense: LiveData<Int> = transactionDao.getTotalExpense().asLiveData()
val income: LiveData<Int> = transactionDao.getTotalIncome().asLiveData()
private fun insertTransaction(transaction: Transaction) {
viewModelScope.launch {
@ -22,11 +22,11 @@ class TransactionViewModel(private val transactionDao: TransactionDao): ViewMode
private fun getNewTransactionEntry(amount: String, description: String, type: Int): Transaction {
val current = Date()
val formatter = SimpleDateFormat("dd-M-yyyy hh:mm", Locale.US)
val formatter = SimpleDateFormat("dd-M-yyyy HH:mm", Locale.US)
val formatted = formatter.format(current)
return Transaction(
amount = amount.toDouble(),
amount = amount.toInt(),
description = description,
type = type,
createdAt = formatted
@ -52,7 +52,7 @@ class TransactionViewModel(private val transactionDao: TransactionDao): ViewMode
private fun getUpdatedTransactionEntry(id: Long, amount: String, description: String, type: Int, createdAt: String): Transaction {
return Transaction(
id = id,
amount = amount.toDouble(),
amount = amount.toInt(),
description = description,
type = type,
createdAt = createdAt

@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="#4CAF50"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M21,18v1c0,1.1 -0.9,2 -2,2L5,21c-1.11,0 -2,-0.9 -2,-2L3,5c0,-1.1 0.89,-2 2,-2h14c1.1,0 2,0.9 2,2v1h-9c-1.11,0 -2,0.9 -2,2v8c0,1.1 0.89,2 2,2h9zM12,16h10L22,8L12,8v8zM16,13.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
</vector>

@ -4,9 +4,6 @@
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"

@ -6,9 +6,6 @@
<data>
<variable
name="viewModel"
type="id.ajikamaludin.wallet.ui.TransactionViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
@ -52,26 +49,23 @@
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.amount}"
android:textAlignment="center"
android:textColor="@color/white"
tools:text="10.000" />
tools:text="1000000000" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_expense"
android:id="@+id/card_income"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="@android:color/holo_red_light"
app:layout_constraintEnd_toStartOf="@+id/card_income"
app:layout_constraintEnd_toStartOf="@+id/card_expense"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/card_balance">
@ -96,26 +90,24 @@
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.expense}"
android:textAlignment="center"
android:textColor="@color/white"
tools:text="10.000" />
tools:text="10000" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_income"
android:id="@+id/card_expense"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="@android:color/holo_green_light"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_expense"
app:layout_constraintStart_toEndOf="@+id/card_income"
app:layout_constraintTop_toBottomOf="@+id/card_balance">
<LinearLayout
@ -139,10 +131,9 @@
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.income}"
android:textAlignment="center"
android:textColor="@color/white"
tools:text="20.000" />
tools:text="20000" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

@ -19,7 +19,7 @@
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="10.000" />
tools:text="10.000.000" />
<TextView
android:id="@+id/textDescription"
@ -34,14 +34,14 @@
<TextView
android:id="@+id/textDate"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="2022-10-2"
android:textColor="@color/black" />
tools:text="2022-10-2" />
<View
android:id="@+id/divider"

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

@ -10,4 +10,8 @@
<string name="amount">Jumlah</string>
<string name="description">Deskripsi</string>
<string name="type">Tipe</string>
<string name="delete_action">Hapus</string>
<string name="delete_question">Anda yakin ?</string>
<string name="no">tidak</string>
<string name="yes">Ya</string>
</resources>

@ -17,4 +17,6 @@
<color name="blue_dark">#004ba0</color>
<color name="red_700">#d32f2f</color>
<color name="ic_launcher_background">#4caf40</color>
</resources>
Loading…
Cancel
Save