--- a/app/src/main/java/com/codesys/forge/MainActivity.java +++ b/app/src/main/java/com/codesys/forge/MainActivity.java @@ -68,14 +68,18 @@ private Context myContext; private WebView myWebView; private static final String TAG = "Main"; - private String currentURL; private BottomNavigationView bottomnav; private SwipeRefreshLayout refreshLayout; - private Boolean xNews; - private Boolean xProjects; - private Boolean xTalk; private ViewTreeObserver.OnScrollChangedListener onScrollChangedListener; - private Boolean xOffline; + // + // When rotating the device, onCreate is rerun, and the instance is recreated. + // We make everything that should survive this layout change static. + // + private static String currentURL = "https://forge.codesys.com/forge/community-feed"; + private static Boolean xOffline; + private static Boolean xNews; + private static Boolean xProjects; + private static Boolean xTalk; // cache directory private File getLocalCacheDir() { @@ -142,6 +146,7 @@ protected void loadUrl(String Url, String Title) { refreshLayout.setRefreshing(true); + currentURL = Url; myWebView.loadUrl(Url); } @@ -266,7 +271,7 @@ } else { - setOnline(); + setOffline(); } myWebView.loadUrl(currentURL); @@ -315,7 +320,6 @@ // reload page refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); refreshLayout.setOnRefreshListener(this); - myWebView.loadUrl("https://forge.codesys.com"); // Override URL Loading myWebView.setWebViewClient(new WebViewClient() { @@ -396,6 +400,10 @@ // remote request if (url.toString().startsWith("https://forge.codesys.com")) { + if(!getNetworkState()) { + xOffline = true; + } + if (!getOffline()) { // online => cache all files @@ -424,6 +432,11 @@ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // load local file, stating that we're offline + /* + File cacheDir = getLocalCacheDir(); + File fileName = new File(cacheDir, "default.html"); + view.loadUrl("file://" + fileName.toString()); + */ refreshLayout.setRefreshing(false); setOffline(); } @@ -456,7 +469,7 @@ // bottomnav = findViewById(R.id.bottomNavigationView); bottomnav.setOnNavigationItemSelectedListener(navListener); - loadUrl("https://forge.codesys.com/forge/community-feed", "Community"); + ReLoadWebView(currentURL); } // back button @@ -519,6 +532,9 @@ break; } menuItem.setChecked(true); +// getNews(); +// notification(); + return true; } };