Refine the profile item layout
This commit is contained in:
@@ -4,23 +4,23 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="true"
|
||||
android:nextFocusRight="@+id/edit"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:background="@drawable/background_selectable"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp">
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/indicator" >
|
||||
<LinearLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp"
|
||||
android:id="@+id/indicator"
|
||||
android:background="@drawable/background_selectable">
|
||||
android:focusable="true"
|
||||
android:nextFocusRight="@+id/edit"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
<LinearLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:id="@+id/container">
|
||||
<TextView android:id="@android:id/text1"
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
@@ -41,11 +41,31 @@
|
||||
android:focusable="true"
|
||||
android:nextFocusLeft="@+id/container"/>
|
||||
</LinearLayout>
|
||||
<TextView android:id="@android:id/text2"
|
||||
android:layout_width="match_parent"
|
||||
<LinearLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
android:layout_marginTop="8dp"
|
||||
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>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<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_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>
|
||||
<plurals name="bytes" translatable="false">
|
||||
<item quantity="one">Byte</item>
|
||||
|
||||
@@ -43,8 +43,9 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
|
||||
with View.OnClickListener {
|
||||
|
||||
var item: Profile = _
|
||||
private val text1 = itemView.findViewById(android.R.id.text1).asInstanceOf[TextView]
|
||||
private val text2 = itemView.findViewById(android.R.id.text2).asInstanceOf[TextView]
|
||||
private val text1 = itemView.findViewById(R.id.title).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]
|
||||
itemView.setOnClickListener(this)
|
||||
|
||||
@@ -63,17 +64,15 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
|
||||
val tx = item.tx + txTotal
|
||||
val rx = item.rx + rxTotal
|
||||
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)
|
||||
if (title == null || title.isEmpty) title = address else builder.append(address)
|
||||
// if (tx != 0 || rx != 0) {
|
||||
if (builder.nonEmpty) builder.append('\n')
|
||||
builder.append(getString(R.string.stat_profiles,
|
||||
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx)))
|
||||
// }
|
||||
if (title == null || title.isEmpty) title = address
|
||||
val traffic = getString(R.string.stat_profiles,
|
||||
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx))
|
||||
|
||||
handler.post(() => {
|
||||
text1.setText(title)
|
||||
text2.setText(builder)
|
||||
text2.setText(address)
|
||||
text3.setText(traffic)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,11 +91,14 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
|
||||
}
|
||||
|
||||
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
|
||||
app.switchProfile(item.id)
|
||||
profilesAdapter.refreshId(old)
|
||||
bind(item)
|
||||
if (state == State.CONNECTED) activity.serviceLoad()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user