Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f0b97423
authored
Sep 06, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved SignInActivity to Kotlin
parent
65462142
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
119 additions
and
131 deletions
.idea/vcs.xml
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/paktalin/vocabularynotebook/SignInActivity.java
app/src/main/java/com/paktalin/vocabularynotebook/SignInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/UserActivity.java
build.gradle
.idea/vcs.xml
0 → 100644
View file @
f0b97423
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
app/build.gradle
View file @
f0b97423
...
...
@@ -22,6 +22,7 @@ dependencies {
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
'com.android.support:appcompat-v7:28.0.0-rc02'
implementation
'com.android.support.constraint:constraint-layout:1.1.3'
implementation
"org.jetbrains.kotlin:kotlin-reflect:1.2.30"
implementation
'com.google.firebase:firebase-core:16.0.3'
implementation
'com.google.firebase:firebase-database:16.0.1'
...
...
@@ -34,3 +35,4 @@ dependencies {
}
apply
plugin:
'com.google.gms.google-services'
apply
plugin:
'kotlin-android'
\ No newline at end of file
app/src/main/AndroidManifest.xml
View file @
f0b97423
...
...
@@ -10,14 +10,14 @@
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
android:name=
".VocabularyApplication"
>
<activity
android:name=
".SignInActivity"
>
<activity
android:name=
".UserActivity"
/>
<activity
android:name=
".SignInActivity"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".UserActivity"
/>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/SignInActivity.java
deleted
100644 → 0
View file @
65462142
package
com
.
paktalin
.
vocabularynotebook
;
import
android.content.Intent
;
import
android.support.annotation.NonNull
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
com.google.android.gms.tasks.OnCompleteListener
;
import
com.google.android.gms.tasks.Task
;
import
com.google.firebase.auth.AuthResult
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
public
class
SignInActivity
extends
AppCompatActivity
{
private
static
final
String
TAG
=
"VN/"
+
SignInActivity
.
class
.
getSimpleName
();
private
EditText
mEmailEt
,
mPasswordEt
;
private
Button
mSignInBtn
,
mSignUpBtn
;
private
FirebaseAuth
mAuth
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_sign_in
);
initializeViews
();
mAuth
=
FirebaseAuth
.
getInstance
();
mSignInBtn
.
setOnClickListener
(
signInClickListener
);
mSignUpBtn
.
setOnClickListener
(
signUpClickListener
);
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
FirebaseUser
currentUser
=
mAuth
.
getCurrentUser
();
if
(
currentUser
!=
null
)
startUserActivity
();
}
private
void
initializeViews
()
{
mEmailEt
=
findViewById
(
R
.
id
.
email
);
mPasswordEt
=
findViewById
(
R
.
id
.
password
);
mSignInBtn
=
findViewById
(
R
.
id
.
btn_sign_in
);
mSignUpBtn
=
findViewById
(
R
.
id
.
btn_sign_up
);
}
private
View
.
OnClickListener
signInClickListener
=
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
signIn
();
}
};
private
View
.
OnClickListener
signUpClickListener
=
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
signUp
();
}
};
private
void
signIn
()
{
String
email
=
mEmailEt
.
getText
().
toString
();
String
password
=
mPasswordEt
.
getText
().
toString
();
if
(
fieldsNotEmpty
(
email
,
password
))
{
mAuth
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
AuthResult
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
AuthResult
>
task
)
{
if
(
task
.
isSuccessful
())
{
Log
.
d
(
TAG
,
"signInWithEmail:success"
);
startUserActivity
();
}
else
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
task
.
getException
());
Toast
.
makeText
(
SignInActivity
.
this
,
"Authentication failed."
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
}
}
private
void
signUp
()
{
String
email
=
mEmailEt
.
getText
().
toString
();
String
password
=
mPasswordEt
.
getText
().
toString
();
if
(
fieldsNotEmpty
(
email
,
password
))
{
mAuth
.
createUserWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
(
this
,
new
OnCompleteListener
<
AuthResult
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
AuthResult
>
task
)
{
if
(
task
.
isSuccessful
())
{
Log
.
d
(
TAG
,
"createUserWithEmail:success"
);
startUserActivity
();
}
else
{
Log
.
w
(
TAG
,
"createUserWithEmail:failure"
,
task
.
getException
());
Toast
.
makeText
(
SignInActivity
.
this
,
"Authentication failed."
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
}
}
private
void
startUserActivity
()
{
Intent
userActivityIntent
=
new
Intent
(
SignInActivity
.
this
,
UserActivity
.
class
);
startActivity
(
userActivityIntent
);
}
private
boolean
fieldsNotEmpty
(
String
email
,
String
password
)
{
if
(
TextUtils
.
isEmpty
(
email
)
||
TextUtils
.
isEmpty
(
password
))
{
Toast
.
makeText
(
SignInActivity
.
this
,
"Please, enter email and password"
,
Toast
.
LENGTH_SHORT
).
show
();
return
false
;
}
return
true
;
}
}
app/src/main/java/com/paktalin/vocabularynotebook/SignInActivity.kt
0 → 100644
View file @
f0b97423
package
com.paktalin.vocabularynotebook
import
android.content.Intent
import
android.support.v7.app.AppCompatActivity
import
android.os.Bundle
import
android.text.TextUtils
import
android.util.Log
import
android.view.View
import
android.widget.Button
import
android.widget.EditText
import
android.widget.Toast
import
com.google.android.gms.signin.SignIn
import
com.google.firebase.auth.FirebaseAuth
class
SignInActivity
:
AppCompatActivity
()
{
private
var
mEmailEt
:
EditText
?
=
null
private
var
mPasswordEt
:
EditText
?
=
null
private
var
mSignInBtn
:
Button
?
=
null
private
var
mSignUpBtn
:
Button
?
=
null
private
var
mAuth
:
FirebaseAuth
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_sign_in
)
initializeViews
()
mAuth
=
FirebaseAuth
.
getInstance
()
mSignInBtn
!!
.
setOnClickListener
({
signIn
()
})
mSignUpBtn
!!
.
setOnClickListener
({
signUp
()
})
}
override
fun
onStart
()
{
super
.
onStart
()
val
currentUser
=
mAuth
!!
.
currentUser
if
(
currentUser
!=
null
)
startUserActivity
()
}
private
fun
initializeViews
()
{
mEmailEt
=
findViewById
(
R
.
id
.
email
)
mPasswordEt
=
findViewById
(
R
.
id
.
password
)
mSignInBtn
=
findViewById
(
R
.
id
.
btn_sign_in
)
mSignUpBtn
=
findViewById
(
R
.
id
.
btn_sign_up
)
}
private
fun
signIn
()
{
val
email
=
mEmailEt
!!
.
text
.
toString
()
val
password
=
mPasswordEt
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
email
,
password
))
{
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
task
->
if
(
task
.
isSuccessful
)
startUserActivity
()
else
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
task
.
exception
)
Toast
.
makeText
(
this
@SignInActivity
,
"Authentication failed."
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
}
}
private
fun
signUp
()
{
val
email
=
mEmailEt
!!
.
text
.
toString
()
val
password
=
mPasswordEt
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
email
,
password
))
{
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
(
this
)
{
task
->
if
(
task
.
isSuccessful
)
startUserActivity
()
else
{
Log
.
w
(
TAG
,
"createUserWithEmail:failure"
,
task
.
exception
)
Toast
.
makeText
(
this
@SignInActivity
,
"Authentication failed."
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
}
}
private
fun
startUserActivity
()
{
Log
.
d
(
TAG
,
"Signed in successfully"
);
val
userActivityIntent
=
Intent
(
this
@SignInActivity
,
UserActivity
::
class
.
java
)
startActivity
(
userActivityIntent
)
}
private
fun
fieldsNotEmpty
(
email
:
String
,
password
:
String
):
Boolean
{
if
(
TextUtils
.
isEmpty
(
email
)
||
TextUtils
.
isEmpty
(
password
))
{
Toast
.
makeText
(
this
@SignInActivity
,
"Please, enter email and password"
,
Toast
.
LENGTH_SHORT
).
show
()
return
false
}
return
true
}
companion
object
{
private
val
TAG
=
"VN/"
+
SignIn
::
class
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/UserActivity.java
View file @
f0b97423
...
...
@@ -7,7 +7,7 @@ import android.support.v7.app.AppCompatActivity;
import
com.google.firebase.auth.FirebaseAuth
;
public
class
UserActivity
extends
AppCompatActivity
{
private
static
final
String
TAG
=
"VN/"
+
SignIn
Activity
.
class
.
getSimpleName
();
private
static
final
String
TAG
=
"VN/"
+
User
Activity
.
class
.
getSimpleName
();
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
...
...
build.gradle
View file @
f0b97423
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
{
ext
.
kotlin_version
=
'1.2.30'
repositories
{
google
()
jcenter
()
mavenCentral
()
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.1.4'
classpath
'com.google.gms:google-services:4.1.0'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment