1
1
package com.kitlink.fragment
2
2
3
+ import android.Manifest
3
4
import android.content.Context
5
+ import android.content.pm.PackageManager
4
6
import android.os.Bundle
5
7
import android.view.LayoutInflater
6
8
import android.view.View
7
9
import android.view.ViewGroup
8
10
import android.widget.*
11
+ import androidx.core.content.ContextCompat
9
12
import com.kitlink.App
10
13
import com.kitlink.R
14
+ import com.kitlink.activity.BaseActivity
15
+ import com.kitlink.activity.DeviceCategoryActivity
11
16
import com.kitlink.activity.SmartConnectActivity
12
17
import com.kitlink.activity.SoftApActivity
13
18
import com.kitlink.entity.CategoryDeviceEntity
@@ -31,9 +36,19 @@ class DeviceFragment(c: Context) : BaseFragment(), MyCallback, AdapterView.OnIte
31
36
32
37
private var mContext : Context = c
33
38
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
+ )
37
52
38
53
override fun getPresenter (): IPresenter ? {
39
54
return null
@@ -109,19 +124,51 @@ class DeviceFragment(c: Context) : BaseFragment(), MyCallback, AdapterView.OnIte
109
124
110
125
override fun onItemClick (parent : AdapterView <* >? , view : View ? , position : Int , id : Long ) {
111
126
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
+ }
117
138
}
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
+ }
120
150
}
121
151
}
122
152
}
123
153
}
124
154
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
+
125
172
fun setListener () {
126
173
devicesGridView?.onItemClickListener = this
127
174
recommendDevicesGridView?.onItemClickListener = this
0 commit comments