Skip to content

Commit

Permalink
Merge pull request #18 from dmitriy-ilchenko/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wewewe718 authored Sep 15, 2020
2 parents 03574e9 + 1d63496 commit 5a100aa
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 1.3
* Add German translation
* Improve continuous scanning
* Rename "Open links automatically" to "Open content automatically"
* Bug fix: storage permission was not requested before saving a barcode and exporting barcode history
* Bug fix: vibration didn't work on some devices

## 1.2
* Support OTP (One time password) QR codes
* Decrease app size
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ android {
applicationId "com.example.barcodescanner"
minSdkVersion 21
targetSdkVersion 29
versionCode 4
versionName "1.2"
versionCode 5
versionName "1.3"
multiDexEnabled true
vectorDrawables.useSupportLibrary true
resConfigs "en", "ru"
resConfigs "en", "ru", "de"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/barcodescanner/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.example.barcodescanner

import android.os.StrictMode
import android.os.StrictMode.VmPolicy
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDexApplication
import com.example.barcodescanner.di.settings
import com.example.barcodescanner.usecase.Logger
import io.reactivex.plugins.RxJavaPlugins

class App : MultiDexApplication() {
Expand All @@ -22,7 +22,7 @@ class App : MultiDexApplication() {

private fun handleUnhandledRxJavaErrors() {
RxJavaPlugins.setErrorHandler { error ->
error.printStackTrace()
Logger.log(error)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.barcodescanner.extension

import com.example.barcodescanner.model.Barcode
import com.google.zxing.Result

fun Result.equalTo(barcode: Barcode?): Boolean {
return barcodeFormat == barcode?.format && text == barcode?.text
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,27 @@ class BarcodeActivity : BaseActivity(), DeleteConfirmationDialogFragment.Listene
copyToClipboard(barcode.text)
}

if (settings.openLinksAutomatically.not()) {
if (settings.openLinksAutomatically.not() || isCreated) {
return
}

when (barcode.schema) {
BarcodeSchema.APP -> openInGooglePlay()
BarcodeSchema.YOUTUBE -> openInYoutube()
BarcodeSchema.BOOKMARK -> saveBookmark()
BarcodeSchema.CRYPTOCURRENCY -> openBitcoinUrl()
BarcodeSchema.EMAIL -> sendEmail(barcode.email)
BarcodeSchema.GEO -> showLocation()
BarcodeSchema.GOOGLE_MAPS -> showLocation()
BarcodeSchema.MMS -> sendSmsOrMms(barcode.phone)
BarcodeSchema.MECARD -> addToContacts()
BarcodeSchema.OTP_AUTH -> openOtpInOtherApp()
BarcodeSchema.PHONE -> callPhone(barcode.phone)
BarcodeSchema.SMS -> sendSmsOrMms(barcode.phone)
BarcodeSchema.URL -> openLink()
BarcodeSchema.VEVENT -> addToCalendar()
BarcodeSchema.VCARD -> addToContacts()
BarcodeSchema.WIFI -> connectToWifi()
BarcodeSchema.YOUTUBE -> openInYoutube()
else -> return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class OtpActivity : BaseActivity() {
showOtp()
}

override fun onDestroy() {
super.onDestroy()
disposable.clear()
}

private fun enableSecurity() {
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_save_barcode_as_image.*

class SaveBarcodeAsImageActivity : BaseActivity() {

companion object {
private const val REQUEST_PERMISSIONS_CODE = 101
private val PERMISSIONS = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)
Expand Down Expand Up @@ -58,6 +59,11 @@ class SaveBarcodeAsImageActivity : BaseActivity() {
}
}

override fun onDestroy() {
super.onDestroy()
disposable.clear()
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.barcodescanner.feature.barcode.save

import android.Manifest
import android.content.Context
import android.content.Intent
import android.os.Bundle
Expand All @@ -8,6 +9,7 @@ import android.widget.Toast
import androidx.core.view.isVisible
import com.example.barcodescanner.R
import com.example.barcodescanner.di.barcodeSaver
import com.example.barcodescanner.di.permissionsHelper
import com.example.barcodescanner.extension.applySystemWindowInsets
import com.example.barcodescanner.extension.showError
import com.example.barcodescanner.extension.unsafeLazy
Expand All @@ -22,6 +24,9 @@ import kotlinx.android.synthetic.main.activity_save_barcode_as_text.*
class SaveBarcodeAsTextActivity : BaseActivity() {

companion object {
private const val REQUEST_PERMISSIONS_CODE = 101
private val PERMISSIONS = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)

private const val BARCODE_KEY = "BARCODE_KEY"

fun start(context: Context, barcode: Barcode) {
Expand All @@ -47,6 +52,17 @@ class SaveBarcodeAsTextActivity : BaseActivity() {
initSaveButton()
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (permissionsHelper.areAllPermissionsGranted(grantResults)) {
saveBarcode()
}
}

override fun onDestroy() {
super.onDestroy()
disposable.clear()
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}
Expand All @@ -67,10 +83,14 @@ class SaveBarcodeAsTextActivity : BaseActivity() {

private fun initSaveButton() {
button_save.setOnClickListener {
saveBarcode()
requestPermissions()
}
}

private fun requestPermissions() {
permissionsHelper.requestPermissions(this, PERMISSIONS, REQUEST_PERMISSIONS_CODE)
}

private fun saveBarcode() {
val saveFunc = when (spinner_save_as.selectedItemPosition) {
0 -> barcodeSaver::saveBarcodeAsCsv
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.barcodescanner.feature.tabs.history.export

import android.Manifest
import android.content.Context
import android.content.Intent
import android.os.Bundle
Expand All @@ -10,6 +11,7 @@ import androidx.core.widget.addTextChangedListener
import com.example.barcodescanner.R
import com.example.barcodescanner.di.barcodeDatabase
import com.example.barcodescanner.di.barcodeSaver
import com.example.barcodescanner.di.permissionsHelper
import com.example.barcodescanner.extension.applySystemWindowInsets
import com.example.barcodescanner.extension.isNotBlank
import com.example.barcodescanner.extension.showError
Expand All @@ -25,6 +27,9 @@ class ExportHistoryActivity : BaseActivity() {
private val disposable = CompositeDisposable()

companion object {
private const val REQUEST_PERMISSIONS_CODE = 101
private val PERMISSIONS = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)

fun start(context: Context) {
val intent = Intent(context, ExportHistoryActivity::class.java)
context.startActivity(intent)
Expand All @@ -41,6 +46,17 @@ class ExportHistoryActivity : BaseActivity() {
initExportButton()
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (permissionsHelper.areAllPermissionsGranted(grantResults)) {
exportHistory()
}
}

override fun onDestroy() {
super.onDestroy()
disposable.clear()
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}
Expand All @@ -67,10 +83,14 @@ class ExportHistoryActivity : BaseActivity() {

private fun initExportButton() {
button_export.setOnClickListener {
exportHistory()
requestPermissions()
}
}

private fun requestPermissions() {
permissionsHelper.requestPermissions(this, PERMISSIONS, REQUEST_PERMISSIONS_CODE)
}

private fun exportHistory() {
val fileName = edit_text_file_name.textString
val saveFunc = when (spinner_export_as.selectedItemPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import androidx.fragment.app.Fragment
import com.budiyev.android.codescanner.*
import com.example.barcodescanner.R
import com.example.barcodescanner.di.*
import com.example.barcodescanner.extension.applySystemWindowInsets
import com.example.barcodescanner.extension.showError
import com.example.barcodescanner.extension.vibrateOnce
import com.example.barcodescanner.extension.vibrator
import com.example.barcodescanner.extension.*
import com.example.barcodescanner.feature.barcode.BarcodeActivity
import com.example.barcodescanner.feature.common.dialog.ConfirmBarcodeDialogFragment
import com.example.barcodescanner.feature.tabs.scan.file.ScanBarcodeFromFileActivity
Expand Down Expand Up @@ -49,6 +46,7 @@ class ScanBarcodeFromCameraFragment : Fragment(), ConfirmBarcodeDialogFragment.L
private val zoomStep = 5
private lateinit var codeScanner: CodeScanner
private var toast: Toast? = null
private var lastResult: Barcode? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_scan_barcode_from_camera, container, false)
Expand Down Expand Up @@ -225,13 +223,19 @@ class ScanBarcodeFromCameraFragment : Fragment(), ConfirmBarcodeDialogFragment.L
}

private fun handleScannedBarcode(result: Result) {
vibrateIfNeeded()

if (requireActivity().intent?.action == ZXING_SCAN_INTENT_ACTION) {
vibrateIfNeeded()
finishWithResult(result)
return
}

if (settings.continuousScanning && result.equalTo(lastResult)) {
restartPreviewWithDelay(false)
return
}

vibrateIfNeeded()

val barcode = barcodeParser.parseResult(result)

when {
Expand All @@ -250,7 +254,11 @@ class ScanBarcodeFromCameraFragment : Fragment(), ConfirmBarcodeDialogFragment.L

private fun vibrateIfNeeded() {
if (settings.vibrate) {
requireContext().vibrator?.vibrateOnce(vibrationPattern)
requireActivity().apply {
runOnUiThread {
applicationContext.vibrator?.vibrateOnce(vibrationPattern)
}
}
}
}

Expand All @@ -265,8 +273,9 @@ class ScanBarcodeFromCameraFragment : Fragment(), ConfirmBarcodeDialogFragment.L
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ id ->
lastResult = barcode
when (settings.continuousScanning) {
true -> restartPreviewWithDelay()
true -> restartPreviewWithDelay(true)
else -> navigateToBarcodeScreen(barcode.copy(id = id))
}
},
Expand All @@ -275,19 +284,23 @@ class ScanBarcodeFromCameraFragment : Fragment(), ConfirmBarcodeDialogFragment.L
.addTo(disposable)
}

private fun restartPreviewWithDelay() {
private fun restartPreviewWithDelay(showMessage: Boolean) {
Completable
.timer(CONTINUOUS_SCANNING_PREVIEW_DELAY, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
showToast(R.string.fragment_scan_barcode_from_camera_barcode_saved)
if (showMessage) {
showToast(R.string.fragment_scan_barcode_from_camera_barcode_saved)
}
restartPreview()
}
.addTo(disposable)
}

private fun restartPreview() {
codeScanner.startPreview()
requireActivity().runOnUiThread {
codeScanner.startPreview()
}
}

private fun toggleFlash() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class ScanBarcodeFromFileActivity : BaseActivity() {
}
}

override fun onDestroy() {
super.onDestroy()
scanDisposable.clear()
disposable.clear()
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
android:id="@+id/button_open_links_automatically"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:text="@string/fragment_settings_open_links_automatically"
app:text="@string/fragment_settings_open_content_automatically"
app:hint="@string/fragment_settings_open_content_automatically_hint"
/>
<com.example.barcodescanner.feature.common.view.SettingsButton
android:id="@+id/button_copy_to_clipboard"
Expand Down
Loading

0 comments on commit 5a100aa

Please sign in to comment.