Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ogzkesk committed Jul 6, 2023
1 parent 9296c98 commit fffb3f8
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 53 deletions.
11 changes: 0 additions & 11 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions app/src/main/java/com/ogzkesk/ad/ui/screens/home/Native.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fun Native() {
onLoadNativeTemplatesClick = {
viewModel.loadNativeSmallTemplate(context)
viewModel.loadNativeMediumTemplate(context)
viewModel.loadNativeMedium2Template(context)
viewModel.loadNativeLargeTemplate(context)
}
)
Expand All @@ -68,6 +69,13 @@ fun Native() {
)
}
item { Spacer(modifier = Modifier.height(16.dp)) }
item {
EonNativeAdView(
nativeAdView = uiState.medium2NativeView,
darkModeSupport = true
)
}
item { Spacer(modifier = Modifier.height(16.dp)) }
item {
EonNativeAdView(
nativeAdView = uiState.largeNativeView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ class NativeViewModel @Inject constructor() : ViewModel() {
)
}

fun loadNativeMedium2Template(context: Context) {
EonAd.getInstance().loadNativeAdTemplate(
context = context,
adUnitId = BuildConfig.ad_native_id,
type = NativeAdTemplate.MEDIUM_2,
onFailedToLoad = {},
onNativeAdLoaded = { view ->
println("EonNativeAd -- ViewModel Medium Loaded :: $view")
_uiState.value = _uiState.value.copy(medium2NativeView = view)
},
)
}

fun loadNativeLargeTemplate(context: Context) {
EonAd.getInstance().loadNativeAdTemplate(
context = context,
Expand Down Expand Up @@ -83,6 +96,7 @@ class NativeViewModel @Inject constructor() : ViewModel() {
data class UiState(
val smallNativeView: View? = null,
val mediumNativeView: View? = null,
val medium2NativeView: View? = null,
val largeNativeView: View? = null,
val error: EonAdError? = null
)
Expand Down
2 changes: 1 addition & 1 deletion eonad/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.ogzkesk'
artifactId = 'eonad'
version = '1.0.3'
version = '1.0.4'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions eonad/src/main/java/com/ogzkesk/eonad/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ internal fun mapBannerAdSize(adSize : BannerAdSize) : AdSize {
enum class NativeAdTemplate {
SMALL,
MEDIUM,
MEDIUM_2,
LARGE
}
8 changes: 2 additions & 6 deletions eonad/src/main/java/com/ogzkesk/eonad/ui/EonNativeAdView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ fun EonNativeAdView(
modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.border(0.6.dp, Color(0xFF9C9C9C), RoundedCornerShape(8.dp))
.windowInsetsPadding(WindowInsets.navigationBars)
.windowInsetsPadding(WindowInsets.statusBars),
.border(0.6.dp, Color(0xFF9C9C9C), RoundedCornerShape(8.dp)),
factory = { nativeAdView },
update = {
try {
Expand All @@ -50,9 +48,7 @@ fun EonNativeAdView(
modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.border(0.6.dp, Color(0xFF9C9C9C), RoundedCornerShape(8.dp))
.windowInsetsPadding(WindowInsets.navigationBars)
.windowInsetsPadding(WindowInsets.statusBars),
.border(0.6.dp, Color(0xFF9C9C9C), RoundedCornerShape(8.dp)),
factory = { nativeAdView }
)
}
Expand Down
50 changes: 48 additions & 2 deletions eonad/src/main/java/com/ogzkesk/eonad/ui/NativeAdUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.widget.Button
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.facebook.shimmer.ShimmerFrameLayout
import com.google.android.gms.ads.nativead.NativeAd
Expand Down Expand Up @@ -72,19 +73,22 @@ internal class NativeAdUi(private val nativeAd: NativeAd?) {
val advertiser = adView.findViewById<TextView>(R.id.ad_advertiser)
val icon = adView.findViewById<ImageView>(R.id.ad_icon)
val callToAction = adView.findViewById<Button>(R.id.ad_call_to_action)
val body = adView.findViewById<TextView>(R.id.ad_body)
val adImage = adView.findViewById<FrameLayout>(R.id.ad_view_container)
.findViewById<ImageView>(R.id.ad_image)

headLine.text = nativeAd.headline
advertiser.text = nativeAd.advertiser
callToAction.text = nativeAd.callToAction
body.text = nativeAd.body
nativeAd.icon?.drawable?.let { draw -> icon.setImageDrawable(draw) }
if (nativeAd.images.isNotEmpty()) {
nativeAd.images[0].drawable?.let { adImage.setImageDrawable(it) }
}

headlineView = headLine
advertiserView = advertiser
bodyView = body
iconView = icon
callToActionView = callToAction
imageView = adImage
Expand All @@ -98,6 +102,47 @@ internal class NativeAdUi(private val nativeAd: NativeAd?) {
}
}

private fun populateMedium2NativeView(context: Context): View {

val loadingView = (context as Activity).layoutInflater.inflate(
R.layout.admob_native_medium_two,
null
) as FrameLayout

return if(nativeAd != null) {
NativeAdView(context).apply {
val adView = (context).layoutInflater.inflate(
R.layout.admob_native_medium_two,
null
) as FrameLayout

val headLine = adView.findViewById<TextView>(R.id.ad_headline)
val advertiser = adView.findViewById<TextView>(R.id.ad_advertiser)
val body = adView.findViewById<TextView>(R.id.ad_body)
val icon = adView.findViewById<ImageView>(R.id.ad_icon)
val callToAction = adView.findViewById<Button>(R.id.ad_call_to_action)

headLine.text = nativeAd.headline
advertiser.text = nativeAd.advertiser
callToAction.text = nativeAd.callToAction
body.text = nativeAd.body
nativeAd.icon?.drawable?.let { draw -> icon.setImageDrawable(draw) }

headlineView = headLine
advertiserView = advertiser
bodyView = body
iconView = icon
callToActionView = callToAction

removeAllViews()
setNativeAd(nativeAd)
addView(adView)
}
} else {
loadingView
}
}

private fun populateLargeNativeView(context: Context): View {
val loadingView = (context as Activity).layoutInflater.inflate(
R.layout.admob_native_large,
Expand Down Expand Up @@ -148,14 +193,15 @@ internal class NativeAdUi(private val nativeAd: NativeAd?) {
return when (type) {
NativeAdTemplate.SMALL -> populateSmallNativeView(context).apply { show(this) }
NativeAdTemplate.MEDIUM -> populateMediumNativeView(context).apply { show(this) }
NativeAdTemplate.MEDIUM_2 -> populateMedium2NativeView(context).apply { show(this) }
NativeAdTemplate.LARGE -> populateLargeNativeView(context).apply { show(this) }
}
}

private fun show(view: View) {
val shimmer = view.findViewById<ShimmerFrameLayout>(R.id.shimmer_view_container)
val adView = view.findViewById<FrameLayout>(R.id.ad_view_container)
shimmer.isVisible = nativeAd == null
adView.isVisible = nativeAd != null
shimmer.isGone = nativeAd != null
adView.isGone = nativeAd == null
}
}
2 changes: 2 additions & 0 deletions eonad/src/main/res/drawable/ad_img_bg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<corners android:radius="8dp"/>
<solid android:color="?android:attr/selectableItemBackground"/>

</shape>
22 changes: 13 additions & 9 deletions eonad/src/main/res/layout/admob_native_large.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@
android:textStyle="normal"
tools:text="Ad description..." />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/ad_image"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:strokeColor="@null"
android:layout_marginHorizontal="8dp"
app:shapeAppearance="@style/ShapeForLarge"
android:adjustViewBounds="true"
android:foreground="?android:attr/selectableItemBackground"
tools:src="@tools:sample/avatars" />
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ad_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:adjustViewBounds="true"
android:foreground="?android:attr/selectableItemBackground"
tools:src="@tools:sample/avatars" />

</FrameLayout>



<Button
Expand Down
29 changes: 15 additions & 14 deletions eonad/src/main/res/layout/admob_native_medium.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@

<TextView
android:id="@+id/ad_body"
android:textSize="12sp"
tools:text="Ad body....."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="4dp"
android:maxLines="3"
android:ellipsize="end"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:maxLines="3"
android:textSize="12sp"
tools:text="Ad body....." />

<FrameLayout
android:layout_width="match_parent"
Expand All @@ -122,15 +122,16 @@

</FrameLayout>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/ad_image"
android:layout_width="0dp"
android:layout_height="match_parent"
app:strokeColor="@null"
android:layout_weight="0.5"
android:scaleType="centerCrop"
app:shapeAppearance="@style/ShapeForMedium"
tools:src="@tools:sample/avatars" />

<ImageView
android:id="@+id/ad_image"
android:layout_width="0dp"
android:layout_height="180dp"
android:foreground="?android:attr/selectableItemBackground"
android:scaleType="centerCrop"
android:layout_weight="0.5"
tools:src="@tools:sample/avatars" />


</LinearLayout>

Expand Down
Loading

0 comments on commit fffb3f8

Please sign in to comment.