Create preference to disable swipe to refresh when not desired. Remove -standard...
authorSoren Stoutner <soren@stoutner.com>
Fri, 6 May 2016 03:04:05 +0000 (20:04 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 6 May 2016 03:04:05 +0000 (20:04 -0700)
app/build.gradle
app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java
app/src/main/res/menu/menu_options.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index 03805931e9d78b07ad5a23d65172cd1c0e8ebb97..dffcddd97fa45be6f378fa4f43c78f17b65fa9e3 100644 (file)
@@ -43,12 +43,10 @@ android {
     productFlavors {
         standard {
             applicationId "com.stoutner.privacybrowser.standard"
-            versionName "1.4-standard"
         }
 
         free {
             applicationId "com.stoutner.privacybrowser.free"
-            versionName "1.4-free"
         }
     }
 }
index bcbdd9f30480ab7ff28f94b8e0bcdd23bab90d9e..99fef852d35edf0618b5a448095d3f9171d8ef33 100644 (file)
@@ -84,6 +84,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
     public static boolean domStorageEnabled;
     // homepage is public static so it can be accessed from  SettingsFragment.  It is also used in onCreate() and onOptionsItemSelected().
     public static String homepage;
+    // swipeToRefresh is public static so it can be accessed from SettingsFragment.  It is also used in onCreate().
+    public static SwipeRefreshLayout swipeToRefresh;
+    // swipeToRefreshEnabled is public static so it can be accessed from SettingsFragment.  It is also used in onCreate().
+    public static boolean swipeToRefreshEnabled;
 
     // drawerToggle is used in onCreate(), onPostCreate(), onConfigurationChanged(), onNewIntent(), and onNavigationItemSelected().
     private ActionBarDrawerToggle drawerToggle;
@@ -115,7 +119,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         final View adView = findViewById(R.id.adView);
 
         // Implement swipe to refresh
-        final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
+        swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
         swipeToRefresh.setColorSchemeResources(R.color.blue);
         swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
             @Override
@@ -303,6 +307,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Hide zoom controls.
         mainWebView.getSettings().setDisplayZoomControls(false);
 
+
         // Initialize the default preference values the first time the program is run.
         PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
 
@@ -333,6 +338,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Set homepage initial status.
         homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com");
 
+        // Set swipe to refresh initial status.  The default is true.
+        swipeToRefreshEnabled = savedPreferences.getBoolean("swipe_to_refresh_enabled", true);
+        swipeToRefresh.setEnabled(swipeToRefreshEnabled);
+
+
         // Get the intent information that started the app.
         final Intent intent = getIntent();
 
@@ -592,6 +602,9 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below.
                 return true;
 
+            case R.id.refresh:
+                mainWebView.reload();
+
             default:
                 return super.onOptionsItemSelected(menuItem);
         }
index 9f11cb5f48c7f457f1417e2571435a98ddf52879..35021b3e8d09dcb333bf70d2954fc98123cf4a95 100644 (file)
@@ -143,6 +143,13 @@ public class SettingsFragment extends PreferenceFragment {
                         MainWebViewActivity.homepage = sharedPreferences.getString("homepage", "https://www.duckduckgo.com");
                         return;
 
+                    case "swipe_to_refresh_enabled":
+                        // Set swipeToRefreshEnabled to the new state.  The default is true.
+                        MainWebViewActivity.swipeToRefreshEnabled = sharedPreferences.getBoolean("swipe_to_refresh_enabled", true);
+
+                        // Update swipeRefreshLayout to match the new state.
+                        MainWebViewActivity.swipeToRefresh.setEnabled(MainWebViewActivity.swipeToRefreshEnabled);
+
                     // If no match, do nothing.
                     default:
                 }
@@ -153,6 +160,8 @@ public class SettingsFragment extends PreferenceFragment {
         savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
     }
 
+    // It is necessary to reregister the listener on every resume or it will randomly stop working for the user because apps can be paused and resumed at any time,
+    // even when they are in the foreground.
     @Override
     public void onResume() {
         super.onResume();
index 038b364ff0a7e75d26a4cc6899574b979794944f..5655644a6d807876953ffe1a89cffeb6aeb59aa8 100644 (file)
         android:title="@string/add_to_home_screen"
         android:orderInCategory="80"
         app:showAsAction="never" />
+
+    <item
+        android:id="@+id/refresh"
+        android:title="@string/refresh"
+        android:orderInCategory="90"
+        app:showAsAction="never" />
 </menu>
index 2805c5dbf898762cfd545fd2e0d72ae20d757e5a..efc7e659459c1d4651568ef115539fdec4476d6f 100644 (file)
@@ -62,6 +62,7 @@
     <string name="clear_dom_storage">Clear DOM Storage</string>
     <string name="share">Share</string>
     <string name="add_to_home_screen">Add to Home Screen</string>
+    <string name="refresh">Refresh</string>
 
     <!-- Create Home Screen Shortcut Alert Dialog. -->
     <string name="shortcut_name">Shortcut name</string>
@@ -84,6 +85,8 @@
         that allows websites to store larger and more complex types of information, like pictures, on your device.</string>
     <string name="general_settings">General Settings</string>
     <string name="homepage_preference">Homepage</string>
+    <string name="swipe_to_refresh_enabled">Swipe to refresh</string>
+    <string name="swipe_to_refresh_enabled_summary">Some websites don\'t work well if swipe to refresh is enabled.</string>
 
     <!-- About Dialog. -->
     <string name="about_privacy_browser">About Privacy Browser</string>
index bc300f002268bdc8ca9ad77aa6cec9a6d546e0b1..747778e776380769b8a0e87b450283e20ccdebff 100644 (file)
             android:defaultValue="https://www.duckduckgo.com"
             android:inputType="textUri"
             android:singleLine="true" />
+
+        <SwitchPreference
+            android:key="swipe_to_refresh_enabled"
+            android:title="@string/swipe_to_refresh_enabled"
+            android:summary="@string/swipe_to_refresh_enabled_summary"
+            android:defaultValue="true" />
     </PreferenceCategory>
 </PreferenceScreen>
\ No newline at end of file