From 1cdc679c70cf55545171a07f811569b548bafebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Mon, 2 Mar 2020 22:10:22 +0100 Subject: [PATCH] WIP: Login form. --- app/build.gradle | 20 ++-- .../minicards/ExampleInstrumentedTest.java | 4 +- app/src/main/AndroidManifest.xml | 3 - .../minicards/CanvasView.java | 4 +- .../minicards/CardActivity.java | 6 +- .../codigoparallevar/minicards/CardFile.java | 2 +- .../minicards/CardPreviewArrayAdapter.java | 6 +- .../minicards/DeckPreviewActivity.java | 66 ++++++++++- .../minicards/PartsHolder.java | 2 +- .../ReloadableAppCompatActivity.java | 2 +- .../minicards/ScrolledCanvas.java | 2 +- .../parts/strings/ConvertToString.java | 2 +- .../connectors/input/AnyInputConnector.java | 2 +- .../main/res/layout/activity_deck_preview.xml | 12 +- app/src/main/res/layout/activity_main.xml | 6 +- app/src/main/res/layout/card_preview.xml | 8 +- .../main/res/layout/content_deck_preview.xml | 6 +- app/src/main/res/layout/login_dialog_view.xml | 111 ++++++++++++++++++ app/src/main/res/values/strings.xml | 3 + gradle.properties | 2 + 20 files changed, 219 insertions(+), 50 deletions(-) create mode 100644 app/src/main/res/layout/login_dialog_view.xml diff --git a/app/build.gradle b/app/build.gradle index 118e307..5dd9eec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,15 +3,15 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' android { - compileSdkVersion 25 + compileSdkVersion 29 buildToolsVersion "27.0.1" defaultConfig { applicationId "com.codigoparallevar.minicards" minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 29 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -23,18 +23,18 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:support-annotations:28.0.0' - implementation 'android.arch.lifecycle:extensions:1.1.1' - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation 'androidx.annotation:annotation:1.0.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' + androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { 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' - implementation 'com.android.support.constraint:constraint-layout:1.0.2' - implementation 'com.android.support:design:25.4.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.google.android.material:material:1.0.0' implementation 'com.getbase:floatingactionbutton:1.10.1' 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 'com.google.code.gson:gson:2.8.6' } diff --git a/app/src/androidTest/java/com/codigoparallevar/minicards/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/codigoparallevar/minicards/ExampleInstrumentedTest.java index 462e2a4..96d21a8 100644 --- a/app/src/androidTest/java/com/codigoparallevar/minicards/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/codigoparallevar/minicards/ExampleInstrumentedTest.java @@ -1,8 +1,8 @@ package com.codigoparallevar.minicards; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index caac83e..aa60a2f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,9 +15,6 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - diff --git a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java index 0a395d3..657fe65 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java @@ -4,8 +4,8 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; diff --git a/app/src/main/java/com/codigoparallevar/minicards/CardActivity.java b/app/src/main/java/com/codigoparallevar/minicards/CardActivity.java index 301a64b..ac142e4 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CardActivity.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CardActivity.java @@ -2,9 +2,9 @@ package com.codigoparallevar.minicards; import android.content.Context; import android.content.Intent; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; diff --git a/app/src/main/java/com/codigoparallevar/minicards/CardFile.java b/app/src/main/java/com/codigoparallevar/minicards/CardFile.java index ee796a7..6a8309e 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CardFile.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CardFile.java @@ -4,7 +4,7 @@ import android.annotation.TargetApi; import android.content.Context; import android.graphics.Color; import android.os.Build; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.util.Log; import com.codigoparallevar.minicards.parts.buttons.RoundButton; diff --git a/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java b/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java index 28a0997..7cefcbe 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java @@ -4,9 +4,9 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.support.annotation.NonNull; -import android.support.v7.app.AlertDialog; -import android.support.v7.widget.CardView; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.cardview.widget.CardView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; diff --git a/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java b/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java index 59925b5..c6f8386 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java +++ b/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java @@ -4,15 +4,19 @@ import android.app.Dialog; import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.app.AlertDialog; -import android.support.v7.widget.Toolbar; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.Toolbar; + +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; +import android.widget.TextView; import android.widget.Toast; import java.io.File; @@ -29,8 +33,60 @@ public class DeckPreviewActivity extends ReloadableAppCompatActivity { private CardPreviewArrayAdapter cardArrayAdapter; 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 @@ -52,7 +108,7 @@ public class DeckPreviewActivity extends ReloadableAppCompatActivity { loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - DeckPreviewActivity.this.openLoginForm(v); + DeckPreviewActivity.this.openLoginDialog(v); } }); diff --git a/app/src/main/java/com/codigoparallevar/minicards/PartsHolder.java b/app/src/main/java/com/codigoparallevar/minicards/PartsHolder.java index 4ccf298..375e96a 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/PartsHolder.java +++ b/app/src/main/java/com/codigoparallevar/minicards/PartsHolder.java @@ -3,7 +3,7 @@ package com.codigoparallevar.minicards; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.support.v7.app.AlertDialog; +import androidx.appcompat.app.AlertDialog; import android.util.Log; import com.codigoparallevar.minicards.parts.buttons.RoundButton; diff --git a/app/src/main/java/com/codigoparallevar/minicards/ReloadableAppCompatActivity.java b/app/src/main/java/com/codigoparallevar/minicards/ReloadableAppCompatActivity.java index c9082af..24c5a8d 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/ReloadableAppCompatActivity.java +++ b/app/src/main/java/com/codigoparallevar/minicards/ReloadableAppCompatActivity.java @@ -1,6 +1,6 @@ package com.codigoparallevar.minicards; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; abstract class ReloadableAppCompatActivity extends AppCompatActivity { public abstract void reload(); diff --git a/app/src/main/java/com/codigoparallevar/minicards/ScrolledCanvas.java b/app/src/main/java/com/codigoparallevar/minicards/ScrolledCanvas.java index 46e650e..28c8ed0 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/ScrolledCanvas.java +++ b/app/src/main/java/com/codigoparallevar/minicards/ScrolledCanvas.java @@ -4,7 +4,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.codigoparallevar.minicards.types.Tuple2; diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/strings/ConvertToString.java b/app/src/main/java/com/codigoparallevar/minicards/parts/strings/ConvertToString.java index dfa7fac..f7a1311 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/strings/ConvertToString.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/strings/ConvertToString.java @@ -3,7 +3,7 @@ package com.codigoparallevar.minicards.parts.strings; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.util.Log; import com.codigoparallevar.minicards.PartInstantiator; diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/AnyInputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/AnyInputConnector.java index a92dd15..fefc48e 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/AnyInputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/AnyInputConnector.java @@ -1,6 +1,6 @@ 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.Part; diff --git a/app/src/main/res/layout/activity_deck_preview.xml b/app/src/main/res/layout/activity_deck_preview.xml index 454b5e7..c5c966d 100644 --- a/app/src/main/res/layout/activity_deck_preview.xml +++ b/app/src/main/res/layout/activity_deck_preview.xml @@ -1,28 +1,28 @@ - - - - + - - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f718591..faf50de 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/card_preview.xml b/app/src/main/res/layout/card_preview.xml index 785f886..1ddbd79 100644 --- a/app/src/main/res/layout/card_preview.xml +++ b/app/src/main/res/layout/card_preview.xml @@ -1,11 +1,11 @@ - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/content_deck_preview.xml b/app/src/main/res/layout/content_deck_preview.xml index 0f293e1..b87a878 100644 --- a/app/src/main/res/layout/content_deck_preview.xml +++ b/app/src/main/res/layout/content_deck_preview.xml @@ -1,5 +1,5 @@ - - - + diff --git a/app/src/main/res/layout/login_dialog_view.xml b/app/src/main/res/layout/login_dialog_view.xml new file mode 100644 index 0000000..07cf6c7 --- /dev/null +++ b/app/src/main/res/layout/login_dialog_view.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + +