1
0
mirror of https://codeberg.org/gitnex/GitNex synced 2025-01-27 09:41:34 +01:00

Reformatting applied.

This commit is contained in:
anonTree1417 2020-03-31 21:04:53 +02:00
parent 2125d38a66
commit a53a5d55bf

View File

@ -57,7 +57,8 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
private String device_id = "token";
@Override
protected int getLayoutResourceId(){
protected int getLayoutResourceId() {
return R.layout.activity_login;
}
@ -86,13 +87,13 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
Resources res = getResources();
String[] allProtocols = res.getStringArray(R.array.protocolValues);
final ArrayAdapter<String> adapterProtocols = new ArrayAdapter<String>(Objects.requireNonNull(getApplicationContext()),
R.layout.spinner_item, allProtocols);
final ArrayAdapter<String> adapterProtocols = new ArrayAdapter<String>(Objects.requireNonNull(getApplicationContext()), R.layout.spinner_item, allProtocols);
adapterProtocols.setDropDownViewResource(R.layout.spinner_dropdown_item);
protocolSpinner.setAdapter(adapterProtocols);
protocolSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String value = getResources().getStringArray(R.array.protocolValues)[pos];
@ -101,7 +102,9 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
@ -172,13 +175,14 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
@Override
public void onClick(View v) {
if (v.getId() == R.id.login_button) {
if(v.getId() == R.id.login_button) {
login();
}
}
private View.OnClickListener loginListener = new View.OnClickListener() {
public void onClick(View v) {
disableProcessButton();
@ -189,17 +193,10 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
};
private View.OnClickListener infoListener = new View.OnClickListener() {
public void onClick(View v) {
new Tooltip.Builder(v)
.setText(R.string.urlInfoTooltip)
.setTextColor(getResources().getColor(R.color.white))
.setBackgroundColor(getResources().getColor(R.color.tooltipBackground))
.setCancelable(true)
.setDismissOnClick(true)
.setPadding(30)
.setCornerRadius(R.dimen.tooltipCornor)
.setGravity(Gravity.BOTTOM)
.show();
new Tooltip.Builder(v).setText(R.string.urlInfoTooltip).setTextColor(getResources().getColor(R.color.white)).setBackgroundColor(getResources().getColor(R.color.tooltipBackground)).setCancelable(true).setDismissOnClick(true).setPadding(30).setCornerRadius(R.dimen.tooltipCornor).setGravity(Gravity.BOTTOM).show();
}
};
@ -238,7 +235,8 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
URI uri = null;
try {
uri = new URI(instanceUrl);
} catch (URISyntaxException e) {
}
catch(URISyntaxException e) {
e.printStackTrace();
}
assert uri != null;
@ -327,7 +325,8 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
URI uri = null;
try {
uri = new URI(instanceUrl);
} catch (URISyntaxException e) {
}
catch(URISyntaxException e) {
e.printStackTrace();
}
assert uri != null;
@ -355,7 +354,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
if(connToInternet) {
if (instanceUrlET.getText().toString().equals("")) {
if(instanceUrlET.getText().toString().equals("")) {
Toasty.info(getApplicationContext(), getString(R.string.emptyFieldURL));
enableProcessButton();
@ -363,7 +362,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
return;
}
if (loginToken_.equals("")) {
if(loginToken_.equals("")) {
Toasty.info(getApplicationContext(), getString(R.string.loginTokenError));
enableProcessButton();
@ -388,24 +387,21 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
final TinyDB tinyDb = new TinyDB(getApplicationContext());
Call<GiteaVersion> callVersion = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getGiteaVersion();
Call<GiteaVersion> callVersion = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getGiteaVersion();
callVersion.enqueue(new Callback<GiteaVersion>() {
@Override
public void onResponse(@NonNull final Call<GiteaVersion> callVersion, @NonNull retrofit2.Response<GiteaVersion> responseVersion) {
if (responseVersion.code() == 200) {
if(responseVersion.code() == 200) {
GiteaVersion version = responseVersion.body();
assert version != null;
VersionCheck vt = VersionCheck.check(getString(R.string.versionLow), getString(R.string.versionHigh), version.getVersion());
switch (vt) {
switch(vt) {
case UNSUPPORTED_NEW:
//Toasty.info(getApplicationContext(), getString(R.string.versionUnsupportedNew));
case SUPPORTED_LATEST:
@ -417,19 +413,16 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx);
alertDialogBuilder
.setTitle(getString(R.string.versionAlertDialogHeader))
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion()))
.setCancelable(true)
.setIcon(R.drawable.ic_warning)
.setNegativeButton(getString(R.string.cancelButton), new DialogInterface.OnClickListener() {
alertDialogBuilder.setTitle(getString(R.string.versionAlertDialogHeader)).setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion())).setCancelable(true).setIcon(R.drawable.ic_warning).setNegativeButton(getString(R.string.cancelButton), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
enableProcessButton();
}
})
.setPositiveButton(getString(R.string.textContinue), new DialogInterface.OnClickListener() {
}).setPositiveButton(getString(R.string.textContinue), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -450,16 +443,17 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
}
}
else if (responseVersion.code() == 403) {
else if(responseVersion.code() == 403) {
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken_);
}
}
private void login(int loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken_) {
if (loginType == 1) {
if(loginType == 1) {
letTheUserIn(instanceUrl, loginUid, loginPass, loginOTP);
}
else if (loginType == 2) { // token
else if(loginType == 2) { // token
letTheUserInViaToken(instanceUrl, loginToken_);
}
}
@ -470,8 +464,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
Log.e("onFailure-version", t.toString());
if(t instanceof NoRouteToHostException) {
Toasty.info(getApplicationContext(), "Could not connect to host. Please check your url or port " +
"for issues.");
Toasty.info(getApplicationContext(), "Could not connect to host. Please check your url or port " + "for issues.");
}
else {
Toasty.info(getApplicationContext(), getResources().getString(R.string.commentError));
@ -490,10 +483,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
final TinyDB tinyDb = new TinyDB(getApplicationContext());
Call<UserInfo> call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getUserInfo("token " + loginToken_);
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getUserInfo("token " + loginToken_);
call.enqueue(new Callback<UserInfo>() {
@ -502,9 +492,9 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
UserInfo userDetails = response.body();
if (response.isSuccessful()) {
if(response.isSuccessful()) {
if (response.code() == 200) {
if(response.code() == 200) {
tinyDb.putBoolean("loggedInMode", true);
assert userDetails != null;
@ -542,6 +532,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
@Override
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
Toasty.info(getApplicationContext(), getResources().getString(R.string.genericError));
enableProcessButton();
@ -557,16 +548,10 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
Call<List<UserTokens>> call;
if(loginOTP != 0) {
call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getUserTokensWithOTP(credential, loginOTP, loginUid);
call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getUserTokensWithOTP(credential, loginOTP, loginUid);
}
else {
call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getUserTokens(credential, loginUid);
call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getUserTokens(credential, loginUid);
}
call.enqueue(new Callback<List<UserTokens>>() {
@ -579,19 +564,19 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
final AppUtil appUtil = new AppUtil();
//Headers responseHeaders = response.headers();
if (response.isSuccessful()) {
if(response.isSuccessful()) {
if (response.code() == 200) {
if(response.code() == 200) {
boolean setTokenFlag = false;
assert userTokens != null;
if (userTokens.size() > 0) {
if(userTokens.size() > 0) {
if(userTokens.get(0).getToken_last_eight() != null) {
for (int i = 0; i < userTokens.size(); i++) {
if (userTokens.get(i).getToken_last_eight().equals(tinyDb.getString(loginUid + "-token-last-eight"))) {
for(int i = 0; i < userTokens.size(); i++) {
if(userTokens.get(i).getToken_last_eight().equals(tinyDb.getString(loginUid + "-token-last-eight"))) {
setTokenFlag = true;
break;
}
@ -601,8 +586,8 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
}
else {
for (int i = 0; i < userTokens.size(); i++) {
if (userTokens.get(i).getSha1().equals(tinyDb.getString(loginUid + "-token"))) {
for(int i = 0; i < userTokens.size(); i++) {
if(userTokens.get(i).getSha1().equals(tinyDb.getString(loginUid + "-token"))) {
setTokenFlag = true;
break;
}
@ -619,16 +604,10 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
Call<UserTokens> callCreateToken;
if(loginOTP != 0) {
callCreateToken = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
callCreateToken = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
}
else {
callCreateToken = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.createNewToken(credential, loginUid, createUserToken);
callCreateToken = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().createNewToken(credential, loginUid, createUserToken);
}
callCreateToken.enqueue(new Callback<UserTokens>() {
@ -644,7 +623,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
assert newToken != null;
//Log.i("Tokens-NEW", "new:" + newToken.getSha1());
if (!newToken.getSha1().equals("")) {
if(!newToken.getSha1().equals("")) {
tinyDb.remove("loginPass");
tinyDb.putBoolean("loggedInMode", true);
@ -713,6 +692,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
@Override
public void onFailure(@NonNull Call<List<UserTokens>> call, @NonNull Throwable t) {
Log.e("onFailure-login", t.toString());
Toasty.info(getApplicationContext(), getResources().getString(R.string.malformedJson));
enableProcessButton();
@ -726,7 +706,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
loginButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setCornerRadius(8);
shape.setColor(getResources().getColor(R.color.hintColor));
loginButton.setBackground(shape);
@ -736,7 +716,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
loginButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setCornerRadius(8);
shape.setColor(getResources().getColor(R.color.btnBackground));
loginButton.setBackground(shape);