Skip to content

Commit

Permalink
Merge pull request #80 from PhenoApps/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
trife authored Sep 29, 2021
2 parents 0d7fc81 + aa214b0 commit b7d2d5d
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 137 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
//link square api has minimum requirement of 21
minSdkVersion 21
targetSdkVersion 30
versionCode 5
versionName "1.1"
versionCode 6
versionName "1.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class DeviceViewModel @Inject constructor() : ViewModel() {
// }
// }

fun scan(context: Context) = liveData<List<LSFrame>> {
fun scan(context: Context) = liveData {

with (manager(context)) {

Expand All @@ -157,13 +157,12 @@ class DeviceViewModel @Inject constructor() : ViewModel() {

}

private suspend fun scan(ledFrames: Int, bulbFrames: Int) = withContext(sDeviceScope.coroutineContext) {
private val mFrames = ArrayList<LSFrame>()
private suspend fun scan(ledFrames: Int, bulbFrames: Int) = withContext<List<LSFrame>>(sDeviceScope.coroutineContext) {

val frames = ArrayList<LSFrame>()
sDevice?.Scan(ledFrames, bulbFrames, mFrames)

sDevice?.Scan(ledFrames, bulbFrames, frames)

return@withContext frames
return@withContext mFrames

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ class BarcodeSearchFragment : Fragment() {

mSamples.find { it.name == result.text.toString() }?.name?.let { name ->

findNavController().navigate(BarcodeSearchFragmentDirections
.actionToScanList(mExpId, name))

if (findNavController().currentDestination?.id == R.id.barcode_search_fragment) {
findNavController().navigate(BarcodeSearchFragmentDirections
.actionToScanList(mExpId, name))
}
}
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.view.ViewGroup
import androidx.appcompat.view.ContextThemeWrapper
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.WithFragmentBindings
import org.phenoapps.prospector.R
import org.phenoapps.prospector.databinding.FragmentConnectInstructionsBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import DATE_DESC
import android.os.Bundle
import android.view.*
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ContextThemeWrapper
import androidx.databinding.DataBindingUtil
Expand All @@ -26,7 +25,6 @@ import kotlinx.coroutines.launch
import org.phenoapps.prospector.R
import org.phenoapps.prospector.activities.MainActivity
import org.phenoapps.prospector.adapter.ExperimentAdapter
import org.phenoapps.prospector.adapter.SampleAdapter
import org.phenoapps.prospector.data.viewmodels.DeviceViewModel
import org.phenoapps.prospector.data.viewmodels.ExperimentViewModel
import org.phenoapps.prospector.databinding.FragmentExperimentListBinding
Expand Down Expand Up @@ -54,14 +52,18 @@ class ExperimentListFragment : Fragment(), CoroutineScope by MainScope() {
*/
private val sOnNewExpClick = View.OnClickListener {

findNavController().navigate(ExperimentListFragmentDirections
if (findNavController().currentDestination?.id == R.id.experiment_list_fragment) {
findNavController().navigate(ExperimentListFragmentDirections
.actionToNewExperiment())
}
}

private var mBinding: FragmentExperimentListBinding? = null

private var mSortState = ALPHA_ASC

private var mTimer: Timer? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

val contextThemeWrapper = ContextThemeWrapper(activity, R.style.AppTheme)
Expand All @@ -76,6 +78,8 @@ class ExperimentListFragment : Fragment(), CoroutineScope by MainScope() {

ui.setupToolbar()

startTimer()

setupButtons()

updateUi()
Expand Down Expand Up @@ -125,8 +129,10 @@ class ExperimentListFragment : Fragment(), CoroutineScope by MainScope() {

} else {

findNavController().navigate(ExperimentListFragmentDirections
.actionToConnectInstructions())
if (findNavController().currentDestination?.id == R.id.experiment_list_fragment) {
findNavController().navigate(ExperimentListFragmentDirections
.actionToConnectInstructions())
}

(activity as? MainActivity)?.startDeviceConnection()
}
Expand Down Expand Up @@ -220,6 +226,9 @@ class ExperimentListFragment : Fragment(), CoroutineScope by MainScope() {

mBinding?.recyclerView?.adapter?.notifyItemRangeChanged(0, it.size)
})
}

private fun startTimer() {

//use the activity view model to access the current connection status
val check = object : TimerTask() {
Expand All @@ -228,24 +237,33 @@ class ExperimentListFragment : Fragment(), CoroutineScope by MainScope() {

activity?.runOnUiThread {

with(mBinding?.experimentToolbar) {
if (isAdded) {
with(mBinding?.experimentToolbar) {

this?.menu?.findItem(R.id.action_connection)
?.setIcon(
if (sDeviceViewModel.isConnected()) R.drawable.ic_vector_link
else R.drawable.ic_vector_difference_ab
)
this?.menu?.findItem(R.id.action_connection)
?.setIcon(
if (sDeviceViewModel.isConnected()) R.drawable.ic_vector_link
else R.drawable.ic_vector_difference_ab
)

}
}
}
}
}

Timer().cancel()
mTimer = Timer()

mTimer?.scheduleAtFixedRate(check, 0, 1500)
}

override fun onDestroy() {
super.onDestroy()

Timer().purge()
mTimer?.cancel()

Timer().scheduleAtFixedRate(check, 0, 1500)
mTimer?.purge()

mTimer = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.phenoapps.prospector.data.models.Sample
import org.phenoapps.prospector.data.viewmodels.SampleViewModel
import org.phenoapps.prospector.databinding.FragmentNewSampleBinding
import org.phenoapps.prospector.utils.Dialogs
import org.phenoapps.prospector.utils.SnackbarQueue
import org.phenoapps.prospector.utils.observeOnce
import java.lang.IllegalStateException
import java.util.*
Expand All @@ -49,6 +48,8 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {
arguments?.getString("note")
}

private var mTimer: Timer? = null

private val sOnBarcodeScanClick = View.OnClickListener {

setFragmentResultListener("BarcodeResult") { _, bundle ->
Expand All @@ -59,9 +60,10 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {

}

findNavController().navigate(NewSampleFragmentDirections
if (findNavController().currentDestination?.id == R.id.new_sample_fragment) {
findNavController().navigate(NewSampleFragmentDirections
.actionToBarcodeScanner())

}
}


Expand Down Expand Up @@ -96,6 +98,8 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {

setupButtons()

startTimer()

binding.setupToolbar()

//possible arguments sent if the sample is being edited
Expand Down Expand Up @@ -213,9 +217,11 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {

if (it) {

findNavController()
.navigate(NewSampleFragmentDirections
.actionToScanList(mExpId, name))
if (findNavController().currentDestination?.id == R.id.new_sample_fragment) {
findNavController()
.navigate(NewSampleFragmentDirections
.actionToScanList(mExpId, name))
}

} else {

Expand All @@ -236,7 +242,7 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {
}
}

private fun startObservers() {
private fun startTimer() {

//use the activity view model to access the current connection status
val check = object : TimerTask() {
Expand All @@ -245,23 +251,26 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {

activity?.runOnUiThread {

with (activity as? MainActivity) {
mBinding?.fragNewSampleToolbar?.menu?.findItem(R.id.action_connection)
?.setIcon(if (this?.sDeviceViewModel?.isConnected() == true){
attachDeviceButtonPressListener()
R.drawable.ic_vector_link
}
else R.drawable.ic_vector_difference_ab)
if (isAdded) {
with (activity as? MainActivity) {
mBinding?.fragNewSampleToolbar?.menu?.findItem(R.id.action_connection)
?.setIcon(if (this?.sDeviceViewModel?.isConnected() == true){
attachDeviceButtonPressListener()
R.drawable.ic_vector_link
}
else R.drawable.ic_vector_difference_ab)
}
}
}
}
}

Timer().cancel()
mTimer = Timer()

Timer().purge()
mTimer?.scheduleAtFixedRate(check, 0, 1500)
}

Timer().scheduleAtFixedRate(check, 0, 1500)
private fun startObservers() {

//set the title header
sViewModel.experiments.observe(viewLifecycleOwner, { experiments ->
Expand Down Expand Up @@ -297,9 +306,11 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {
sDeviceViewModel.reset()
} else {

findNavController().navigate(
NewSampleFragmentDirections
.actionToConnectInstructions())
if (findNavController().currentDestination?.id == R.id.new_sample_fragment) {
findNavController().navigate(
NewSampleFragmentDirections
.actionToConnectInstructions())
}

this?.startDeviceConnection()
}
Expand Down Expand Up @@ -332,13 +343,15 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {

(act as MainActivity).notify("$newSampleString $name")

if (startScan) {
if (findNavController().currentDestination?.id == R.id.new_sample_fragment) {
if (startScan) {

findNavController().navigate(NewSampleFragmentDirections
.actionToScanList(mExpId, name, startScan))
findNavController().navigate(NewSampleFragmentDirections
.actionToScanList(mExpId, name, startScan))

} else findNavController().navigate(NewSampleFragmentDirections
.actionToScanList(mExpId, name))
} else findNavController().navigate(NewSampleFragmentDirections
.actionToScanList(mExpId, name))
}
}
}
}
Expand Down Expand Up @@ -369,4 +382,14 @@ class NewSampleFragment : Fragment(), CoroutineScope by MainScope() {

mBinding?.onBarcodeScanClick = sOnBarcodeScanClick
}

override fun onDestroy() {
super.onDestroy()

mTimer?.cancel()

mTimer?.purge()

mTimer = null
}
}
Loading

0 comments on commit b7d2d5d

Please sign in to comment.