2525import java .util .HashSet ;
2626import java .util .List ;
2727import java .util .Set ;
28+ import java .util .Objects ;
2829
2930public class OnboardingFragment2 extends Fragment {
3031
@@ -78,26 +79,22 @@ public ServerItemViewHolder onCreateViewHolder(final @NonNull ViewGroup parent,
7879
7980 final ServerItemViewHolder holder = new ServerItemViewHolder (view );
8081
81- holder .itemView .setOnClickListener (v -> {
82- tempUrl .setValue (holder .urlTextView .getText ().toString ());
83- });
82+ holder .itemView .setOnClickListener (v -> tempUrl .setValue (holder .urlTextView .getText ().toString ()));
8483
8584 holder .itemView .setOnLongClickListener (v -> {
8685 removeServer (holder .urlTextView .getText ().toString ());
8786 return true ;
8887 });
8988
90- tempUrl .observe (requireActivity (), url -> {
91- ((MaterialCardView ) holder .itemView ).setChecked (holder .urlTextView .getText ().toString ().equals (url ));
92- });
89+ tempUrl .observe (requireActivity (), url -> ((MaterialCardView ) holder .itemView ).setChecked (holder .urlTextView .getText ().toString ().equals (url )));
9390
9491 return holder ;
9592 }
9693
9794 @ Override
9895 public void onBindViewHolder (final @ NonNull ServerItemViewHolder holder , final int position ) {
9996 holder .bind (items .get (position ));
100- ((MaterialCardView ) holder .itemView ).setChecked (holder .urlTextView .getText ().toString (). equals ( tempUrl .getValue ()));
97+ ((MaterialCardView ) holder .itemView ).setChecked (Objects . equals ( holder .urlTextView .getText ().toString (), tempUrl .getValue ()));
10198 }
10299
103100 @ Override
@@ -124,7 +121,8 @@ public void onViewCreated(final @NonNull View view, final Bundle savedInstanceSt
124121 pref = PreferenceManager .getDefaultSharedPreferences (requireContext ());
125122 tempUrl .setValue (pref .getString (getString (R .string .pref_baseurl ), "https://drop.erikraft.com/" ));
126123
127- if (tempUrl .getValue ().equals ("https://snapdrop.net" ) || tempUrl .getValue ().equals ("https://pairdrop.net" )) {
124+ final String currentTempUrl = tempUrl .getValue ();
125+ if (Objects .equals (currentTempUrl , "https://snapdrop.net" ) || Objects .equals (currentTempUrl , "https://pairdrop.net" )) {
128126 tempUrl .setValue ("https://drop.erikraft.com/" );
129127
130128 binding .scrollview .setVisibility (View .INVISIBLE );
@@ -143,45 +141,51 @@ public void onViewCreated(final @NonNull View view, final Bundle savedInstanceSt
143141
144142 reloadServerList ();
145143
146- binding .add .setOnClickListener (v -> ViewUtils .showEditTextWithResetPossibility (this , "Custom URL" , null , null , Link .bind ("https://github.com/RobinLinus/snapdrop/blob/master/docs/faq.md#inofficial-instances" , R .string .baseurl_unofficial_instances ), url -> {
147- if (url == null ) {
148- return ;
149- }
150-
151- if (url .startsWith ("!!" )) { // hidden feature to force a different url
152- newServer (url .substring ("!!" .length ()));
153- } else if (url .startsWith ("http" )) {
154- NetworkUtils .checkInstance (this , url , result -> {
155- if (result ) {
156- newServer (url );
144+ binding .add .setOnClickListener (v -> {
145+ ViewUtils .showEditTextWithResetPossibility (OnboardingFragment2 .this ,
146+ "Custom URL" ,
147+ null ,
148+ null ,
149+ Link .bind ("https://github.com/RobinLinus/snapdrop/blob/master/docs/faq.md#inofficial-instances" , R .string .baseurl_unofficial_instances ),
150+ url -> {
151+ if (url == null ) {
152+ return ;
153+ }
154+
155+ if (url .startsWith ("!!" )) { // hidden feature to force a different url
156+ newServer (url .substring ("!!" .length ()));
157+ } else if (url .startsWith ("http" )) {
158+ NetworkUtils .checkInstance (OnboardingFragment2 .this , url , result -> {
159+ if (Boolean .TRUE .equals (result )) {
160+ newServer (url );
161+ }
162+ });
163+ } else {
164+ // do some magic in case user forgot to specify the protocol
165+ String mightBeHttpsUrl = "https://" + url ;
166+ NetworkUtils .checkInstance (OnboardingFragment2 .this , mightBeHttpsUrl , resultHttps -> {
167+ if (Boolean .TRUE .equals (resultHttps )) {
168+ newServer (mightBeHttpsUrl );
169+ } else {
170+ String mightBeHttpUrl = "http://" + url ;
171+ NetworkUtils .checkInstance (OnboardingFragment2 .this , mightBeHttpUrl , resultHttp -> {
172+ if (Boolean .TRUE .equals (resultHttp )) {
173+ newServer (mightBeHttpUrl );
174+ }
175+ });
176+ }
177+ });
178+ }
157179 }
158- });
159- } else {
160-
161- // do some magic in case user forgot to specify the protocol
162-
163- String mightBeHttpsUrl = "https://" + url ;
164- NetworkUtils .checkInstance (this , mightBeHttpsUrl , resultHttps -> {
165- if (resultHttps ) {
166- newServer (mightBeHttpsUrl );
167- } else {
168- String mightBeHttpUrl = "http://" + url ;
169- NetworkUtils .checkInstance (this , mightBeHttpUrl , resultHttp -> {
170- if (resultHttp ) {
171- newServer (mightBeHttpUrl );
172- }
173- });
174- }
175- });
176- }
177- }));
180+ );
181+ });
178182
179183 binding .continueButton .setOnClickListener (v -> {
180184 viewModel .url (tempUrl .getValue ());
181185 if (viewModel .isOnlyServerSelection ()) {
182186 requireActivity ().finish ();
183187 } else {
184- viewModel .launchFragment (OnboardingFragment3 . class );
188+ viewModel .launchFragment (new OnboardingFragment3 () );
185189 }
186190 });
187191 binding .continueButton .requestFocus ();
@@ -191,8 +195,8 @@ private void reloadServerList() {
191195 final Set <String > serverUrls = pref .getStringSet (getString (R .string .pref_custom_servers ), new HashSet <>());
192196
193197 final List <ServerItem > servers = new ArrayList <>();
194- servers .add (new ServerItem ("https://drop.erikraft.com/" , getString (R .string .onboarding_server_pairdrop_summary ), null ));
195- servers .add (new ServerItem ("https://pairdrop.net" , getString (R .string .onboarding_server_pairdrop_summary ), null ));
198+ servers .add (new ServerItem ("https://drop.erikraft.com/" ,getString (R .string .onboarding_server_pairdrop_summary ), null ));
199+ servers .add (new ServerItem ("https://pairdrop.net" , getString (R .string .onboarding_server_snapdrop_summary ), null ));
196200
197201 for (String url : serverUrls ) {
198202 servers .add (new ServerItem (url , null , null ));
0 commit comments