Skip to content

Commit

Permalink
ui: change most toolbar default icon to Icons
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Sep 25, 2024
1 parent 4404717 commit faafa84
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 55 deletions.
47 changes: 29 additions & 18 deletions app/src/main/java/info/plateaukao/einkbro/view/compose/Toolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,35 @@ fun ToolbarIcon(
val pressed by interactionSource.collectIsPressedAsState()
val borderWidth = if (pressed) 0.5.dp else (-1).dp

Icon(
modifier = Modifier
.fillMaxHeight()
.width(toolbarIconWidth)
.padding(6.dp)
.border(borderWidth, MaterialTheme.colors.onBackground, RoundedCornerShape(7.dp))
.combinedClickable(
indication = null,
interactionSource = interactionSource,
onClick = { onClick(toolbarAction) },
onLongClick = { onLongClick?.invoke(toolbarAction) }
)
.padding(6.dp)
.testTag(toolbarAction.name.lowercase()),
painter = painterResource(id = iconResId),
contentDescription = stringResource(id = toolbarAction.titleResId),
tint = MaterialTheme.colors.onBackground
)
val modifier = Modifier
.fillMaxHeight()
.width(toolbarIconWidth)
.padding(6.dp)
.border(borderWidth, MaterialTheme.colors.onBackground, RoundedCornerShape(7.dp))
.combinedClickable(
indication = null,
interactionSource = interactionSource,
onClick = { onClick(toolbarAction) },
onLongClick = { onLongClick?.invoke(toolbarAction) }
)
.padding(6.dp)
.testTag(toolbarAction.name.lowercase())

if (iconResId != 0) {
Icon(
modifier = modifier,
painter = painterResource(id = iconResId),
contentDescription = stringResource(id = toolbarAction.titleResId),
tint = MaterialTheme.colors.onBackground
)
} else {
Icon(
modifier = modifier,
imageVector = toolbarAction.imageVector!!,
contentDescription = stringResource(id = toolbarAction.titleResId),
tint = MaterialTheme.colors.onBackground
)
}
}

