diff --git a/bondoman/app/src/main/java/com/example/bondoman/GraphPage.kt b/bondoman/app/src/main/java/com/example/bondoman/GraphPage.kt index 0bd4426d940648948ecbfd8a1cbbff6e2db0699c..bfe2ffc006d87d811d0da1ec4ad48cc8c945705c 100644 --- a/bondoman/app/src/main/java/com/example/bondoman/GraphPage.kt +++ b/bondoman/app/src/main/java/com/example/bondoman/GraphPage.kt @@ -47,6 +47,7 @@ class GraphPage : Fragment(R.layout.fragment_graph_page) { pieChart.setUsePercentValues(true) pieChart.legend.isEnabled = false + pieChart.description.isEnabled = false progressBarTumbas.max = 100 transactionRepository = TransactionRepositoryImplement(db.transactionDao(), requireContext()) diff --git a/bondoman/app/src/main/java/com/example/bondoman/ScanPage.kt b/bondoman/app/src/main/java/com/example/bondoman/ScanPage.kt index 1a15e7360f5fdc2fb1fb258450f3004ca17ab79b..575da536a2a278fde4d86131826591b277d4d462 100644 --- a/bondoman/app/src/main/java/com/example/bondoman/ScanPage.kt +++ b/bondoman/app/src/main/java/com/example/bondoman/ScanPage.kt @@ -2,11 +2,10 @@ package com.example.bondoman import android.app.Activity import android.content.ContentValues -import android.content.Context import android.content.Intent import android.content.pm.PackageManager -import android.net.ConnectivityManager -import android.net.NetworkCapabilities +import android.graphics.Bitmap +import android.graphics.Matrix import android.net.Uri import android.os.Build import android.os.Bundle @@ -51,6 +50,8 @@ class ScanPage : Fragment() { private val binding get() = _binding!! private var imageCapture: ImageCapture? = null private val PICK_IMAGE_REQUEST = 2 + private var cameraOn = false + private var imagePath = "" val db by lazy { TransactionDB(requireContext()) } @@ -65,9 +66,12 @@ class ScanPage : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - + binding.nextButton.visibility = View.GONE + binding.hasilFoto.visibility = View.GONE + binding.retryButton.visibility = View.GONE if (allPermissionsGranted()) { startCamera() + cameraOn = true } else { ActivityCompat.requestPermissions( requireActivity(), REQUIRED_PERMISSIONS, 10 @@ -75,13 +79,34 @@ class ScanPage : Fragment() { } binding.shutterButton.setOnClickListener { - takePhoto() + if (cameraOn){ + takePhoto() + } else { + cameraOn = true + binding.nextButton.visibility = View.GONE + binding.hasilFoto.visibility = View.GONE + binding.retryButton.visibility = View.GONE + binding.previewView.visibility = View.VISIBLE + } } binding.selectButton.setOnClickListener { selectPhoto() } + binding.nextButton.setOnClickListener { + sendImageToAPI(imagePath) + } + + binding.retryButton.setOnClickListener { + cameraOn = true + binding.nextButton.visibility = View.GONE + binding.hasilFoto.visibility = View.GONE + binding.retryButton.visibility = View.GONE + binding.previewView.visibility = View.VISIBLE + binding.shutterButton.visibility = View.VISIBLE + } + } private fun selectPhoto() { @@ -151,8 +176,18 @@ class ScanPage : Fragment() { val dataIndex = it.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) if (it.moveToFirst()) { val path = it.getString(dataIndex) + val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, savedUri) + val rotationMat = Matrix().apply { postRotate(90f) } + val rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, rotationMat, true) + binding.hasilFoto.setImageBitmap(rotatedBitmap) + binding.hasilFoto.visibility = View.VISIBLE + binding.previewView.visibility = View.GONE + binding.nextButton.visibility = View.VISIBLE + binding.retryButton.visibility = View.VISIBLE + binding.shutterButton.visibility = View.GONE + + imagePath = path Log.d("Camera", "File path: $path") - sendImageToAPI(path) } } cursor?.close() @@ -218,12 +253,13 @@ class ScanPage : Fragment() { val retro = Retrofit.getInstance().create(EndpointScan::class.java) Log.d("Scan", "pathname: ${pathname}") - val file = File(pathname) val requestBody = RequestBody.create(MediaType.parse("image/jpeg"), file) val filePart = MultipartBody.Part.createFormData("file", file.name, requestBody) Log.d("Scan", "filePart: ${filePart}") + Toast.makeText(requireContext(), "Mroses gambar..", Toast.LENGTH_SHORT).show() + lifecycleScope.launch { try { val response = retro.scan("Bearer $token", filePart) @@ -286,12 +322,13 @@ class ScanPage : Fragment() { var count = 0 for (item in data) { + val price = item.price * item.qty db.transactionDao().addTransaction( Transaction( 0, payloadJson.optString("nim"), item.name, - item.price.toString(), + price.toString(), "Pengeluaran", "", SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(System.currentTimeMillis()) diff --git a/bondoman/app/src/main/res/layout/fragment_scan_page.xml b/bondoman/app/src/main/res/layout/fragment_scan_page.xml index fe4be692a3dc15f6d79292a0520e0ef978920ee3..90ceac6b63b373f682369e4eb4e8d8d7c5a60990 100644 --- a/bondoman/app/src/main/res/layout/fragment_scan_page.xml +++ b/bondoman/app/src/main/res/layout/fragment_scan_page.xml @@ -17,7 +17,7 @@ app:layout_constraintTop_toTopOf="parent" /> - <LinearLayout + <FrameLayout android:id="@+id/layout_scan" android:layout_width="270dp" android:layout_height="350dp" @@ -30,7 +30,13 @@ android:id="@+id/previewView" android:layout_width="match_parent" android:layout_height="match_parent" /> - </LinearLayout> + + <ImageView + android:id="@+id/hasil_Foto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:scaleType="centerCrop" /> + </FrameLayout> <Button android:id="@+id/shutter_button" @@ -44,15 +50,40 @@ android:contentDescription="@string/scan_take_picture" /> + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + app:layout_constraintTop_toBottomOf="@id/layout_scan" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + android:layout_marginTop="40dp" + > + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Lanjut" + android:id="@+id/next_button" + android:background="@drawable/custom_button" + android:textColor="@color/white" + android:layout_marginRight="40dp"/> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Ulang" + android:id="@+id/retry_button" + android:background="@drawable/select_button"/> + </LinearLayout> + <Button android:id="@+id/select_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="130dp" android:text="@string/select_photos" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/shutter_button" + app:layout_constraintTop_toBottomOf="@id/layout_scan" android:background="@drawable/select_button"/> </androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file