19
19
import android .view .LayoutInflater ;
20
20
import android .view .View ;
21
21
import android .view .ViewGroup ;
22
- import android .widget .ImageView ;
23
- import android .widget .TextView ;
24
22
25
23
import androidx .annotation .NonNull ;
26
24
import androidx .annotation .Nullable ;
30
28
import com .pranavpandey .android .dynamic .support .model .DynamicPermission ;
31
29
import com .pranavpandey .android .dynamic .support .permission .DynamicPermissions ;
32
30
import com .pranavpandey .android .dynamic .support .permission .view .DynamicPermissionsView ;
31
+ import com .pranavpandey .android .dynamic .support .utils .DynamicResourceUtils ;
32
+ import com .pranavpandey .android .dynamic .support .view .DynamicInfoView ;
33
+ import com .pranavpandey .android .dynamic .support .widget .DynamicImageView ;
34
+ import com .pranavpandey .android .dynamic .theme .Theme ;
35
+ import com .pranavpandey .android .dynamic .utils .DynamicSdkUtils ;
33
36
34
37
import java .util .ArrayList ;
35
38
36
- import static android .view .View .GONE ;
37
-
38
39
/**
39
40
* A {@link RecyclerView.Adapter} to show the {@link DynamicPermissions}.
40
41
*/
@@ -51,6 +52,12 @@ public class DynamicPermissionsAdapter extends
51
52
*/
52
53
private DynamicPermissionsView .PermissionListener mPermissionListener ;
53
54
55
+ /**
56
+ * Constructor to initialize an object of this class.
57
+ *
58
+ * @param dataSet The data set for this adapter.
59
+ * @param permissionListener The listener to receiver the permission events.
60
+ */
54
61
public DynamicPermissionsAdapter (@ NonNull ArrayList <DynamicPermission > dataSet ,
55
62
@ Nullable DynamicPermissionsView .PermissionListener permissionListener ) {
56
63
mPermissions = dataSet ;
@@ -62,68 +69,62 @@ public DynamicPermissionsAdapter(@NonNull ArrayList<DynamicPermission> dataSet,
62
69
@ Override
63
70
public @ NonNull ViewHolder onCreateViewHolder (@ NonNull ViewGroup viewGroup , int viewType ) {
64
71
return new ViewHolder (LayoutInflater .from (viewGroup .getContext ())
65
- .inflate (R .layout .ads_layout_info , viewGroup , false ));
72
+ .inflate (R .layout .ads_layout_info_view_card , viewGroup , false ));
66
73
}
67
74
68
75
@ Override
69
76
public void onBindViewHolder (@ NonNull final ViewHolder viewHolder , final int position ) {
70
77
if (mPermissionListener != null ) {
71
- viewHolder .getLayout ().setOnClickListener (new View .OnClickListener () {
78
+ viewHolder .getRoot ().setOnClickListener (new View .OnClickListener () {
72
79
@ Override
73
80
public void onClick (View v ) {
74
81
mPermissionListener .onPermissionSelected (v , position , getItem (position ));
75
82
}
76
83
});
77
84
} else {
78
- viewHolder .getLayout ().setClickable (false );
85
+ viewHolder .getRoot ().setClickable (false );
79
86
}
80
87
81
88
DynamicPermission dynamicPermission = getItem (position );
82
89
83
- if (dynamicPermission .getIcon () != null ) {
84
- viewHolder .getIcon ().setImageDrawable (dynamicPermission .getIcon ());
85
- viewHolder .getIcon ().setVisibility (View .VISIBLE );
86
- } else {
87
- viewHolder .getIcon ().setVisibility (GONE );
88
- }
89
-
90
- if (dynamicPermission .getTitle () != null ) {
91
- viewHolder .getTitle ().setText (dynamicPermission .getTitle ());
92
- viewHolder .getTitle ().setVisibility (View .VISIBLE );
93
- } else {
94
- viewHolder .getTitle ().setVisibility (GONE );
95
- }
96
-
97
- if (dynamicPermission .getSubtitle () != null ) {
98
- viewHolder .getSubtitle ().setText (dynamicPermission .getSubtitle ());
99
- viewHolder .getSubtitle ().setVisibility (View .VISIBLE );
100
- } else {
101
- viewHolder .getSubtitle ().setVisibility (GONE );
102
- }
103
-
104
- if (dynamicPermission .getDescription () != null ) {
105
- viewHolder .getDescription ().setText (dynamicPermission .getDescription ());
106
- viewHolder .getDescription ().setVisibility (View .VISIBLE );
107
- } else {
108
- viewHolder .getDescription ().setVisibility (GONE );
109
- }
90
+ viewHolder .getInfoView ().setIconBig (dynamicPermission .getIcon ());
91
+ viewHolder .getInfoView ().setTitle (dynamicPermission .getTitle ());
92
+ viewHolder .getInfoView ().setSubtitle (dynamicPermission .getSubtitle ());
93
+ viewHolder .getInfoView ().setDescription (dynamicPermission .getDescription ());
110
94
111
95
if (dynamicPermission .isAllowed ()) {
112
- viewHolder .getStatusIcon ().setImageResource (R .drawable .ads_ic_check );
113
- viewHolder .getInfo ().setText (R .string .ads_perm_granted_desc );
114
- viewHolder .getStatus ().setText (R .string .ads_perm_granted );
115
- viewHolder .getLayout ().setClickable (false );
96
+ viewHolder .getInfoView ().setIcon (DynamicResourceUtils .getDrawable (
97
+ viewHolder .getInfoView ().getContext (), R .drawable .ads_ic_check ));
98
+ viewHolder .getInfoView ().setDescription (viewHolder .getInfoView ()
99
+ .getContext ().getString (R .string .ads_perm_granted_desc ));
100
+ viewHolder .getInfoView ().setStatus (viewHolder .getInfoView ()
101
+ .getContext ().getString (R .string .ads_perm_granted ));
102
+ viewHolder .getRoot ().setClickable (false );
116
103
} else {
117
- viewHolder .getStatusIcon ().setImageResource (R .drawable .ads_ic_close );
118
- viewHolder .getInfo ().setText (R .string .ads_perm_request_desc );
119
- viewHolder .getStatus ().setText (R .string .ads_perm_request );
104
+ viewHolder .getInfoView ().setIcon (DynamicResourceUtils .getDrawable (
105
+ viewHolder .getInfoView ().getContext (), R .drawable .ads_ic_close ));
106
+ viewHolder .getInfoView ().setDescription (viewHolder .getInfoView ()
107
+ .getContext ().getString (R .string .ads_perm_request_desc ));
108
+ viewHolder .getInfoView ().setStatus (viewHolder .getInfoView ()
109
+ .getContext ().getString (R .string .ads_perm_request ));
120
110
121
111
if (!dynamicPermission .isAskAgain ()) {
122
- viewHolder .getStatusIcon ().setImageResource (R .drawable .ads_ic_error );
123
- viewHolder .getInfo ().setText (R .string .ads_perm_denied_desc );
124
- viewHolder .getStatus ().setText (R .string .ads_perm_denied );
112
+ viewHolder .getInfoView ().setIcon (DynamicResourceUtils .getDrawable (
113
+ viewHolder .getInfoView ().getContext (), R .drawable .ads_ic_error ));
114
+
115
+ if (DynamicSdkUtils .is23 ()) {
116
+ viewHolder .getInfoView ().setDescription (viewHolder .getInfoView ()
117
+ .getContext ().getString (R .string .ads_perm_denied_desc ));
118
+ viewHolder .getInfoView ().setStatus (viewHolder .getInfoView ()
119
+ .getContext ().getString (R .string .ads_perm_denied ));
120
+ } else {
121
+ viewHolder .getInfoView ().setDescription (viewHolder .getInfoView ()
122
+ .getContext ().getString (R .string .ads_perm_reinstall_desc ));
123
+ viewHolder .getInfoView ().setStatus (viewHolder .getInfoView ()
124
+ .getContext ().getString (R .string .ads_perm_reinstall ));
125
+ }
125
126
}
126
- viewHolder .getLayout ().setClickable (true );
127
+ viewHolder .getRoot ().setClickable (true );
127
128
}
128
129
}
129
130
@@ -149,138 +150,54 @@ public DynamicPermission getItem(int position) {
149
150
}
150
151
151
152
/**
152
- * View holder to hold the permission layout .
153
+ * View holder to hold the permission root .
153
154
*/
154
155
static class ViewHolder extends RecyclerView .ViewHolder {
155
156
156
157
/**
157
- * Layout used by this view holder.
158
- */
159
- private final ViewGroup layout ;
160
-
161
- /**
162
- * Image view to show the permission status icon.
163
- */
164
- private final ImageView statusIcon ;
165
-
166
- /**
167
- * Image view to show the permission icon.
168
- */
169
- private final ImageView icon ;
170
-
171
- /**
172
- * Text view to show the permission title.
173
- */
174
- private final TextView title ;
175
-
176
- /**
177
- * Text view to show the permission subtitle.
178
- */
179
- private final TextView subtitle ;
180
-
181
- /**
182
- * Text view to show the permission info.
183
- */
184
- private final TextView info ;
185
-
186
- /**
187
- * Text view to show the permission description.
158
+ * Root view used by this view holder.
188
159
*/
189
- private final TextView description ;
160
+ private final ViewGroup root ;
190
161
191
162
/**
192
- * Text view to show the permission status .
163
+ * Dynamic info view used by this view holder .
193
164
*/
194
- private final TextView status ;
165
+ private final DynamicInfoView dynamicInfo ;
195
166
196
167
/**
197
- * Constructor to initialize views from the supplied layout .
168
+ * Constructor to initialize views from the supplied root .
198
169
*
199
170
* @param view The view for this view holder.
200
171
*/
201
172
ViewHolder (@ NonNull View view ) {
202
173
super (view );
203
174
204
- layout = view .findViewById (R .id .ads_info_layout );
205
- icon = view .findViewById (R .id .ads_info_icon_big );
206
- statusIcon = view .findViewById (R .id .ads_info_icon );
207
- title = view .findViewById (R .id .ads_info_title );
208
- subtitle = view .findViewById (R .id .ads_info_subtitle );
209
- info = view .findViewById (R .id .ads_info_status_description );
210
- description = view .findViewById (R .id .ads_info_description );
211
- status = view .findViewById (R .id .ads_info_status );
212
- }
213
-
214
- /**
215
- * Get the layout used by this view holder.
216
- *
217
- * @return The layout used by this view holder.
218
- */
219
- ViewGroup getLayout () {
220
- return layout ;
221
- }
222
-
223
- /**
224
- * Get the image view to show the permission status icon.
225
- *
226
- * @return The image view to show the permission status icon.
227
- */
228
- ImageView getStatusIcon () {
229
- return statusIcon ;
230
- }
231
-
232
- /**
233
- * Get the image view to show the permission icon.
234
- *
235
- * @return The image view to show the permission icon.
236
- */
237
- ImageView getIcon () {
238
- return icon ;
239
- }
240
-
241
- /**
242
- * Get the text view to show the permission title.
243
- *
244
- * @return The text view to show the permission title.
245
- */
246
- TextView getTitle () {
247
- return title ;
248
- }
249
-
250
- /**
251
- * Get the text view to show the permission subtitle.
252
- *
253
- * @return The text view to show the permission subtitle.
254
- */
255
- TextView getSubtitle () {
256
- return subtitle ;
257
- }
175
+ root = view .findViewById (R .id .ads_info_view_card );
176
+ dynamicInfo = view .findViewById (R .id .ads_dynamic_info_view );
258
177
259
- /**
260
- * Get the text view to show the permission info.
261
- *
262
- * @return The text view to show the permission info.
263
- */
264
- TextView getInfo () {
265
- return info ;
178
+ dynamicInfo .getSubtitleView ().setAllCaps (true );
179
+ if (dynamicInfo .getIconView () instanceof DynamicImageView ) {
180
+ ((DynamicImageView ) dynamicInfo .getIconView ())
181
+ .setColorType (Theme .ColorType .PRIMARY );
182
+ }
266
183
}
267
184
268
185
/**
269
- * Get the text view to show the permission description .
186
+ * Get the root view used by this view holder .
270
187
*
271
- * @return The text view to show the permission description .
188
+ * @return The root view used by this view holder .
272
189
*/
273
- TextView getDescription () {
274
- return description ;
190
+ ViewGroup getRoot () {
191
+ return root ;
275
192
}
276
193
277
194
/**
278
- * Get the text view to show the permission status .
195
+ * Get the dynamic info view used by this view holder .
279
196
*
280
- * @return The text view to show the permission status .
197
+ * @return The dynamic info view used by this view holder .
281
198
*/
282
- TextView getStatus () {
283
- return status ;
199
+ DynamicInfoView getInfoView () {
200
+ return dynamicInfo ;
284
201
}
285
202
}
286
203
}
0 commit comments