Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import org.phenoapps.intercross.util.BluetoothUtil
import org.phenoapps.intercross.util.Dialogs
import org.phenoapps.intercross.util.FileUtil
import org.phenoapps.intercross.util.KeyUtil
import org.phenoapps.intercross.util.VibrateUtil
import org.phenoapps.intercross.util.observeOnce
import javax.inject.Inject

Expand All @@ -55,14 +56,14 @@ class EventDetailFragment:
IntercrossBaseFragment<FragmentEventDetailBinding>(R.layout.fragment_event_detail),
MetadataManager {

private val requestBluetoothPermissions = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { granted ->
@Inject
lateinit var vibrateUtil: VibrateUtil

granted?.let { grant ->
private val requestBluetoothPermissions = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { granted ->

if (grant.filter { it.value == false }.isNotEmpty()) {
if (granted.filter { !it.value }.isNotEmpty()) {

Toast.makeText(context, R.string.error_no_bluetooth_permission, Toast.LENGTH_SHORT).show()
}
Toast.makeText(context, R.string.error_no_bluetooth_permission, Toast.LENGTH_SHORT).show()
}
}

Expand Down Expand Up @@ -401,7 +402,7 @@ class EventDetailFragment:
private fun startPrintProcess() {
context?.let { ctx ->

var permit = true
var permit = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED
&& ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
Expand All @@ -412,7 +413,7 @@ class EventDetailFragment:
android.Manifest.permission.BLUETOOTH_CONNECT
))
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
} else
if (ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED
&& ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_ADMIN) == PackageManager.PERMISSION_GRANTED) {
permit = true
Expand All @@ -422,12 +423,12 @@ class EventDetailFragment:
android.Manifest.permission.BLUETOOTH_ADMIN
))
}
}

