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.graphics.drawable.GradientDrawable;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
2019-10-24 17:48:00 +02:00
|
|
|
import android.widget.RadioGroup;
|
2020-04-04 21:19:44 +02:00
|
|
|
import android.widget.ScrollView;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.TextView;
|
2019-10-22 17:27:33 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.tooltip.Tooltip;
|
2019-10-22 17:27:33 +02:00
|
|
|
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-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-04-04 21:19:44 +02:00
|
|
|
import org.mian.gitnex.helpers.SnackBar;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
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 {
|
|
|
|
|
|
|
|
private enum Protocol { HTTPS, HTTP }
|
|
|
|
private enum LoginType { BASIC, TOKEN }
|
|
|
|
|
|
|
|
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;
|
|
|
|
private Spinner protocolSpinner;
|
|
|
|
private TextView otpInfo;
|
|
|
|
private RadioGroup loginMethod;
|
|
|
|
private String device_id = "token";
|
|
|
|
private ScrollView layoutView;
|
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);
|
|
|
|
otpInfo = findViewById(R.id.otpInfo);
|
|
|
|
ImageView info_button = findViewById(R.id.info);
|
|
|
|
protocolSpinner = findViewById(R.id.httpsSpinner);
|
|
|
|
loginMethod = findViewById(R.id.loginMethod);
|
|
|
|
loginTokenCode = findViewById(R.id.loginTokenCode);
|
|
|
|
layoutView = findViewById(R.id.loginForm);
|
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-06-28 17:11:59 +02:00
|
|
|
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.spinner_item, Protocol.values());
|
2020-05-17 18:14:06 +02:00
|
|
|
adapterProtocols.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
protocolSpinner.setAdapter(adapterProtocols);
|
2020-05-17 18:14:06 +02:00
|
|
|
protocolSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(protocolSpinner.getSelectedItem() == Protocol.HTTP) {
|
2020-05-17 18:14:06 +02:00
|
|
|
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.protocolError));
|
|
|
|
}
|
|
|
|
}
|
2020-03-28 15:49:08 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
public void onNothingSelected(AdapterView<?> parent) {}
|
2020-03-28 15:49:08 +01:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
});
|
2020-04-12 21:04:02 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
info_button.setOnClickListener(view -> new Tooltip.Builder(view)
|
|
|
|
.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());
|
2019-10-24 17:48:00 +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-06-28 17:11:59 +02:00
|
|
|
AppUtil.setMultiVisibility(View.GONE, loginUidET, loginPassword, otpCode, otpInfo);
|
2020-05-17 18:14:06 +02:00
|
|
|
loginTokenCode.setVisibility(View.VISIBLE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
AppUtil.setMultiVisibility(View.VISIBLE, loginUidET, loginPassword, otpCode, otpInfo);
|
2020-05-17 18:14:06 +02:00
|
|
|
loginTokenCode.setVisibility(View.GONE);
|
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-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();
|
|
|
|
SnackBar.success(ctx, layoutView, getResources().getString(R.string.netConnectionIsBack));
|
|
|
|
}
|
|
|
|
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-05-17 18:14:06 +02:00
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.checkNetConnection));
|
|
|
|
}
|
|
|
|
});
|
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();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
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-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
|
|
|
Protocol protocol = (Protocol) protocolSpinner.getSelectedItem();
|
|
|
|
LoginType loginType = (loginMethod.getCheckedRadioButtonId() == R.id.loginUsernamePassword) ? LoginType.BASIC : LoginType.TOKEN;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-30 16:43:27 +02:00
|
|
|
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET.getText().toString(), "http"))
|
|
|
|
.toUri();
|
|
|
|
|
|
|
|
URI instanceUrlWithProtocol = UrlBuilder.fromUri(rawInstanceUrl)
|
2020-06-30 20:19:55 +02:00
|
|
|
.withPath(PathsHelper.join(rawInstanceUrl.getPath()))
|
2020-06-30 16:43:27 +02:00
|
|
|
.withScheme(protocol.name().toLowerCase())
|
|
|
|
.toUri();
|
|
|
|
|
|
|
|
URI instanceUrl = UrlBuilder.fromUri(instanceUrlWithProtocol)
|
|
|
|
.withPath(PathsHelper.join(instanceUrlWithProtocol.getPath(), "/api/v1/"))
|
|
|
|
.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());
|
|
|
|
tinyDB.putString("instanceUrlWithProtocol", instanceUrlWithProtocol.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-06-28 17:11:59 +02:00
|
|
|
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.emptyFieldURL));
|
|
|
|
enableProcessButton();
|
|
|
|
return;
|
2019-10-24 19:42:09 +02:00
|
|
|
|
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) {
|
|
|
|
|
|
|
|
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.loginOTPTypeError));
|
|
|
|
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-10-24 19:42:09 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
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-05-17 18:14:06 +02:00
|
|
|
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.emptyFieldUsername));
|
|
|
|
enableProcessButton();
|
|
|
|
return;
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
if(loginPass.equals("")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.emptyFieldPassword));
|
|
|
|
enableProcessButton();
|
|
|
|
return;
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
versionCheck(instanceUrl.toString(), loginUid, loginPass, loginOTP, loginToken, 1);
|
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-05-17 18:14:06 +02:00
|
|
|
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.loginTokenError));
|
|
|
|
enableProcessButton();
|
|
|
|
return;
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-06-30 16:43:27 +02:00
|
|
|
versionCheck(instanceUrl.toString(), loginUid, loginPass, 123, loginToken, 2);
|
2020-06-28 17:11:59 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-06-28 17:11:59 +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());
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.malformedUrl));
|
|
|
|
enableProcessButton();
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-22 17:27:33 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
private void versionCheck(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String loginToken, final int 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("")) {
|
|
|
|
|
|
|
|
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken(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);
|
|
|
|
|
|
|
|
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();
|
2020-06-28 17:11:59 +02:00
|
|
|
Version gitea_version;
|
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
assert version != null;
|
2020-03-31 21:04:08 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
try {
|
|
|
|
gitea_version = new Version(version.getVersion());
|
|
|
|
}
|
|
|
|
catch(Error e) {
|
2020-06-28 17:11:59 +02:00
|
|
|
|
2020-06-06 21:41:19 +02:00
|
|
|
SnackBar.error(ctx, layoutView, 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-05-17 18:14:06 +02:00
|
|
|
if(gitea_version.less(getString(R.string.versionLow))) {
|
2020-03-31 16:41:50 +02:00
|
|
|
|
2020-06-28 17:11:59 +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)
|
|
|
|
.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-05-17 18:14:06 +02:00
|
|
|
SnackBar.info(ctx, layoutView, 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-06-28 17:11:59 +02:00
|
|
|
private void login(int loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken) {
|
2019-10-24 19:42:09 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
if(loginType == 1) {
|
2020-06-28 17:11:59 +02:00
|
|
|
setup(instanceUrl, loginUid, loginPass, loginOTP);
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
else if(loginType == 2) { // Token
|
|
|
|
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-05-17 18:14:06 +02:00
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.errorOnLogin));
|
|
|
|
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-06-28 17:11:59 +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-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);
|
|
|
|
|
|
|
|
if(checkAccount == 0) {
|
|
|
|
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
|
|
|
}
|
|
|
|
|
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;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
case 401:
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.unauthorizedApiError));
|
|
|
|
enableProcessButton();
|
|
|
|
break;
|
2019-11-15 20:39:09 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
default:
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
|
|
|
|
enableProcessButton();
|
2019-11-15 20:39:09 +01:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2019-11-15 20:39:09 +01:00
|
|
|
|
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());
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericError));
|
|
|
|
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-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);
|
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-06-28 17:11:59 +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-06-28 17:11:59 +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
|
|
|
AppUtil appUtil = new AppUtil();
|
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-06-30 16:43:27 +02:00
|
|
|
boolean setTokenFlag = false;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(userTokens.size() > 0) { // FIXME This is in need of a refactor, but i don't understand what the code is used for.
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(userTokens.get(0).getToken_last_eight() != null) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
for(int i = 0; i < userTokens.size(); i++) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(userTokens.get(i).getToken_last_eight().equals(tinyDB.getString(loginUid + "-token-last-eight"))) {
|
|
|
|
setTokenFlag = true;
|
|
|
|
break;
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
for(int i = 0; i < userTokens.size(); i++) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(userTokens.get(i).getSha1().equals(tinyDB.getString(loginUid + "-token"))) {
|
|
|
|
setTokenFlag = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(tinyDB.getString(loginUid + "-token").isEmpty() || !setTokenFlag) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
UserTokens createUserToken = new UserTokens("gitnex-app-" + device_id);
|
|
|
|
Call<UserTokens> callCreateToken;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(loginOTP != 0) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx)
|
|
|
|
.getApiInterface()
|
|
|
|
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
|
|
|
|
}
|
|
|
|
else {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx)
|
|
|
|
.getApiInterface()
|
|
|
|
.createNewToken(credential, loginUid, createUserToken);
|
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
callCreateToken.enqueue(new Callback<UserTokens>() {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserTokens> callCreateToken, @NonNull retrofit2.Response<UserTokens> responseCreate) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(responseCreate.code() == 201) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
UserTokens newToken = responseCreate.body();
|
|
|
|
assert newToken != null;
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
if(!newToken.getSha1().equals("")) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx)
|
|
|
|
.getApiInterface()
|
|
|
|
.getUserInfo("token " + newToken.getSha1());
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
call.enqueue(new Callback<UserInfo>() {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
UserInfo userDetails = response.body();
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
switch(response.code()) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
case 200:
|
2020-06-30 16:43:27 +02:00
|
|
|
assert userDetails != null;
|
2020-06-28 17:11:59 +02:00
|
|
|
tinyDB.remove("loginPass");
|
|
|
|
tinyDB.putBoolean("loggedInMode", true);
|
|
|
|
tinyDB.putString("userLogin", userDetails.getUsername());
|
|
|
|
tinyDB.putString(loginUid + "-token", newToken.getSha1());
|
|
|
|
tinyDB.putString(loginUid + "-token-last-eight", appUtil.getLastCharactersOfWord(newToken.getSha1(), 8));
|
2020-03-31 21:04:53 +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);
|
|
|
|
|
|
|
|
if(checkAccount == 0) {
|
|
|
|
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
|
|
|
|
}
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
|
|
|
finish();
|
|
|
|
break;
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
case 401:
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.unauthorizedApiError));
|
|
|
|
enableProcessButton();
|
|
|
|
break;
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
default:
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
|
2020-05-17 18:14:06 +02:00
|
|
|
enableProcessButton();
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
|
2020-03-31 21:04:53 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericError));
|
|
|
|
enableProcessButton();
|
2020-04-02 23:07:20 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
|
|
|
});
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
else if(responseCreate.code() == 500) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
|
|
|
|
enableProcessButton();
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserTokens> createUserToken, @NonNull Throwable t) {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Log.e("onFailure-token", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
String instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
Call<UserInfo> callGetUsername = RetrofitClient.getInstance(instanceUrl, ctx)
|
|
|
|
.getApiInterface()
|
|
|
|
.getUserInfo(instanceToken);
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
callGetUsername.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:
|
|
|
|
assert userDetails != null;
|
|
|
|
tinyDB.putString("userLogin", userDetails.getUsername());
|
|
|
|
tinyDB.putBoolean("loggedInMode", true);
|
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);
|
|
|
|
|
|
|
|
if(checkAccount == 0) {
|
|
|
|
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), instanceToken, "");
|
|
|
|
}
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
|
|
|
finish();
|
|
|
|
break;
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
case 401:
|
2020-05-17 18:14:06 +02:00
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.unauthorizedApiError));
|
|
|
|
enableProcessButton();
|
2020-06-28 17:11:59 +02:00
|
|
|
break;
|
2020-04-07 08:05:42 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
default:
|
2020-05-17 18:14:06 +02:00
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
|
|
|
|
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
|
|
|
}
|
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());
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericError));
|
|
|
|
enableProcessButton();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
}
|
|
|
|
});
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-04-02 19:04:54 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
|
|
|
|
enableProcessButton();
|
2020-04-02 19:04:54 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<UserTokens>> call, @NonNull Throwable t) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-17 18:14:06 +02:00
|
|
|
Log.e("onFailure-login", t.toString());
|
|
|
|
SnackBar.error(ctx, layoutView, getResources().getString(R.string.malformedJson));
|
|
|
|
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-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 loadDefaults() {
|
|
|
|
|
|
|
|
if(tinyDB.getString("loginType").equals(LoginType.BASIC.name().toLowerCase())) {
|
|
|
|
loginMethod.check(R.id.loginUsernamePassword);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loginMethod.check(R.id.loginToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!tinyDB.getString("instanceUrlRaw").equals("")) {
|
|
|
|
instanceUrlET.setText(tinyDB.getString("instanceUrlRaw"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!tinyDB.getString("loginUid").equals("")) {
|
|
|
|
loginUidET.setText(tinyDB.getString("loginUid"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tinyDB.getBoolean("loggedInMode")) {
|
|
|
|
|
|
|
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!tinyDB.getString("uniqueAppId").isEmpty()) {
|
|
|
|
device_id = tinyDB.getString("uniqueAppId");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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-05-17 18:14:06 +02:00
|
|
|
GradientDrawable shape = new GradientDrawable();
|
|
|
|
shape.setCornerRadius(8);
|
|
|
|
shape.setColor(getResources().getColor(R.color.hintColor));
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
loginButton.setText(R.string.processingText);
|
2020-05-17 18:14:06 +02:00
|
|
|
loginButton.setBackground(shape);
|
2020-06-28 17:11:59 +02:00
|
|
|
loginButton.setEnabled(false);
|
2020-05-17 18:14:06 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableProcessButton() {
|
|
|
|
|
|
|
|
GradientDrawable shape = new GradientDrawable();
|
|
|
|
shape.setCornerRadius(8);
|
|
|
|
shape.setColor(getResources().getColor(R.color.btnBackground));
|
2020-06-28 17:11:59 +02:00
|
|
|
|
|
|
|
loginButton.setText(R.string.btnLogin);
|
2020-05-17 18:14:06 +02:00
|
|
|
loginButton.setBackground(shape);
|
2020-06-28 17:11:59 +02:00
|
|
|
loginButton.setEnabled(true);
|
2020-05-17 18:14:06 +02:00
|
|
|
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
}
|