mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
refactor: Extract CopyTextBottomSheetFragment display logic (#969)
This commit is contained in:
parent
45bc223659
commit
b72bfdef37
@ -199,7 +199,6 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
|
|||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
|
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
|
||||||
String parentText = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY);
|
String parentText = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY);
|
||||||
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
|
||||||
|
|
||||||
int linkColor = mCustomThemeWrapper.getLinkColor();
|
int linkColor = mCustomThemeWrapper.getLinkColor();
|
||||||
Markwon markwon = Markwon.builder(this)
|
Markwon markwon = Markwon.builder(this)
|
||||||
@ -242,15 +241,13 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
|
|||||||
if (parentTextMarkdown != null) {
|
if (parentTextMarkdown != null) {
|
||||||
commentParentMarkwonView.setOnLongClickListener(view -> {
|
commentParentMarkwonView.setOnLongClickListener(view -> {
|
||||||
Utils.hideKeyboard(CommentActivity.this);
|
Utils.hideKeyboard(CommentActivity.this);
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
if (parentText == null) {
|
if (parentText == null) {
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentTextMarkdown);
|
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
|
||||||
|
parentTextMarkdown, null);
|
||||||
} else {
|
} else {
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentText);
|
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentTextMarkdown);
|
parentText, parentTextMarkdown);
|
||||||
}
|
}
|
||||||
copyTextBottomSheetFragment.setArguments(bundle);
|
|
||||||
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
markwon.setMarkdown(commentParentMarkwonView, parentTextMarkdown);
|
markwon.setMarkdown(commentParentMarkwonView, parentTextMarkdown);
|
||||||
@ -285,11 +282,8 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
|
|||||||
textView.setTextColor(markdownColor);
|
textView.setTextColor(markdownColor);
|
||||||
textView.setOnLongClickListener(view -> {
|
textView.setOnLongClickListener(view -> {
|
||||||
Utils.hideKeyboard(CommentActivity.this);
|
Utils.hideKeyboard(CommentActivity.this);
|
||||||
Bundle bundle = new Bundle();
|
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentBody);
|
parentBody, parentBodyMarkdown);
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentBodyMarkdown);
|
|
||||||
copyTextBottomSheetFragment.setArguments(bundle);
|
|
||||||
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -404,11 +404,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
|
|
||||||
descriptionTextView.setOnLongClickListener(view -> {
|
descriptionTextView.setOnLongClickListener(view -> {
|
||||||
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
|
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
|
||||||
Bundle bundle = new Bundle();
|
CopyTextBottomSheetFragment.show(getSupportFragmentManager(), description, null);
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, description);
|
|
||||||
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
|
||||||
copyTextBottomSheetFragment.setArguments(bundle);
|
|
||||||
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -400,11 +400,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
|
|
||||||
descriptionTextView.setOnLongClickListener(view -> {
|
descriptionTextView.setOnLongClickListener(view -> {
|
||||||
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
|
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
|
||||||
Bundle bundle = new Bundle();
|
CopyTextBottomSheetFragment.show(getSupportFragmentManager(), description, null);
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, description);
|
|
||||||
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
|
||||||
copyTextBottomSheetFragment.setArguments(bundle);
|
|
||||||
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -269,12 +269,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
|||||||
textView.setTextColor(markdownColor);
|
textView.setTextColor(markdownColor);
|
||||||
textView.setOnLongClickListener(view -> {
|
textView.setOnLongClickListener(view -> {
|
||||||
if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) {
|
if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) {
|
||||||
Bundle bundle = new Bundle();
|
CopyTextBottomSheetFragment.show(
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, mPost.getSelfTextPlain());
|
mActivity.getSupportFragmentManager(),
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, mPost.getSelfText());
|
mPost.getSelfTextPlain(), mPost.getSelfText()
|
||||||
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
);
|
||||||
copyTextBottomSheetFragment.setArguments(bundle);
|
|
||||||
copyTextBottomSheetFragment.show(mActivity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -181,12 +181,8 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
|||||||
|
|
||||||
copyTextView.setOnClickListener(view -> {
|
copyTextView.setOnClickListener(view -> {
|
||||||
dismiss();
|
dismiss();
|
||||||
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
CopyTextBottomSheetFragment.show(activity.getSupportFragmentManager(),
|
||||||
Bundle copyBundle = new Bundle();
|
comment.getCommentRawText(), comment.getCommentMarkdown());
|
||||||
copyBundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, comment.getCommentMarkdown());
|
|
||||||
copyBundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, comment.getCommentRawText());
|
|
||||||
copyTextBottomSheetFragment.setArguments(copyBundle);
|
|
||||||
copyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
reportTextView.setOnClickListener(view -> {
|
reportTextView.setOnClickListener(view -> {
|
||||||
|
@ -12,8 +12,10 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
@ -49,6 +51,19 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
|
|||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for creating the dialog, creating and setting arguments bundle
|
||||||
|
* and displaying the dialog
|
||||||
|
*/
|
||||||
|
public static void show(@NonNull FragmentManager fragmentManager,
|
||||||
|
@Nullable String rawText, @Nullable String markdown) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, rawText);
|
||||||
|
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, markdown);
|
||||||
|
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
||||||
|
copyTextBottomSheetFragment.setArguments(bundle);
|
||||||
|
copyTextBottomSheetFragment.show(fragmentManager, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -286,11 +286,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
|
|||||||
&& !activity.isFinishing()
|
&& !activity.isFinishing()
|
||||||
&& captionTextView.getSelectionStart() == -1
|
&& captionTextView.getSelectionStart() == -1
|
||||||
&& captionTextView.getSelectionEnd() == -1) {
|
&& captionTextView.getSelectionEnd() == -1) {
|
||||||
Bundle bundle = new Bundle();
|
CopyTextBottomSheetFragment.show(
|
||||||
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, caption);
|
activity.getSupportFragmentManager(), caption, null);
|
||||||
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
|
|
||||||
copyTextBottomSheetFragment.setArguments(bundle);
|
|
||||||
copyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user