Browse Source

Use Application context in Toasts

pull/70/head
Ezerous 4 years ago
parent
commit
cf782505ca
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java
  2. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  4. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java
  5. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/create_content/CreateContentActivity.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  7. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  8. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  9. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java
  10. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  11. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  12. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadFieldsBuilderActivity.java
  13. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadsHelper.java
  14. 10
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

2
app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java

@ -110,7 +110,7 @@ public class AboutActivity extends BaseActivity {
} }
versionTextView.setOnLongClickListener(view -> { 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; return true;
}); });
} }

16
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -105,7 +105,7 @@ public class LoginActivity extends BaseActivity {
} }
private void onLoginFailed() { 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); btnLogin.setEnabled(true);
} }
@ -166,7 +166,7 @@ public class LoginActivity extends BaseActivity {
protected void onPostExecute(Integer result) { //Handle attempt result protected void onPostExecute(Integer result) { //Handle attempt result
switch (result) { switch (result) {
case SUCCESS: //Successful login case SUCCESS: //Successful login
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG)
.show(); .show();
BaseApplication.getInstance().logFirebaseAnalyticsEvent(FirebaseAnalytics.Event.LOGIN, null); 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); overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break; break;
case WRONG_USER: case WRONG_USER:
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"Wrong username!", Toast.LENGTH_LONG).show(); "Wrong username!", Toast.LENGTH_LONG).show();
inputUsername.requestFocus(); inputUsername.requestFocus();
break; break;
case WRONG_PASSWORD: case WRONG_PASSWORD:
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"Wrong password!", Toast.LENGTH_LONG).show(); "Wrong password!", Toast.LENGTH_LONG).show();
inputPassword.requestFocus(); inputPassword.requestFocus();
break; break;
case BANNED_USER: case BANNED_USER:
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"You are banned!", Toast.LENGTH_LONG).show(); "You are banned!", Toast.LENGTH_LONG).show();
inputPassword.requestFocus(); inputPassword.requestFocus();
break; break;
case FAILURE: case FAILURE:
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"Login failed...", Toast.LENGTH_LONG).show(); "Login failed...", Toast.LENGTH_LONG).show();
break; break;
case CONNECTION_ERROR: case CONNECTION_ERROR:
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"Connection Error", Toast.LENGTH_LONG).show(); "Connection Error", Toast.LENGTH_LONG).show();
break; break;
case EXCEPTION: case EXCEPTION:
Toast.makeText(getApplicationContext(), Toast.makeText(BaseApplication.getInstance().getApplicationContext(),
"Error", Toast.LENGTH_LONG).show(); "Error", Toast.LENGTH_LONG).show();
break; break;

3
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.LoginActivity;
import gr.thmmy.mthmmy.activities.create_content.CreateContentActivity; import gr.thmmy.mthmmy.activities.create_content.CreateContentActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.ThmmyPage; 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)); ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(boardUrl));
if (!target.is(ThmmyPage.PageCategory.BOARD)) { if (!target.is(ThmmyPage.PageCategory.BOARD)) {
Timber.e("Bundle came with a non board url!\nUrl:\n%s", boardUrl); 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(); finish();
} }

5
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.board.BoardActivity;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE;
@ -90,7 +91,7 @@ public class BookmarksActivity extends BaseActivity {
return toggleNotification(bookmarkedTopic); return toggleNotification(bookmarkedTopic);
case BookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK: case BookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK:
removeBookmark(bookmarkedTopic); removeBookmark(bookmarkedTopic);
Toast.makeText(BookmarksActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show();
break; break;
default: default:
break; break;
@ -113,7 +114,7 @@ public class BookmarksActivity extends BaseActivity {
return toggleNotification(bookmarkedBoard); return toggleNotification(bookmarkedBoard);
case BookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK: case BookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK:
removeBookmark(bookmarkedBoard); removeBookmark(bookmarkedBoard);
Toast.makeText(BookmarksActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show();
break; break;
default: default:
break; break;

3
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.R;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.views.editorview.EditorView; import gr.thmmy.mthmmy.views.editorview.EditorView;
import gr.thmmy.mthmmy.views.editorview.EmojiKeyboard; import gr.thmmy.mthmmy.views.editorview.EmojiKeyboard;
@ -104,7 +105,7 @@ public class CreateContentActivity extends BaseActivity implements NewTopicTask.
finish(); finish();
} else { } else {
Timber.w("New topic creation failed"); 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(); finish();
} }
} }

2
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)); ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(downloadsUrl));
if (!target.is(ThmmyPage.PageCategory.DOWNLOADS)) { if (!target.is(ThmmyPage.PageCategory.DOWNLOADS)) {
Timber.e("Bundle came with a non downloads url!\nUrl:\n%s", downloadsUrl); 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(); finish();
} }
} else downloadsUrl = downloadsIndexUrl; } else downloadsUrl = downloadsIndexUrl;

