Skip to content

Commit

Permalink
Merge pull request #20610 from wordpress-mobile/release/24.6
Browse files Browse the repository at this point in the history
Merge 24.6-rc-2 to trunk
  • Loading branch information
oguzkocer authored Apr 8, 2024
2 parents d1577bb + 3ecff4b commit db2858d
Show file tree
Hide file tree
Showing 76 changed files with 1,046 additions and 130 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [**] Block editor: Highlight text fixes [https://github.com/WordPress/gutenberg/pull/57650]
* [*] Block editor: Fixes an Aztec editor crash occurring on some occasions when the keyboard suggestions are used [https://github.com/wordpress-mobile/WordPress-Android/pull/20518]
* [*] [Jetpack-only] Change "∞" symbol with "100%" on stats [https://github.com/wordpress-mobile/WordPress-Android/pull/20564]
* [**] [Jetpack-only] Reader: introduce "reading preferences", an experimental feature that allows users to customize their Reader post content screen with the color, font, and size that they like the most. [https://github.com/wordpress-mobile/WordPress-Android/pull/20567]

24.5
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
mSiteSettings.setDefaultCategory(Integer.parseInt(newValue.toString()));
setDetailListPreferenceValue(mCategoryPref,
newValue.toString(),
mSiteSettings.getDefaultCategoryForDisplay());
mSiteSettings.getDefaultCategoryForDisplay().replace("%", "%%"));
} else if (preference == mFormatPref) {
mSiteSettings.setDefaultFormat(newValue.toString());
setDetailListPreferenceValue(mFormatPref,
Expand Down Expand Up @@ -1652,7 +1652,7 @@ private void setCategories() {
mCategoryPref.setEntries(entries);
mCategoryPref.setEntryValues(values);
mCategoryPref.setValue(String.valueOf(mSiteSettings.getDefaultCategory()));
mCategoryPref.setSummary(mSiteSettings.getDefaultCategoryForDisplay());
mCategoryPref.setSummary(mSiteSettings.getDefaultCategoryForDisplay().replace("%", "%%"));
}

private void setPostFormats() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class AccountSettingsFragment : PreferenceFragmentLifeCycleOwner(),
primarySiteSettingsUiState?.let { state ->
primarySitePreference.apply {
value = (state.primarySite?.siteId ?: "").toString()
summary = state.primarySite?.siteName
summary = state.primarySite?.siteName?.replace("%", "%%")
entries = state.siteNames
entryValues = state.siteIds
canShowDialog = state.canShowChoosePrimarySiteDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import org.wordpress.android.ui.reader.discover.ReaderPostCardAction.PrimaryActi
import org.wordpress.android.ui.reader.discover.ReaderPostCardActionType
import org.wordpress.android.ui.reader.models.ReaderBlogIdPostId
import org.wordpress.android.ui.reader.models.ReaderReadingPreferences
import org.wordpress.android.ui.reader.tracker.ReaderReadingPreferencesTracker
import org.wordpress.android.ui.reader.tracker.ReaderTracker
import org.wordpress.android.ui.reader.tracker.ReaderTracker.Companion.SOURCE_POST_DETAIL_TOOLBAR
import org.wordpress.android.ui.reader.usecases.ReaderGetReadingPreferencesSyncUseCase
Expand Down Expand Up @@ -932,7 +933,10 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
}

ReaderNavigationEvents.ShowReadingPreferences ->
ReaderReadingPreferencesDialogFragment.show(childFragmentManager)
ReaderReadingPreferencesDialogFragment.show(
childFragmentManager,
ReaderReadingPreferencesTracker.Source.POST_DETAIL_MORE_MENU,
)

is ReaderNavigationEvents.ShowPostDetail,
is ReaderNavigationEvents.ShowVideoViewer,
Expand Down Expand Up @@ -1105,7 +1109,10 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
true
}
R.id.menu_reading_preferences -> {
ReaderReadingPreferencesDialogFragment.show(childFragmentManager)
ReaderReadingPreferencesDialogFragment.show(
childFragmentManager,
ReaderReadingPreferencesTracker.Source.POST_DETAIL_TOOLBAR,
)
true
}
else -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.wordpress.android.ui.reader.services.post.ReaderPostServiceStarter;
import org.wordpress.android.ui.reader.tracker.ReaderTracker;
import org.wordpress.android.ui.reader.tracker.ReaderTrackerType;
import org.wordpress.android.ui.reader.usecases.ReaderGetReadingPreferencesSyncUseCase;
import org.wordpress.android.ui.reader.utils.ReaderPostSeenStatusWrapper;
import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource;
import org.wordpress.android.ui.uploads.UploadActionUseCase;
Expand Down Expand Up @@ -176,6 +177,7 @@ public enum DirectOperation {
private JetpackFeatureFullScreenOverlayViewModel mJetpackFullScreenViewModel;
@Inject AccountStore mAccountStore;
@Inject JetpackFeatureRemovalPhaseHelper mJetpackFeatureRemovalPhaseHelper;
@Inject ReaderGetReadingPreferencesSyncUseCase mGetReadingPreferencesSyncUseCase;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -766,7 +768,8 @@ private void trackPost(long blogId, long postId) {
// analytics tracking
mReaderTracker.trackPost(
AnalyticsTracker.Stat.READER_ARTICLE_OPENED,
mReaderPostTableWrapper.getBlogPost(blogId, postId, true)
mReaderPostTableWrapper.getBlogPost(blogId, postId, true),
mGetReadingPreferencesSyncUseCase.invoke()
);
}

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

import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -22,11 +23,13 @@ import org.wordpress.android.R
import org.wordpress.android.ui.WPWebViewActivity
import org.wordpress.android.ui.compose.theme.AppTheme
import org.wordpress.android.ui.reader.models.ReaderReadingPreferences
import org.wordpress.android.ui.reader.tracker.ReaderReadingPreferencesTracker
import org.wordpress.android.ui.reader.viewmodels.ReaderPostDetailViewModel
import org.wordpress.android.ui.reader.viewmodels.ReaderReadingPreferencesViewModel
import org.wordpress.android.ui.reader.viewmodels.ReaderReadingPreferencesViewModel.ActionEvent
import org.wordpress.android.ui.reader.views.compose.readingpreferences.ReadingPreferencesScreen
import org.wordpress.android.util.extensions.fillScreen
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.setWindowStatusBarColor

@AndroidEntryPoint
Expand All @@ -40,6 +43,13 @@ class ReaderReadingPreferencesDialogFragment : BottomSheetDialogFragment() {
return R.style.ReaderReadingPreferencesDialogFragment
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.getSerializableCompat<ReaderReadingPreferencesTracker.Source>(ARG_SOURCE)?.let {
viewModel.onScreenOpened(it)
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -78,6 +88,11 @@ class ReaderReadingPreferencesDialogFragment : BottomSheetDialogFragment() {
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
viewModel.onScreenClosed()
}

private fun observeActionEvents() {
viewModel.actionEvents.onEach {
when (it) {
Expand Down Expand Up @@ -106,13 +121,23 @@ class ReaderReadingPreferencesDialogFragment : BottomSheetDialogFragment() {
}

companion object {
const val TAG = "READER_READING_PREFERENCES_FRAGMENT"
private const val TAG = "READER_READING_PREFERENCES_FRAGMENT"
private const val ARG_SOURCE = "source"

@JvmStatic
fun newInstance(): ReaderReadingPreferencesDialogFragment = ReaderReadingPreferencesDialogFragment()
fun newInstance(
source: ReaderReadingPreferencesTracker.Source,
): ReaderReadingPreferencesDialogFragment = ReaderReadingPreferencesDialogFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_SOURCE, source)
}
}

@JvmStatic
fun show(fm: FragmentManager): ReaderReadingPreferencesDialogFragment = newInstance().also {
fun show(
fm: FragmentManager,
source: ReaderReadingPreferencesTracker.Source,
): ReaderReadingPreferencesDialogFragment = newInstance(source).also {
it.show(fm, TAG)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ class ReaderPostCardActionsHandler @Inject constructor(
}

private fun handleReadingPreferencesClicked() {
// TODO add analytics readerTracker.track(AnalyticsTracker.Stat.READER_READING_PREFERENCES_OPENED)
_navigationEvents.postValue(Event(ShowReadingPreferences))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import java.util.Locale
import com.google.android.material.R as MaterialR

data class ReaderReadingPreferences @JvmOverloads constructor(
val theme: Theme = Theme.SYSTEM,
val fontFamily: FontFamily = FontFamily.SANS,
val theme: Theme = Theme.DEFAULT,
val fontFamily: FontFamily = FontFamily.DEFAULT,
val fontSize: FontSize = FontSize.DEFAULT,
) {
enum class Theme(
Expand Down Expand Up @@ -74,7 +74,11 @@ data class ReaderReadingPreferences @JvmOverloads constructor(
backgroundColorRes = R.color.reader_theme_candy_background,
baseTextColorRes = R.color.reader_theme_candy_text,
linkColorRes = R.color.reader_theme_candy_text,
),
);

companion object {
val DEFAULT = SYSTEM
}
}

@Suppress("MagicNumber")
Expand Down Expand Up @@ -165,17 +169,39 @@ data class ReaderReadingPreferences @JvmOverloads constructor(
MONO(
displayNameRes = R.string.reader_preferences_font_family_mono,
value = "monospace",
),
);

companion object {
val DEFAULT = SANS
}
}

enum class FontSize(val value: Int) {
EXTRA_SMALL(10),
SMALL(12),
enum class FontSize(
@StringRes val displayNameRes: Int,
val value: Int,
) {
EXTRA_SMALL(
displayNameRes = R.string.reader_preferences_font_size_extra_small,
value = 10,
),
SMALL(
displayNameRes = R.string.reader_preferences_font_size_small,
value = 12,
),

@FallbackValue
NORMAL(16),
LARGE(20),
EXTRA_LARGE(24);
NORMAL(
displayNameRes = R.string.reader_preferences_font_size_normal,
value = 16,
),
LARGE(
displayNameRes = R.string.reader_preferences_font_size_large,
value = 20,
),
EXTRA_LARGE(
displayNameRes = R.string.reader_preferences_font_size_extra_large,
value = 24,
);

val multiplier: Float
get() = value / DEFAULT.value.toFloat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.wordpress.android.util.EnumWithFallbackValueTypeAdapterFactory
import org.wordpress.android.util.config.ReaderReadingPreferencesFeatureConfig
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton

@Singleton
class ReaderReadingPreferencesRepository @Inject constructor(
private val appPrefsWrapper: AppPrefsWrapper,
private val readingPreferencesFeatureConfig: ReaderReadingPreferencesFeatureConfig,
Expand All @@ -20,23 +22,31 @@ class ReaderReadingPreferencesRepository @Inject constructor(
.registerTypeAdapterFactory(EnumWithFallbackValueTypeAdapterFactory())
.create()

// the preferences never change during the app lifecycle, so we can cache them safely for better performance
private var readingPreferences: ReaderReadingPreferences? = null

suspend fun getReadingPreferences(): ReaderReadingPreferences = withContext(ioDispatcher) {
getReadingPreferencesSync()
}

fun getReadingPreferencesSync(): ReaderReadingPreferences {
val savedPreferences = if (readingPreferencesFeatureConfig.isEnabled()) {
appPrefsWrapper.readerReadingPreferencesJson
} else {
null
if (!readingPreferencesFeatureConfig.isEnabled()) {
return ReaderReadingPreferences()
}

return savedPreferences?.let {
gson.fromJson(it, ReaderReadingPreferences::class.java)
} ?: ReaderReadingPreferences()
return readingPreferences ?: loadReadingPreferences().also {
readingPreferences = it
}
}

suspend fun saveReadingPreferences(preferences: ReaderReadingPreferences): Unit = withContext(ioDispatcher) {
appPrefsWrapper.readerReadingPreferencesJson = gson.toJson(preferences)
readingPreferences = preferences
}

private fun loadReadingPreferences(): ReaderReadingPreferences {
return appPrefsWrapper.readerReadingPreferencesJson?.let {
gson.fromJson(it, ReaderReadingPreferences::class.java)
} ?: ReaderReadingPreferences()
}
}
Loading

0 comments on commit db2858d

Please sign in to comment.