WIP: Login form.

This commit is contained in:
Sergio Martínez Portela 2020-03-02 22:10:22 +01:00
parent 9fb10281cb
commit 1cdc679c70
20 changed files with 219 additions and 50 deletions

View File

@ -3,15 +3,15 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
android { android {
compileSdkVersion 25 compileSdkVersion 29
buildToolsVersion "27.0.1" buildToolsVersion "27.0.1"
defaultConfig { defaultConfig {
applicationId "com.codigoparallevar.minicards" applicationId "com.codigoparallevar.minicards"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 25 targetSdkVersion 29
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
release { release {
@ -23,18 +23,18 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:28.0.0' implementation 'androidx.annotation:annotation:1.0.0'
implementation 'android.arch.lifecycle:extensions:1.1.1' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
implementation 'com.android.support:appcompat-v7:25.4.0' implementation 'androidx.appcompat:appcompat:1.0.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:25.4.0' implementation 'com.google.android.material:material:1.0.0'
implementation 'com.getbase:floatingactionbutton:1.10.1' implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.larswerkman:HoloColorPicker:1.5' implementation 'com.larswerkman:HoloColorPicker:1.5'
implementation 'com.android.support:cardview-v7:25.4.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
} }

View File

@ -1,8 +1,8 @@
package com.codigoparallevar.minicards; package com.codigoparallevar.minicards;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry; import androidx.test.platform.app.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;

View File

@ -15,9 +15,6 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity
android:name=".ui.login.LoginActivity"
android:label="@string/title_activity_login"></activity>
<activity android:name=".CardActivity"> <activity android:name=".CardActivity">
<intent-filter> <intent-filter>
<action android:name="com.codigoparallevar.minicards.CARD" /> <action android:name="com.codigoparallevar.minicards.CARD" />

View File

@ -4,8 +4,8 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.support.annotation.NonNull; import androidx.annotation.NonNull;
import android.support.annotation.Nullable; import androidx.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;

View File

@ -2,9 +2,9 @@ package com.codigoparallevar.minicards;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.design.widget.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.support.v7.app.ActionBar; import androidx.appcompat.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;

View File

@ -4,7 +4,7 @@ import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull; import androidx.annotation.NonNull;
import android.util.Log; import android.util.Log;
import com.codigoparallevar.minicards.parts.buttons.RoundButton; import com.codigoparallevar.minicards.parts.buttons.RoundButton;

View File

@ -4,9 +4,9 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.support.annotation.NonNull; import androidx.annotation.NonNull;
import android.support.v7.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import android.support.v7.widget.CardView; import androidx.cardview.widget.CardView;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -4,15 +4,19 @@ import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.support.v7.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import android.support.v7.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.io.File; import java.io.File;
@ -29,8 +33,60 @@ public class DeckPreviewActivity extends ReloadableAppCompatActivity {
private CardPreviewArrayAdapter cardArrayAdapter; private CardPreviewArrayAdapter cardArrayAdapter;
private ProgramakerApi ProgramakerApi = new ProgramakerApi(); private ProgramakerApi ProgramakerApi = new ProgramakerApi();
protected void openLoginForm(View view) { protected void openLoginDialog(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View loginDialog = (LayoutInflater.from(this)
.inflate(R.layout.login_dialog_view, null));
final EditText loginUsernameText = (EditText) loginDialog.findViewById(R.id.login_username_text);
final EditText loginPasswordText = (EditText) loginDialog.findViewById(R.id.login_password_text);
final Button loginButton = (Button) loginDialog.findViewById(R.id.login_dialog_login_button);
final Button cancelButton = (Button) loginDialog.findViewById(R.id.login_dialog_cancel_button);
final TextView messageLabel = (TextView) loginDialog.findViewById(R.id.login_message_label);
builder.setTitle("Login").setView(loginDialog);
final Dialog dialog = builder.create();
dialog.show();
cancelButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
dialog.cancel();
}
});
final TextWatcher watcher = (new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if ((messageLabel.getVisibility() != View.VISIBLE) &&
(loginUsernameText.getText().length() > 0) &&
(loginPasswordText.getText().length() > 0)) {
loginButton.setEnabled(true);
} else {
loginButton.setEnabled(false);
}
}
});
loginButton.setEnabled(false);
loginUsernameText.addTextChangedListener(watcher);
loginPasswordText.addTextChangedListener(watcher);
loginButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
messageLabel.setVisibility(View.VISIBLE);
messageLabel.setText(R.string.loading);
watcher.afterTextChanged(null);
}
});
} }
@Override @Override
@ -52,7 +108,7 @@ public class DeckPreviewActivity extends ReloadableAppCompatActivity {
loginButton.setOnClickListener(new View.OnClickListener() { loginButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
DeckPreviewActivity.this.openLoginForm(v); DeckPreviewActivity.this.openLoginDialog(v);
} }
}); });

View File

