From f9c3e28486449e1a7dfedf5ab200361a89a4e47f Mon Sep 17 00:00:00 2001 From: Krithic Kumar Date: Thu, 22 Oct 2020 12:58:38 +0530 Subject: [PATCH] changed all toasts to snackbars --- app/build.gradle | 2 +- .../view/SettingsFragment.java | 28 ++++++++++--------- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/preferences.xml | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4c070d6..a0fd98b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 24 targetSdkVersion 30 versionCode 1 - versionName "1.0" + versionName "0.9.0-beta03" javaCompileOptions { annotationProcessorOptions { diff --git a/app/src/main/java/com/attendancemanager/view/SettingsFragment.java b/app/src/main/java/com/attendancemanager/view/SettingsFragment.java index d21e570..4cf9e9b 100644 --- a/app/src/main/java/com/attendancemanager/view/SettingsFragment.java +++ b/app/src/main/java/com/attendancemanager/view/SettingsFragment.java @@ -44,6 +44,7 @@ import com.attendancemanager.viewmodel.SubjectViewModel; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.slider.Slider; +import com.google.android.material.snackbar.Snackbar; import com.google.android.material.timepicker.MaterialTimePicker; import com.google.android.material.timepicker.TimeFormat; import com.google.gson.Gson; @@ -66,6 +67,7 @@ import java.util.List; import java.util.Locale; +@SuppressWarnings("ConstantConditions") public class SettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener { public static final String NAME = "key_name"; @@ -261,13 +263,13 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) backupDatabase(); else - Toast.makeText(getContext(), "Permission denied. Backup failed", Toast.LENGTH_SHORT).show(); + Snackbar.make(getView(), "Permission denied. Backup failed", Snackbar.LENGTH_SHORT).show(); break; case READ_PERMISSION_REQUEST: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) showRestoreAlertDialog(); else - Toast.makeText(getContext(), "Permission denied. Recovery failed", Toast.LENGTH_SHORT).show(); + Snackbar.make(getView(), "Permission denied. Recovery failed", Snackbar.LENGTH_SHORT).show(); break; default: break; @@ -282,9 +284,9 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d if (data != null) restoreDatabase(data.getData()); else - Toast.makeText(getContext(), "Recovery failed", Toast.LENGTH_SHORT).show(); + Snackbar.make(getView(), "Recovery failed", Snackbar.LENGTH_SHORT).show(); else - Toast.makeText(getContext(), "Recovery failed", Toast.LENGTH_SHORT).show(); + Snackbar.make(getView(), "Recovery failed", Snackbar.LENGTH_SHORT).show(); } } @@ -450,10 +452,10 @@ private void backupDatabase() { fileWriter.write(Base64.encodeToString(jsonObject.toString().getBytes(), Base64.DEFAULT)); fileWriter.flush(); fileWriter.close(); - Toast.makeText(getContext(), "Backup successfully created in Android/data/com.attendancemanager/files", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "Backup successfully created in Android/data/com.attendancemanager/files", Snackbar.LENGTH_LONG).show(); } catch (JSONException | IOException e) { - Toast.makeText(getContext(), "Backup failed", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "Backup failed", Snackbar.LENGTH_LONG).show(); } } @@ -515,10 +517,10 @@ private void restoreDatabase(Uri uri) { sEditor.putString(MainActivity.SHARED_PREFS_EXTRA_LAST_ADDED, lastAdded); sEditor.apply(); - Toast.makeText(getContext(), "Restored successfully", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "Restored successfully", Snackbar.LENGTH_LONG).show(); } catch (JSONException e) { - Toast.makeText(getContext(), "Recovery failed. Choose a valid file", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "Recovery failed. Choose a valid file", Snackbar.LENGTH_LONG).show(); } } @@ -529,7 +531,7 @@ private String readJsonFile(Uri uri) { try { fileReader = new BufferedReader(new InputStreamReader(getContext().getContentResolver().openInputStream(uri))); } catch (FileNotFoundException e) { - Toast.makeText(getContext(), "File not found", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "File not found", Snackbar.LENGTH_LONG).show(); return null; } try { @@ -541,15 +543,15 @@ private String readJsonFile(Uri uri) { } fileReader.close(); } catch (IOException e) { - Toast.makeText(getContext(), "Unable to read file", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "Unable to read file", Snackbar.LENGTH_LONG).show(); return null; } catch (OutOfMemoryError e) { - Toast.makeText(getContext(), "File size is too big. Choose a valid file", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "File size is too big. Choose a valid file", Snackbar.LENGTH_LONG).show(); } try { return new String(Base64.decode(jsonString.toString(), Base64.DEFAULT)); } catch (IllegalArgumentException | OutOfMemoryError e) { - Toast.makeText(getContext(), "Choose a valid file", Toast.LENGTH_LONG).show(); + Snackbar.make(getView(), "Choose a valid file", Snackbar.LENGTH_LONG).show(); return null; } } @@ -621,7 +623,7 @@ private void bugReport() { try { appVersion = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { - appVersion = getString(R.string.app_version_number) + " (from version number)"; + appVersion = getString(R.string.app_version_name); Toast.makeText(getContext(), "Not able to get app version", Toast.LENGTH_SHORT).show(); } StringBuilder mailInfoBuilder; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee48d33..cc14a52 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,7 +2,7 @@ Attendance Manager Krithic Kumar - 0.9.0-beta02 + 0.9.0-beta03 Time Table Home Settings diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 29a868a..9267d9f 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -113,7 +113,7 @@