Skip to content

Commit

Permalink
Add Gradient background (linear) option (#33)
Browse files Browse the repository at this point in the history
* This commit adds an option to the Style menu to select a Gradient background.
* Currently, the gradient can only be linear, but a radial option will be a future addition.
* The gradient "stops" may not yet be customized; it is yet to be determined if this will be added.
* The gradient may have 2-7 colors.
* The gradient angle may be specified.
  • Loading branch information
Tyler-Lopez authored Feb 24, 2023
1 parent 2c272a4 commit 3f99579
Show file tree
Hide file tree
Showing 25 changed files with 670 additions and 260 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.activityartapp"
minSdk 26
targetSdk 33
versionCode 14
versionName "1.3.4"
versionCode 15
versionName "1.4.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/activityartapp/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ object AppModule {
@Provides
fun provideTimeUtils() = TimeUtils()

@Provides
fun provideGradientAngleUtils() = GradientAngleUtils()

@Provides
fun provideParseNumberFromStringUtils() = ParseNumberFromStringUtils()

Expand All @@ -95,9 +98,10 @@ object AppModule {
fun provideVisualizationUtils(
activitySortUtils: ActivitySortUtils,
colorBrightnessUtils: ColorBrightnessUtils,
gradientAngleUtils: GradientAngleUtils,
@ApplicationContext appContext: Context
) =
VisualizationUtils(appContext, activitySortUtils, colorBrightnessUtils)
VisualizationUtils(appContext, activitySortUtils, colorBrightnessUtils, gradientAngleUtils)

@Provides
fun provideFileRepository(@ApplicationContext appContext: Context): FileRepository =
Expand Down
51 changes: 26 additions & 25 deletions app/src/main/java/com/activityartapp/presentation/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MainActivity : ComponentActivity(), Router<MainDestination> {
navController.navigate(
route = Error.withArgs(
args = arrayOf(
ErrorScreen to destination.errorScreenType.toString()
ErrorScreenArg to destination.errorScreenType.toString()
)
)
) {
Expand All @@ -137,9 +137,9 @@ class MainActivity : ComponentActivity(), Router<MainDestination> {
inclusive = true
}
val a = ""
val b: List<String> = a.mapIndexed { index, _ ->
a.substring(index, a.lastIndex)
}
val b: List<String> = a.mapIndexed { index, _ ->
a.substring(index, a.lastIndex)
}
}
}
}
Expand All @@ -148,7 +148,7 @@ class MainActivity : ComponentActivity(), Router<MainDestination> {
navController.navigate(
route = EditArt.withArgs(
args = arrayOf(
AthleteId to destination.athleteId.toString(),
AthleteIdArg to destination.athleteId.toString(),
)
)
) {
Expand All @@ -163,26 +163,27 @@ class MainActivity : ComponentActivity(), Router<MainDestination> {
navController.navigate(
route = SaveArt.withArgs(
args = arrayOf(
ActivityTypes to gson.toJson(activityTypes.map { it.toString() }),
AthleteId to athleteId.toString(),
BackgroundType to backgroundType.toString(),
ColorActivitiesArgb to colorActivitiesArgb.toString(),
ColorBackgroundArgb to backgroundColorArgb.toString(),
ColorFontArgb to colorFontArgb.toString(),
FilterDateAfterMs to filterAfterMs.toString(),
FilterDateBeforeMs to filterBeforeMs.toString(),
FilterDistanceLessThanMeters to filterDistanceLessThanMeters.toString(),
FilterDistanceMoreThanMeters to filterDistanceMoreThanMeters.toString(),
SizeHeightPx to sizeHeightPx.toString(),
SizeWidthPx to sizeWidthPx.toString(),
SortType to sortType.toString(),
SortDirectionType to sortDirectionType.toString(),
StrokeWidth to strokeWidthType.toString(),
TextLeft to (textLeft ?: ""),
TextCenter to (textCenter ?: ""),
TextRight to (textRight ?: ""),
TextFontAssetPath to textFontAssetPath,
TextFontSize to textFontSize.toString()
ActivityTypesArg to gson.toJson(activityTypes.map { it.toString() }),
AthleteIdArg to athleteId.toString(),
BackgroundGradientAngleTypeArg to backgroundAngleType.toString(),
BackgroundTypeArg to backgroundType.toString(),
ColorActivitiesArgbArg to colorActivitiesArgb.toString(),
ColorBackgroundArgbListArg to gson.toJson(backgroundColorsArgb.map { it.toString() }),
ColorFontArgbArg to colorFontArgb.toString(),
FilterDateAfterMsArg to filterAfterMs.toString(),
FilterDateBeforeMsArg to filterBeforeMs.toString(),
FilterDistanceLessThanMetersArg to filterDistanceLessThanMeters.toString(),
FilterDistanceMoreThanMetersArg to filterDistanceMoreThanMeters.toString(),
SizeHeightPxArg to sizeHeightPx.toString(),
SizeWidthPxArg to sizeWidthPx.toString(),
SortTypeArg to sortType.toString(),
SortDirectionTypeArg to sortDirectionType.toString(),
StrokeWidthArg to strokeWidthType.toString(),
TextLeftArg to (textLeft ?: ""),
TextCenterArg to (textCenter ?: ""),
TextRightArg to (textRight ?: ""),
TextFontAssetPathArg to textFontAssetPath,
TextFontSizeArg to textFontSize.toString()
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ sealed interface MainDestination : Destination {
data class NavigateSaveArt(
val activityTypes: List<SportType>,
val athleteId: Long,
val backgroundAngleType: AngleType,
val backgroundType: BackgroundType,
val backgroundColorArgb: Int,
val backgroundColorsArgb: List<Int>,
val colorActivitiesArgb: Int,
val colorFontArgb: Int,
val filterBeforeMs: Long,
Expand Down
45 changes: 23 additions & 22 deletions app/src/main/java/com/activityartapp/presentation/MainNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun MainNavHost(
swipingInOutComposable(
screen = EditArt,
navArgSpecifications = listOf(
AthleteId
AthleteIdArg
)
) {
EditArtViewDelegate(viewModel = hiltViewModel<EditArtViewModel>().apply {
Expand All @@ -73,26 +73,27 @@ fun MainNavHost(
swipingInOutComposable(
screen = SaveArt,
navArgSpecifications = listOf(
ActivityTypes,
AthleteId,
BackgroundType,
ColorActivitiesArgb,
ColorBackgroundArgb,
ColorFontArgb,
FilterDateAfterMs,
FilterDateBeforeMs,
FilterDistanceLessThanMeters,
FilterDistanceMoreThanMeters,
SizeHeightPx,
SizeWidthPx,
SortDirectionType,
SortType,
StrokeWidth,
TextLeft,
TextCenter,
TextRight,
TextFontAssetPath,
TextFontSize
ActivityTypesArg,
AthleteIdArg,
BackgroundGradientAngleTypeArg,
BackgroundTypeArg,
ColorActivitiesArgbArg,
ColorBackgroundArgbListArg,
ColorFontArgbArg,
FilterDateAfterMsArg,
FilterDateBeforeMsArg,
FilterDistanceLessThanMetersArg,
FilterDistanceMoreThanMetersArg,
SizeHeightPxArg,
SizeWidthPxArg,
SortDirectionTypeArg,
SortTypeArg,
StrokeWidthArg,
TextLeftArg,
TextCenterArg,
TextRightArg,
TextFontAssetPathArg,
TextFontSizeArg
)
) {
SaveArtViewDelegate(viewModel = hiltViewModel<SaveArtViewModel>().apply {
Expand All @@ -102,7 +103,7 @@ fun MainNavHost(
swipingInOutComposable(
screen = Error,
navArgSpecifications = listOf(
ErrorScreen
ErrorScreenArg
)
) {
ErrorScreen(viewModel = hiltViewModel<ErrorViewModel>().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.activityartapp.presentation.editArtScreen

enum class EditArtDialogType {
INFO_CHECKERED_BACKGROUND,
INFO_GRADIENT_BACKGROUND,
INFO_TRANSPARENT,
NAVIGATE_UP,
NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import android.os.Parcelable
import androidx.annotation.StringRes
import androidx.compose.foundation.ScrollState
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.*
import androidx.compose.ui.res.stringResource
import androidx.room.Ignore
import com.activityartapp.R
import com.activityartapp.architecture.ViewEvent
import com.activityartapp.architecture.ViewState
Expand All @@ -33,6 +30,7 @@ annotation class UnixMS
sealed interface EditArtViewEvent : ViewEvent {

object ClickedInfoCheckeredBackground : EditArtViewEvent
object ClickedInfoGradientBackground : EditArtViewEvent
object ClickedInfoTransparentBackground : EditArtViewEvent
object DialogDismissed : EditArtViewEvent
object DialogNavigateUpConfirmed : EditArtViewEvent
Expand All @@ -57,7 +55,7 @@ sealed interface EditArtViewEvent : ViewEvent {
}

data class StyleColorPendingChanged(
val styleType: StyleType,
val style: StyleIdentifier,
val colorType: ColorType,
val changedTo: String
) : EditArtViewEvent
Expand Down Expand Up @@ -119,16 +117,19 @@ sealed interface EditArtViewEvent : ViewEvent {
data class SizeRotated(val rotatedIndex: Int) : ArtMutatingEvent
data class SortDirectionChanged(val changedTo: EditArtSortDirectionType) : ArtMutatingEvent
data class SortTypeChanged(val changedTo: EditArtSortType) : ArtMutatingEvent
data class StyleGradientAngleTypeChanged(val changedTo: AngleType) : ArtMutatingEvent
data class StyleBackgroundTypeChanged(val changedTo: BackgroundType) : ArtMutatingEvent
object StyleBackgroundColorAdded : ArtMutatingEvent
data class StyleBackgroundColorRemoved(val index: Int) : ArtMutatingEvent
data class StyleColorChanged(
val styleType: StyleType,
val colorType: ColorType,
val changedTo: Float
val changedTo: Float,
val style: StyleIdentifier
) : ArtMutatingEvent

data class StyleColorPendingChangeConfirmed(val styleType: StyleType) : ArtMutatingEvent
data class StyleColorPendingChangeConfirmed(val style: StyleIdentifier) : ArtMutatingEvent
data class StyleColorFontUseCustomChanged(val useCustom: Boolean) : ArtMutatingEvent
data class StylesStrokeWidthChanged(val changedTo: StrokeWidthType) : ArtMutatingEvent
data class StyleStrokeWidthChanged(val changedTo: StrokeWidthType) : ArtMutatingEvent
data class TypeCustomTextChanged(
val section: EditArtTypeSection,
val changedTo: String
Expand All @@ -149,6 +150,8 @@ sealed interface EditArtViewState : ViewState {

companion object {
private const val FADE_LENGTH_MS = 1000
const val MAX_GRADIENT_BG_COLORS = 7
const val MIN_GRADIENT_BG_COLORS = 2
}

val dialogActive: EditArtDialogType
Expand All @@ -163,12 +166,6 @@ sealed interface EditArtViewState : ViewState {
)
) : EditArtViewState

/**
* @param styleActivities The color of the activities on the art.
* @param styleBackground The color of the background of the art.
* @param styleFont The color of text on the art. When set to null, [styleActivities] determines
* the color of the text.
*/
@Parcelize
data class Standby(
@IgnoredOnParcel val bitmap: Bitmap? = null,
Expand Down Expand Up @@ -205,13 +202,26 @@ sealed interface EditArtViewState : ViewState {
green = INIT_ACTIVITIES_GREEN,
red = INIT_ACTIVITIES_RED
),
val styleBackgroundList: List<ColorWrapper> = (0 until MAX_GRADIENT_BG_COLORS).map {
if (it % 2 == 0) {
ColorWrapper(
alpha = INIT_BACKGROUND_ALPHA,
blue = INIT_BACKGROUND_BLUE,
green = INIT_BACKGROUND_GREEN,
red = INIT_BACKGROUND_RED
)
} else {
ColorWrapper(
alpha = INIT_ACTIVITIES_ALPHA,
blue = INIT_ACTIVITIES_BLUE,
green = INIT_ACTIVITIES_GREEN,
red = INIT_ACTIVITIES_RED
)
}
},
val styleBackgroundAngleType: AngleType = AngleType.CW90,
val styleBackgroundGradientColorCount: Int = MIN_GRADIENT_BG_COLORS,
val styleBackgroundType: BackgroundType = BackgroundType.SOLID,
val styleBackground: ColorWrapper = ColorWrapper(
alpha = INIT_BACKGROUND_ALPHA,
blue = INIT_BACKGROUND_BLUE,
green = INIT_BACKGROUND_GREEN,
red = INIT_BACKGROUND_RED
),
val styleFont: ColorWrapper? = null,
val styleStrokeWidthType: StrokeWidthType = INIT_STROKE_WIDTH,
val typeActivitiesDistanceMetersSummed: Int = -1,
Expand Down Expand Up @@ -302,10 +312,10 @@ data class FilterStateWrapper(

@Parcelize
data class ColorWrapper(
val alpha: Float,
val blue: Float,
val green: Float,
val red: Float,
var alpha: Float,
var blue: Float,
var green: Float,
var red: Float,
@IgnoredOnParcel val pendingAlpha: String? = null,
@IgnoredOnParcel val pendingBlue: String? = null,
@IgnoredOnParcel val pendingGreen: String? = null,
Expand Down Expand Up @@ -340,11 +350,9 @@ data class ColorWrapper(
fun greenToEightBitString() = ratioToEightBit(green).toString()
fun blueToEightBitString() = ratioToEightBit(blue).toString()
fun alphaToEightBitString() = ratioToEightBit(alpha).toString()

}

sealed interface DateSelection : Parcelable {

@Parcelize
object All : DateSelection

Expand All @@ -368,11 +376,10 @@ sealed interface DateSelection : Parcelable {
}
}


enum class StyleType {
BACKGROUND,
ACTIVITIES,
FONT
sealed interface StyleIdentifier {
object Activities : StyleIdentifier
data class Background(val index: Int) : StyleIdentifier
object Font : StyleIdentifier
}

enum class ColorType(@StringRes val strRes: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ fun EditArtViewDelegate(viewModel: EditArtViewModel) {
)
}
STYLE -> EditArtStyleViewDelegate(
styleBackground,
styleBackgroundType,
styleBackgroundAngleType,
styleBackgroundList.take(styleBackgroundGradientColorCount),
styleActivities,
styleFont,
styleStrokeWidthType,
viewModel
)
TYPE -> EditArtTypeScreen(
typeActivitiesDistanceMetersSummed,
// typeAthleteName,
typeCenterCustomText,
typeLeftCustomText,
typeRightCustomText,
Expand Down Expand Up @@ -171,6 +171,10 @@ fun EditArtViewDelegate(viewModel: EditArtViewModel) {
body = stringArrayResource(id = R.array.edit_art_dialog_info_background_checkered),
eventReceiver = viewModel
)
INFO_GRADIENT_BACKGROUND -> EditArtDialogInfo(
body = stringArrayResource(id = R.array.edit_art_dialog_info_background_gradient),
eventReceiver = viewModel
)
INFO_TRANSPARENT -> EditArtDialogInfo(
body = stringArrayResource(id = R.array.edit_art_dialog_info_background_transparent),
eventReceiver = viewModel
Expand Down
Loading

0 comments on commit 3f99579

Please sign in to comment.