Commit 982605b3 authored by Mygod's avatar Mygod

Slide up stats bar on connect

parent 38e437da
......@@ -21,7 +21,6 @@
package com.github.shadowsocks
import android.app.Activity
import android.app.PendingIntent
import android.app.backup.BackupManager
import android.content.ActivityNotFoundException
import android.content.Intent
......@@ -33,7 +32,6 @@ import android.util.Log
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.browser.customtabs.CustomTabsIntent
......@@ -76,7 +74,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
internal lateinit var drawer: DrawerLayout
private lateinit var navigation: NavigationView
val snackbar by lazy { findViewById<View>(R.id.snackbar) }
val snackbar by lazy { findViewById<CoordinatorLayout>(R.id.snackbar) }
fun snackbar(text: CharSequence = "") = Snackbar.make(snackbar, text, Snackbar.LENGTH_LONG).apply {
view.updateLayoutParams<CoordinatorLayout.LayoutParams> {
bottomMargin += snackbar.measuredHeight - fab.top - fab.translationY.roundToInt()
......
......@@ -41,8 +41,7 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet?
private lateinit var txRateText: TextView
private lateinit var rxRateText: TextView
private val tester by lazy { HttpsTest(statusText::setText) { (context as MainActivity).snackbar(it).show() } }
override fun getBehavior() = object : Behavior() {
private val behavior = object : Behavior() {
val threshold = context.resources.getDimensionPixelSize(R.dimen.stats_bar_scroll_threshold)
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: BottomAppBar, target: View,
dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int) {
......@@ -50,7 +49,9 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet?
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, if (Math.abs(dy) >= threshold) dy else 0,
dxUnconsumed, 0, type)
}
public override fun slideUp(child: BottomAppBar) = super.slideUp(child)
}
override fun getBehavior() = behavior
override fun setOnClickListener(l: OnClickListener?) {
statusText = findViewById(R.id.status)
......@@ -71,7 +72,7 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet?
if (state != BaseService.CONNECTED) {
updateTraffic(0, 0, 0, 0)
tester.invalidate()
}
} else behavior.slideUp(this)
}
fun updateTraffic(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment