Commits

Luke Plant  committed 2dc1216

Better behaviour of back button if modals are open

  • Participants
  • Parent commits b29f65b

Comments (0)

Files changed (1)

File src/net/learnscripture/webviewapp/Dashboard.java

 	public String DASHBOARD_URL = BASE_URL + "dashboard/";
 
 	public boolean enablePreferencesMenu = false;
+	public boolean modalIsVisible = false;
 
 	@SuppressLint("SetJavaScriptEnabled") @Override
 	protected void onCreate(Bundle savedInstanceState) {
 			public void onPageStarted(WebView view, String url, Bitmap favicon)
 			{
 				enablePreferencesMenu  = false;
+				modalIsVisible = false;
 				progressBar.setVisibility(View.VISIBLE);
 			}
 
 	public void onBackPressed() {
 		WebView engine = getEngine();
 		String url = engine.getUrl(); 
-		if (url.equals(BASE_URL) ||
+		if (modalIsVisible) {
+			engine.loadUrl("javascript: learnscripture.hideModal();");
+		} else if (url.equals(BASE_URL) ||
 				url.equals(DASHBOARD_URL) ||
 				!engine.canGoBack()) {
 			// exit
 		}
 	}
 
+	// The method of IJavascriptHandler are called from javascript
 	final class IJavascriptHandler {
 		private Dashboard activity;
 
 		}
 
 		public void setEnablePreferencesMenu() {
-			// this is called from JS with passed value
 			activity.enablePreferencesMenu = true;
 		}
+
+		public void setModalIsVisible(boolean visible) {
+			activity.modalIsVisible  = visible;
+		}
 	}
 
 }