if (permit) {

BluetoothUtil().print(requireContext(), arrayOf(mEvent))
BluetoothUtil().print(ctx, arrayOf(mEvent))

vibrateUtil.vibrate()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.phenoapps.intercross.databinding.FragmentImportZplBinding
import org.phenoapps.intercross.util.KeyUtil
import java.io.InputStreamReader
import javax.inject.Inject
import androidx.core.content.edit

@AndroidEntryPoint
class ImportZPLFragment : IntercrossBaseFragment<FragmentImportZplBinding>(R.layout.fragment_import_zpl) {
Expand All @@ -29,7 +30,10 @@ class ImportZPLFragment : IntercrossBaseFragment<FragmentImportZplBinding>(R.lay

mBinding.codeTextView.text = text

mPref.edit().putString(mKeyUtil.zplCodeKey, text).apply()
mPref.edit {
putString(mKeyUtil.zplTemplateKey, context?.getString(R.string.none) ?: "None")
putString(mKeyUtil.zplCodeKey, text)
}

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.phenoapps.intercross.fragments

import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Build
Expand Down Expand Up @@ -42,6 +43,7 @@ import org.phenoapps.intercross.util.BluetoothUtil
import org.phenoapps.intercross.util.Dialogs
import org.phenoapps.intercross.util.ImportUtil
import org.phenoapps.intercross.util.KeyUtil
import org.phenoapps.intercross.util.VibrateUtil
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -50,12 +52,9 @@ class ParentsFragment: IntercrossBaseFragment<FragmentParentsBinding>(R.layout.f

private val requestBluetoothPermissions = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { granted ->

granted?.let { grant ->
if (granted.filter { !it.value }.isNotEmpty()) {

if (grant.filter { it.value == false }.isNotEmpty()) {

Toast.makeText(context, R.string.error_no_bluetooth_permission, Toast.LENGTH_SHORT).show()
}
Toast.makeText(context, R.string.error_no_bluetooth_permission, Toast.LENGTH_SHORT).show()
}
}

Expand All @@ -75,6 +74,9 @@ class ParentsFragment: IntercrossBaseFragment<FragmentParentsBinding>(R.layout.f
ParentsListViewModelFactory(ParentsRepository.getInstance(db.parentsDao()))
}

@Inject
lateinit var vibrateUtil: VibrateUtil

@Inject
lateinit var mPref: SharedPreferences

Expand Down Expand Up @@ -425,44 +427,6 @@ class ParentsFragment: IntercrossBaseFragment<FragmentParentsBinding>(R.layout.f
}
}

private fun checkBluetoothRuntimePermission(): Boolean {

var permit = true

context?.let { ctx ->

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED
&& ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
) {
permit = true
} else {
requestBluetoothPermissions.launch(
arrayOf(
android.Manifest.permission.BLUETOOTH_SCAN,
android.Manifest.permission.BLUETOOTH_CONNECT
)
)
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED
&& ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_ADMIN) == PackageManager.PERMISSION_GRANTED
) {
permit = true
} else {
requestBluetoothPermissions.launch(
arrayOf(
android.Manifest.permission.BLUETOOTH,
android.Manifest.permission.BLUETOOTH_ADMIN
)
)
}
}
}

return permit
}

private fun FragmentParentsBinding.setupBottomNavBar() {

bottomNavBar.setOnNavigationItemSelectedListener { item ->
Expand Down Expand Up @@ -494,37 +458,65 @@ class ParentsFragment: IntercrossBaseFragment<FragmentParentsBinding>(R.layout.f
}
}

private fun FragmentParentsBinding.printParents() {
private fun FragmentParentsBinding.requestPermissionAndPrintParents() {

if (tabLayout.getTabAt(0)?.isSelected == true) {
context?.let { ctx ->

val outParents = mFemaleAdapter.currentList.filterIsInstance(Parent::class.java)
var permit = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED
&& ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
permit = true
} else {
requestBluetoothPermissions.launch(arrayOf(
android.Manifest.permission.BLUETOOTH_SCAN,
android.Manifest.permission.BLUETOOTH_CONNECT
))
}
} else
if (ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED
&& ctx.checkSelfPermission(android.Manifest.permission.BLUETOOTH_ADMIN) == PackageManager.PERMISSION_GRANTED) {
permit = true
} else {
requestBluetoothPermissions.launch(arrayOf(
android.Manifest.permission.BLUETOOTH,
android.Manifest.permission.BLUETOOTH_ADMIN
))
}

if (permit) {
printParents(ctx)
}
}
}

private fun FragmentParentsBinding.printParents(ctx: Context) {

val outParents: List<Parent> = if (tabLayout.getTabAt(0)?.isSelected == true) {

mFemaleAdapter.currentList.filterIsInstance<Parent>()

} else {

val outParents = mMaleAdapter.currentList
.filterIsInstance<Parent>()

outParents + mMaleAdapter.currentList
.filterIsInstance<PollenGroup>()
.map { group -> Parent(group.codeId, 1, group.name)}
}

if (outParents.isNotEmpty()) {

BluetoothUtil().print(
requireContext(),
ctx,
outParents.filter { p -> p.selected }.toTypedArray()
)

vibrateUtil.vibrate()
}
}

// override fun onCreate(savedInstanceState: Bundle?) {
//
// } else {
//
// val outParents = mMaleAdapter.currentList
// .filterIsInstance(Parent::class.java)
// .filter { p -> p.selected }
//
// val outAll = outParents + mMaleAdapter.currentList
// .filterIsInstance(PollenGroup::class.java)
// .filter { p -> p.selected }
// .map { group -> Parent(group.codeId, 1, group.name) }
//
// BluetoothUtil().print(requireContext(), outAll.toTypedArray())
//
// }
// }

override fun onResume() {
super.onResume()

Expand All @@ -545,7 +537,7 @@ class ParentsFragment: IntercrossBaseFragment<FragmentParentsBinding>(R.layout.f
}

R.id.action_parents_print -> {
mBinding.printParents()
mBinding.requestPermissionAndPrintParents()
}

android.R.id.home -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class BehaviorPreferencesFragment : BasePreferenceFragment(R.xml.behavior_prefer
settings?.let {
findPreference<Preference>(mKeyUtil.crossPatternKey)?.apply {
summary = when {
settings.isPattern -> "Pattern"
!settings.isUUID && !settings.isPattern -> "None"
else -> "UUID"
settings.isPattern -> context.getString(R.string.pattern)
!settings.isUUID && !settings.isPattern -> context.getString(R.string.none)
else -> context.getString(R.string.uuid)
}
}
}
Expand Down
Loading