2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2019-10-22 17:27:33 +02:00
|
|
|
import android.content.Context;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ArrayAdapter;
|
2020-10-20 20:09:07 +02:00
|
|
|
import android.widget.AutoCompleteTextView;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2019-10-24 17:48:00 +02:00
|
|
|
import android.widget.RadioGroup;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.TextView;
|
2019-10-22 17:27:33 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import org.mian.gitnex.R;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
2020-08-06 17:31:31 +02:00
|
|
|
import org.mian.gitnex.database.models.UserAccount;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2020-03-28 15:49:08 +01:00
|
|
|
import org.mian.gitnex.helpers.NetworkObserver;
|
2020-06-30 16:43:27 +02:00
|
|
|
import org.mian.gitnex.helpers.PathsHelper;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
2020-08-06 17:16:51 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2020-06-28 17:11:59 +02:00
|
|
|
import org.mian.gitnex.helpers.UrlHelper;
|
2020-05-17 18:14:06 +02:00
|
|
|
import org.mian.gitnex.helpers.Version;
|
2019-10-22 17:27:33 +02:00
|
|
|
import org.mian.gitnex.models.GiteaVersion;
|
2019-10-24 19:42:09 +02:00
|
|
|
import org.mian.gitnex.models.UserInfo;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.models.UserTokens;
|
2020-06-30 16:43:27 +02:00
|
|
|
import java.net.URI;
|
2020-03-19 14:54:20 +01:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2019-06-03 23:25:05 +02:00
|
|
|
import java.util.List;
|
2019-11-13 16:52:49 +01:00
|
|
|
import java.util.UUID;
|
2020-06-30 16:43:27 +02:00
|
|
|
import io.mikael.urlbuilder.UrlBuilder;
|
2019-06-03 23:25:05 +02:00
|
|
|
import okhttp3.Credentials;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
public class LoginActivity extends BaseActivity {
|
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
private enum Protocol {HTTPS, HTTP}
|
|
|
|
|
|
|
|
private enum LoginType {BASIC, TOKEN}
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
private Context appCtx;
|
|
|
|
private Context ctx = this;
|
|
|
|
private TinyDB tinyDB;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
private Button loginButton;
|
|
|
|
private EditText instanceUrlET, loginUidET, loginPassword, otpCode, loginTokenCode;
|
2020-10-20 20:09:07 +02:00
|
|
|
private AutoCompleteTextView protocolSpinner;
|
2020-05-17 18:14:06 +02:00
|
|
|
private RadioGroup loginMethod;
|
|
|
|
private String device_id = "token";
|
2020-10-20 20:09:07 +02:00
|
|
|
private String selectedProtocol;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
protected int getLayoutResourceId() {
|
2020-01-01 21:03:53 +01:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
return R.layout.activity_login;
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
appCtx = getApplicationContext();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
tinyDB = new TinyDB(appCtx);
|
|
|
|
NetworkObserver networkMonitor = new NetworkObserver(ctx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
loginButton = findViewById(R.id.login_button);
|
|
|
|
instanceUrlET = findViewById(R.id.instance_url);
|
|
|
|
loginUidET = findViewById(R.id.login_uid);
|
|
|
|
loginPassword = findViewById(R.id.login_passwd);
|
|
|
|
otpCode = findViewById(R.id.otpCode);
|
|
|
|
protocolSpinner = findViewById(R.id.httpsSpinner);
|
|
|
|
loginMethod = findViewById(R.id.loginMethod);
|
|
|
|
loginTokenCode = findViewById(R.id.loginTokenCode);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
((TextView) findViewById(R.id.appVersion)).setText(AppUtil.getAppVersion(appCtx));
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.list_spinner_items, Protocol.values());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
protocolSpinner.setAdapter(adapterProtocols);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
protocolSpinner.setOnItemClickListener((parent, view, position, id) -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
selectedProtocol = String.valueOf(parent.getItemAtPosition(position));
|
|
|
|
|
|
|
|
if(selectedProtocol.equals(String.valueOf(Protocol.HTTP))) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.protocolError));
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-10-20 20:09:07 +02:00
|
|
|
});
|
2020-03-28 15:49:08 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
if(R.id.loginToken == loginMethod.getCheckedRadioButtonId()) {
|
2020-07-29 16:27:47 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
AppUtil.setMultiVisibility(View.GONE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
|
|
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
else {
|
2020-03-28 15:49:08 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
AppUtil.setMultiVisibility(View.VISIBLE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
|
|
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.GONE);
|
|
|
|
}
|
2020-04-12 21:04:02 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
loginMethod.setOnCheckedChangeListener((group, checkedId) -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
if(checkedId == R.id.loginToken) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
AppUtil.setMultiVisibility(View.GONE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
|
|
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.VISIBLE);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
AppUtil.setMultiVisibility(View.VISIBLE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
|
|
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.GONE);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
networkMonitor.onInternetStateListener(isAvailable -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
if(isAvailable) {
|
2020-06-28 17:11:59 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
else {
|
2020-06-28 17:11:59 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
disableProcessButton();
|
2020-06-28 17:11:59 +02:00
|
|
|
loginButton.setText(getResources().getString(R.string.btnLogin));
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loadDefaults();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loginButton.setOnClickListener(view -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
disableProcessButton();
|
|
|
|
login();
|
2020-06-28 17:11:59 +02:00
|
|
|
});
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
private void login() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
try {
|
2020-04-12 21:04:02 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
if(selectedProtocol == null) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.protocolEmptyError));
|
|
|
|
enableProcessButton();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
String loginUid = loginUidET.getText().toString();
|
|
|
|
String loginPass = loginPassword.getText().toString();
|
|
|
|
String loginToken = loginTokenCode.getText().toString().trim();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
LoginType loginType = (loginMethod.getCheckedRadioButtonId() == R.id.loginUsernamePassword) ? LoginType.BASIC : LoginType.TOKEN;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET.getText().toString(), "http")).toUri();
|
2020-06-30 16:43:27 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
URI instanceUrl = UrlBuilder.fromUri(rawInstanceUrl).withScheme(selectedProtocol.toLowerCase()).withPath(PathsHelper.join(rawInstanceUrl.getPath(), "/api/v1/"))
|
2020-06-30 16:43:27 +02:00
|
|
|
.toUri();
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
tinyDB.putString("loginType", loginType.name().toLowerCase());
|
2020-06-30 16:43:27 +02:00
|
|
|
tinyDB.putString("instanceUrlRaw", instanceUrlET.getText().toString());
|
|
|
|
tinyDB.putString("instanceUrl", instanceUrl.toString());
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(instanceUrlET.getText().toString().equals("")) {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
|
2020-06-28 17:11:59 +02:00
|
|
|
enableProcessButton();
|
|
|
|
return;
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(loginType == LoginType.BASIC) {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-30 16:43:27 +02:00
|
|
|
if(otpCode.length() != 0 && otpCode.length() != 6) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.loginOTPTypeError));
|
2020-06-30 16:43:27 +02:00
|
|
|
enableProcessButton();
|
|
|
|
return;
|
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(rawInstanceUrl.getUserInfo() != null) {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
tinyDB.putString("basicAuthPassword", loginPass);
|
|
|
|
tinyDB.putBoolean("basicAuthFlag", true);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
if(loginUid.equals("")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldUsername));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
return;
|
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
if(loginPass.equals("")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldPassword));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
return;
|
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-30 16:43:27 +02:00
|
|
|
int loginOTP = (otpCode.length() > 0) ? Integer.parseInt(otpCode.getText().toString().trim()) : 0;
|
|
|
|
tinyDB.putString("loginUid", loginUid);
|
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
versionCheck(instanceUrl.toString(), loginUid, loginPass, loginOTP, loginToken, loginType);
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(loginToken.equals("")) {
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
return;
|
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
versionCheck(instanceUrl.toString(), loginUid, loginPass, 123, loginToken, loginType);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
}
|
|
|
|
catch(Exception e) {
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Log.e("onFailure-login", e.toString());
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
|
2020-06-28 17:11:59 +02:00
|
|
|
enableProcessButton();
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
private void versionCheck(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String loginToken,
|
|
|
|
final LoginType loginType) {
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
Call<GiteaVersion> callVersion;
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
if(!loginToken.equals("")) {
|
|
|
|
|
2020-09-03 19:26:24 +02:00
|
|
|
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken("token " + loginToken);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
callVersion =
|
|
|
|
(loginOTP != 0) ? RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithOTP(credential, loginOTP) :
|
|
|
|
RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithBasic(credential);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
callVersion.enqueue(new Callback<GiteaVersion>() {
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull final Call<GiteaVersion> callVersion, @NonNull retrofit2.Response<GiteaVersion> responseVersion) {
|
2020-03-31 21:04:08 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
if(responseVersion.code() == 200) {
|
2020-03-31 21:04:08 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
GiteaVersion version = responseVersion.body();
|
|
|
|
assert version != null;
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-09-04 16:33:37 +02:00
|
|
|
if(!Version.valid(version.getVersion())) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
2020-06-28 17:11:59 +02:00
|
|
|
return;
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-03-31 21:04:08 +02:00
|
|
|
|
2020-09-04 16:33:37 +02:00
|
|
|
tinyDB.putString("giteaVersion", version.getVersion());
|
|
|
|
Version gitea_version = new Version(version.getVersion());
|
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
if(gitea_version.less(getString(R.string.versionLow))) {
|
2020-03-31 16:41:50 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx).setTitle(getString(R.string.versionAlertDialogHeader))
|
|
|
|
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion())).setIcon(R.drawable.ic_warning)
|
2020-06-28 17:11:59 +02:00
|
|
|
.setCancelable(true);
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
enableProcessButton();
|
2020-06-28 17:11:59 +02:00
|
|
|
});
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
dialog.dismiss();
|
2020-06-28 17:11:59 +02:00
|
|
|
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
2020-05-17 18:14:06 +02:00
|
|
|
});
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
alertDialogBuilder.create().show();
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else if(gitea_version.lessOrEqual(getString(R.string.versionHigh))) {
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-06-28 17:11:59 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
2020-06-28 17:11:59 +02:00
|
|
|
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else if(responseVersion.code() == 403) {
|
2020-03-31 16:41:50 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
private void login(LoginType loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken) {
|
|
|
|
|
|
|
|
// ToDo: before store/create token: get UserInfo to check DB/AccountManager if there already exist a token
|
|
|
|
// the setup methods then can better handle all different cases
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
if(loginType == LoginType.BASIC) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
setup(instanceUrl, loginUid, loginPass, loginOTP);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-07-29 16:27:47 +02:00
|
|
|
else if(loginType == LoginType.TOKEN) { // Token
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
setupUsingExistingToken(instanceUrl, loginToken);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
2020-06-28 17:11:59 +02:00
|
|
|
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Log.e("onFailure-versionCheck", t.toString());
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.errorOnLogin));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
private void setupUsingExistingToken(String instanceUrl, final String loginToken) {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
call.enqueue(new Callback<UserInfo>() {
|
2020-04-13 10:01:56 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
UserInfo userDetails = response.body();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
switch(response.code()) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
case 200:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
assert userDetails != null;
|
2020-06-30 16:43:27 +02:00
|
|
|
tinyDB.putBoolean("loggedInMode", true);
|
2020-06-28 17:11:59 +02:00
|
|
|
tinyDB.putString(userDetails.getLogin() + "-token", loginToken);
|
|
|
|
tinyDB.putString("loginUid", userDetails.getLogin());
|
|
|
|
tinyDB.putString("userLogin", userDetails.getUsername());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
// insert new account to db if does not exist
|
|
|
|
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
|
|
|
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
|
|
|
int checkAccount = userAccountsApi.getCount(accountName);
|
2020-08-06 17:31:31 +02:00
|
|
|
long accountId;
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
|
|
|
|
if(checkAccount == 0) {
|
2020-08-06 17:31:31 +02:00
|
|
|
|
|
|
|
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
|
|
|
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
}
|
2020-08-04 22:50:04 +02:00
|
|
|
else {
|
2020-08-06 17:31:31 +02:00
|
|
|
|
2020-08-04 22:50:04 +02:00
|
|
|
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
|
2020-08-06 17:31:31 +02:00
|
|
|
UserAccount data = userAccountsApi.getAccountData(accountName);
|
|
|
|
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
|
|
|
finish();
|
2020-06-28 17:11:59 +02:00
|
|
|
break;
|
|
|
|
case 401:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
2020-06-28 17:11:59 +02:00
|
|
|
enableProcessButton();
|
|
|
|
break;
|
|
|
|
default:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
2020-06-28 17:11:59 +02:00
|
|
|
enableProcessButton();
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-15 20:39:09 +01:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
private void setup(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
2020-07-29 16:27:47 +02:00
|
|
|
final String tokenName = "gitnex-app-" + device_id;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
Call<List<UserTokens>> call;
|
|
|
|
if(loginOTP != 0) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokensWithOTP(credential, loginOTP, loginUid);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokens(credential, loginUid);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
call.enqueue(new Callback<List<UserTokens>>() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<UserTokens>> call, @NonNull retrofit2.Response<List<UserTokens>> response) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
List<UserTokens> userTokens = response.body();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(response.code() == 200) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
assert userTokens != null;
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
for(UserTokens t : userTokens) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
if(t.getName().equals(tokenName)) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
// this app had created an token on this instance before
|
|
|
|
// -> since it looks like GitNex forgot the secret we have to delete it first
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
Call<Void> delcall;
|
|
|
|
if(loginOTP != 0) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
|
|
|
.deleteTokenWithOTP(credential, loginOTP, loginUid, t.getId());
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-07-29 16:27:47 +02:00
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().deleteToken(credential, loginUid, t.getId());
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
delcall.enqueue(new Callback<Void>() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<Void> delcall, @NonNull retrofit2.Response<Void> response) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
if(response.code() == 204) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
|
|
|
|
}
|
|
|
|
else {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
2020-07-29 16:27:47 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Void> delcall, @NonNull Throwable t) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
Log.e("onFailure-login", t.toString());
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
2020-07-29 16:27:47 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
|
|
|
|
}
|
|
|
|
else {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
2020-07-29 16:27:47 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<UserTokens>> call, @NonNull Throwable t) {
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
Log.e("onFailure-login", t.toString());
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
2020-07-29 16:27:47 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
private void setupToken(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String tokenName) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
UserTokens createUserToken = new UserTokens(tokenName);
|
|
|
|
Call<UserTokens> callCreateToken;
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
if(loginOTP != 0) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
|
|
|
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
|
|
|
|
}
|
|
|
|
else {
|
2020-04-02 23:07:20 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().createNewToken(credential, loginUid, createUserToken);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
callCreateToken.enqueue(new Callback<UserTokens>() {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserTokens> callCreateToken, @NonNull retrofit2.Response<UserTokens> responseCreate) {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
if(responseCreate.code() == 201) {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
UserTokens newToken = responseCreate.body();
|
|
|
|
assert newToken != null;
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
if(!newToken.getSha1().equals("")) {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
|
|
|
.getUserInfo("token " + newToken.getSha1());
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
call.enqueue(new Callback<UserInfo>() {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
UserInfo userDetails = response.body();
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
switch(response.code()) {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
case 200:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
assert userDetails != null;
|
2020-07-29 16:27:47 +02:00
|
|
|
tinyDB.remove("loginPass");
|
2020-06-28 17:11:59 +02:00
|
|
|
tinyDB.putBoolean("loggedInMode", true);
|
2020-07-29 16:27:47 +02:00
|
|
|
tinyDB.putString("userLogin", userDetails.getUsername());
|
|
|
|
tinyDB.putString(loginUid + "-token", newToken.getSha1());
|
|
|
|
tinyDB.putString(loginUid + "-token-last-eight", newToken.getToken_last_eight());
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
|
|
|
|
// insert new account to db if does not exist
|
|
|
|
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
|
|
|
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
|
|
|
int checkAccount = userAccountsApi.getCount(accountName);
|
2020-08-06 17:31:31 +02:00
|
|
|
long accountId;
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
|
|
|
|
if(checkAccount == 0) {
|
2020-08-06 17:31:31 +02:00
|
|
|
|
2020-09-04 16:33:37 +02:00
|
|
|
accountId = userAccountsApi
|
|
|
|
.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
|
2020-08-06 17:31:31 +02:00
|
|
|
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
}
|
2020-08-04 22:50:04 +02:00
|
|
|
else {
|
2020-08-06 17:31:31 +02:00
|
|
|
|
2020-08-04 22:50:04 +02:00
|
|
|
userAccountsApi.updateTokenByAccountName(accountName, newToken.getSha1());
|
2020-08-06 17:31:31 +02:00
|
|
|
UserAccount data = userAccountsApi.getAccountData(accountName);
|
|
|
|
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message
translation updates
format improvements
typo update
some renaming refactors
Use better naming convention
remove duplicate source
arrange draft titles
enhance click listener area
Launch drafts from reply screen and clean up
Add message draft saved
update repositories tasks
Update user accounts repository with thread, remove async tasks
remove async task in drafts
update layout, change async to thread in drafts
Merge branch 'master' into pull_139
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139
Merge branch 'master' into pull_139 and fix conflicts
# Conflicts:
# app/build.gradle
# app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
# app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
# app/src/main/res/values/strings.xml
Code Format
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/res/values/strings.xml
Go to draft, save on type and other fixes
delete all drafts, added messages where needed
delete draft
Force logout
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/src/main/java/org/mian/gitnex/activities/MainActivity.java
# app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
check if account data is null, we need to log the user out for the 1st time.
Merge branch 'master' into 15-comments-draft
fix repo owner, name sequence
Add comments for test, show drafts list
Add repos to db
Add account to db and other refactors to the code
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
Merge branch 'master' into 15-comments-draft
# Conflicts:
# app/build.gradle
# app/src/main/AndroidManifest.xml
Merge branch 'master' into 15-comments-draft
merge
more queries, added dao repositories, layout update
Added queries in dao
some refactor. added models, dao, entities (accounts, repositories, drafts)
WIP on implementing drafts, introduced Room persistence library for db.
Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
|
|
|
finish();
|
|
|
|
break;
|
|
|
|
case 401:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
2020-06-28 17:11:59 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
2020-06-28 17:11:59 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-29 16:27:47 +02:00
|
|
|
else if(responseCreate.code() == 500) {
|
2020-04-02 19:04:54 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
2020-07-29 16:27:47 +02:00
|
|
|
public void onFailure(@NonNull Call<UserTokens> createUserToken, @NonNull Throwable t) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
Log.e("onFailure-token", t.toString());
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-29 16:27:47 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
private void loadDefaults() {
|
|
|
|
|
|
|
|
if(tinyDB.getString("loginType").equals(LoginType.BASIC.name().toLowerCase())) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loginMethod.check(R.id.loginUsernamePassword);
|
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loginMethod.check(R.id.loginToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!tinyDB.getString("instanceUrlRaw").equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
instanceUrlET.setText(tinyDB.getString("instanceUrlRaw"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!tinyDB.getString("loginUid").equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loginUidET.setText(tinyDB.getString("loginUid"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tinyDB.getBoolean("loggedInMode")) {
|
|
|
|
|
|
|
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!tinyDB.getString("uniqueAppId").isEmpty()) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
device_id = tinyDB.getString("uniqueAppId");
|
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
device_id = UUID.randomUUID().toString();
|
|
|
|
tinyDB.putString("uniqueAppId", device_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
private void disableProcessButton() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loginButton.setText(R.string.processingText);
|
|
|
|
loginButton.setEnabled(false);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enableProcessButton() {
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
loginButton.setText(R.string.btnLogin);
|
|
|
|
loginButton.setEnabled(true);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
}
|