Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @username suggestions to notification and reader full comment view. #10781

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.wordpress.android.push.GCMRegistrationIntentService;
import org.wordpress.android.push.NotificationsProcessingService;
import org.wordpress.android.ui.AddQuickPressShortcutActivity;
import org.wordpress.android.ui.CommentFullScreenDialogFragment;
import org.wordpress.android.ui.DeepLinkingIntentReceiverActivity;
import org.wordpress.android.ui.JetpackConnectionResultActivity;
import org.wordpress.android.ui.JetpackRemoteInstallFragment;
Expand Down Expand Up @@ -236,6 +237,8 @@ public interface AppComponent extends AndroidInjector<WordPress> {

void inject(CommentDetailFragment object);

void inject(CommentFullScreenDialogFragment object);

void inject(EditCommentActivity object);

void inject(CommentAdapter object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ import dagger.android.support.AndroidSupportInjection
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.wordpress.android.R
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.CollapseFullScreenDialogFragment.CollapseFullScreenDialogContent
import org.wordpress.android.ui.CollapseFullScreenDialogFragment.CollapseFullScreenDialogController
import org.wordpress.android.ui.suggestion.util.SuggestionServiceConnectionManager
import org.wordpress.android.ui.suggestion.util.SuggestionUtils
import org.wordpress.android.util.SiteUtils
import org.wordpress.android.widgets.SuggestionAutoCompleteText
import javax.inject.Inject
import org.wordpress.android.fluxc.store.SiteStore

class CommentFullScreenDialogFragment : Fragment(), CollapseFullScreenDialogContent {
@Inject lateinit var viewModel: CommentFullScreenDialogViewModel
@Inject lateinit var siteStore: SiteStore
private lateinit var dialogController: CollapseFullScreenDialogController
private lateinit var reply: SuggestionAutoCompleteText
private lateinit var siteModel: SiteModel

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -55,11 +62,31 @@ class CommentFullScreenDialogFragment : Fragment(), CollapseFullScreenDialogCont
reply.setText(it.getString(EXTRA_REPLY))
reply.setSelection(it.getInt(EXTRA_SELECTION_START), it.getInt(EXTRA_SELECTION_END))
viewModel.init()

siteModel = siteStore.getSiteBySiteId(it.getLong(EXTRA_SITE_ID))
setupSuggestionServiceAndAdapter(siteModel)
}

return layout
}

private fun setupSuggestionServiceAndAdapter(site: SiteModel) {
if (!isAdded || !SiteUtils.isAccessedViaWPComRest(site)) {
return
}
val suggestionServiceConnectionManager = SuggestionServiceConnectionManager(
activity,
site.siteId
)
val suggestionAdapter = SuggestionUtils.setupSuggestions(
site, activity,
suggestionServiceConnectionManager
)
if (suggestionAdapter != null) {
this.reply.setAdapter(suggestionAdapter)
}
}

override fun onCollapseClicked(controller: CollapseFullScreenDialogController): Boolean {
controller.collapse(saveResult())
return true
Expand Down Expand Up @@ -95,12 +122,14 @@ class CommentFullScreenDialogFragment : Fragment(), CollapseFullScreenDialogCont
private const val EXTRA_REPLY = "EXTRA_REPLY"
private const val EXTRA_SELECTION_START = "EXTRA_SELECTION_START"
private const val EXTRA_SELECTION_END = "EXTRA_SELECTION_END"
private const val EXTRA_SITE_ID = "EXTRA_SITE_ID"

fun newBundle(reply: String, selectionStart: Int, selectionEnd: Int): Bundle {
fun newBundle(reply: String, selectionStart: Int, selectionEnd: Int, siteId: Long): Bundle {
val bundle = Bundle()
bundle.putString(EXTRA_REPLY, reply)
bundle.putInt(EXTRA_SELECTION_START, selectionStart)
bundle.putInt(EXTRA_SELECTION_END, selectionEnd)
bundle.putLong(EXTRA_SITE_ID, siteId)
return bundle
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ public void onClick(View v) {
Bundle bundle = Companion.newBundle(
mEditReply.getText().toString(),
mEditReply.getSelectionStart(),
mEditReply.getSelectionEnd()
mEditReply.getSelectionEnd(),
mSite.getSiteId()
);

new Builder(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.wordpress.android.datasets.ReaderPostTable;
import org.wordpress.android.datasets.SuggestionTable;
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.models.ReaderComment;
import org.wordpress.android.models.ReaderPost;
import org.wordpress.android.models.Suggestion;
Expand Down Expand Up @@ -117,7 +119,9 @@ public class ReaderCommentListActivity extends AppCompatActivity {
private long mCommentId;
private int mRestorePosition;
private String mInterceptedUri;
private SiteModel mSite;

@Inject SiteStore mSiteStore;
@Inject AccountStore mAccountStore;
@Inject ViewModelProvider.Factory mViewModelFactory;
private ReaderCommentListViewModel mViewModel;
Expand Down Expand Up @@ -256,6 +260,8 @@ public void afterTextChanged(Editable s) {

AnalyticsUtils.trackWithReaderPostDetails(AnalyticsTracker.Stat.READER_ARTICLE_COMMENTS_OPENED, mPost);

mSite = mSiteStore.getSiteBySiteId(mBlogId);

ImageView buttonExpand = findViewById(R.id.button_expand);
buttonExpand.setOnClickListener(
new OnClickListener() {
Expand All @@ -264,7 +270,9 @@ public void onClick(View v) {
Bundle bundle = CommentFullScreenDialogFragment.Companion
.newBundle(mEditComment.getText().toString(),
mEditComment.getSelectionStart(),
mEditComment.getSelectionEnd());
mEditComment.getSelectionEnd(),
mBlogId
);

new Builder(ReaderCommentListActivity.this)
.setTitle(R.string.comment)
Expand Down
40 changes: 27 additions & 13 deletions WordPress/src/main/res/layout/comment_dialog_fragment.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>

<ScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:clipChildren="false"
android:clipToPadding="false"
android:fillViewport="true"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="@dimen/margin_extra_large"
android:scrollbarStyle="outsideOverlay" >
android:scrollbarStyle="outsideOverlay">

<org.wordpress.android.widgets.SuggestionAutoCompleteText
android:id="@+id/edit_comment_expand"
android:background="@android:color/transparent"
android:gravity="start|top"
android:hint="@string/reader_hint_comment_on_post"
android:imeOptions="actionSend"
android:inputType="text|textCapSentences|textMultiLine"
android:layout_height="wrap_content"
<androidx.constraintlayout.widget.ConstraintLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:textAlignment="viewStart"
android:textColorHint="@color/neutral_40"
android:textSize="@dimen/text_sz_large" >
</org.wordpress.android.widgets.SuggestionAutoCompleteText>
android:layout_height="wrap_content">

<org.wordpress.android.widgets.SuggestionAutoCompleteText
android:id="@+id/edit_comment_expand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="start|top"
android:hint="@string/reader_hint_comment_on_post"
android:imeOptions="actionSend"
android:inputType="text|textCapSentences|textMultiLine"
android:textAlignment="viewStart"
android:textColorHint="@color/neutral_40"
android:textSize="@dimen/text_sz_large"
app:layout_constraintTop_toTopOf="parent"
android:dropDownAnchor="@+id/dummy_hidden_view" />

<View
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really smart. 👍

android:id="@+id/dummy_hidden_view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>