Skip to content

Commit

Permalink
Merge branch 'trunk' into task/os-version-rules
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
Antonis Lilis committed Jun 6, 2024
2 parents d8450b6 + dd271c7 commit f7f572b
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 53 deletions.
20 changes: 11 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ GEM
no_proxy_fix
octokit (>= 4.0)
terminal-table (>= 1, < 4)
danger-dangermattic (1.0.2)
danger-dangermattic (1.1.1)
danger (~> 9.4)
danger-plugin-api (~> 1.0)
danger-rubocop (~> 0.12)
rubocop (~> 1.61)
danger-rubocop (~> 0.13)
rubocop (~> 1.63)
danger-plugin-api (1.0.0)
danger (> 2.0)
danger-rubocop (0.12.0)
danger-rubocop (0.13.0)
danger
rubocop (~> 1.0)
declarative (0.0.20)
Expand Down Expand Up @@ -259,30 +259,31 @@ GEM
optparse (0.4.0)
os (1.1.4)
parallel (1.24.0)
parser (3.3.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
plist (3.7.1)
progress_bar (1.3.3)
highline (>= 1.6, < 3)
options (~> 2.3.0)
public_suffix (5.0.5)
racc (1.7.3)
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rchardet (1.8.0)
regexp_parser (2.9.1)
regexp_parser (2.9.2)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.6)
rexml (3.2.8)
strscan (>= 3.0.9)
rmagick (4.3.0)
rouge (2.0.7)
rubocop (1.63.5)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -310,6 +311,7 @@ GEM
simctl (1.6.10)
CFPropertyList
naturally
strscan (3.1.0)
terminal-notifier (2.0.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.wordpress.android.datasets

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
* Helper class to handle async tasks by using coroutines
* @see <a href="https://github.com/wordpress-mobile/WordPress-Android/pull/20937">Introduction</a>
*/
object AsyncTaskHandler {
/**
* Load data in the background and handle the result on the main thread
*/
@JvmStatic
fun <T> load(backgroundTask: () -> T, callback: AsyncTaskCallback<T>) {
CoroutineScope(Dispatchers.IO).launch {
// handle the background task
val result = backgroundTask()

withContext(Dispatchers.Main) {
// handle the result on the main thread
callback.onTaskFinished(result)
}
}
}

interface AsyncTaskCallback<T> {
fun onTaskFinished(result: T)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ class ChooseSiteViewHolder(private val binding: ItemChooseSiteBinding) : Recycle
}

private fun handleAvatar(site: SiteRecord) {
imageManager.loadImageWithCorners(
binding.avatar, site.blavatarType, site.blavatarUrl,
itemView.context.resources.getDimensionPixelSize(R.dimen.blavatar_sz) / 2
)
imageManager.load(binding.avatar, site.blavatarType, site.blavatarUrl)
val isDarkTheme = itemView.resources.configuration.isDarkTheme()
val borderColor = ContextCompat.getColor(
itemView.context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.datasets.AsyncTaskHandler;
import org.wordpress.android.datasets.ReaderPostTable;
import org.wordpress.android.datasets.ReaderTagTable;
import org.wordpress.android.fluxc.store.AccountStore;
Expand Down Expand Up @@ -371,44 +372,47 @@ private void toggleFollowButton(
return;
}

final boolean isAskingToFollow = !ReaderTagTable.isFollowedTagName(currentTag.getTagSlug());

final String slugForTracking = currentTag.getTagSlug();
AsyncTaskHandler.load(
() -> !ReaderTagTable.isFollowedTagName(currentTag.getTagSlug()),
isAskingToFollow -> {
final String slugForTracking = currentTag.getTagSlug();

ReaderActions.ActionListener listener = succeeded -> {
if (!succeeded) {
int errResId = isAskingToFollow ? R.string.reader_toast_err_adding_tag
: R.string.reader_toast_err_removing_tag;
ToastUtils.showToast(context, errResId);
} else {
if (isAskingToFollow) {
mReaderTracker.trackTag(
AnalyticsTracker.Stat.READER_TAG_FOLLOWED,
slugForTracking,
mSource
);
} else {
mReaderTracker.trackTag(
AnalyticsTracker.Stat.READER_TAG_UNFOLLOWED,
slugForTracking,
mSource
);
}
}
renderTagHeader(currentTag, tagHolder, true);
};

boolean success;
boolean isLoggedIn = mAccountStore.hasAccessToken();
if (isAskingToFollow) {
success = ReaderTagActions.addTag(mCurrentTag, listener, isLoggedIn);
} else {
success = ReaderTagActions.deleteTag(mCurrentTag, listener, isLoggedIn);
}

ReaderActions.ActionListener listener = succeeded -> {
if (!succeeded) {
int errResId = isAskingToFollow ? R.string.reader_toast_err_adding_tag
: R.string.reader_toast_err_removing_tag;
ToastUtils.showToast(context, errResId);
} else {
if (isAskingToFollow) {
mReaderTracker.trackTag(
AnalyticsTracker.Stat.READER_TAG_FOLLOWED,
slugForTracking,
mSource
);
} else {
mReaderTracker.trackTag(
AnalyticsTracker.Stat.READER_TAG_UNFOLLOWED,
slugForTracking,
mSource
);
if (isLoggedIn && success) {
renderTagHeader(currentTag, tagHolder, false);
}
}
}
renderTagHeader(currentTag, tagHolder, true);
};

boolean success;
boolean isLoggedIn = mAccountStore.hasAccessToken();
if (isAskingToFollow) {
success = ReaderTagActions.addTag(mCurrentTag, listener, isLoggedIn);
} else {
success = ReaderTagActions.deleteTag(mCurrentTag, listener, isLoggedIn);
}

if (isLoggedIn && success) {
renderTagHeader(currentTag, tagHolder, false);
}
);
}

private void renderXPost(int position, ReaderXPostViewHolder holder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,30 @@ class ReaderTopBarMenuHelper @Inject constructor(
.takeIf { it.isNotEmpty() }
?.let { customListsArray ->
add(MenuElementData.Divider)
add(createCustomListsItem(customListsArray))
createCustomListsItems(customListsArray)
}
}
}

private fun MutableList<MenuElementData>.createCustomListsItems(
customListsArray: SparseArrayCompat<ReaderTag>
) {
if (customListsArray.size() > 2) {
// If custom lists has more than 2 items, we add a submenu called "Lists"
add(createCustomListsItem(customListsArray))
} else {
// If the custom lists has 2 or less items, we add the items directly without submenu
customListsArray.forEach { index, readerTag ->
add(
MenuElementData.Item.Single(
id = getMenuItemIdFromReaderTagIndex(index),
text = UiString.UiStringText(readerTag.tagTitle),
)
)
}
}
}

private fun createDiscoverItem(id: String): MenuElementData.Item.Single {
return MenuElementData.Item.Single(
id = id,
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/item_choose_site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_extra_large"
android:layout_marginVertical="@dimen/margin_medium"
app:cardCornerRadius="@dimen/avatar_sz_medium_radius"
app:cardCornerRadius="@dimen/blavatar_sz_radius"
app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
<dimen name="avatar_sz_extra_small">24dp</dimen>
<dimen name="avatar_sz_small">32dp</dimen>
<dimen name="avatar_sz_medium">40dp</dimen>
<dimen name="avatar_sz_medium_radius">20dp</dimen>
<dimen name="avatar_sz_inner_circle">48dp</dimen>
<dimen name="avatar_sz_large">64dp</dimen>
<dimen name="avatar_sz_extra_large">72dp</dimen>
Expand All @@ -189,6 +188,7 @@
<dimen name="avatar_background_padding">1dp</dimen>
<dimen name="blavatar_sz_small">32dp</dimen>
<dimen name="blavatar_sz">40dp</dimen>
<dimen name="blavatar_sz_radius">5dp</dimen>
<dimen name="blavatar_sz_extra_large">72dp</dimen>
<dimen name="my_site_blavatar_sz">56dp</dimen>

Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,6 @@

<style name="AvatarShapeAppearanceOverlay">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">@dimen/avatar_sz_medium_radius</item>
<item name="cornerSize">@dimen/blavatar_sz_radius</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ class ReaderTopBarMenuHelperTest {
assertThat(customList3Item.text).isEqualTo(UiStringText("custom-list-3"))
}

@Test
fun `GIVEN custom lists has 2 items or less WHEN createMenu THEN custom lists items are shown outside a submenu`() {
val tags = ReaderTagList().apply {
add(mockFollowingTag()) // item 0
add(mockDiscoverTag()) // item 1
add(mockSavedTag()) // item 2
add(mockLikedTag()) // item 3
add(mockA8CTag()) // item 4
add(mockFollowedP2sTag()) // item 5
add(createCustomListTag("custom-list-1")) // item 6
add(createCustomListTag("custom-list-2")) // item 7
}
val menu = helper.createMenu(tags)

val customListItem1 = menu.findSingleItem { it.id == "6" }!!
assertThat(customListItem1.text).isEqualTo(UiStringText("custom-list-1"))

val customListItem2 = menu.findSingleItem { it.id == "7" }!!
assertThat(customListItem2.text).isEqualTo(UiStringText("custom-list-2"))
}

@Test
fun `GIVEN all tags are available and tags FF enabled WHEN createMenu THEN all items are created correctly`() {
whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true)
Expand Down

0 comments on commit f7f572b

Please sign in to comment.