3434import com .vrem .util .BuildUtils ;
3535import com .vrem .wifianalyzer .MainContext ;
3636import com .vrem .wifianalyzer .R ;
37+ import com .vrem .wifianalyzer .databinding .ChannelRatingDetailsBinding ;
3738import com .vrem .wifianalyzer .settings .Settings ;
3839import com .vrem .wifianalyzer .wifi .band .WiFiBand ;
3940import com .vrem .wifianalyzer .wifi .band .WiFiChannel ;
@@ -96,32 +97,28 @@ private List<WiFiChannel> setWiFiChannels(WiFiBand wiFiBand) {
9697
9798 @ NonNull
9899 @ Override
99- public View getView (int position , @ Nullable View convertView , @ NonNull ViewGroup parent ) {
100- View view = convertView ;
101- if (view == null ) {
102- LayoutInflater layoutInflater = MainContext .INSTANCE .getLayoutInflater ();
103- view = layoutInflater .inflate (R .layout .channel_rating_details , parent , false );
104- }
105-
100+ public View getView (int position , @ Nullable View view , @ NonNull ViewGroup parent ) {
101+ Binding binding = view == null ? new Binding (create (parent )) : new Binding (view );
106102 WiFiChannel wiFiChannel = getItem (position );
107- if (wiFiChannel == null ) {
108- return view ;
103+ if (wiFiChannel != null ) {
104+ binding .getChannelNumber ()
105+ .setText (String .format (Locale .ENGLISH , "%d" , wiFiChannel .getChannel ()));
106+ binding .getAccessPointCount ()
107+ .setText (String .format (Locale .ENGLISH , "%d" , channelRating .getCount (wiFiChannel )));
108+ RatingBar ratingBar = binding .getChannelRating ();
109+ ratingBar (wiFiChannel , ratingBar );
109110 }
111+ return binding .getRoot ();
112+ }
110113
111- view .<TextView >findViewById (R .id .channelNumber )
112- .setText (String .format (Locale .ENGLISH , "%d" , wiFiChannel .getChannel ()));
113- view .<TextView >findViewById (R .id .accessPointCount )
114- .setText (String .format (Locale .ENGLISH , "%d" , channelRating .getCount (wiFiChannel )));
114+ private void ratingBar (WiFiChannel wiFiChannel , RatingBar ratingBar ) {
115115 Strength strength = Strength .reverse (channelRating .getStrength (wiFiChannel ));
116- RatingBar ratingBar = view .findViewById (R .id .channelRating );
117116 int size = Strength .values ().length ;
118117 ratingBar .setMax (size );
119118 ratingBar .setNumStars (size );
120119 ratingBar .setRating (strength .ordinal () + 1 );
121120 int color = ContextCompat .getColor (getContext (), strength .colorResource ());
122121 setRatingBarColor (ratingBar , color );
123-
124- return view ;
125122 }
126123
127124 private void setRatingBarColor (RatingBar ratingBar , int color ) {
@@ -132,7 +129,6 @@ private void setRatingBarColor(RatingBar ratingBar, int color) {
132129 }
133130 }
134131
135- @ SuppressWarnings ("deprecation" )
136132 private void setRatingBarColorLegacy (Drawable drawable , int color ) {
137133 try {
138134 int background = ContextCompat .getColor (getContext (), R .color .background );
@@ -176,4 +172,50 @@ void bestChannels(@NonNull WiFiBand wiFiBand, @NonNull List<WiFiChannel> wiFiCha
176172 }
177173 }
178174
175+ private ChannelRatingDetailsBinding create (@ NonNull ViewGroup parent ) {
176+ LayoutInflater layoutInflater = MainContext .INSTANCE .getLayoutInflater ();
177+ return ChannelRatingDetailsBinding .inflate (layoutInflater , parent , false );
178+ }
179+
180+ private class Binding {
181+ private final View root ;
182+ private final TextView channelNumber ;
183+ private final TextView accessPointCount ;
184+ private final RatingBar channelRating ;
185+
186+ Binding (@ NonNull ChannelRatingDetailsBinding binding ) {
187+ root = binding .getRoot ();
188+ channelNumber = binding .channelNumber ;
189+ accessPointCount = binding .accessPointCount ;
190+ channelRating = binding .channelRating ;
191+ }
192+
193+ Binding (@ NonNull View view ) {
194+ root = view ;
195+ channelNumber = view .findViewById (R .id .channelNumber );
196+ accessPointCount = view .findViewById (R .id .accessPointCount );
197+ channelRating = view .findViewById (R .id .channelRating );
198+ }
199+
200+ @ NonNull
201+ View getRoot () {
202+ return root ;
203+ }
204+
205+ @ NonNull
206+ TextView getChannelNumber () {
207+ return channelNumber ;
208+ }
209+
210+ @ NonNull
211+ TextView getAccessPointCount () {
212+ return accessPointCount ;
213+ }
214+
215+ @ NonNull
216+ RatingBar getChannelRating () {
217+ return channelRating ;
218+ }
219+ }
220+
179221}
0 commit comments