-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
327 additions
and
203 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package fr.geonature.sync.api | ||
|
||
import fr.geonature.sync.api.model.Taxref | ||
import okhttp3.ResponseBody | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
|
||
/** | ||
* TaxHub API interface definition. | ||
* | ||
* @author [S. Grimault](mailto:[email protected]) | ||
*/ | ||
interface TaxHubService { | ||
|
||
@GET("api/taxref/regnewithgroupe2") | ||
fun getTaxonomyRanks(): Call<ResponseBody> | ||
|
||
// TODO: fetch all taxa | ||
@GET("api/taxref/allnamebylist/100") | ||
fun getTaxref(): Call<List<Taxref>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package fr.geonature.sync.auth | |
import android.app.Application | ||
import android.text.TextUtils | ||
import androidx.annotation.StringRes | ||
import androidx.lifecycle.AndroidViewModel | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
|
@@ -15,7 +16,6 @@ import fr.geonature.sync.api.GeoNatureAPIClient | |
import fr.geonature.sync.api.model.AuthCredentials | ||
import fr.geonature.sync.api.model.AuthLogin | ||
import fr.geonature.sync.api.model.AuthLoginError | ||
import fr.geonature.sync.util.SettingsUtils | ||
import kotlinx.coroutines.launch | ||
import retrofit2.Response | ||
|
||
|
@@ -24,10 +24,10 @@ import retrofit2.Response | |
* | ||
* @author [S. Grimault](mailto:[email protected]) | ||
*/ | ||
class AuthLoginViewModel(application: Application) : ViewModel() { | ||
class AuthLoginViewModel(application: Application) : AndroidViewModel(application) { | ||
|
||
private val authManager: AuthManager = AuthManager.getInstance(application) | ||
private var geoNatureAPIClient: GeoNatureAPIClient? = null | ||
private val geoNatureAPIClient: GeoNatureAPIClient? = GeoNatureAPIClient.instance(application) | ||
|
||
private val _loginFormState = MutableLiveData<LoginFormState>() | ||
val loginFormState: LiveData<LoginFormState> = _loginFormState | ||
|
@@ -38,22 +38,25 @@ class AuthLoginViewModel(application: Application) : ViewModel() { | |
val isLoggedIn: LiveData<Boolean> = authManager.isLoggedIn | ||
|
||
init { | ||
SettingsUtils.getGeoNatureServerUrl(application) | ||
?.also { | ||
geoNatureAPIClient = GeoNatureAPIClient.instance( | ||
application, | ||
it | ||
) | ||
.value | ||
} | ||
if (geoNatureAPIClient == null) { | ||
_loginResult.value = LoginResult(error = R.string.login_failed_server_url_configuration) | ||
_loginFormState.value = LoginFormState( | ||
isValid = false, | ||
usernameError = null, | ||
passwordError = null | ||
) | ||
} | ||
} | ||
|
||
fun login( | ||
username: String, | ||
password: String, | ||
applicationId: Int | ||
) { | ||
val geoNatureAPIClient = geoNatureAPIClient ?: return | ||
if (geoNatureAPIClient == null) { | ||
_loginResult.value = LoginResult(error = R.string.login_failed_server_url_configuration) | ||
return | ||
} | ||
|
||
viewModelScope.launch { | ||
try { | ||
|
@@ -112,7 +115,11 @@ class AuthLoginViewModel(application: Application) : ViewModel() { | |
return | ||
} | ||
|
||
_loginFormState.value = LoginFormState(isValid = true) | ||
_loginFormState.value = LoginFormState( | ||
isValid = true, | ||
usernameError = null, | ||
passwordError = null | ||
) | ||
} | ||
|
||
fun logout(): LiveData<Boolean> { | ||
|
Oops, something went wrong.