From cf782505ca4088643d85475925b47f26eb3edd03 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 9 Aug 2020 22:34:55 +0300 Subject: [PATCH] Use Application context in Toasts --- .../mthmmy/activities/AboutActivity.java | 2 +- .../mthmmy/activities/LoginActivity.java | 16 +++++++-------- .../activities/board/BoardActivity.java | 3 ++- .../bookmarks/BookmarksActivity.java | 5 +++-- .../create_content/CreateContentActivity.java | 3 ++- .../downloads/DownloadsActivity.java | 2 +- .../mthmmy/activities/main/MainActivity.java | 7 ++++--- .../activities/profile/ProfileActivity.java | 7 ++++--- .../activities/shoutbox/ShoutboxFragment.java | 6 +++--- .../activities/topic/TopicActivity.java | 16 +++++++-------- .../activities/upload/UploadActivity.java | 20 +++++++++---------- .../upload/UploadFieldsBuilderActivity.java | 9 +++++---- .../activities/upload/UploadsHelper.java | 3 ++- .../gr/thmmy/mthmmy/base/BaseActivity.java | 10 +++++----- 14 files changed, 58 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index 8ff6dfe5..54127dd5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -110,7 +110,7 @@ public class AboutActivity extends BaseActivity { } versionTextView.setOnLongClickListener(view -> { - Toast.makeText(getApplicationContext(), BaseApplication.getFirebaseProjectId(), Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), BaseApplication.getFirebaseProjectId(), Toast.LENGTH_SHORT).show(); return true; }); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java index d9aff7eb..f3304276 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -105,7 +105,7 @@ public class LoginActivity extends BaseActivity { } private void onLoginFailed() { - Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show(); btnLogin.setEnabled(true); } @@ -166,7 +166,7 @@ public class LoginActivity extends BaseActivity { protected void onPostExecute(Integer result) { //Handle attempt result switch (result) { case SUCCESS: //Successful login - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) .show(); BaseApplication.getInstance().logFirebaseAnalyticsEvent(FirebaseAnalytics.Event.LOGIN, null); @@ -180,30 +180,30 @@ public class LoginActivity extends BaseActivity { overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); break; case WRONG_USER: - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Wrong username!", Toast.LENGTH_LONG).show(); inputUsername.requestFocus(); break; case WRONG_PASSWORD: - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Wrong password!", Toast.LENGTH_LONG).show(); inputPassword.requestFocus(); break; case BANNED_USER: - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "You are banned!", Toast.LENGTH_LONG).show(); inputPassword.requestFocus(); break; case FAILURE: - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Login failed...", Toast.LENGTH_LONG).show(); break; case CONNECTION_ERROR: - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Connection Error", Toast.LENGTH_LONG).show(); break; case EXCEPTION: - Toast.makeText(getApplicationContext(), + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Error", Toast.LENGTH_LONG).show(); break; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java index 30df2cc5..a4ede049 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java @@ -28,6 +28,7 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.create_content.CreateContentActivity; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.ThmmyPage; @@ -77,7 +78,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(boardUrl)); if (!target.is(ThmmyPage.PageCategory.BOARD)) { Timber.e("Bundle came with a non board url!\nUrl:\n%s", boardUrl); - Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show(); finish(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java index 7054db43..107ed6ce 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java @@ -19,6 +19,7 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Bookmark; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; @@ -90,7 +91,7 @@ public class BookmarksActivity extends BaseActivity { return toggleNotification(bookmarkedTopic); case BookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK: removeBookmark(bookmarkedTopic); - Toast.makeText(BookmarksActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); break; default: break; @@ -113,7 +114,7 @@ public class BookmarksActivity extends BaseActivity { return toggleNotification(bookmarkedBoard); case BookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK: removeBookmark(bookmarkedBoard); - Toast.makeText(BookmarksActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); break; default: break; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java index 29b0c699..ba14ff98 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java @@ -15,6 +15,7 @@ import com.google.android.material.textfield.TextInputLayout; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.views.editorview.EditorView; import gr.thmmy.mthmmy.views.editorview.EmojiKeyboard; @@ -104,7 +105,7 @@ public class CreateContentActivity extends BaseActivity implements NewTopicTask. finish(); } else { Timber.w("New topic creation failed"); - Toast.makeText(getBaseContext(), "Failed to create new topic!", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Failed to create new topic!", Toast.LENGTH_LONG).show(); finish(); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java index 2bb96af2..1327a2d0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java @@ -78,7 +78,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter. ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(downloadsUrl)); if (!target.is(ThmmyPage.PageCategory.DOWNLOADS)) { Timber.e("Bundle came with a non downloads url!\nUrl:\n%s", downloadsUrl); - Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show(); finish(); } } else downloadsUrl = downloadsIndexUrl; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index b102c7f7..5d8aa004 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -31,6 +31,7 @@ import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.TopicSummary; @@ -138,7 +139,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF super.onBackPressed(); return; } else { - Toast.makeText(getBaseContext(), "Press back again to exit!" + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Press back again to exit!" , Toast.LENGTH_SHORT).show(); } mBackPressed = System.currentTimeMillis(); @@ -278,10 +279,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF redirectIntent.putExtra(BUNDLE_DOWNLOADS_TITLE, ""); startActivity(redirectIntent); } else if (!page.is(ThmmyPage.PageCategory.INDEX)) { - Toast.makeText(this, "This thmmy sector is not yet supported.", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "This thmmy sector is not yet supported.", Toast.LENGTH_LONG).show(); } } else { - Toast.makeText(this, "This is not thmmy.", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "This is not thmmy.", Toast.LENGTH_LONG).show(); } } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 223f36e9..1b9062b2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -43,6 +43,7 @@ import gr.thmmy.mthmmy.activities.profile.stats.StatsFragment; import gr.thmmy.mthmmy.activities.profile.summary.SummaryFragment; import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.utils.Parcel; @@ -177,7 +178,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(profileUrl)); if (!target.is(ThmmyPage.PageCategory.PROFILE)) { Timber.e("Bundle came with a non profile url!\nUrl:\n%s", profileUrl); - Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); finish(); } if (target.is(ThmmyPage.PageCategory.PROFILE_STATS)) { @@ -331,12 +332,12 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment } } else if (result == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Network error while excecuting profile activity"); - Toast.makeText(getBaseContext(), "Network error" + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error" , Toast.LENGTH_LONG).show(); finish(); } else { Timber.d("Parse failed!"); - Toast.makeText(getBaseContext(), "Fatal error!\n Aborting..." + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Fatal error!\n Aborting..." , Toast.LENGTH_LONG).show(); finish(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java index e776423f..d6ab6cfd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java @@ -142,7 +142,7 @@ public class ShoutboxFragment extends Fragment { shoutboxViewModel.loadShoutbox(true); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Failed to send shout"); - Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "NetworkError", Toast.LENGTH_SHORT).show(); } } @@ -154,10 +154,10 @@ public class ShoutboxFragment extends Fragment { editorView.setVisibility(View.VISIBLE); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Timber.w("Failed to retreive shoutbox due to network error"); - Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "NetworkError", Toast.LENGTH_SHORT).show(); } else { Timber.wtf("Failed to retreive shoutbox due to unknown error"); - Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show(); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 3621057f..1bc7da95 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -150,7 +150,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo Uri.parse(topicPageUrl)); if (!target.is(ThmmyPage.PageCategory.TOPIC)) { Timber.e("Bundle came with a non topic url!\nUrl: %s", topicPageUrl); - Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); finish(); } @@ -516,7 +516,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo viewModel.reloadPage(); } else { Timber.w("Failed to delete post"); - Toast.makeText(getBaseContext(), "Delete failed!", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Delete failed!", Toast.LENGTH_SHORT).show(); } }); viewModel.setReplyFinishListener(new ReplyTask.ReplyTaskCallbacks() { @@ -579,7 +579,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo break; default: Timber.w("Post reply unsuccessful"); - Toast.makeText(getBaseContext(), "Post failed!", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Post failed!", Toast.LENGTH_SHORT).show(); recyclerView.getChildAt(recyclerView.getChildCount() - 1).setAlpha(1f); recyclerView.getChildAt(recyclerView.getChildCount() - 1).setEnabled(true); } @@ -623,7 +623,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo viewModel.reloadPage(); } else { Timber.i("Post edit unsuccessful"); - Toast.makeText(getBaseContext(), "Edit failed!", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Edit failed!", Toast.LENGTH_SHORT).show(); recyclerView.getChildAt(viewModel.getPostBeingEditedPosition()).setAlpha(1); recyclerView.getChildAt(viewModel.getPostBeingEditedPosition()).setEnabled(true); } @@ -649,7 +649,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo } else { Timber.w("Failed to send vote"); - Toast.makeText(this, "Failed to send vote", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Failed to send vote", Toast.LENGTH_LONG).show(); } }); viewModel.setRemoveVoteTaskStartedListener(() -> progressBar.setVisibility(ProgressBar.VISIBLE)); @@ -661,7 +661,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo } else { Timber.w("Failed to remove vote"); - Toast.makeText(this, "Failed to remove vote", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Failed to remove vote", Toast.LENGTH_LONG).show(); } }); // observe the changes in data @@ -770,7 +770,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo default: //Parse failed - should never happen Timber.wtf("Parse failed!"); //TODO report ParseException!!! - Toast.makeText(getBaseContext(), "Fatal Error", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Fatal Error", Toast.LENGTH_SHORT).show(); finish(); break; } @@ -824,7 +824,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo //Make a toast to inform the user that the url was copied Toast.makeText( - TopicActivity.this, + BaseApplication.getInstance().getApplicationContext(), TopicActivity.this.getString(R.string.link_copied_msg), Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index 55f3f16e..ea3975d9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -268,11 +268,11 @@ public class UploadActivity extends BaseActivity { shouldReturn = true; } if (filesList.isEmpty()) { - Toast.makeText(view.getContext(), "Please choose a file to upload or take a photo", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please choose a file to upload or take a photo", Toast.LENGTH_LONG).show(); shouldReturn = true; } if (categorySelected.equals("-1")) { - Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); shouldReturn = true; } if (!filesList.isEmpty()) { @@ -282,7 +282,7 @@ public class UploadActivity extends BaseActivity { } if (totalFilesSize > MAX_FILE_SIZE_SUPPORTED) { - Toast.makeText(view.getContext(), "Your files are too powerful for thmmy. Reduce size or split!", Toast.LENGTH_LONG).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Your files are too powerful for thmmy. Reduce size or split!", Toast.LENGTH_LONG).show(); shouldReturn = true; } } @@ -338,7 +338,7 @@ public class UploadActivity extends BaseActivity { if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { //Something went wrong, abort - Toast.makeText(this, "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); progressBar.setVisibility(View.GONE); return; } @@ -385,7 +385,7 @@ public class UploadActivity extends BaseActivity { : tempFileUri)) { finish(); } else { - Toast.makeText(this, "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); } }); @@ -580,7 +580,7 @@ public class UploadActivity extends BaseActivity { zipTask.execute(filesListArray); finish(); } else { - Toast.makeText(this, "Please retry uploading.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please retry uploading.", Toast.LENGTH_SHORT).show(); } break; } @@ -746,7 +746,7 @@ public class UploadActivity extends BaseActivity { Timber.d("Uploading a file with properties: \nTitle: %s\nCategory: %s\nDescription: %s\nIcon: %s\nUploader: %s", uploadTitleText, categorySelected, uploadDescriptionText, fileIcon, uploaderProfileIndex); multipartUploadRequest.startUpload(); - Toast.makeText(context, "Uploading file(s) in the background...", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Uploading file(s) in the background...", Toast.LENGTH_SHORT).show(); return true; } catch (Exception exception) { Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); @@ -1041,7 +1041,7 @@ public class UploadActivity extends BaseActivity { @Override protected void onPreExecute() { assert weakActivity != null; - Toast.makeText(weakActivity.get(), "Zipping files", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Zipping files", Toast.LENGTH_SHORT).show(); } @Override @@ -1068,7 +1068,7 @@ public class UploadActivity extends BaseActivity { return; if (!result) { - Toast.makeText(weakActivity.get(), "Couldn't create zip!", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Couldn't create zip!", Toast.LENGTH_SHORT).show(); return; } @@ -1077,7 +1077,7 @@ public class UploadActivity extends BaseActivity { getConfigForUpload(weakActivity.get(), uploadID, zipFilename), categorySelected, uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex, zipFileUri)) { - Toast.makeText(weakActivity.get(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); } } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java index 2ea58fee..8e75b979 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java @@ -17,6 +17,7 @@ import java.util.Calendar; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; import timber.log.Timber; public class UploadFieldsBuilderActivity extends BaseActivity { @@ -76,7 +77,7 @@ public class UploadFieldsBuilderActivity extends BaseActivity { courseGreeklishName = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_GREEKLISH_NAME); semester = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER); if (courseName == null || courseName.equals("") || semester == null || semester.equals("")) { - Toast.makeText(this, "Something went wrong!", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Something went wrong!", Toast.LENGTH_SHORT).show(); Timber.e("Bundle came empty in %s", UploadFieldsBuilderActivity.class.getSimpleName()); Intent returnIntent = new Intent(); @@ -119,13 +120,13 @@ public class UploadFieldsBuilderActivity extends BaseActivity { int typeId = typeRadio.getCheckedRadioButtonId(), semesterId = semesterRadio.getCheckedRadioButtonId(); if (typeId == -1) { - Toast.makeText(view.getContext(), "Please choose a type for the upload", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please choose a type for the upload", Toast.LENGTH_SHORT).show(); return; } else if (semesterChooserLinear.getVisibility() == View.VISIBLE && semesterId == -1) { - Toast.makeText(view.getContext(), "Please choose a semester for the upload", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please choose a semester for the upload", Toast.LENGTH_SHORT).show(); return; } else if (year.getText().toString().isEmpty() || !isValidYear) { - Toast.makeText(view.getContext(), "Please choose a valid year for the upload", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please choose a valid year for the upload", Toast.LENGTH_SHORT).show(); return; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java index 92b71cb0..4bc71490 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java @@ -21,6 +21,7 @@ import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.FileUtils; import timber.log.Timber; @@ -41,7 +42,7 @@ public class UploadsHelper { if (!tempDirectory.exists() && !tempDirectory.mkdirs()) { Timber.w("Temporary directory build returned false in %s", UploadActivity.class.getSimpleName()); - Toast.makeText(context, "Couldn't create temporary directory", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Couldn't create temporary directory", Toast.LENGTH_SHORT).show(); return null; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 733e12b8..be9ec059 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -569,11 +569,11 @@ public abstract class BaseActivity extends AppCompatActivity { if (thisPageBookmark.matchExists(topicsBookmarked)) { thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_false_accent_24dp); toggleTopicToBookmarks(thisPageBookmark); - Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); } else { thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_true_accent_24dp); toggleTopicToBookmarks(thisPageBookmark); - Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); } } @@ -586,10 +586,10 @@ public abstract class BaseActivity extends AppCompatActivity { thisPageBookmarkImageButton.setOnClickListener(view -> { if (thisPageBookmark.matchExists(boardsBookmarked)) { thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp); - Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); } else { thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp); - Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); } toggleBoardToBookmarks(thisPageBookmark); }); @@ -771,7 +771,7 @@ public abstract class BaseActivity extends AppCompatActivity { BaseActivity.this.startActivity(intent); } catch (Exception e) { Timber.e(e, "Couldn't open downloaded file..."); - Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); } });