Skip to content

Commit

Permalink
Sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoukoul committed Jul 29, 2020
1 parent f337ebd commit fd82d1e
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ class AccountNicknameActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_accountnickname)
val prefs = getSharedPreferences("co.anode.AnodeVPN", Context.MODE_PRIVATE)
val prefsusername = prefs!!.getString("username","username")
val prefsusername = prefs!!.getString("username","")
usernameText = findViewById(R.id.editTextNickname)
usernameText?.setText(prefsusername)
if (prefsusername.isEmpty()) {
usernameGenerate().execute()
} else {
usernameText?.setText(prefsusername)
}

val generateusername: Button = findViewById(R.id.button_generateusername)
generateusername.setOnClickListener() {
usernameGenerate().execute()
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/co/anode/anodevpn/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class MainActivity : AppCompatActivity() {
AnodeClient.statustv = findViewById(R.id.textview_status)
AnodeClient.connectButton = findViewById(R.id.buttonconnectvpns)

with (prefs.edit()) {
putBoolean("SignedIn", false)
commit()
}
//Get Public Key ID for API Authorization
//AnodeClient.httpPostPubKeyRegistration("test","test")

Expand Down Expand Up @@ -196,6 +200,19 @@ class MainActivity : AppCompatActivity() {

}

override fun onResume() {
super.onResume()
val prefs = getSharedPreferences("co.anode.AnodeVPN", Context.MODE_PRIVATE)
val signedin = prefs.getBoolean("SignedIn", false)
val topUsername: TextView = findViewById(R.id.top_username)
if (signedin) {
val username = prefs.getString("username","")
topUsername.text = username
} else {
topUsername.text = ""
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean { // Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/java/co/anode/anodevpn/SignInActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.anode.anodevpn

import android.content.Context
import android.content.Intent
import android.os.AsyncTask
import android.os.Bundle
Expand All @@ -19,22 +20,22 @@ import org.json.JSONObject

class SignInActivity : AppCompatActivity() {
private val API_VERSION = "0.3"
private var API_SIGNIN_URL = "https://vpn.anode.co/api/$API_VERSION/vpn/accounts/authorize"
private var API_SIGNIN_URL = "https://vpn.anode.co/api/$API_VERSION/vpn/accounts/authorize/"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sign_in)

val signup: TextView = findViewById(R.id.textSignUp)
val link: Spanned = HtmlCompat.fromHtml("don't have an account yer? <a href='#'>Sign Up</a>", HtmlCompat.FROM_HTML_MODE_LEGACY)
val link: Spanned = HtmlCompat.fromHtml("don't have an account yet? <a href='#'>Sign Up</a>", HtmlCompat.FROM_HTML_MODE_LEGACY)
signup.movementMethod = LinkMovementMethod.getInstance()
signup.text = link

val signUpLink = findViewById<TextView>(R.id.textSignUp)
signUpLink.setMovementMethod(object : TextViewLinkHandler() {
override fun onLinkClick(url: String?) {
val accountActivity = Intent(applicationContext, AccountMainActivity::class.java)
startActivityForResult(accountActivity, 0)
val nicknameActivity = Intent(applicationContext, AccountNicknameActivity::class.java)
startActivityForResult(nicknameActivity, 0)
}
})

Expand Down Expand Up @@ -94,13 +95,19 @@ class SignInActivity : AppCompatActivity() {
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
Log.i(LOGTAG,"Received: $result")
if ((result.isNullOrBlank()) || (result.contains("Internal Server Error"))) {
if (result.isNullOrBlank()) {
Toast.makeText(baseContext, "User signed in successfully", Toast.LENGTH_SHORT).show()
val prefs = getSharedPreferences("co.anode.AnodeVPN", Context.MODE_PRIVATE)
with (prefs.edit()) {
putBoolean("SignedIn", true)
commit()
}
thread.start();
}
else if (result.contains("Internal Server Error")) {
finish()
} else if (result.contains("400") || result.contains("401")) {
Toast.makeText(baseContext, "Error: $result", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(baseContext, "User signed in successfully", Toast.LENGTH_SHORT).show()
thread.start();
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable-anydpi/ic_refresh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#666666">
<group android:scaleX="0.92"
android:scaleY="0.92"
android:translateX="0.96"
android:translateY="0.96">
<path
android:fillColor="@android:color/holo_green_dark"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</group>
</vector>
Binary file added app/src/main/res/drawable-hdpi/ic_refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 9 additions & 10 deletions app/src/main/res/layout/activity_accountnickname.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_generateusername"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="0dp"
android:background="@drawable/ic_refresh"
app:layout_constraintBottom_toBottomOf="@+id/editTextNickname"
app:layout_constraintStart_toEndOf="@+id/editTextNickname"/>

<CheckBox
android:id="@+id/checkBoxDataPolicy"
Expand All @@ -31,16 +40,6 @@
tools:layout_editor_absoluteX="103dp"
tools:layout_editor_absoluteY="311dp" />

<Button
android:id="@+id/button_generateusername"
android:text="GENERATE USERNAME"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
app:layout_constraintBottom_toTopOf="@+id/button_continue"/>

<Button
android:id="@+id/button_continue"
android:text="CONTINUE"
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

<TextView
android:id="@+id/top_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="-20dp"
android:layout_marginEnd="40dp"
android:text=""/>
</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_main" />
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_sign_in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
android:hint="@string/prompt_password" />
</com.google.android.material.textfield.TextInputLayout>

<TextView
<!--<TextView
android:id="@+id/textForgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="forgot password?"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="@id/passwordLayout"
app:layout_constraintTop_toBottomOf="@id/passwordLayout" />
app:layout_constraintTop_toBottomOf="@id/passwordLayout" />-->

<Button
android:id="@+id/buttonSingIn"
Expand Down

0 comments on commit fd82d1e

Please sign in to comment.