Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Test new billing logic (#86)
Browse files Browse the repository at this point in the history
* Add lint

* Add new libs

* Update libs and add friends tab

* Aggressively hide nonrecent posts

* Update dependencies

* Add php to most recents

* Add full size image downloader

* Fix css cleaner

* Fix notification and circle

* Bring back regex

* Update kau, optimize imports, and remove string ambiguity

* Bring back anjlab iab and move to alpha

* Create initial billing test
  • Loading branch information
AllanWang authored Jul 23, 2017
1 parent 37a9f90 commit 1388240
Show file tree
Hide file tree
Showing 35 changed files with 239 additions and 1,932 deletions.
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: 'com.github.triplet.play'

play {
jsonFile = file('../files/gplay-keys.json')
track = 'beta'
track = 'alpha'
errorOnSizeLimit = true
uploadImages = false
untrackOld = true
Expand Down Expand Up @@ -130,11 +130,10 @@ dependencies {

compile "ca.allanwang.kau:about:$KAU"
compile "ca.allanwang.kau:colorpicker:$KAU"
// compile "ca.allanwang.kau:imagepicker:$KAU"
compile "ca.allanwang.kau:imagepicker:$KAU"
compile "ca.allanwang.kau:kpref-activity:$KAU"
compile "ca.allanwang.kau:searchview:$KAU"

compile "org.jetbrains.kotlin:kotlin-stdlib:${KOTLIN}"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:${KOTLIN}"

debugCompile "com.squareup.leakcanary:leakcanary-android:${LEAK_CANARY}"
Expand All @@ -155,8 +154,7 @@ dependencies {

compile "com.squareup.okhttp3:okhttp:${OKHTTP}"

compile "com.github.bumptech.glide:glide:${GLIDE}"
kapt "com.github.bumptech.glide:compiler:${GLIDE}"
compile "com.anjlab.android.iab.v3:library:${IAB}"

// compile("com.mikepenz:materialdrawer:${MATERIAL_DRAWER}@aar") {
// transitive = true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
android:theme="@style/FrostTheme.Settings" />
<activity
android:name=".activities.AboutActivity"
android:theme="@style/Kau.Translucent.About" />
android:theme="@style/Kau.About" />
<activity
android:name=".activities.ImageActivity"
android:theme="@style/FrostTheme.Overlay.Fade" />
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import android.app.Application
import android.graphics.drawable.Drawable
import android.net.Uri
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ApplicationVersionSignature
import com.crashlytics.android.Crashlytics
import com.crashlytics.android.answers.Answers
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.CrashReportingTree
import com.pitchedapps.frost.utils.GlideApp
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.Showcase
import com.raizlabs.android.dbflow.config.FlowConfig
Expand Down Expand Up @@ -65,8 +64,8 @@ class FrostApp : Application() {
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String) {
val c = imageView.context
val old = GlideApp.with(c).load(uri).apply(RequestOptions().placeholder(placeholder))
GlideApp.with(c).load(uri).apply(RequestOptions().signature(ApplicationVersionSignature.obtain(c)))
val old = Glide.with(c).load(uri).apply(RequestOptions().placeholder(placeholder))
Glide.with(c).load(uri).apply(RequestOptions().signature(ApplicationVersionSignature.obtain(c)))
.thumbnail(old).into(imageView)
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pitchedapps.frost.activities

import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Bitmap
Expand All @@ -21,6 +19,7 @@ import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE
import ca.allanwang.kau.permissions.kauOnRequestPermissionsResult
import ca.allanwang.kau.permissions.kauRequestPermissions
import ca.allanwang.kau.utils.*
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.BaseTarget
import com.bumptech.glide.request.target.SizeReadyCallback
import com.bumptech.glide.request.target.Target
Expand All @@ -31,7 +30,10 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.ARG_IMAGE_URL
import com.pitchedapps.frost.utils.ARG_TEXT
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.sothree.slidinguppanel.SlidingUpPanelLayout
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
Expand Down Expand Up @@ -82,7 +84,8 @@ class ImageActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(if (!text.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless)
val layout = if (!text.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless
setContentView(layout)
container.setBackgroundColor(Prefs.bgColor.withMinAlpha(222))
caption?.setTextColor(Prefs.textColor)
caption?.setBackgroundColor(Prefs.bgColor.colorToForeground(0.2f).withAlpha(255))
Expand All @@ -104,7 +107,7 @@ class ImageActivity : AppCompatActivity() {
imageCallback(null, false)
}
})
GlideApp.with(this).asBitmap().load(imageUrl).into(PhotoTarget(this::imageCallback))
Glide.with(this).asBitmap().load(imageUrl).into(PhotoTarget(this::imageCallback))
}

/**
Expand Down Expand Up @@ -196,7 +199,8 @@ class ImageActivity : AppCompatActivity() {
} finally {
L.d("Download image async finished: $success")
uiThread {
snackbar(if (success) R.string.image_download_success else R.string.image_download_fail)
val text = if (success) R.string.image_download_success else R.string.image_download_fail
snackbar(text)
if (success) {
deleteTempFile()
fabAction = FabStates.SHARE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.support.annotation.StringRes
import android.support.design.widget.*
import android.support.design.widget.AppBarLayout
import android.support.design.widget.CoordinatorLayout
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.TabLayout
import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
Expand Down Expand Up @@ -52,7 +55,8 @@ import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.iab.validatePro
import com.pitchedapps.frost.utils.iab.FrostBilling
import com.pitchedapps.frost.utils.iab.IABMain
import com.pitchedapps.frost.views.BadgedIcon
import com.pitchedapps.frost.views.FrostViewPager
import com.pitchedapps.frost.web.SearchWebView
Expand All @@ -64,7 +68,8 @@ import org.jsoup.Jsoup
import java.util.concurrent.TimeUnit

class MainActivity : BaseActivity(), SearchWebView.SearchContract,
ActivityWebContract, FileChooserContract by FileChooserDelegate() {
ActivityWebContract, FileChooserContract by FileChooserDelegate(),
FrostBilling by IABMain() {

lateinit var adapter: SectionsPagerAdapter
val toolbar: Toolbar by bindView(R.id.toolbar)
Expand Down Expand Up @@ -97,12 +102,12 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
* Possible responses from the SettingsActivity
* after the configurations have changed
*/
const val REQUEST_RESTART = 90909
const val REQUEST_REFRESH = 80808
const val REQUEST_WEB_ZOOM = 50505
const val REQUEST_NAV = 10101
const val REQUEST_SEARCH = 70707
const val REQUEST_RESTART_APPLICATION = 60606
const val REQUEST_RESTART_APPLICATION = 1 shl 1
const val REQUEST_RESTART = 1 shl 2
const val REQUEST_REFRESH = 1 shl 3
const val REQUEST_WEB_ZOOM = 1 shl 4
const val REQUEST_NAV = 1 shl 5
const val REQUEST_SEARCH = 1 shl 6
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -149,12 +154,12 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
viewPager.post { webFragmentObservable.onNext(0); lastPosition = 0 } //trigger hook so title is set
setupDrawer(savedInstanceState)
setupTabs()
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
// fab.setOnClickListener { view ->
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show()
// }
setFrostColors(toolbar, themeWindow = false, headers = arrayOf(tabs, appBar), backgrounds = arrayOf(viewPager))
validatePro()
onCreateBilling()
}

fun tabsForEachView(action: (position: Int, view: BadgedIcon) -> Unit) {
Expand Down Expand Up @@ -394,26 +399,28 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
if (onActivityResultWeb(requestCode, resultCode, data)) return
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ACTIVITY_SETTINGS) {
when (resultCode) {
REQUEST_RESTART -> restart()
REQUEST_REFRESH -> webFragmentObservable.onNext(WebFragment.REQUEST_REFRESH)
REQUEST_NAV -> frostNavigationBar()
REQUEST_WEB_ZOOM -> webFragmentObservable.onNext(WebFragment.REQUEST_TEXT_ZOOM)
REQUEST_SEARCH -> invalidateOptionsMenu()
REQUEST_RESTART_APPLICATION -> { //completely restart application
L.d("Restart Application Requested")
val intent = packageManager.getLaunchIntentForPackage(packageName)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
val pending = PendingIntent.getActivity(this, 666, intent, PendingIntent.FLAG_CANCEL_CURRENT)
val alarm = getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
alarm.setExactAndAllowWhileIdle(AlarmManager.RTC, System.currentTimeMillis() + 100, pending)
else
alarm.setExact(AlarmManager.RTC, System.currentTimeMillis() + 100, pending)
finish()
System.exit(0)
}
if (resultCode and REQUEST_RESTART_APPLICATION > 0) { //completely restart application
L.d("Restart Application Requested")
val intent = packageManager.getLaunchIntentForPackage(packageName)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
val pending = PendingIntent.getActivity(this, 666, intent, PendingIntent.FLAG_CANCEL_CURRENT)
val alarm = getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
alarm.setExactAndAllowWhileIdle(AlarmManager.RTC, System.currentTimeMillis() + 100, pending)
else
alarm.setExact(AlarmManager.RTC, System.currentTimeMillis() + 100, pending)
finish()
System.exit(0)
return
}
if (resultCode and REQUEST_RESTART > 0) return restart()
/*
* These results can be stacked
*/
if (resultCode and REQUEST_REFRESH > 0) webFragmentObservable.onNext(WebFragment.REQUEST_REFRESH)
if (resultCode and REQUEST_NAV > 0) frostNavigationBar()
if (resultCode and REQUEST_WEB_ZOOM > 0) webFragmentObservable.onNext(WebFragment.REQUEST_TEXT_ZOOM)
if (resultCode and REQUEST_SEARCH > 0) invalidateOptionsMenu()
}
}

Expand All @@ -435,6 +442,11 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
super.onStart()
}

override fun onDestroy() {
onDestroyBilling()
super.onDestroy()
}

override fun onBackPressed() {
if (searchView?.onBackPressed() ?: false) return
if (currentFragment.onBackPressed()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@ import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.settings.*
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.iab.*
import com.pitchedapps.frost.utils.iab.FrostBilling
import com.pitchedapps.frost.utils.iab.IABSettings
import com.pitchedapps.frost.utils.iab.IS_FROST_PRO


/**
* Created by Allan Wang on 2017-06-06.
*/
class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListener {
class SettingsActivity : KPrefActivity(), FrostBilling by IABSettings() {

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (!IAB.handleActivityResult(requestCode, resultCode, data)) {
if (!onActivityResultBilling(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data)
adapter.notifyDataSetChanged()
}
}


override fun receivedBroadcast() {
L.d("IAB broadcast")
adapter.notifyDataSetChanged()
}

override fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit = {
textColor = { Prefs.textColor }
accentColor = { Prefs.accentColor }
Expand Down Expand Up @@ -72,7 +68,7 @@ class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListe
plainText(R.string.restore_purchases) {
descRes = R.string.restore_purchases_desc
iicon = GoogleMaterial.Icon.gmd_refresh
onClick = { _, _, _ -> this@SettingsActivity.restorePurchases(); true }
onClick = { _, _, _ -> restorePurchases(false); true }
}

plainText(R.string.about_frost) {
Expand All @@ -86,7 +82,7 @@ class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListe
}

fun KPrefItemBase.BaseContract<*>.dependsOnPro() {
onDisabledClick = { _, _, _ -> openPlayProPurchase(0); true }
onDisabledClick = { _, _, _ -> purchasePro(); true }
enabler = { IS_FROST_PRO }
}

Expand All @@ -99,6 +95,7 @@ class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListe
super.onCreate(savedInstanceState)
animate = Prefs.animate
themeExterior(false)
onCreateBilling()
}

fun themeExterior(animate: Boolean = true) {
Expand Down Expand Up @@ -139,7 +136,7 @@ class SettingsActivity : KPrefActivity(), IabBroadcastReceiver.IabBroadcastListe
}

override fun onDestroy() {
IAB.dispose()
onDestroyBilling()
super.onDestroy()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.pitchedapps.frost.injectors

import android.webkit.WebView
import com.pitchedapps.frost.utils.L

/**
* Created by Allan Wang on 2017-05-31.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ import android.support.v4.app.NotificationManagerCompat
import ca.allanwang.kau.utils.color
import ca.allanwang.kau.utils.dpToPx
import ca.allanwang.kau.utils.string
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.activities.FrostWebActivity
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.FrostWebActivity
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.dbflow.fetchUsername
import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.ARG_USER_ID
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.withRoundIcon
import org.jetbrains.anko.runOnUiThread

/**
Expand Down Expand Up @@ -100,7 +104,7 @@ data class NotificationContent(val data: CookieModel,

if (profileUrl.isNotBlank()) {
context.runOnUiThread {
GlideApp.with(context)
Glide.with(context)
.asBitmap()
.load(profileUrl)
.withRoundIcon()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.frostAnswersCustom
import com.pitchedapps.frost.web.MessageWebView
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import java.util.concurrent.Future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import ca.allanwang.kau.kpref.activity.items.KPrefColorPicker
import ca.allanwang.kau.kpref.activity.items.KPrefSeekbar
import ca.allanwang.kau.ui.views.RippleCanvas
import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.activities.SettingsActivity
import com.pitchedapps.frost.injectors.CssAssets
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.iab.IS_FROST_PRO
import com.pitchedapps.frost.utils.iab.openPlayProPurchase
import com.pitchedapps.frost.views.KPrefTextSeekbar

/**
Expand All @@ -33,7 +32,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = {
_, _, which, text ->
if (item.pref != which) {
if (which == Theme.CUSTOM.ordinal && !IS_FROST_PRO) {
openPlayProPurchase(9)
purchasePro()
return@itemsCallbackSingleChoice true
}
item.pref = which
Expand Down
Loading

0 comments on commit 1388240

Please sign in to comment.