Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Apr 1, 2023
1 parent 258507d commit 06e531d
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import ru.tech.imageresizershrinker.main_screen.components.drawHorizontalStroke
import ru.tech.imageresizershrinker.main_screen.components.fabBorder
import ru.tech.imageresizershrinker.resize_screen.components.ImageNotPickedWidget
import ru.tech.imageresizershrinker.resize_screen.components.LoadingDialog
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.resize_screen.components.blend
import ru.tech.imageresizershrinker.theme.blend
import ru.tech.imageresizershrinker.utils.BitmapUtils.getBitmapByUri
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import ru.tech.imageresizershrinker.main_screen.components.LocalAmoledMode
import ru.tech.imageresizershrinker.main_screen.components.LocalAppPrimaryColor
import ru.tech.imageresizershrinker.main_screen.components.LocalDynamicColors
import ru.tech.imageresizershrinker.main_screen.components.LocalNightMode
import ru.tech.imageresizershrinker.widget.ToastHost
import ru.tech.imageresizershrinker.widget.rememberToastHostState
import ru.tech.imageresizershrinker.theme.ImageResizerTheme
import ru.tech.imageresizershrinker.widget.AutoSizeText
import ru.tech.imageresizershrinker.widget.ToastHost
import ru.tech.imageresizershrinker.widget.activity.M3Activity
import ru.tech.imageresizershrinker.widget.rememberToastHostState

@AndroidEntryPoint
class CrashActivity : M3Activity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ import ru.tech.imageresizershrinker.main_screen.components.drawHorizontalStroke
import ru.tech.imageresizershrinker.main_screen.components.fabBorder
import ru.tech.imageresizershrinker.resize_screen.components.ImageNotPickedWidget
import ru.tech.imageresizershrinker.resize_screen.components.LoadingDialog
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.theme.outlineVariant
import ru.tech.imageresizershrinker.utils.BitmapUtils.decodeBitmapFromUri
import ru.tech.imageresizershrinker.utils.BitmapUtils.shareBitmap
import ru.tech.imageresizershrinker.utils.ContextUtils.isExternalStorageWritable
import ru.tech.imageresizershrinker.utils.ContextUtils.requestPermission
import ru.tech.imageresizershrinker.utils.SavingFolder
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ import ru.tech.imageresizershrinker.pick_color_from_image.copyColorIntoClipboard
import ru.tech.imageresizershrinker.pick_color_from_image.format
import ru.tech.imageresizershrinker.resize_screen.components.ImageNotPickedWidget
import ru.tech.imageresizershrinker.resize_screen.components.LoadingDialog
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.theme.PaletteSwatch
import ru.tech.imageresizershrinker.utils.BitmapUtils.decodeBitmapFromUri
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import ru.tech.imageresizershrinker.pick_color_from_image.PickColorFromImageScre
import ru.tech.imageresizershrinker.resize_screen.SingleResizeScreen
import ru.tech.imageresizershrinker.resize_screen.components.*
import ru.tech.imageresizershrinker.theme.ImageResizerTheme
import ru.tech.imageresizershrinker.theme.blend
import ru.tech.imageresizershrinker.theme.getAppColorTuple
import ru.tech.imageresizershrinker.theme.outlineVariant
import ru.tech.imageresizershrinker.utils.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.tech.imageresizershrinker.main_screen.components

import android.annotation.SuppressLint
import android.os.Build
import android.text.method.LinkMovementMethod
import android.util.TypedValue
Expand All @@ -16,14 +17,14 @@ import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.res.ResourcesCompat
import androidx.core.text.HtmlCompat
import ru.tech.imageresizershrinker.R
import ru.tech.imageresizershrinker.resize_screen.components.blend
import ru.tech.imageresizershrinker.theme.blend

