Commit da3690d1 authored by Mygod's avatar Mygod

Fix #441

parent ffdde981
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<include layout="@layout/toolbar_light_dark" /> <include layout="@layout/toolbar_light_dark" />
<android.support.v7.widget.RecyclerView android:id="@+id/profilesList" <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="0dp"
android:layout_height="0dp" android:layout_weight="1">
android:layout_weight="1" /> <android.support.v7.widget.RecyclerView android:id="@+id/profilesList"
app:layout_behavior="com.github.shadowsocks.widget.AutoPaddingBehavior"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout> </LinearLayout>
...@@ -153,7 +153,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe ...@@ -153,7 +153,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
profilesList.setLayoutManager(new LinearLayoutManager(this)) profilesList.setLayoutManager(new LinearLayoutManager(this))
profilesList.setItemAnimator(new DefaultItemAnimator) profilesList.setItemAnimator(new DefaultItemAnimator)
profilesList.setAdapter(profilesAdapter) profilesList.setAdapter(profilesAdapter)
removedSnackbar = Snackbar.make(findViewById(android.R.id.content), R.string.removed, Snackbar.LENGTH_LONG) removedSnackbar = Snackbar.make(profilesList, R.string.removed, Snackbar.LENGTH_LONG)
.setAction(R.string.undo, ((v: View) => profilesAdapter.undoRemoves): OnClickListener) .setAction(R.string.undo, ((v: View) => profilesAdapter.undoRemoves): OnClickListener)
removedSnackbar.getView.addOnAttachStateChangeListener(new OnAttachStateChangeListener { removedSnackbar.getView.addOnAttachStateChangeListener(new OnAttachStateChangeListener {
def onViewDetachedFromWindow(v: View) = profilesAdapter.commitRemoves def onViewDetachedFromWindow(v: View) = profilesAdapter.commitRemoves
......
...@@ -293,12 +293,6 @@ class Shadowsocks ...@@ -293,12 +293,6 @@ class Shadowsocks
} }
} }
def isTextEmpty(s: String, msg: String): Boolean = {
if (s != null && s.length > 0) return false
Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), msg, Snackbar.LENGTH_LONG).show
true
}
def cancelStart() { def cancelStart() {
clearDialog() clearDialog()
changeSwitch(checked = false) changeSwitch(checked = false)
...@@ -554,7 +548,9 @@ class Shadowsocks ...@@ -554,7 +548,9 @@ class Shadowsocks
def checkText(key: String): Boolean = { def checkText(key: String): Boolean = {
val text = ShadowsocksApplication.settings.getString(key, "") val text = ShadowsocksApplication.settings.getString(key, "")
!isTextEmpty(text, getString(R.string.proxy_empty)) if (text != null && text.length > 0) return true
Snackbar.make(findViewById(android.R.id.content), getString(R.string.proxy_empty), Snackbar.LENGTH_LONG).show
false
} }
/** Called when connect button is clicked. */ /** Called when connect button is clicked. */
...@@ -598,7 +594,7 @@ class Shadowsocks ...@@ -598,7 +594,7 @@ class Shadowsocks
handler.postDelayed(() => fabProgressCircle.hide(), 1000) handler.postDelayed(() => fabProgressCircle.hide(), 1000)
fab.setEnabled(true) fab.setEnabled(true)
changeSwitch(checked = false) changeSwitch(checked = false)
if (m != null) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), if (m != null) Snackbar.make(findViewById(android.R.id.content),
getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m), Snackbar.LENGTH_LONG).show getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m), Snackbar.LENGTH_LONG).show
setPreferenceEnabled(enabled = true) setPreferenceEnabled(enabled = true)
case State.STOPPING => case State.STOPPING =>
......
...@@ -5,9 +5,9 @@ import java.util.Locale ...@@ -5,9 +5,9 @@ import java.util.Locale
import android.content.{DialogInterface, Intent} import android.content.{DialogInterface, Intent}
import android.net.Uri import android.net.Uri
import android.os.{Build, Bundle} import android.os.{Build, Bundle}
import android.preference.{SwitchPreference, Preference, PreferenceFragment} import android.preference.{Preference, PreferenceFragment, SwitchPreference}
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.webkit.{WebViewClient, WebView} import android.webkit.{WebView, WebViewClient}
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
// TODO: Move related logic here // TODO: Move related logic here
......
package com.github.shadowsocks.widget
import android.content.Context
import android.support.design.widget.CoordinatorLayout
import android.support.design.widget.CoordinatorLayout.Behavior
import android.support.design.widget.Snackbar.SnackbarLayout
import android.util.AttributeSet
import android.view.View
/**
* @author Mygod
*/
class AutoPaddingBehavior(context: Context, attrs: AttributeSet) extends Behavior[View] {
override def layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View) =
dependency.isInstanceOf[SnackbarLayout]
override def onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View) =
dependency match {
case sl: SnackbarLayout =>
child.setPadding(0, 0, 0, dependency.getHeight)
true
case _ => super.onDependentViewChanged(parent, child, dependency)
}
override def onDependentViewRemoved(parent: CoordinatorLayout, child: View, dependency: View) =
dependency match {
case sl: SnackbarLayout => child.setPadding(0, 0, 0, 0)
case _ => super.onDependentViewRemoved(parent, child, dependency)
}
}
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