Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Qr Reader #229

Merged
merged 25 commits into from
May 5, 2022
Merged

Qr Reader #229

merged 25 commits into from
May 5, 2022

Conversation

MaximeZmt
Copy link
Owner

@MaximeZmt MaximeZmt commented May 2, 2022

Qr Reader

This is related to issue #221

This Pull Requests contains:

  • UserSearchActivity: Add of a button to go to QR Code Scan Activity
  • QrCodeActivity: QR code scanner that add friends

In addition the code is tested with a coverage of: [64.8]%

Notes for reviewers

  • Low coverage because impossible (very difficult) to mock the camera

}


/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method setupControls has 56 lines of code (exceeds 25 allowed). Consider refactoring.


binding.cameraSurfaceView.getHolder().addCallback(object : SurfaceHolder.Callback {
@SuppressLint("MissingPermission")
override fun surfaceCreated(holder: SurfaceHolder) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

format: Int,
width: Int,
height: Int
) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the body of surfaceChanged and surfaceCreated are identical, refactor may also boost the coverage

@@ -38,6 +44,14 @@ class SearchUserActivity : AppCompatActivity() {
searchEditText = findViewById(R.id.searchUserET)
searchForUsers("")

val buttonScan: FloatingActionButton = findViewById(R.id.searchUser_scanning)

buttonScan.setOnClickListener {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

val usersRepo: DataGetter = DataGetter()
var isTest: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method onCreate has 29 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be a good practice to break onCreate down into smaller functions.

}


/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method setupControls has 45 lines of code (exceeds 25 allowed). Consider refactoring.

* This section is related to the handler when code is detected
*/

private fun solveDetection(detections: Detector.Detections<Barcode>) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method solveDetection has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.

* This section is related to the handler when code is detected
*/

private fun solveDetection(detections: Detector.Detections<Barcode>) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method solveDetection has 26 lines of code (exceeds 25 allowed). Consider refactoring.

@MaximeZmt MaximeZmt marked this pull request as ready for review May 3, 2022 22:38
@MaximeZmt MaximeZmt changed the title Qr Reader first version Qr Reader May 3, 2022
@MaximeZmt MaximeZmt linked an issue May 3, 2022 that may be closed by this pull request
@MaximeZmt MaximeZmt self-assigned this May 3, 2022
var uidList: ArrayList<String> = ArrayList()
val usersRepo: DataGetter = DataGetter()

override fun onCreate(savedInstanceState: Bundle?) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method onCreate has 31 lines of code (exceeds 25 allowed). Consider refactoring.

}


/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method setupControls has 42 lines of code (exceeds 25 allowed). Consider refactoring.

@jiabaow jiabaow self-requested a review May 4, 2022 06:08
Copy link
Collaborator

@jiabaow jiabaow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I left some comments concerning breaking down large functions into multiple smaller functions and duplications.

if (extras != null) {
uidList = extras.get("uidList") as ArrayList<String>
isTest = extras.getBoolean("isTest", false)
}else{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else{
} else {

AnimationUtils.loadAnimation(this@QrScanningActivity, R.anim.qr_anim)
binding.barcodeLine.startAnimation(aniSlide)

if(isTest){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(isTest){
if (isTest) {

val usersRepo: DataGetter = DataGetter()
var isTest: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be a good practice to break onCreate down into smaller functions.

format: Int,
width: Int,
height: Int
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the body of surfaceChanged and surfaceCreated are identical, refactor may also boost the coverage

finish()
} else {
// Camera permission not granted, come back to previous activity
Toast.makeText(applicationContext, "Camera Permission should be granted for that feature", Toast.LENGTH_LONG).show()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use string.xml


barcodeDetector.setProcessor(object : Detector.Processor<Barcode> {
override fun release() {
Toast.makeText(applicationContext, "Scanner has been closed", Toast.LENGTH_SHORT).show()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use string.xml

/*
* This section is related to the handler when code is detected
*/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}
Toast.makeText(this@QrScanningActivity, "Congratulations, you have a new friends", Toast.LENGTH_SHORT).show()
endInt.putExtra("isSuccess", true)
}else{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else{
} else {

if (!isTest) {
usersRepo.setSubFieldValue(FireBaseAuthenticator.getCurrentUID(),"friends", scannedValue, true)
}
Toast.makeText(this@QrScanningActivity, "Congratulations, you have a new friends", Toast.LENGTH_SHORT).show()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Toast.makeText(this@QrScanningActivity, "Congratulations, you have a new friends", Toast.LENGTH_SHORT).show()
Toast.makeText(this@QrScanningActivity, "Congratulations, you have a new friend", Toast.LENGTH_SHORT).show()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.xml

@@ -136,7 +136,9 @@ class DataGetter @Inject constructor() {
* @param searchInput search text inputed by user
* @param callback function to call with found users by username
*/
fun searchByField(field: String, searchInput: String, callback:(ArrayList<User>) -> Unit) {
fun searchByField(field: String, searchInput: String, callback:(ArrayList<User>) -> Unit, callback2 :(ArrayList<String>) -> Unit) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to update the function documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe give callback and callback2 more meaningful names

Copy link
Collaborator

@kamilababayeva kamilababayeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have did a partial review. I wanna give it a second look later! thank you for the changes! The feature is cool and the moving bar in an old way is the best.

@MaximeZmt MaximeZmt added actual: 10h actual time to fix and removed actual: 8h labels May 4, 2022
}
}

/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method setupControls has 35 lines of code (exceeds 25 allowed). Consider refactoring.

if (!isTest) {
usersRepo.setSubFieldValue(FireBaseAuthenticator.getCurrentUID(),"friends", scannedValue, true)
}
Toast.makeText(this@QrScanningActivity, getString(R.string.qrScanning_newFriend), Toast.LENGTH_SHORT).show()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

Toast.makeText(this@QrScanningActivity, getString(R.string.qrScanning_newFriend), Toast.LENGTH_SHORT).show()
startActivityWExtra(Intent(this@QrScanningActivity, SearchUserActivity::class.java), "isSuccess", true)
} else {
Toast.makeText(this@QrScanningActivity, getString(R.string.qrScanning_noExistUid), Toast.LENGTH_SHORT).show()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.


barcodeDetector.setProcessor(object : Detector.Processor<Barcode> {
override fun release() {
Toast.makeText(applicationContext, getString(R.string.qrScanning_scannerClosed), Toast.LENGTH_SHORT).show()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

startActivityWExtra(Intent(this@QrScanningActivity, QrScanningActivity::class.java), "uidList", uidList)
} else {
// Camera permission not granted, come back to previous activity
Toast.makeText(applicationContext, getString(R.string.qrScanning_cameraError), Toast.LENGTH_LONG).show()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will having a function for toast solve the problem?

Copy link
Collaborator

@kamilababayeva kamilababayeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! thanks for a nice feature!

startActivityWExtra(Intent(this@QrScanningActivity, QrScanningActivity::class.java), "uidList", uidList)
} else {
// Camera permission not granted, come back to previous activity
Toast.makeText(applicationContext, getString(R.string.qrScanning_cameraError), Toast.LENGTH_LONG).show()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will having a function for toast solve the problem?

Copy link
Collaborator

@jiabaow jiabaow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but don't forget to change the string.xml

<string name="qrScanning_scannerClosed">Scanner has been closed</string>
<string name="qrScanning_cameraError">Camera Permission should be granted for that feature</string>
<string name="qrScanning_noExistUid">Error not an existing uid</string>
<string name="qrScanning_newFriend">Congratulations, you have a new friends</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="qrScanning_newFriend">Congratulations, you have a new friends</string>
<string name="qrScanning_newFriend">Congratulations, you have a new friend</string>

@codeclimate
Copy link

codeclimate bot commented May 5, 2022

Code Climate has analyzed commit a766e60 and detected 7 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3
Duplication 4

The test coverage on the diff in this pull request is 71.7% (80% is the threshold).

This pull request will bring the total coverage in the repository to 84.0% (0.0% change).

View more on Code Climate.

@MaximeZmt MaximeZmt merged commit 99d421e into main May 5, 2022
@MaximeZmt MaximeZmt deleted the maximezmt/qrreader branch May 5, 2022 08:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
actual: 10h actual time to fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

identify the QR code and add it to the user's friend list.(#220)
3 participants