Skip to content
Snippets Groups Projects
Commit e83a9391 authored by Nigel  Sahl's avatar Nigel Sahl
Browse files

Merge branch 'feature/randomize' into 'main'

Feature/randomize

See merge request NerbFox/if3210-2024-android-nos!16
parents d5ce3cd5 bc3c334b
Branches
Tags
No related merge requests found
package com.example.nerbos.fragments.transaction
import android.Manifest
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.location.Geocoder
......@@ -49,7 +51,8 @@ import java.util.Locale
class TransactionFragment : Fragment() {
private lateinit var transactionViewModel: TransactionViewModel
private lateinit var transactionViewModel: TransactionViewModel
private lateinit var transactionReceiver: TransactionReceiver
private lateinit var authentication: Authentication
private var currentLocation: Location? = null
private var networkManagerService: NetworkManagerService = NetworkManagerService()
......@@ -162,9 +165,27 @@ class TransactionFragment : Fragment() {
xlsxSend.visibility = View.GONE
}
// Randomize Transactionq
view.findViewById<ImageView>(R.id.randomizeTransactionButton).setOnClickListener {
val intent = Intent("ACTION_RANDOMIZE_TRANSACTION")
requireContext().sendBroadcast(intent)
}
return view
}
@SuppressLint("UnspecifiedRegisterReceiverFlag")
override fun onResume() {
super.onResume()
transactionReceiver = TransactionReceiver(this)
requireContext().registerReceiver(transactionReceiver, IntentFilter("ACTION_RANDOMIZE_TRANSACTION"))
}
override fun onPause() {
super.onPause()
requireContext().unregisterReceiver(transactionReceiver)
}
private fun createExcelFile(transactions : List<Transaction>, extension: String) : Workbook{
val workbook : Workbook
val sheet : Sheet
......@@ -306,6 +327,65 @@ class TransactionFragment : Fragment() {
dialog.window!!.setBackgroundDrawableResource(R.drawable.round_corner_transparent)
dialog.window!!.attributes = layoutParams
}
internal fun showRandomAddTransactionDialog() {
val dialog = Dialog(requireContext())
dialog.setContentView(R.layout.add_transaction)
dialog.setCancelable(true)
val layoutParams = WindowManager.LayoutParams()
layoutParams.copyFrom(dialog.window!!.attributes)
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
// Getting reference from elements in the dialog
val nameInput = dialog.findViewById<EditText>(R.id.nameInput)
val nominalInput = dialog.findViewById<EditText>(R.id.nominalInput)
val locationInput = dialog.findViewById<EditText>(R.id.locationInput)
val incomeRadioButton = dialog.findViewById<RadioButton>(R.id.incomeInput)
val outcomeRadioButton = dialog.findViewById<RadioButton>(R.id.outcomeInput)
// Randomize
val randomName = "Transaction " + (1..1000).random()
val randomNominal = (1..1000000).random().toFloat()
val randomLocation = "Location " + (1..1000).random()
val randomCategory = (0..1).random() // 0 for income, 1 for outcome
// Setting the random content
nameInput.setText(randomName)
nominalInput.setText(randomNominal.toString())
locationInput.setText(randomLocation)
if (randomCategory == 0) {
incomeRadioButton.isChecked = true
} else {
outcomeRadioButton.isChecked = true
}
dialog.findViewById<Button>(R.id.addButton).setOnClickListener {
if (insertDataToDatabase(dialog)) {
dialog.dismiss()
}
}
dialog.findViewById<Button>(R.id.cancelButton).setOnClickListener {
dialog.dismiss()
}
dialog.findViewById<ImageView>(R.id.autoFillLocationButton).setOnClickListener {
if (!networkManagerService.isNetworkAvailable(requireContext())) {
Toast.makeText(requireContext(), "No internet connection, this feature requires internet connection", Toast.LENGTH_SHORT).show()
} else {
locationInput.setText(getAddressName())
}
}
dialog.show()
dialog.window!!.setBackgroundDrawableResource(R.drawable.round_corner_transparent)
dialog.window!!.attributes = layoutParams
}
private fun showModifyTransactionDialog(transaction: Transaction) {
val dialog = Dialog(requireContext())
......
package com.example.nerbos.fragments.transaction
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.widget.Toast
class TransactionReceiver(private val fragment: TransactionFragment) : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == "ACTION_RANDOMIZE_TRANSACTION") {
fragment.showRandomAddTransactionDialog()
Toast.makeText(context, "Broadcast Received: Randomize Transaction", Toast.LENGTH_SHORT).show()
}
}
}
\ No newline at end of file
app/src/main/res/drawable/random.png

4.54 KiB

......@@ -49,6 +49,17 @@
app:layout_constraintTop_toBottomOf="@+id/saveTransactionsButton"
/>
<ImageView
android:id="@+id/randomizeTransactionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginEnd="50dp"
android:background="@drawable/random"
android:contentDescription="@string/randomize_transaction_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/sendTransactionsButton" />
<ImageView
android:id="@+id/addTransactionButton"
android:layout_width="wrap_content"
......
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">NerbOS</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="navbar_transaction">Transactions</string>
......@@ -17,7 +17,7 @@
<string name="password">password</string>
<string name="token">token</string>
<string name="key_alias">key13521000</string>
<string name="cipher_transformation">RSA/ECB/PKCS1Padding</string>
<string name="cipher_transformation" tools:ignore="Typos">RSA/ECB/PKCS1Padding</string>
<string name="android_key_store">AndroidKeyStore</string>
<string name="authorization">Authorization</string>
<string name="bearer">Bearer</string>
......@@ -69,5 +69,6 @@
<string name="logo">Logo</string>
<string name="back_button">Back Button</string>
<string name="autofill_location_button">AutoFill Location Button</string>
<string name="randomize_transaction_button">Randomize Transaction Button</string>
</resources>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment