Commit c87930b2 authored by Max Lv's avatar Max Lv

Refine the profile item layout

parent 436119e0
...@@ -4,23 +4,23 @@ ...@@ -4,23 +4,23 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="true" android:background="@drawable/background_selectable"
android:nextFocusRight="@+id/edit"
android:background="?android:attr/selectableItemBackground"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"> android:layout_marginEnd="8dp"
android:id="@+id/indicator" >
<LinearLayout android:layout_width="match_parent" <LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:padding="8dp" android:padding="8dp"
android:id="@+id/indicator" android:focusable="true"
android:background="@drawable/background_selectable"> android:nextFocusRight="@+id/edit"
android:background="?android:attr/selectableItemBackground">
<LinearLayout android:layout_width="match_parent" <LinearLayout android:layout_width="match_parent"
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="@android:id/text1" <TextView android:id="@+id/title"
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"
...@@ -41,11 +41,31 @@ ...@@ -41,11 +41,31 @@
android:focusable="true" android:focusable="true"
android:nextFocusLeft="@+id/container"/> android:nextFocusLeft="@+id/container"/>
</LinearLayout> </LinearLayout>
<TextView android:id="@android:id/text2" <LinearLayout android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginTop="8dp"
android:textColor="?android:attr/textColorSecondary"/> android:id="@+id/details">
<TextView android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="1"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"/>
<TextView android:id="@+id/traffic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|right"
android:layout_weight="1"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<string name="remote_dns_summary">DNS server for remote hostname resolution. (Default 8.8.8.8)</string> <string name="remote_dns_summary">DNS server for remote hostname resolution. (Default 8.8.8.8)</string>
<string name="stat">Network Traffic</string> <string name="stat">Network Traffic</string>
<string name="stat_summary">Sent: \t\t\t\t\t%3$s\t↑\t%1$s/s\nReceived: \t%4$s\t↓\t%2$s/s</string> <string name="stat_summary">Sent: \t\t\t\t\t%3$s\t↑\t%1$s/s\nReceived: \t%4$s\t↓\t%2$s/s</string>
<string name="stat_profiles">\n%1$s↑\t%2$s↓</string> <string name="stat_profiles">%1$s↑\t%2$s↓</string>
<string name="traffic_summary">%1$s/s↑\t%2$s/s↓</string> <string name="traffic_summary">%1$s/s↑\t%2$s/s↓</string>
<plurals name="bytes" translatable="false"> <plurals name="bytes" translatable="false">
<item quantity="one">Byte</item> <item quantity="one">Byte</item>
......
...@@ -43,8 +43,9 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -43,8 +43,9 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
with View.OnClickListener { with View.OnClickListener {
var item: Profile = _ var item: Profile = _
private val text1 = itemView.findViewById(android.R.id.text1).asInstanceOf[TextView] private val text1 = itemView.findViewById(R.id.title).asInstanceOf[TextView]
private val text2 = itemView.findViewById(android.R.id.text2).asInstanceOf[TextView] private val text2 = itemView.findViewById(R.id.address).asInstanceOf[TextView]
private val text3 = itemView.findViewById(R.id.traffic).asInstanceOf[TextView]
private val indicator = itemView.findViewById(R.id.indicator).asInstanceOf[ViewGroup] private val indicator = itemView.findViewById(R.id.indicator).asInstanceOf[ViewGroup]
itemView.setOnClickListener(this) itemView.setOnClickListener(this)
...@@ -63,17 +64,15 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -63,17 +64,15 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
val tx = item.tx + txTotal val tx = item.tx + txTotal
val rx = item.rx + rxTotal val rx = item.rx + rxTotal
var title = if (isDemoMode) "Profile #" + item.id else item.name var title = if (isDemoMode) "Profile #" + item.id else item.name
val builder = new StringBuilder()
val address = (if (item.host.contains(":")) "[%s]:%d" else "%s:%d").format(item.host, item.remotePort) val address = (if (item.host.contains(":")) "[%s]:%d" else "%s:%d").format(item.host, item.remotePort)
if (title == null || title.isEmpty) title = address else builder.append(address) if (title == null || title.isEmpty) title = address
// if (tx != 0 || rx != 0) { val traffic = getString(R.string.stat_profiles,
if (builder.nonEmpty) builder.append('\n') TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx))
builder.append(getString(R.string.stat_profiles,
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx)))
// }
handler.post(() => { handler.post(() => {
text1.setText(title) text1.setText(title)
text2.setText(builder) text2.setText(address)
text3.setText(traffic)
}) })
} }
...@@ -92,11 +91,14 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -92,11 +91,14 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
} }
def onClick(v: View) { def onClick(v: View) {
if (getActivity.asInstanceOf[MainActivity].state == State.STOPPED) { val activity = getActivity.asInstanceOf[MainActivity]
val state = activity.state
if (state == State.STOPPED || state == State.CONNECTED) {
val old = app.profileId val old = app.profileId
app.switchProfile(item.id) app.switchProfile(item.id)
profilesAdapter.refreshId(old) profilesAdapter.refreshId(old)
bind(item) bind(item)
if (state == State.CONNECTED) activity.serviceLoad()
} }
} }
} }
......
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