7
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.settings.SettingsActivity;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.model.TopicSummary;
@ -138,7 +139,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
super.onBackPressed(); super.onBackPressed();
return; return;
} else { } else {
Toast.makeText(getBaseContext(), "Press back again to exit!" Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Press back again to exit!"
, Toast.LENGTH_SHORT).show(); , Toast.LENGTH_SHORT).show();
} }
mBackPressed = System.currentTimeMillis(); mBackPressed = System.currentTimeMillis();
@ -278,10 +279,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
redirectIntent.putExtra(BUNDLE_DOWNLOADS_TITLE, ""); redirectIntent.putExtra(BUNDLE_DOWNLOADS_TITLE, "");
startActivity(redirectIntent); startActivity(redirectIntent);
} else if (!page.is(ThmmyPage.PageCategory.INDEX)) { } 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 { } 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();
} }
} }
} }

7
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.profile.summary.SummaryFragment;
import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.PostSummary;
import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.utils.Parcel; 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)); ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(profileUrl));
if (!target.is(ThmmyPage.PageCategory.PROFILE)) { if (!target.is(ThmmyPage.PageCategory.PROFILE)) {
Timber.e("Bundle came with a non profile url!\nUrl:\n%s", profileUrl); 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(); finish();
} }
if (target.is(ThmmyPage.PageCategory.PROFILE_STATS)) { if (target.is(ThmmyPage.PageCategory.PROFILE_STATS)) {
@ -331,12 +332,12 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
} }
} else if (result == NetworkResultCodes.NETWORK_ERROR) { } else if (result == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Network error while excecuting profile activity"); Timber.w("Network error while excecuting profile activity");
Toast.makeText(getBaseContext(), "Network error" Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error"
, Toast.LENGTH_LONG).show(); , Toast.LENGTH_LONG).show();
finish(); finish();
} else { } else {
Timber.d("Parse failed!"); Timber.d("Parse failed!");
Toast.makeText(getBaseContext(), "Fatal error!\n Aborting..." Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Fatal error!\n Aborting..."
, Toast.LENGTH_LONG).show(); , Toast.LENGTH_LONG).show();
finish(); finish();
} }

6
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java

@ -142,7 +142,7 @@ public class ShoutboxFragment extends Fragment {
shoutboxViewModel.loadShoutbox(true); shoutboxViewModel.loadShoutbox(true);
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to send shout"); 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); editorView.setVisibility(View.VISIBLE);
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to retreive shoutbox due to 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 { } else {
Timber.wtf("Failed to retreive shoutbox due to unknown error"); 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();
} }
} }

16
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)); Uri.parse(topicPageUrl));
if (!target.is(ThmmyPage.PageCategory.TOPIC)) { if (!target.is(ThmmyPage.PageCategory.TOPIC)) {
Timber.e("Bundle came with a non topic url!\nUrl: %s", topicPageUrl); 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(); finish();
} }
@ -516,7 +516,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
viewModel.reloadPage(); viewModel.reloadPage();
} else { } else {
Timber.w("Failed to delete post"); 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() { viewModel.setReplyFinishListener(new ReplyTask.ReplyTaskCallbacks() {
@ -579,7 +579,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
break; break;
default: default:
Timber.w("Post reply unsuccessful"); 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).setAlpha(1f);
recyclerView.getChildAt(recyclerView.getChildCount() - 1).setEnabled(true); recyclerView.getChildAt(recyclerView.getChildCount() - 1).setEnabled(true);
} }
@ -623,7 +623,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
viewModel.reloadPage(); viewModel.reloadPage();
} else { } else {
Timber.i("Post edit unsuccessful"); 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()).setAlpha(1);
recyclerView.getChildAt(viewModel.getPostBeingEditedPosition()).setEnabled(true); recyclerView.getChildAt(viewModel.getPostBeingEditedPosition()).setEnabled(true);
} }
@ -649,7 +649,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
} }
else { else {
Timber.w("Failed to send vote"); 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)); viewModel.setRemoveVoteTaskStartedListener(() -> progressBar.setVisibility(ProgressBar.VISIBLE));
@ -661,7 +661,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
} }
else { else {
Timber.w("Failed to remove vote"); 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 // observe the changes in data
@ -770,7 +770,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
default: default:
//Parse failed - should never happen //Parse failed - should never happen
Timber.wtf("Parse failed!"); //TODO report ParseException!!! 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(); finish();
break; 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 //Make a toast to inform the user that the url was copied
Toast.makeText( Toast.makeText(
TopicActivity.this, BaseApplication.getInstance().getApplicationContext(),
TopicActivity.this.getString(R.string.link_copied_msg), TopicActivity.this.getString(R.string.link_copied_msg),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }

20
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -268,11 +268,11 @@ public class UploadActivity extends BaseActivity {
shouldReturn = true; shouldReturn = true;
} }
if (filesList.isEmpty()) { 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; shouldReturn = true;
} }
if (categorySelected.equals("-1")) { 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; shouldReturn = true;
} }
if (!filesList.isEmpty()) { if (!filesList.isEmpty()) {
@ -282,7 +282,7 @@ public class UploadActivity extends BaseActivity {
} }
if (totalFilesSize > MAX_FILE_SIZE_SUPPORTED) { 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; shouldReturn = true;
} }
} }
@ -338,7 +338,7 @@ public class UploadActivity extends BaseActivity {
if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) {
//Something went wrong, abort //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); progressBar.setVisibility(View.GONE);
return; return;
} }
@ -385,7 +385,7 @@ public class UploadActivity extends BaseActivity {
: tempFileUri)) { : tempFileUri)) {
finish(); finish();
} else { } 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); zipTask.execute(filesListArray);
finish(); finish();
} else { } else {
Toast.makeText(this, "Please retry uploading.", Toast.LENGTH_SHORT).show(); Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please retry uploading.", Toast.LENGTH_SHORT).show();
} }
break; 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", Timber.d("Uploading a file with properties: \nTitle: %s\nCategory: %s\nDescription: %s\nIcon: %s\nUploader: %s",
uploadTitleText, categorySelected, uploadDescriptionText, fileIcon, uploaderProfileIndex); uploadTitleText, categorySelected, uploadDescriptionText, fileIcon, uploaderProfileIndex);
multipartUploadRequest.startUpload(); 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; return true;
} catch (Exception exception) { } catch (Exception exception) {
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); Timber.e(exception, "AndroidUploadService: %s", exception.getMessage());
@ -1041,7 +1041,7 @@ public class UploadActivity extends BaseActivity {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
assert weakActivity != null; 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 @Override
@ -1068,7 +1068,7 @@ public class UploadActivity extends BaseActivity {
return; return;
if (!result) { 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; return;
} }
@ -1077,7 +1077,7 @@ public class UploadActivity extends BaseActivity {
getConfigForUpload(weakActivity.get(), uploadID, zipFilename), categorySelected, getConfigForUpload(weakActivity.get(), uploadID, zipFilename), categorySelected,
uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex, uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex,
zipFileUri)) { 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();
} }
} }
} }

