mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 02:56:45 -06:00
Fix showing empty view in mobile device view (#407)
This commit is contained in:
parent
ba6fb1a4b9
commit
58d5e4da0e
@ -35,10 +35,18 @@ class MobileDeviceRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun unregisterDevice(semester: Semester, device: MobileDevice): Single<Boolean> {
|
fun unregisterDevice(semester: Semester, device: MobileDevice): Single<Boolean> {
|
||||||
return remote.unregisterDevice(semester, device)
|
return ReactiveNetwork.checkInternetConnectivity(settings)
|
||||||
|
.flatMap {
|
||||||
|
if (it) remote.unregisterDevice(semester, device)
|
||||||
|
else Single.error(UnknownHostException())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getToken(semester: Semester): Single<MobileDeviceToken> {
|
fun getToken(semester: Semester): Single<MobileDeviceToken> {
|
||||||
return remote.getToken(semester)
|
return ReactiveNetwork.checkInternetConnectivity(settings)
|
||||||
|
.flatMap {
|
||||||
|
if (it) remote.getToken(semester)
|
||||||
|
else Single.error(UnknownHostException())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@ import io.github.wulkanowy.data.db.entities.MobileDevice
|
|||||||
|
|
||||||
class MobileDeviceAdapter<T : IFlexible<*>> : FlexibleAdapter<T>(null, null, true) {
|
class MobileDeviceAdapter<T : IFlexible<*>> : FlexibleAdapter<T>(null, null, true) {
|
||||||
|
|
||||||
var onDeviceUnregisterListener: (MobileDevice, position: Int) -> Unit = { _, _ -> }
|
var onDeviceUnregisterListener: (device: MobileDevice, position: Int) -> Unit = { _, _ -> }
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ import android.view.View.VISIBLE
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import eu.davidea.flexibleadapter.common.FlexibleItemDecoration
|
import eu.davidea.flexibleadapter.common.FlexibleItemDecoration
|
||||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
|
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
|
||||||
import eu.davidea.flexibleadapter.helpers.EmptyViewHelper
|
|
||||||
import eu.davidea.flexibleadapter.helpers.UndoHelper
|
import eu.davidea.flexibleadapter.helpers.UndoHelper
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
|
import io.github.wulkanowy.data.db.entities.MobileDevice
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment
|
import io.github.wulkanowy.ui.base.BaseFragment
|
||||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||||
import io.github.wulkanowy.ui.modules.main.MainView
|
import io.github.wulkanowy.ui.modules.main.MainView
|
||||||
@ -48,7 +48,7 @@ class MobileDeviceFragment : BaseFragment(), MobileDeviceView, MainView.TitledVi
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
mobileDevicesRecycler.run {
|
with(mobileDevicesRecycler) {
|
||||||
layoutManager = SmoothScrollLinearLayoutManager(context)
|
layoutManager = SmoothScrollLinearLayoutManager(context)
|
||||||
adapter = devicesAdapter
|
adapter = devicesAdapter
|
||||||
addItemDecoration(FlexibleItemDecoration(context)
|
addItemDecoration(FlexibleItemDecoration(context)
|
||||||
@ -56,37 +56,43 @@ class MobileDeviceFragment : BaseFragment(), MobileDeviceView, MainView.TitledVi
|
|||||||
.withDrawDividerOnLastItem(false)
|
.withDrawDividerOnLastItem(false)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
EmptyViewHelper.create(devicesAdapter, mobileDevicesEmpty)
|
with(devicesAdapter) {
|
||||||
|
isPermanentDelete = false
|
||||||
|
onDeviceUnregisterListener = presenter::onUnregisterDevice
|
||||||
|
}
|
||||||
mobileDevicesSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
mobileDevicesSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
||||||
mobileDeviceAddButton.setOnClickListener { presenter.onRegisterDevice() }
|
mobileDeviceAddButton.setOnClickListener { presenter.onRegisterDevice() }
|
||||||
devicesAdapter.run {
|
|
||||||
isPermanentDelete = false
|
|
||||||
onDeviceUnregisterListener = { device, position ->
|
|
||||||
val onActionListener = object : UndoHelper.OnActionListener {
|
|
||||||
override fun onActionConfirmed(action: Int, event: Int) {
|
|
||||||
presenter.onUnregister(device)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActionCanceled(action: Int, positions: MutableList<Int>?) {
|
|
||||||
devicesAdapter.restoreDeletedItems()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UndoHelper(devicesAdapter, onActionListener)
|
|
||||||
.withConsecutive(false)
|
|
||||||
.withAction(UndoHelper.Action.REMOVE)
|
|
||||||
.start(listOf(position), mobileDevicesRecycler, R.string.mobile_device_removed, R.string.all_undo, 3000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateData(data: List<MobileDeviceItem>) {
|
override fun updateData(data: List<MobileDeviceItem>) {
|
||||||
devicesAdapter.updateDataSet(data)
|
devicesAdapter.updateDataSet(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun restoreDeleteItem() {
|
||||||
|
devicesAdapter.restoreDeletedItems()
|
||||||
|
}
|
||||||
|
|
||||||
override fun clearData() {
|
override fun clearData() {
|
||||||
devicesAdapter.clear()
|
devicesAdapter.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun showUndo(position: Int, device: MobileDevice) {
|
||||||
|
val onActionListener = object : UndoHelper.OnActionListener {
|
||||||
|
override fun onActionConfirmed(action: Int, event: Int) {
|
||||||
|
presenter.onUnregisterConfirmed(device)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionCanceled(action: Int, positions: MutableList<Int>?) {
|
||||||
|
presenter.onUnregisterCancelled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UndoHelper(devicesAdapter, onActionListener)
|
||||||
|
.withConsecutive(false)
|
||||||
|
.withAction(UndoHelper.Action.REMOVE)
|
||||||
|
.start(listOf(position), mobileDevicesRecycler, R.string.mobile_device_removed, R.string.all_undo, 3000)
|
||||||
|
}
|
||||||
|
|
||||||
override fun hideRefresh() {
|
override fun hideRefresh() {
|
||||||
mobileDevicesSwipe.isRefreshing = false
|
mobileDevicesSwipe.isRefreshing = false
|
||||||
}
|
}
|
||||||
@ -95,6 +101,10 @@ class MobileDeviceFragment : BaseFragment(), MobileDeviceView, MainView.TitledVi
|
|||||||
mobileDevicesProgress.visibility = if (show) VISIBLE else GONE
|
mobileDevicesProgress.visibility = if (show) VISIBLE else GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun showEmpty(show: Boolean) {
|
||||||
|
mobileDevicesEmpty.visibility = if (show) VISIBLE else GONE
|
||||||
|
}
|
||||||
|
|
||||||
override fun enableSwipe(enable: Boolean) {
|
override fun enableSwipe(enable: Boolean) {
|
||||||
mobileDevicesSwipe.isEnabled = enable
|
mobileDevicesSwipe.isEnabled = enable
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ class MobileDevicePresenter @Inject constructor(
|
|||||||
view?.run {
|
view?.run {
|
||||||
updateData(it)
|
updateData(it)
|
||||||
showContent(it.isNotEmpty())
|
showContent(it.isNotEmpty())
|
||||||
|
showEmpty(it.isEmpty())
|
||||||
}
|
}
|
||||||
analytics.logEvent("load_devices", "items" to it.size, "force_refresh" to forceRefresh)
|
analytics.logEvent("load_devices", "items" to it.size, "force_refresh" to forceRefresh)
|
||||||
}) {
|
}) {
|
||||||
@ -62,13 +63,27 @@ class MobileDevicePresenter @Inject constructor(
|
|||||||
view?.showTokenDialog()
|
view?.showTokenDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onUnregister(device: MobileDevice) {
|
fun onUnregisterDevice(device: MobileDevice, position: Int) {
|
||||||
|
view?.run {
|
||||||
|
showUndo(position, device)
|
||||||
|
showEmpty(isViewEmpty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onUnregisterCancelled() {
|
||||||
|
view?.run {
|
||||||
|
restoreDeleteItem()
|
||||||
|
showEmpty(isViewEmpty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onUnregisterConfirmed(device: MobileDevice) {
|
||||||
Timber.i("Unregister device started")
|
Timber.i("Unregister device started")
|
||||||
disposable.add(studentRepository.getCurrentStudent()
|
disposable.add(studentRepository.getCurrentStudent()
|
||||||
.flatMap { semesterRepository.getCurrentSemester(it) }
|
.flatMap { semesterRepository.getCurrentSemester(it) }
|
||||||
.flatMap { semester ->
|
.flatMap { semester ->
|
||||||
mobileDeviceRepository.unregisterDevice(semester, device)
|
mobileDeviceRepository.unregisterDevice(semester, device)
|
||||||
.flatMap { mobileDeviceRepository.getDevices(semester, it) }
|
.flatMap { mobileDeviceRepository.getDevices(semester, it) }
|
||||||
}
|
}
|
||||||
.map { items -> items.map { MobileDeviceItem(it) } }
|
.map { items -> items.map { MobileDeviceItem(it) } }
|
||||||
.subscribeOn(schedulers.backgroundThread)
|
.subscribeOn(schedulers.backgroundThread)
|
||||||
@ -84,6 +99,7 @@ class MobileDevicePresenter @Inject constructor(
|
|||||||
view?.run {
|
view?.run {
|
||||||
updateData(it)
|
updateData(it)
|
||||||
showContent(it.isNotEmpty())
|
showContent(it.isNotEmpty())
|
||||||
|
showEmpty(it.isEmpty())
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
Timber.i("Unregister device result: An exception occurred")
|
Timber.i("Unregister device result: An exception occurred")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.wulkanowy.ui.modules.mobiledevice
|
package io.github.wulkanowy.ui.modules.mobiledevice
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.db.entities.MobileDevice
|
||||||
import io.github.wulkanowy.ui.base.BaseView
|
import io.github.wulkanowy.ui.base.BaseView
|
||||||
|
|
||||||
interface MobileDeviceView : BaseView {
|
interface MobileDeviceView : BaseView {
|
||||||
@ -10,6 +11,8 @@ interface MobileDeviceView : BaseView {
|
|||||||
|
|
||||||
fun updateData(data: List<MobileDeviceItem>)
|
fun updateData(data: List<MobileDeviceItem>)
|
||||||
|
|
||||||
|
fun restoreDeleteItem()
|
||||||
|
|
||||||
fun hideRefresh()
|
fun hideRefresh()
|
||||||
|
|
||||||
fun clearData()
|
fun clearData()
|
||||||
@ -20,5 +23,9 @@ interface MobileDeviceView : BaseView {
|
|||||||
|
|
||||||
fun showContent(show: Boolean)
|
fun showContent(show: Boolean)
|
||||||
|
|
||||||
|
fun showEmpty(show: Boolean)
|
||||||
|
|
||||||
|
fun showUndo(position: Int, device: MobileDevice)
|
||||||
|
|
||||||
fun showTokenDialog()
|
fun showTokenDialog()
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:alpha="0.0">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user