-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AC-1050: Migrate login package from MVP to MVVM architecture
- Loading branch information
Showing
19 changed files
with
1,094 additions
and
1,208 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
...droid-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/LoginRepository.kt
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,31 @@ | ||
package com.openmrs.android_sdk.library.api.repository | ||
|
||
import com.openmrs.android_sdk.library.api.RestApi | ||
import com.openmrs.android_sdk.library.api.RestServiceBuilder | ||
import com.openmrs.android_sdk.library.databases.AppDatabaseHelper.createObservableIO | ||
import com.openmrs.android_sdk.library.models.Session | ||
import rx.Observable | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import java.util.concurrent.Callable | ||
|
||
@Singleton | ||
class LoginRepository @Inject constructor() : BaseRepository() { | ||
|
||
/** | ||
* Gets an authenticated session by username and password. | ||
* | ||
* @param username authenticated username | ||
* @param password authenticated password | ||
* @return observable session | ||
*/ | ||
fun getSession(username: String, password: String): Observable<Session> { | ||
return createObservableIO(Callable { | ||
restApi = RestServiceBuilder.createService(RestApi::class.java, username, password) | ||
restApi.getSession().execute().run { | ||
if (isSuccessful && body() != null) return@Callable body()!! | ||
else throw Exception("Error fetching session: ${message()}") | ||
} | ||
}) | ||
} | ||
} |
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
32 changes: 0 additions & 32 deletions
32
.../java/com/openmrs/android_sdk/library/listeners/retrofitcallbacks/GetVisitTypeCallback.kt
This file was deleted.
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
72 changes: 0 additions & 72 deletions
72
openmrs-client/src/main/java/org/openmrs/mobile/activities/login/LoginActivity.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
openmrs-client/src/main/java/org/openmrs/mobile/activities/login/LoginActivity.kt
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,53 @@ | ||
/* | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.mobile.activities.login | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.Menu | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import org.openmrs.mobile.R | ||
import org.openmrs.mobile.activities.ACBaseActivity | ||
|
||
@AndroidEntryPoint | ||
class LoginActivity : ACBaseActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_login) | ||
|
||
supportActionBar?.run { | ||
elevation = 0f | ||
setTitle(R.string.app_name) | ||
} | ||
|
||
// Create fragment | ||
var loginFragment = supportFragmentManager.findFragmentById(R.id.loginContentFrame) as LoginFragment? | ||
if (loginFragment == null) { | ||
loginFragment = LoginFragment.newInstance() | ||
} | ||
if (!loginFragment.isActive) { | ||
addFragmentToActivity(supportFragmentManager, loginFragment, R.id.loginContentFrame) | ||
} | ||
} | ||
|
||
override fun onBackPressed() { | ||
val intent = Intent(Intent.ACTION_MAIN) | ||
intent.addCategory(Intent.CATEGORY_HOME) | ||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
startActivity(intent) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean = true | ||
} |
Oops, something went wrong.