Set base for adding login.
This commit is contained in:
parent
a02d372b90
commit
9fb10281cb
@ -1,4 +1,6 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
@ -21,6 +23,8 @@ 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', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
@ -28,7 +32,12 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
implementation 'com.android.support:design:25.4.0'
|
||||
compile 'com.getbase:floatingactionbutton:1.10.1'
|
||||
compile 'com.larswerkman:HoloColorPicker:1.5'
|
||||
implementation 'com.getbase:floatingactionbutton:1.10.1'
|
||||
implementation 'com.larswerkman:HoloColorPicker:1.5'
|
||||
implementation 'com.android.support:cardview-v7:25.4.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.codigoparallevar.minicards">
|
||||
|
||||
<!-- OpenGL ES 2.0 -->
|
||||
|
||||
<uses-feature
|
||||
android:glEsVersion="0x00020000"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@ -15,9 +15,13 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".ui.login.LoginActivity"
|
||||
android:label="@string/title_activity_login"></activity>
|
||||
<activity android:name=".CardActivity">
|
||||
<intent-filter>
|
||||
<action android:name="com.codigoparallevar.minicards.CARD" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@ -26,10 +30,12 @@
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.codigoparallevar.minicards.DECK" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
@ -2,6 +2,7 @@ package com.codigoparallevar.minicards;
|
||||
|
||||
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;
|
||||
@ -9,6 +10,7 @@ import android.support.v7.widget.Toolbar;
|
||||
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.Toast;
|
||||
@ -18,11 +20,18 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.programaker.api.ProgramakerApi;
|
||||
|
||||
public class DeckPreviewActivity extends ReloadableAppCompatActivity {
|
||||
|
||||
public static final String INTENT = "com.codigoparallevar.minicards.DECK";
|
||||
private ListView listView;
|
||||
private CardPreviewArrayAdapter cardArrayAdapter;
|
||||
private ProgramakerApi ProgramakerApi = new ProgramakerApi();
|
||||
|
||||
protected void openLoginForm(View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -39,7 +48,26 @@ public class DeckPreviewActivity extends ReloadableAppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
Button loginButton = (Button) findViewById(R.id.login_in_programaker_button);
|
||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DeckPreviewActivity.this.openLoginForm(v);
|
||||
}
|
||||
});
|
||||
|
||||
listView = (ListView) findViewById(R.id.card_deck_list);
|
||||
|
||||
|
||||
new AsyncTask<ProgramakerApi, Void, Boolean>() {
|
||||
protected Boolean doInBackground(ProgramakerApi... api) {
|
||||
return api[0].Check();
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean result) {
|
||||
Log.d("MiniCards", "check result: " + result);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this.ProgramakerApi);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
72
app/src/main/java/com/programaker/api/ProgramakerApi.kt
Normal file
72
app/src/main/java/com/programaker/api/ProgramakerApi.kt
Normal file
@ -0,0 +1,72 @@
|
||||
package com.programaker.api
|
||||
|
||||
import android.os.Build
|
||||
import android.util.JsonReader
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.io.*
|
||||
import java.lang.reflect.Type
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.net.URLConnection
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
||||
|
||||
class ProgramakerApi(private val ApiRoot: String="https://programaker.com/api") {
|
||||
private val LogTag: String = "ProgramakerApi"
|
||||
private val TokenEntry: String = "ProgramakerAuthToken"
|
||||
|
||||
// API
|
||||
fun Check(): Boolean {
|
||||
val conn = URL(getCheckUrl()).openConnection() as HttpURLConnection
|
||||
if (conn == null){
|
||||
Log.e(LogTag, "URL Connection not established, set to NULL")
|
||||
return false
|
||||
}
|
||||
try {
|
||||
addAuthHeader(conn)
|
||||
} catch(ex: TokenNotFoundException) {
|
||||
return false
|
||||
}
|
||||
|
||||
val result: ProgramakerCheckResult
|
||||
try {
|
||||
result = parseJson(conn.inputStream, ProgramakerCheckResult::class.java)
|
||||
} catch(ex: JsonParseException) {
|
||||
ex.logError(LogTag)
|
||||
return false
|
||||
}
|
||||
return result.success
|
||||
}
|
||||
|
||||
// Initialization
|
||||
init {
|
||||
// Disable connection reuse if necessary
|
||||
// HTTP connection reuse which was buggy pre-froyo
|
||||
if (Build.VERSION.SDK.toInt() < Build.VERSION_CODES.FROYO) {
|
||||
System.setProperty("http.keepAlive", "false")
|
||||
}
|
||||
}
|
||||
|
||||
// Private functions
|
||||
private fun getCheckUrl(): String {
|
||||
return "$ApiRoot/v0/ping"
|
||||
}
|
||||
|
||||
private fun addAuthHeader(conn: URLConnection) {
|
||||
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
private fun <T>parseJson(content: InputStream, resultClass: Type): T {
|
||||
val reader = InputStreamReader(content)
|
||||
val gson = Gson()
|
||||
return gson.fromJson(reader, resultClass)
|
||||
}
|
||||
}
|
||||
|
||||
class JsonParseException(private val content: String, private val cls: Type) : Exception() {
|
||||
fun logError(tag: String) {
|
||||
Log.e(tag, "Cannot JSON parse: ${this.content} as ${this.cls}")
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.programaker.api
|
||||
|
||||
class ProgramakerCheckResult(val success: Boolean) {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.programaker.api
|
||||
|
||||
open class ProgramakerConfigurationException : Exception() {
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.programaker.api
|
||||
|
||||
class TokenNotFoundException : ProgramakerConfigurationException() {
|
||||
}
|
@ -11,23 +11,23 @@
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="10dp"
|
||||
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingRight="15dp"
|
||||
android:paddingBottom="5dp"
|
||||
card_view:cardCornerRadius="5dp"
|
||||
card_view:cardPreventCornerOverlap="true"
|
||||
card_view:cardElevation="10dp"
|
||||
card_view:cardUseCompatPadding="true"
|
||||
tools:layout_editor_absoluteX="8dp"
|
||||
tools:layout_editor_absoluteY="3dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:minHeight="100dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="100dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_preview_name"
|
||||
@ -44,9 +44,9 @@
|
||||
android:id="@+id/card_preview_settings_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:alpha="1"
|
||||
android:clickable="true"
|
||||
android:src="@drawable/ic_settings_gray" />
|
||||
|
@ -8,12 +8,24 @@
|
||||
tools:context="com.codigoparallevar.minicards.DeckPreviewActivity"
|
||||
tools:showIn="@layout/activity_deck_preview">
|
||||
|
||||
<android.support.v7.widget.AppCompatButton
|
||||
android:id="@+id/login_in_programaker_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#FFFFFF"
|
||||
android:text="@string/login_in_programaker"
|
||||
android:textAllCaps="false"
|
||||
app:backgroundTint="@color/colorAccent"
|
||||
app:layout_constraintBottom_toTopOf="@id/card_deck_list"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/card_deck_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@null"
|
||||
android:dividerHeight="2dp"
|
||||
android:paddingTop="5dp"
|
||||
android:dividerHeight="2dp" />
|
||||
app:layout_constraintTop_toBottomOf="@id/login_in_programaker_button" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
@ -1,3 +1,6 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
||||
|
@ -1,4 +1,14 @@
|
||||
<resources>
|
||||
<string name="app_name">mini-cards</string>
|
||||
<string name="title_activity_deck_preview">DeckPreviewActivity</string>
|
||||
<string name="login_in_programaker">Login in PrograMaker</string>
|
||||
<string name="title_activity_login">Sign in</string>
|
||||
<string name="prompt_email">Email</string>
|
||||
<string name="prompt_password">Password</string>
|
||||
<string name="action_sign_in">Sign in or register</string>
|
||||
<string name="action_sign_in_short">Sign in</string>
|
||||
<string name="welcome">"Welcome !"</string>
|
||||
<string name="invalid_username">Not a valid username</string>
|
||||
<string name="invalid_password">Password must be >5 characters</string>
|
||||
<string name="login_failed">"Login failed"</string>
|
||||
</resources>
|
||||
|
@ -1,13 +1,15 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.61'
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.android.tools.build:gradle:3.6.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
Loading…
Reference in New Issue
Block a user