Skip to content

Commit

Permalink
3 brand new themes (closes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x192 committed Oct 6, 2021
1 parent 123b7c2 commit 7f748fc
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 174 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and `Removed`.
- Multi-user support (#16): You can now debloat/restore for any user of the phone (not only the primary user 0).
- `Multi user mode` setting (default to on for Android 5+) allowing to remove packages for all users ([a work profile is another user](https://developer.android.com/work/managed-profiles)) instead of only the selected user.
- User switcher (picklist).
- New themes! (#11) : light, dark and dracula. Dracula theme is now the new default theme. Themes can be changed from the settings.

## Fixed
- [Regression] Unsafe packages can be deleted without enabling `expert mode`.
Expand Down Expand Up @@ -57,4 +58,4 @@ and `Removed`.

### Fixed
- Spelling mistake
- Failed build with MSVC toolchain
- Failed build with MSVC toolchain
3 changes: 2 additions & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod sync;
pub mod uad_lists;
pub mod utils;
pub mod utils;
pub mod theme;
176 changes: 176 additions & 0 deletions src/core/theme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
use std::cmp::Ordering;
use iced::Color;

#[derive(Debug, Clone)]
pub struct Theme {
pub name: String,
pub palette: ColorPalette,
}

#[derive(Debug, Clone, Copy)]
pub struct BaseColors {
pub background: Color,
pub foreground: Color,
}

#[derive(Debug, Clone, Copy)]
pub struct NormalColors {
pub primary: Color,
pub secondary: Color,
pub surface: Color,
pub error: Color,
}

#[derive(Debug, Clone, Copy)]
pub struct BrightColors {
pub primary: Color,
pub secondary: Color,
pub surface: Color,
pub error: Color,
}

#[derive(Debug, Clone, Copy)]
pub struct ColorPalette {
pub base: BaseColors,
pub normal: NormalColors,
pub bright: BrightColors,
}

impl Theme {
pub fn all() -> Vec<Theme> {
vec![
Theme::dark(),
Theme::light(),
Theme::lupin(),
]
}

pub fn dark() -> Theme {
Theme {
name: "Dark".to_string(),
palette: ColorPalette {
base: BaseColors {
background: hex_to_color("#111111").unwrap(),
foreground: hex_to_color("#1C1C1C").unwrap(),
},
normal: NormalColors {
primary: hex_to_color("#3f2b56").unwrap(),
secondary: hex_to_color("#386e50").unwrap(),
surface: hex_to_color("#828282").unwrap(),
error: hex_to_color("#992B2B").unwrap(),
},
bright: BrightColors {
primary: hex_to_color("#BA84FC").unwrap(),
secondary: hex_to_color("#49eb7a").unwrap(),
surface: hex_to_color("#E0E0E0").unwrap(),
error: hex_to_color("#C13047").unwrap(),
},
},
}
}

pub fn light() -> Theme {
Theme {
name: "Light".to_string(),
palette: ColorPalette {
base: BaseColors {
background: hex_to_color("#EEEEEE").unwrap(),
foreground: hex_to_color("#E0E0E0").unwrap(),
},
normal: NormalColors {
primary: hex_to_color("#673AB7").unwrap(),
secondary: hex_to_color("#F9D659").unwrap(),
surface: hex_to_color("#818181").unwrap(),
error: hex_to_color("#992B2B").unwrap(),
},
bright: BrightColors {
primary: hex_to_color("#673AB7").unwrap(),
secondary: hex_to_color("#3797A4").unwrap(),
surface: hex_to_color("#000000").unwrap(),
error: hex_to_color("#C13047").unwrap(),
},
},
}
}

pub fn lupin() -> Theme {
Theme {
name: "Lupin".to_string(),
palette: ColorPalette {
base: BaseColors {
background: hex_to_color("#282a36").unwrap(),
foreground: hex_to_color("#353746").unwrap(),
},
normal: NormalColors {
primary: hex_to_color("#483e61").unwrap(),
secondary: hex_to_color("#386e50").unwrap(),
surface: hex_to_color("#a2a4a3").unwrap(),
error: hex_to_color("#A13034").unwrap(),
},
bright: BrightColors {
primary: hex_to_color("#bd94f9").unwrap(),
secondary: hex_to_color("#49eb7a").unwrap(),
surface: hex_to_color("#f4f8f3").unwrap(),
error: hex_to_color("#cc0000").unwrap(),
},
},
}
}

}

impl PartialEq for Theme {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}

impl PartialOrd for Theme {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.name.cmp(&other.name))
}
}

impl Eq for Theme {}

impl Ord for Theme {
fn cmp(&self, other: &Self) -> Ordering {
self.name.cmp(&other.name)
}
}

impl std::fmt::Display for Theme {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self.name.as_str() {
"Dark" => "Dark",
"Light" => "Light",
"Lupin" => "Lupin",
_ => "Unknown theme",
}
)
}
}

fn hex_to_color(hex: &str) -> Option<Color> {
if hex.len() == 7 {
let hash = &hex[0..1];
let r = u8::from_str_radix(&hex[1..3], 16);
let g = u8::from_str_radix(&hex[3..5], 16);
let b = u8::from_str_radix(&hex[5..7], 16);

return match (hash, r, g, b) {
("#", Ok(r), Ok(g), Ok(b)) => Some(Color {
r: r as f32 / 255.0,
g: g as f32 / 255.0,
b: b as f32 / 255.0,
a: 1.0,
}),
_ => None,
};
}

None
}
12 changes: 6 additions & 6 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Application for UadGui {
let apps_btn = Button::new(&mut self.apps_btn, Text::new("Apps"))
.on_press(Message::AppsPress)
.padding(5)
.style(style::PrimaryButton::Enabled);
.style(style::PrimaryButton(self.settings_view.theme.palette));

#[cfg(feature = "wgpu")]
#[allow(unused_variables)]
Expand All @@ -128,19 +128,19 @@ impl Application for UadGui {
let apps_refresh_btn = Button::new(&mut self.apps_refresh_btn, refresh_btn_display)
.on_press(Message::AppsRefreshPress)
.padding(5)
.style(style::PrimaryButton::Enabled);
.style(style::RefreshButton(self.settings_view.theme.palette));

let uad_version = Text::new(env!("CARGO_PKG_VERSION"));

let about_btn = Button::new(&mut self.about_btn, Text::new("About"))
.on_press(Message::AboutPressed)
.padding(5)
.style(style::PrimaryButton::Enabled);
.style(style::PrimaryButton(self.settings_view.theme.palette));

let settings_btn = Button::new(&mut self.settings_btn, Text::new("Settings"))
.on_press(Message::SettingsPressed)
.padding(5)
.style(style::PrimaryButton::Enabled);
.style(style::PrimaryButton(self.settings_view.theme.palette));

let row = Row::new()
.width(Length::Fill)
Expand All @@ -157,11 +157,11 @@ impl Application for UadGui {
let navigation_container = Container::new(row)
.width(Length::Fill)
.padding(10)
.style(style::NavigationContainer);
.style(style::NavigationContainer(self.settings_view.theme.palette));

let main_container = match self.view {
View::List => self.apps_view.view(&self.settings_view, &self.phone).map(Message::AppsAction),
View::About => self.about_view.view(),
View::About => self.about_view.view(&self.settings_view),
View::Settings => self.settings_view.view().map(Message::SettingsAction),
};

Expand Down
Loading

0 comments on commit 7f748fc

Please sign in to comment.