Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 282 additions & 32 deletions app/src/main/java/app/opendocument/droid/nonfree/AdManager.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class BillingManager {

if (hasPurchased()) {
adManager.removeAds()

// no banner to gate, but withdrawal has to survive the purchase, and only an
// update tells us whether the sdk wants a way back out
adManager.updateConsentInfo()
} else {
adManager.showGoogleAds()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ class MainActivity : AppCompatActivity(), MenuProvider {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)

adManager.showGoogleAds()
// the banner's size follows the orientation; the consent flow behind it does not
adManager.refreshAds()
}

fun requestSave() {
Expand Down Expand Up @@ -377,6 +378,9 @@ class MainActivity : AppCompatActivity(), MenuProvider {
adManager = AdManager()
adManager.setEnabled(!IS_TESTING && useProprietaryLibraries)
adManager.setAdContainer(adContainer)
// the menu is built long before the consent update comes back
adManager.setConsentListener { invalidateMenu() }
adManager.setPurchaseListener { buyAdRemoval() }
adManager.initialize(this, analyticsManager, crashManager)

billingManager = BillingManager()
Expand Down Expand Up @@ -406,6 +410,8 @@ class MainActivity : AppCompatActivity(), MenuProvider {
if (billingManager.hasPurchased()) {
menu.findItem(R.id.menu_remove_ads).isVisible = false
}

menu.findItem(R.id.menu_privacy_options).isVisible = adManager.isPrivacyOptionsRequired()
Comment thread
andiwand marked this conversation as resolved.
}

// The play services availability dialog calls startActivityForResult() itself with a
Expand Down Expand Up @@ -522,6 +528,12 @@ class MainActivity : AppCompatActivity(), MenuProvider {
buyAdRemoval()
}

R.id.menu_privacy_options -> {
analyticsManager.report("menu_privacy_options")

adManager.showPrivacyOptions()
}

R.id.menu_fullscreen -> {
if (fullscreen) {
analyticsManager.report("menu_fullscreen_leave")
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/house_ad_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- White, with the bottom edge the banner would have brought - without that line the
strip reads as a stray line of text on the page. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>

<item
android:gravity="bottom"
android:height="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/house_ad_divider" />
</shape>
</item>
</layer-list>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/house_ad_pill.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/house_ad_pill" />
<corners android:radius="99dp" />
</shape>
72 changes: 72 additions & 0 deletions app/src/main/res/layout/house_ad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- Stands in for a banner that did not fill, in the slot it would have had. AdManager
sizes it and drops parts as the slot narrows - see showHouseAd. The white is the point
rather than overdraw: the page behind it is grey. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/house_ad_background"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
tools:ignore="Overdraw">

<ImageView
android:id="@+id/house_ad_icon"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginEnd="10dp"
android:contentDescription="@string/app_title"
android:src="@mipmap/ic_launcher" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:orientation="vertical">

<!-- both truncate rather than wrap, so a long translation cannot break the height -->
<TextView
android:id="@+id/house_ad_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:attr/textColorPrimary"
android:textSize="13sp"
android:textStyle="bold"
tools:text="@string/house_ad_support_headline" />

<TextView
android:id="@+id/house_ad_subline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/house_ad_subline"
android:textSize="11sp"
tools:text="@string/house_ad_support_subline" />
</LinearLayout>

<TextView
android:id="@+id/house_ad_cta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/house_ad_pill"
android:paddingStart="10dp"
android:paddingTop="5dp"
android:paddingEnd="10dp"
android:paddingBottom="5dp"
android:textColor="@android:color/white"
android:textSize="11sp"
android:textStyle="bold"
tools:text="@string/house_ad_cta_go_pro" />
</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@
android:id="@+id/menu_remove_ads"
android:title="@string/menu_remove_ads"
app:showAsAction="never" />

<!-- shown only where the ump sdk asks for a re-entry point into the consent form -->
<item
android:id="@+id/menu_privacy_options"
android:title="@string/menu_privacy_options"
android:visible="false"
app:showAsAction="never" />
</menu>
10 changes: 10 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- the house ad does not take its greys from MainTheme: textColorSecondary is too
light to read at 11sp -->
<color name="house_ad_subline">#6b7280</color>
<color name="house_ad_pill">#2f80c8</color>
<color name="house_ad_divider">#e3e6ea</color>

</resources>
17 changes: 17 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
<string name="menu_share">Share document</string>
<string name="menu_edit">Edit document</string>
<string name="menu_remove_ads">Remove advertisements</string>
<string name="menu_privacy_options">Ad privacy settings</string>

<!-- the house ad, shown when a request does not fill. three angles at the same offer;
the short headlines are what a narrow phone gets once the rest drops out -->
<string name="house_ad_support_headline">Support OpenDocument Reader</string>
<string name="house_ad_support_headline_short">Support us</string>
<string name="house_ad_support_subline">Get Pro — no ads, ever</string>
<string name="house_ad_support_subline_wide">It is open source and ad-supported. Pro drops the advertisement.</string>
<string name="house_ad_ad_free_headline">Read without ads</string>
<string name="house_ad_ad_free_subline">ODR Pro — a one-time purchase</string>
<string name="house_ad_ad_free_subline_wide">ODR Pro is the same reader, minus the advertisement.</string>
<string name="house_ad_open_source_headline">Open source, kept free</string>
<string name="house_ad_open_source_headline_short">Open source</string>
<string name="house_ad_open_source_subline">Pro pays for it — and drops the ads</string>
<string name="house_ad_open_source_subline_wide">Buying Pro funds the work and removes the advertisement.</string>
<string name="house_ad_cta_go_pro">Go Pro</string>
<string name="house_ad_cta_get_pro">Get Pro</string>
<string name="menu_fullscreen">Fullscreen mode</string>
<string name="menu_cloud_print">Print document</string>
<string name="menu_tts">Text-To-Speech</string>
Expand Down