Skip to content

Commit 5cabdfd

Browse files
committed
Fix error / empty views
1 parent bf043cc commit 5cabdfd

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/ObservableUseCase.kt renamed to domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/FlowableUseCase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import org.buffer.android.boilerplate.domain.executor.ThreadExecutor
1414
/**
1515
* Abstract class for a UseCase that returns an instance of a [Single].
1616
*/
17-
abstract class ObservableUseCase<T, in Params> constructor(
17+
abstract class FlowableUseCase<T, in Params> constructor(
1818
private val threadExecutor: ThreadExecutor,
1919
private val postExecutionThread: PostExecutionThread) {
2020

2121
private val disposables = CompositeDisposable()
2222

2323
/**
24-
* Builds a [Single] which will be used when the current [ObservableUseCase] is executed.
24+
* Builds a [Single] which will be used when the current [FlowableUseCase] is executed.
2525
*/
2626
protected abstract fun buildUseCaseObservable(params: Params? = null): Flowable<T>
2727

domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/browse/GetBufferoos.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.buffer.android.boilerplate.domain.interactor.browse
33
import io.reactivex.Flowable
44
import org.buffer.android.boilerplate.domain.executor.PostExecutionThread
55
import org.buffer.android.boilerplate.domain.executor.ThreadExecutor
6-
import org.buffer.android.boilerplate.domain.interactor.ObservableUseCase
6+
import org.buffer.android.boilerplate.domain.interactor.FlowableUseCase
77
import org.buffer.android.boilerplate.domain.model.Bufferoo
88
import org.buffer.android.boilerplate.domain.repository.BufferooRepository
99
import javax.inject.Inject
@@ -14,7 +14,7 @@ import javax.inject.Inject
1414
open class GetBufferoos @Inject constructor(val bufferooRepository: BufferooRepository,
1515
threadExecutor: ThreadExecutor,
1616
postExecutionThread: PostExecutionThread):
17-
ObservableUseCase<List<Bufferoo>, Void?>(threadExecutor, postExecutionThread) {
17+
FlowableUseCase<List<Bufferoo>, Void?>(threadExecutor, postExecutionThread) {
1818

1919
public override fun buildUseCaseObservable(params: Void?): Flowable<List<Bufferoo>> {
2020
return bufferooRepository.getBufferoos()

mobile-ui/src/main/java/org/buffer/android/boilerplate/ui/widget/empty/EmptyView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.util.AttributeSet
55
import android.view.LayoutInflater
66
import android.widget.RelativeLayout
7+
import kotlinx.android.synthetic.main.view_empty.view.*
78
import org.buffer.android.boilerplate.ui.R
89

910
/**
@@ -28,6 +29,7 @@ class EmptyView: RelativeLayout {
2829

2930
private fun init() {
3031
LayoutInflater.from(context).inflate(R.layout.view_empty, this)
32+
button_check_again.setOnClickListener { emptyListener?.onCheckAgainClicked() }
3133
}
3234

3335
}

mobile-ui/src/main/java/org/buffer/android/boilerplate/ui/widget/error/ErrorView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.util.AttributeSet
55
import android.view.LayoutInflater
66
import android.widget.RelativeLayout
7+
import kotlinx.android.synthetic.main.view_error.view.*
78
import org.buffer.android.boilerplate.ui.R
89

910
/**
@@ -28,6 +29,7 @@ class ErrorView : RelativeLayout {
2829

2930
private fun init() {
3031
LayoutInflater.from(context).inflate(R.layout.view_error, this)
32+
button_try_again.setOnClickListener { errorListener?.onTryAgainClicked() }
3133
}
3234

3335
}

mobile-ui/src/main/res/layout/view_empty.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
android:id="@+id/text_message"
88
android:layout_width="wrap_content"
99
android:layout_height="wrap_content"
10-
android:layout_centerInParent="true" />
10+
android:layout_centerInParent="true"
11+
android:text="@string/label_empty_result" />
1112

1213
<Button
1314
android:id="@+id/button_check_again"
1415
android:layout_width="wrap_content"
1516
android:layout_height="wrap_content"
1617
android:layout_below="@+id/text_message"
18+
android:layout_centerHorizontal="true"
1719
android:padding="16dp"
18-
android:layout_centerHorizontal="true" />
20+
android:text="@string/button_try_again" />
1921

2022
</merge>

mobile-ui/src/main/res/layout/view_error.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
android:id="@+id/text_message"
88
android:layout_width="wrap_content"
99
android:layout_height="wrap_content"
10-
android:layout_centerInParent="true" />
10+
android:layout_centerInParent="true"
11+
android:text="@string/label_error_result" />
1112

1213
<Button
1314
android:id="@+id/button_try_again"
1415
android:layout_width="wrap_content"
1516
android:layout_height="wrap_content"
1617
android:layout_below="@+id/text_message"
18+
android:layout_centerHorizontal="true"
1719
android:padding="16dp"
18-
android:layout_centerHorizontal="true" />
20+
android:text="@string/button_try_again" />
1921

2022
</merge>

readme.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
[![Build Status](https://travis-ci.org/bufferapp/android-clean-architecture-boilerplate.svg?branch=master)](https://travis-ci.org/bufferapp/android-clean-architecture-boilerplate) [![codecov](https://codecov.io/gh/bufferapp/android-clean-architecture-boilerplate/branch/master/graph/badge.svg)](https://codecov.io/gh/bufferapp/android-clean-architecture-boilerplate) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/278fa00f492d48a288ab64188d15fb61)](https://www.codacy.com/app/hitherejoe/android-clean-architecture-boilerplate?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=bufferapp/android-clean-architecture-boilerplate&amp;utm_campaign=Badge_Grade)
22

3-
# Android Clean Architecture Boilerplate
3+
# Android Clean Architecture Components Boilerplate
4+
5+
6+
Note: This is a fork of our original [Clean Architecture Boilerplate](https://github.com/bufferapp/android-clean-architecture-boilerplate), except in this repo we have switched out the MVP approach found in the presentation layer to now use ViewModels from the Android Architecture Components Library.
7+
The caching layer now also uses Room.
8+
49

510
Welcome 👋 We hope this boilerplate is not only helpful to other developers, but also that it helps to educate in the area of architecture. We created this boilerplate for a few reasons:
611

712
1. To experiment with modularisation
8-
2. To share some approaches to clean architecture, especially as we've been [talking a lot about it](https://academy.realm.io/posts/converting-an-app-to-use-clean-architecture/)
9-
3. To use as a starting point in future projects where clean architecture feels appropriate
13+
2. TO experiment with the Android Architecture Components
14+
3. To share some approaches to clean architecture, especially as we've been [talking a lot about it](https://academy.realm.io/posts/converting-an-app-to-use-clean-architecture/)
15+
4. To use as a starting point in future projects where clean architecture feels appropriate
1016

1117
It is written 100% in Kotlin with both UI and Unit tests - we will also be keeping this up-to-date as libraries change!
1218

@@ -19,6 +25,8 @@ Clean Architecture will not be appropriate for every project, so it is down to y
1925
## Languages, libraries and tools used
2026

2127
* [Kotlin](https://kotlinlang.org/)
28+
* [Room](https://developer.android.com/topic/libraries/architecture/room.html)
29+
* [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html)
2230
* Android Support Libraries
2331
* [RxJava2](https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0)
2432
* [Dagger 2 (2.11)](https://github.com/google/dagger)
@@ -59,13 +67,11 @@ This layer makes use of the Android Framework and is used to create all of our U
5967

6068
### Presentation
6169

62-
This layer's responsibilty is to handle the presentation of the User Interface, but at the same time knows nothing about the user interface itself. This layer has no dependance on the Android Framework, it is a pure Kotlin module. Each Presenter class that is created implements the [Presenter](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/BasePresenter.kt) interface defined within an instance of a contract - in this case the [BrowseContract](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/browse/BrowseBufferoosContract.kt), which also contains an interface for the [View](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/BaseView.kt) interface.
63-
64-
When a Presenter is constructed, an instance of this View is passed in. This view is then used and the presenter is set for it using the implemented [setPresenter()](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/browse/BrowseBufferoosPresenter.kt#L15) call.
70+
This layer's responsibilty is to handle the presentation of the User Interface, but at the same time knows nothing about the user interface itself. This layer has no dependance on the Android Framework, it is a pure Kotlin module. Each ViewModel class that is created implements the ViewModel class found within the Architecture components library. This ViewModel can then be used by the UI layer to communicate with UseCases and retrieve data. The [BrowseBufferoosViewModel]() returns an instance of a Resource which contains data that can be used by the UI - this includes the [ResourceState](), data to be used by the UI and a message if required (for error states).
6571

66-
The presenters use an instance of a [SingleUseCase](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/ObservableUseCase.kt) from the Domain layer to retrieve data. Note here that there is no direct name reference to the UseCase that we are using - we do inject an instance of the [GetBufferoos](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/browse/GetBufferoos.kt) UseCase, however.
72+
The ViewModels use an instance of a [FlowableUseCase](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/FlowableUseCase.kt) from the Domain layer to retrieve data. Note here that there is no direct name reference to the UseCase that we are using - we do inject an instance of the [GetBufferoos](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/domain/src/main/java/org/buffer/android/boilerplate/domain/interactor/browse/GetBufferoos.kt) UseCase, however.
6773

68-
The presenter receives data from the Domain layer in the form of a [Bufferoo](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/model/BufferooView.kt). These instances are mapped to instance of this layers model, which is a BufferooView using the [BufferooMapper](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/mapper/BufferooMapper.kt).
74+
The ViewModel receives data from the Domain layer in the form of a [Bufferoo](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/model/BufferooView.kt). These instances are mapped to instance of this layers model, which is a BufferooView using the [BufferooMapper](https://github.com/bufferapp/android-clean-architecture-boilerplate/blob/master/presentation/src/main/java/org/buffer/android/boilerplate/presentation/mapper/BufferooMapper.kt).
6975

7076
### Domain
7177

0 commit comments

Comments
 (0)