Skip to content

Commit bb65b24

Browse files
support API 33; minimum API 23;
1 parent d710b47 commit bb65b24

File tree

81 files changed

+566
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+566
-313
lines changed

app/build.gradle

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ dependencies {
2727
// Compile Build Dependencies
2828
implementation fileTree(include: ["*.jar"], dir: "libs")
2929
implementation 'com.google.android.material:material:1.6.1'
30-
implementation 'androidx.annotation:annotation:1.4.0'
31-
implementation 'androidx.appcompat:appcompat:1.4.2'
30+
implementation 'androidx.annotation:annotation:1.5.0'
31+
implementation 'androidx.appcompat:appcompat:1.5.1'
3232
implementation 'androidx.collection:collection-ktx:1.2.0'
33-
implementation 'androidx.core:core-ktx:1.8.0'
34-
implementation 'androidx.core:core-splashscreen:1.0.0-rc01'
33+
implementation 'androidx.core:core-ktx:1.9.0'
34+
implementation 'androidx.core:core-splashscreen:1.0.0'
3535
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
36+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
3637
implementation 'androidx.media:media:1.6.0'
3738
implementation 'androidx.preference:preference-ktx:1.2.0'
3839
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -41,10 +42,10 @@ dependencies {
4142
testImplementation 'androidx.test.ext:junit:1.1.3'
4243
testImplementation 'com.googlecode.junit-toolbox:junit-toolbox:2.4'
4344
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
44-
testImplementation 'io.mockk:mockk:1.12.4'
45+
testImplementation 'io.mockk:mockk:1.13.1'
4546
testImplementation 'junit:junit:4.13.2'
46-
testImplementation 'org.mockito:mockito-core:4.6.1'
47-
testImplementation 'org.robolectric:robolectric:4.8.1'
47+
testImplementation 'org.mockito:mockito-core:4.8.0'
48+
testImplementation 'org.robolectric:robolectric:4.9-alpha-1'
4849
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
4950
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
5051
// Android Test Dependencies
@@ -54,7 +55,7 @@ dependencies {
5455

5556
android {
5657
namespace 'com.vrem.wifianalyzer'
57-
compileSdkVersion 31
58+
compileSdkVersion 33
5859
buildToolsVersion '33.0.0'
5960

6061
sourceSets.each {
@@ -63,8 +64,8 @@ android {
6364

6465
defaultConfig {
6566
applicationId "com.vrem.wifianalyzer"
66-
minSdkVersion 21
67-
targetSdkVersion 31
67+
minSdkVersion 23
68+
targetSdkVersion 33
6869
versionCode
6970
versionName
7071
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

app/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Build Properties
2-
#Sat Jun 25 08:43:59 EDT 2022
2+
#Tue Sep 27 10:54:09 EDT 2022
33
version_minor=0
44
version_store=61
55
version_patch=9
6-
version_build=0
6+
version_build=1
77
version_major=3

app/src/main/kotlin/com/vrem/util/BuildUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ package com.vrem.util
2020

2121
import android.os.Build
2222

23+
fun buildMinVersionT(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
24+
25+
fun buildMinVersionS(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
26+
2327
fun buildMinVersionR(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
2428

2529
fun buildMinVersionQ(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
@@ -29,5 +33,3 @@ fun buildMinVersionP(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
2933
fun buildVersionP(): Boolean = Build.VERSION.SDK_INT == Build.VERSION_CODES.P
3034

3135
fun buildMinVersionN(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
32-
33-
fun buildMinVersionM(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M

app/src/main/kotlin/com/vrem/util/CompatUtils.kt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package com.vrem.util
1919

2020
import android.annotation.TargetApi
2121
import android.content.Context
22+
import android.content.pm.PackageInfo
23+
import android.content.pm.PackageManager.PackageInfoFlags
2224
import android.content.res.Configuration
2325
import android.content.res.Resources
26+
import android.net.wifi.ScanResult
2427
import android.os.Build
25-
import androidx.annotation.ColorInt
26-
import androidx.annotation.ColorRes
27-
import androidx.core.content.ContextCompat
2828
import java.util.*
2929

3030
fun Context.createContext(newLocale: Locale): Context =
@@ -51,10 +51,32 @@ private fun Context.createContextLegacy(newLocale: Locale): Context {
5151
return this
5252
}
5353

54-
@ColorInt
55-
fun Context.compatColor(@ColorRes id: Int): Int =
56-
if (buildMinVersionM()) {
57-
getColor(id)
54+
fun Context.packageInfo(): PackageInfo =
55+
if (buildMinVersionT()) {
56+
packageInfoAndroidT()
5857
} else {
59-
ContextCompat.getColor(this, id)
58+
packageInfoLegacy()
6059
}
60+
61+
@TargetApi(Build.VERSION_CODES.TIRAMISU)
62+
private fun Context.packageInfoAndroidT(): PackageInfo =
63+
packageManager.getPackageInfo(packageName, PackageInfoFlags.of(0))
64+
65+
@Suppress("DEPRECATION")
66+
private fun Context.packageInfoLegacy(): PackageInfo =
67+
packageManager.getPackageInfo(packageName, 0)
68+
69+
fun ScanResult.ssid(): String =
70+
if (buildMinVersionT()) {
71+
ssidAndroidT()
72+
} else {
73+
ssidLegacy()
74+
}
75+
76+
@TargetApi(Build.VERSION_CODES.TIRAMISU)
77+
private fun ScanResult.ssidAndroidT(): String =
78+
wifiSsid?.toString() ?: String.EMPTY
79+
80+
@Suppress("DEPRECATION")
81+
private fun ScanResult.ssidLegacy(): String =
82+
if (SSID == null) String.EMPTY else SSID
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2015 - 2022 VREM Software Development <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
19+
package com.vrem.wifianalyzer
20+
21+
import androidx.activity.OnBackPressedCallback
22+
23+
class MainActivityBackPressed(val mainActivity: MainActivity) : OnBackPressedCallback(true) {
24+
override fun handleOnBackPressed() {
25+
if (!mainActivity.closeDrawer()) {
26+
val selectedMenu = MainContext.INSTANCE.settings.selectedMenu()
27+
if (selectedMenu == mainActivity.currentNavigationMenu()) {
28+
mainActivity.finish()
29+
} else {
30+
mainActivity.currentNavigationMenu(selectedMenu)
31+
mainActivity.onNavigationItemSelected(mainActivity.currentMenuItem())
32+
}
33+
}
34+
}
35+
}

app/src/main/kotlin/com/vrem/wifianalyzer/MainActivity.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class MainActivity : AppCompatActivity(), NavigationMenuControl, OnSharedPrefere
8989
connectionView = ConnectionView(this)
9090

9191
permissionService = PermissionService(this)
92+
93+
onBackPressedDispatcher.addCallback(this, MainActivityBackPressed(this))
9294
}
9395

9496
public override fun onPostCreate(savedInstanceState: Bundle?) {
@@ -142,26 +144,14 @@ class MainActivity : AppCompatActivity(), NavigationMenuControl, OnSharedPrefere
142144
updateActionBar()
143145
}
144146

145-
override fun onBackPressed() {
146-
if (!closeDrawer()) {
147-
val selectedMenu = MainContext.INSTANCE.settings.selectedMenu()
148-
if (selectedMenu == currentNavigationMenu()) {
149-
super.onBackPressed()
150-
} else {
151-
currentNavigationMenu(selectedMenu)
152-
onNavigationItemSelected(currentMenuItem())
153-
}
154-
}
155-
}
156-
157147
override fun onNavigationItemSelected(menuItem: MenuItem): Boolean {
158148
closeDrawer()
159149
val currentNavigationMenu = findOne(NavigationMenu.values(), menuItem.itemId, NavigationMenu.ACCESS_POINTS)
160150
currentNavigationMenu.activateNavigationMenu(this, menuItem)
161151
return true
162152
}
163153

164-
private fun closeDrawer(): Boolean {
154+
fun closeDrawer(): Boolean {
165155
val drawer = findViewById<DrawerLayout>(R.id.drawer_layout)
166156
if (drawer.isDrawerOpen(GravityCompat.START)) {
167157
drawer.closeDrawer(GravityCompat.START)

app/src/main/kotlin/com/vrem/wifianalyzer/about/AboutFragment.kt

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import androidx.core.content.pm.PackageInfoCompat
3535
import androidx.fragment.app.Fragment
3636
import androidx.fragment.app.FragmentActivity
3737
import com.vrem.util.EMPTY
38+
import com.vrem.util.packageInfo
3839
import com.vrem.util.readFile
3940
import com.vrem.wifianalyzer.MainContext
4041
import com.vrem.wifianalyzer.R
@@ -44,7 +45,7 @@ import java.util.*
4445

4546
class AboutFragment : Fragment() {
4647

47-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
48+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
4849
val binding: AboutContentBinding = AboutContentBinding.inflate(inflater, container, false)
4950
val activity: FragmentActivity = requireActivity()
5051
setTexts(binding, activity)
@@ -61,12 +62,20 @@ class AboutFragment : Fragment() {
6162
}
6263

6364
private fun device(): String =
64-
Build.MANUFACTURER + " - " + Build.BRAND + " - " + Build.MODEL
65+
Build.MANUFACTURER + " - " + Build.BRAND + " - " + Build.MODEL
6566

6667
private fun wiFiState(binding: AboutContentBinding) {
6768
val wiFiManagerWrapper = MainContext.INSTANCE.wiFiManagerWrapper
68-
wiFiBand(wiFiManagerWrapper.is5GHzBandSupported(), binding.aboutWifiBand5ghzSuccess, binding.aboutWifiBand5ghzFails)
69-
wiFiBand(wiFiManagerWrapper.is6GHzBandSupported(), binding.aboutWifiBand6ghzSuccess, binding.aboutWifiBand6ghzFails)
69+
wiFiBand(
70+
wiFiManagerWrapper.is5GHzBandSupported(),
71+
binding.aboutWifiBand5ghzSuccess,
72+
binding.aboutWifiBand5ghzFails
73+
)
74+
wiFiBand(
75+
wiFiManagerWrapper.is6GHzBandSupported(),
76+
binding.aboutWifiBand6ghzSuccess,
77+
binding.aboutWifiBand6ghzFails
78+
)
7079
}
7180

7281
private fun wiFiBand(bandSupported: Boolean, aboutWifiBandSuccess: TextView, aboutWifiBandFails: TextView) {
@@ -82,7 +91,8 @@ class AboutFragment : Fragment() {
8291
private fun setOnClicks(binding: AboutContentBinding, activity: FragmentActivity) {
8392
val gpl = AlertDialogClickListener(activity, R.string.gpl, R.raw.gpl)
8493
binding.license.setOnClickListener(gpl)
85-
val contributors = AlertDialogClickListener(activity, R.string.about_contributor_title, R.raw.contributors, false)
94+
val contributors =
95+
AlertDialogClickListener(activity, R.string.about_contributor_title, R.raw.contributors, false)
8696
binding.contributors.setOnClickListener(contributors)
8797
val al = AlertDialogClickListener(activity, R.string.al, R.raw.al)
8898
binding.graphViewLicense.setOnClickListener(al)
@@ -91,7 +101,7 @@ class AboutFragment : Fragment() {
91101
}
92102

93103
private fun copyright(): String =
94-
resources.getString(R.string.app_copyright) + SimpleDateFormat(YEAR_FORMAT, Locale.getDefault()).format(Date())
104+
resources.getString(R.string.app_copyright) + SimpleDateFormat(YEAR_FORMAT, Locale.getDefault()).format(Date())
95105

96106
private fun version(activity: FragmentActivity): String {
97107
val configuration = MainContext.INSTANCE.configuration
@@ -102,12 +112,13 @@ class AboutFragment : Fragment() {
102112
}
103113

104114
private fun applicationVersion(activity: FragmentActivity): String =
105-
try {
106-
val packageInfo: PackageInfo = activity.packageManager.getPackageInfo(activity.packageName, 0)
107-
packageInfo.versionName + " - " + PackageInfoCompat.getLongVersionCode(packageInfo)
108-
} catch (e: NameNotFoundException) {
109-
String.EMPTY
110-
}
115+
try {
116+
val packageInfo: PackageInfo = activity.packageInfo()
117+
packageInfo.versionName + " - " + PackageInfoCompat.getLongVersionCode(packageInfo)
118+
} catch (e: NameNotFoundException) {
119+
String.EMPTY
120+
}
121+
111122

112123
private class WriteReviewClickListener(private val activity: Activity) : View.OnClickListener {
113124
override fun onClick(view: View) {
@@ -119,21 +130,22 @@ class AboutFragment : Fragment() {
119130
Toast.makeText(view.context, e.localizedMessage, Toast.LENGTH_LONG).show()
120131
}
121132
}
122-
123133
}
124134

125-
private class AlertDialogClickListener(private val activity: Activity,
126-
private val titleId: Int,
127-
private val resourceId: Int,
128-
private val isSmallFont: Boolean = true) : View.OnClickListener {
135+
private class AlertDialogClickListener(
136+
private val activity: Activity,
137+
private val titleId: Int,
138+
private val resourceId: Int,
139+
private val isSmallFont: Boolean = true
140+
) : View.OnClickListener {
129141
override fun onClick(view: View) {
130142
if (!activity.isFinishing) {
131143
val text = readFile(activity.resources, resourceId)
132144
val alertDialog: AlertDialog = AlertDialog.Builder(view.context)
133-
.setTitle(titleId)
134-
.setMessage(text)
135-
.setNeutralButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() }
136-
.create()
145+
.setTitle(titleId)
146+
.setMessage(text)
147+
.setNeutralButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() }
148+
.create()
137149
alertDialog.show()
138150
if (isSmallFont) {
139151
alertDialog.findViewById<TextView>(android.R.id.message).textSize = 8f
@@ -143,11 +155,11 @@ class AboutFragment : Fragment() {
143155
}
144156

145157
private fun ifElse(condition: Boolean, value: String) =
146-
if (condition) {
147-
value
148-
} else {
149-
String.EMPTY
150-
}
158+
if (condition) {
159+
value
160+
} else {
161+
String.EMPTY
162+
}
151163

152164

153165
companion object {

app/src/main/kotlin/com/vrem/wifianalyzer/navigation/availability/Filter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package com.vrem.wifianalyzer.navigation.availability
1919

20-
import com.vrem.util.compatColor
20+
import androidx.core.content.ContextCompat
2121
import com.vrem.wifianalyzer.MainContext
2222
import com.vrem.wifianalyzer.R
2323

@@ -30,6 +30,6 @@ internal val navigationOptionFilterOn: NavigationOption = {
3030
val color = if (MainContext.INSTANCE.filtersAdapter.isActive()) R.color.selected else R.color.regular
3131
val menuItem = menu.findItem(R.id.action_filter)
3232
menuItem.isVisible = true
33-
menuItem.icon.setTint(it.compatColor(color))
33+
menuItem.icon?.setTint(ContextCompat.getColor(it, color))
3434
}
3535
}

app/src/main/kotlin/com/vrem/wifianalyzer/permission/ApplicationPermission.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
package com.vrem.wifianalyzer.permission
1919

2020
import android.Manifest
21-
import android.annotation.TargetApi
2221
import android.app.Activity
2322
import android.content.pm.PackageManager
24-
import android.os.Build
2523
import com.vrem.annotation.OpenClass
26-
import com.vrem.util.buildMinVersionM
2724

2825
@OpenClass
29-
class ApplicationPermission(private val activity: Activity, private val permissionDialog: PermissionDialog = PermissionDialog(activity)) {
26+
class ApplicationPermission(
27+
private val activity: Activity,
28+
private val permissionDialog: PermissionDialog = PermissionDialog(activity)
29+
) {
3030
fun check() {
3131
if (granted()) {
3232
return
@@ -38,13 +38,10 @@ class ApplicationPermission(private val activity: Activity, private val permissi
3838
}
3939

4040
fun granted(requestCode: Int, grantResults: IntArray): Boolean =
41-
requestCode == REQUEST_CODE && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED
41+
requestCode == REQUEST_CODE && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED
4242

43-
fun granted(): Boolean = !buildMinVersionM() || grantedAndroidM()
44-
45-
@TargetApi(Build.VERSION_CODES.M)
46-
private fun grantedAndroidM(): Boolean =
47-
activity.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
43+
fun granted(): Boolean =
44+
activity.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
4845

4946
companion object {
5047
internal val PERMISSIONS = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)

0 commit comments

Comments
 (0)