Commit 64f32a64 authored by Mygod's avatar Mygod

Refine connection test layout

parent 7de4a01d
...@@ -20,9 +20,15 @@ ...@@ -20,9 +20,15 @@
android:orientation="vertical" android:orientation="vertical"
android:nextFocusRight="@+id/fab" android:nextFocusRight="@+id/fab"
android:layout_alignParentBottom="true"> android:layout_alignParentBottom="true">
<TextView android:id="@+id/status"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee"
android:paddingEnd="72dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.GridLayout android:layout_width="match_parent" <android.support.v7.widget.GridLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingEnd="72dip"
app:columnCount="4"> app:columnCount="4">
<TextView app:layout_column="0" style="@style/TextAppearance.AppCompat.Body2" <TextView app:layout_column="0" style="@style/TextAppearance.AppCompat.Body2"
android:ellipsize="marquee" android:text="@string/sent" android:ellipsize="marquee" android:text="@string/sent"
...@@ -58,23 +64,6 @@ ...@@ -58,23 +64,6 @@
android:layout_width="0dp" android:layout_height="wrap_content" app:layout_columnWeight="1" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_columnWeight="1"
app:layout_gravity="fill_horizontal" android:gravity="end"/> app:layout_gravity="fill_horizontal" android:gravity="end"/>
</android.support.v7.widget.GridLayout> </android.support.v7.widget.GridLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<TextView android:text="@string/stat"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/connection_test"
android:gravity="end"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
<com.github.jorgecastilloprz.FABProgressCircle android:id="@+id/fabProgressCircle" <com.github.jorgecastilloprz.FABProgressCircle android:id="@+id/fabProgressCircle"
app:reusable="true" app:reusable="true"
......
...@@ -45,7 +45,6 @@ import com.github.shadowsocks.aidl.IShadowsocksServiceCallback ...@@ -45,7 +45,6 @@ import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.utils.CloseUtils.autoDisconnect import com.github.shadowsocks.utils.CloseUtils.autoDisconnect
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import com.google.android.gms.ads.AdView
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
import com.mikepenz.materialdrawer.model.{PrimaryDrawerItem, SecondaryDrawerItem} import com.mikepenz.materialdrawer.model.{PrimaryDrawerItem, SecondaryDrawerItem}
import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder} import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder}
...@@ -89,7 +88,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -89,7 +88,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
fab.setImageResource(R.drawable.ic_start_busy) fab.setImageResource(R.drawable.ic_start_busy)
fab.setEnabled(false) fab.setEnabled(false)
fabProgressCircle.show() fabProgressCircle.show()
//stat.setVisibility(View.GONE) statusText.setText("Connecting...")
case State.CONNECTED => case State.CONNECTED =>
fab.setBackgroundTintList(greenTint) fab.setBackgroundTintList(greenTint)
if (state == State.CONNECTING) { if (state == State.CONNECTING) {
...@@ -99,11 +98,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -99,11 +98,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
} }
fab.setEnabled(true) fab.setEnabled(true)
changeSwitch(checked = true) changeSwitch(checked = true)
stat.setVisibility(View.VISIBLE) statusText.setText(if (app.isNatEnabled) "Connected" else "Connected, tap to check connection")
if (app.isNatEnabled) connectionTestText.setVisibility(View.GONE) else {
connectionTestText.setVisibility(View.VISIBLE)
connectionTestText.setText(getString(R.string.connection_test_pending))
}
case State.STOPPED => case State.STOPPED =>
fab.setBackgroundTintList(greyTint) fab.setBackgroundTintList(greyTint)
fabProgressCircle.postDelayed(hideCircle, 1000) fabProgressCircle.postDelayed(hideCircle, 1000)
...@@ -116,13 +111,13 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -116,13 +111,13 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
snackbar.show() snackbar.show()
Log.e(TAG, "Error to start VPN service: " + m) Log.e(TAG, "Error to start VPN service: " + m)
} }
//stat.setVisibility(View.GONE) statusText.setText("Not connected")
case State.STOPPING => case State.STOPPING =>
fab.setBackgroundTintList(greyTint) fab.setBackgroundTintList(greyTint)
fab.setImageResource(R.drawable.ic_start_busy) fab.setImageResource(R.drawable.ic_start_busy)
fab.setEnabled(false) fab.setEnabled(false)
if (state == State.CONNECTED) fabProgressCircle.show() // ignore for stopped if (state == State.CONNECTED) fabProgressCircle.show() // ignore for stopped
//stat.setVisibility(View.GONE) statusText.setText("Shutting down...")
} }
state = s state = s
}) })
...@@ -168,22 +163,17 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -168,22 +163,17 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
} }
private var testCount: Int = _ private var testCount: Int = _
private var stat: View = _ private var statusText: TextView = _ // TODO: localize texts for statusText in this file
private var connectionTestText: TextView = _
private var txText: TextView = _ private var txText: TextView = _
private var rxText: TextView = _ private var rxText: TextView = _
private var txRateText: TextView = _ private var txRateText: TextView = _
private var rxRateText: TextView = _ private var rxRateText: TextView = _
private lazy val greyTint = ContextCompat.getColorStateList(this, R.color.material_blue_grey_700) private lazy val greyTint = ContextCompat.getColorStateList(this, R.color.material_blue_grey_700)
private lazy val greenTint = ContextCompat.getColorStateList(this, R.color.material_green_700) private lazy val greenTint = ContextCompat.getColorStateList(this, R.color.material_green_700)
private var adView: AdView = _
val handler = new Handler() val handler = new Handler()
private val connectedListener: BroadcastReceiver = (_, _) => private val connectedListener: BroadcastReceiver = (_, _) =>
if (app.isNatEnabled) connectionTestText.setVisibility(View.GONE) else { statusText.setText(if (app.isNatEnabled) "Connected" else "Connected, tap to check connection")
connectionTestText.setVisibility(View.VISIBLE)
connectionTestText.setText(getString(R.string.connection_test_pending))
}
private def changeSwitch(checked: Boolean) { private def changeSwitch(checked: Boolean) {
serviceStarted = checked serviceStarted = checked
...@@ -248,16 +238,15 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -248,16 +238,15 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
if (tf != null) title.setTypeface(tf) if (tf != null) title.setTypeface(tf)
if (savedInstanceState == null) displayFragment(profilesFragment) if (savedInstanceState == null) displayFragment(profilesFragment)
stat = findViewById(R.id.stat) statusText = findViewById(R.id.status).asInstanceOf[TextView]
connectionTestText = findViewById(R.id.connection_test).asInstanceOf[TextView]
txText = findViewById(R.id.tx).asInstanceOf[TextView] txText = findViewById(R.id.tx).asInstanceOf[TextView]
txRateText = findViewById(R.id.txRate).asInstanceOf[TextView] txRateText = findViewById(R.id.txRate).asInstanceOf[TextView]
rxText = findViewById(R.id.rx).asInstanceOf[TextView] rxText = findViewById(R.id.rx).asInstanceOf[TextView]
rxRateText = findViewById(R.id.rxRate).asInstanceOf[TextView] rxRateText = findViewById(R.id.rxRate).asInstanceOf[TextView]
stat.setOnClickListener(_ => { findViewById(R.id.stat).setOnClickListener(_ => {
val id = synchronized { val id = synchronized {
testCount += 1 testCount += 1
handler.post(() => connectionTestText.setText(R.string.connection_test_testing)) handler.post(() => statusText.setText(R.string.connection_test_testing))
testCount testCount
} }
Utils.ThrowableFuture { Utils.ThrowableFuture {
...@@ -284,9 +273,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -284,9 +273,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
success = false success = false
result = getString(R.string.connection_test_error, e.getMessage) result = getString(R.string.connection_test_error, e.getMessage)
} }
synchronized(if (testCount == id && app.isVpnEnabled) handler.post(() => synchronized(if (serviceStarted && testCount == id && app.isVpnEnabled) handler.post(() =>
if (success) connectionTestText.setText(result) else { if (success) statusText.setText(result) else {
connectionTestText.setText(R.string.connection_test_fail) statusText.setText(R.string.connection_test_fail)
Snackbar.make(findViewById(android.R.id.content), result, Snackbar.LENGTH_LONG).show() Snackbar.make(findViewById(android.R.id.content), result, Snackbar.LENGTH_LONG).show()
})) }))
} }
...@@ -404,32 +393,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -404,32 +393,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
private def updateState() { private def updateState() {
if (bgService != null) { if (bgService != null) {
Log.d(TAG, "bgService " + bgService.getState) Log.d(TAG, "bgService " + bgService.getState)
bgService.getState match { callback.stateChanged(bgService.getState, null, null)
case State.CONNECTING =>
fab.setBackgroundTintList(greyTint)
serviceStarted = false
fab.setImageResource(R.drawable.ic_start_busy)
fabProgressCircle.show()
//stat.setVisibility(View.GONE)
case State.CONNECTED =>
fab.setBackgroundTintList(greenTint)
serviceStarted = true
fab.setImageResource(R.drawable.ic_start_connected)
fabProgressCircle.postDelayed(hideCircle, 100)
stat.setVisibility(View.VISIBLE)
case State.STOPPING =>
fab.setBackgroundTintList(greyTint)
serviceStarted = false
fab.setImageResource(R.drawable.ic_start_busy)
fabProgressCircle.show()
//stat.setVisibility(View.GONE)
case _ =>
fab.setBackgroundTintList(greyTint)
serviceStarted = false
fab.setImageResource(R.drawable.ic_start_idle)
fabProgressCircle.postDelayed(hideCircle, 100)
//stat.setVisibility(View.GONE)
}
state = bgService.getState state = bgService.getState
} }
} }
......
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