Skip to content

Commit

Permalink
Fix #441
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Nov 23, 2015
1 parent ffdde98 commit da3690d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
13 changes: 9 additions & 4 deletions src/main/res/layout/layout_profiles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar_light_dark" />
<android.support.v7.widget.RecyclerView android:id="@+id/profilesList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
android:layout_height="0dp"
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>
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
profilesList.setLayoutManager(new LinearLayoutManager(this))
profilesList.setItemAnimator(new DefaultItemAnimator)
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)
removedSnackbar.getView.addOnAttachStateChangeListener(new OnAttachStateChangeListener {
def onViewDetachedFromWindow(v: View) = profilesAdapter.commitRemoves
Expand Down
12 changes: 4 additions & 8 deletions src/main/scala/com/github/shadowsocks/Shadowsocks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
clearDialog()
changeSwitch(checked = false)
Expand Down Expand Up @@ -554,7 +548,9 @@ class Shadowsocks

def checkText(key: String): Boolean = {
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. */
Expand Down Expand Up @@ -598,7 +594,7 @@ class Shadowsocks
handler.postDelayed(() => fabProgressCircle.hide(), 1000)
fab.setEnabled(true)
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
setPreferenceEnabled(enabled = true)
case State.STOPPING =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import java.util.Locale
import android.content.{DialogInterface, Intent}
import android.net.Uri
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.webkit.{WebViewClient, WebView}
import android.webkit.{WebView, WebViewClient}
import com.github.shadowsocks.utils.Key

// TODO: Move related logic here
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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)
}
}

0 comments on commit da3690d

Please sign in to comment.