aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-20 20:43:14 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-20 20:43:14 -0600
commit7da841d2de9ac0526c3863e85d7d603facabb95c (patch)
tree57f9ad1386fe89d622f4c219d1dc25d0637f5860 /androidApp/src/main
parentd3fbda46d35ef58deb8c8965a2c6f937f204d980 (diff)
downloadetbsa-trackermap-mobile-7da841d2de9ac0526c3863e85d7d603facabb95c.tar.gz
etbsa-trackermap-mobile-7da841d2de9ac0526c3863e85d7d603facabb95c.tar.bz2
etbsa-trackermap-mobile-7da841d2de9ac0526c3863e85d7d603facabb95c.zip
Implemented feature to switch to different Traccar servers by URL and removed annoying auto-generated redundant qualifiers
Diffstat (limited to 'androidApp/src/main')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt15
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt21
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt4
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt5
-rw-r--r--androidApp/src/main/res/layout/login.xml29
-rw-r--r--androidApp/src/main/res/layout/user_information_activity.xml14
-rw-r--r--androidApp/src/main/res/values-es-rMX/strings.xml2
-rw-r--r--androidApp/src/main/res/values/strings.xml3
8 files changed, 78 insertions, 15 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
index 1811733..2901dbb 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt
@@ -29,14 +29,13 @@ open class TrackerApp : Application() {
super.onCreate()
val appModule = module {
- single { "https://etbsa.net/api" }
- factory { SessionApi(get()) }
- factory { UsersApi(get()) }
- factory { DevicesApi(get()) }
- factory { PositionsApi(get()) }
- factory { CommandsApi(get()) }
- factory { ReportsApi(get()) }
- factory { GeofencesApi(get()) }
+ factory { SessionApi() }
+ factory { UsersApi() }
+ factory { DevicesApi() }
+ factory { PositionsApi() }
+ factory { CommandsApi() }
+ factory { ReportsApi() }
+ factory { GeofencesApi() }
factory { SessionController(get(), get()) }
factory { UnitsController(get(), get()) }
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt
index f1b23a6..c87e134 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt
@@ -7,7 +7,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
-import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
@@ -43,6 +42,14 @@ class LoginFragment : Fragment() {
setupEvents()
setupObservers()
broadcastManager = LocalBroadcastManager.getInstance(activity!!)
+ binding.urlEditText.setText(
+ PreferenceManager
+ .getDefaultSharedPreferences(activity)
+ .getString(
+ PREFERENCE_SERVER_URL,
+ getString(R.string.default_server_url)
+ ) ?: getString(R.string.default_server_url)
+ )
loginViewModel.restoreSession()
}
@@ -67,6 +74,7 @@ class LoginFragment : Fragment() {
loginViewModel.login(
binding.usernameEditText.text.toString(),
binding.passwordEditText.text.toString(),
+ binding.urlEditText.text.toString(),
PreferenceManager
.getDefaultSharedPreferences(activity)
.getString(PREFERENCE_TOKEN, null)
@@ -84,6 +92,10 @@ class LoginFragment : Fragment() {
SessionController.LoginState.Loading -> {
binding.infoLoading.root.visibility = View.VISIBLE
}
+ SessionController.LoginState.UrlMissing -> {
+ binding.infoLoading.root.visibility = View.GONE
+ Toast.makeText(context, getString(R.string.login_url_missing), Toast.LENGTH_SHORT).show()
+ }
SessionController.LoginState.EmailMissing -> {
binding.infoLoading.root.visibility = View.GONE
Toast.makeText(context, getString(R.string.login_username_missing), Toast.LENGTH_SHORT).show()
@@ -97,6 +109,12 @@ class LoginFragment : Fragment() {
Toast.makeText(context, getString(R.string.login_login_failed), Toast.LENGTH_SHORT).show()
}
SessionController.LoginState.Success -> {
+ PreferenceManager
+ .getDefaultSharedPreferences(activity)
+ .edit()
+ .putString(PREFERENCE_SERVER_URL, binding.urlEditText.text.toString())
+ .apply()
+
broadcastManager.sendBroadcast(Intent(EVENT_LOGIN))
val activity = requireActivity()
val intent = Intent(activity.applicationContext, UnitsActivity::class.java)
@@ -126,6 +144,7 @@ class LoginFragment : Fragment() {
const val EVENT_TOKEN = "eventToken"
const val KEY_TOKEN = "keyToken"
+ const val PREFERENCE_SERVER_URL = "server_url"
const val PREFERENCE_TOKEN = "token"
}
} \ No newline at end of file
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt
index 88b56cf..b5516e7 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt
@@ -40,7 +40,7 @@ class LoginViewModel : ViewModel(), KoinComponent {
sessionController.restoreSession()
}
- fun login(email: String, password: String, token: String?) {
- sessionController.login(SessionBody(email, password, token))
+ fun login(email: String, password: String, url: String, token: String?) {
+ sessionController.login(SessionBody(url, email, password, token))
}
} \ No newline at end of file
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt
index 5fad118..81577c7 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt
@@ -65,6 +65,11 @@ class UserInformationActivity : AppCompatActivity() {
emailInfo.text = user.email ?: ""
idInfo.text = "${user.id ?: "--"}"
adminInfo.text = "${user.administrator}"
+ serverInfo.text = "${
+ PreferenceManager
+ .getDefaultSharedPreferences(this@UserInformationActivity)
+ .getString(LoginFragment.PREFERENCE_SERVER_URL, getString(R.string.default_server_url))
+ }"
user.deviceLimit?.let {
deviceLimitInfo.text = "${user.deviceLimit ?: "--"}"
if (it > 0) {
diff --git a/androidApp/src/main/res/layout/login.xml b/androidApp/src/main/res/layout/login.xml
index 7c79e5c..78c3e46 100644
--- a/androidApp/src/main/res/layout/login.xml
+++ b/androidApp/src/main/res/layout/login.xml
@@ -70,8 +70,8 @@
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/usernameInputLayout"
- app:layout_constraintBottom_toTopOf="@id/signinButton"
- android:layout_marginTop="24dp">
+ app:layout_constraintBottom_toTopOf="@id/urlInputLayout"
+ android:layout_marginTop="@dimen/fields_spacing">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/passwordEditText"
@@ -81,17 +81,38 @@
</com.google.android.material.textfield.TextInputLayout>
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/urlInputLayout"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/login_url"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/passwordInputLayout"
+ app:layout_constraintBottom_toTopOf="@id/signinButton"
+ android:layout_marginTop="@dimen/fields_spacing">
+
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/urlEditText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="textUri"/>
+
+ </com.google.android.material.textfield.TextInputLayout>
+
<com.google.android.material.button.MaterialButton
android:id="@+id/signinButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_percent="0.5"
- app:layout_constraintTop_toBottomOf="@id/passwordInputLayout"
+ app:layout_constraintTop_toBottomOf="@id/urlInputLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
- android:layout_marginTop="24dp"
+ android:layout_marginTop="@dimen/fields_large_spacing"
android:text="@string/login_login"/>
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/androidApp/src/main/res/layout/user_information_activity.xml b/androidApp/src/main/res/layout/user_information_activity.xml
index 45e747c..f223522 100644
--- a/androidApp/src/main/res/layout/user_information_activity.xml
+++ b/androidApp/src/main/res/layout/user_information_activity.xml
@@ -131,6 +131,20 @@
android:layout_marginBottom="@dimen/fields_spacing"
tools:text="Admin" />
+ <TextView
+ android:id="@+id/serverInfoLabel"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/login_url"
+ android:textAppearance="@style/TextAppearance.AppCompat.Body2"/>
+
+ <TextView
+ android:id="@+id/serverInfo"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="@dimen/fields_spacing"
+ tools:text="@string/default_server_url" />
+
<com.google.android.material.button.MaterialButton
android:id="@+id/signoutButton"
android:layout_width="match_parent"
diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml
index 2645205..8792b08 100644
--- a/androidApp/src/main/res/values-es-rMX/strings.xml
+++ b/androidApp/src/main/res/values-es-rMX/strings.xml
@@ -10,10 +10,12 @@
<!-- LoginActivity -->
<string name="login_username">Nombre de usuario</string>
<string name="login_password">Contraseña</string>
+ <string name="login_url">URL del servidor</string>
<string name="login_login">Iniciar sesión</string>
<string name="login_username_missing">Falta el nombre de usuario</string>
<string name="login_password_missing">Falta la contraseña</string>
+ <string name="login_url_missing">Falta la URL del servidor</string>
<string name="login_login_failed">Falló el inicio de sesión</string>
<!-- UnitsActivity -->
diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml
index 8e59b14..a6cba19 100644
--- a/androidApp/src/main/res/values/strings.xml
+++ b/androidApp/src/main/res/values/strings.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">TrackerMap</string>
+ <string name="default_server_url" translatable="false">https://gps.trackermap.mx/api</string>
<!-- Non translatable -->
<string name="app_website_url" translatable="false">https://trackermap.mx/</string>
@@ -23,10 +24,12 @@
<!-- LoginActivity -->
<string name="login_username">Username</string>
<string name="login_password">Password</string>
+ <string name="login_url">Server URL</string>
<string name="login_login">Login</string>
<string name="login_username_missing">Username is missing</string>
<string name="login_password_missing">Password is missing</string>
+ <string name="login_url_missing">Server URL is missing</string>
<string name="login_login_failed">Login failed</string>
<!-- UnitsActivity -->