code refactoring on login activity
This commit is contained in:
parent
402b545473
commit
7a9a93e757
3 changed files with 25 additions and 28 deletions
|
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
tools:ignore="ScopedStorage" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
|
||||||
|
|
@ -73,32 +73,30 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v == binding.login) {
|
final Context context = this;
|
||||||
final Context context = this;
|
if (binding.server.getText().toString().trim().length() == 0) {
|
||||||
if (binding.server.getText().toString().trim().length() == 0) {
|
Toast.makeText(this, getResources().getString(R.string.error_login_empty_address), Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(context, context.getResources().getString(R.string.error_login_empty_address), Toast.LENGTH_SHORT).show();
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (binding.username.getText().toString().trim().length() == 0) {
|
|
||||||
Toast.makeText(context, context.getResources().getString(R.string.error_no_username), Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
App.getApiClient().ChangeServerLocation(binding.server.getText().toString());
|
|
||||||
App.getApiClient().AuthenticateUserAsync(binding.username.getText().toString(), binding.password.getText().toString(), new Response<AuthenticationResult>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(AuthenticationResult result) {
|
|
||||||
if (result.getAccessToken() == null) return;
|
|
||||||
check(binding.server.getText().toString(), result.getUser().getId(), result.getAccessToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Exception exception) {
|
|
||||||
Toast.makeText(context, context.getResources().getString(R.string.error_login_credentials), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (binding.username.getText().toString().trim().length() == 0) {
|
||||||
|
Toast.makeText(this, getResources().getString(R.string.error_no_username), Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
App.getApiClient().ChangeServerLocation(binding.server.getText().toString());
|
||||||
|
App.getApiClient().AuthenticateUserAsync(binding.username.getText().toString(), binding.password.getText().toString(), new Response<AuthenticationResult>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(AuthenticationResult result) {
|
||||||
|
if (result.getAccessToken() == null) return;
|
||||||
|
check(binding.server.getText().toString(), result.getUser().getId(), result.getAccessToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Exception exception) {
|
||||||
|
Toast.makeText(context, context.getResources().getString(R.string.error_login_credentials), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void check(String server, String user, String token) {
|
private void check(String server, String user, String token) {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
<include layout="@layout/status_bar" />
|
<include layout="@layout/status_bar" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
<androidx.appcompat.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
|
||||||
style="@style/Toolbar"
|
style="@style/Toolbar"
|
||||||
|
android:id="@+id/toolbar"
|
||||||
android:background="@android:color/transparent" />
|
android:background="@android:color/transparent" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
|
@ -104,9 +104,7 @@
|
||||||
android:id="@+id/login"
|
android:id="@+id/login"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="64dp"
|
android:layout_height="64dp"
|
||||||
android:layout_marginStart="32dp"
|
android:layout_margin="32dp"
|
||||||
android:layout_marginEnd="32dp"
|
|
||||||
android:layout_marginTop="32dp"
|
|
||||||
android:text="@string/login"
|
android:text="@string/login"
|
||||||
app:cornerRadius="24dp" />
|
app:cornerRadius="24dp" />
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue