From 3a04cec66133cb043df3f254c20c1e2a4c447d3c Mon Sep 17 00:00:00 2001
From: cczhr <464591548@qq.com>
Date: Mon, 11 Apr 2022 14:50:35 +0800
Subject: [PATCH] 1.1.4
---
app/build.gradle | 5 +-
app/src/main/AndroidManifest.xml | 4 +-
.../com/cczhr/otglocation/BaseActivity.kt | 51 +++++++++++--------
.../com/cczhr/otglocation/MainActivity.kt | 40 +++++++++++++--
.../java/com/cczhr/otglocation/net/Api.kt | 2 +-
.../com/cczhr/otglocation/utils/FileUtils.kt | 18 +++----
.../otglocation/utils/IMobileDeviceTools.kt | 2 +-
app/src/main/res/layout/activity_main.xml | 40 ++++++++++++---
8 files changed, 116 insertions(+), 46 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 1d33d98..a22aac7 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -13,8 +13,8 @@ android {
applicationId "com.cczhr.otglocation"
minSdkVersion 24
targetSdkVersion 30
- versionCode 6
- versionName "1.1.3"
+ versionCode 7
+ versionName "1.1.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -66,4 +66,5 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'
+ implementation 'com.github.getActivity:XXPermissions:12.5'
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 93698d5..fb509be 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,9 +3,11 @@
package="com.cczhr.otglocation">
+
+
+
-
diff --git a/app/src/main/java/com/cczhr/otglocation/BaseActivity.kt b/app/src/main/java/com/cczhr/otglocation/BaseActivity.kt
index a846797..d92e617 100644
--- a/app/src/main/java/com/cczhr/otglocation/BaseActivity.kt
+++ b/app/src/main/java/com/cczhr/otglocation/BaseActivity.kt
@@ -16,7 +16,12 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
+import com.cczhr.otglocation.utils.Application
+import com.cczhr.otglocation.utils.CommonUtil
import com.google.android.material.floatingactionbutton.FloatingActionButton
+import com.hjq.permissions.OnPermissionCallback
+import com.hjq.permissions.Permission
+import com.hjq.permissions.XXPermissions
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
@@ -40,27 +45,31 @@ abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope()
init()
}
fun requestPermissions(result: (Boolean) -> Unit) {
- permissionsResult = result
- val permissions = arrayOf(
- Manifest.permission.READ_EXTERNAL_STORAGE,
- Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.READ_PHONE_STATE,
- Manifest.permission.ACCESS_COARSE_LOCATION,
- Manifest.permission.ACCESS_WIFI_STATE,
- Manifest.permission.ACCESS_NETWORK_STATE
- )
- var isGetAllPermissions = true
- for (p in permissions) {
- if (ContextCompat.checkSelfPermission(this, p) == PackageManager.PERMISSION_DENIED) {
- isGetAllPermissions = false
- break
- }
- }
- if (!isGetAllPermissions) {
- ActivityCompat.requestPermissions(this, permissions, 100)
- } else {
- permissionsResult.invoke(true)
- }
+ permissionsResult= result
+
+ XXPermissions.with(this) // 申请安装包权限
+ .permission(Permission.MANAGE_EXTERNAL_STORAGE)
+ .permission(Permission.ACCESS_FINE_LOCATION)
+ .permission(Permission.ACCESS_COARSE_LOCATION)
+ .permission(Permission.READ_PHONE_STATE)
+ .request(object : OnPermissionCallback {
+ override fun onGranted(permissions: List, all: Boolean) {
+ permissionsResult.invoke(true)
+ }
+
+ override fun onDenied(permissions: List, never: Boolean) {
+ permissionsResult.invoke(false)
+ if (never) {
+ CommonUtil.showToast(Application.context,"获取权限失败!请手动赋予权限")
+ // 如果是被永久拒绝就跳转到应用权限系统设置页面
+ XXPermissions.startPermissionActivity(this@BaseActivity, permissions)
+ } else {
+ CommonUtil.showToast(Application.context,"获取权限失败!请手动赋予权限")
+ // 如果是被永久拒绝就跳转到应用权限系统设置页面
+ XXPermissions.startPermissionActivity(this@BaseActivity, permissions)
+ }
+ }
+ })
}
diff --git a/app/src/main/java/com/cczhr/otglocation/MainActivity.kt b/app/src/main/java/com/cczhr/otglocation/MainActivity.kt
index 70368f3..e5d63d9 100644
--- a/app/src/main/java/com/cczhr/otglocation/MainActivity.kt
+++ b/app/src/main/java/com/cczhr/otglocation/MainActivity.kt
@@ -7,12 +7,20 @@ import android.content.Intent
import android.text.TextUtils
import android.util.Log
import android.view.View
+import android.widget.ArrayAdapter
import androidx.lifecycle.Observer
import com.amap.api.mapcore.util.it
+import com.amap.api.maps.CameraUpdateFactory
+import com.amap.api.maps.model.LatLng
+import com.cczhr.otglocation.database.AppDatabase
+import com.cczhr.otglocation.database.LocationData
import com.cczhr.otglocation.net.RetrofitManager
import com.cczhr.otglocation.utils.*
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_main.*
+import kotlinx.android.synthetic.main.activity_main.select_location
+import kotlinx.android.synthetic.main.activity_main.text_input_layout
+import kotlinx.android.synthetic.main.activity_map.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
@@ -30,9 +38,9 @@ class MainActivity : BaseActivity() {
var isRoot = false
var isConnected = false
var hasDeveloperImg = false
-
var progressDialog: ProgressDialog? = null
-
+ lateinit var locationAdapter: ArrayAdapter
+ val locationData = ArrayList()
@SuppressLint("SetTextI18n")
@@ -42,9 +50,33 @@ class MainActivity : BaseActivity() {
progressDialog?.dismiss()
}
- override fun init() {
+ private fun loadLocationData() {
+ launch {
+ locationData.clear()
+ locationAdapter.notifyDataSetChanged()
+ withContext(Dispatchers.IO) {
+ locationData.addAll(
+ AppDatabase.getDatabase(this@MainActivity).locationDataDao().getAll()
+ )
+ }
+ locationAdapter.notifyDataSetChanged()
+ }
+ }
+
+
+ override fun onResume() {
+ super.onResume()
+ loadLocationData()
+ }
+ override fun init() {
+ locationAdapter = ArrayAdapter(this, R.layout.popup_location_item, locationData)
+ select_location.setOnItemClickListener { _, _, position, _ ->
+ latitude.setText( locationData[position].lat)
+ longitude.setText( locationData[position].lon)
+ }
+ select_location.setAdapter(locationAdapter)
version?.text = "V ${Application.getVersion()}"
latitude.setText(Application.getLat())
longitude.setText(Application.getLon())
@@ -186,6 +218,7 @@ class MainActivity : BaseActivity() {
Application.saveLon(lon.toString())
libTools.modifyLocation(lat, lon) {
+ logAdd("定位修改成功")
CommonUtil.showToast(Application.context, "定位修改成功")
}
}
@@ -199,6 +232,7 @@ class MainActivity : BaseActivity() {
libTools.resetLocation {
CommonUtil.showToast(Application.context, "定位已还原")
+ logAdd("定位已还原")
}
}
diff --git a/app/src/main/java/com/cczhr/otglocation/net/Api.kt b/app/src/main/java/com/cczhr/otglocation/net/Api.kt
index 0ef8ea0..8fff69b 100644
--- a/app/src/main/java/com/cczhr/otglocation/net/Api.kt
+++ b/app/src/main/java/com/cczhr/otglocation/net/Api.kt
@@ -14,7 +14,7 @@ import retrofit2.http.Url
* @since 2021/6/10 10:06
*/
interface Api {
- @GET("repos/iGhibli/iOS-DeviceSupport/contents/DeviceSupport")
+ @GET("repos/filsv/iPhoneOSDeviceSupport/contents")
suspend fun getDeviceSupport(): DeviceSupportBean?
@Streaming
diff --git a/app/src/main/java/com/cczhr/otglocation/utils/FileUtils.kt b/app/src/main/java/com/cczhr/otglocation/utils/FileUtils.kt
index e29c25f..f27dc75 100644
--- a/app/src/main/java/com/cczhr/otglocation/utils/FileUtils.kt
+++ b/app/src/main/java/com/cczhr/otglocation/utils/FileUtils.kt
@@ -1,5 +1,6 @@
package com.cczhr.otglocation.utils
+import android.util.Log
import java.io.File
import java.io.FileFilter
@@ -10,20 +11,17 @@ import java.io.FileFilter
*/
class FileUtils {
companion object{
- fun findFile(dir: File,fileName:String):String{
- if (dir.isDirectory) {
- val files = dir.listFiles()
- for (file in files) {
- if(file.isDirectory)
- return findFile(file,fileName)
- else if(file.isFile&&file.name==fileName){
- return file.absolutePath
- }
+ fun findFile(dir: File,fileName:String):String {
+
+ val fileTreeWalk = dir.walk()
+ fileTreeWalk.iterator().forEach {
+ if (it.name == fileName && it.isFile) {
+ return it.absolutePath
}
+
}
return ""
}
-
/**
* Delete the all in directory.
*
diff --git a/app/src/main/java/com/cczhr/otglocation/utils/IMobileDeviceTools.kt b/app/src/main/java/com/cczhr/otglocation/utils/IMobileDeviceTools.kt
index f63d2e5..78999ef 100644
--- a/app/src/main/java/com/cczhr/otglocation/utils/IMobileDeviceTools.kt
+++ b/app/src/main/java/com/cczhr/otglocation/utils/IMobileDeviceTools.kt
@@ -145,7 +145,7 @@ class IMobileDeviceTools {
successResult = BufferedReader(InputStreamReader(process!!.inputStream))
errorResult = BufferedReader(InputStreamReader(process!!.errorStream))
os = DataOutputStream(process!!.outputStream)
- os?.write(".$saveFilePath/usbmuxd -v -f --pidfile NONE --usbfd $fd ".toByteArray())//--pidfile NONE --usbfd $fd --usbfd $fd
+ os?.write(".$saveFilePath/usbmuxd -v -f ".toByteArray())//--pidfile NONE --usbfd $fd --usbfd $fd
os?.writeBytes("\n")
os?.flush()
os?.close()
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 0811986..14e9640 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -121,6 +121,7 @@
android:text="@string/latitude" />
-
+
+
+
+
+
+
+
+
+