Implement main menu
This commit is contained in:
parent
e30e71516e
commit
8c9afa6128
@ -272,31 +272,23 @@ impl State for EnterPinState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
enum MainMenuItem {
|
enum MainMenuItem {
|
||||||
#[default]
|
#[default]
|
||||||
Item1,
|
SendSMS,
|
||||||
Item2,
|
ReadSMS,
|
||||||
Item3,
|
|
||||||
Item4,
|
|
||||||
Item5,
|
|
||||||
Item6,
|
|
||||||
}
|
}
|
||||||
impl MenuItem for MainMenuItem {
|
impl MenuItem for MainMenuItem {
|
||||||
fn as_text(&self) -> String {
|
fn as_text(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
MainMenuItem::Item1 => "item1",
|
MainMenuItem::SendSMS => "Send SMS",
|
||||||
MainMenuItem::Item2 => "item2",
|
MainMenuItem::ReadSMS => "Read SMS",
|
||||||
MainMenuItem::Item3 => "item3",
|
|
||||||
MainMenuItem::Item4 => "item4",
|
|
||||||
MainMenuItem::Item5 => "item5",
|
|
||||||
MainMenuItem::Item6 => "item6",
|
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MainMenuState {
|
pub struct MainMenuState {
|
||||||
menu: Menu<MainMenuItem>,
|
menu: Menu<MainMenuItem>,
|
||||||
}
|
}
|
||||||
@ -305,19 +297,20 @@ impl Default for MainMenuState {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
menu: Menu::default()
|
menu: Menu::default()
|
||||||
.with_item(MainMenuItem::Item1)
|
.with_item(MainMenuItem::SendSMS)
|
||||||
.with_item(MainMenuItem::Item2)
|
.with_item(MainMenuItem::ReadSMS),
|
||||||
.with_item(MainMenuItem::Item3)
|
|
||||||
.with_item(MainMenuItem::Item4)
|
|
||||||
.with_item(MainMenuItem::Item5)
|
|
||||||
.with_item(MainMenuItem::Item6),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State for MainMenuState {
|
impl State for MainMenuState {
|
||||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||||
self.menu.poll(&mut data.io);
|
if let Some(option) = self.menu.poll(&mut data.io) {
|
||||||
|
match option {
|
||||||
|
MainMenuItem::SendSMS => return Some(Box::new(PhoneNumberState::default())),
|
||||||
|
MainMenuItem::ReadSMS => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,15 +368,15 @@ impl State for MessageState {
|
|||||||
|resp| match resp.unwrap() {
|
|resp| match resp.unwrap() {
|
||||||
SendSMSResponse::MessageRefrence(refrence) => Box::new(TextState {
|
SendSMSResponse::MessageRefrence(refrence) => Box::new(TextState {
|
||||||
text: format!("SMS sent\nRef: {}", refrence),
|
text: format!("SMS sent\nRef: {}", refrence),
|
||||||
after: PhoneNumberState::default(),
|
after: MainMenuState::default(),
|
||||||
}),
|
}),
|
||||||
SendSMSResponse::Error => Box::new(TextState {
|
SendSMSResponse::Error => Box::new(TextState {
|
||||||
text: "ERROR!".to_owned(),
|
text: "ERROR!".to_owned(),
|
||||||
after: PhoneNumberState::default(),
|
after: MainMenuState::default(),
|
||||||
}),
|
}),
|
||||||
SendSMSResponse::ErrorMessage(msg) => Box::new(TextState {
|
SendSMSResponse::ErrorMessage(msg) => Box::new(TextState {
|
||||||
text: format!("Error:\n{}", msg),
|
text: format!("Error:\n{}", msg),
|
||||||
after: PhoneNumberState::default(),
|
after: MainMenuState::default(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
)))
|
)))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user