Refactor backHistory() code so calling navigator.app.backHistory() has consistent behavior with backbutton.

This commit is contained in:
Bryce Curtis 2011-11-09 23:37:16 -06:00
parent 827af8a920
commit 2a866e2a7c

View File

@ -577,13 +577,27 @@ public class DroidGap extends PhonegapActivity {
/** /**
* Go to previous page in history. (We manage our own history) * Go to previous page in history. (We manage our own history)
*
* @return true if we went back, false if we are already at top
*/ */
public void backHistory() { public boolean backHistory() {
if (this.urls.size() > 1) {
this.urls.pop(); // Pop current url // Check webview first to see if there is a history
String url = this.urls.pop(); // Pop prev url that we want to load // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
this.loadUrl(url); if (this.appView.canGoBack()) {
this.appView.goBack();
return true;
} }
// If our managed history has prev url
if (this.urls.size() > 1) {
this.urls.pop(); // Pop current url
String url = this.urls.pop(); // Pop prev url that we want to load, since it will be added back by loadUrl()
this.loadUrl(url);
return true;
}
return false;
} }
@Override @Override
@ -1466,12 +1480,7 @@ public class DroidGap extends PhonegapActivity {
else { else {
// Go to previous page in webview if it is possible to go back // Go to previous page in webview if it is possible to go back
if (this.appView.canGoBack()) { if (this.backHistory()) {
this.appView.goBack(); // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
return true;
}
else if (this.urls.size() > 1) {
this.backHistory();
return true; return true;
} }