Browse Source

replace Snackbar calls with utils calls

AndyScherzinger 6 years ago
parent
commit
99225f1282

+ 6 - 13
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -90,7 +90,6 @@ import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.TextView.OnEditorActionListener;
-import android.widget.Toast;
 
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
@@ -430,7 +429,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         new Handler().postDelayed(new Runnable() {
             @Override
             public void run() {
-                Snackbar.make(mLoginWebView, R.string.fallback_weblogin_text, Snackbar.LENGTH_INDEFINITE)
+                DisplayUtils.createSnackbar(mLoginWebView, R.string.fallback_weblogin_text, Snackbar.LENGTH_INDEFINITE)
                         .setActionTextColor(getResources().getColor(R.color.primary_dark))
                         .setAction(R.string.fallback_weblogin_back, new View.OnClickListener() {
                             @Override
@@ -969,8 +968,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 try {
                     populateLoginFields(dataString);
                 } catch (IllegalArgumentException e) {
-                    Snackbar.make(findViewById(R.id.scroll), "Illegal login data URL used",
-                            Snackbar.LENGTH_SHORT).show();
+                    DisplayUtils.showSnackMessage(findViewById(R.id.scroll), R.string.auth_illegal_login_used);
                     Log_OC.e(TAG, "Illegal login data URL used, no Login pre-fill!", e);
                 }
             }
@@ -981,9 +979,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         if (!bindService(new Intent(this, OperationsService.class),
                 mOperationsServiceConnection,
                 Context.BIND_AUTO_CREATE)) {
-            Snackbar.make(findViewById(R.id.scroll), R.string.error_cant_bind_to_operations_service,
-                    Snackbar.LENGTH_LONG)
-                    .show();
+            DisplayUtils.showSnackMessage(findViewById(R.id.scroll), R.string.error_cant_bind_to_operations_service);
             finish();
         }
 
@@ -1378,8 +1374,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
                     } catch (AccountNotFoundException e) {
                         Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
-                        Snackbar.make(findViewById(R.id.scroll), R.string.auth_account_does_not_exist,
-                                Snackbar.LENGTH_SHORT).show();
+                        DisplayUtils.showSnackMessage(findViewById(R.id.scroll), R.string.auth_account_does_not_exist);
                         finish();
                     }
                 }
@@ -1706,8 +1701,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
                 } catch (AccountNotFoundException e) {
                     Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
-                    Snackbar.make(findViewById(R.id.scroll), R.string.auth_account_does_not_exist,
-                            Snackbar.LENGTH_SHORT).show();
+                    DisplayUtils.showSnackMessage(findViewById(R.id.scroll), R.string.auth_account_does_not_exist);
                     finish();
                 }
             }
@@ -1769,8 +1763,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 mLoginWebView = findViewById(R.id.login_webview);
                 initWebViewLogin(mServerInfo.mBaseUrl);
 
-                Snackbar.make(mLoginWebView, getString(R.string.auth_access_failed) + ": " + result.getLogMessage(),
-                        Snackbar.LENGTH_LONG).show();
+                DisplayUtils.showSnackMessage(this, mLoginWebView, R.string.auth_access_failed, result.getLogMessage());
             } else {
                 updateAuthStatusIconAndText(result);
                 showAuthStatus();

+ 7 - 11
src/main/java/com/owncloud/android/ui/activity/ErrorsWhileCopyingHandlerActivity.java

@@ -27,7 +27,6 @@ import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.annotation.NonNull;
-import android.support.design.widget.Snackbar;
 import android.support.v4.app.DialogFragment;
 import android.support.v7.app.AppCompatActivity;
 import android.text.method.ScrollingMovementMethod;
@@ -45,13 +44,13 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
+import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 
 import java.io.File;
 import java.util.ArrayList;
 
 
-
 /**
  * Activity reporting errors occurred when local files uploaded to an ownCloud account with an app
  * in version under 1.3.16 where being copied to the ownCloud local folder.
@@ -251,12 +250,12 @@ public class ErrorsWhileCopyingHandlerActivity  extends AppCompatActivity implem
 
         /**
          * Updates the activity UI after the movement of local files is tried.
-         * 
+         *
          * If the movement was successful for all the files, finishes the activity immediately.
-         * 
+         *
          * In other case, the list of remaining files is still available to retry the movement.
-         * 
-         * @param result      'True' when the movement was successful.
+         *
+         * @param result 'True' when the movement was successful.
          */
         @Override
         protected void onPostExecute(Boolean result) {
@@ -267,13 +266,10 @@ public class ErrorsWhileCopyingHandlerActivity  extends AppCompatActivity implem
             
             if (result) {
                 // nothing else to do in this activity
-                Snackbar.make(findViewById(android.R.id.content),R.string.foreign_files_success,Snackbar.LENGTH_LONG)
-                        .show();
+                DisplayUtils.showSnackMessage(findViewById(android.R.id.content), R.string.foreign_files_success);
                 finish();
-                
             } else {
-                Snackbar.make(findViewById(android.R.id.content),R.string.foreign_files_fail,Snackbar.LENGTH_LONG)
-                        .show();
+                DisplayUtils.showSnackMessage(findViewById(android.R.id.content), R.string.foreign_files_fail);
             }
         }
     }

+ 13 - 19
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java

