@@ -18,6 +18,7 @@ import androidx.browser.customtabs.CustomTabsClient
1818import androidx.browser.customtabs.CustomTabsIntent
1919import androidx.browser.customtabs.CustomTabsServiceConnection
2020import androidx.browser.customtabs.CustomTabsSession
21+ import androidx.compose.ui.platform.ComposeView
2122import androidx.constraintlayout.widget.ConstraintLayout
2223import androidx.core.content.ContextCompat.getColor
2324import androidx.core.content.ContextCompat.startActivity
@@ -53,6 +54,7 @@ import com.pennapps.labs.pennmobile.home.classes.CalendarCell
5354import com.pennapps.labs.pennmobile.home.classes.CalendarEvent
5455import com.pennapps.labs.pennmobile.home.classes.HomepageDataModel
5556import com.pennapps.labs.pennmobile.home.classes.NewsCell
57+ import com.pennapps.labs.pennmobile.home.classes.NewsComposableComponent
5658import com.pennapps.labs.pennmobile.home.classes.Poll
5759import com.pennapps.labs.pennmobile.home.classes.PollCell
5860import com.pennapps.labs.pennmobile.home.classes.Post
@@ -583,149 +585,10 @@ class HomeAdapter(
583585 ) {
584586 val article = cell.article
585587
586- if (article.imageUrl.isNullOrEmpty()) {
587- holder.itemView.visibility = View .GONE
588- holder.newsCardContainer.visibility = View .GONE
589- holder.homeNewsImageView.setImageDrawable(null )
590- holder.homeNewsTitle.text = " "
591- holder.homeNewsSubtitle.text = " "
592- holder.homeNewsTimestamp.text = " "
593- dataModel.notifyNewsBlurLoaded()
594- return
595- }
596-
597- holder.homeNewsTitle.text = article.title
598- holder.homeNewsSubtitle.text = article.subtitle
599-
600- holder.homeNewsTimestamp.text = article.timestamp?.trim()
601-
602- Glide
603- .with (mContext)
604- .load(article.imageUrl)
605- .fitCenter()
606- .centerCrop()
607- .into(holder.homeNewsImageView)
608-
609- // /** Adds dynamically generated accent color from the fetched image to the news card */
610- var accentColor: Int = getColor(mContext, R .color.black)
611- mActivity.lifecycleScope.launch(Dispatchers .Default ) {
612- Log .d(" HomeAdapter" , " Image Url is ${article.imageUrl} " )
613- val bitmap =
614- withContext(Dispatchers .IO ) {
615- Glide
616- .with (mContext)
617- .load(article.imageUrl)
618- .submit()
619- .get()
620- }.toBitmap()
621-
622- // Create palette from bitmap
623- fun createPaletteSync (bitmap : Bitmap ): Palette = Palette .from(bitmap).generate()
624- val vibrantSwatch: Palette .Swatch ? = createPaletteSync(bitmap).darkVibrantSwatch
625- vibrantSwatch?.rgb?.let { accentColor = it }
626-
627- mActivity.runOnUiThread {
628- // Change all the components to match the accent color palette
629- vibrantSwatch?.titleTextColor?.let {
630- DrawableCompat .setTint(
631- DrawableCompat .wrap(holder.newsCardLogo.drawable),
632- ColorUtils .setAlphaComponent(it, 150 ),
633- )
634- DrawableCompat .setTint(
635- DrawableCompat .wrap(holder.newsInfoIcon.drawable),
636- it,
637- )
638- DrawableCompat .setTint(
639- DrawableCompat .wrap(holder.dotDivider.drawable),
640- it,
641- )
642- holder.newsButton.setTextColor(ColorUtils .setAlphaComponent(it, 150 ))
643- DrawableCompat .setTint(
644- DrawableCompat .wrap(holder.newsButton.background),
645- it,
646- )
647- holder.homeNewsTitle.setTextColor(
648- ColorUtils .setAlphaComponent(
649- it,
650- 150 ,
651- ),
652- )
653- holder.homeNewsSubtitle.setTextColor(it)
654- holder.homeNewsTimestamp.setTextColor(it)
655- }
656- holder.newsCardContainer.background =
657- BitmapDrawable (
658- holder.itemBinding.root.resources,
659- bitmap,
660- )
661- holder.newsBlurView
662- .setOverlayColor(ColorUtils .setAlphaComponent(accentColor, 150 ))
663-
664- // tell model that the news blur view has been loaded
665- dataModel.notifyNewsBlurLoaded()
666- }
667- }
668-
669- // Logic for the more info button on the news card
670- holder.newsInfoIcon.setOnClickListener {
671- when (holder.homeNewsSubtitle.visibility) {
672- View .GONE -> {
673- holder.homeNewsSubtitle.visibility = View .VISIBLE
674- holder.homeNewsTitle.setPadding(0 , 0 , 0 , 0 )
675- holder.newsBlurView
676- .setOverlayColor(ColorUtils .setAlphaComponent(accentColor, 250 ))
677- }
678-
679- View .VISIBLE -> {
680- holder.homeNewsSubtitle.visibility = View .GONE
681- holder.homeNewsTitle.setPadding(0 , 0 , 0 , convertToDp(mContext, 8f ))
682- holder.newsBlurView
683- .setOverlayColor(ColorUtils .setAlphaComponent(accentColor, 150 ))
684- }
685- }
686- }
687-
688- // Sets up blur view on news card
689- holder.newsBlurView
690- .setupWith(holder.newsCardContainer, RenderScriptBlur (mContext))
691- .setFrameClearDrawable(ColorDrawable (getColor(mContext, R .color.white)))
692- .setBlurRadius(25f )
693-
694- holder.newsButton.setOnClickListener {
695- val url = article?.articleUrl
696-
697- val connection = NewsCustomTabsServiceConnection ()
698- builder = CustomTabsIntent .Builder ()
699- share = Intent (Intent .ACTION_SEND )
700- share?.type = " text/plain"
701- builder?.setToolbarColor(0x3E50B4 )
702- builder?.setStartAnimations(
703- mContext,
704- androidx.appcompat.R .anim.abc_popup_enter,
705- androidx.appcompat.R .anim.abc_popup_exit,
706- )
707- CustomTabsClient .bindCustomTabsService(
708- mContext,
709- NewsFragment .CUSTOM_TAB_PACKAGE_NAME ,
710- connection,
711- )
712-
713- if (mContext.isChromeCustomTabsSupported()) {
714- share?.putExtra(Intent .EXTRA_TEXT , url)
715- builder?.addMenuItem(
716- " Share" ,
717- PendingIntent .getActivity(
718- mContext,
719- 0 ,
720- share,
721- PendingIntent .FLAG_CANCEL_CURRENT or PendingIntent .FLAG_IMMUTABLE ,
722- ),
723- )
724- customTabsIntent = builder?.build()
725- customTabsIntent?.launchUrl(mActivity, Uri .parse(url))
726- } else {
727- val browserIntent = Intent (Intent .ACTION_VIEW , Uri .parse(url))
728- startActivity(mContext, browserIntent, null )
588+ val composeView = holder.itemView.findViewById<ComposeView >(R .id.news_compose_view)
589+ composeView.apply {
590+ setContent {
591+ NewsComposableComponent (article)
729592 }
730593 }
731594 }
0 commit comments