refactor: Extract CopyTextBottomSheetFragment display logic (#969)

This commit is contained in:
Sergei Kozelko 2022-09-09 08:38:42 +03:00 committed by GitHub
parent 45bc223659
commit b72bfdef37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 39 deletions

View File

@ -199,7 +199,6 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
Intent intent = getIntent();
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
String parentText = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
int linkColor = mCustomThemeWrapper.getLinkColor();
Markwon markwon = Markwon.builder(this)
@ -242,15 +241,13 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
if (parentTextMarkdown != null) {
commentParentMarkwonView.setOnLongClickListener(view -> {
Utils.hideKeyboard(CommentActivity.this);
Bundle bundle = new Bundle();
if (parentText == null) {
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentTextMarkdown);
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
parentTextMarkdown, null);
} else {
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentText);
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentTextMarkdown);
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
parentText, parentTextMarkdown);
}
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
return true;
});
markwon.setMarkdown(commentParentMarkwonView, parentTextMarkdown);
@ -285,11 +282,8 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
textView.setTextColor(markdownColor);
textView.setOnLongClickListener(view -> {
Utils.hideKeyboard(CommentActivity.this);
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentBody);
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentBodyMarkdown);
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
parentBody, parentBodyMarkdown);
return true;
});
}

View File

@ -404,11 +404,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, description);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
CopyTextBottomSheetFragment.show(getSupportFragmentManager(), description, null);
}
return true;
});

View File

@ -400,11 +400,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, description);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
CopyTextBottomSheetFragment.show(getSupportFragmentManager(), description, null);
}
return true;
});

View File

@ -269,12 +269,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
textView.setTextColor(markdownColor);
textView.setOnLongClickListener(view -> {
if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) {
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, mPost.getSelfTextPlain());
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, mPost.getSelfText());
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(mActivity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
CopyTextBottomSheetFragment.show(
mActivity.getSupportFragmentManager(),
mPost.getSelfTextPlain(), mPost.getSelfText()
);
}
return true;
});

View File

@ -181,12 +181,8 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
copyTextView.setOnClickListener(view -> {
dismiss();
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
Bundle copyBundle = new Bundle();
copyBundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, comment.getCommentMarkdown());
copyBundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, comment.getCommentRawText());
copyTextBottomSheetFragment.setArguments(copyBundle);
copyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
CopyTextBottomSheetFragment.show(activity.getSupportFragmentManager(),
comment.getCommentRawText(), comment.getCommentMarkdown());
});
reportTextView.setOnClickListener(view -> {

View File

@ -12,8 +12,10 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -49,6 +51,19 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
// 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
public View onCreateView(LayoutInflater inflater, ViewGroup container,

View File

@ -286,11 +286,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
&& !activity.isFinishing()
&& captionTextView.getSelectionStart() == -1
&& captionTextView.getSelectionEnd() == -1) {
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, caption);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
CopyTextBottomSheetFragment.show(
activity.getSupportFragmentManager(), caption, null);
}
return true;
});