diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d70e3be5..83d0b25c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -73,17 +73,27 @@ android { else -> "FANBOX" } + // This ID must be valid or the app will crash. + // When building from GitHub, either exclude AdMob code or register with AdMob for an ID. + val admobTestAppId = "ca-app-pub-0000000000000000~0000000000" val bannerAdTestId = "ca-app-pub-3940256099942544/6300978111" val nativeAdTestId = "ca-app-pub-3940256099942544/2247696110" - it.resValues.put(it.makeResValueKey("string", "app_name"), ResValue(appName, null)) + it.manifestPlaceholders.apply { + putManifestPlaceholder(localProperties, "ADMOB_APP_ID", defaultValue = admobTestAppId) + } + + it.resValues.apply { + put(it.makeResValueKey("string", "app_name"), ResValue(appName, null)) + } + it.buildConfigFields.apply { putBuildConfig(localProperties, "VERSION_NAME", libs.versions.versionName.get().toStringLiteral()) putBuildConfig(localProperties, "VERSION_CODE", libs.versions.versionCode.get().toStringLiteral()) putBuildConfig(localProperties, "DEVELOPER_PASSWORD") putBuildConfig(localProperties, "PIXIV_CLIENT_ID") putBuildConfig(localProperties, "PIXIV_CLIENT_SECRET") - putBuildConfig(localProperties, "ADMOB_APP_ID") + putBuildConfig(localProperties, "ADMOB_APP_ID", defaultValue = admobTestAppId) putBuildConfig(localProperties, "ADMOB_BANNER_AD_UNIT_ID", if (it.buildType != "release") bannerAdTestId else null) putBuildConfig(localProperties, "ADMOB_NATIVE_AD_UNIT_ID", if (it.buildType != "release") nativeAdTestId else null) } @@ -145,13 +155,29 @@ fun MapProperty>.putBuildConfig( key: String, value: String? = null, type: String = "String", + defaultValue: String = "", comment: String? = null ) { - val defaultValue = value?.toStringLiteral() + val data = value?.toStringLiteral() + val property = localProperties.getProperty(key)?.toStringLiteral() + val env = System.getenv(key)?.toStringLiteral() + val defaultData = defaultValue.toStringLiteral() + + put(key, BuildConfigField(type, data ?: property ?: env ?: defaultData, comment)) +} + +fun MapProperty.putManifestPlaceholder( + localProperties: Properties, + key: String, + value: String? = null, + defaultValue: String = "", +) { + val data = value?.toStringLiteral() val property = localProperties.getProperty(key)?.toStringLiteral() - val env = System.getenv(key).orEmpty().toStringLiteral() + val env = System.getenv(key)?.toStringLiteral() + val defaultData = defaultValue.toStringLiteral() - put(key, BuildConfigField(type, defaultValue ?: property ?: env, comment)) + put(key, data ?: property ?: env ?: defaultData) } fun Any.toStringLiteral(): String { diff --git a/core/ui/src/main/java/caios/android/fanbox/core/ui/ads/template/NativeAdsTemplateStyle.java b/core/ui/src/main/java/caios/android/fanbox/core/ui/ads/template/NativeAdsTemplateStyle.java deleted file mode 100644 index 76bf5081..00000000 --- a/core/ui/src/main/java/caios/android/fanbox/core/ui/ads/template/NativeAdsTemplateStyle.java +++ /dev/null @@ -1,272 +0,0 @@ -package caios.android.fanbox.core.ui.ads.template; - -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import android.graphics.Typeface; -import android.graphics.drawable.ColorDrawable; -import androidx.annotation.Nullable; -import com.google.errorprone.annotations.CanIgnoreReturnValue; - -/** A class containing the optional styling options for the Native Template. */ -public class NativeAdsTemplateStyle { - - // Call to action typeface. - private Typeface callToActionTextTypeface; - - // Size of call to action text. - private float callToActionTextSize; - - // Call to action typeface color in the form 0xAARRGGBB. - @Nullable private Integer callToActionTypefaceColor; - - // Call to action background color. - private ColorDrawable callToActionBackgroundColor; - - // All templates have a primary text area which is populated by the native ad's headline. - - // Primary text typeface. - private Typeface primaryTextTypeface; - - // Size of primary text. - private float primaryTextSize; - - // Primary text typeface color in the form 0xAARRGGBB. - @Nullable private Integer primaryTextTypefaceColor; - - // Primary text background color. - private ColorDrawable primaryTextBackgroundColor; - - // The typeface, typeface color, and background color for the second row of text in the template. - // All templates have a secondary text area which is populated either by the body of the ad or - // by the rating of the app. - - // Secondary text typeface. - private Typeface secondaryTextTypeface; - - // Size of secondary text. - private float secondaryTextSize; - - // Secondary text typeface color in the form 0xAARRGGBB. - @Nullable private Integer secondaryTextTypefaceColor; - - // Secondary text background color. - private ColorDrawable secondaryTextBackgroundColor; - - // The typeface, typeface color, and background color for the third row of text in the template. - // The third row is used to display store name or the default tertiary text. - - // Tertiary text typeface. - private Typeface tertiaryTextTypeface; - - // Size of tertiary text. - private float tertiaryTextSize; - - // Tertiary text typeface color in the form 0xAARRGGBB. - @Nullable private Integer tertiaryTextTypefaceColor; - - // Tertiary text background color. - private ColorDrawable tertiaryTextBackgroundColor; - - // The background color for the bulk of the ad. - private ColorDrawable mainBackgroundColor; - - public Typeface getCallToActionTextTypeface() { - return callToActionTextTypeface; - } - - public float getCallToActionTextSize() { - return callToActionTextSize; - } - - @Nullable - public Integer getCallToActionTypefaceColor() { - return callToActionTypefaceColor; - } - - public ColorDrawable getCallToActionBackgroundColor() { - return callToActionBackgroundColor; - } - - public Typeface getPrimaryTextTypeface() { - return primaryTextTypeface; - } - - public float getPrimaryTextSize() { - return primaryTextSize; - } - - @Nullable - public Integer getPrimaryTextTypefaceColor() { - return primaryTextTypefaceColor; - } - - public ColorDrawable getPrimaryTextBackgroundColor() { - return primaryTextBackgroundColor; - } - - public Typeface getSecondaryTextTypeface() { - return secondaryTextTypeface; - } - - public float getSecondaryTextSize() { - return secondaryTextSize; - } - - @Nullable - public Integer getSecondaryTextTypefaceColor() { - return secondaryTextTypefaceColor; - } - - public ColorDrawable getSecondaryTextBackgroundColor() { - return secondaryTextBackgroundColor; - } - - public Typeface getTertiaryTextTypeface() { - return tertiaryTextTypeface; - } - - public float getTertiaryTextSize() { - return tertiaryTextSize; - } - - @Nullable - public Integer getTertiaryTextTypefaceColor() { - return tertiaryTextTypefaceColor; - } - - public ColorDrawable getTertiaryTextBackgroundColor() { - return tertiaryTextBackgroundColor; - } - - public ColorDrawable getMainBackgroundColor() { - return mainBackgroundColor; - } - - /** A class that provides helper methods to build a style object. */ - public static class Builder { - - private NativeAdsTemplateStyle styles; - - public Builder() { - this.styles = new NativeAdsTemplateStyle(); - } - - @CanIgnoreReturnValue - public Builder withCallToActionTextTypeface(Typeface callToActionTextTypeface) { - this.styles.callToActionTextTypeface = callToActionTextTypeface; - return this; - } - - @CanIgnoreReturnValue - public Builder withCallToActionTextSize(float callToActionTextSize) { - this.styles.callToActionTextSize = callToActionTextSize; - return this; - } - - @CanIgnoreReturnValue - public Builder withCallToActionTypefaceColor(int callToActionTypefaceColor) { - this.styles.callToActionTypefaceColor = callToActionTypefaceColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withCallToActionBackgroundColor(ColorDrawable callToActionBackgroundColor) { - this.styles.callToActionBackgroundColor = callToActionBackgroundColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withPrimaryTextTypeface(Typeface primaryTextTypeface) { - this.styles.primaryTextTypeface = primaryTextTypeface; - return this; - } - - @CanIgnoreReturnValue - public Builder withPrimaryTextSize(float primaryTextSize) { - this.styles.primaryTextSize = primaryTextSize; - return this; - } - - @CanIgnoreReturnValue - public Builder withPrimaryTextTypefaceColor(int primaryTextTypefaceColor) { - this.styles.primaryTextTypefaceColor = primaryTextTypefaceColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withPrimaryTextBackgroundColor(ColorDrawable primaryTextBackgroundColor) { - this.styles.primaryTextBackgroundColor = primaryTextBackgroundColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withSecondaryTextTypeface(Typeface secondaryTextTypeface) { - this.styles.secondaryTextTypeface = secondaryTextTypeface; - return this; - } - - @CanIgnoreReturnValue - public Builder withSecondaryTextSize(float secondaryTextSize) { - this.styles.secondaryTextSize = secondaryTextSize; - return this; - } - - @CanIgnoreReturnValue - public Builder withSecondaryTextTypefaceColor(int secondaryTextTypefaceColor) { - this.styles.secondaryTextTypefaceColor = secondaryTextTypefaceColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withSecondaryTextBackgroundColor(ColorDrawable secondaryTextBackgroundColor) { - this.styles.secondaryTextBackgroundColor = secondaryTextBackgroundColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withTertiaryTextTypeface(Typeface tertiaryTextTypeface) { - this.styles.tertiaryTextTypeface = tertiaryTextTypeface; - return this; - } - - @CanIgnoreReturnValue - public Builder withTertiaryTextSize(float tertiaryTextSize) { - this.styles.tertiaryTextSize = tertiaryTextSize; - return this; - } - - @CanIgnoreReturnValue - public Builder withTertiaryTextTypefaceColor(int tertiaryTextTypefaceColor) { - this.styles.tertiaryTextTypefaceColor = tertiaryTextTypefaceColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withTertiaryTextBackgroundColor(ColorDrawable tertiaryTextBackgroundColor) { - this.styles.tertiaryTextBackgroundColor = tertiaryTextBackgroundColor; - return this; - } - - @CanIgnoreReturnValue - public Builder withMainBackgroundColor(ColorDrawable mainBackgroundColor) { - this.styles.mainBackgroundColor = mainBackgroundColor; - return this; - } - - public NativeAdsTemplateStyle build() { - return styles; - } - } -} diff --git a/feature/creator/src/main/java/caios/android/fanbox/feature/creator/top/CreatorTopViewModel.kt b/feature/creator/src/main/java/caios/android/fanbox/feature/creator/top/CreatorTopViewModel.kt index 541ee98d..7c4f65d9 100644 --- a/feature/creator/src/main/java/caios/android/fanbox/feature/creator/top/CreatorTopViewModel.kt +++ b/feature/creator/src/main/java/caios/android/fanbox/feature/creator/top/CreatorTopViewModel.kt @@ -56,6 +56,10 @@ class CreatorTopViewModel @Inject constructor( _screenState.value = screenState.value.changeContent { it.copy(bookmarkedPosts = data) } } } + + viewModelScope.launch { + nativeAdsPreLoader.preloadAd() + } } fun fetch(creatorId: CreatorId) { diff --git a/feature/library/src/main/java/caios/android/fanbox/feature/library/home/LibraryHomeViewModel.kt b/feature/library/src/main/java/caios/android/fanbox/feature/library/home/LibraryHomeViewModel.kt index f1048ef1..7546c176 100644 --- a/feature/library/src/main/java/caios/android/fanbox/feature/library/home/LibraryHomeViewModel.kt +++ b/feature/library/src/main/java/caios/android/fanbox/feature/library/home/LibraryHomeViewModel.kt @@ -35,7 +35,7 @@ class LibraryHomeViewModel @Inject constructor( bookmarkedPosts = emptyList(), homePaging = emptyPaging(), supportedPaging = emptyPaging(), - nativeAdUnitId = "", + nativeAdUnitId = pixiViewConfig.adMobNativeAdUnitId, ), )