@OptIn(ExperimentalFoundationApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -151,6 +152,7 @@ fun ToggleItem(
state: Boolean,
titleResId: Int,
iconResId: Int,
imageVector: ImageVector? = null,
isEnabled: Boolean = true,
onEditAction: (() -> Unit)? = null,
onClicked: (Boolean) -> Unit,
Expand Down Expand Up @@ -195,6 +197,15 @@ fun ToggleItem(
tint = MaterialTheme.colors.onBackground
)
}
if (imageVector != null) {
Icon(
imageVector = imageVector, contentDescription = null,
modifier = Modifier
.padding(horizontal = 6.dp)
.fillMaxHeight(),
tint = MaterialTheme.colors.onBackground
)
}
Spacer(
modifier = Modifier
.width(6.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.SettingsSuggest
import androidx.compose.material.icons.outlined.Share
import androidx.compose.material.icons.outlined.Splitscreen
import androidx.compose.material.icons.outlined.Straighten
import androidx.compose.material.icons.outlined.TouchApp
import androidx.compose.material.icons.outlined.Translate
import androidx.compose.material.icons.outlined.ViewColumn
import androidx.compose.material.icons.outlined.ViewStream
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -273,7 +273,7 @@ private fun MenuItems(
) {
MenuItem(
R.string.split_screen,
Icons.Outlined.Splitscreen,
Icons.Outlined.ViewStream,
) { onClicked(MenuItemType.SplitScreen) }
MenuItem(
R.string.translate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fun ToolbarToggleItem(
state = info.isOn,
titleResId = info.toolbarAction.titleResId,
iconResId = info.toolbarAction.iconResId,
imageVector = info.toolbarAction.imageVector,
isEnabled = shouldEnableCheckClick,
// settings should not be clickable, and always there
onClicked = { if (info.toolbarAction != ToolbarAction.Settings) onItemClicked(info.toolbarAction) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,75 @@
package info.plateaukao.einkbro.view.toolbaricons

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ChromeReaderMode
import androidx.compose.material.icons.automirrored.outlined.KeyboardArrowLeft
import androidx.compose.material.icons.automirrored.outlined.KeyboardArrowRight
import androidx.compose.material.icons.automirrored.outlined.RotateRight
import androidx.compose.material.icons.automirrored.outlined.Segment
import androidx.compose.material.icons.automirrored.outlined.Toc
import androidx.compose.material.icons.outlined.AccessTime
import androidx.compose.material.icons.outlined.Bookmarks
import androidx.compose.material.icons.outlined.CancelPresentation
import androidx.compose.material.icons.outlined.DesktopWindows
import androidx.compose.material.icons.outlined.Download
import androidx.compose.material.icons.outlined.FolderCopy
import androidx.compose.material.icons.outlined.FormatSize
import androidx.compose.material.icons.outlined.Fullscreen
import androidx.compose.material.icons.outlined.GTranslate
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.LibraryAdd
import androidx.compose.material.icons.outlined.Menu
import androidx.compose.material.icons.outlined.Minimize
import androidx.compose.material.icons.outlined.ModeEdit
import androidx.compose.material.icons.outlined.Pin
import androidx.compose.material.icons.outlined.RecordVoiceOver
import androidx.compose.material.icons.outlined.Refresh
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.SpaceBar
import androidx.compose.material.icons.outlined.Straighten
import androidx.compose.material.icons.outlined.Swipe
import androidx.compose.material.icons.outlined.SwipeVertical
import androidx.compose.material.icons.outlined.TextDecrease
import androidx.compose.material.icons.outlined.TextIncrease
import androidx.compose.material.icons.outlined.TouchApp
import androidx.compose.material.icons.outlined.Translate
import androidx.compose.material.icons.outlined.Upload
import androidx.compose.material.icons.outlined.ViewColumn
import androidx.compose.ui.graphics.vector.ImageVector
import info.plateaukao.einkbro.R

enum class ToolbarAction(
val iconResId: Int = 0,
val imageVector: ImageVector? = null,
val titleResId: Int,
val iconActiveInfo: IconActiveInfo = IconActiveInfo(isActivable = false),
val isAddable: Boolean = true,
) {
Title(iconResId = R.drawable.icon_info, titleResId = R.string.toolbar_title), // 0
Back(iconResId = R.drawable.icon_arrow_left_gest, titleResId = R.string.back),
Title(imageVector = Icons.Outlined.Info, titleResId = R.string.toolbar_title), // 0
Back(imageVector = Icons.AutoMirrored.Outlined.KeyboardArrowLeft, titleResId = R.string.back),
Refresh(
iconResId = R.drawable.icon_refresh,
imageVector = Icons.Outlined.Refresh,
titleResId = R.string.refresh,
iconActiveInfo = IconActiveInfo(true, R.drawable.ic_stop, R.drawable.icon_refresh)
),
Touch(
iconResId = R.drawable.ic_touch_enabled,
imageVector = Icons.Outlined.TouchApp,
titleResId = R.string.touch_turn_page,
iconActiveInfo = IconActiveInfo(
true,
R.drawable.ic_touch_enabled,
R.drawable.ic_touch_disabled
)
),
PageUp(iconResId = R.drawable.ic_page_up, titleResId = R.string.page_up),
PageDown(iconResId = R.drawable.ic_page_down, titleResId = R.string.page_down),
TabCount(iconResId = R.drawable.icon_preview, titleResId = R.string.tab_preview),
Font(iconResId = R.drawable.icon_size, titleResId = R.string.font_size),
Settings(iconResId = R.drawable.ic_menu, titleResId = R.string.settings),
Bookmark(iconResId = R.drawable.ic_bookmarks, titleResId = R.string.bookmarks),
IconSetting(iconResId = R.drawable.ic_toolbar, titleResId = R.string.toolbars),
VerticalLayout(iconResId = R.drawable.ic_vertical_read, titleResId = R.string.vertical_read),
ReaderMode(iconResId = R.drawable.ic_reader, titleResId = R.string.reader_mode),
PageUp(imageVector = Icons.Outlined.Upload, titleResId = R.string.page_up),
PageDown(imageVector = Icons.Outlined.Download, titleResId = R.string.page_down),
TabCount(imageVector = Icons.Outlined.Pin, titleResId = R.string.tab_preview),
Font(imageVector = Icons.Outlined.FormatSize, titleResId = R.string.font_size),
Settings(imageVector = Icons.Outlined.Menu, titleResId = R.string.settings),
Bookmark(imageVector = Icons.Outlined.Bookmarks, titleResId = R.string.bookmarks),
IconSetting(imageVector = Icons.Outlined.Straighten, titleResId = R.string.toolbars),
VerticalLayout(imageVector = Icons.Outlined.ViewColumn, titleResId = R.string.vertical_read),
ReaderMode(imageVector = Icons.AutoMirrored.Outlined.ChromeReaderMode, titleResId = R.string.reader_mode),
BoldFont(
iconResId = R.drawable.ic_bold_font,
titleResId = R.string.bold_font,
Expand All @@ -42,29 +79,29 @@ enum class ToolbarAction(
R.drawable.ic_bold_font
)
),
IncreaseFont(iconResId = R.drawable.ic_font_increase, titleResId = R.string.font_size_increase),
DecreaseFont(iconResId = R.drawable.ic_font_decrease, titleResId = R.string.font_size_decrease),
FullScreen(iconResId = R.drawable.icon_fullscreen, titleResId = R.string.fullscreen),
Forward(iconResId = R.drawable.icon_arrow_right_gest, titleResId = R.string.forward),
RotateScreen(iconResId = R.drawable.ic_rotate, titleResId = R.string.rotate),
Translation(iconResId = R.drawable.ic_translate, titleResId = R.string.translate),
CloseTab(iconResId = R.drawable.icon_close, titleResId = R.string.close_tab),
InputUrl(iconResId = R.drawable.ic_input_url, titleResId = R.string.input_url),
NewTab(iconResId = R.drawable.icon_plus, titleResId = R.string.open_new_tab),
IncreaseFont(imageVector = Icons.Outlined.TextIncrease, titleResId = R.string.font_size_increase),
DecreaseFont(imageVector = Icons.Outlined.TextDecrease, titleResId = R.string.font_size_decrease),
FullScreen(imageVector = Icons.Outlined.Fullscreen, titleResId = R.string.fullscreen),
Forward(imageVector = Icons.AutoMirrored.Outlined.KeyboardArrowRight, titleResId = R.string.forward),
RotateScreen(imageVector = Icons.AutoMirrored.Outlined.RotateRight, titleResId = R.string.rotate),
Translation(imageVector = Icons.Outlined.Translate, titleResId = R.string.translate),
CloseTab(imageVector = Icons.Outlined.CancelPresentation, titleResId = R.string.close_tab),
InputUrl(imageVector = Icons.Outlined.ModeEdit, titleResId = R.string.input_url),
NewTab(imageVector = Icons.Outlined.LibraryAdd, titleResId = R.string.open_new_tab),
Desktop(
iconResId = R.drawable.icon_desktop,
imageVector = Icons.Outlined.DesktopWindows,
titleResId = R.string.desktop_mode,
iconActiveInfo = IconActiveInfo(
true,
R.drawable.icon_desktop_activate,
R.drawable.icon_desktop
)
),
TOC(iconResId = R.drawable.ic_toc, titleResId = R.string.title_in_toc, isAddable = false),
Search(iconResId = R.drawable.icon_search, titleResId = R.string.setting_title_search),
DuplicateTab(iconResId = R.drawable.ic_copy, titleResId = R.string.duplicate_tab),
TOC(imageVector = Icons.AutoMirrored.Outlined.Toc, titleResId = R.string.title_in_toc, isAddable = false),
Search(imageVector = Icons.Outlined.Search, titleResId = R.string.setting_title_search),
DuplicateTab(imageVector = Icons.Outlined.FolderCopy, titleResId = R.string.duplicate_tab),
Tts(
iconResId = R.drawable.ic_tts,
imageVector = Icons.Outlined.RecordVoiceOver,
titleResId = R.string.menu_tts,
iconActiveInfo = IconActiveInfo(
true,
Expand All @@ -74,23 +111,23 @@ enum class ToolbarAction(
),
PageInfo(iconResId = R.drawable.ic_page_count, titleResId = R.string.page_count),
GoogleInPlace(
iconResId = R.drawable.ic_translate_google,
imageVector = Icons.Outlined.GTranslate,
titleResId = R.string.google_in_place
),
TranslateByParagraph(
iconResId = R.drawable.ic_translate_paragraph,
imageVector = Icons.AutoMirrored.Outlined.Segment,
titleResId = R.string.inter_translate
),
PapagoByParagraph(
iconResId = R.drawable.ic_papago,
titleResId = R.string.papago
),
MoveToBackground(
iconResId = R.drawable.ic_minimize,
imageVector = Icons.Outlined.Minimize,
titleResId = R.string.move_to_background
),
TouchDirectionUpDown(
iconResId = R.drawable.ic_touch_direction_up,
imageVector = Icons.Outlined.SwipeVertical,
titleResId = R.string.switch_touch_area_action_short,
iconActiveInfo = IconActiveInfo(
true,
Expand All @@ -99,7 +136,7 @@ enum class ToolbarAction(
)
),
TouchDirectionLeftRight(
iconResId = R.drawable.ic_touch_direction_left,
imageVector = Icons.Outlined.Swipe,
titleResId = R.string.switch_touch_area_action_short,
iconActiveInfo = IconActiveInfo(
true,
Expand All @@ -108,15 +145,15 @@ enum class ToolbarAction(
)
),
Time(
iconResId = R.drawable.ic_history,
imageVector = Icons.Outlined.AccessTime,
titleResId = R.string.toolbar_time,
),
Spacer1(
iconResId = 0,
imageVector = Icons.Outlined.SpaceBar,
titleResId = R.string.expand_space,
),
Spacer2(
iconResId = 0,
imageVector = Icons.Outlined.SpaceBar,
titleResId = R.string.expand_space,
),
;
Expand Down

0 comments on commit faafa84

Please sign in to comment.