Skip to content

Commit

Permalink
Merge pull request #12 from dmitriy-ilchenko/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wewewe718 authored Aug 29, 2020
2 parents af9e57a + 31a7b01 commit e7691d7
Show file tree
Hide file tree
Showing 114 changed files with 636 additions and 206 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Change Log

## 1.1
* Support dark theme on all Android versions
* Support edge-to-edge on Android 10
* Bug fixes

## 1.0
* First version
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.example.barcodescanner"
minSdkVersion 21
targetSdkVersion 29
versionCode 2
versionName "1.0"
versionCode 3
versionName "1.1"
multiDexEnabled true
vectorDrawables.useSupportLibrary true
resConfigs "en", "ru"
Expand Down Expand Up @@ -63,12 +63,13 @@ dependencies {

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
kapt 'com.android.databinding:compiler:3.1.4'

// Android
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
implementation 'androidx.multidex:multidex:2.0.1'

// Room
Expand Down Expand Up @@ -103,5 +104,5 @@ dependencies {
implementation 'com.github.florent37:singledateandtimepicker:2.2.6'

// Sentry
implementation 'io.sentry:sentry-android:2.3.0'
implementation 'io.sentry:sentry-android:2.3.1'
}
20 changes: 20 additions & 0 deletions app/googlePlay/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 1,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "org.barcodescanner",
"variantName": "googlePlayRelease",
"elements": [
{
"type": "SINGLE",
"filters": [],
"properties": [],
"versionCode": 2,
"versionName": "1.0",
"enabled": true,
"outputFile": "app-googlePlay-release.apk"
}
]
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/example/barcodescanner/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package com.example.barcodescanner

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

class App : MultiDexApplication() {

override fun onCreate() {
handleUnhandledRxJavaErrors()
enableStrictModeIfNeeded()
showTheme()
applyTheme()
super.onCreate()
}

private fun showTheme() {
AppCompatDelegate.setDefaultNightMode(settings.theme)
private fun applyTheme() {
settings.reapplyTheme()
}

private fun handleUnhandledRxJavaErrors() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.example.barcodescanner.extension

import com.example.barcodescanner.usecase.Logger
import java.text.DateFormat
import java.util.*

fun DateFormat.parseOrNull(date: String?): Date? {
return try {
parse(date.orEmpty())
} catch (ex: Exception) {
Logger.log(ex)
null
}
}
Expand All @@ -27,7 +25,6 @@ fun DateFormat.formatOrNull(time: Long?): String? {
return try {
format(Date(time!!))
} catch (ex: Exception) {
Logger.log(ex)
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ val Fragment.packageManager: PackageManager
fun Fragment.showError(error: Throwable?) {
val errorDialog = ErrorDialogFragment.newInstance(requireContext(), error)
errorDialog.show(childFragmentManager, "")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.barcodescanner.extension

import android.annotation.SuppressLint
import android.view.View
import android.view.WindowInsets

fun View.applySystemWindowInsets(
applyLeft: Boolean = false,
applyTop: Boolean = false,
applyRight: Boolean = false,
applyBottom: Boolean = false
) {
doOnApplyWindowInsets { view, insets, padding ->
val left = if (applyLeft) insets.systemWindowInsetLeft else 0
val top = if (applyTop) insets.systemWindowInsetTop else 0
val right = if (applyRight) insets.systemWindowInsetRight else 0
val bottom = if (applyBottom) insets.systemWindowInsetBottom else 0

view.setPadding(
padding.left + left,
padding.top + top,
padding.right + right,
padding.bottom + bottom
)
}
}

@SuppressLint("RestrictedApi")
fun View.doOnApplyWindowInsets(f: (View, WindowInsets, InitialPadding) -> Unit) {
// Create a snapshot of the view's padding state
val initialPadding = recordInitialPaddingForView(this)
// Set an actual OnApplyWindowInsetsListener which proxies to the given
// lambda, also passing in the original padding state
setOnApplyWindowInsetsListener { v, insets ->
f(v, insets, initialPadding)
// Always return the insets, so that children can also use them
insets
}
// request some insets
requestApplyInsetsWhenAttached()
}

data class InitialPadding(val left: Int, val top: Int,
val right: Int, val bottom: Int)

private fun recordInitialPaddingForView(view: View) = InitialPadding(
view.paddingLeft, view.paddingTop, view.paddingRight, view.paddingBottom)

fun View.requestApplyInsetsWhenAttached() {
if (isAttachedToWindow) {
// We're already attached, just request as normal
requestApplyInsets()
} else {
// We're not attached to the hierarchy, add a listener to
// request when we are
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
v.removeOnAttachStateChangeListener(this)
v.requestApplyInsets()
}

override fun onViewDetachedFromWindow(v: View) = Unit
})
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
package com.example.barcodescanner.feature

import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.example.barcodescanner.R
import com.example.barcodescanner.di.settings

abstract class BaseActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setWhiteStatusBar()
}

fun setBlackStatusBar() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return
}

if (settings.isDarkTheme) {
return
}

window.apply {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
decorView.systemUiVisibility = 0
statusBarColor = ContextCompat.getColor(context, R.color.black)
}
}

fun setWhiteStatusBar() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return
}

if (settings.isDarkTheme) {
return
}

window.apply {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
statusBarColor = ContextCompat.getColor(context, R.color.white)
}
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BarcodeActivity : BaseActivity(), DeleteConfirmationDialogFragment.Listene
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_barcode)
supportEdgeToEdge()
applySettings()
handleToolbarBackPressed()
handleToolbarMenuClicked()
Expand All @@ -91,6 +92,10 @@ class BarcodeActivity : BaseActivity(), DeleteConfirmationDialogFragment.Listene
}


