Commit 982605b3 authored by Mygod's avatar Mygod

Slide up stats bar on connect

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