Skip to content

Commit

Permalink
hotfix: dark theme on android < 10 (#10)
Browse files Browse the repository at this point in the history
* refactoring

* hotfix: dark mode on android < 10
  • Loading branch information
vadiole committed Mar 28, 2022
1 parent c4900a3 commit 6f0996e
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 47 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<h1 align="start">Unicode</h1>
<h4 align="start">Application for searching, viewing and copying characters from Unicode 15</h1>
<h4 align="start">Application for searching, viewing and copying characters from Unicode 15</h4>

<img src="https://raw.githubusercontent.com/vadiole/Unicode/master/assets/Screenshot-1.png" alt="screenshot 1" width="24.6%" height="24%"> <img src="https://raw.githubusercontent.com/vadiole/Unicode/master/assets/Screenshot-2.png" alt="screenshot 2" width="24.6%" height="23%"> <img src="https://raw.githubusercontent.com/vadiole/Unicode/master/assets/Screenshot-3.png" alt="screenshot 2" width="24.6%" height="24%"> <img src="https://raw.githubusercontent.com/vadiole/Unicode/master/assets/Screenshot-4.png" alt="screenshot 4" width="24.6%" height="24%">


### Caution
### Caution ⚠️
I decided to develop an app without using the classic modern-android-development stack.
There is no mvvm or clean architecture, no dagger, no room, no app compat and material libraries, no fragments and navigation component, no constraint layout and basically no xml. The motivation is to learn to create applications with as few dependencies as possible. As for xml – I just don't like it.

The Ui is in pure Kotlin. The navigation is made with views, the database is a plain sqlite. Dependencies injection is done via constructor, and async using coroutines (thinking about moving to executors).

### Design
### Design 📱
I tried to make ui close to iOS in appearance and behavior using spring animations, squircle for roundings, self-written themes, etc. This is one of the reasons why I had to get rid of fragments and xml.

### Conclusion
### Conclusion 📍
This is an interesting experiment. I will be glad if you try the application, share with friends, leave feedback or find something useful for yourself in the source code.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/build
/release
/debug
11 changes: 5 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "vadiole.unicode"
minSdk = 26
targetSdk = 31
versionCode = 121
versionName = "1.2.1"
versionCode = 122
versionName = "1.2.2"
resourceConfigurations.addAll(listOf("en"))
setProperty("archivesBaseName", "unicode-v$versionName")
}
Expand Down Expand Up @@ -60,18 +60,17 @@ android {
"UnusedAttribute",
"NotifyDataSetChanged",
"ktNoinlineFunc",
"ClickableViewAccessibility",
)
)
}
}

dependencies {
implementation("androidx.core:core-ktx:1.7.0")

implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03")
implementation("androidx.dynamicanimation:dynamicanimation-ktx:1.0.0-alpha03")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-native-mt")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
}
1 change: 0 additions & 1 deletion app/src/main/kotlin/vadiole/unicode/data/CodePoint.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package vadiole.unicode.data


@JvmInline
value class CodePoint(val value: Int) {
val char: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ class UserConfig(context: Context) {
set(value) {
editor.putBoolean(key_showUnsupportedChars, value).apply()
}

}
7 changes: 2 additions & 5 deletions app/src/main/kotlin/vadiole/unicode/ui/NavigationView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package vadiole.unicode.ui

import android.annotation.SuppressLint
import android.content.Context
import android.view.*
import android.widget.FrameLayout
Expand Down Expand Up @@ -167,8 +166,6 @@ class NavigationView(context: Context, appComponent: AppComponent) : FrameLayout
return false
}

// TODO: add perform click
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
val content = detailsSheet ?: return false
val deltaY = event.rawY - touchDownY
Expand All @@ -189,7 +186,7 @@ class NavigationView(context: Context, appComponent: AppComponent) : FrameLayout
val needOverdrag = content.translationY + deltaY < 0
content.translationY = if (needOverdrag) {
val realOverdrag = touchDownTranslationY + deltaY
-normalize(-realOverdrag, maxOverdragY)
-normalizeOverdrag(-realOverdrag, maxOverdragY)
} else {
touchDownTranslationY + deltaY
}
Expand Down Expand Up @@ -234,7 +231,7 @@ class NavigationView(context: Context, appComponent: AppComponent) : FrameLayout
dimView.isVisible = percentDone > 0
}

