Store last nav item in nav manager

This commit is contained in:
Manfred Karrer 2014-09-15 17:07:58 +02:00
parent e145faf46f
commit 526382bdc0
4 changed files with 17 additions and 27 deletions

View File

@ -17,6 +17,8 @@
package io.bitsquare.gui;
import io.bitsquare.persistence.Persistence;
import com.google.inject.Inject;
import java.util.ArrayList;
@ -27,6 +29,7 @@ import org.slf4j.LoggerFactory;
public class NavigationManager {
private static final Logger log = LoggerFactory.getLogger(NavigationManager.class);
private Persistence persistence;
///////////////////////////////////////////////////////////////////////////////////////////
// Interface
@ -36,7 +39,6 @@ public class NavigationManager {
void onNavigationRequested(NavigationItem... navigationItems);
}
private List<NavigationListener> listeners = new ArrayList<>();
private NavigationItem[] previousMainNavigationItems;
private NavigationItem[] currentNavigationItems;
@ -47,7 +49,8 @@ public class NavigationManager {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public NavigationManager() {
public NavigationManager(Persistence persistence) {
this.persistence = persistence;
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -58,10 +61,18 @@ public class NavigationManager {
previousMainNavigationItems = currentNavigationItems;
currentNavigationItems = navigationItems;
persistence.write(this, "navigationItems", navigationItems);
listeners.stream().forEach((e) -> e.onNavigationRequested(navigationItems));
}
public void navigateToLastStoredItem() {
NavigationItem[] navigationItems = (NavigationItem[]) persistence.read(this, "navigationItems");
if (navigationItems == null || navigationItems.length == 0)
navigationItems = new NavigationItem[]{NavigationItem.HOME};
navigationTo(navigationItems);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Listeners
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -20,7 +20,6 @@ package io.bitsquare.gui.main;
import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.UIModel;
import io.bitsquare.gui.util.Profiler;
import io.bitsquare.msg.MessageFacade;
@ -135,10 +134,6 @@ class MainModel extends UIModel {
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
void setSelectedNavigationItem(NavigationItem navigationItem) {
persistence.write(this, "selectedNavigationItem", navigationItem);
}
void setCurrentBankAccount(BankAccount bankAccount) {
user.setCurrentBankAccount(bankAccount);
persistence.write(user);
@ -157,14 +152,6 @@ class MainModel extends UIModel {
return user.currentBankAccountProperty();
}
NavigationItem[] getSelectedNavigationItems() {
NavigationItem[] selectedNavigationItems = (NavigationItem[]) persistence.read(this, "selectedNavigationItems");
if (selectedNavigationItems == null || selectedNavigationItems.length == 0)
selectedNavigationItems = new NavigationItem[]{NavigationItem.BUY};
return selectedNavigationItems;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private

View File

@ -18,7 +18,6 @@
package io.bitsquare.gui.main;
import io.bitsquare.bank.BankAccount;
import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.PresentationModel;
import io.bitsquare.gui.util.BSFormatter;
@ -112,10 +111,6 @@ class MainPM extends PresentationModel<MainModel> {
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
void setSelectedNavigationItem(NavigationItem navigationItem) {
model.setSelectedNavigationItem(navigationItem);
}
void setCurrentBankAccount(BankAccount bankAccount) {
model.setCurrentBankAccount(bankAccount);
}
@ -125,10 +120,6 @@ class MainPM extends PresentationModel<MainModel> {
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
NavigationItem[] getSelectedNavigationItems() {
return model.getSelectedNavigationItems();
}
ObservableList<BankAccount> getBankAccounts() {
return model.getBankAccounts();
}

View File

@ -152,7 +152,6 @@ public class MainViewCB extends ViewCB<MainPM> {
if (childController instanceof ViewCB)
((ViewCB) childController).setParent(this);
presentationModel.setSelectedNavigationItem(navigationItem);
return childController;
} catch (IOException e) {
e.getStackTrace();
@ -211,7 +210,7 @@ public class MainViewCB extends ViewCB<MainPM> {
AWTSystemTray.setAlert();
});
navigationManager.navigationTo(presentationModel.getSelectedNavigationItems());
navigationManager.navigateToLastStoredItem();
onContentAdded();
}
@ -400,7 +399,9 @@ public class MainViewCB extends ViewCB<MainPM> {
}
});
toggleButton.setOnAction(e -> loadView(navigationItem));
toggleButton.setOnAction(e -> navigationManager.navigationTo(navigationItem));
// toggleButton.setOnAction(e -> loadView(navigationItem));
parent.getChildren().add(toggleButton);
return toggleButton;
}