9
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.R;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import timber.log.Timber; import timber.log.Timber;
public class UploadFieldsBuilderActivity extends BaseActivity { public class UploadFieldsBuilderActivity extends BaseActivity {
@ -76,7 +77,7 @@ public class UploadFieldsBuilderActivity extends BaseActivity {
courseGreeklishName = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_GREEKLISH_NAME); courseGreeklishName = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_COURSE_GREEKLISH_NAME);
semester = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER); semester = extras.getString(BUNDLE_UPLOAD_FIELD_BUILDER_SEMESTER);
if (courseName == null || courseName.equals("") || semester == null || semester.equals("")) { 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()); Timber.e("Bundle came empty in %s", UploadFieldsBuilderActivity.class.getSimpleName());
Intent returnIntent = new Intent(); Intent returnIntent = new Intent();
@ -119,13 +120,13 @@ public class UploadFieldsBuilderActivity extends BaseActivity {
int typeId = typeRadio.getCheckedRadioButtonId(), int typeId = typeRadio.getCheckedRadioButtonId(),
semesterId = semesterRadio.getCheckedRadioButtonId(); semesterId = semesterRadio.getCheckedRadioButtonId();
if (typeId == -1) { 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; return;
} else if (semesterChooserLinear.getVisibility() == View.VISIBLE && semesterId == -1) { } 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; return;
} else if (year.getText().toString().isEmpty() || !isValidYear) { } 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; return;
} }

3
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.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.utils.FileUtils; import gr.thmmy.mthmmy.utils.FileUtils;
import timber.log.Timber; import timber.log.Timber;
@ -41,7 +42,7 @@ public class UploadsHelper {
if (!tempDirectory.exists() && !tempDirectory.mkdirs()) { if (!tempDirectory.exists() && !tempDirectory.mkdirs()) {
Timber.w("Temporary directory build returned false in %s", UploadActivity.class.getSimpleName()); 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; return null;
} }

10
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -569,11 +569,11 @@ public abstract class BaseActivity extends AppCompatActivity {
if (thisPageBookmark.matchExists(topicsBookmarked)) { if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_false_accent_24dp); thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_false_accent_24dp);
toggleTopicToBookmarks(thisPageBookmark); toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Bookmark removed", Toast.LENGTH_SHORT).show();
} else { } else {
thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_true_accent_24dp); thisPageBookmarkMenuButton.setIcon(R.drawable.ic_bookmark_true_accent_24dp);
toggleTopicToBookmarks(thisPageBookmark); 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 -> { thisPageBookmarkImageButton.setOnClickListener(view -> {
if (thisPageBookmark.matchExists(boardsBookmarked)) { if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp); 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 { } else {
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_true_accent_24dp); 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); toggleBoardToBookmarks(thisPageBookmark);
}); });
@ -771,7 +771,7 @@ public abstract class BaseActivity extends AppCompatActivity {
BaseActivity.this.startActivity(intent); BaseActivity.this.startActivity(intent);
} catch (Exception e) { } catch (Exception e) {
Timber.e(e, "Couldn't open downloaded file..."); 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();
} }
}); });

Loading…
Cancel
Save