Commit 7d3f6096 authored by Mygod's avatar Mygod

Add plugin to card

Fix #1054.
parent c7c72c65
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:id="@+id/container"> android:id="@+id/container">
<TextView android:id="@+id/title" <TextView android:id="@android:id/text1"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
...@@ -54,15 +54,16 @@ ...@@ -54,15 +54,16 @@
android:contentDescription="@string/edit" android:contentDescription="@string/edit"
android:focusable="true"/> android:focusable="true"/>
</LinearLayout> </LinearLayout>
<LinearLayout android:layout_width="match_parent" <RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="4dp" android:layout_marginTop="4dp">
android:id="@+id/details"> <TextView android:id="@android:id/text2"
<TextView android:id="@+id/address" android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/traffic"
android:layout_marginEnd="8dp"
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
...@@ -71,10 +72,11 @@ ...@@ -71,10 +72,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_alignParentEnd="true"
android:ellipsize="end" android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/> android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</com.github.shadowsocks.widget.BoundedCardView> </com.github.shadowsocks.widget.BoundedCardView>
</FrameLayout> </FrameLayout>
...@@ -142,4 +142,5 @@ ...@@ -142,4 +142,5 @@
<string name="plugin_configure">Configure…</string> <string name="plugin_configure">Configure…</string>
<string name="plugin_disabled">Disabled</string> <string name="plugin_disabled">Disabled</string>
<string name="plugin_unknown">Unknown plugin %s</string> <string name="plugin_unknown">Unknown plugin %s</string>
<string name="profile_plugin">Plugin: %s</string>
</resources> </resources>
...@@ -37,11 +37,12 @@ import android.view._ ...@@ -37,11 +37,12 @@ import android.view._
import android.widget.{LinearLayout, PopupMenu, TextView, Toast} import android.widget.{LinearLayout, PopupMenu, TextView, Toast}
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import com.github.shadowsocks.widget.UndoSnackbarManager import com.github.shadowsocks.widget.UndoSnackbarManager
import com.google.android.gms.ads.{AdRequest, AdSize, NativeExpressAdView} import com.google.android.gms.ads.{AdRequest, AdSize, NativeExpressAdView}
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.Random import scala.util.Random
object ProfilesFragment { object ProfilesFragment {
...@@ -77,8 +78,8 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic ...@@ -77,8 +78,8 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
var item: Profile = _ var item: Profile = _
private val title = itemView.findViewById(R.id.title).asInstanceOf[TextView] private val text1 = itemView.findViewById(android.R.id.text1).asInstanceOf[TextView]
private val address = itemView.findViewById(R.id.address).asInstanceOf[TextView] private val text2 = itemView.findViewById(android.R.id.text2).asInstanceOf[TextView]
private val traffic = itemView.findViewById(R.id.traffic).asInstanceOf[TextView] private val traffic = itemView.findViewById(R.id.traffic).asInstanceOf[TextView]
private val edit = itemView.findViewById(R.id.edit) private val edit = itemView.findViewById(R.id.edit)
edit.setOnClickListener(_ => startConfig(item.id)) edit.setOnClickListener(_ => startConfig(item.id))
...@@ -111,10 +112,22 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic ...@@ -111,10 +112,22 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
tx += txTotal tx += txTotal
rx += rxTotal rx += rxTotal
} }
title.setText(item.getName) text1.setText(item.getName)
address.setText(if (item.nameIsEmpty) "" else item.formattedAddress) val t2 = new ListBuffer[String]
traffic.setText(if (tx <= 0 && rx <= 0) null else getString(R.string.stat_profiles, if (!item.nameIsEmpty) t2 += item.formattedAddress
new PluginConfiguration(item.plugin).selected match {
case "" =>
case id => t2 += app.getString(R.string.profile_plugin, id)
}
if (t2.isEmpty) text2.setVisibility(View.GONE) else {
text2.setVisibility(View.VISIBLE)
text2.setText(t2.mkString("\n"))
}
if (tx <= 0 && rx <= 0) traffic.setVisibility(View.GONE) else {
traffic.setVisibility(View.VISIBLE)
traffic.setText(getString(R.string.stat_profiles,
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx))) TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx)))
}
if (item.id == app.profileId) { if (item.id == app.profileId) {
itemView.setSelected(true) itemView.setSelected(true)
......
...@@ -11,6 +11,7 @@ import com.github.shadowsocks.utils.{Commandline, IOUtils} ...@@ -11,6 +11,7 @@ import com.github.shadowsocks.utils.{Commandline, IOUtils}
import eu.chainfire.libsuperuser.Shell import eu.chainfire.libsuperuser.Shell
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer
/** /**
* @author Mygod * @author Mygod
...@@ -80,14 +81,14 @@ object PluginManager { ...@@ -80,14 +81,14 @@ object PluginManager {
IOUtils.deleteRecursively(pluginDir) IOUtils.deleteRecursively(pluginDir)
if (!pluginDir.mkdirs()) throw new FileNotFoundException("Unable to create plugin directory") if (!pluginDir.mkdirs()) throw new FileNotFoundException("Unable to create plugin directory")
val pluginDirPath = pluginDir.getAbsolutePath + '/' val pluginDirPath = pluginDir.getAbsolutePath + '/'
var list: List[String] = Nil val list = new ListBuffer[String]
do { do {
val path = cursor.getString(0) val path = cursor.getString(0)
val file = new File(pluginDir, path) val file = new File(pluginDir, path)
assert(file.getAbsolutePath.startsWith(pluginDirPath)) assert(file.getAbsolutePath.startsWith(pluginDirPath))
autoClose(cr.openInputStream(builder.path(path).build()))(in => autoClose(cr.openInputStream(builder.path(path).build()))(in =>
autoClose(new FileOutputStream(file))(out => IOUtils.copy(in, out))) autoClose(new FileOutputStream(file))(out => IOUtils.copy(in, out)))
list +:= Commandline.toString(Array("chmod", cursor.getString(1), file.getAbsolutePath)) list += Commandline.toString(Array("chmod", cursor.getString(1), file.getAbsolutePath))
if (path == id) initialized = true if (path == id) initialized = true
} while (cursor.moveToNext()) } while (cursor.moveToNext())
if (!initialized) entryNotFound() if (!initialized) entryNotFound()
......
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