Craete a history with data from different fragment

44 Views Asked by At

T User scans a receipt and the output is put in an editable Text, which the User can adjust if the OCR made a mistake.

I have a "confirm" button, on which the data from these editable Text fields should be taken and put into a new fragment called "History" which is supposed to be a table that simply stores the data for every new receipt that is scanned. With 3 simple rows "Total","Data","Store".

How to implement this functionality?

This is how it looks when you use the OCRTHis is what i want later in the History Tab

The code for my MainActivity which sets up the TabBar: class MainActivity : AppCompatActivity() {

private lateinit var viewPager: ViewPager
private lateinit var tabs: TabLayout

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    viewPager = findViewById(R.id.viewPager)
    tabs = findViewById(R.id.tabs)
    setUpTabs()
}

private fun setUpTabs(){
    val adapter = ViewPagerAdapter(supportFragmentManager)
    adapter.addFragment(HomeFragment(),"")
    adapter.addFragment(HistoryFragment(),"")
    adapter.addFragment(Scanner(),"")
    viewPager.adapter = adapter
    tabs.setupWithViewPager(viewPager)
    tabs.getTabAt(0)!!.setIcon(R.drawable.ic_baseline_home_24)
    tabs.getTabAt(1)!!.setIcon(R.drawable.ic_baseline_show_chart_24)
    tabs.getTabAt(2)!!.setIcon(R.drawable.ic_baseline_receipt_24)
}

In my fragment for the OCR this is the code for the Textrecognition and putting it in the TextView:

   private fun textRecognitionAction() {

    var text = ""
    receiptsViewModel.textDetector.process(mlkitImage)
        .addOnSuccessListener {
            pb.visibility = View.GONE
            for (block in it.textBlocks) text += block.text + "\n"
            val receipts = receiptsViewModel.getReceipts(text)
            editTotal.setText(receipts.total, TextView.BufferType.EDITABLE)
            editStore.setText(receipts.store, TextView.BufferType.EDITABLE)
            editDate.setText(receipts.date, TextView.BufferType.EDITABLE)

        }
}
0

There are 0 best solutions below