setup of the basic structure of the project with boiler plate code
This commit is contained in:
11
app/src/main/java/com/example/refactoredapp/MyApplication.kt
Normal file
11
app/src/main/java/com/example/refactoredapp/MyApplication.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.example.refactoredapp
|
||||
|
||||
import android.app.Application
|
||||
import com.example.refactoredapp.data.model.SampleDetails
|
||||
|
||||
class MyApplication : Application() {
|
||||
|
||||
private val sampleDetails = SampleDetails("Change it later");
|
||||
fun getSampleDetails() : SampleDetails = sampleDetails
|
||||
// fun setSampleDetails(sample: SampleDetails) {sampleDetails = sample}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.refactoredapp.data
|
||||
|
||||
object Constants {
|
||||
const val ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.refactoredapp.data
|
||||
|
||||
object DataHolder {
|
||||
var isStoragePermissionGranted = false
|
||||
var isAppFolderCreated = false
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.refactoredapp.data
|
||||
|
||||
import com.example.refactoredapp.data.model.TestInfo
|
||||
import java.io.File
|
||||
|
||||
interface Repository {
|
||||
suspend fun saveToDatabase(info: TestInfo)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.refactoredapp.data
|
||||
|
||||
import com.example.refactoredapp.data.model.TestInfo
|
||||
|
||||
class RepositoryImpl : Repository {
|
||||
|
||||
override suspend fun saveToDatabase(info: TestInfo) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.refactoredapp.data.model
|
||||
|
||||
data class DenovixData(
|
||||
val serialNumber: Int,
|
||||
val nameSample: String,
|
||||
val ratio: Double,
|
||||
val result: String
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.refactoredapp.data.model
|
||||
|
||||
enum class DeviceType {
|
||||
Denovix,
|
||||
TestRight
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.refactoredapp.data.model
|
||||
|
||||
data class SampleDetails(
|
||||
val sampleName: String
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.refactoredapp.data.model
|
||||
|
||||
data class TestInfo(
|
||||
val value: String,
|
||||
val number1: String,
|
||||
val number2: String,
|
||||
val device: DeviceType,
|
||||
val result: String,
|
||||
val resultConfirmatory: String,
|
||||
val directoryPath: String,
|
||||
val fullPath: String
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.refactoredapp.domain
|
||||
|
||||
import java.io.File
|
||||
|
||||
interface ParseCSV {
|
||||
fun parseCSV(file: File)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.refactoredapp.domain
|
||||
|
||||
import com.opencsv.CSVReader
|
||||
import java.io.*
|
||||
|
||||
class ParseDenovixUseCase : ParseCSV {
|
||||
|
||||
override fun parseCSV(file: File) {
|
||||
val reader = CSVReader(FileReader(file))
|
||||
var line: Array<String?>
|
||||
val inputStream: InputStream = FileInputStream(file)
|
||||
val br = BufferedReader(InputStreamReader(inputStream))
|
||||
val header: Array<String> = reader.readNext()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.refactoredapp.domain
|
||||
|
||||
import com.opencsv.CSVReader
|
||||
import java.io.*
|
||||
|
||||
class ParseTestRightCSVUseCase : ParseCSV {
|
||||
|
||||
override fun parseCSV(file: File){
|
||||
val reader = CSVReader(FileReader(file))
|
||||
var line: Array<String?>
|
||||
val inputStream: InputStream = FileInputStream(file)
|
||||
val br = BufferedReader(InputStreamReader(inputStream))
|
||||
val header: Array<String> = reader.readNext()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +1,162 @@
|
||||
package com.example.refactoredapp.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.data.Constants
|
||||
import com.example.refactoredapp.databinding.ActivityMainBinding
|
||||
import com.example.refactoredapp.presentation.TestRight.TestRightActivity
|
||||
import com.example.refactoredapp.util.MyUtils
|
||||
import com.example.refactoredapp.util.MyViewModelFactory
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialPort
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
import com.hoho.android.usbserial.util.SerialInputOutputManager
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
class MainActivity : AppCompatActivity()
|
||||
// , SerialInputOutputManager.Listener
|
||||
{
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var viewModel: MainViewModel
|
||||
|
||||
private val TAG = "MainActivity"
|
||||
// private lateinit var usbSerialPort: UsbSerialPort
|
||||
// private val WRITE_WAIT_MILLIS = 5000
|
||||
|
||||
// private val TAG = "Surya"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
viewModel = ViewModelProvider(this)[MainViewModel::class.java]
|
||||
setDropDownMenu()
|
||||
}
|
||||
|
||||
private fun setDropDownMenu() {
|
||||
val adapter = ArrayAdapter.createFromResource(
|
||||
viewModel = ViewModelProvider(
|
||||
this,
|
||||
R.array.instrument, android.R.layout.simple_spinner_item
|
||||
)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
binding.spinnerDevice.adapter = adapter
|
||||
binding.spinnerDevice.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(
|
||||
parent: AdapterView<*>,
|
||||
p1: View?,
|
||||
position: Int,
|
||||
p3: Long
|
||||
) {
|
||||
viewModel.device = parent.getItemAtPosition(position).toString()
|
||||
}
|
||||
MyViewModelFactory(applicationContext)
|
||||
)[MainViewModel::class.java]
|
||||
|
||||
override fun onNothingSelected(p0: AdapterView<*>?) {}
|
||||
}
|
||||
|
||||
// setupObservers()
|
||||
setupListeners()
|
||||
|
||||
// getUSBData()
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
|
||||
binding.cvItem1.setOnClickListener {
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
binding.cvItem2.setOnClickListener {
|
||||
Toast.makeText(this, "To be Implemented", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
|
||||
// binding.confirmatory.setOnClickListener {
|
||||
// val usbIoManager = SerialInputOutputManager(usbSerialPort, this)
|
||||
// object : SerialInputOutputManager.Listener {
|
||||
//
|
||||
// override fun onNewData(data: ByteArray?) {
|
||||
// Log.d(TAG, "onNewData callback called")
|
||||
// data?.let {
|
||||
// val str: String = String(data, StandardCharsets.UTF_8)
|
||||
// Log.d(TAG, "DATA FROM DEVICE IS : $str")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onRunError(e: Exception?) {
|
||||
// Log.d(TAG, "ERORRRRR -> $e")
|
||||
// }
|
||||
// })
|
||||
|
||||
// usbIoManager.start()
|
||||
// usbSerialPort.write("print\r".toByteArray(), WRITE_WAIT_MILLIS);
|
||||
// }
|
||||
}
|
||||
|
||||
// private fun getUSBData() {
|
||||
// val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
||||
// val availableDrivers: List<UsbSerialDriver> =
|
||||
// UsbSerialProber.getDefaultProber().findAllDrivers(manager)
|
||||
// if (availableDrivers.isEmpty()) {
|
||||
// Log.d(TAG, "No device Connected")
|
||||
// } else {
|
||||
// val driver: UsbSerialDriver = availableDrivers[0]
|
||||
// val connection = manager.openDevice(driver.device)
|
||||
// if (connection == null) {
|
||||
// requestUserPermission(manager, driver.device)
|
||||
// }
|
||||
//
|
||||
// usbSerialPort = driver.ports[0]
|
||||
// usbSerialPort.open(connection)
|
||||
// usbSerialPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
||||
// }
|
||||
// }
|
||||
|
||||
/*
|
||||
* Request user permission. The response will be received in the BroadcastReceiver
|
||||
*/
|
||||
// private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
// Log.d(
|
||||
// TAG,
|
||||
// String.format("requestUserPermission(%X:%X)", device.vendorId, device.productId)
|
||||
// )
|
||||
// val mPendingIntent = PendingIntent.getBroadcast(
|
||||
// this,
|
||||
// 0,
|
||||
// Intent(Constants.ACTION_USB_PERMISSION),
|
||||
// 0
|
||||
// )
|
||||
// manager.requestPermission(device, mPendingIntent)
|
||||
// }
|
||||
|
||||
private fun setupObservers() {
|
||||
// viewModel.isStoragePermission.observe(this) {
|
||||
// if (it) {
|
||||
// createFolder()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
// override fun onNewData(data: ByteArray?) {
|
||||
//// Log.d(TAG, "onNewData callback called")
|
||||
// data?.let {
|
||||
// val str: String = String(data, StandardCharsets.UTF_8)
|
||||
// Log.d(TAG, "DATA FROM DEVICE IS : $str")
|
||||
// }
|
||||
// }
|
||||
|
||||
// override fun onRunError(e: Exception?) {
|
||||
// Log.d(TAG, "ERORRRRR -> $e")
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,8 +1,25 @@
|
||||
package com.example.refactoredapp.presentation
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.refactoredapp.data.model.DenovixData
|
||||
import com.example.refactoredapp.data.model.DeviceType
|
||||
import com.example.refactoredapp.domain.ParseCSV
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
class MainViewModel(private val parseDenovix: ParseCSV, private val parseTestRight: ParseCSV) : ViewModel() {
|
||||
|
||||
var device = ""
|
||||
var device = DeviceType.TestRight
|
||||
var isStoragePermission = MutableLiveData<Boolean>(false)
|
||||
|
||||
val resultsLiveData = MutableLiveData<ArrayList<DenovixData>>()
|
||||
|
||||
fun parseCSV(file: File){
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
parseDenovix.parseCSV(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.example.refactoredapp.presentation
|
||||
|
||||
import com.example.refactoredapp.data.model.DenovixData
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.refactoredapp.R
|
||||
|
||||
class RVAdapter : RecyclerView.Adapter<RVAdapter.ViewHolder>() {
|
||||
|
||||
private val dataset = ArrayList<DenovixData>()
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.table_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataset.size
|
||||
}
|
||||
|
||||
fun updateDataSet(newDataSet: ArrayList<DenovixData>) {
|
||||
dataset.clear()
|
||||
dataset.addAll(newDataSet)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.example.refactoredapp.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.data.DataHolder
|
||||
import com.example.refactoredapp.databinding.ActivitySplashBinding
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Splash Activity
|
||||
* Used for preprocessing of data, permissions
|
||||
*/
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivitySplashBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySplashBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
checkForPermissions()
|
||||
}
|
||||
|
||||
private fun checkForPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
getPermissionsAboveAndroidR()
|
||||
} else {
|
||||
getPermissionsBelowAndroidR()
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun getPermissionsAboveAndroidR() {
|
||||
// Checking if permission is already granted or not.
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
val storagePermissionResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = false
|
||||
Toast.makeText(
|
||||
this,
|
||||
"You must grant permission to storage to use the app",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
val intent = Intent()
|
||||
intent.action = Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
|
||||
intent.data = Uri.fromParts("package", this.packageName, null)
|
||||
storagePermissionResultLauncher.launch(intent)
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPermissionsBelowAndroidR() {
|
||||
val requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
|
||||
if (isGranted) {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = false
|
||||
Toast.makeText(
|
||||
this,
|
||||
"You must grant permission to storage to use the app",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveToLandingPage() {
|
||||
createAppFolder()
|
||||
val i = Intent(applicationContext, MainActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
private fun createAppFolder() {
|
||||
val file = File(
|
||||
Environment.getExternalStorageDirectory().absolutePath + "/" + resources.getString(R.string.app_name) + "/"
|
||||
)
|
||||
if (!file.exists()) {
|
||||
if (!file.mkdirs()) {
|
||||
Toast.makeText(this, "Problem creating folder", Toast.LENGTH_SHORT).show()
|
||||
DataHolder.isAppFolderCreated = false
|
||||
} else {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
}
|
||||
} else {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.refactoredapp.presentation.TestRight
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.databinding.ActivityMainBinding
|
||||
import com.example.refactoredapp.databinding.ActivityTestRightBinding
|
||||
import com.example.refactoredapp.util.MyViewModelFactory
|
||||
|
||||
class TestRightActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityTestRightBinding
|
||||
private lateinit var viewModel: TestRightViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityTestRightBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
viewModel = ViewModelProvider(this, MyViewModelFactory(this.applicationContext))[TestRightViewModel::class.java]
|
||||
|
||||
if (!viewModel.isReferenceDone)
|
||||
supportFragmentManager.beginTransaction().replace(binding.flMain.id, TestRightExpReference()).commit()
|
||||
else
|
||||
supportFragmentManager.beginTransaction().replace(binding.flMain.id, TestRightExpSample()).commit()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.example.refactoredapp.presentation.TestRight
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.databinding.FragmentTestRightExpReferenceBinding
|
||||
import com.example.refactoredapp.databinding.FragmentTestRightResultsBinding
|
||||
|
||||
class TestRightExpReference : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentTestRightExpReferenceBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupListeners()
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.btnSetReference.setOnClickListener {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.example.refactoredapp.presentation.TestRight
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.databinding.FragmentTestRightExpReferenceBinding
|
||||
|
||||
class TestRightExpSample : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentTestRightExpReferenceBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.example.refactoredapp.presentation.TestRight
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.databinding.FragmentTestRightResultsBinding
|
||||
import com.example.refactoredapp.util.MyUtils
|
||||
|
||||
class TestRightResults : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightResultsBinding
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_test_right_results, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setDropDownMenu()
|
||||
}
|
||||
|
||||
// TODO: Incomplete
|
||||
fun setDropDownMenu() {
|
||||
val adapter = ArrayAdapter.createFromResource(
|
||||
requireContext(),
|
||||
R.array.instrument, android.R.layout.simple_spinner_item
|
||||
)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
// binding.spinnerDevice.adapter = adapter
|
||||
// binding.spinnerDevice.onItemSelectedListener =
|
||||
// object : AdapterView.OnItemSelectedListener {
|
||||
// override fun onItemSelected(
|
||||
// parent: AdapterView<*>,
|
||||
// p1: View?,
|
||||
// position: Int,
|
||||
// p3: Long
|
||||
// ) {
|
||||
// viewModel.device = MyUtils().getDeviceTypeFromString(
|
||||
// parent.getItemAtPosition(position).toString()
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// override fun onNothingSelected(p0: AdapterView<*>?) {}
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.refactoredapp.presentation.TestRight
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class TestRightViewModel : ViewModel() {
|
||||
|
||||
var isReferenceDone = false
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.refactoredapp.presentation.TestRight
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
|
||||
class UsbService : Service() {
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
TODO("Return the communication channel to the service.")
|
||||
}
|
||||
}
|
||||
16
app/src/main/java/com/example/refactoredapp/util/MyUtils.kt
Normal file
16
app/src/main/java/com/example/refactoredapp/util/MyUtils.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.example.refactoredapp.util
|
||||
|
||||
import com.example.refactoredapp.R
|
||||
import com.example.refactoredapp.data.model.DeviceType
|
||||
|
||||
class MyUtils {
|
||||
|
||||
fun getDeviceTypeFromString(deviceName: String) : DeviceType {
|
||||
return if (deviceName == "TestRight"){
|
||||
DeviceType.TestRight
|
||||
} else {
|
||||
DeviceType.Denovix
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.refactoredapp.util
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.refactoredapp.data.RepositoryImpl
|
||||
import com.example.refactoredapp.domain.ParseDenovixUseCase
|
||||
import com.example.refactoredapp.domain.ParseTestRightCSVUseCase
|
||||
import com.example.refactoredapp.presentation.MainActivity
|
||||
import com.example.refactoredapp.presentation.MainViewModel
|
||||
import com.example.refactoredapp.presentation.TestRight.TestRightActivity
|
||||
import com.example.refactoredapp.presentation.TestRight.TestRightViewModel
|
||||
|
||||
class MyViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
|
||||
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(MainViewModel::class.java))
|
||||
return MainViewModel(ParseDenovixUseCase(), ParseTestRightCSVUseCase()) as T
|
||||
else if (modelClass.isAssignableFrom(TestRightViewModel::class.java))
|
||||
return TestRightViewModel() as T
|
||||
else
|
||||
throw IllegalArgumentException("Unknown ViewModel class");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user