Skip to content

Commit

Permalink
Merge pull request #20158 from wordpress-mobile/merge/24.2-into-trunk
Browse files Browse the repository at this point in the history
Merge 24.2-rc-2 into trunk
  • Loading branch information
spencertransier authored Feb 9, 2024
2 parents eabd347 + 15782b1 commit daca615
Show file tree
Hide file tree
Showing 66 changed files with 2,877 additions and 4,415 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [*] [Jetpack-only] Site Monitoring: Add Metrics, PHP Logs, and Web Server Logs under Site Monitoring [https://github.com/wordpress-mobile/WordPress-Android/issues/20067]
* [**] Prevent images from temporarily disappearing when uploading media [https://github.com/WordPress/gutenberg/pull/57869]
* [***] [Jetpack-only] Reader: introduced new UI/UX for content navigation and filtering [https://github.com/wordpress-mobile/WordPress-Android/pull/19978]
* [**] Prevents crashes when the webview state is too big [https://github.com/wordpress-mobile/WordPress-Android/pull/20139]

24.1
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.util.extensions.CompatExtensionsKt;

import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -28,6 +30,9 @@ public abstract class WebViewActivity extends LocaleAwareActivity {

private static final String URL = "url";

private static final String WEBVIEW_CHROMIUM_STATE = "WEBVIEW_CHROMIUM_STATE";
private static final int WEBVIEW_CHROMIUM_STATE_THRESHOLD = 300 * 1024; // 300 KB

protected WebView mWebView;

@Override
Expand Down Expand Up @@ -84,18 +89,43 @@ protected void loadContent() {
* save the webView state with the bundle so it can be restored
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
mWebView.saveState(outState);

// If the WebView state is too large, remove it from the bundle and track the error. This workaround is
// necessary since the Android system cannot handle large states without a crash.
// Note that Chromium `WebViewBrowserFragment` uses a similar workaround for this issue:
// https://source.chromium.org/chromium/chromium/src/+/27a9bbd3dcd7005ac9f3862dc2e356b557023de9
byte[] webViewState = outState.getByteArray(WEBVIEW_CHROMIUM_STATE);
if (webViewState != null && webViewState.length > WEBVIEW_CHROMIUM_STATE_THRESHOLD) {
outState.remove(WEBVIEW_CHROMIUM_STATE);

// Save the URL so it can be restored later
String url = mWebView.getUrl();
outState.putString(URL, url);

// Track the error to better understand the root of the issue
Map<String, String> properties = new HashMap<>();
properties.put(URL, url);
AnalyticsTracker.track(AnalyticsTracker.Stat.WEBVIEW_TOO_LARGE_PAYLOAD_ERROR, properties);
}
super.onSaveInstanceState(outState);
}

/*
* restore the webView state saved above
*/
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mWebView.restoreState(savedInstanceState);
if (savedInstanceState.containsKey(WEBVIEW_CHROMIUM_STATE)) {
mWebView.restoreState(savedInstanceState);
} else {
String url = savedInstanceState.getString(URL);
if (url != null) {
mWebView.loadUrl(url);
}
}
}

@Override
Expand Down
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 Expand Up @@ -168,7 +201,9 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), ScrollableView

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
viewModel.onSaveInstanceState(outState)
if (::viewModel.isInitialized) {
viewModel.onSaveInstanceState(outState)
}
}

private fun updateUiState(uiState: ReaderViewModel.ReaderUiState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (blogInfo.hasName()) {
blogHolder.mTxtTitle.setText(blogInfo.getName());
} else {
blogHolder.mTxtTitle.setText(R.string.reader_untitled_post);
blogHolder.mTxtTitle.setText(UrlUtils.getHost(blogInfo.getUrl()));
}
if (blogInfo.hasUrl()) {
blogHolder.mTxtUrl.setText(UrlUtils.getHost(blogInfo.getUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ class ReaderPostUiStateBuilder @Inject constructor(

private fun buildBlogName(post: ReaderPost, isP2Post: Boolean = false): UiString {
val blogName = post.takeIf { it.hasBlogName() }?.blogName?.let { UiStringText(it) }
?:post.takeIf { it.hasBlogUrl() }
?.blogUrl
?.let { UiStringText(urlUtilsWrapper.removeScheme(it)) }
?: UiStringRes(R.string.untitled_in_parentheses)

if (!isP2Post) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.datasets.ReaderBlogTable
import org.wordpress.android.datasets.ReaderTagTable
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.models.ReaderBlog
import org.wordpress.android.models.ReaderTag
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.modules.UI_THREAD
Expand All @@ -32,9 +33,12 @@ import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T
import org.wordpress.android.util.EventBusWrapper
import org.wordpress.android.util.StringUtils
import org.wordpress.android.util.UrlUtils
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ScopedViewModel
import org.wordpress.android.viewmodel.SingleLiveEvent
import java.util.Comparator
import java.util.EnumSet
import javax.inject.Inject
import javax.inject.Named
Expand Down Expand Up @@ -110,6 +114,17 @@ class SubFilterViewModel @Inject constructor(
}
}

private fun getBlogNameForComparison(blog: ReaderBlog?): String {
return if (blog == null) {
""
} else if (blog.hasName()) {
blog.name
} else if (blog.hasUrl()) {
StringUtils.notNullStr(UrlUtils.getHost(blog.url))
} else {
""
}
}
fun loadSubFilters() {
launch {
val filterList = ArrayList<SubfilterListItem>()
Expand All @@ -124,7 +139,12 @@ class SubFilterViewModel @Inject constructor(
blog.organizationId == organization.orgId
} ?: false
}
}
}.sortedWith(Comparator { blog1, blog2 ->
// sort followed blogs by name/domain to match display
val blogOneName = getBlogNameForComparison(blog1)
val blogTwoName = getBlogNameForComparison(blog2)
blogOneName.compareTo(blogTwoName, true)
})

filterList.addAll(
followedBlogs.map { blog ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.ItemType.TAG
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.UrlUtils

sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = false) {
open var isSelected: Boolean = false
Expand Down Expand Up @@ -68,7 +69,8 @@ sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean =
override val label: UiString = if (blog.name.isNotEmpty()) {
UiStringText(blog.name)
} else {
UiStringRes(R.string.reader_untitled_post)
if (blog.url.isNotEmpty()) UiStringText(UrlUtils.getHost(blog.url))
else UiStringRes(R.string.reader_untitled_post)
}
val showUnseenCount: Boolean = blog.numUnseenPosts > 0
val unseenCount: Int = blog.numUnseenPosts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.JetpackBrandingUtils
import org.wordpress.android.util.QuickStartUtils
import org.wordpress.android.util.SnackbarSequencer
import org.wordpress.android.util.UrlUtilsWrapper
import org.wordpress.android.util.distinct
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ScopedViewModel
Expand All @@ -75,6 +76,7 @@ class ReaderViewModel @Inject constructor(
private val snackbarSequencer: SnackbarSequencer,
private val jetpackFeatureRemovalOverlayUtil: JetpackFeatureRemovalOverlayUtil,
private val readerTopBarMenuHelper: ReaderTopBarMenuHelper,
private val urlUtilsWrapper: UrlUtilsWrapper,
// todo: annnmarie removed this private val getFollowedTagsUseCase: GetFollowedTagsUseCase
) : ScopedViewModel(mainDispatcher) {
private var initialized: Boolean = false
Expand Down Expand Up @@ -385,7 +387,8 @@ class ReaderViewModel @Inject constructor(
fun onSubFilterItemSelected(item: SubfilterListItem) {
when (item) {
is SubfilterListItem.SiteAll -> clearTopBarFilter()
is SubfilterListItem.Site -> updateTopBarFilter(item.blog.name, ReaderFilterType.BLOG)
is SubfilterListItem.Site -> updateTopBarFilter(item.blog.name
.ifEmpty { urlUtilsWrapper.removeScheme(item.blog.url.ifEmpty { "" }) }, ReaderFilterType.BLOG)
is SubfilterListItem.Tag -> updateTopBarFilter(item.tag.tagDisplayName, ReaderFilterType.TAG)
else -> Unit // do nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ private void showBlogInfo(ReaderBlog blogInfo, String source) {
if (blogInfo.hasName()) {
txtBlogName.setText(blogInfo.getName());
} else {
txtBlogName.setText(R.string.reader_untitled_post);
if (blogInfo.getUrl() != null) {
txtBlogName.setText(UrlUtils.getHost(blogInfo.getUrl()));
} else {
txtBlogName.setText(R.string.reader_untitled_post);
}
}

if (blogInfo.hasUrl()) {
Expand Down
Loading

0 comments on commit daca615

Please sign in to comment.