Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ class LandingFragment : Fragment(), LandingAdapter.Listener {
state.catchAllEnabled,
)
)

// asked here rather than carried in the state: what billing knows lives on the activity,
// not in anything the ViewModel reads. it is only ever false in pro or after a purchase,
// both of which are settled long before the first refresh comes back
if (mainActivity.offersAdRemoval()) {
items.add(
LandingItem.Action(
LandingItem.ACTION_REMOVE_ADS,
R.string.menu_remove_ads,
R.drawable.ic_block,
)
)
}
}

/** "2 hours ago", or nothing at all for entries written before this was recorded. */
Expand Down Expand Up @@ -417,6 +430,11 @@ class LandingFragment : Fragment(), LandingAdapter.Listener {
when (action) {
LandingItem.ACTION_ADD_FOLDER -> addFolder()
LandingItem.ACTION_UP -> viewModel.leaveFolder()
LandingItem.ACTION_REMOVE_ADS -> {
mainActivity.analyticsManager.report("settings_remove_ads")

mainActivity.buyAdRemoval()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@ class MainActivity : AppCompatActivity(), MenuProvider {

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.menu_main, menu)

if (billingManager.hasPurchased()) {
menu.findItem(R.id.menu_remove_ads).isVisible = false
}
}

// The play services availability dialog calls startActivityForResult() itself with a
Expand Down Expand Up @@ -470,12 +466,6 @@ class MainActivity : AppCompatActivity(), MenuProvider {
analyticsManager.report("menu_share")
}

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

buyAdRemoval()
}

R.id.menu_fullscreen -> {
if (fullscreen) {
analyticsManager.report("menu_fullscreen_leave")
Expand Down Expand Up @@ -572,7 +562,18 @@ class MainActivity : AppCompatActivity(), MenuProvider {
ttsActionMode = null
}

private fun buyAdRemoval() {
/**
* Whether the ad removal is still worth offering: never in pro, where the purchase is implied,
* and not once it has been bought.
*
* The landing screen asks rather than being told, because billing is set up by
* [initializeProprietaryLibraries] - which can run a second time, after the play services
* dialog - and it is not something the ViewModel could read off disk itself.
*/
fun offersAdRemoval(): Boolean =
::billingManager.isInitialized && !billingManager.hasPurchased()

fun buyAdRemoval() {
analyticsManager.report(AnalyticsConstants.EVENT_ADD_TO_CART)

// the play listing id is the applicationId, which stays at.tomtasche.reader.pro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ sealed class LandingItem {
companion object {
const val ACTION_ADD_FOLDER: Int = 1
const val ACTION_UP: Int = 2
const val ACTION_REMOVE_ADS: Int = 3

const val SETTING_CATCH_ALL: Int = 1
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_block.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z" />
</vector>
4 changes: 0 additions & 4 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,4 @@
android:visible="false"
app:showAsAction="never" />

<item
android:id="@+id/menu_remove_ads"
android:title="@string/menu_remove_ads"
app:showAsAction="never" />
</menu>
Loading