aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap')
-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
4 files changed, 34 insertions, 11 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) {