Skip to content

Commit

Permalink
extract to function
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky authored and alperozturk96 committed Sep 11, 2024
1 parent 8d07410 commit b0e1d9a
Showing 1 changed file with 48 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,55 +365,60 @@ protected void onCreate(Bundle savedInstanceState) {
if (TextUtils.isEmpty(getString(R.string.enforce_servers))) {
initAuthorizationPreFragment(savedInstanceState);
} else {
showAuthStatus();
accountSetupBinding.hostUrlFrame.setVisibility(View.GONE);
accountSetupBinding.hostUrlInputHelperText.setVisibility(View.GONE);
accountSetupBinding.scanQr.setVisibility(View.GONE);
accountSetupBinding.serversSpinner.setVisibility(View.VISIBLE);

ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.enforced_servers_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

ArrayList<String> servers = new ArrayList<>();
servers.add("");
adapter.add(getString(R.string.please_select_a_server));

ArrayList<EnforcedServer> t = new Gson().fromJson(getString(R.string.enforce_servers),
new TypeToken<ArrayList<EnforcedServer>>() {
}
.getType());

for (EnforcedServer e : t) {
adapter.add(e.getName());
servers.add(e.getUrl());
}
showEnforcedServers();
}

initServerPreFragment(savedInstanceState);
ProcessLifecycleOwner.get().getLifecycle().addObserver(lifecycleEventObserver);

accountSetupBinding.serversSpinner.setAdapter(adapter);
accountSetupBinding.serversSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
// webViewUtil.checkWebViewVersion();
}
}

private void showEnforcedServers() {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String url = servers.get(position);

if (URLUtil.isValidUrl(url)) {
accountSetupBinding.hostUrlInput.setText(url);
checkOcServer();
}
}
showAuthStatus();
accountSetupBinding.hostUrlFrame.setVisibility(View.GONE);
accountSetupBinding.hostUrlInputHelperText.setVisibility(View.GONE);
accountSetupBinding.scanQr.setVisibility(View.GONE);
accountSetupBinding.serversSpinner.setVisibility(View.VISIBLE);

@Override
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.enforced_servers_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

ArrayList<String> servers = new ArrayList<>();
servers.add("");
adapter.add(getString(R.string.please_select_a_server));

ArrayList<EnforcedServer> t = new Gson().fromJson(getString(R.string.enforce_servers),
new TypeToken<ArrayList<EnforcedServer>>() {
}
.getType());

for (EnforcedServer e : t) {
adapter.add(e.getName());
servers.add(e.getUrl());
}
}

initServerPreFragment(savedInstanceState);
ProcessLifecycleOwner.get().getLifecycle().addObserver(lifecycleEventObserver);
accountSetupBinding.serversSpinner.setAdapter(adapter);
accountSetupBinding.serversSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){

// webViewUtil.checkWebViewVersion();
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String url = servers.get(position);

if (URLUtil.isValidUrl(url)) {
accountSetupBinding.hostUrlInput.setText(url);
checkOcServer();
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});
}

private final LifecycleEventObserver lifecycleEventObserver = ((lifecycleOwner, event) -> {
if (event == Lifecycle.Event.ON_START && token != null) {
Expand Down

0 comments on commit b0e1d9a

Please sign in to comment.