private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}

private fun applySettings() {
if (settings.copyToClipboard) {
copyToClipboard(barcode.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.core.view.isVisible
import com.example.barcodescanner.R
import com.example.barcodescanner.di.barcodeImageGenerator
import com.example.barcodescanner.di.settings
import com.example.barcodescanner.extension.applySystemWindowInsets
import com.example.barcodescanner.extension.toStringId
import com.example.barcodescanner.extension.unsafeLazy
import com.example.barcodescanner.feature.BaseActivity
Expand Down Expand Up @@ -37,10 +38,15 @@ class BarcodeImageActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_barcode_image)
supportEdgeToEdge()
handleToolbarBackPressed()
showBarcode()
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}

private fun handleToolbarBackPressed() {
toolbar.setNavigationOnClickListener {
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.example.barcodescanner.R
import com.example.barcodescanner.di.barcodeImageGenerator
import com.example.barcodescanner.di.barcodeImageSaver
import com.example.barcodescanner.di.permissionsHelper
import com.example.barcodescanner.extension.applySystemWindowInsets
import com.example.barcodescanner.extension.showError
import com.example.barcodescanner.extension.unsafeLazy
import com.example.barcodescanner.feature.BaseActivity
Expand Down Expand Up @@ -45,6 +46,7 @@ class SaveBarcodeAsImageActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_save_barcode_as_image)
supportEdgeToEdge()
initToolbar()
initFormatSpinner()
initSaveButton()
Expand All @@ -56,6 +58,10 @@ class SaveBarcodeAsImageActivity : BaseActivity() {
}
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}

private fun initToolbar() {
toolbar.setNavigationOnClickListener {
finish()
Expand All @@ -64,9 +70,9 @@ class SaveBarcodeAsImageActivity : BaseActivity() {

private fun initFormatSpinner() {
spinner_save_as.adapter = ArrayAdapter.createFromResource(
this, R.array.activity_save_barcode_as_image_formats, android.R.layout.simple_spinner_item
this, R.array.activity_save_barcode_as_image_formats, R.layout.item_spinner
).apply {
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
setDropDownViewResource(R.layout.item_spinner_dropdown)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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.extension.applySystemWindowInsets
import com.example.barcodescanner.extension.showError
import com.example.barcodescanner.extension.unsafeLazy
import com.example.barcodescanner.feature.BaseActivity
Expand Down Expand Up @@ -40,11 +41,16 @@ class SaveBarcodeAsTextActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_save_barcode_as_text)
supportEdgeToEdge()
initToolbar()
initFormatSpinner()
initSaveButton()
}

private fun supportEdgeToEdge() {
root_view.applySystemWindowInsets(applyTop = true, applyBottom = true)
}

private fun initToolbar() {
toolbar.setNavigationOnClickListener {
finish()
Expand All @@ -53,9 +59,9 @@ class SaveBarcodeAsTextActivity : BaseActivity() {

private fun initFormatSpinner() {
spinner_save_as.adapter = ArrayAdapter.createFromResource(
this, R.array.activity_save_barcode_as_text_formats, android.R.layout.simple_spinner_item
this, R.array.activity_save_barcode_as_text_formats, R.layout.item_spinner
).apply {
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
setDropDownViewResource(R.layout.item_spinner_dropdown)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConfirmBarcodeDialogFragment : DialogFragment() {
val barcode = arguments?.getSerializable(BARCODE_KEY) as? Barcode ?: throw IllegalArgumentException("No barcode passed")
val messageId = barcode.format.toStringId()

return AlertDialog.Builder(requireContext())
return AlertDialog.Builder(requireActivity(), R.style.DialogTheme)
.setTitle(R.string.fragment_scan_barcode_from_camera_confirm_barcode_dialog_title)
.setMessage(messageId)
.setCancelable(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DeleteConfirmationDialogFragment : DialogFragment() {
val listener = requireActivity() as? Listener ?: parentFragment as? Listener
val messageId = arguments?.getInt(MESSAGE_ID_KEY).orZero()

val dialog = AlertDialog.Builder(requireContext())
val dialog = AlertDialog.Builder(requireActivity(), R.style.DialogTheme)
.setMessage(messageId)
.setPositiveButton(R.string.dialog_delete_positive_button) { _, _ -> listener?.onDeleteConfirmed() }
.setNegativeButton(R.string.dialog_delete_negative_button, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ErrorDialogFragment : DialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val message = arguments?.getString(ERROR_MESSAGE_KEY).orEmpty()
return AlertDialog.Builder(requireContext())
return AlertDialog.Builder(requireActivity(), R.style.DialogTheme)
.setTitle(R.string.error_dialog_title)
.setMessage(message)
.setCancelable(false)
Expand Down
Loading

0 comments on commit e7691d7

Please sign in to comment.