-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from dmitriy-ilchenko/develop
Develop
- Loading branch information
Showing
114 changed files
with
636 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/example/barcodescanner/extension/WindowsInsets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} | ||
} |
41 changes: 1 addition & 40 deletions
41
app/src/main/java/com/example/barcodescanner/feature/BaseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.