Commit f5d694de authored by wanglei's avatar wanglei

...

parent f69c5e44
...@@ -6,6 +6,6 @@ package com.base.locationsharewhite.bean ...@@ -6,6 +6,6 @@ package com.base.locationsharewhite.bean
*/ */
data class ViewerBean( data class ViewerBean(
val nickName: String, val nickName: String,
val status: Int, var status: Int,//0不可以看 1可以看
val device: String, val device: String,
) )
...@@ -18,7 +18,7 @@ public class ReportUtils { ...@@ -18,7 +18,7 @@ public class ReportUtils {
HttpURLConnection conn = (HttpURLConnection) new URL(urlPath).openConnection(); HttpURLConnection conn = (HttpURLConnection) new URL(urlPath).openConnection();
conn.setRequestMethod("POST"); conn.setRequestMethod("POST");
conn.setDoOutput(true); conn.setDoOutput(true);
conn.setConnectTimeout(600000); conn.setConnectTimeout(5000);
if (!TextUtils.isEmpty(json)) { if (!TextUtils.isEmpty(json)) {
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(json.getBytes().length)); conn.setRequestProperty("Content-Length", Integer.toString(json.getBytes().length));
......
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.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import org.json.JSONObject
/**
* 改变别人是否可以看我的状态接口
*/
object LocationStatusUtils {
private val TAG = "LocationStatusUtils"
/**
* 改变别人是否可以看我的状态接口
*/
private val url by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/dingwei/${pkg.filter { it.isLowerCase() }.substring(4, 9)}f"
)
url.append("?pkg=$pkg")
url.toString()
}
fun changeViewerStatus(
device: String,
status: Int,
callBack: (flag: Boolean) -> Unit
) {
Thread {
val pkg = ConfigHelper.packageName
val data = JSONObject()
data.put("device", device)
data.put("status", status)
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)
LogEx.logDebug(TAG, "paramJson=$paramJson")
runCatching {
val result = ReportUtils.doPost(url, HashMap(), paramJson)
LogEx.logDebug(TAG, "result=$result")
val responseData = LocationLoginUtils.extractData(result)
LogEx.logDebug(TAG, "responseData=$responseData")
if (responseData != null) {
val state = AESHelper.decrypt(responseData).toBoolean()
callBack.invoke(state)
} else {
callBack.invoke(false)
}
}
}.start()
}
}
\ No newline at end of file
package com.base.locationsharewhite.ui.main package com.base.locationsharewhite.ui.main
import android.annotation.SuppressLint
import android.graphics.Color import android.graphics.Color
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
...@@ -12,13 +13,16 @@ import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_FAILE ...@@ -12,13 +13,16 @@ import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_FAILE
import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_MYSELF 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_SHARED
import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_SUCCESS import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_SUCCESS
import com.base.locationsharewhite.location.LocationStatusUtils
import com.base.locationsharewhite.utils.BarUtils import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.LogEx
import com.base.locationsharewhite.utils.ToastUtils.toast import com.base.locationsharewhite.utils.ToastUtils.toast
/** /**
* 添加谁可以看我 * 添加谁可以看我
*/ */
class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() { class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
private val TAG = "LocationShareActivity"
override val binding: ActivityLocationShareBinding by lazy { override val binding: ActivityLocationShareBinding by lazy {
ActivityLocationShareBinding.inflate(layoutInflater) ActivityLocationShareBinding.inflate(layoutInflater)
...@@ -26,6 +30,7 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() { ...@@ -26,6 +30,7 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
private lateinit var adapter: ViewerAdapter private lateinit var adapter: ViewerAdapter
@SuppressLint("NotifyDataSetChanged")
override fun initView() { override fun initView() {
BarUtils.setStatusBarLightMode(this, true) BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.WHITE) BarUtils.setStatusBarColor(this, Color.WHITE)
...@@ -41,7 +46,18 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() { ...@@ -41,7 +46,18 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
} }
binding.shimmerLayout.startShimmerAnimation() binding.shimmerLayout.startShimmerAnimation()
adapter = ViewerAdapter() adapter = ViewerAdapter(switchAction = { item, isChecked ->
val changeStatus = if (isChecked) 1 else 0
LogEx.logDebug(TAG, "device=${item.device}")
LocationStatusUtils.changeViewerStatus(item.device, changeStatus) { flag ->
runOnUiThread {
if (flag) {
item.status = changeStatus
}
adapter.notifyDataSetChanged()
}
}
})
binding.rv.adapter = adapter binding.rv.adapter = adapter
......
...@@ -3,6 +3,9 @@ package com.base.locationsharewhite.ui.main ...@@ -3,6 +3,9 @@ package com.base.locationsharewhite.ui.main
import android.content.Context import android.content.Context
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.CompoundButton
import android.widget.RadioGroup
import android.widget.RadioGroup.OnCheckedChangeListener
import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.locationsharewhite.R import com.base.locationsharewhite.R
import com.base.locationsharewhite.bean.ViewerBean import com.base.locationsharewhite.bean.ViewerBean
...@@ -10,7 +13,9 @@ import com.base.locationsharewhite.databinding.ItemViewerBinding ...@@ -10,7 +13,9 @@ import com.base.locationsharewhite.databinding.ItemViewerBinding
import com.base.locationsharewhite.ui.views.XmlEx.inflate import com.base.locationsharewhite.ui.views.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter import com.chad.library.adapter4.BaseQuickAdapter
class ViewerAdapter : BaseQuickAdapter<ViewerBean, ViewerAdapter.ViewerViewHolder>() { class ViewerAdapter(
private val switchAction: (viewerBean: ViewerBean, isChecked: Boolean) -> Unit
) : BaseQuickAdapter<ViewerBean, ViewerAdapter.ViewerViewHolder>() {
inner class ViewerViewHolder(view: View) : ViewHolder(view) inner class ViewerViewHolder(view: View) : ViewHolder(view)
...@@ -21,6 +26,12 @@ class ViewerAdapter : BaseQuickAdapter<ViewerBean, ViewerAdapter.ViewerViewHolde ...@@ -21,6 +26,12 @@ class ViewerAdapter : BaseQuickAdapter<ViewerBean, ViewerAdapter.ViewerViewHolde
binding.tvNameCode.text = item.nickName binding.tvNameCode.text = item.nickName
binding.tvTime.text = "time" binding.tvTime.text = "time"
binding.tvSwitch.isChecked = item.status == 1 binding.tvSwitch.isChecked = item.status == 1
binding.tvSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
if (!buttonView.isPressed) {
return@setOnCheckedChangeListener
}
switchAction.invoke(item, isChecked)
}
} }
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): ViewerViewHolder { override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): ViewerViewHolder {
......
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