Skip to content

Commit

Permalink
changed all toasts to snackbars
Browse files Browse the repository at this point in the history
  • Loading branch information
Krithic Kumar committed Oct 22, 2020
1 parent cde6240 commit f9c3e28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionName "0.9.0-beta03"

javaCompileOptions {
annotationProcessorOptions {
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/com/attendancemanager/view/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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 {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- General -->
<string name="app_name">Attendance Manager</string>
<string name="developer_name">Krithic Kumar</string>
<string name="app_version_number">0.9.0-beta02</string>
<string name="app_version_name">0.9.0-beta03</string>
<string name="time_table">Time Table</string>
<string name="home">Home</string>
<string name="settings">Settings</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<Preference
app:icon="@drawable/ic_info"
app:key="@string/key_about"
app:summary="@string/app_version_number"
app:summary="@string/app_version_name"
app:title="About Attendance Manager" />

<Preference
Expand Down

0 comments on commit f9c3e28

Please sign in to comment.