private fun normalize(dy: Float, max: Float): Float {
private fun normalizeOverdrag(dy: Float, max: Float): Float {
return (2 * max * atan(0.5 * PI * dy / max) / PI).toFloat()
}

Expand Down
13 changes: 10 additions & 3 deletions app/src/main/kotlin/vadiole/unicode/ui/UnicodeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import vadiole.unicode.utils.extension.insetsController
import vadiole.unicode.utils.extension.isDarkMode

class UnicodeActivity : Activity() {
private var backHandler: () -> Boolean = { false }
private var backButtonHandler: () -> Boolean = { false }
private var deepLinkHandler: (codePoint: CodePoint) -> Unit = { _ -> }

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -23,7 +23,7 @@ class UnicodeActivity : Activity() {
val appComponent = (applicationContext as UnicodeApp).appComponent
val navigationView = NavigationView(this, appComponent)
setContentView(navigationView)
backHandler = {
backButtonHandler = {
navigationView.hideDetailsBottomSheet()
}
deepLinkHandler = { codePoint ->
Expand All @@ -41,7 +41,7 @@ class UnicodeActivity : Activity() {
}

override fun onBackPressed() {
val handled = backHandler.invoke()
val handled = backButtonHandler.invoke()
if (!handled) {
super.onBackPressed()
}
Expand All @@ -64,8 +64,15 @@ class UnicodeActivity : Activity() {
}
}


private fun updateSystemBars(isDarkMode: Boolean) {
insetsController.isAppearanceLightStatusBars = !isDarkMode
insetsController.isAppearanceLightNavigationBars = !isDarkMode
}

override fun onDestroy() {
super.onDestroy()
backButtonHandler = { false }
deepLinkHandler = { _ -> }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.view.View
import vadiole.unicode.ui.theme.*
import vadiole.unicode.utils.extension.dp

class InfoView(context: Context, theme: AppTheme) : View(context), ThemeDelegate {
class CharInfoView(context: Context, theme: AppTheme) : View(context), ThemeDelegate {
private val backgroundDrawable = SquircleDrawable(12.dp(context))
private val valuePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
textAlign = Paint.Align.CENTER
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/kotlin/vadiole/unicode/ui/common/SpacerDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ import android.graphics.PixelFormat
import android.graphics.drawable.Drawable

class SpacerDrawable(val height: Int = 0, val width: Int = 0) : Drawable() {
override fun getIntrinsicHeight(): Int {
return height
}

override fun getIntrinsicWidth(): Int {
return width
}

override fun getIntrinsicHeight(): Int = height
override fun getIntrinsicWidth(): Int = width
override fun setColorFilter(colorFilter: ColorFilter?) = Unit
override fun getOpacity(): Int = PixelFormat.TRANSPARENT
override fun setAlpha(alpha: Int) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DetailsSheet(
}
private val infoViewHeight = 56.dp(context)
private val infoViews = List(4) {
InfoView(context, theme).apply {
CharInfoView(context, theme).apply {
layoutParams = linearParams(matchParent, infoViewHeight, weight = 1f)
onLongClick = {
charObj?.let { value ->
Expand Down Expand Up @@ -106,12 +106,10 @@ class DetailsSheet(
}
}
private var divider2PositionY = vertical.toFloat() + screenPadding

private val actionShare = ActionCell(context, theme, "Share Link", bottomItem = true).apply {
layoutParams = frameParams(matchParent, actionCellHeight, marginTop = vertical)
setIcon(R.drawable.ic_link)
vertical += actionCellHeight

var canClick = true
onClick = {
if (canClick) {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/kotlin/vadiole/unicode/ui/table/CharRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.Log
import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import android.view.View
Expand All @@ -14,7 +13,6 @@ import vadiole.unicode.ui.theme.*
import vadiole.unicode.utils.extension.dp
import kotlin.math.floor


class CharRow(
context: Context,
appTheme: AppTheme,
Expand Down Expand Up @@ -60,10 +58,8 @@ class CharRow(
invalidate()
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
val index = floor(event.x / width * count).toInt()
Log.d("TOUCH", "onTouchEvent: ${event.actionMasked}")
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
actionDownIndex = index
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/vadiole/unicode/ui/theme/AppTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ class AppTheme(scheme: Scheme) : Theme() {
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package vadiole.unicode.utils.extension

import android.app.Activity
import android.content.res.Configuration
import android.os.Build
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat

val Activity.insetsController: WindowInsetsControllerCompat
get() = WindowCompat.getInsetsController(window, window.decorView)!!

val Configuration.isDarkMode: Boolean
get() = Build.VERSION.SDK_INT >= 30 && isNightModeActive
get() = uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
7 changes: 0 additions & 7 deletions app/src/main/kotlin/vadiole/unicode/utils/extension/Ui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package vadiole.unicode.utils.extension

import android.animation.ObjectAnimator
import android.content.Context
import android.graphics.Paint
import android.graphics.Rect
import android.util.Property
import android.view.Gravity
Expand All @@ -27,8 +26,6 @@ val WindowInsetsCompat.navigationBars: Insets
val WindowInsetsCompat.statusBars: Insets
get() = getInsets(WindowInsetsCompat.Type.statusBars())



fun frameParams(
width: Int,
height: Int,
Expand Down Expand Up @@ -81,10 +78,6 @@ fun linearParams(
return layoutParams
}

fun Paint.measureText(text: CharSequence): Float {
return measureText(text, 0, text.length)
}

fun <T : View> T.animate(
property: Property<T, Float>,
vararg values: Float, apply: ObjectAnimator.() -> Unit = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ inline fun View.setPadding(@Px size: Int) {

@Suppress("NOTHING_TO_INLINE")
inline fun View.setPaddingHorizontal(@Px size: Int) {
setPadding(size, paddingTop, size, paddingTop)
setPadding(size, paddingTop, size, paddingBottom)
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 6f0996e

Please sign in to comment.