Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Tidy up icon resources #685

Merged
merged 3 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/res/menu/home_bottomnav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<item
android:id="@id/navigation_watched"
android:icon="@drawable/ic_eye_24dp"
android:icon="@drawable/ic_visibility"
android:title="@string/watched_shows_title" />

<item
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/java/app/tivi/buildsrc/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ object Libs {

const val ui = "androidx.compose.ui:ui:${version}"
const val material = "androidx.compose.material:material:${version}"
const val iconsExtended = "androidx.compose.material:material-icons-extended:${version}"

const val animation = "androidx.compose.animation:animation:${version}"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package app.tivi.common.compose

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Icon
import androidx.compose.foundation.contentColor
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.DeferredResource
import androidx.compose.ui.res.loadVectorResource

@Composable
fun IconResource(
@DrawableRes resourceId: Int,
modifier: Modifier = Modifier,
tint: Color = contentColor()
) {
val deferredResource = loadVectorResource(resourceId)
deferredResource.onLoadRun { asset ->
Icon(asset = asset, modifier = modifier, tint = tint)
}
}

inline fun <T> DeferredResource<T>.onLoadRun(block: (T) -> Unit) {
val res = resource.resource
if (res != null) {
block(res)
}
}
19 changes: 11 additions & 8 deletions common-ui-compose/src/main/java/app/tivi/common/compose/vector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.vector.VectorAsset
import androidx.compose.ui.graphics.vector.VectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.res.loadVectorResource

@Composable
fun VectorImage(
Expand All @@ -40,13 +40,16 @@ fun VectorImage(
tintColor: Color = contentColor(),
modifier: Modifier = Modifier.wrapContentSize(align = alignment)
) {
VectorImage(
vector = vectorResource(id = id),
alignment = alignment,
contentScale = contentScale,
tintColor = tintColor,
modifier = modifier
)
val deferred = loadVectorResource(id)
deferred.onLoadRun { asset ->
VectorImage(
vector = asset,
alignment = alignment,
contentScale = contentScale,
tintColor = tintColor,
modifier = modifier
)
}
}

@Composable
Expand Down
26 changes: 26 additions & 0 deletions common-ui-resources/src/main/res/drawable/ic_calendar_today.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
~ Copyright 2020 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,3h-1L19,1h-2v2L7,3L7,1L5,1v2L4,3c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,5c0,-1.1 -0.9,-2 -2,-2zM20,21L4,21L4,8h16v13z"/>
</vector>
21 changes: 21 additions & 0 deletions common-ui-resources/src/main/res/drawable/ic_cloud_upload.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
~ Copyright 2020 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector android:autoMirrored="true" android:height="24dp"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM14,13v4h-4v-4H7l5,-5 5,5h-3z"/>
</vector>
26 changes: 26 additions & 0 deletions common-ui-resources/src/main/res/drawable/ic_delete_sweep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
~ Copyright 2020 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM14,5h-3l-1,-1L6,4L5,5L2,5v2h12z"/>
</vector>
26 changes: 26 additions & 0 deletions common-ui-resources/src/main/res/drawable/ic_publish.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
~ Copyright 2020 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M5,4v2h14L19,4L5,4zM5,14h4v6h6v-6h4l-7,-7 -7,7z"/>
</vector>
21 changes: 21 additions & 0 deletions common-ui-resources/src/main/res/drawable/ic_visibility_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
~ Copyright 2020 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector android:autoMirrored="true" android:height="24dp"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
</vector>
1 change: 0 additions & 1 deletion ui-account/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ dependencies {
implementation Libs.AndroidX.Compose.animation
implementation Libs.AndroidX.Compose.tooling
implementation Libs.AndroidX.Compose.livedata
implementation Libs.AndroidX.Compose.iconsExtended

implementation Libs.Mdc.material
implementation Libs.Mdc.composeThemeAdapter
Expand Down
1 change: 0 additions & 1 deletion ui-episodedetails/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ dependencies {
implementation Libs.AndroidX.Compose.animation
implementation Libs.AndroidX.Compose.tooling
implementation Libs.AndroidX.Compose.livedata
implementation Libs.AndroidX.Compose.iconsExtended

implementation Libs.Mdc.material
implementation Libs.Mdc.composeThemeAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,17 @@ import androidx.compose.material.Snackbar
import androidx.compose.material.Surface
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CalendarToday
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.DeleteSweep
import androidx.compose.material.icons.filled.Publish
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Providers
import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.state
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.drawWithContent
Expand All @@ -80,14 +75,15 @@ import androidx.compose.ui.graphics.vector.VectorAsset
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ConfigurationAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.res.loadVectorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.center
import androidx.compose.ui.unit.dp
import androidx.lifecycle.LiveData
import androidx.ui.tooling.preview.Preview
import app.tivi.common.compose.AutoSizedCircularProgressIndicator
import app.tivi.common.compose.ExpandingText
import app.tivi.common.compose.IconResource
import app.tivi.common.compose.ProvideDisplayInsets
import app.tivi.common.compose.SwipeDirection
import app.tivi.common.compose.SwipeToDismiss
Expand All @@ -96,6 +92,7 @@ import app.tivi.common.compose.TiviDateFormatterAmbient
import app.tivi.common.compose.boundsInParent
import app.tivi.common.compose.navigationBarsHeight
import app.tivi.common.compose.navigationBarsPadding
import app.tivi.common.compose.onLoadRun
import app.tivi.common.compose.onPositionInParentChanged
import app.tivi.common.compose.rememberMutableState
import app.tivi.data.entities.Episode
Expand Down Expand Up @@ -317,11 +314,14 @@ private fun InfoPanes(episode: Episode) {

episode.firstAired?.let { firstAired ->
val formatter = TiviDateFormatterAmbient.current
InfoPane(
icon = Icons.Default.CalendarToday,
label = formatter.formatShortRelativeTime(firstAired),
modifier = Modifier.weight(1f)
)
val deferredIcon = loadVectorResource(id = R.drawable.ic_calendar_today)
deferredIcon.onLoadRun { asset ->
InfoPane(
icon = asset,
label = formatter.formatShortRelativeTime(firstAired),
modifier = Modifier.weight(1f)
)
}
}
}
}
Expand Down Expand Up @@ -370,7 +370,7 @@ private fun EpisodeWatchesHeader(onSweepWatchesClick: () -> Unit) {
modifier = Modifier.padding(end = 4.dp),
onClick = { onSweepWatchesClick() }
) {
Icon(asset = Icons.Default.DeleteSweep)
IconResource(R.drawable.ic_delete_sweep)
}
}
}
Expand All @@ -394,16 +394,20 @@ private fun EpisodeWatch(episodeWatchEntry: EpisodeWatchEntry) {

ProvideEmphasis(emphasis = EmphasisAmbient.current.medium) {
if (episodeWatchEntry.pendingAction != PendingAction.NOTHING) {
Icon(
asset = Icons.Filled.Publish,
modifier = Modifier.padding(start = 8.dp).gravity(Alignment.CenterVertically)
IconResource(
resourceId = R.drawable.ic_publish,
modifier = Modifier
.padding(start = 8.dp)
.gravity(Alignment.CenterVertically)
)
}

if (episodeWatchEntry.pendingAction == PendingAction.DELETE) {
Icon(
asset = Icons.Filled.VisibilityOff,
modifier = Modifier.padding(start = 8.dp).gravity(Alignment.CenterVertically)
IconResource(
resourceId = R.drawable.ic_visibility_off,
modifier = Modifier
.padding(start = 8.dp)
.gravity(Alignment.CenterVertically)
)
}
}
Expand Down
1 change: 0 additions & 1 deletion ui-showdetails/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ dependencies {
implementation Libs.AndroidX.Compose.animation
implementation Libs.AndroidX.Compose.tooling
implementation Libs.AndroidX.Compose.livedata
implementation Libs.AndroidX.Compose.iconsExtended

implementation Libs.Mdc.material
implementation Libs.Mdc.composeThemeAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ import androidx.compose.material.Surface
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.CloudUpload
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Providers
import androidx.compose.runtime.Recomposer
Expand All @@ -99,6 +96,7 @@ import androidx.ui.tooling.preview.Preview
import app.tivi.common.compose.AutoSizedCircularProgressIndicator
import app.tivi.common.compose.ExpandableFloatingActionButton
import app.tivi.common.compose.ExpandingText
import app.tivi.common.compose.IconResource
import app.tivi.common.compose.InsetsAmbient
import app.tivi.common.compose.LogCompositions
import app.tivi.common.compose.PopupMenu
Expand Down Expand Up @@ -886,8 +884,8 @@ private fun EpisodeWithWatchesRow(
ProvideEmphasis(EmphasisAmbient.current.medium) {
var needSpacer = false
if (hasPending) {
Icon(
asset = Icons.Default.CloudUpload,
IconResource(
resourceId = R.drawable.ic_cloud_upload,
modifier = Modifier.gravity(Alignment.CenterVertically)
)
needSpacer = true
Expand All @@ -896,10 +894,10 @@ private fun EpisodeWithWatchesRow(
if (needSpacer) {
Spacer(Modifier.preferredWidth(4.dp))
}
Icon(
asset = when {
onlyPendingDeletes -> Icons.Default.VisibilityOff
else -> Icons.Default.Visibility
IconResource(
resourceId = when {
onlyPendingDeletes -> R.drawable.ic_visibility_off
else -> R.drawable.ic_visibility
},
modifier = Modifier.gravity(Alignment.CenterVertically)
)
Expand Down