@ -3,7 +3,7 @@ package com.codigoparallevar.minicards;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v7.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import android.util.Log; import android.util.Log;
import com.codigoparallevar.minicards.parts.buttons.RoundButton; import com.codigoparallevar.minicards.parts.buttons.RoundButton;

View File

@ -1,6 +1,6 @@
package com.codigoparallevar.minicards; package com.codigoparallevar.minicards;
import android.support.v7.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
abstract class ReloadableAppCompatActivity extends AppCompatActivity { abstract class ReloadableAppCompatActivity extends AppCompatActivity {
public abstract void reload(); public abstract void reload();

View File

@ -4,7 +4,7 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.Rect; import android.graphics.Rect;
import android.support.annotation.NonNull; import androidx.annotation.NonNull;
import com.codigoparallevar.minicards.types.Tuple2; import com.codigoparallevar.minicards.types.Tuple2;

View File

@ -3,7 +3,7 @@ package com.codigoparallevar.minicards.parts.strings;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.support.annotation.NonNull; import androidx.annotation.NonNull;
import android.util.Log; import android.util.Log;
import com.codigoparallevar.minicards.PartInstantiator; import com.codigoparallevar.minicards.PartInstantiator;

View File

@ -1,6 +1,6 @@
package com.codigoparallevar.minicards.types.connectors.input; package com.codigoparallevar.minicards.types.connectors.input;
import android.support.annotation.NonNull; import androidx.annotation.NonNull;
import com.codigoparallevar.minicards.types.Moveable; import com.codigoparallevar.minicards.types.Moveable;
import com.codigoparallevar.minicards.types.Part; import com.codigoparallevar.minicards.types.Part;

View File

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.codigoparallevar.minicards.DeckPreviewActivity"> tools:context="com.codigoparallevar.minicards.DeckPreviewActivity">
<android.support.design.widget.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" /> app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_deck_preview" /> <include layout="@layout/content_deck_preview" />
<android.support.design.widget.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/create_new_card_fab" android:id="@+id/create_new_card_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -31,4 +31,4 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
app:srcCompat="@drawable/ic_add_black" /> app:srcCompat="@drawable/ic_add_black" />
</android.support.design.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
@ -30,7 +30,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:layout_editor_absoluteX="1dp" /> tools:layout_editor_absoluteX="1dp" />
<android.support.design.widget.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/remove_part_fab" android:id="@+id/remove_part_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -129,4 +129,4 @@
</com.getbase.floatingactionbutton.FloatingActionsMenu> </com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.v7.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/card_preview_card" android:id="@+id/card_preview_card"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -53,6 +53,6 @@
</RelativeLayout> </RelativeLayout>
</android.support.v7.widget.CardView> </androidx.cardview.widget.CardView>
</android.support.v7.widget.LinearLayoutCompat> </androidx.appcompat.widget.LinearLayoutCompat>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -8,7 +8,7 @@
tools:context="com.codigoparallevar.minicards.DeckPreviewActivity" tools:context="com.codigoparallevar.minicards.DeckPreviewActivity"
tools:showIn="@layout/activity_deck_preview"> tools:showIn="@layout/activity_deck_preview">
<android.support.v7.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/login_in_programaker_button" android:id="@+id/login_in_programaker_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -28,4 +28,4 @@
android:paddingTop="5dp" android:paddingTop="5dp"
app:layout_constraintTop_toBottomOf="@id/login_in_programaker_button" /> app:layout_constraintTop_toBottomOf="@id/login_in_programaker_button" />
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true">
<RelativeLayout
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/login_username_label"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:text="Username"
android:layout_alignBaseline="@id/login_username_text"
/>
<EditText
android:id="@+id/login_username_text"
android:layout_width="225dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_toRightOf="@id/login_username_label"
android:ems="10"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/login_password_label"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:text="Password"
android:layout_alignBaseline="@id/login_password_text"
/>
<EditText
android:id="@+id/login_password_text"
android:layout_width="225dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_toRightOf="@id/login_password_label"
android:ems="10"
android:inputType="textPassword"
android:text="" />
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/login_dialog_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="@color/colorAccent"
android:text="@string/action_login_short"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/login_dialog_cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="@android:color/transparent"
android:text="@android:string/cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/login_dialog_login_button"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/login_message_label"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View File

@ -11,4 +11,7 @@
<string name="invalid_username">Not a valid username</string> <string name="invalid_username">Not a valid username</string>
<string name="invalid_password">Password must be >5 characters</string> <string name="invalid_password">Password must be >5 characters</string>
<string name="login_failed">"Login failed"</string> <string name="login_failed">"Login failed"</string>
<string name="login_username_label">Username</string>
<string name="action_login_short">Login</string>
<string name="loading">Loading...</string>
</resources> </resources>

View File

@ -11,4 +11,6 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
#Fri Sep 27 08:37:30 PDT 2019 #Fri Sep 27 08:37:30 PDT 2019
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"