aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/build.gradle2
-rw-r--r--app/src/main/AndroidManifest.xml4
-rw-r--r--app/src/main/java/com/no_name/no_name/InitialActivity.kt38
-rw-r--r--app/src/main/java/com/no_name/no_name/LoginActivity.kt15
-rw-r--r--app/src/main/java/com/no_name/no_name/MainActivity.kt17
-rw-r--r--app/src/main/res/values/strings.xml1
6 files changed, 54 insertions, 23 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 363ef6f..186aadc 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -27,6 +27,8 @@ dependencies {
implementation 'com.kazakago.cryptore:cryptore:1.3.0'
implementation 'com.github.kittinunf.fuel:fuel-android:1.6.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation "org.jetbrains.anko:anko-commons:0.10.5"
+ implementation "org.jetbrains.anko:anko-design:0.10.5"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 29c7f56..1ce29c3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -17,7 +17,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup">
- <activity android:name=".InitialActivity">
+ <activity
+ android:name=".InitialActivity"
+ android:label="@string/loading">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/app/src/main/java/com/no_name/no_name/InitialActivity.kt b/app/src/main/java/com/no_name/no_name/InitialActivity.kt
index 9e7f27c..ee25d3d 100644
--- a/app/src/main/java/com/no_name/no_name/InitialActivity.kt
+++ b/app/src/main/java/com/no_name/no_name/InitialActivity.kt
@@ -1,39 +1,55 @@
package com.no_name.no_name
-import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.github.kittinunf.fuel.android.extension.responseJson
import com.github.kittinunf.fuel.core.FuelManager
import com.github.kittinunf.fuel.httpGet
import com.madapps.prefrences.EasyPrefrences
+import org.jetbrains.anko.alert
+import org.jetbrains.anko.startActivity
+import java.io.IOException
/**
* Activity which will be run before any other to verify user and choose which activity
* should be started next
*/
class InitialActivity : AppCompatActivity() {
+ private val server_address = "192.168.0.102"
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- FuelManager.instance.basePath = "http://192.168.0.59"
+ FuelManager.instance.basePath = "http://$server_address"
+ alert("Logging you in.", "Loading...") {
+ isCancelable = false
+ }.show()
verifyLogin()
}
+ @Throws(InterruptedException::class, IOException::class)
+ fun isConnected(): Boolean {
+ val command = "ping -c 1 google.com"
+ return Runtime.getRuntime().exec(command).waitFor() == 0
+ }
+
private fun verifyLogin() {
val accessToken: String? = SecureStorage(this@InitialActivity).get("access_token")
- var intent = Intent(this@InitialActivity, LoginActivity::class.java)
-
- if (accessToken != null) { // TODO: Check if user has internet connection, if not -> show MA without verification
+ // synced function of fuel doesn't work here (#331) -> ugly workaround
+ if (accessToken != null) {
val userID = EasyPrefrences(this@InitialActivity).getString("user_id")
- "/users/$userID".httpGet() // synced function of fuel doesn't work here (#331) -> ugly workaround
+ "/users/$userID".httpGet() // verify by making request to user api
.header("Authorization" to "Bearer $accessToken")
- .responseJson { _, _, result ->
- val (_, error) = result
- if (error == null) intent = Intent(this@InitialActivity, MainActivity::class.java)
- startActivity(intent)
+ .responseJson { _, response, result ->
+ val (_, serverError) = result
+ when {
+ response.httpStatusCode == 200 -> startActivity<MainActivity>()
+ !isConnected() -> startActivity<MainActivity>("notConnected" to true)
+ serverError != null -> startActivity<MainActivity>("serverDown" to true)
+ else -> startActivity<LoginActivity>()
+ }
}
} else {
- startActivity(intent)
+ startActivity<LoginActivity>()
}
}
} \ No newline at end of file
diff --git a/app/src/main/java/com/no_name/no_name/LoginActivity.kt b/app/src/main/java/com/no_name/no_name/LoginActivity.kt
index 78289b4..3076e39 100644
--- a/app/src/main/java/com/no_name/no_name/LoginActivity.kt
+++ b/app/src/main/java/com/no_name/no_name/LoginActivity.kt
@@ -6,7 +6,6 @@ import android.animation.AnimatorListenerAdapter
import android.annotation.TargetApi
import android.app.LoaderManager.LoaderCallbacks
import android.content.CursorLoader
-import android.content.Intent
import android.content.Loader
import android.content.pm.PackageManager
import android.database.Cursor
@@ -18,16 +17,16 @@ import android.provider.ContactsContract
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
-import android.view.Gravity
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.ArrayAdapter
import android.widget.TextView
-import android.widget.Toast
import com.github.kittinunf.fuel.android.extension.responseJson
import com.github.kittinunf.fuel.httpPost
import com.madapps.prefrences.EasyPrefrences
import kotlinx.android.synthetic.main.activity_login.*
+import org.jetbrains.anko.longToast
+import org.jetbrains.anko.startActivity
import org.json.JSONObject
import java.util.*
@@ -95,7 +94,6 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {
}
}
-
/**
* Attempts to sign in or register the account specified by the login form.
* If there are form errors (invalid email, missing fields, etc.), the
@@ -289,13 +287,8 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {
showProgress(false)
if (success!!) {
- val intent = Intent(this@LoginActivity, MainActivity::class.java)
- //intent.putExtra("keyIdentifier", value)
- startActivity(intent)
-
- val toast = Toast.makeText(this@LoginActivity, "Successfully logged in.", Toast.LENGTH_LONG)
- toast.setGravity(Gravity.CENTER, 0, 0)
- toast.show()
+ startActivity<MainActivity>()
+ longToast("Successfully logged in.")
} else {
password.error = getString(R.string.error_incorrect_password)
password.requestFocus()
diff --git a/app/src/main/java/com/no_name/no_name/MainActivity.kt b/app/src/main/java/com/no_name/no_name/MainActivity.kt
index f44e873..b7e61cd 100644
--- a/app/src/main/java/com/no_name/no_name/MainActivity.kt
+++ b/app/src/main/java/com/no_name/no_name/MainActivity.kt
@@ -5,6 +5,8 @@ import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_main.*
+import org.jetbrains.anko.alert
+import org.jetbrains.anko.longToast
/**
* Main activity aka home screen of app
@@ -18,6 +20,21 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
+ val serverDown = intent.getBooleanExtra("serverDown", false)
+ if (serverDown) {
+ alert("We are sorry, but our servers do not seem to be working at the moment. Please wait a few minutes before you try again.", "Sorry") {
+ positiveButton("Okay") {
+ finishAffinity() // TODO: Loading activity will somehow still be opened after close
+ System.exit(0)
+ }
+ }.show()
+ }
+
+ val notConnected = intent.getBooleanExtra("notConnected", false)
+ if (notConnected) {
+ longToast("No internet connection!")
+ }
+
fab.setOnClickListener { view ->
// TODO: Set FAB onclick event
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e25ea27..4840b69 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -15,4 +15,5 @@
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
+ <string name="loading">Loading...</string>
</resources>