aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java87
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java42
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SendComment.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java10
10 files changed, 173 insertions, 77 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java
index 012e7479..0065ea45 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit;
+import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
@@ -8,10 +9,11 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
-import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -104,7 +106,10 @@ public class CommentActivity extends AppCompatActivity {
setSupportActionBar(toolbar);
commentEditText.requestFocus();
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
}
private void getCurrentAccount() {
@@ -118,6 +123,15 @@ public class CommentActivity extends AppCompatActivity {
}
@Override
+ protected void onPause() {
+ super.onPause();
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.hideSoftInputFromWindow(commentEditText.getWindowToken(), 0);
+ }
+ }
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.comment_activity, menu);
return true;
@@ -130,6 +144,11 @@ public class CommentActivity extends AppCompatActivity {
finish();
return true;
case R.id.action_send_comment_activity:
+ if(commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.comment_content_required, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
+
item.setEnabled(false);
item.getIcon().setAlpha(130);
Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
@@ -152,18 +171,16 @@ public class CommentActivity extends AppCompatActivity {
}
@Override
- public void sendCommentFailed() {
+ public void sendCommentFailed(@Nullable String errorMessage) {
sendingSnackbar.dismiss();
item.setEnabled(true);
item.getIcon().setAlpha(255);
- Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
- }
- @Override
- public void parseSentCommentFailed() {
- Intent returnIntent = new Intent();
- setResult(RESULT_OK, returnIntent);
- finish();
+ if(errorMessage == null) {
+ Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
+ } else {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
+ }
}
});
return true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
index 595ac06c..d24f297b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
@@ -13,6 +13,7 @@ class CommentData implements Parcelable {
private String id;
private String fullName;
private String author;
+ private String linkAuthor;
private String commentTime;
private String commentContent;
private String linkId;
@@ -35,12 +36,13 @@ class CommentData implements Parcelable {
private boolean isLoadingMoreChildren;
private boolean loadMoreChildrenFailed;
- CommentData(String id, String fullName, String author, String commentTime, String commentContent,
+ CommentData(String id, String fullName, String author, String linkAuthor, String commentTime, String commentContent,
String linkId, String subredditName, String parentId, int score, boolean isSubmitter, String permalink,
int depth, boolean collapsed, boolean hasReply, boolean scoreHidden) {
this.id = id;
this.fullName = fullName;
this.author = author;
+ this.linkAuthor = linkAuthor;
this.commentTime = commentTime;
this.commentContent = commentContent;
this.linkId = linkId;
@@ -70,6 +72,7 @@ class CommentData implements Parcelable {
id = in.readString();
fullName = in.readString();
author = in.readString();
+ linkAuthor = in.readString();
commentTime = in.readString();
commentContent = in.readString();
linkId = in.readString();
@@ -120,6 +123,10 @@ class CommentData implements Parcelable {
this.author = author;
}
+ public String getLinkAuthor() {
+ return linkAuthor;
+ }
+
public String getCommentTime() {
return commentTime;
}
@@ -285,6 +292,7 @@ class CommentData implements Parcelable {
parcel.writeString(id);
parcel.writeString(fullName);
parcel.writeString(author);
+ parcel.writeString(linkAuthor);
parcel.writeString(commentTime);
parcel.writeString(commentContent);
parcel.writeString(linkId);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
index 06c4f232..adab3ba3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
@@ -83,53 +83,54 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if(holder instanceof DataViewHolder) {
CommentData comment = getItem(holder.getAdapterPosition());
+ if(comment != null) {
+ if(comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) {
+ ((DataViewHolder) holder).authorTextView.setText("u/" + comment.getLinkAuthor());
+ ((DataViewHolder) holder).authorTextView.setTextColor(mTextColorPrimaryDark);
+ ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
+ Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor());
+ mContext.startActivity(intent);
+ });
+ } else {
+ ((DataViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName());
+ ((DataViewHolder) holder).authorTextView.setTextColor(mColorAccent);
+ ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
+ Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName());
+ mContext.startActivity(intent);
+ });
+ }
- if(comment.getAuthor().equals(comment.getSubredditName().substring(2))) {
- ((DataViewHolder) holder).authorTextView.setText("u/" + comment.getAuthor());
- ((DataViewHolder) holder).authorTextView.setTextColor(mTextColorPrimaryDark);
- ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
- Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
- intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor());
- mContext.startActivity(intent);
- });
- } else {
- ((DataViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName());
- ((DataViewHolder) holder).authorTextView.setTextColor(mColorAccent);
- ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
- Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
- intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName());
- mContext.startActivity(intent);
- });
- }
-
- ((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
+ ((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
- ((DataViewHolder) holder).commentMarkdownView.setMarkdown(comment.getCommentContent(), mContext);
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore()));
+ ((DataViewHolder) holder).commentMarkdownView.setMarkdown(comment.getCommentContent(), mContext);
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore()));
- switch (comment.getVoteType()) {
- case 1:
- ((DataViewHolder) holder).upvoteButton
- .setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
- break;
- case 2:
- ((DataViewHolder) holder).downvoteButton
- .setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
- break;
- }
+ switch (comment.getVoteType()) {
+ case 1:
+ ((DataViewHolder) holder).upvoteButton
+ .setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ break;
+ case 2:
+ ((DataViewHolder) holder).downvoteButton
+ .setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ break;
+ }
- if(comment.getAuthor().equals(mAccountName)) {
- ((DataViewHolder) holder).moreButton.setVisibility(View.VISIBLE);
- ((DataViewHolder) holder).moreButton.setOnClickListener(view -> {
- ModifyCommentBottomSheetFragment modifyCommentBottomSheetFragment = new ModifyCommentBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
- bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_CONTENT, comment.getCommentContent());
- bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_FULLNAME, comment.getFullName());
- bundle.putInt(ModifyCommentBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 1);
- modifyCommentBottomSheetFragment.setArguments(bundle);
- modifyCommentBottomSheetFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(), modifyCommentBottomSheetFragment.getTag());
- });
+ if(comment.getAuthor().equals(mAccountName)) {
+ ((DataViewHolder) holder).moreButton.setVisibility(View.VISIBLE);
+ ((DataViewHolder) holder).moreButton.setOnClickListener(view -> {
+ ModifyCommentBottomSheetFragment modifyCommentBottomSheetFragment = new ModifyCommentBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
+ bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_CONTENT, comment.getCommentContent());
+ bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_FULLNAME, comment.getFullName());
+ bundle.putInt(ModifyCommentBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 1);
+ modifyCommentBottomSheetFragment.setArguments(bundle);
+ modifyCommentBottomSheetFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(), modifyCommentBottomSheetFragment.getTag());
+ });
+ }
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java
index 0570f133..5739dfe6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit;
+import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
@@ -8,7 +9,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
-import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;
@@ -85,7 +86,19 @@ public class EditCommentActivity extends AppCompatActivity {
contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
contentEditText.requestFocus();
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.hideSoftInputFromWindow(contentEditText.getWindowToken(), 0);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java
index 29282fe1..e535b31d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit;
+import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
@@ -8,7 +9,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
-import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@@ -85,7 +86,19 @@ public class EditPostActivity extends AppCompatActivity {
contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
contentEditText.requestFocus();
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.hideSoftInputFromWindow(contentEditText.getWindowToken(), 0);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
index 8d6539ec..f3d40d58 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
@@ -15,6 +15,7 @@ public class JSONUtils {
static final String SUBREDDIT_NAME_PREFIX_KEY = "subreddit_name_prefixed";
static final String SELFTEXT_KEY = "selftext";
static final String AUTHOR_KEY = "author";
+ static final String LINK_AUTHOR_KEY = "link_author";
static final String LINK_FLAIR_TEXT_KEY = "link_flair_text";
static final String SCORE_KEY = "score";
static final String LIKES_KEY = "likes";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index 1ea058e6..aeddffc0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -24,7 +24,7 @@ class ParseComment {
interface ParseSentCommentListener {
void onParseSentCommentSuccess(CommentData commentData);
- void onParseSentCommentFailed();
+ void onParseSentCommentFailed(@Nullable String errorMessage);
}
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale,
@@ -179,6 +179,7 @@ class ParseComment {
private Locale locale;
private ParseSentCommentListener parseSentCommentListener;
private boolean parseFailed;
+ private String errorMessage;
private CommentData commentData;
ParseSentCommentAsyncTask(String response, int depth, Locale locale, ParseSentCommentListener parseSentCommentListener) {
@@ -196,6 +197,7 @@ class ParseComment {
commentData = parseSingleComment(sentCommentData, depth, locale);
} catch (JSONException e) {
e.printStackTrace();
+ errorMessage = parseSentCommentErrorMessage(response);
parseFailed = true;
}
return null;
@@ -205,7 +207,7 @@ class ParseComment {
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if(parseFailed) {
- parseSentCommentListener.onParseSentCommentFailed();
+ parseSentCommentListener.onParseSentCommentFailed(errorMessage);
} else {
parseSentCommentListener.onParseSentCommentSuccess(commentData);
}
@@ -213,10 +215,10 @@ class ParseComment {
}
static CommentData parseSingleComment(JSONObject singleCommentData, int depth, Locale locale) throws JSONException {
- Log.i("adfasdf", singleCommentData.toString());
String id = singleCommentData.getString(JSONUtils.ID_KEY);
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY);
+ String linkAuthor = singleCommentData.has(JSONUtils.LINK_AUTHOR_KEY) ? singleCommentData.getString(JSONUtils.LINK_AUTHOR_KEY) : null;
String linkId = singleCommentData.getString(JSONUtils.LINK_ID_KEY).substring(3);
String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY);
String parentId = singleCommentData.getString(JSONUtils.PARENT_ID_KEY);
@@ -242,7 +244,37 @@ class ParseComment {
boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY);
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
- return new CommentData(id, fullName, author, formattedSubmitTime, commentContent, linkId,
- subredditName, parentId, score, isSubmitter, permalink, depth, collapsed, hasReply, scoreHidden);
+ return new CommentData(id, fullName, author, linkAuthor, formattedSubmitTime, commentContent,
+ linkId, subredditName, parentId, score, isSubmitter, permalink, depth, collapsed,
+ hasReply, scoreHidden);
+ }
+
+ @Nullable
+ private static String parseSentCommentErrorMessage(String response) {
+ try {
+ JSONObject responseObject = new JSONObject(response).getJSONObject(JSONUtils.JSON_KEY);
+
+ if(responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() != 0) {
+ JSONArray error = responseObject.getJSONArray(JSONUtils.ERRORS_KEY)
+ .getJSONArray(responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() - 1);
+ if(error.length() != 0) {
+ String errorString;
+ if(error.length() >= 2) {
+ errorString = error.getString(1);
+ } else {
+ errorString = error.getString(0);
+ }
+ return errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ return null;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
index e44c6bf5..f6558013 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
@@ -9,7 +10,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
-import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -171,7 +172,19 @@ public class SearchActivity extends AppCompatActivity {
query = null;
}
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
+ if(imm != null) {
+ imm.hideSoftInputFromWindow(simpleSearchView.getSearchEditText().getWindowToken(), 0);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SendComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SendComment.java
index 18eac5cf..6be33004 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SendComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SendComment.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.Locale;
@@ -15,8 +16,7 @@ class SendComment {
interface SendCommentListener {
void sendCommentSuccess(CommentData commentData);
- void sendCommentFailed();
- void parseSentCommentFailed();
+ void sendCommentFailed(String errorMessage);
}
static void sendComment(String commentMarkdown, String thingFullname, int parentDepth,
@@ -43,18 +43,18 @@ class SendComment {
}
@Override
- public void onParseSentCommentFailed() {
-
+ public void onParseSentCommentFailed(@Nullable String errorMessage) {
+ sendCommentListener.sendCommentFailed(errorMessage);
}
});
} else {
- sendCommentListener.sendCommentFailed();
+ sendCommentListener.sendCommentFailed(response.message());
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- sendCommentListener.sendCommentFailed();
+ sendCommentListener.sendCommentFailed(t.getMessage());
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java
index e0a9dcc8..018d3a7c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java
@@ -204,6 +204,7 @@ class SubmitPost {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if(response.isSuccessful()) {
+ Log.i("afasdfadsfasdfasdfasdf", "a " + response.body());
try {
getSubmittedPost(response.body(), kind, oauthRetrofit, accessToken,
locale, submitPostListener);
@@ -219,8 +220,7 @@ class SubmitPost {
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- Log.i("call_failed", call.request().url().toString());
- submitPostListener.submitFailed(null);
+ submitPostListener.submitFailed(t.getMessage());
}
});
}
@@ -414,13 +414,11 @@ class SubmitPost {
String errorString;
if(error.length() >= 2) {
errorString = error.getString(1);
- errorString = errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
- submitPostListener.submitFailed(errorString);
} else {
errorString = error.getString(0);
- errorString = errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
- submitPostListener.submitFailed(errorString);
}
+ errorString = errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
+ submitPostListener.submitFailed(errorString);
} else {
submitPostListener.submitFailed(null);
}