diff --git a/app/src/main/java/com/example/bondoman/TambahTransaksi.kt b/app/src/main/java/com/example/bondoman/TambahTransaksi.kt new file mode 100644 index 0000000000000000000000000000000000000000..5669ca670c1eca97b7b2dbb4eab21eb3f36d9540 --- /dev/null +++ b/app/src/main/java/com/example/bondoman/TambahTransaksi.kt @@ -0,0 +1,41 @@ +package com.example.bondoman + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.EditText +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +class TambahTransaksi : Fragment() { + private lateinit var nama: EditText + private lateinit var kategori: EditText + private lateinit var date: EditText + private lateinit var nominal: EditText + private lateinit var lokasi: EditText + private lateinit var save: EditText + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_tambah_transaksi, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val currentDate = LocalDate.now() + val formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy") + val formattedDate = currentDate.format(formatter) + date.setText(formattedDate) + nama = view.findViewById(R.id.NamaTransaksi) + kategori = view.findViewById(R.id.KategoriTransaksi) + date = view.findViewById(R.id.TanggalTransaksi) + nominal = view.findViewById(R.id.NominalTransaksi) + lokasi = view.findViewById(R.id.LokasiTransaksi) + save = view.findViewById(R.id.SimpanTransaksi) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bondoman/retrofit/adapter/TransactionAdapter.kt b/app/src/main/java/com/example/bondoman/retrofit/adapter/TransactionAdapter.kt new file mode 100644 index 0000000000000000000000000000000000000000..6fe800aca54681f366097b5fb594548d4a804908 --- /dev/null +++ b/app/src/main/java/com/example/bondoman/retrofit/adapter/TransactionAdapter.kt @@ -0,0 +1,78 @@ +package com.example.bondoman.retrofit.adapter + +import android.content.Intent +import android.net.Uri +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import android.widget.Toast +import androidx.recyclerview.widget.RecyclerView +import com.example.bondoman.R +import com.example.bondoman.retrofit.data.entity.TransactionEntity + +class TransactionAdapter(private val listData: ArrayList<TransactionEntity>): RecyclerView.Adapter<TransactionAdapter.ViewHolder>(){ + + override fun onBindViewHolder(holder: com.example.bondoman.TransactionAdapter.DataViewHolder, position: Int) { + val currentData = listData[position] + holder.txtName.text = currentData.name + holder.txtCategory.text = currentData.category.toString() + val temp = "IDR " + currentData.price.toString() + holder.txtPrice.text = temp + holder.txtLocation.text = currentData.location + holder.txtDate.text = currentData.date + + // Set click listener for itemLocation TextView + holder.txtLocation.setOnClickListener { + val context = holder.itemView.context + // Check if the location is not "Unknown" and not empty before opening Google Maps + if (currentData.location != null && currentData.location != "Unknown" && currentData.location!!.isNotBlank()) { + // Open Google Maps app + val gmmIntentUri = Uri.parse("geo:0,0?q=${Uri.encode(currentData.location)}") + val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri) + mapIntent.setPackage("com.google.android.apps.maps") + if (mapIntent.resolveActivity(context.packageManager) != null) { + context.startActivity(mapIntent) + } else { + // Open Google Maps website in a web browser + val webIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/maps/search/?api=1&query=${Uri.encode(currentData.location)}")) + context.startActivity(webIntent) + } + } + } + + holder.itemView.setOnClickListener { + // Display a toast message when the item is clicked + val toastMessage = "Clicked item: ${currentData.name} with id ${currentData.id}" + Toast.makeText(holder.itemView.context, toastMessage, Toast.LENGTH_SHORT).show() + + val intent = Intent(holder.itemView.context, AddTransactionActivity::class.java) + + // Optionally, pass data to the AddTransactionActivity + intent.putExtra("transactionId", currentData.id) + + // Start the activity + holder.itemView.context.startActivity(intent) + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): com.example.bondoman.TransactionAdapter.ViewHolder { + val view: View = LayoutInflater.from(parent.context).inflate(R.layout.row_data,parent,false) + return com.example.bondoman.TransactionAdapter.ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + TODO("Not yet implemented") + } + + override fun getItemCount(): Int { + return listData.count() + } + class ViewHolder(item: View) : RecyclerView.ViewHolder(item) { + val txtName: TextView = item.findViewById(R.id.itemName) + val txtCategory:TextView= item.findViewById(R.id.category) + val txtDate: TextView= item.findViewById(R.id.itemDate) + val txtPrice : TextView= item.findViewById(R.id.itemPrice) + val txtLocation : TextView = item.findViewById(R.id.itemLocation) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bondoman/retrofit/data/TransactionDB.kt b/app/src/main/java/com/example/bondoman/retrofit/data/TransactionDB.kt new file mode 100644 index 0000000000000000000000000000000000000000..c3ed442c664dcb11fea85d48a0f56e911349fd50 --- /dev/null +++ b/app/src/main/java/com/example/bondoman/retrofit/data/TransactionDB.kt @@ -0,0 +1,27 @@ +package com.example.bondoman.retrofit.data + +import android.content.Context +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase +import com.example.bondoman.retrofit.data.dao.TransactionDao +import com.example.bondoman.retrofit.data.entity.TransactionEntity + +@Database(entities = [TransactionEntity::class], version = 1) +abstract class TransactionDB : RoomDatabase() { + abstract fun transactionDao(): TransactionDao + + companion object{ + private var instance : TransactionDB? = null + + fun getInstance(context: Context) : TransactionDB{ + if (instance==null){ + instance = Room.databaseBuilder(context, TransactionDB::class.java, "transaction-database") + .allowMainThreadQueries() + .build() + } + + return instance!! + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bondoman/retrofit/data/dao/TransactionDao.kt b/app/src/main/java/com/example/bondoman/retrofit/data/dao/TransactionDao.kt new file mode 100644 index 0000000000000000000000000000000000000000..27ebc42d15503365179a3e7de04b69a9a9d433fe --- /dev/null +++ b/app/src/main/java/com/example/bondoman/retrofit/data/dao/TransactionDao.kt @@ -0,0 +1,27 @@ +package com.example.bondoman.retrofit.data.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import com.example.bondoman.retrofit.data.entity.TransactionEntity + +@Dao +interface TransactionDao { + + @Query("SELECT * FROM transactionentity") + fun getAll(): List<TransactionEntity> + + @Query("SELECT * FROM transactionentity WHERE id IN (:userIds)") + fun loadAllByIds(userIds: IntArray): List<TransactionEntity> + + @Query("SELECT * FROM transactionentity WHERE name LIKE :name AND " + + "price LIKE :nominal LIMIT 1") + fun findByName(name: String, nominal: String): TransactionEntity + + @Insert + fun insertAll(vararg transactions: TransactionEntity) + + @Delete + fun delete(transaction: TransactionEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bondoman/retrofit/data/entity/TransactionEntitiy.kt b/app/src/main/java/com/example/bondoman/retrofit/data/entity/TransactionEntitiy.kt new file mode 100644 index 0000000000000000000000000000000000000000..ba0328edb120115b631262197d7e8ee9f0bb5887 --- /dev/null +++ b/app/src/main/java/com/example/bondoman/retrofit/data/entity/TransactionEntitiy.kt @@ -0,0 +1,20 @@ +package com.example.bondoman.retrofit.data.entity + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +enum class TransactionCategory { + PEMASUKAN, + PENGELUARAN +} + +@Entity +data class TransactionEntity( + @PrimaryKey(autoGenerate = true) var id: Int? = null, + @ColumnInfo(name = "name") var name: String? = null, + @ColumnInfo(name = "category") var category: TransactionCategory? = null, + @ColumnInfo(name = "date") var date: String? = null, + @ColumnInfo(name = "price") var price: Int? = null, + @ColumnInfo(name = "location") var location: String? = null +) \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_add_24.xml b/app/src/main/res/drawable/baseline_add_24.xml new file mode 100644 index 0000000000000000000000000000000000000000..89633bb125d37a7e89833cfd4708ae8b8902822d --- /dev/null +++ b/app/src/main/res/drawable/baseline_add_24.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" android:tint="#000000" + 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="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/> +</vector> diff --git a/app/src/main/res/drawable/component_7.xml b/app/src/main/res/drawable/component_7.xml new file mode 100644 index 0000000000000000000000000000000000000000..26e09f08e75530ec4bec1a5e8ebe1e94dd90cde0 --- /dev/null +++ b/app/src/main/res/drawable/component_7.xml @@ -0,0 +1,30 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="54dp" + android:height="52dp" + android:viewportWidth="54" + android:viewportHeight="52"> + <path + android:pathData="M24,0L30,0A20,20 0,0 1,50 20L50,24A20,20 0,0 1,30 44L24,44A20,20 0,0 1,4 24L4,20A20,20 0,0 1,24 0z" + android:fillColor="#9290C3"/> + <path + android:pathData="M27,18.426V25.573" + android:strokeLineJoin="round" + android:strokeWidth="1.5" + android:fillColor="#00000000" + android:strokeColor="#ffffff" + android:strokeLineCap="round"/> + <path + android:pathData="M30.578,22H23.422" + android:strokeLineJoin="round" + android:strokeWidth="1.5" + android:fillColor="#00000000" + android:strokeColor="#ffffff" + android:strokeLineCap="round"/> + <path + android:pathData="M27,12.263C34.302,12.263 36.737,14.698 36.737,22C36.737,29.302 34.302,31.737 27,31.737C19.698,31.737 17.263,29.302 17.263,22C17.263,16.03 18.891,13.313 23.475,12.521" + android:strokeLineJoin="round" + android:strokeWidth="1.5" + android:fillColor="#00000000" + android:strokeColor="#ffffff" + android:strokeLineCap="round"/> +</vector> diff --git a/app/src/main/res/layout/fragment_tambah_transaksi.xml b/app/src/main/res/layout/fragment_tambah_transaksi.xml new file mode 100644 index 0000000000000000000000000000000000000000..9f974debc408cf6950a9a422ed53895397e63615 --- /dev/null +++ b/app/src/main/res/layout/fragment_tambah_transaksi.xml @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="20dp" + android:layout_margin="20dp" + tools:context=".TambahTransaksi"> + + <com.google.android.material.textfield.TextInputLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + app:boxBackgroundMode="outline" + android:layout_marginBottom="15dp"> + <EditText + android:id="@+id/NamaTransaksi" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="textPersonName" + android:hint="Nama Transaksi" + /> + </com.google.android.material.textfield.TextInputLayout> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:layout_marginBottom="15dp"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Kategori" + android:textSize="16sp" + android:layout_marginStart="15dp" + android:layout_marginBottom="10dp" + /> + <RadioGroup + android:id="@+id/KategoriTransaksi" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_marginBottom="14dp" + android:layout_marginStart="15dp"> + <RadioButton + android:id="@+id/Pemasukan" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Pemasukan" + android:checked="true" + /> + <RadioButton + android:id="@+id/Pengeluaran" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Pengeluaran" + /> + </RadioGroup> + </LinearLayout> + <com.google.android.material.textfield.TextInputLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + app:boxBackgroundMode="outline" + android:layout_marginBottom="15dp"> + <EditText + android:id="@+id/NominalTransaksi" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="numberDecimal" + android:hint="Masukkan Nominal Transaksi" + /> + </com.google.android.material.textfield.TextInputLayout> + <com.google.android.material.textfield.TextInputLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + app:boxBackgroundMode="outline" + android:layout_marginBottom="25dp"> + <EditText + android:id="@+id/LokasiTransaksi" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="textLongMessage" + android:hint="Lokasi Transaksi" + /> + </com.google.android.material.textfield.TextInputLayout> + <Button + android:id="@+id/SimpanTransaksi" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Simpan" + android:backgroundTint="@color/purple" + android:textColor="@color/white" + android:layout_marginBottom="25dp" + /> +</LinearLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/row_data.xml b/app/src/main/res/layout/row_data.xml new file mode 100644 index 0000000000000000000000000000000000000000..1ca99191441741b0d3986a620bbf18afc14af522 --- /dev/null +++ b/app/src/main/res/layout/row_data.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_margin="8dp" + android:orientation="horizontal"> + <LinearLayout + android:layout_width="220dp" + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_margin="8dp"> + <TextView + android:id="@+id/KategoriTransaksi" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@drawable/cornered_simpan" + android:textColor="@color/light_grey" + android:padding="4dp" + android:textSize="12sp" + /> + <TextView + android:id="@+id/NamaTransaksi" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="2dp" + android:textSize="16sp" + /> + <TextView + android:id="@+id/TanggalTransaksi" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="2dp" + android:textSize="12sp" + /> + </LinearLayout> + <LinearLayout + android:layout_width="90dp" + android:layout_height="match_parent" + android:layout_marginEnd="5dp" + android:layout_marginStart="0dp" + android:orientation="vertical" + android:gravity="end"> + <TextView + android:id="@+id/NominalTransaksi" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="2dp" + android:textSize="16sp" + android:layout_weight="1"/> + <TextView + android:id="@+id/LokasiTransaksi" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="2dp" + android:textSize="12sp" + android:ellipsize="end" + android:maxLines="1" + android:layout_weight="2" + android:clickable="true" /> + + + </LinearLayout> + +</LinearLayout> \ No newline at end of file