Commit c4077fee authored by wanglei's avatar wanglei

...

parent 2999b426
package com.base.locationsharewhite.bean
/**
* 谁可以看我,可更改对我的可见状态
*/
data class Viewer(
val nickName: String,
val status: Int,
val device: String,
)
package com.base.locationsharewhite.bean
/**
* 我可以看谁,自身无法切换状态
*/
data class ViewingBean(
val nickname: String,
val status: Int = -1,
val locatDate: LocationDate? = null,
)
data class LocationDate(
val longitude: Double,
val latitude: Double,
val power: Double,
)
\ No newline at end of file
......@@ -9,6 +9,9 @@ import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import org.json.JSONObject
/**
* 登录
*/
object LocationLoginUtils {
var invitationCodeSp = ""
......@@ -28,7 +31,7 @@ object LocationLoginUtils {
AppPreferences.getInstance().put("nickNameSp", value, true)
}
private val TAG = "LocationRequestUtils"
private val TAG = "LocationLoginUtils"
private const val DATA_KEY = "data"
private val url by lazy {
......@@ -79,7 +82,7 @@ object LocationLoginUtils {
}
private fun extractData(response: String): String? {
fun extractData(response: String): String? {
val regex = Regex("\"$DATA_KEY\":\"(.*?)\"")
val match = regex.find(response)
return match?.groupValues?.get(1)
......
......@@ -10,6 +10,9 @@ import com.base.locationsharewhite.utils.LogEx
import com.google.android.gms.maps.model.LatLng
import org.json.JSONObject
/**
* 上报自身位置
*/
object LocationPositionUtils {
private val TAG = "LocationPositionUtils"
......
package com.base.locationsharewhite.location
import android.os.Build
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.bean.Viewer
import com.base.locationsharewhite.bean.ViewingBean
import com.base.locationsharewhite.helper.AESHelper
import com.base.locationsharewhite.helper.ConfigHelper
import com.base.locationsharewhite.helper.ReportUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import org.json.JSONObject
/**
* 获取分享关系列表
*/
object LocationShareListUtils {
private val TAG = "LocationListUtils"
/**
* 分享关系列表
*/
private val url by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/dingwei/${pkg.filter { it.isLowerCase() }.substring(4, 9)}ac"
)
url.append("?pkg=$pkg")
url.toString()
}
fun getShareList(
viewerListCallBack: ((viewerList: List<Viewer>) -> Unit)? = null,
viewingListCallBack: ((viewingList: List<ViewingBean>) -> Unit)? = null
) {
Thread {
val pkg = ConfigHelper.packageName
val data = JSONObject()
val bp = JSONObject()
// .put("${pkg}_1", "")
.put("${pkg}_5", Build.VERSION.SDK_INT)
.put("${pkg}_8", BuildConfig.VERSION_NAME)
.put("${pkg}_9", AppPreferences.getInstance().getString("uuid", ""))
.put("${pkg}_10", AppPreferences.getInstance().getString("uuid", ""))//gid
.put("${pkg}_13", "android")
.put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_15", "google")
.put("${pkg}_24", BuildConfig.BUILD_TYPE)
val body = JSONObject()
.put("data", data)
.put("bp", bp)
.toString()
val paramJson = AESHelper.encrypt(body)
val result = ReportUtils.doPost(url, HashMap(), paramJson)
val responseData = LocationLoginUtils.extractData(result)
if (responseData != null) {
val decryptedData = AESHelper.decrypt(responseData)
parseShareListData(decryptedData, viewerListCallBack, viewingListCallBack)
}
}.start()
}
private fun parseShareListData(
decryptedData: String,
viewerListCallBack: ((viewerList: List<Viewer>) -> Unit)? = null,
viewingListCallBack: ((viewingList: List<ViewingBean>) -> Unit)? = null
) {
val jsonObject = JSONObject(decryptedData)
val viewerListJson = jsonObject.getJSONArray("viewerList").toString()
LogEx.logDebug(TAG, "viewerListJson=$viewerListJson")
val viewingListJson = jsonObject.getJSONArray("viewingList").toString()
LogEx.logDebug(TAG, "viewingListJson=$viewingListJson")
}
}
\ No newline at end of file
package com.base.locationsharewhite.location
import android.os.Build
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.helper.AESHelper
import com.base.locationsharewhite.helper.ConfigHelper
import com.base.locationsharewhite.helper.ReportUtils
import com.base.locationsharewhite.location.LocationLoginUtils.extractData
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import org.json.JSONObject
/**
* 通过邀请码建立分享关系
*/
object LocationShareUtils {
private val TAG = "ShareLocationUtils"
const val SHARE_STATE_FAILED = 0
const val SHARE_STATE_SUCCESS = 1
const val SHARE_STATE_SHARED = 2
const val SHARE_STATE_MYSELF = 3
/**
* 分享位置接口
*/
private val url by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/dingwei/${pkg.filter { it.isLowerCase() }.substring(4, 9)}m"
)
url.append("?pkg=$pkg")
url.toString()
}
fun shareMyLocationByInvitationCode(
invitationCode: String,
callBack: (state: Int) -> Unit
) {
Thread {
val pkg = ConfigHelper.packageName
val data = JSONObject()
data.put("invitationCode", invitationCode)
LogEx.logDebug(TAG, "invitationCode=${invitationCode}")
val bp = JSONObject()
// .put("${pkg}_1", "")
.put("${pkg}_5", Build.VERSION.SDK_INT)
.put("${pkg}_8", BuildConfig.VERSION_NAME)
.put("${pkg}_9", AppPreferences.getInstance().getString("uuid", ""))
.put("${pkg}_10", AppPreferences.getInstance().getString("uuid", ""))//gid
.put("${pkg}_13", "android")
.put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_15", "google")
.put("${pkg}_24", BuildConfig.BUILD_TYPE)
LogEx.logDebug(TAG, "uuid=${AppPreferences.getInstance().getString("uuid", "")}")
val body = JSONObject()
.put("data", data)
.put("bp", bp)
.toString()
val paramJson = AESHelper.encrypt(body)
val result = ReportUtils.doPost(url, HashMap(), paramJson)
val responseData = extractData(result)
if (responseData != null) {
val state = AESHelper.decrypt(responseData).toInt()
callBack.invoke(state)
} else {
callBack.invoke(0)
}
}.start()
}
}
\ No newline at end of file
......@@ -3,9 +3,14 @@ package com.base.locationsharewhite.ui.main
import android.graphics.Color
import androidx.activity.addCallback
import androidx.core.view.updatePadding
import com.base.locationsharewhite.R
import com.base.locationsharewhite.databinding.ActivityLocationCodeBinding
import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.location.LocationLoginUtils
import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.ClipboardUtils.copyText
import com.base.locationsharewhite.utils.ToastUtils.toast
class LocationCodeActivity : BaseActivity<ActivityLocationCodeBinding>() {
......@@ -18,6 +23,12 @@ class LocationCodeActivity : BaseActivity<ActivityLocationCodeBinding>() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.WHITE)
binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
binding.tvCode.text = LocationLoginUtils.invitationCodeSp
binding.tvCopy.setOnClickListener {
copyText("MyLocationCode", binding.tvCode.text.toString())
toast(resources.getString(R.string.copy))
}
}
override fun initListener() {
......
......@@ -3,14 +3,20 @@ package com.base.locationsharewhite.ui.main
import android.graphics.Color
import androidx.activity.addCallback
import androidx.core.view.updatePadding
import com.base.locationsharewhite.R
import com.base.locationsharewhite.databinding.ActivityLocationShareBinding
import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.location.LocationLoginUtils
import com.base.locationsharewhite.location.LocationShareListUtils
import com.base.locationsharewhite.location.LocationShareUtils
import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_FAILED
import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_MYSELF
import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_SHARED
import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_SUCCESS
import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.ClipboardUtils.copyText
import com.base.locationsharewhite.utils.ToastUtils.toast
/**
* 添加谁可以看我
*/
class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
override val binding: ActivityLocationShareBinding by lazy {
......@@ -23,13 +29,10 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
BarUtils.setStatusBarColor(this, Color.WHITE)
binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
binding.tvCode.text = LocationLoginUtils.invitationCodeSp
binding.ivCopy.setOnClickListener {
copyText("MyLocationCode", binding.tvCode.text.toString())
toast(resources.getString(R.string.copy))
}
initShareData()
}
override fun initListener() {
super.initListener()
onBackPressedDispatcher.addCallback {
......@@ -38,6 +41,41 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
binding.flFanhui.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.tvShare.setOnClickListener {
val code = binding.editCode.text.toString()
if (code.length >= 8) {
LocationShareUtils.shareMyLocationByInvitationCode(code) { status ->
runOnUiThread {
when (status) {
SHARE_STATE_FAILED -> {
toast("Code verification failed")
}
SHARE_STATE_SUCCESS -> {
toast("Code verification success")
}
SHARE_STATE_SHARED -> {
toast("Sharing code has been added")
}
SHARE_STATE_MYSELF -> {
toast("Sharing code is yourself code")
}
}
}
}
} else {
toast("code verification failed")
}
}
}
private fun initShareData() {
LocationShareListUtils.getShareList(viewerListCallBack = {
})
}
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#3C93E2" />
<size android:width="1dp" />
</shape>
\ No newline at end of file
......@@ -69,6 +69,7 @@
android:background="@drawable/bg_stroke_dash_03b988_15">
<TextView
android:id="@+id/tv_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
......@@ -78,6 +79,7 @@
tools:text="AZEQFOU2" />
<ImageView
android:id="@+id/tv_copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
......
......@@ -28,7 +28,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_location_code"
android:text="@string/share_location_code"
android:textColor="#001725"
android:textSize="22sp"
android:textStyle="bold"
......@@ -68,18 +68,20 @@
android:layout_marginTop="30dp"
android:background="@drawable/bg_stroke_dash_03b988_15">
<TextView
android:id="@+id/tv_code"
<EditText
android:id="@+id/edit_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="40dp"
android:layout_marginHorizontal="80dp"
android:background="@null"
android:gravity="center"
android:hint="@string/enter_others_location_code"
android:maxLength="8"
android:maxLines="2"
android:textColor="#3C93E2"
android:textColorHint="#98C3F0"
android:textCursorDrawable="@drawable/bg_cursor_3c93e2"
android:textSize="26sp"
android:textStyle="bold"
tools:ignore="Autofill,TextFields" />
......@@ -96,6 +98,7 @@
<TextView
android:id="@+id/tv_share"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginHorizontal="16dp"
......
......@@ -2,7 +2,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fl"
android:layout_width="185dp"
android:layout_width="160dp"
android:layout_height="76dp"
android:layout_margin="6dp"
android:background="@drawable/bg_language_selector">
......
......@@ -4,6 +4,7 @@
<string name="friend_location_map">Friend Location Map</string>
<string name="view_friend_locations_on_the_map">View friend locations on the map</string>
<string name="my_location_code">My Location code</string>
<string name="share_location_code">Share My Location</string>
<string name="share_my_location">Share my location</string>
<string name="how_to_use">How to use?</string>
<string name="settings">Settings</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment