Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account view model state repository and api service #39

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main

abstract class NetworkBoundResource<ResponseObject, CacheObject, ViewStateType>
abstract class NetworkBoundResource<ResponseObject, ViewStateType>
(
isNetworkAvailable: Boolean, // is their a network connection?
isNetworkRequest: Boolean // is this a network request?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ constructor(
return returnErrorResponse(loginFieldErrors, ResponseType.Dialog())
}

return object: NetworkBoundResource<LoginResponse, Void, AuthViewState>(
return object: NetworkBoundResource<LoginResponse, AuthViewState>(
sessionManager.isConnectedToTheInternet(),
true
){
Expand Down Expand Up @@ -129,7 +129,7 @@ constructor(
return returnErrorResponse(registrationFieldErrors, ResponseType.Dialog())
}

return object: NetworkBoundResource<RegistrationResponse, Void, AuthViewState>(
return object: NetworkBoundResource<RegistrationResponse, AuthViewState>(
sessionManager.isConnectedToTheInternet(),
true
){
Expand Down Expand Up @@ -209,7 +209,7 @@ constructor(
return returnNoTokenFound()
}
else{
return object: NetworkBoundResource<Void, AccountProperties, AuthViewState>(
return object: NetworkBoundResource<Void, AuthViewState>(
sessionManager.isConnectedToTheInternet(),
false
){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.codingwithmitch.openapi.repository.main

import android.util.Log
import com.codingwithmitch.openapi.api.main.OpenApiMainService
import com.codingwithmitch.openapi.persistence.AccountPropertiesDao
import com.codingwithmitch.openapi.session.SessionManager
import kotlinx.coroutines.Job
import javax.inject.Inject

class AccountRepository
Expand All @@ -14,6 +16,15 @@ constructor(
)
{

private val TAG: String = "AppDebug"

private var repositoryJob: Job? = null


fun cancelActiveJobs(){
Log.d(TAG, "AuthRepository: Cancelling on-going jobs...")
repositoryJob?.cancel()
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codingwithmitch.openapi.ui.main.account

import androidx.lifecycle.LiveData
import com.codingwithmitch.openapi.models.AccountProperties
import com.codingwithmitch.openapi.repository.main.AccountRepository
import com.codingwithmitch.openapi.session.SessionManager
import com.codingwithmitch.openapi.ui.BaseViewModel
Expand Down Expand Up @@ -41,6 +42,15 @@ constructor(
return AccountViewState()
}

fun setAccountPropertiesData(accountProperties: AccountProperties){
val update = getCurrentViewStateOrNew()
if(update.accountProperties == accountProperties){
return
}
update.accountProperties = accountProperties
_viewState.value = update
}

fun logout(){
sessionManager.logout()
}
Expand Down