1
1
package tk.superl2.xwifi
2
2
3
+ import android.Manifest
3
4
import android.app.AlertDialog
4
5
import android.content.Intent
5
- import android.content.SharedPreferences
6
+ import android.content.pm.PackageManager
6
7
import android.os.AsyncTask
7
8
import android.os.Build
8
9
import android.os.Bundle
9
10
import android.preference.PreferenceManager
11
+ import android.support.v4.app.ActivityCompat
12
+ import android.support.v4.content.ContextCompat
10
13
import android.support.v7.app.AppCompatActivity
11
14
import android.support.v7.app.AppCompatDelegate
12
15
import android.text.Html
@@ -18,28 +21,26 @@ import android.widget.ImageView
18
21
import android.widget.ProgressBar
19
22
import android.widget.Toast
20
23
import com.applovin.sdk.AppLovinSdk
21
- import com.mopub.mobileads.MoPubView
22
24
import kotlinx.android.synthetic.main.activity_main.*
23
25
import net.glxn.qrgen.android.QRCode
24
26
import net.glxn.qrgen.core.scheme.Wifi
25
27
26
28
private const val TAG = " MainActivity"
27
- private const val DEFAULT_QR_GENERATION_RESOLUTION = " 300"
28
- private const val QR_CODE_DIALOG_BOTTOM_IMAGE_MARGIN = 0
29
29
const val PERMISSION_CODE_GROUP_ADS = 0
30
30
31
+ internal const val QR_CODE_DIALOG_BOTTOM_IMAGE_MARGIN = 0
32
+
31
33
class MainActivity : AppCompatActivity () {
32
34
// This variable holds an ArrayList of WifiEntry objects that each contain a saved wifi SSID and
33
35
// password. It is updated whenever focus returns to the app (onResume).
34
36
private lateinit var wifiEntries: ArrayList <WifiEntry >
35
37
private val wifiEntrySSIDs = ArrayList <String >()
36
38
private lateinit var loadWifiEntriesInBackgroundTask: LoadWifiEntriesInBackground
37
- private lateinit var prefs: SharedPreferences
38
-
39
39
private lateinit var qrDialog: AlertDialog
40
+
40
41
override fun onCreate (savedInstanceState : Bundle ? ) {
41
42
PreferenceManager .setDefaultValues(this , R .xml.preferences, false )
42
- prefs = PreferenceManager .getDefaultSharedPreferences(this )
43
+ val prefs = PreferenceManager .getDefaultSharedPreferences(this )
43
44
44
45
setThemeFromSharedPrefs(prefs)
45
46
super .onCreate(savedInstanceState)
@@ -61,7 +62,7 @@ class MainActivity: AppCompatActivity() {
61
62
qrCodeView.setImageBitmap(QRCode
62
63
.from(Wifi ()
63
64
.withSsid(wifiEntrySSIDs[position])
64
- .withPsk(wifiEntries[position].getPassword( true ) )
65
+ .withPsk(wifiEntries[position].password )
65
66
.withAuthentication(wifiEntries[position].type.asQRCodeAuth()))
66
67
.withColor((if (AppCompatDelegate .getDefaultNightMode() != AppCompatDelegate .MODE_NIGHT_YES ) 0xFF000000 else 0xFFE0E0E0 ).toInt(), 0x00000000 ) // TODO Better colour handling - atm, the colours may be wrong if the theme is set to system or auto.
67
68
.withSize(prefs.getString(" qr_code_resolution" , DEFAULT_QR_GENERATION_RESOLUTION ).toInt(), prefs.getString(" qr_code_resolution" , DEFAULT_QR_GENERATION_RESOLUTION ).toInt())
@@ -78,14 +79,14 @@ class MainActivity: AppCompatActivity() {
78
79
builder.setMessage(if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
79
80
Html .fromHtml(
80
81
" <b>SSID</b>: ${wifiEntries[position].title} <br>" +
81
- (if (wifiEntries[position].getPassword( true ) != " " ) " <b>Password</b>: ${if (wifiEntries[position].type != WifiEntry .Type .WEP ) wifiEntries[position].getPassword( true ) else wifiEntries[position].getPassword( true ) .removePrefix(" \" " ).removeSuffix(" \" " )} <br>" else { " " }) +
82
+ (if (wifiEntries[position].password != " " ) " <b>Password</b>: ${if (wifiEntries[position].type != WifiEntry .Type .WEP ) wifiEntries[position].password else wifiEntries[position].password .removePrefix(" \" " ).removeSuffix(" \" " )} <br>" else { " " }) +
82
83
" <b>Type</b>: ${wifiEntries[position].type} " ,
83
84
Html .FROM_HTML_MODE_LEGACY )
84
85
} else {
85
86
@Suppress(" DEPRECATION" )
86
87
Html .fromHtml(
87
88
" <b>SSID</b>: ${wifiEntries[position].title} <br>" +
88
- (if (wifiEntries[position].getPassword( true ) != " " ) " <b>Password</b>: ${if (wifiEntries[position].type != WifiEntry .Type .WEP ) wifiEntries[position].getPassword( true ) else wifiEntries[position].getPassword( true ) .removePrefix(" \" " ).removeSuffix(" \" " )} <br>" else { " " }) +
89
+ (if (wifiEntries[position].password != " " ) " <b>Password</b>: ${if (wifiEntries[position].type != WifiEntry .Type .WEP ) wifiEntries[position].password else wifiEntries[position].password .removePrefix(" \" " ).removeSuffix(" \" " )} <br>" else { " " }) +
89
90
" <b>Type</b>: ${wifiEntries[position].type} "
90
91
)
91
92
}
@@ -126,14 +127,14 @@ class MainActivity: AppCompatActivity() {
126
127
private lateinit var errorDialog: AlertDialog
127
128
private lateinit var loadingDialog: AlertDialog
128
129
129
- private inner class LoadWifiEntriesInBackground : AsyncTask <Unit , Unit , Unit >() {
130
+ private inner class LoadWifiEntriesInBackground : AsyncTask <Unit , Unit , Unit >() {
130
131
override fun onPreExecute () {
131
132
val loadingDialogBuilder = AlertDialog .Builder (this @MainActivity)
132
133
loadingDialogBuilder.setCancelable(false )
133
134
loadingDialogBuilder.setMessage(R .string.wifi_loading_message)
134
135
loadingDialogBuilder.setView(ProgressBar (this @MainActivity))
135
136
loadingDialog = loadingDialogBuilder.create()
136
- loadingDialog.show()
137
+ runOnUiThread { loadingDialog.show() }
137
138
}
138
139
139
140
override fun doInBackground (vararg params : Unit? ) {
@@ -194,7 +195,7 @@ class MainActivity: AppCompatActivity() {
194
195
override fun onOptionsItemSelected (item : MenuItem ? ): Boolean {
195
196
return when (item!! .itemId) {
196
197
R .id.settingsItem -> {
197
- startActivity(Intent (this , SettingsActivity ::class .java))
198
+ startActivity(Intent (this , SettingsActivity ::class .java).putExtra( " xposed " , false ) )
198
199
true
199
200
}
200
201
else -> super .onOptionsItemSelected(item)
0 commit comments