aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/BaseLeakActivity.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt15
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt12
-rw-r--r--app/src/main/res/layout/activity_login.xml10
-rw-r--r--app/src/main/res/values/strings.xml1
13 files changed, 72 insertions, 19 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/BaseLeakActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/BaseLeakActivity.kt
new file mode 100644
index 00000000..ab91f044
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/BaseLeakActivity.kt
@@ -0,0 +1,14 @@
+package com.pitchedapps.frost
+
+import android.support.v7.app.AppCompatActivity
+import com.pitchedapps.frost.utils.refWatch
+
+/**
+ * Created by Allan Wang on 2017-06-04.
+ */
+open class BaseLeakActivity : AppCompatActivity() {
+ override fun onDestroy() {
+ super.onDestroy()
+ refWatch()
+ }
+} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
index 52cb8c06..5527e434 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
@@ -9,7 +9,6 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.crashlytics.android.Crashlytics
import com.crashlytics.android.answers.Answers
-import com.crashlytics.android.core.CrashlyticsCore
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerUIUtils
@@ -18,6 +17,8 @@ import com.pitchedapps.frost.utils.CrashReportingTree
import com.pitchedapps.frost.utils.Prefs
import com.raizlabs.android.dbflow.config.FlowConfig
import com.raizlabs.android.dbflow.config.FlowManager
+import com.squareup.leakcanary.LeakCanary
+import com.squareup.leakcanary.RefWatcher
import io.fabric.sdk.android.Fabric
import timber.log.Timber
import timber.log.Timber.DebugTree
@@ -28,7 +29,19 @@ import timber.log.Timber.DebugTree
*/
class FrostApp : Application() {
+ companion object {
+ fun refWatcher(c: Context) = (c.applicationContext as FrostApp).refWatcher
+ }
+
+ lateinit var refWatcher: RefWatcher
+
override fun onCreate() {
+ if (LeakCanary.isInAnalyzerProcess(this)) {
+ // This process is dedicated to LeakCanary for heap analysis.
+ // You should not init your app in this process.
+ return;
+ }
+ refWatcher = LeakCanary.install(this);
if (BuildConfig.DEBUG) Timber.plant(DebugTree())
else {
Fabric.with(this, Crashlytics(), Answers())
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt
index fcda7fb4..914e27b2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt
@@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
import android.support.v4.widget.SwipeRefreshLayout
-import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.AppCompatTextView
import android.support.v7.widget.Toolbar
import android.widget.ImageView
@@ -40,7 +39,7 @@ import kotlin.concurrent.thread
/**
* Created by Allan Wang on 2017-06-01.
*/
-class LoginActivity : AppCompatActivity() {
+class LoginActivity : BaseLeakActivity() {
val toolbar: Toolbar by bindView(R.id.toolbar)
val web: LoginWebView by bindView(R.id.login_webview)
@@ -67,6 +66,7 @@ class LoginActivity : AppCompatActivity() {
setContentView(R.layout.activity_login)
ButterKnife.bind(this)
setSupportActionBar(toolbar)
+ setTitle(R.string.login)
web.loginObservable = loginObservable
web.progressObservable = progressObservable
loginObservable.observeOn(AndroidSchedulers.mainThread()).subscribe {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
index 931d6df7..7d46ef50 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
@@ -34,7 +34,7 @@ import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
-class MainActivity : AppCompatActivity() {
+class MainActivity : BaseLeakActivity() {
lateinit var adapter: SectionsPagerAdapter
val toolbar: Toolbar by bindView(R.id.toolbar)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
index 04056043..7245b9c5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
@@ -9,7 +9,7 @@ import com.pitchedapps.frost.utils.launchNewTask
/**
* Created by Allan Wang on 2017-05-28.
*/
-class StartActivity : AppCompatActivity() {
+class StartActivity : BaseLeakActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
index 3ec47a10..9bf6f500 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
@@ -1,7 +1,6 @@
package com.pitchedapps.frost
import android.os.Bundle
-import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import butterknife.ButterKnife
import com.jude.swipbackhelper.SwipeBackHelper
@@ -13,7 +12,7 @@ import com.pitchedapps.frost.web.FrostWebView
/**
* Created by Allan Wang on 2017-06-01.
*/
-class WebOverlayActivity : AppCompatActivity() {
+class WebOverlayActivity : BaseLeakActivity() {
val toolbar: Toolbar by bindView(R.id.overlay_toolbar)
val frostWeb: FrostWebView by bindView(R.id.overlay_frost_webview)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt
index 06484500..4ca45d86 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt
@@ -1,7 +1,9 @@
package com.pitchedapps.frost.fragments
+import android.support.annotation.CallSuper
import android.support.v4.app.Fragment
import com.pitchedapps.frost.utils.putInt
+import com.pitchedapps.frost.utils.refWatch
/**
* Created by Allan Wang on 2017-05-29.
@@ -22,4 +24,8 @@ abstract class BaseFragment : Fragment(), BaseFragmentContract {
}
}
+// override fun onDestroyView() {
+// super.onDestroyView()
+// refWatch()
+// }
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt
index 1cc0bf64..13a8a836 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt
@@ -4,7 +4,9 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.support.v4.app.ActivityOptionsCompat
+import android.support.v4.app.Fragment
import android.support.v4.content.ContextCompat
+import com.pitchedapps.frost.FrostApp
import com.pitchedapps.frost.R
import com.pitchedapps.frost.WebOverlayActivity
import com.pitchedapps.frost.dbflow.CookieModel
@@ -45,4 +47,10 @@ fun Activity.restart() {
overridePendingTransition(0, 0) //No transitions
startActivity(intent);
overridePendingTransition(0, 0)
-} \ No newline at end of file
+}
+
+fun Context.refWatch() {
+ FrostApp.refWatcher(this).watch(this)
+}
+
+fun Fragment.refWatch() = context.refWatch() \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
index d5fd6391..c5ac03ae 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
@@ -37,12 +37,13 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS
inflate(getContext(), R.layout.swipe_webview, this)
ButterKnife.bind(this)
web.progressObservable.observeOn(AndroidSchedulers.mainThread()).subscribe {
- val loaded = it == 100
- refresh.isRefreshing = !loaded
- progress.visibility = if (loaded) View.INVISIBLE else View.VISIBLE
+ progress.visibility = if (it == 100) View.INVISIBLE else View.VISIBLE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progress.setProgress(it, true)
else progress.progress = it
}
+ web.refreshObservable.observeOn(AndroidSchedulers.mainThread()).subscribe {
+ refresh.isRefreshing = it
+ }
refresh.setOnRefreshListener(this)
addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
override fun onViewDetachedFromWindow(v: View) {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
index 5c1aa5b1..fb5fd0e7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
@@ -15,11 +15,12 @@ import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.launchNewTask
import com.pitchedapps.frost.views.circularReveal
import com.pitchedapps.frost.views.fadeOut
+import io.reactivex.subjects.Subject
/**
* Created by Allan Wang on 2017-05-31.
*/
-class FrostWebViewClient(val position: () -> Int) : WebViewClient() {
+class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClient() {
companion object {
//Collections of jewels mapped with url match -> id
@@ -33,6 +34,7 @@ class FrostWebViewClient(val position: () -> Int) : WebViewClient() {
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
L.i("FWV Loading $url")
+ refreshObservable.onNext(true)
if (!url.contains(FACEBOOK_COM)) return
if (url.contains("logout.php")) {
FbCookie.logout(Prefs.userId)
@@ -46,6 +48,7 @@ class FrostWebViewClient(val position: () -> Int) : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
+ refreshObservable.onNext(false)
if (!url.contains(FACEBOOK_COM)) return
CssAssets.HEADER.inject(view, {
view.circularReveal(offset = 150L)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
index eaee60bc..34fd4509 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
@@ -36,18 +36,18 @@ class FrostWebViewCore @JvmOverloads constructor(
private val scrollOffset = IntArray(2)
private val scrollConsumed = IntArray(2)
private var nestedOffsetY: Int = 0
- val progressObservable: Subject<Int>
- val titleObservable: Subject<String>
+ val progressObservable: BehaviorSubject<Int> // Keeps track of every progress change
+ val refreshObservable: BehaviorSubject<Boolean> // Only emits on page loads
+ val titleObservable: BehaviorSubject<String> // Only emits on different non http titles
- private val chromeClient: FrostChromeClient
var baseUrl: String? = null
var position: Int = -1
init {
isNestedScrollingEnabled = true
progressObservable = BehaviorSubject.create<Int>()
+ refreshObservable = BehaviorSubject.create<Boolean>()
titleObservable = BehaviorSubject.create<String>()
- chromeClient = FrostChromeClient(progressObservable, titleObservable)
setupWebview()
}
@@ -56,8 +56,8 @@ class FrostWebViewCore @JvmOverloads constructor(
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
setLayerType(View.LAYER_TYPE_HARDWARE, null)
- setWebViewClient(FrostWebViewClient({ position }))
- setWebChromeClient(chromeClient)
+ setWebViewClient(FrostWebViewClient(refreshObservable))
+ setWebChromeClient(FrostChromeClient(progressObservable, titleObservable))
}
override fun loadUrl(url: String?) {
diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml
index 2c03624b..eef0e434 100644
--- a/app/src/main/res/layout/activity_login.xml
+++ b/app/src/main/res/layout/activity_login.xml
@@ -13,9 +13,17 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
+ android:theme="@style/AppTheme.AppBarOverlay"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
- <include layout="@layout/login_webview" />
+ <FrameLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginTop="?attr/actionBarSize">
+
+ <include layout="@layout/login_webview" />
+
+ </FrameLayout>
</android.support.design.widget.CoordinatorLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 97c84093..f99bd0ce 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -24,4 +24,5 @@
<string name="photos">Photos</string>
<string name="loading_account">Getting everything ready…</string>
<string name="welcome">Welcome %s</string>
+ <string name="login">Login</string>
</resources>