@Composable
fun HtmlText(
nightMode: Boolean,
html: String,
color: Color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
) {
val style = LocalTextStyle.current
val textColor = color.toArgb()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ import nl.dionsegijn.konfetti.core.*
import ru.tech.imageresizershrinker.BuildConfig
import ru.tech.imageresizershrinker.R
import ru.tech.imageresizershrinker.main_screen.viewModel.MainViewModel
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.resize_screen.components.inverse
import ru.tech.imageresizershrinker.theme.*
import ru.tech.imageresizershrinker.utils.*
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee
import ru.tech.imageresizershrinker.widget.Picture
import java.lang.Integer.max
Expand Down Expand Up @@ -806,7 +805,9 @@ fun MainScreen(
)
)
},
modifier = Modifier.fabBorder().requiredSize(size=56.dp),
modifier = Modifier
.fabBorder()
.requiredSize(size = 56.dp),
containerColor = MaterialTheme.colorScheme.primaryContainer,
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
content = { Icon(Icons.Rounded.Github, null) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ru.tech.imageresizershrinker.resize_screen.components.blend
import ru.tech.imageresizershrinker.theme.blend
import ru.tech.imageresizershrinker.widget.AutoSizeText

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.tech.imageresizershrinker.main_screen.components

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import androidx.compose.animation.*
Expand Down Expand Up @@ -28,7 +29,7 @@ import ru.tech.imageresizershrinker.utils.APP_LINK

@Composable
fun SourceCodePreference(
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp),
color: Color = MaterialTheme.colorScheme.tertiaryContainer
Expand All @@ -55,7 +56,7 @@ fun SourceCodePreference(
fun SingleResizePreference(
onClick: () -> Unit,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand All @@ -73,7 +74,7 @@ fun SingleResizePreference(
fun BytesResizePreference(
onClick: () -> Unit,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand All @@ -92,7 +93,7 @@ fun BytesResizePreference(
fun BatchResizePreference(
onClick: () -> Unit,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand All @@ -109,7 +110,7 @@ fun BatchResizePreference(
@Composable
fun GeneratePalettePreference(
onClick: () -> Unit,
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp),
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)
Expand All @@ -128,7 +129,7 @@ fun GeneratePalettePreference(
fun CropPreference(
onClick: () -> Unit,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand All @@ -146,7 +147,7 @@ fun CropPreference(
fun PickColorPreference(
onClick: () -> Unit,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand All @@ -164,7 +165,7 @@ fun PickColorPreference(
fun ComparePreference(
onClick: () -> Unit,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand All @@ -187,7 +188,7 @@ fun PreferenceItem(
icon: ImageVector? = null,
endIcon: ImageVector? = null,
color: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
modifier: Modifier = Modifier
@SuppressLint("ModifierParameter") modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import kotlinx.coroutines.withContext
import org.w3c.dom.Element
import ru.tech.imageresizershrinker.BuildConfig
import ru.tech.imageresizershrinker.main_screen.components.Screen
import ru.tech.imageresizershrinker.widget.ToastHostState
import ru.tech.imageresizershrinker.theme.md_theme_dark_primary
import ru.tech.imageresizershrinker.utils.*
import ru.tech.imageresizershrinker.widget.ToastHostState
import java.net.URL
import javax.inject.Inject
import javax.xml.parsers.DocumentBuilderFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ import ru.tech.imageresizershrinker.main_screen.components.*
import ru.tech.imageresizershrinker.pick_color_from_image.viewModel.PickColorViewModel
import ru.tech.imageresizershrinker.resize_screen.components.ImageNotPickedWidget
import ru.tech.imageresizershrinker.resize_screen.components.LoadingDialog
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.theme.PaletteSwatch
import ru.tech.imageresizershrinker.theme.outlineVariant
import ru.tech.imageresizershrinker.utils.BitmapUtils.decodeBitmapFromUri
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -285,7 +285,10 @@ fun PickColorFromImageScreen(
}
}
}
AnimatedContent(targetState = viewModel.bitmap, modifier = Modifier.weight(1f)) { bitmap ->
AnimatedContent(
targetState = viewModel.bitmap,
modifier = Modifier.weight(1f)
) { bitmap ->
bitmap?.let {
ImageColorDetector(
canZoom = canZoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import ru.tech.imageresizershrinker.R
import ru.tech.imageresizershrinker.main_screen.components.block
import ru.tech.imageresizershrinker.theme.mixedColor
import ru.tech.imageresizershrinker.theme.onMixedColor
import ru.tech.imageresizershrinker.widget.AutoSizeText
import ru.tech.imageresizershrinker.widget.GroupRipple

@Composable
fun ExtensionGroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import ru.tech.imageresizershrinker.R
import ru.tech.imageresizershrinker.main_screen.components.block
import ru.tech.imageresizershrinker.theme.mixedColor
import ru.tech.imageresizershrinker.theme.onMixedColor
import ru.tech.imageresizershrinker.utils.BitmapUtils.with
import ru.tech.imageresizershrinker.widget.AutoSizeText

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import ru.tech.imageresizershrinker.R
import ru.tech.imageresizershrinker.main_screen.components.block
import ru.tech.imageresizershrinker.widget.ToggleGroupButton


@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import ru.tech.imageresizershrinker.theme.Telegram
import ru.tech.imageresizershrinker.theme.mixedColor
import ru.tech.imageresizershrinker.theme.onMixedColor

@Composable
fun TelegramButton(
Expand Down
51 changes: 50 additions & 1 deletion app/src/main/java/ru/tech/imageresizershrinker/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package ru.tech.imageresizershrinker.theme

import androidx.annotation.FloatRange
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.dp
import androidx.core.graphics.ColorUtils
import ru.tech.imageresizershrinker.main_screen.components.LocalNightMode
import ru.tech.imageresizershrinker.main_screen.components.isNightMode


val md_theme_light_primary = Color(0xFF3D6A00)
Expand Down Expand Up @@ -87,4 +94,46 @@ fun ColorScheme.suggestContainerColorBy(color: Color) = when (color) {
onSurfaceVariant -> surfaceVariant
inverseOnSurface -> inverseSurface
else -> surface
}
}

inline val ColorScheme.mixedColor: Color
@Composable get() = run {
tertiaryContainer.blend(
primaryContainer,
0.15f
)
}

inline val ColorScheme.onMixedColor: Color
@Composable get() = run {
onTertiaryContainer.blend(
onPrimaryContainer,
0.15f
)
}

fun Color.blend(
color: Color,
@FloatRange(from = 0.0, to = 1.0) fraction: Float = 0.2f
): Color = Color(ColorUtils.blendARGB(this.toArgb(), color.toArgb(), fraction))

@Composable
fun Color.inverse(
fraction: (Boolean) -> Float = { 0.5f },
darkMode: Boolean = LocalNightMode.current.isNightMode(),
): Color = if (darkMode) blend(Color.White, fraction(darkMode))
else blend(Color.Black, fraction(darkMode))


fun Int.blend(
color: Color,
@FloatRange(from = 0.0, to = 1.0) fraction: Float = 0.2f
): Int = ColorUtils.blendARGB(this, color.toArgb(), fraction)

@Composable
fun Color.harmonizeWithPrimary(
@FloatRange(
from = 0.0,
to = 1.0
) fraction: Float = 0.2f
): Color = blend(MaterialTheme.colorScheme.primary, fraction)
Loading

0 comments on commit 06e531d

Please sign in to comment.