diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 01f1d0c94c72e6caa3bc12a7f937daa45a5cfd68..ca3b8ab7f29aa8932f2d4a142b38381362c34868 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,18 +5,17 @@ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> - <uses-permission android:name="android.permission.CAMERA" /> - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> - - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" /> - <uses-permission android:name="android.permission.INTERNET" /> + <queries> + <package android:name="com.google.android.apps.maps" /> + </queries> + <application android:name=".MainApplication" android:allowBackup="true" @@ -29,7 +28,7 @@ android:theme="@style/Theme.BondoMan"> <activity android:name=".views.activities.MainActivity" - android:exported="true"></activity> + android:exported="true" /> <activity android:name=".views.activities.LoginActivity" android:exported="true"> diff --git a/app/src/main/java/com/example/bondoman/data/viewmodels/transaction/TransactionViewModel.kt b/app/src/main/java/com/example/bondoman/data/viewmodels/transaction/TransactionViewModel.kt index 2f61bb3a0f89aea1e4afebf6f6fea085cb3fc91e..2341bf8e541e46ad42acef391a083c40f5bc15d4 100644 --- a/app/src/main/java/com/example/bondoman/data/viewmodels/transaction/TransactionViewModel.kt +++ b/app/src/main/java/com/example/bondoman/data/viewmodels/transaction/TransactionViewModel.kt @@ -56,7 +56,7 @@ class TransactionViewModel( Transaction( title = title, owner = currentUserNim, - amount = Long.MAX_VALUE, + amount = amount, category = category, location = location, ) diff --git a/app/src/main/java/com/example/bondoman/views/components/TransactionDetailComponent.kt b/app/src/main/java/com/example/bondoman/views/components/TransactionDetailComponent.kt index 71e0ee550e62bf2adb96c86e4c42960606714964..e770dfa9d06d488af831b67c69e92e59990434fe 100644 --- a/app/src/main/java/com/example/bondoman/views/components/TransactionDetailComponent.kt +++ b/app/src/main/java/com/example/bondoman/views/components/TransactionDetailComponent.kt @@ -1,6 +1,9 @@ package com.example.bondoman.views.components import android.content.Context +import android.content.Intent +import android.net.Uri +import android.text.Html import android.util.AttributeSet import android.view.LayoutInflater import android.view.View @@ -15,144 +18,175 @@ import com.example.bondoman.databinding.ComponentTransactionDetailBinding import com.google.android.material.bottomsheet.BottomSheetBehavior import eightbitlab.com.blurview.BlurView + class TransactionDetailComponent - @JvmOverloads - constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0, - ) : LinearLayout(context, attrs, defStyleAttr) { - private var viewBinding: ComponentTransactionDetailBinding - private var transactionParser: TransactionParser - private var onTransactionRemovedListener: (() -> Unit)? = null - - fun setOnTransactionRemovedListener(listener: (() -> Unit)?) { - this.onTransactionRemovedListener = listener - } +@JvmOverloads +constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, +) : LinearLayout(context, attrs, defStyleAttr) { + + companion object { + private const val UNKNOWN_LOCATION_VALUE = "Unknown" + private const val GOOGLE_MAP_INTENT_URL = "com.google.android.apps.maps" + } - private var blurView: BlurView - private lateinit var bottomSheetBehavior: BottomSheetBehavior<out View> + private var viewBinding: ComponentTransactionDetailBinding + private var transactionParser: TransactionParser + private var onTransactionRemovedListener: (() -> Unit)? = null - private val blurRadius: Float = 1f - private val blurColor = ContextCompat.getColor(context, R.color.blur) - private val transparentColor = ContextCompat.getColor(context, android.R.color.transparent) + fun setOnTransactionRemovedListener(listener: (() -> Unit)?) { + this.onTransactionRemovedListener = listener + } - init { - viewBinding = - ComponentTransactionDetailBinding.inflate(LayoutInflater.from(context), this, true) - transactionParser = TransactionParser() + private var blurView: BlurView + private lateinit var bottomSheetBehavior: BottomSheetBehavior<out View> - blurView = viewBinding.blurView - configureBottomSheetBehaviour() - } + private val blurRadius: Float = 1f + private val blurColor = ContextCompat.getColor(context, R.color.blur) + private val transparentColor = ContextCompat.getColor(context, android.R.color.transparent) - fun configureBlurEffect(rootView: ViewGroup) { - blurView - .setupWith(rootView) - .setFrameClearDrawable(rootView.background) - .setBlurRadius(blurRadius) - blurView.setBlurEnabled(false) - } + init { + viewBinding = + ComponentTransactionDetailBinding.inflate(LayoutInflater.from(context), this, true) + transactionParser = TransactionParser() + + blurView = viewBinding.blurView + configureBottomSheetBehaviour() + + viewBinding.transactionDetailLocationText.isClickable = true + viewBinding.transactionDetailLocationText.setOnClickListener { + val locationText = viewBinding.transactionDetailLocationText.text.toString() - private fun hideAction() { - blurView.setBlurEnabled(false) - blurView.setBackgroundColor(transparentColor) - blurView.isClickable = false - } - private fun showAction() { - blurView.setBlurEnabled(true) - blurView.setBackgroundColor(transparentColor) + if (locationText != UNKNOWN_LOCATION_VALUE) { + val gmmIntentUri = + Uri.parse("geo:0,0?q=" + Uri.encode(locationText)) + val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri) + mapIntent.setPackage(GOOGLE_MAP_INTENT_URL) - blurView.isClickable = true + if (mapIntent.resolveActivity(context.packageManager) != null) { + context.startActivity(mapIntent) + } + } } + } - private fun configureBottomSheetBehaviour() { - val detailSheet = viewBinding.transactionDetailSheet + fun configureBlurEffect(rootView: ViewGroup) { + blurView + .setupWith(rootView) + .setFrameClearDrawable(rootView.background) + .setBlurRadius(blurRadius) + blurView.setBlurEnabled(false) + } - bottomSheetBehavior = BottomSheetBehavior.from(detailSheet) - bottomSheetBehavior.skipCollapsed = true - bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + private fun hideAction() { + blurView.setBlurEnabled(false) + blurView.setBackgroundColor(transparentColor) + blurView.isClickable = false + } - viewBinding.transactionDetailSheetButton - .setOnClickListener { - bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN - } + private fun showAction() { + blurView.setBlurEnabled(true) + blurView.setBackgroundColor(transparentColor) - bottomSheetBehavior.addBottomSheetCallback( - object : BottomSheetBehavior.BottomSheetCallback() { - override fun onStateChanged( - view: View, - newState: Int, - ) { - when (newState) { - BottomSheetBehavior.STATE_HIDDEN -> { - hideAction() - onTransactionRemovedListener?.invoke() - } - - BottomSheetBehavior.STATE_EXPANDED -> { - showAction() - } - // You can handle other states if needed - } - } + blurView.isClickable = true + } - override fun onSlide( - view: View, - offset: Float, - ) { - blurView.setBlurEnabled(false) - blurView.setBackgroundColor(blurColor) - } - }, - ) + private fun configureBottomSheetBehaviour() { + val detailSheet = viewBinding.transactionDetailSheet - blurView.setOnClickListener { + bottomSheetBehavior = BottomSheetBehavior.from(detailSheet) + bottomSheetBehavior.skipCollapsed = true + bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + + viewBinding.transactionDetailSheetButton + .setOnClickListener { bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN } - blurView.isClickable = false + + bottomSheetBehavior.addBottomSheetCallback( + object : BottomSheetBehavior.BottomSheetCallback() { + override fun onStateChanged( + view: View, + newState: Int, + ) { + when (newState) { + BottomSheetBehavior.STATE_HIDDEN -> { + hideAction() + onTransactionRemovedListener?.invoke() + } + + BottomSheetBehavior.STATE_EXPANDED -> { + showAction() + } + // You can handle other states if needed + } + } + + override fun onSlide( + view: View, + offset: Float, + ) { + blurView.setBlurEnabled(false) + blurView.setBackgroundColor(blurColor) + } + }, + ) + + blurView.setOnClickListener { + bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + } + blurView.isClickable = false + } + + fun setTransaction(transaction: Transaction) { + viewBinding.transactionDetailDate.text = transactionParser.getDateString(transaction.date) + viewBinding.transactionDetailAmount.text = + transactionParser.getAmountString(transaction.amount, transaction.category) + viewBinding.transactionDetailTitle.text = transaction.title + + if (transaction.location == null) { + viewBinding.transactionDetailLocationText.text = UNKNOWN_LOCATION_VALUE + } else { + val htmlContent = "<u>${transaction.location}</u>" + viewBinding.transactionDetailLocationText.text = + Html.fromHtml(htmlContent, Html.FROM_HTML_MODE_LEGACY) } - fun setTransaction(transaction: Transaction) { - viewBinding.transactionDetailDate.text = transactionParser.getDateString(transaction.date) - viewBinding.transactionDetailAmount.text = - transactionParser.getAmountString(transaction.amount, transaction.category) - viewBinding.transactionDetailTitle.text = transaction.title - viewBinding.transactionDetailLocationText.text = transaction.location ?: "Unknown" - - val categoryBackgroundColor = - ContextCompat.getColor( - context, - if (transaction.category == TransactionCategory.EARNINGS) { - R.color.teal_200 - } else { - R.color.rose_200 - }, - ) - - viewBinding.transactionDetailIconImage.setImageResource( + val categoryBackgroundColor = + ContextCompat.getColor( + context, if (transaction.category == TransactionCategory.EARNINGS) { - R.drawable.ic_coins + R.color.teal_200 } else { - R.drawable.ic_shopping_bag_minus + R.color.rose_200 }, ) - viewBinding.transactionDetailIconImage.setBackgroundColor(categoryBackgroundColor) - viewBinding.transactionDetailCategoryText.text = transaction.category.string.uppercase() - viewBinding.transactionDetailCategoryText.setBackgroundColor(categoryBackgroundColor) - } + viewBinding.transactionDetailIconImage.setImageResource( + if (transaction.category == TransactionCategory.EARNINGS) { + R.drawable.ic_coins + } else { + R.drawable.ic_shopping_bag_minus + }, + ) + viewBinding.transactionDetailIconImage.setBackgroundColor(categoryBackgroundColor) + + viewBinding.transactionDetailCategoryText.text = transaction.category.string.uppercase() + viewBinding.transactionDetailCategoryText.setBackgroundColor(categoryBackgroundColor) + } - fun setDeleteListener(listener: () -> Unit) { - viewBinding.trasactionDetailDeleteButton.setOnClickListener { listener() } - } + fun setDeleteListener(listener: () -> Unit) { + viewBinding.trasactionDetailDeleteButton.setOnClickListener { listener() } + } - fun setUpdateListener(listener: () -> Unit) { - viewBinding.trasactionDetailEditButton.setOnClickListener { listener() } - } + fun setUpdateListener(listener: () -> Unit) { + viewBinding.trasactionDetailEditButton.setOnClickListener { listener() } + } - fun setBottomSheetState(state: Int) { - bottomSheetBehavior.state = state - } + fun setBottomSheetState(state: Int) { + bottomSheetBehavior.state = state } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 25142fc9b0c03f244b7727569643698ac776fcf2..2280d207b2256e20bfa9d14f6d71723da3365807 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,7 +17,7 @@ <string name="dummy_transaction_date">30 Mar 2026</string> <string name="dummy_transaction_amount">-Rp9.000.000.000.000.000</string> <string name="dummy_transaction_title">Ethereum to the earth’s core</string> - <string name="dummy_transaction_location">Tokyo, Japan</string> + <string name="dummy_transaction_location"><u>Tokyo, Japan</u></string> <string name="text_button_swipe_vertical">swipe vertically</string> <string name="desc_delete_transaction">Delete transaction</string> <string name="dummy_page_title">Title</string>