mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
Add an option to preview markdown in several activitys.
This commit is contained in:
parent
441458b8b2
commit
aa8d0c49c1
@ -51,7 +51,7 @@
|
||||
android:parentActivityName=".Activity.MainActivity"
|
||||
android:theme="@style/AppTheme.Slidable" />
|
||||
<activity
|
||||
android:name=".Activity.CommentFullMarkdownActivity"
|
||||
android:name=".Activity.FullMarkdownActivity"
|
||||
android:parentActivityName=".Activity.MainActivity"
|
||||
android:theme="@style/AppTheme.Slidable" />
|
||||
<activity
|
||||
|
@ -327,60 +327,64 @@ public class CommentActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
case R.id.action_send_comment_activity:
|
||||
if (!isSubmitting) {
|
||||
isSubmitting = true;
|
||||
if (commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
|
||||
isSubmitting = false;
|
||||
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);
|
||||
sendingSnackbar.show();
|
||||
|
||||
SendComment.sendComment(commentEditText.getText().toString(), parentFullname, parentDepth,
|
||||
getResources().getConfiguration().locale, mOauthRetrofit,
|
||||
mAccessToken,
|
||||
new SendComment.SendCommentListener() {
|
||||
@Override
|
||||
public void sendCommentSuccess(Comment comment) {
|
||||
isSubmitting = false;
|
||||
item.setEnabled(true);
|
||||
item.getIcon().setAlpha(255);
|
||||
Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, comment);
|
||||
returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
|
||||
if (isReplying) {
|
||||
returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
|
||||
}
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCommentFailed(@Nullable String errorMessage) {
|
||||
isSubmitting = false;
|
||||
sendingSnackbar.dismiss();
|
||||
item.setEnabled(true);
|
||||
item.getIcon().setAlpha(255);
|
||||
|
||||
if (errorMessage == null || !errorMessage.equals("")) {
|
||||
Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_preview_comment_activity) {
|
||||
Intent intent = new Intent(this, FullMarkdownActivity.class);
|
||||
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, commentEditText.getText().toString());
|
||||
startActivity(intent);
|
||||
} else if (itemId == R.id.action_send_comment_activity) {
|
||||
if (!isSubmitting) {
|
||||
isSubmitting = true;
|
||||
if (commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
|
||||
isSubmitting = false;
|
||||
Snackbar.make(coordinatorLayout, R.string.comment_content_required, Snackbar.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
item.setEnabled(false);
|
||||
item.getIcon().setAlpha(130);
|
||||
Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
|
||||
sendingSnackbar.show();
|
||||
|
||||
SendComment.sendComment(commentEditText.getText().toString(), parentFullname, parentDepth,
|
||||
getResources().getConfiguration().locale, mOauthRetrofit,
|
||||
mAccessToken,
|
||||
new SendComment.SendCommentListener() {
|
||||
@Override
|
||||
public void sendCommentSuccess(Comment comment) {
|
||||
isSubmitting = false;
|
||||
item.setEnabled(true);
|
||||
item.getIcon().setAlpha(255);
|
||||
Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, comment);
|
||||
returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
|
||||
if (isReplying) {
|
||||
returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
|
||||
}
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCommentFailed(@Nullable String errorMessage) {
|
||||
isSubmitting = false;
|
||||
sendingSnackbar.dismiss();
|
||||
item.setEnabled(true);
|
||||
item.getIcon().setAlpha(255);
|
||||
|
||||
if (errorMessage == null || !errorMessage.equals("")) {
|
||||
Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -156,7 +156,11 @@ public class EditCommentActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_send_edit_comment_activity) {
|
||||
if (item.getItemId() == R.id.action_preview_edit_comment_activity) {
|
||||
Intent intent = new Intent(this, FullMarkdownActivity.class);
|
||||
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
|
||||
startActivity(intent);
|
||||
} else if (item.getItemId() == R.id.action_send_edit_comment_activity) {
|
||||
if (!isSubmitting) {
|
||||
isSubmitting = true;
|
||||
|
||||
|
@ -167,7 +167,11 @@ public class EditPostActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_send_edit_post_activity) {
|
||||
if (item.getItemId() == R.id.action_preview_edit_post_activity) {
|
||||
Intent intent = new Intent(this, FullMarkdownActivity.class);
|
||||
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
|
||||
startActivity(intent);
|
||||
} else if (item.getItemId() == R.id.action_send_edit_post_activity) {
|
||||
if (!isSubmitting) {
|
||||
isSubmitting = true;
|
||||
|
||||
|
@ -55,7 +55,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
|
||||
public class CommentFullMarkdownActivity extends BaseActivity {
|
||||
public class FullMarkdownActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_COMMENT_MARKDOWN = "ECM";
|
||||
public static final String EXTRA_IS_NSFW = "EIN";
|
||||
@ -184,7 +184,7 @@ public class CommentFullMarkdownActivity extends BaseActivity {
|
||||
@Override
|
||||
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||
builder.linkResolver((view, link) -> {
|
||||
Intent intent = new Intent(CommentFullMarkdownActivity.this, LinkResolverActivity.class);
|
||||
Intent intent = new Intent(FullMarkdownActivity.this, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(link);
|
||||
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
|
||||
@ -260,7 +260,7 @@ public class CommentFullMarkdownActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void applyCustomTheme() {
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getCommentBackgroundColor());
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||
}
|
||||
}
|
@ -414,57 +414,61 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if (isPosting) {
|
||||
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
|
||||
return true;
|
||||
} else {
|
||||
if (!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) {
|
||||
promptAlertDialog(R.string.discard, R.string.discard_detail);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
finish();
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == android.R.id.home) {
|
||||
if (isPosting) {
|
||||
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
|
||||
return true;
|
||||
case R.id.action_send_post_text_activity:
|
||||
if (!subredditSelected) {
|
||||
Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) {
|
||||
promptAlertDialog(R.string.discard, R.string.discard_detail);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
|
||||
Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
isPosting = true;
|
||||
|
||||
item.setEnabled(false);
|
||||
item.getIcon().setAlpha(130);
|
||||
|
||||
mPostingSnackbar.show();
|
||||
|
||||
String subredditName;
|
||||
if (subredditIsUser) {
|
||||
subredditName = "u_" + subredditNameTextView.getText().toString();
|
||||
} else {
|
||||
subredditName = subredditNameTextView.getText().toString();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
|
||||
startService(intent);
|
||||
|
||||
}
|
||||
finish();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_preview_post_text_activity) {
|
||||
Intent intent = new Intent(this, FullMarkdownActivity.class);
|
||||
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
|
||||
startActivity(intent);
|
||||
} else if (itemId == R.id.action_send_post_text_activity) {
|
||||
if (!subredditSelected) {
|
||||
Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
|
||||
Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
isPosting = true;
|
||||
|
||||
item.setEnabled(false);
|
||||
item.getIcon().setAlpha(130);
|
||||
|
||||
mPostingSnackbar.show();
|
||||
|
||||
String subredditName;
|
||||
if (subredditIsUser) {
|
||||
subredditName = "u_" + subredditNameTextView.getText().toString();
|
||||
} else {
|
||||
subredditName = subredditNameTextView.getText().toString();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
|
||||
startService(intent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -134,6 +134,9 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
|
||||
-> {
|
||||
String text = textEditText.getText().toString();
|
||||
String link = linkEditText.getText().toString();
|
||||
if (text.equals("")) {
|
||||
text = link;
|
||||
}
|
||||
|
||||
commentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"[" + text + "](" + link + ")", 0, "[]()".length() + text.length() + link.length());
|
||||
|
@ -6,7 +6,7 @@ import dagger.Component;
|
||||
import ml.docilealligator.infinityforreddit.Activity.AccountPostsActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.AccountSavedThingActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.CommentActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.CommentFullMarkdownActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.FullMarkdownActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.CreateMultiRedditActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.CustomThemeListingActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.CustomThemePreviewActivity;
|
||||
@ -208,7 +208,7 @@ public interface AppComponent {
|
||||
|
||||
void inject(SubmitCrosspostActivity submitCrosspostActivity);
|
||||
|
||||
void inject(CommentFullMarkdownActivity commentFullMarkdownActivity);
|
||||
void inject(FullMarkdownActivity fullMarkdownActivity);
|
||||
|
||||
void inject(SelectUserFlairActivity selectUserFlairActivity);
|
||||
|
||||
|
@ -21,7 +21,7 @@ import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import ml.docilealligator.infinityforreddit.Activity.CommentFullMarkdownActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.FullMarkdownActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.EditCommentActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.GiveAwardActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ReportActivity;
|
||||
@ -155,9 +155,9 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag
|
||||
});
|
||||
|
||||
viewFullMarkdownTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(activity, CommentFullMarkdownActivity.class);
|
||||
intent.putExtra(CommentFullMarkdownActivity.EXTRA_IS_NSFW, bundle.getBoolean(EXTRA_IS_NSFW, false));
|
||||
intent.putExtra(CommentFullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, bundle.getString(EXTRA_COMMENT_MARKDOWN, ""));
|
||||
Intent intent = new Intent(activity, FullMarkdownActivity.class);
|
||||
intent.putExtra(FullMarkdownActivity.EXTRA_IS_NSFW, bundle.getBoolean(EXTRA_IS_NSFW, false));
|
||||
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, bundle.getString(EXTRA_COMMENT_MARKDOWN, ""));
|
||||
activity.startActivity(intent);
|
||||
|
||||
dismiss();
|
||||
|
@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/coordinator_layout_comment_full_markdown_activity"
|
||||
tools:context=".Activity.CommentFullMarkdownActivity">
|
||||
tools:context=".Activity.FullMarkdownActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_layout_comment_full_markdown_activity"
|
||||
|
@ -2,8 +2,15 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_send_comment_activity"
|
||||
android:id="@+id/action_preview_comment_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_preview"
|
||||
android:icon="@drawable/ic_preview_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send_comment_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_send"
|
||||
android:icon="@drawable/ic_send_toolbar_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
@ -2,8 +2,15 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_send_edit_comment_activity"
|
||||
android:id="@+id/action_preview_edit_comment_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_preview"
|
||||
android:icon="@drawable/ic_preview_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send_edit_comment_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_send"
|
||||
android:icon="@drawable/ic_send_toolbar_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
@ -2,8 +2,15 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_send_edit_post_activity"
|
||||
android:id="@+id/action_preview_edit_post_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_preview"
|
||||
android:icon="@drawable/ic_preview_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send_edit_post_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_send"
|
||||
android:icon="@drawable/ic_send_toolbar_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
@ -2,8 +2,15 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_send_post_text_activity"
|
||||
android:id="@+id/action_preview_post_text_activity"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_preview"
|
||||
android:icon="@drawable/ic_preview_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send_post_text_activity"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_send"
|
||||
android:icon="@drawable/ic_send_toolbar_24dp"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
Loading…
Reference in New Issue
Block a user