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

refactor: migrate notfication from java to kotlin #1461

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.mifos.mobilewallet.mifospay.notification

import org.mifos.mobilewallet.core.domain.model.NotificationPayload
import org.mifos.mobilewallet.mifospay.base.BasePresenter
import org.mifos.mobilewallet.mifospay.base.BaseView

/**
* Created by ankur on 24/July/2018
*/
interface NotificationContract {
interface NotificationPresenter : BasePresenter {
fun fetchNotifications()
}

interface NotificationView : BaseView<NotificationPresenter?> {
fun fetchNotificationsSuccess(notificationPayloadList: List<NotificationPayload?>?)
fun fetchNotificationsError(message: String?)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.mifos.mobilewallet.mifospay.notification.presenter

import org.mifos.mobilewallet.core.base.UseCase.UseCaseCallback
import org.mifos.mobilewallet.core.base.UseCaseHandler
import org.mifos.mobilewallet.core.domain.usecase.notification.FetchNotifications
import org.mifos.mobilewallet.mifospay.base.BaseView
import org.mifos.mobilewallet.mifospay.data.local.LocalRepository
import org.mifos.mobilewallet.mifospay.notification.NotificationContract
import org.mifos.mobilewallet.mifospay.notification.NotificationContract.NotificationView
import javax.inject.Inject

/**
* Created by ankur on 24/July/2018
*/
class NotificationPresenter @Inject constructor(
private val mUseCaseHandler: UseCaseHandler,
private val mLocalRepository: LocalRepository
) : NotificationContract.NotificationPresenter {
var mNotificationView: NotificationView? = null

@JvmField
@Inject
var fetchNotificationsUseCase: FetchNotifications? = null
override fun attachView(baseView: BaseView<*>?) {
mNotificationView = baseView as NotificationView?
mNotificationView?.setPresenter(this)
}

override fun fetchNotifications() {
mUseCaseHandler.execute(fetchNotificationsUseCase,
FetchNotifications.RequestValues(
mLocalRepository.clientDetails.clientId
),
object : UseCaseCallback<FetchNotifications.ResponseValue?> {
override fun onSuccess(response: FetchNotifications.ResponseValue?) {
mNotificationView?.fetchNotificationsSuccess(
response?.notificationPayloadList
)
}

override fun onError(message: String) {
mNotificationView?.fetchNotificationsError(message)
}
})
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.mifos.mobilewallet.mifospay.notification.ui

import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import dagger.hilt.android.AndroidEntryPoint
import org.mifos.mobilewallet.core.domain.model.NotificationPayload
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.base.BaseActivity
import org.mifos.mobilewallet.mifospay.notification.NotificationContract
import org.mifos.mobilewallet.mifospay.notification.NotificationContract.NotificationView
import org.mifos.mobilewallet.mifospay.notification.presenter.NotificationPresenter
import org.mifos.mobilewallet.mifospay.utils.Constants
import org.mifos.mobilewallet.mifospay.utils.DebugUtil
import org.mifos.mobilewallet.mifospay.utils.Toaster
import javax.inject.Inject

/**
* This activity is to view notifications record.
* Notifications Datatable is populated automatically by server when an event happens.
* This feature is yet to be implemented on the server side.
*/
@AndroidEntryPoint
class NotificationActivity : BaseActivity(), NotificationView {
@JvmField
@Inject
var mPresenter: NotificationPresenter? = null
var mNotificationPresenter: NotificationContract.NotificationPresenter? = null

@JvmField
@BindView(R.id.rv_notification)
var mRvNotification: RecyclerView? = null

@JvmField
@BindView(R.id.tv_placeholder)
var tvplaceholder: TextView? = null

@JvmField
@Inject
var mNotificationAdapter: NotificationAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_notification)
ButterKnife.bind(this)
setToolbarTitle("Notifications")
showColoredBackButton(Constants.BLACK_BACK_BUTTON)
setupRecyclerView()
setupSwipeRefreshLayout()
mPresenter?.attachView(this)
showSwipeProgress()
mNotificationPresenter?.fetchNotifications()
}

private fun setupRecyclerView() {
mRvNotification?.layoutManager = LinearLayoutManager(this)
mRvNotification?.adapter = mNotificationAdapter
mRvNotification?.addItemDecoration(
DividerItemDecoration(
this,
DividerItemDecoration.VERTICAL
)
)
}

private fun setupSwipeRefreshLayout() {
setSwipeRefreshEnabled(true)
swipeLayout.setOnRefreshListener { mNotificationPresenter?.fetchNotifications() }
}

override fun fetchNotificationsSuccess(notificationPayloadList: List<NotificationPayload?>?) {
hideSwipeProgress()
if (notificationPayloadList.isNullOrEmpty()) {
DebugUtil.log("null")
mRvNotification?.visibility = View.GONE
tvplaceholder?.visibility = View.VISIBLE
} else {
DebugUtil.log("yes")
mRvNotification?.visibility = View.VISIBLE
tvplaceholder?.visibility = View.GONE
mNotificationAdapter?.setNotificationPayloadList(notificationPayloadList as List<NotificationPayload>)
}
mNotificationAdapter?.setNotificationPayloadList(notificationPayloadList as List<NotificationPayload>)
}

override fun fetchNotificationsError(message: String?) {
hideSwipeProgress()
showToast(message)
}

override fun setPresenter(presenter: NotificationContract.NotificationPresenter?) {
mNotificationPresenter = presenter
}

fun showToast(message: String?) {
Toaster.showToast(this, message)
}
}
Loading
Loading