1919package com .vrem .wifianalyzer .wifi .channelavailable ;
2020
2121import android .content .Context ;
22+ import android .content .res .Resources ;
2223import android .text .TextUtils ;
2324import android .view .LayoutInflater ;
2425import android .view .View ;
2829
2930import com .vrem .wifianalyzer .MainContext ;
3031import com .vrem .wifianalyzer .R ;
32+ import com .vrem .wifianalyzer .databinding .ChannelAvailableDetailsBinding ;
3133import com .vrem .wifianalyzer .wifi .band .WiFiBand ;
3234import com .vrem .wifianalyzer .wifi .band .WiFiChannelCountry ;
3335
@@ -46,30 +48,89 @@ class ChannelAvailableAdapter extends ArrayAdapter<WiFiChannelCountry> {
4648
4749 @ NonNull
4850 @ Override
49- public View getView (int position , @ Nullable View convertView , @ NonNull ViewGroup parent ) {
50- MainContext mainContext = MainContext .INSTANCE ;
51- View view = convertView ;
52- if (view == null ) {
53- LayoutInflater layoutInflater = mainContext .getLayoutInflater ();
54- view = layoutInflater .inflate (R .layout .channel_available_details , parent , false );
55- }
56-
57- Locale currentLocale = mainContext .getSettings ().getLanguageLocale ();
51+ public View getView (int position , @ Nullable View view , @ NonNull ViewGroup parent ) {
52+ Binding binding = view == null ? new Binding (create (parent )) : new Binding (view );
53+ View rootView = binding .getRoot ();
54+ Resources resources = rootView .getResources ();
5855
56+ Locale currentLocale = MainContext .INSTANCE .getSettings ().getLanguageLocale ();
5957 WiFiChannelCountry wiFiChannelCountry = getItem (position );
60- view .< TextView > findViewById ( R . id . channel_available_country )
58+ binding . getChannelAvailableCountry ( )
6159 .setText (wiFiChannelCountry .getCountryCode () + " - " + wiFiChannelCountry .getCountryName (currentLocale ));
62- view .< TextView > findViewById ( R . id . channel_available_title_ghz_2 )
60+ binding . getChannelAvailableTitleGhz2 ( )
6361 .setText (String .format (Locale .ENGLISH , "%s : " ,
64- view . getResources () .getString (WiFiBand .GHZ2 .getTextResource ())));
65- view .< TextView > findViewById ( R . id . channel_available_ghz_2 )
62+ resources .getString (WiFiBand .GHZ2 .getTextResource ())));
63+ binding . getChannelAvailableGhz2 ( )
6664 .setText (TextUtils .join (SEPARATOR , wiFiChannelCountry .getChannelsGHZ2 ().toArray ()));
67- view .< TextView > findViewById ( R . id . channel_available_title_ghz_5 )
65+ binding . getChannelAvailableTitleGhz5 ( )
6866 .setText (String .format (Locale .ENGLISH , "%s : " ,
69- view . getResources () .getString (WiFiBand .GHZ5 .getTextResource ())));
70- view .< TextView > findViewById ( R . id . channel_available_ghz_5 )
67+ resources .getString (WiFiBand .GHZ5 .getTextResource ())));
68+ binding . getChannelAvailableGhz5 ( )
7169 .setText (TextUtils .join (SEPARATOR , wiFiChannelCountry .getChannelsGHZ5 ().toArray ()));
72- return view ;
70+ return rootView ;
71+ }
72+
73+ private ChannelAvailableDetailsBinding create (@ NonNull ViewGroup parent ) {
74+ LayoutInflater layoutInflater = MainContext .INSTANCE .getLayoutInflater ();
75+ return ChannelAvailableDetailsBinding .inflate (layoutInflater , parent , false );
76+ }
77+
78+
79+ private class Binding {
80+ private final View root ;
81+ private final TextView channelAvailableCountry ;
82+ private final TextView channelAvailableTitleGhz2 ;
83+ private final TextView channelAvailableGhz2 ;
84+ private final TextView channelAvailableTitleGhz5 ;
85+ private final TextView channelAvailableGhz5 ;
86+
87+ Binding (@ NonNull ChannelAvailableDetailsBinding binding ) {
88+ root = binding .getRoot ();
89+ channelAvailableCountry = binding .channelAvailableCountry ;
90+ channelAvailableTitleGhz2 = binding .channelAvailableTitleGhz2 ;
91+ channelAvailableGhz2 = binding .channelAvailableGhz2 ;
92+ channelAvailableTitleGhz5 = binding .channelAvailableTitleGhz5 ;
93+ channelAvailableGhz5 = binding .channelAvailableGhz5 ;
94+ }
95+
96+ Binding (@ NonNull View view ) {
97+ root = view ;
98+ channelAvailableCountry = view .findViewById (R .id .channel_available_country );
99+ channelAvailableTitleGhz2 = view .findViewById (R .id .channel_available_title_ghz_2 );
100+ channelAvailableGhz2 = view .findViewById (R .id .channel_available_ghz_2 );
101+ channelAvailableTitleGhz5 = view .findViewById (R .id .channel_available_title_ghz_5 );
102+ channelAvailableGhz5 = view .findViewById (R .id .channel_available_ghz_5 );
103+ }
104+
105+ @ NonNull
106+ View getRoot () {
107+ return root ;
108+ }
109+
110+ @ NonNull
111+ TextView getChannelAvailableCountry () {
112+ return channelAvailableCountry ;
113+ }
114+
115+ @ NonNull
116+ TextView getChannelAvailableTitleGhz2 () {
117+ return channelAvailableTitleGhz2 ;
118+ }
119+
120+ @ NonNull
121+ TextView getChannelAvailableGhz2 () {
122+ return channelAvailableGhz2 ;
123+ }
124+
125+ @ NonNull
126+ TextView getChannelAvailableTitleGhz5 () {
127+ return channelAvailableTitleGhz5 ;
128+ }
129+
130+ @ NonNull
131+ TextView getChannelAvailableGhz5 () {
132+ return channelAvailableGhz5 ;
133+ }
73134 }
74135
75136}
0 commit comments