@@ -31,7 +31,6 @@ import android.os.AsyncTask;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
-import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
 import android.support.v7.app.ActionBar;
 import android.support.v7.widget.AppCompatButton;
@@ -338,9 +337,8 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
                 .build()
                 .schedule();
 
-        Snackbar.make(getView().findViewById(R.id.contacts_linear_layout),
-                R.string.contacts_preferences_backup_scheduled,
-                Snackbar.LENGTH_LONG).show();
+        DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout),
+                R.string.contacts_preferences_backup_scheduled);
     }
 
     private void setAutomaticBackup(final boolean bool) {
@@ -369,16 +367,13 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
             if (PermissionUtil.shouldShowRequestPermissionRationale(contactsPreferenceActivity,
                     android.Manifest.permission.READ_CONTACTS)) {
                 // Show explanation to the user and then request permission
-                Snackbar snackbar = Snackbar.make(getView().findViewById(R.id.contacts_linear_layout),
-                        R.string.contacts_read_permission,
-                        Snackbar.LENGTH_INDEFINITE)
-                        .setAction(R.string.common_ok, new View.OnClickListener() {
-                            @Override
-                            public void onClick(View v) {
-                                requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
-                                        PermissionUtil.PERMISSIONS_READ_CONTACTS_AUTOMATIC);
-                            }
-                        });
+                Snackbar snackbar = DisplayUtils.createSnackbar(
+                        getView().findViewById(R.id.contacts_linear_layout),
+                        R.string.contacts_read_permission, Snackbar.LENGTH_INDEFINITE)
+                        .setAction(R.string.common_ok, v -> requestPermissions(
+                                new String[]{Manifest.permission.READ_CONTACTS},
+                                PermissionUtil.PERMISSIONS_READ_CONTACTS_AUTOMATIC)
+                        );
 
                 ThemeUtils.colorSnackbar(contactsPreferenceActivity, snackbar);
 
@@ -453,9 +448,8 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
 
             datePickerDialog.show();
         } else {
-            Snackbar.make(getView().findViewById(R.id.contacts_linear_layout),
-                    R.string.contacts_preferences_something_strange_happened,
-                    Snackbar.LENGTH_SHORT).show();
+            DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout),
+                    R.string.contacts_preferences_something_strange_happened);
         }
     }
 
@@ -532,8 +526,8 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
                     .addToBackStack(ContactsPreferenceActivity.BACKUP_TO_LIST)
                     .commit();
         } else {
-            Snackbar.make(getView().findViewById(R.id.contacts_linear_layout), R.string.contacts_preferences_no_file_found,
-                    Snackbar.LENGTH_SHORT).show();
+            DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout),
+                    R.string.contacts_preferences_no_file_found);
         }
     }
 }

+ 34 - 2
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -676,6 +676,26 @@ public class DisplayUtils {
         Snackbar.make(activity.findViewById(android.R.id.content), messageResource, Snackbar.LENGTH_LONG).show();
     }
 
+    /**
+     * Show a temporary message in a Snackbar bound to the given view.
+     *
+     * @param view the view the Snackbar is bound to.
+     * @param messageResource Message to show.
+     */
+    public static void showSnackMessage(View view, @StringRes int messageResource) {
+        Snackbar.make(view, messageResource, Snackbar.LENGTH_LONG).show();
+    }
+
+    /**
+     * create a temporary message in a Snackbar bound to the given view.
+     *
+     * @param view the view the Snackbar is bound to.
+     * @param messageResource Message to show.
+     */
+    public static Snackbar createSnackbar(View view, @StringRes int messageResource, int length) {
+        return Snackbar.make(view, messageResource, length);
+    }
+
     /**
      * Show a temporary message in a Snackbar bound to the content view.
      *
@@ -684,9 +704,21 @@ public class DisplayUtils {
      * @param formatArgs      The format arguments that will be used for substitution.
      */
     public static void showSnackMessage(Activity activity, @StringRes int messageResource, Object... formatArgs) {
+        showSnackMessage(activity, activity.findViewById(android.R.id.content), messageResource, formatArgs);
+    }
+
+    /**
+     * Show a temporary message in a Snackbar bound to the content view.
+     *
+     * @param context         to laod resources.
+     * @param view            content view the Snackbar is bound to.
+     * @param messageResource Resource id for the format string - message to show.
+     * @param formatArgs      The format arguments that will be used for substitution.
+     */
+    public static void showSnackMessage(Context context, View view, @StringRes int messageResource, Object... formatArgs) {
         Snackbar.make(
-                activity.findViewById(android.R.id.content),
-                String.format(activity.getString(messageResource, formatArgs)),
+                view,
+                String.format(context.getString(messageResource, formatArgs)),
                 Snackbar.LENGTH_LONG)
                 .show();
     }

+ 2 - 1
src/main/res/values/strings.xml

@@ -269,7 +269,8 @@
 	<string name="auth_fail_get_user_name">Your server is not returning a correct user ID, please contact an admin</string>
 	<string name="auth_can_not_auth_against_server">Cannot authenticate to this server</string>
     <string name="auth_account_does_not_exist">The account is not added on this device yet</string>
-    <string name="auth_access_failed">Access failed</string>
+    <string name="auth_access_failed">Access failed: %1$s</string>
+    <string name="auth_illegal_login_used">Illegal login data URL used</string>
 
     <string name="favorite">Set as available offline</string>
     <string name="unfavorite">Unset as available offline</string>