Skip to content

Commit 2c972e2

Browse files
committed
Add security icons
1 parent 43f300d commit 2c972e2

File tree

5 files changed

+91
-38
lines changed

5 files changed

+91
-38
lines changed

app/src/main/java/tk/superl2/xwifi/MainActivity.kt

+41-28
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import android.view.MenuItem
2626
import android.view.ViewGroup
2727
import android.widget.*
2828
import kotlinx.android.synthetic.main.activity_main.*
29+
import kotlinx.android.synthetic.main.wifi_list_item.view.*
2930
import net.glxn.qrgen.android.QRCode
3031
import net.glxn.qrgen.core.scheme.Wifi
3132

@@ -64,12 +65,35 @@ class MainActivity: AppCompatActivity() {
6465
// The adapter class for the RecyclerView
6566
inner class WifiListAdapter: RecyclerView.Adapter<WifiListAdapter.ViewHolder>(), Filterable {
6667
// The ViewHolder class for the adapter
67-
inner class ViewHolder(val item: TextView) : RecyclerView.ViewHolder(item) {
68+
inner class ViewHolder(val item: LinearLayout) : RecyclerView.ViewHolder(item) {
6869
// The WifiEntry object associated with the list item
6970
lateinit var wifiEntry: WifiEntry
7071
init {
71-
// Set onClick action
72-
item.setOnClickListener {
72+
fun createAndShowInfoDialog(): Boolean {
73+
qrDialog = AlertDialog.Builder(this@MainActivity).apply {
74+
setMessage(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
75+
Html.fromHtml(
76+
"<b>SSID:</b> ${wifiEntry.title}<br>" +
77+
if (wifiEntry.password != "") "<b>Password:</b> ${if (wifiEntry.type != WifiEntry.Type.WEP) wifiEntry.password else wifiEntry.password.removePrefix("\"").removeSuffix("\"")}<br>" else { "" } +
78+
"<b>Type:</b> ${wifiEntry.type}",
79+
Html.FROM_HTML_MODE_LEGACY)
80+
} else {
81+
@Suppress("DEPRECATION")
82+
Html.fromHtml(
83+
"<b>SSID:</b> ${wifiEntry.title}<br>" +
84+
if (wifiEntry.password != "") "<b>Password:</b> ${if (wifiEntry.type != WifiEntry.Type.WEP) wifiEntry.password else wifiEntry.password.removePrefix("\"").removeSuffix("\"")}<br>" else { "" } +
85+
"<b>Type:</b> ${wifiEntry.type}"
86+
)
87+
}
88+
)
89+
setPositiveButton("Done") { dialog, _ -> dialog.dismiss() }
90+
}.create()
91+
qrDialog.show()
92+
return true
93+
}
94+
95+
// Set label onClick action
96+
item.label.setOnClickListener {
7397
qrDialog = AlertDialog.Builder(this@MainActivity).apply {
7498
setTitle(wifiEntry.title)
7599
setView(ImageView(this@MainActivity).apply {
@@ -88,40 +112,29 @@ class MainActivity: AppCompatActivity() {
88112
}.create()
89113
qrDialog.show()
90114
}
91-
// Set onLongClick action
92-
item.setOnLongClickListener {
93-
qrDialog = AlertDialog.Builder(this@MainActivity).apply {
94-
setMessage(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
95-
Html.fromHtml(
96-
"<b>SSID:</b> ${wifiEntry.title ?: "<i>ERROR</i>"}<br>" +
97-
if (wifiEntry.password != "") "<b>Password:</b> ${if (wifiEntry.type != WifiEntry.Type.WEP) wifiEntry.password else wifiEntry.password.removePrefix("\"").removeSuffix("\"")}<br>" else { "" } +
98-
"<b>Type:</b> ${wifiEntry.type ?: "</i>ERROR</i>"}",
99-
Html.FROM_HTML_MODE_LEGACY)
100-
} else {
101-
@Suppress("DEPRECATION")
102-
Html.fromHtml(
103-
"<b>SSID:</b> ${wifiEntry.title ?: "<i>ERROR</i>"}<br>" +
104-
if (wifiEntry.password != "") "<b>Password:</b> ${if (wifiEntry.type != WifiEntry.Type.WEP) wifiEntry.password else wifiEntry.password.removePrefix("\"").removeSuffix("\"")}<br>" else { "" } +
105-
"<b>Type:</b> ${wifiEntry.type ?: "</i>ERROR</i>"}"
106-
)
107-
}
108-
)
109-
setPositiveButton("Done") { dialog, _ -> dialog.dismiss() }
110-
}.create()
111-
qrDialog.show()
112-
true
113-
}
115+
// Set label onLongClick action
116+
item.label.setOnLongClickListener { createAndShowInfoDialog() }
117+
118+
// Set security icon onClick action
119+
item.security.setOnClickListener { createAndShowInfoDialog() }
114120
}
115121
}
116122

