mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-25 17:24:45 +01:00
Handle sending comment fails. Fixed snackbar hidden by keyboard in some activities. Minor bugs fixed.
This commit is contained in:
parent
a340517974
commit
029bbc951b
@ -124,6 +124,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".CommentActivity"
|
android:name=".CommentActivity"
|
||||||
android:label="@string/comment_activity_label"
|
android:label="@string/comment_activity_label"
|
||||||
|
android:parentActivityName=".MainActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar"
|
android:theme="@style/AppTheme.NoActionBar"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
<activity
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -8,10 +9,11 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
@ -104,7 +106,10 @@ public class CommentActivity extends AppCompatActivity {
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
commentEditText.requestFocus();
|
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() {
|
private void getCurrentAccount() {
|
||||||
@ -117,6 +122,15 @@ public class CommentActivity extends AppCompatActivity {
|
|||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
if(imm != null) {
|
||||||
|
imm.hideSoftInputFromWindow(commentEditText.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.comment_activity, menu);
|
getMenuInflater().inflate(R.menu.comment_activity, menu);
|
||||||
@ -130,6 +144,11 @@ public class CommentActivity extends AppCompatActivity {
|
|||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_send_comment_activity:
|
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.setEnabled(false);
|
||||||
item.getIcon().setAlpha(130);
|
item.getIcon().setAlpha(130);
|
||||||
Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
|
Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
|
||||||
@ -152,18 +171,16 @@ public class CommentActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCommentFailed() {
|
public void sendCommentFailed(@Nullable String errorMessage) {
|
||||||
sendingSnackbar.dismiss();
|
sendingSnackbar.dismiss();
|
||||||
item.setEnabled(true);
|
item.setEnabled(true);
|
||||||
item.getIcon().setAlpha(255);
|
item.getIcon().setAlpha(255);
|
||||||
Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if(errorMessage == null) {
|
||||||
public void parseSentCommentFailed() {
|
Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
|
||||||
Intent returnIntent = new Intent();
|
} else {
|
||||||
setResult(RESULT_OK, returnIntent);
|
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
|
||||||
finish();
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -13,6 +13,7 @@ class CommentData implements Parcelable {
|
|||||||
private String id;
|
private String id;
|
||||||
private String fullName;
|
private String fullName;
|
||||||
private String author;
|
private String author;
|
||||||
|
private String linkAuthor;
|
||||||
private String commentTime;
|
private String commentTime;
|
||||||
private String commentContent;
|
private String commentContent;
|
||||||
private String linkId;
|
private String linkId;
|
||||||
@ -35,12 +36,13 @@ class CommentData implements Parcelable {
|
|||||||
private boolean isLoadingMoreChildren;
|
private boolean isLoadingMoreChildren;
|
||||||
private boolean loadMoreChildrenFailed;
|
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,
|
String linkId, String subredditName, String parentId, int score, boolean isSubmitter, String permalink,
|
||||||
int depth, boolean collapsed, boolean hasReply, boolean scoreHidden) {
|
int depth, boolean collapsed, boolean hasReply, boolean scoreHidden) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.fullName = fullName;
|
this.fullName = fullName;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
|
this.linkAuthor = linkAuthor;
|
||||||
this.commentTime = commentTime;
|
this.commentTime = commentTime;
|
||||||
this.commentContent = commentContent;
|
this.commentContent = commentContent;
|
||||||
this.linkId = linkId;
|
this.linkId = linkId;
|
||||||
@ -70,6 +72,7 @@ class CommentData implements Parcelable {
|
|||||||
id = in.readString();
|
id = in.readString();
|
||||||
fullName = in.readString();
|
fullName = in.readString();
|
||||||
author = in.readString();
|
author = in.readString();
|
||||||
|
linkAuthor = in.readString();
|
||||||
commentTime = in.readString();
|
commentTime = in.readString();
|
||||||
commentContent = in.readString();
|
commentContent = in.readString();
|
||||||
linkId = in.readString();
|
linkId = in.readString();
|
||||||
@ -120,6 +123,10 @@ class CommentData implements Parcelable {
|
|||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLinkAuthor() {
|
||||||
|
return linkAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCommentTime() {
|
public String getCommentTime() {
|
||||||
return commentTime;
|
return commentTime;
|
||||||
}
|
}
|
||||||
@ -285,6 +292,7 @@ class CommentData implements Parcelable {
|
|||||||
parcel.writeString(id);
|
parcel.writeString(id);
|
||||||
parcel.writeString(fullName);
|
parcel.writeString(fullName);
|
||||||
parcel.writeString(author);
|
parcel.writeString(author);
|
||||||
|
parcel.writeString(linkAuthor);
|
||||||
parcel.writeString(commentTime);
|
parcel.writeString(commentTime);
|
||||||
parcel.writeString(commentContent);
|
parcel.writeString(commentContent);
|
||||||
parcel.writeString(linkId);
|
parcel.writeString(linkId);
|
||||||
|
@ -83,53 +83,54 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
if(holder instanceof DataViewHolder) {
|
if(holder instanceof DataViewHolder) {
|
||||||
CommentData comment = getItem(holder.getAdapterPosition());
|
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).commentTimeTextView.setText(comment.getCommentTime());
|
||||||
((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).commentMarkdownView.setMarkdown(comment.getCommentContent(), mContext);
|
||||||
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore()));
|
||||||
|
|
||||||
((DataViewHolder) holder).commentMarkdownView.setMarkdown(comment.getCommentContent(), mContext);
|
switch (comment.getVoteType()) {
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore()));
|
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()) {
|
if(comment.getAuthor().equals(mAccountName)) {
|
||||||
case 1:
|
((DataViewHolder) holder).moreButton.setVisibility(View.VISIBLE);
|
||||||
((DataViewHolder) holder).upvoteButton
|
((DataViewHolder) holder).moreButton.setOnClickListener(view -> {
|
||||||
.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
ModifyCommentBottomSheetFragment modifyCommentBottomSheetFragment = new ModifyCommentBottomSheetFragment();
|
||||||
break;
|
Bundle bundle = new Bundle();
|
||||||
case 2:
|
bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
((DataViewHolder) holder).downvoteButton
|
bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_CONTENT, comment.getCommentContent());
|
||||||
.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
|
bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_FULLNAME, comment.getFullName());
|
||||||
break;
|
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());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -8,7 +9,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -85,7 +86,19 @@ public class EditCommentActivity extends AppCompatActivity {
|
|||||||
contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
|
contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
|
||||||
|
|
||||||
contentEditText.requestFocus();
|
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
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -8,7 +9,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -85,7 +86,19 @@ public class EditPostActivity extends AppCompatActivity {
|
|||||||
contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
|
contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
|
||||||
|
|
||||||
contentEditText.requestFocus();
|
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
|
@Override
|
||||||
|
@ -15,6 +15,7 @@ public class JSONUtils {
|
|||||||
static final String SUBREDDIT_NAME_PREFIX_KEY = "subreddit_name_prefixed";
|
static final String SUBREDDIT_NAME_PREFIX_KEY = "subreddit_name_prefixed";
|
||||||
static final String SELFTEXT_KEY = "selftext";
|
static final String SELFTEXT_KEY = "selftext";
|
||||||
static final String AUTHOR_KEY = "author";
|
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 LINK_FLAIR_TEXT_KEY = "link_flair_text";
|
||||||
static final String SCORE_KEY = "score";
|
static final String SCORE_KEY = "score";
|
||||||
static final String LIKES_KEY = "likes";
|
static final String LIKES_KEY = "likes";
|
||||||
|
@ -24,7 +24,7 @@ class ParseComment {
|
|||||||
|
|
||||||
interface ParseSentCommentListener {
|
interface ParseSentCommentListener {
|
||||||
void onParseSentCommentSuccess(CommentData commentData);
|
void onParseSentCommentSuccess(CommentData commentData);
|
||||||
void onParseSentCommentFailed();
|
void onParseSentCommentFailed(@Nullable String errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
||||||
@ -179,6 +179,7 @@ class ParseComment {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private ParseSentCommentListener parseSentCommentListener;
|
private ParseSentCommentListener parseSentCommentListener;
|
||||||
private boolean parseFailed;
|
private boolean parseFailed;
|
||||||
|
private String errorMessage;
|
||||||
private CommentData commentData;
|
private CommentData commentData;
|
||||||
|
|
||||||
ParseSentCommentAsyncTask(String response, int depth, Locale locale, ParseSentCommentListener parseSentCommentListener) {
|
ParseSentCommentAsyncTask(String response, int depth, Locale locale, ParseSentCommentListener parseSentCommentListener) {
|
||||||
@ -196,6 +197,7 @@ class ParseComment {
|
|||||||
commentData = parseSingleComment(sentCommentData, depth, locale);
|
commentData = parseSingleComment(sentCommentData, depth, locale);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
errorMessage = parseSentCommentErrorMessage(response);
|
||||||
parseFailed = true;
|
parseFailed = true;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -205,7 +207,7 @@ class ParseComment {
|
|||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
super.onPostExecute(aVoid);
|
super.onPostExecute(aVoid);
|
||||||
if(parseFailed) {
|
if(parseFailed) {
|
||||||
parseSentCommentListener.onParseSentCommentFailed();
|
parseSentCommentListener.onParseSentCommentFailed(errorMessage);
|
||||||
} else {
|
} else {
|
||||||
parseSentCommentListener.onParseSentCommentSuccess(commentData);
|
parseSentCommentListener.onParseSentCommentSuccess(commentData);
|
||||||
}
|
}
|
||||||
@ -213,10 +215,10 @@ class ParseComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CommentData parseSingleComment(JSONObject singleCommentData, int depth, Locale locale) throws JSONException {
|
static CommentData parseSingleComment(JSONObject singleCommentData, int depth, Locale locale) throws JSONException {
|
||||||
Log.i("adfasdf", singleCommentData.toString());
|
|
||||||
String id = singleCommentData.getString(JSONUtils.ID_KEY);
|
String id = singleCommentData.getString(JSONUtils.ID_KEY);
|
||||||
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
|
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
|
||||||
String author = singleCommentData.getString(JSONUtils.AUTHOR_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 linkId = singleCommentData.getString(JSONUtils.LINK_ID_KEY).substring(3);
|
||||||
String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY);
|
String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY);
|
||||||
String parentId = singleCommentData.getString(JSONUtils.PARENT_ID_KEY);
|
String parentId = singleCommentData.getString(JSONUtils.PARENT_ID_KEY);
|
||||||
@ -242,7 +244,37 @@ class ParseComment {
|
|||||||
boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY);
|
boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY);
|
||||||
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
|
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
|
||||||
|
|
||||||
return new CommentData(id, fullName, author, formattedSubmitTime, commentContent, linkId,
|
return new CommentData(id, fullName, author, linkAuthor, formattedSubmitTime, commentContent,
|
||||||
subredditName, parentId, score, isSubmitter, permalink, depth, collapsed, hasReply, scoreHidden);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -9,7 +10,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -171,7 +172,19 @@ public class SearchActivity extends AppCompatActivity {
|
|||||||
query = null;
|
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
|
@Override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -15,8 +16,7 @@ class SendComment {
|
|||||||
|
|
||||||
interface SendCommentListener {
|
interface SendCommentListener {
|
||||||
void sendCommentSuccess(CommentData commentData);
|
void sendCommentSuccess(CommentData commentData);
|
||||||
void sendCommentFailed();
|
void sendCommentFailed(String errorMessage);
|
||||||
void parseSentCommentFailed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendComment(String commentMarkdown, String thingFullname, int parentDepth,
|
static void sendComment(String commentMarkdown, String thingFullname, int parentDepth,
|
||||||
@ -43,18 +43,18 @@ class SendComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onParseSentCommentFailed() {
|
public void onParseSentCommentFailed(@Nullable String errorMessage) {
|
||||||
|
sendCommentListener.sendCommentFailed(errorMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sendCommentListener.sendCommentFailed();
|
sendCommentListener.sendCommentFailed(response.message());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
sendCommentListener.sendCommentFailed();
|
sendCommentListener.sendCommentFailed(t.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -204,6 +204,7 @@ class SubmitPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
Log.i("afasdfadsfasdfasdfasdf", "a " + response.body());
|
||||||
try {
|
try {
|
||||||
getSubmittedPost(response.body(), kind, oauthRetrofit, accessToken,
|
getSubmittedPost(response.body(), kind, oauthRetrofit, accessToken,
|
||||||
locale, submitPostListener);
|
locale, submitPostListener);
|
||||||
@ -219,8 +220,7 @@ class SubmitPost {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
Log.i("call_failed", call.request().url().toString());
|
submitPostListener.submitFailed(t.getMessage());
|
||||||
submitPostListener.submitFailed(null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -414,13 +414,11 @@ class SubmitPost {
|
|||||||
String errorString;
|
String errorString;
|
||||||
if(error.length() >= 2) {
|
if(error.length() >= 2) {
|
||||||
errorString = error.getString(1);
|
errorString = error.getString(1);
|
||||||
errorString = errorString.substring(0, 1).toUpperCase() + errorString.substring(1);
|
|
||||||
submitPostListener.submitFailed(errorString);
|
|
||||||
} else {
|
} else {
|
||||||
errorString = error.getString(0);
|
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 {
|
} else {
|
||||||
submitPostListener.submitFailed(null);
|
submitPostListener.submitFailed(null);
|
||||||
}
|
}
|
||||||
|
@ -21,31 +21,37 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<androidx.core.widget.NestedScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="16dp"
|
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<ru.noties.markwon.view.MarkwonView
|
<LinearLayout
|
||||||
android:id="@+id/comment_parent_markwon_view_comment_activity"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/comment_edit_text_comment_activity"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="top"
|
android:orientation="vertical"
|
||||||
android:hint="@string/write_comment_hint"
|
android:padding="16dp">
|
||||||
android:inputType="textCapSentences|textMultiLine"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:background="#00000000"
|
|
||||||
android:textColor="@color/primaryTextColor" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
<ru.noties.markwon.view.MarkwonView
|
||||||
|
android:id="@+id/comment_parent_markwon_view_comment_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/comment_edit_text_comment_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="top"
|
||||||
|
android:hint="@string/write_comment_hint"
|
||||||
|
android:inputType="textCapSentences|textMultiLine"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:background="#00000000"
|
||||||
|
android:textColor="@color/primaryTextColor" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -2,7 +2,7 @@
|
|||||||
<string name="app_name">Infinity</string>
|
<string name="app_name">Infinity</string>
|
||||||
<string name="login_activity_label">Login</string>
|
<string name="login_activity_label">Login</string>
|
||||||
<string name="search_activity_label">Search</string>
|
<string name="search_activity_label">Search</string>
|
||||||
<string name="comment_activity_label">Add Comment</string>
|
<string name="comment_activity_label">Send Comment</string>
|
||||||
<string name="comment_activity_label_is_replying">Reply</string>
|
<string name="comment_activity_label_is_replying">Reply</string>
|
||||||
<string name="post_text_activity_label">Text Post</string>
|
<string name="post_text_activity_label">Text Post</string>
|
||||||
<string name="subreddit_selection_activity_label">Select a Subreddit</string>
|
<string name="subreddit_selection_activity_label">Select a Subreddit</string>
|
||||||
@ -104,7 +104,8 @@
|
|||||||
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>
|
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>
|
||||||
<string name="lazy_mode_stop">Lazy Mode stopped</string>
|
<string name="lazy_mode_stop">Lazy Mode stopped</string>
|
||||||
|
|
||||||
<string name="write_comment_hint">Your interesting thoughts here</string>
|
<string name="write_comment_hint">Your interesting thought here</string>
|
||||||
|
<string name="comment_content_required">Where is your interesting thought</string>
|
||||||
<string name="sending_comment">Sending</string>
|
<string name="sending_comment">Sending</string>
|
||||||
<string name="send_comment_failed">Could not send this comment</string>
|
<string name="send_comment_failed">Could not send this comment</string>
|
||||||
<string name="parse_sent_comment_failed">The comment is sent but unable to get the sent comment</string>
|
<string name="parse_sent_comment_failed">The comment is sent but unable to get the sent comment</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user