Skip to content

Commit

Permalink
Merge branch 'main' into recommended-content-design
Browse files Browse the repository at this point in the history
* main:
  Optimizing the NewsItem and OnThisDay variables (#4923)
  • Loading branch information
cooltey committed Sep 5, 2024
2 parents b751ba7 + d21edaa commit 9c0b2ed
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 72 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/wikipedia/feed/news/NewsItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NewsItem(
}
}

private fun getFirstImageUri(links: List<PageSummary?>): Uri? {
return links.firstOrNull { !it?.thumbnailUrl.isNullOrEmpty() }?.run { Uri.parse(thumbnailUrl) }
private fun getFirstImageUri(links: List<PageSummary>): Uri? {
return links.firstOrNull { !it.thumbnailUrl.isNullOrEmpty() }?.run { Uri.parse(thumbnailUrl) }
}
}
1 change: 0 additions & 1 deletion app/src/main/java/org/wikipedia/feed/news/NewsLinkCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.wikipedia.feed.model.Card
import org.wikipedia.feed.model.CardType
import org.wikipedia.page.PageTitle
import org.wikipedia.util.ImageUrlUtil
import org.wikipedia.util.ImageUrlUtil.getUrlForPreferredSize

class NewsLinkCard(private val page: PageSummary, private val wiki: WikiSite) : Card() {

Expand Down
7 changes: 1 addition & 6 deletions app/src/main/java/org/wikipedia/feed/onthisday/OnThisDay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ class OnThisDay {

@Serializable
class Event {

private val pages: List<PageSummary?>? = null
val pages: List<PageSummary> = emptyList()
val text = ""
val year = 0

fun pages(): List<PageSummary>? {
return pages?.filterNotNull()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import org.wikipedia.feed.model.WikiSiteCard
import org.wikipedia.feed.view.FeedAdapter
import org.wikipedia.util.DateUtil
import org.wikipedia.util.L10nUtil
import java.util.*
import java.util.Calendar
import java.util.Random
import java.util.concurrent.TimeUnit

class OnThisDayCard(events: List<OnThisDay.Event>, wiki: WikiSite, val age: Int) : WikiSiteCard(wiki) {
Expand Down Expand Up @@ -58,7 +59,7 @@ class OnThisDayCard(events: List<OnThisDay.Event>, wiki: WikiSite, val age: Int)
return date
}

fun pages(): List<PageSummary>? {
return eventShownOnCard.pages()
fun pages(): List<PageSummary> {
return eventShownOnCard.pages
}
}
106 changes: 53 additions & 53 deletions app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,67 +90,67 @@ class OnThisDayCardView(context: Context) : DefaultFeedCardView<OnThisDayCard>(c

private fun updateOtdEventUI(card: OnThisDayCard) {
binding.eventLayout.pagesPager.visibility = GONE
card.pages()?.let { pages ->
binding.eventLayout.onThisDayPage.root.visibility = VISIBLE
val chosenPage = pages.find { it.thumbnailUrl != null }
chosenPage?.let { page ->
if (page.thumbnailUrl.isNullOrEmpty()) {
binding.eventLayout.onThisDayPage.imageContainer.visibility = GONE
if (card.pages().isEmpty()) {
binding.eventLayout.onThisDayPage.root.visibility = GONE
return
}
binding.eventLayout.onThisDayPage.root.visibility = VISIBLE
val chosenPage = card.pages().find { it.thumbnailUrl != null }
chosenPage?.let { page ->
if (page.thumbnailUrl.isNullOrEmpty()) {
binding.eventLayout.onThisDayPage.imageContainer.visibility = GONE
} else {
binding.eventLayout.onThisDayPage.imageContainer.visibility = VISIBLE
binding.eventLayout.onThisDayPage.image.loadImage(Uri.parse(page.thumbnailUrl))
ImageZoomHelper.setViewZoomable(binding.eventLayout.onThisDayPage.image)
}
binding.eventLayout.onThisDayPage.description.text = page.description
binding.eventLayout.onThisDayPage.description.visibility =
if (page.description.isNullOrEmpty()) GONE else VISIBLE
binding.eventLayout.onThisDayPage.title.maxLines =
if (page.description.isNullOrEmpty()) 2 else 1
binding.eventLayout.onThisDayPage.title.text = StringUtil.fromHtml(page.displayTitle)
binding.eventLayout.onThisDayPage.root.setOnClickListener {
callback?.onSelectPage(card,
HistoryEntry(page.getPageTitle(card.wikiSite()), HistoryEntry.SOURCE_ON_THIS_DAY_CARD),
TransitionUtil.getSharedElements(context, binding.eventLayout.onThisDayPage.image)
)
}
binding.eventLayout.onThisDayPage.root.setOnLongClickListener { view ->
if (ImageZoomHelper.isZooming) {
ImageZoomHelper.dispatchCancelEvent(binding.eventLayout.onThisDayPage.root)
} else {
binding.eventLayout.onThisDayPage.imageContainer.visibility = VISIBLE
binding.eventLayout.onThisDayPage.image.loadImage(Uri.parse(page.thumbnailUrl))
ImageZoomHelper.setViewZoomable(binding.eventLayout.onThisDayPage.image)
}
binding.eventLayout.onThisDayPage.description.text = page.description
binding.eventLayout.onThisDayPage.description.visibility =
if (page.description.isNullOrEmpty()) GONE else VISIBLE
binding.eventLayout.onThisDayPage.title.maxLines =
if (page.description.isNullOrEmpty()) 2 else 1
binding.eventLayout.onThisDayPage.title.text = StringUtil.fromHtml(page.displayTitle)
binding.eventLayout.onThisDayPage.root.setOnClickListener {
callback?.onSelectPage(card,
HistoryEntry(page.getPageTitle(card.wikiSite()), HistoryEntry.SOURCE_ON_THIS_DAY_CARD),
TransitionUtil.getSharedElements(context, binding.eventLayout.onThisDayPage.image)
)
}
binding.eventLayout.onThisDayPage.root.setOnLongClickListener { view ->
if (ImageZoomHelper.isZooming) {
ImageZoomHelper.dispatchCancelEvent(binding.eventLayout.onThisDayPage.root)
} else {
val pageTitle = page.getPageTitle(card.wikiSite())
val entry = HistoryEntry(pageTitle, HistoryEntry.SOURCE_ON_THIS_DAY_CARD)
LongPressMenu(view, callback = object : LongPressMenu.Callback {
override fun onOpenLink(entry: HistoryEntry) {
callback?.onSelectPage(
card,
entry,
TransitionUtil.getSharedElements(
context,
binding.eventLayout.onThisDayPage.image
)
val pageTitle = page.getPageTitle(card.wikiSite())
val entry = HistoryEntry(pageTitle, HistoryEntry.SOURCE_ON_THIS_DAY_CARD)
LongPressMenu(view, callback = object : LongPressMenu.Callback {
override fun onOpenLink(entry: HistoryEntry) {
callback?.onSelectPage(
card,
entry,
TransitionUtil.getSharedElements(
context,
binding.eventLayout.onThisDayPage.image
)
}
)
}

override fun onOpenInNewTab(entry: HistoryEntry) {
callback?.onSelectPage(card, entry, true)
}
override fun onOpenInNewTab(entry: HistoryEntry) {
callback?.onSelectPage(card, entry, true)
}

override fun onAddRequest(entry: HistoryEntry, addToDefault: Boolean) {
ReadingListBehaviorsUtil.addToDefaultList(context as Activity, entry.title, addToDefault, InvokeSource.ON_THIS_DAY_CARD_BODY)
}
override fun onAddRequest(entry: HistoryEntry, addToDefault: Boolean) {
ReadingListBehaviorsUtil.addToDefaultList(context as Activity, entry.title, addToDefault, InvokeSource.ON_THIS_DAY_CARD_BODY)
}

override fun onMoveRequest(page: ReadingListPage?, entry: HistoryEntry) {
page?.let {
ReadingListBehaviorsUtil.moveToList(context as Activity, page.listId, entry.title, InvokeSource.ON_THIS_DAY_CARD_BODY)
}
override fun onMoveRequest(page: ReadingListPage?, entry: HistoryEntry) {
page?.let {
ReadingListBehaviorsUtil.moveToList(context as Activity, page.listId, entry.title, InvokeSource.ON_THIS_DAY_CARD_BODY)
}
}).show(entry)
}
true
}
}).show(entry)
}
true
}
} ?: run {
binding.eventLayout.onThisDayPage.root.visibility = GONE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ class OnThisDayFragment : Fragment(), CustomDatePicker.Callback {
}

private fun setPagesViewPager(event: OnThisDay.Event) {
event.pages()?.let {
otdEventLayout.pagesPager.adapter = ViewPagerAdapter(it, wiki)
otdEventLayout.pagesPager.offscreenPageLimit = 2
TabLayoutMediator(otdEventLayout.pagesIndicator, otdEventLayout.pagesPager) { _, _ -> }.attach()
otdEventLayout.pagesPager.visibility = View.VISIBLE
otdEventLayout.pagesIndicator.visibility = if (it.size == 1) View.GONE else View.VISIBLE
} ?: run {
if (event.pages.isEmpty()) {
otdEventLayout.pagesPager.visibility = View.GONE
otdEventLayout.pagesIndicator.visibility = View.GONE
return
}
otdEventLayout.pagesPager.adapter = ViewPagerAdapter(event.pages, wiki)
otdEventLayout.pagesPager.offscreenPageLimit = 2
TabLayoutMediator(otdEventLayout.pagesIndicator, otdEventLayout.pagesPager) { _, _ -> }.attach()
otdEventLayout.pagesPager.visibility = View.VISIBLE
otdEventLayout.pagesIndicator.visibility = if (event.pages.size == 1) View.GONE else View.VISIBLE
}

fun animateRadioButton() {
Expand Down

0 comments on commit 9c0b2ed

Please sign in to comment.