117123
// Creates and returns ViewHolders
118124
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
119-
ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.wifi_list_item, parent, false) as TextView)
125+
ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.wifi_list_item, parent, false) as LinearLayout)
120126

121127
// Binds new data to recycled ViewHolders
122128
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
123129
holder.wifiEntry = wifiList[position]
124-
holder.item.text = holder.wifiEntry.title
130+
holder.item.label.text = holder.wifiEntry.title
131+
holder.item.security.setImageDrawable(
132+
if (holder.wifiEntry.type == WifiEntry.Type.NONE) {
133+
ContextCompat.getDrawable(this@MainActivity, R.drawable.ic_signal_wifi_4_bar_24dp)
134+
} else {
135+
ContextCompat.getDrawable(this@MainActivity, R.drawable.ic_signal_wifi_4_bar_lock_24dp)
136+
}
137+
)
125138
}
126139

127140
// Returns how many list items there are
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="?attr/textColorAlertDialogListItem"
8+
android:pathData="M12.01,21.49L23.64,7c-0.45,-0.34 -4.93,-4 -11.64,-4C5.28,3 0.81,6.66 0.36,7l11.63,14.49 0.01,0.01 0.01,-0.01z" />
9+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector android:autoMirrored="true"
2+
android:height="24dp"
3+
android:viewportHeight="24.0"
4+
android:viewportWidth="24.0"
5+
android:width="24dp"
6+
xmlns:android="http://schemas.android.com/apk/res/android">
7+
<path
8+
android:fillColor="?attr/textColorAlertDialogListItem"
9+
android:pathData="M23,16v-1.5c0,-1.4 -1.1,-2.5 -2.5,-2.5S18,13.1 18,14.5L18,16c-0.5,0 -1,0.5 -1,1v4c0,0.5 0.5,1 1,1h5c0.5,0 1,-0.5 1,-1v-4c0,-0.5 -0.5,-1 -1,-1zM22,16h-3v-1.5c0,-0.8 0.7,-1.5 1.5,-1.5s1.5,0.7 1.5,1.5L22,16zM15.5,14.5c0,-2.8 2.2,-5 5,-5 0.4,0 0.7,0 1,0.1L23.6,7c-0.4,-0.3 -4.9,-4 -11.6,-4C5.3,3 0.8,6.7 0.4,7L12,21.5l3.5,-4.4v-2.6z" />
10+
</vector>
+30-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:id="@+id/ssid"
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
33
android:layout_width="match_parent"
44
android:layout_height="wrap_content"
5-
android:background="?android:attr/selectableItemBackground"
6-
android:gravity="center_vertical"
7-
android:minHeight="?android:attr/listPreferredItemHeightSmall"
8-
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
9-
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
10-
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
11-
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
12-
android:textAppearance="?android:attr/textAppearanceListItemSmall" />
5+
android:orientation="horizontal">
6+
7+
<TextView
8+
android:id="@+id/label"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:layout_weight="1"
12+
android:background="?android:attr/selectableItemBackground"
13+
android:gravity="center_vertical"
14+
android:minHeight="?android:attr/listPreferredItemHeightSmall"
15+
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
16+
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
17+
android:textAppearance="?android:attr/textAppearanceListItemSmall"
18+
tools:ignore="RtlSymmetry" />
19+
20+
<ImageView
21+
android:id="@+id/security"
22+
android:layout_width="50dp"
23+
android:layout_height="match_parent"
24+
android:layout_weight="0"
25+
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
26+
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
27+
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
28+
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
29+
android:contentDescription="@string/security_type_image_description"
30+
android:background="?android:attr/selectableItemBackground"
31+
tools:ignore="RtlSymmetry" />
32+
</LinearLayout>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<string name="theme_restart_message">You may need to restart the app for the new theme to apply properly.</string>
1111
<string name="item_sort_menu_activity_main">Sort order</string>
1212
<string name="item_search_menu_activity_main">Search</string>
13+
<string name="security_type_image_description">Security</string>
1314
</resources>

0 commit comments

Comments
 (0)