diff --git a/app/src/main/java/com/example/bondoyap/ui/scanner/ScanResultFragment.kt b/app/src/main/java/com/example/bondoyap/ui/scanner/ScanResultFragment.kt index 1f72aec1b5beac20955e231811770fb1b4be3302..f83ea07122a99d0a8b9e0c65da163102dc7e16e2 100644 --- a/app/src/main/java/com/example/bondoyap/ui/scanner/ScanResultFragment.kt +++ b/app/src/main/java/com/example/bondoyap/ui/scanner/ScanResultFragment.kt @@ -44,7 +44,7 @@ class ScanResultFragment : Fragment() { navController = findNavController() val scannerViewModel: ScannerViewModel by activityViewModels() val items = scannerViewModel.items ?: throw Exception("Scan Result is null") - Log.d("Scan Result", "Result Received: $items") + Log.d("ScanResult", "Result Received: $items") val recyclerView = binding.recyclerView val adapter = ScanResultListAdapter() @@ -69,6 +69,18 @@ class ScanResultFragment : Fragment() { } private fun saveNota(items: List<Item>) { + try { + Log.d("ScanResult", "Saving note: $items") + saveNotaRepository(items) + Toast.makeText(requireContext(), "Nota berhasil disimpan", Toast.LENGTH_SHORT).show() + navController.popBackStack() + } catch (e: Exception) { + Toast.makeText(requireContext(), "Nota gagal disimpan", Toast.LENGTH_SHORT).show() + Log.e("ScanResult", "Saving note failed:", e) + } + } + + private fun saveNotaRepository(items: List<Item>) { val dateDateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()) val titleDateFormat = SimpleDateFormat("dd_MM_yyyy_HH_mm_ss", Locale.getDefault()) val currentTime = Date() @@ -82,6 +94,7 @@ class ScanResultFragment : Fragment() { } LocationManager.askLocationPermission(requireContext(), requireActivity()) + Log.d("ScanResult", "Getting location") val location = LocationManager.getLocation(requireContext()) var longitude = "" var latitude = "" @@ -90,7 +103,8 @@ class ScanResultFragment : Fragment() { latitude = it1.latitude.toString() } - val transaction: Transactions = Transactions( + Log.d("ScanResult", "Saving note on database") + val transaction = Transactions( judul = "Scanner_${title}", nominal = value, isPemasukan = false, @@ -99,7 +113,5 @@ class ScanResultFragment : Fragment() { latitude = latitude ) transactionsViewModel.upsert(transaction) - - Toast.makeText(requireContext(), "Nota berhasil disimpan", Toast.LENGTH_SHORT).show() } } \ No newline at end of file diff --git a/app/src/main/java/com/example/bondoyap/ui/scanner/ScannerFragment.kt b/app/src/main/java/com/example/bondoyap/ui/scanner/ScannerFragment.kt index 51117c1a9f9a916a690cbf4c58bd47a86c5debf1..94353b0bae865f894553b87498625e90e009a073 100644 --- a/app/src/main/java/com/example/bondoyap/ui/scanner/ScannerFragment.kt +++ b/app/src/main/java/com/example/bondoyap/ui/scanner/ScannerFragment.kt @@ -90,7 +90,7 @@ class ScannerFragment : Fragment() { try { val data = it.data val imgUri = data?.data ?: throw Exception("Image Uri is null") - Log.d("Image Input", "Image Selected with URI: $imgUri") + Log.d("ImageInput", "Image Selected with URI: $imgUri") // Copying image from external directory to cache val tempFile = File.createTempFile("Gallery_Image", ".jpg", cacheDir) @@ -104,7 +104,7 @@ class ScannerFragment : Fragment() { uploadPhoto(tempFile) } catch (e: Exception) { - Log.e("Image Input", "Image Input Failed:", e) + Log.e("ImageInput", "Image Input Failed:", e) } } } @@ -229,19 +229,19 @@ class ScannerFragment : Fragment() { if (response.isSuccessful) { val billResponse = response.body() ?: throw Exception("Bill Response is Empty") - Log.d("Bill Upload", "Server Response: $billResponse") + Log.d("BillUpload", "Server Response: $billResponse") navigateScanResult(billResponse.items) } else { - Log.e("Bill Upload", "Error: ${response.code()}") + Log.e("BillUpload", "Error: ${response.code()}") } } override fun onFailure(call: Call<BillResponse>, t: Throwable) { - Log.e("Bill Upload", "Failed to upload bill", t) + Log.e("BillUpload", "Failed to upload bill", t) } }) } catch (e: Exception) { - Log.e("Bill Upload", "Bill Upload Failed:", e) + Log.e("BillUpload", "Bill Upload Failed:", e) } } diff --git a/app/src/main/java/com/example/bondoyap/ui/scanner/listAdapter/ItemViewHolder.kt b/app/src/main/java/com/example/bondoyap/ui/scanner/listAdapter/ItemViewHolder.kt index 113bfe4879247955c2213e9ea067e5eaa1666f38..3c751de3299b6cb36e794fe7c31cf07999f5943c 100644 --- a/app/src/main/java/com/example/bondoyap/ui/scanner/listAdapter/ItemViewHolder.kt +++ b/app/src/main/java/com/example/bondoyap/ui/scanner/listAdapter/ItemViewHolder.kt @@ -1,11 +1,9 @@ package com.example.bondoyap.ui.scanner.listAdapter -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView -import androidx.cardview.widget.CardView import androidx.recyclerview.widget.RecyclerView import com.example.bondoyap.R import com.example.bondoyap.service.api.data.Item @@ -16,9 +14,9 @@ class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val itemQuantity: TextView = itemView.findViewById(R.id.item_quantity) val itemPrice: TextView = itemView.findViewById(R.id.item_price) - itemName.text = item.name - itemQuantity.text = item.quantity.toString() - itemPrice.text = item.price.toString() + itemName.text = "Nama: ${item.name}" + itemQuantity.text = "Jumlah: ${item.quantity}" + itemPrice.text = "Harga: ${item.price}" } companion object {