0

I have a problem because I am trying to add an onReceiptsAdd () function to onStart () but I don't know how to make it work. how to add onReceiptsAdd () to onStart () here is my code:

class ScanFragment : Fragment(), OnReceiptsItemAdd {
    private var _binding: FragmentScanBinding? = null
    private val binding get() = _binding!!

    private val scanVm by viewModels<ScanViewModel>()
    private val adapter = ReceiptsAdapter(this)

    private val SCAN_DEBUG = "SCAN_DEBUG"

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        _binding = FragmentScanBinding.inflate(inflater, container, false)
        // Inflate the layout for this fragment
        return binding.root
    }
    override fun onStart() {
        super.onStart()

        val value = binding.etBlank.text?.trim().toString()
        val from = binding.etBlank.text?.trim().toString()
        val image = binding.etBlank.text?.trim().toString()
        val rootRef = FirebaseFirestore.getInstance()
        val usersRef = rootRef.collection("receipts")
        val auth = FirebaseAuth.getInstance()
        auth.currentUser?.apply {
            usersRef.document(uid).set(mapOf(
                "id" to uid,
                "from" to from,
                "value" to value,
                "image" to image,
            )).addOnCompleteListener { task ->
                if (task.isSuccessful) {
                    Log.d("TAG", "User successfully added.")
                } else {
                    Log.d("TAG", task.exception!!.message!!)
                }
            }
        }
    }
    override fun onReceiptsAdd(receipts: dataReceipts, position: Int) {
        scanVm.addFavReceipt(receipts)
    }
}
MaksChojniak1
  • 35
  • 1
  • 6

0 Answers0