Skip to content

Commit

Permalink
Merge branch 'mvvm_architecture' into loanAcc-detail-mvvm
Browse files Browse the repository at this point in the history
  • Loading branch information
PratyushSingh07 authored Jul 21, 2023
2 parents eb0c52c + a6a541d commit 7573f2e
Show file tree
Hide file tree
Showing 29 changed files with 1,172 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.mifos.mobile.repositories.NotificationRepositoryImp
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.repositories.LoanRepository
import org.mifos.mobile.repositories.LoanRepositoryImp
import org.mifos.mobile.repositories.NotificationRepository
import org.mifos.mobile.api.local.PreferencesHelper
import org.mifos.mobile.repositories.ClientRepository
import org.mifos.mobile.repositories.ClientRepositoryImp
import org.mifos.mobile.repositories.RecentTransactionRepository
import org.mifos.mobile.repositories.RecentTransactionRepositoryImp
import org.mifos.mobile.repositories.UserAuthRepository
import org.mifos.mobile.repositories.UserAuthRepositoryImp

Expand All @@ -23,4 +30,19 @@ class RepositoryModule {
fun providesLoanRepository(dataManager: DataManager): LoanRepository {
return LoanRepositoryImp(dataManager)
}

@Provides
fun providesNotificationRepository(dataManager: DataManager) : NotificationRepository {
return NotificationRepositoryImp(dataManager)
}

@Provides
fun providesClientRepository(preferencesHelper: PreferencesHelper): ClientRepository {
return ClientRepositoryImp(preferencesHelper)
}

@Provides
fun providesRecentTransactionRepository(dataManager: DataManager): RecentTransactionRepository {
return RecentTransactionRepositoryImp(dataManager)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mifos.mobile.repositories

interface ClientRepository {

fun updateAuthenticationToken(password: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.mifos.mobile.repositories

import okhttp3.Credentials
import org.mifos.mobile.api.BaseApiManager
import org.mifos.mobile.api.local.PreferencesHelper
import javax.inject.Inject

class ClientRepositoryImp @Inject constructor(private val preferencesHelper: PreferencesHelper) : ClientRepository {

override fun updateAuthenticationToken(password: String) {
val authenticationToken = Credentials.basic(preferencesHelper.userName!!, password)
preferencesHelper.saveToken(authenticationToken)
BaseApiManager.createService(
preferencesHelper.baseUrl,
preferencesHelper.tenant,
preferencesHelper.token,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mifos.mobile.repositories

import io.reactivex.Observable
import org.mifos.mobile.models.notification.MifosNotification

interface NotificationRepository {

fun loadNotifications(): Observable<List<MifosNotification?>?>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.mifos.mobile.repositories

import io.reactivex.Observable
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.models.notification.MifosNotification
import javax.inject.Inject

class NotificationRepositoryImp @Inject constructor(private val dataManager: DataManager) : NotificationRepository {

override fun loadNotifications(): Observable<List<MifosNotification?>?> {
return dataManager.notifications
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.mifos.mobile.repositories


import io.reactivex.Observable
import org.mifos.mobile.models.Page
import org.mifos.mobile.models.Transaction

interface RecentTransactionRepository {

fun recentTransactions(
offset: Int?,
limit: Int?
): Observable<Page<Transaction?>?>?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.mifos.mobile.repositories

import io.reactivex.Observable
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.models.Page
import org.mifos.mobile.models.Transaction
import javax.inject.Inject

class RecentTransactionRepositoryImp @Inject constructor(private val dataManager: DataManager) :
RecentTransactionRepository {

override fun recentTransactions(offset: Int?, limit: Int?): Observable<Page<Transaction?>?>? {
return limit?.let { offset?.let { it1 -> dataManager.getRecentTransactions(it1, it) } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ interface UserAuthRepository {
password: String?,
username: String?
): Observable<ResponseBody?>?

fun verifyUser(authenticationToken: String?, requestId: String?): Observable<ResponseBody?>?

fun updateAccountPassword(
newPassword: String, confirmPassword: String
): Observable<ResponseBody?>?

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.mifos.mobile.repositories
import io.reactivex.Observable
import okhttp3.ResponseBody
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.models.UpdatePasswordPayload
import org.mifos.mobile.models.register.RegisterPayload
import org.mifos.mobile.models.register.UserVerify
import javax.inject.Inject

class UserAuthRepositoryImp @Inject constructor(private val dataManager: DataManager) :
UserAuthRepository {
class UserAuthRepositoryImp @Inject constructor(private val dataManager: DataManager) : UserAuthRepository {

override fun registerUser(
accountNumber: String?,
Expand All @@ -31,4 +32,24 @@ class UserAuthRepositoryImp @Inject constructor(private val dataManager: DataMan
}
return dataManager.registerUser(registerPayload)
}

override fun verifyUser(authenticationToken: String?, requestId: String?): Observable<ResponseBody?>? {
val userVerify = UserVerify().apply {
this.authenticationToken = authenticationToken
this.requestId = requestId
}
return dataManager.verifyUser(userVerify)
}

override fun updateAccountPassword(
newPassword: String, confirmPassword: String
): Observable<ResponseBody?>? {
val payload = UpdatePasswordPayload().apply {
this.password = newPassword
this.repeatPassword = confirmPassword
}

return dataManager.updateAccountPassword(payload)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,31 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener
import com.github.therajanmaurya.sweeterror.SweetUIErrorHandler
import dagger.hilt.android.AndroidEntryPoint
import org.mifos.mobile.BuildConfig
import org.mifos.mobile.utils.NotificationUiState
import org.mifos.mobile.R
import org.mifos.mobile.databinding.FragmentNotificationBinding
import org.mifos.mobile.models.notification.MifosNotification
import org.mifos.mobile.presenters.NotificationPresenter
import org.mifos.mobile.ui.adapters.NotificationAdapter
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.ui.views.NotificationView
import org.mifos.mobile.utils.DividerItemDecoration
import org.mifos.mobile.utils.Network
import org.mifos.mobile.viewModels.NotificationViewModel
import javax.inject.Inject

/**
* Created by dilpreet on 13/9/17.
*/
@AndroidEntryPoint
class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener {
class NotificationFragment : BaseFragment(), OnRefreshListener {
private var _binding: FragmentNotificationBinding? = null
private val binding get() = _binding!!

@JvmField
@Inject
var presenter: NotificationPresenter? = null
private lateinit var viewModel : NotificationViewModel

@JvmField
@Inject
Expand All @@ -49,6 +47,7 @@ class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener
): View {
_binding = FragmentNotificationBinding.inflate(inflater, container, false)
val rootView = binding.root
viewModel = ViewModelProvider(this)[NotificationViewModel::class.java]
sweetUIErrorHandler = SweetUIErrorHandler(activity, rootView)
val layoutManager = LinearLayoutManager(activity)
layoutManager.orientation = LinearLayoutManager.VERTICAL
Expand All @@ -67,12 +66,11 @@ class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener
R.color.red_light,
)
binding.swipeNotificationContainer.setOnRefreshListener(this)
presenter?.attachView(this)
presenter?.loadNotifications()
loadNotifications()
return rootView
}

override fun showNotifications(notifications: List<MifosNotification?>?) {
private fun showNotifications(notifications: List<MifosNotification?>?) {
if (BuildConfig.DEBUG && notifications == null) {
error("Assertion failed")
}
Expand All @@ -88,7 +86,7 @@ class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener
}
}

override fun showError(msg: String?) {
fun showError(msg: String?) {
if (!Network.isConnected(activity)) {
sweetUIErrorHandler?.showSweetNoInternetUI(
binding.rvNotifications,
Expand All @@ -106,18 +104,37 @@ class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.notificationUiState.observe(viewLifecycleOwner) { state ->
when(state) {
NotificationUiState.Loading -> showProgress()
NotificationUiState.Error -> {
hideProgress()
showError(context?.getString(R.string.notification))
}
is NotificationUiState.LoadNotificationsSuccessful -> {
hideProgress()
showNotifications(state.notifications)
}
}
}

binding.layoutError.btnTryAgain.setOnClickListener {
retryClicked()
}
}

fun retryClicked() {
private fun loadNotifications() {
viewModel.loadNotifications()
}

private fun retryClicked() {
if (Network.isConnected(context)) {
sweetUIErrorHandler?.hideSweetErrorLayoutUI(
binding.rvNotifications,
binding.layoutError.root,
)
presenter?.loadNotifications()
loadNotifications()
} else {
Toast.makeText(
context,
Expand All @@ -127,11 +144,11 @@ class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener
}
}

override fun showProgress() {
fun showProgress() {
binding.swipeNotificationContainer.isRefreshing = true
}

override fun hideProgress() {
fun hideProgress() {
binding.swipeNotificationContainer.isRefreshing = false
}

Expand All @@ -140,7 +157,7 @@ class NotificationFragment : BaseFragment(), NotificationView, OnRefreshListener
binding.rvNotifications,
binding.layoutError.root,
)
presenter?.loadNotifications()
loadNotifications()
}

override fun onDestroyView() {
Expand Down
Loading

0 comments on commit 7573f2e

Please sign in to comment.