Skip to content

Commit 9ca7a8e

Browse files
archurcodelarrytin
authored andcommitted
1 parent d2383a5 commit 9ca7a8e

File tree

2 files changed

+86
-11
lines changed

2 files changed

+86
-11
lines changed

tenextllapp/app/src/main/java/com/kitlink/activity/DeviceCategoryActivity.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.kitlink.activity
22

3+
import android.Manifest
34
import android.app.Activity
45
import android.content.Context
56
import android.content.Intent
@@ -29,6 +30,7 @@ import com.mvp.IPresenter
2930
import com.qrcode.Constant
3031
import com.qrcode.ScannerActivity
3132
import com.util.L
33+
import com.util.T
3234
import com.view.recyclerview.CRecyclerView
3335
import kotlinx.android.synthetic.main.activity_device_category.*
3436
import kotlinx.android.synthetic.main.menu_back_layout.*
@@ -41,6 +43,11 @@ import q.rorbin.verticaltablayout.widget.TabView
4143

4244

4345
class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerItemView, View.OnClickListener, VerticalTabLayout.OnTabSelectedListener{
46+
47+
private var permissions = arrayOf(
48+
Manifest.permission.CAMERA
49+
)
50+
4451
override fun getPresenter(): IPresenter? {
4552
return null
4653
}
@@ -102,6 +109,15 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI
102109
}
103110
}
104111
}
112+
RequestCode.scan_bind_device-> {
113+
if (response.isSuccess()) {
114+
T.show("添加成功")
115+
App.data.setRefreshLevel(2)
116+
finish()
117+
} else {
118+
T.show(response.msg)
119+
}
120+
}
105121
}
106122
}
107123

@@ -121,10 +137,22 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI
121137
return 0
122138
}
123139

140+
override fun permissionAllGranted() {
141+
startActivityForResult(Intent(this, ScannerActivity::class.java), 103)
142+
}
143+
144+
override fun permissionDenied(permission: String) {
145+
requestPermission(arrayOf(permission))
146+
}
147+
124148
override fun onClick(v: View?) {
125149
when (v) {
126150
iv_scann -> {
127-
startActivityForResult(Intent(this, ScannerActivity::class.java), 103)
151+
if (checkPermissions(permissions)) {
152+
startActivityForResult(Intent(this, ScannerActivity::class.java), 103)
153+
} else {
154+
requestPermission(permissions)
155+
}
128156
}
129157
iv_question -> {
130158
jumpActivity(HelpCenterActivity::class.java)

tenextllapp/app/src/main/java/com/kitlink/fragment/DeviceFragment.kt

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.kitlink.fragment
22

3+
import android.Manifest
34
import android.content.Context
5+
import android.content.pm.PackageManager
46
import android.os.Bundle
57
import android.view.LayoutInflater
68
import android.view.View
79
import android.view.ViewGroup
810
import android.widget.*
11+
import androidx.core.content.ContextCompat
912
import com.kitlink.App
1013
import com.kitlink.R
14+
import com.kitlink.activity.BaseActivity
15+
import com.kitlink.activity.DeviceCategoryActivity
1116
import com.kitlink.activity.SmartConnectActivity
1217
import com.kitlink.activity.SoftApActivity
1318
import com.kitlink.entity.CategoryDeviceEntity
@@ -31,9 +36,19 @@ class DeviceFragment(c: Context) : BaseFragment(), MyCallback, AdapterView.OnIte
3136

3237
private var mContext : Context = c
3338
private var devicesGridView : GridView? = null
34-
var recommendDevicesGridView : GridView? = null
35-
var categoryList = arrayListOf<CategoryDeviceEntity>()
36-
var productList = arrayListOf<RecommDeviceEntity>()
39+
private var recommendDevicesGridView : GridView? = null
40+
private var categoryList = arrayListOf<CategoryDeviceEntity>()
41+
private var productList = arrayListOf<RecommDeviceEntity>()
42+
private var isRecommDeviceClicked = false
43+
private var recommDeviceIndex = 0
44+
45+
46+
private var permissions = arrayOf(
47+
Manifest.permission.ACCESS_WIFI_STATE,
48+
Manifest.permission.CHANGE_WIFI_STATE,
49+
Manifest.permission.CHANGE_WIFI_MULTICAST_STATE,
50+
Manifest.permission.ACCESS_FINE_LOCATION
51+
)
3752

3853
override fun getPresenter(): IPresenter? {
3954
return null
@@ -109,19 +124,51 @@ class DeviceFragment(c: Context) : BaseFragment(), MyCallback, AdapterView.OnIte
109124

110125
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
111126
if (view != null && parent != null) {
112-
when (parent.id) {
113-
R.id.gv_recommend_devices->{
114-
val productsList = arrayListOf<String>()
115-
productsList.add(productList[position].ProductId)
116-
HttpRequest.instance.getProductsConfig(productsList, this)
127+
128+
if(ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)
129+
!= PackageManager.PERMISSION_GRANTED){
130+
when (parent.id) {
131+
R.id.gv_recommend_devices->{
132+
isRecommDeviceClicked = true
133+
recommDeviceIndex = position
134+
}
135+
R.id.gv_devices->{
136+
isRecommDeviceClicked = false
137+
}
117138
}
118-
R.id.gv_devices->{
119-
jumpActivity(SmartConnectActivity::class.java)
139+
requestPermissions(permissions,1)
140+
} else {
141+
when (parent.id) {
142+
R.id.gv_recommend_devices->{
143+
val productsList = arrayListOf<String>()
144+
productsList.add(productList[position].ProductId)
145+
HttpRequest.instance.getProductsConfig(productsList, this)
146+
}
147+
R.id.gv_devices->{
148+
jumpActivity(SmartConnectActivity::class.java)
149+
}
120150
}
121151
}
122152
}
123153
}
124154

155+
override fun onRequestPermissionsResult(
156+
requestCode: Int,
157+
permissions: Array<out String>,
158+
grantResults: IntArray
159+
) {
160+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
161+
if (requestCode == 1) {
162+
if (isRecommDeviceClicked) {
163+
val productsList = arrayListOf<String>()
164+
productsList.add(productList[recommDeviceIndex].ProductId)
165+
HttpRequest.instance.getProductsConfig(productsList, this)
166+
} else {
167+
jumpActivity(SmartConnectActivity::class.java)
168+
}
169+
}
170+
}
171+
125172
fun setListener() {
126173
devicesGridView?.onItemClickListener = this
127174
recommendDevicesGridView?.onItemClickListener = this

0 commit comments

Comments
 (0)