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

[Reader IA] Refresh blogs count after subscribing/unsubscribing from search screen #20135

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -184,8 +184,11 @@ public static void showReaderTagPreview(Context context, @NonNull ReaderTag tag,
}

public static void showReaderSearch(Context context) {
Intent intent = new Intent(context, ReaderSearchActivity.class);
context.startActivity(intent);
context.startActivity(createReaderSearchIntent(context));
}

public static Intent createReaderSearchIntent(@NonNull final Context context) {
return new Intent(context, ReaderSearchActivity.class);
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package org.wordpress.android.ui.reader

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.platform.ViewCompositionStrategy
Expand Down Expand Up @@ -67,6 +73,8 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), ScrollableView

private var binding: ReaderFragmentLayoutBinding? = null

private var readerSearchResultLauncher: ActivityResultLauncher<Intent>? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = ReaderFragmentLayoutBinding.bind(view).apply {
initTopAppBar()
Expand All @@ -89,6 +97,28 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), ScrollableView
activity?.let { viewModel.onScreenInBackground(it.isChangingConfigurations) }
}

override fun onAttach(context: Context) {
super.onAttach(context)
initReaderSearchActivityResultLauncher()
}

private fun initReaderSearchActivityResultLauncher() {
readerSearchResultLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
val data = result.data
if (data != null) {
val shouldRefreshSubscriptions =
data.getBooleanExtra(ReaderSearchActivity.RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, false)
if (shouldRefreshSubscriptions) {
getSubFilterViewModel()?.loadSubFilters()
}
}
}
}
}

private fun ReaderFragmentLayoutBinding.initTopAppBar() {
readerTopBarComposeView.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
Expand Down Expand Up @@ -125,7 +155,10 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), ScrollableView
}

viewModel.showSearch.observeEvent(viewLifecycleOwner) {
ReaderActivityLauncher.showReaderSearch(context)
context?.let {
val intent = ReaderActivityLauncher.createReaderSearchIntent(it)
readerSearchResultLauncher?.launch(intent)
}
}

viewModel.showReaderInterests.observeEvent(viewLifecycleOwner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -1261,7 +1262,10 @@ public boolean onMenuItemActionExpand(@NonNull MenuItem item) {
}

@Override
public boolean onMenuItemActionCollapse(@NonNull MenuItem item) {
public boolean onMenuItemActionCollapse(@NonNull final MenuItem item) {
if (getActivity() instanceof ReaderSearchActivity) {
((ReaderSearchActivity) requireActivity()).finishWithRefreshSubscriptionsResult();
}
requireActivity().finish();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.reader

import android.content.Intent
import android.os.Bundle
import dagger.hilt.android.AndroidEntryPoint
import org.wordpress.android.R
Expand Down Expand Up @@ -46,4 +47,15 @@ class ReaderSearchActivity : LocaleAwareActivity() {
super.onPause()
readerTracker.stop(MAIN_READER)
}

fun finishWithRefreshSubscriptionsResult() {
val data = Intent()
data.putExtra(ReaderSubsActivity.RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, true)
setResult(RESULT_OK, data)
finish()
}

companion object {
const val RESULT_SHOULD_REFRESH_SUBSCRIPTIONS = "should_refresh_subscriptions"
}
}
Loading