Skip to content

Commit

Permalink
Merge pull request #28 from mvarnagiris/dev
Browse files Browse the repository at this point in the history
v0.6.0
  • Loading branch information
mvarnagiris committed May 23, 2017
2 parents 84c1f3c + 82a9779 commit f4efb02
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 102 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### v0.6.0
- `new` Date formatting now includes year.
- `new` Added empty state for transactions screen.
- `new` Added ability to view and restore archived transactions.
- `new` Showing *Yesterday* and *Tomorrow* for days around *Today*.
- `new` Added empty state for tags report.

### v0.5.4
- `fix` This time for real fixed billing crash. Maybe.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package com.mvcoding.expensius.feature.reports.tags
import com.mvcoding.expensius.RxSchedulers
import com.mvcoding.expensius.data.Cache
import com.mvcoding.expensius.data.DataSource
import com.mvcoding.expensius.feature.EmptyView
import com.mvcoding.expensius.feature.ignoreError
import com.mvcoding.expensius.feature.updateEmptyView
import com.mvcoding.expensius.model.RemoteFilter
import com.mvcoding.expensius.model.ReportSettings
import com.mvcoding.expensius.model.TagsReport
Expand All @@ -43,10 +45,13 @@ class TagsReportPresenter(
.subscribeOn(schedulers.io)
.observeOn(schedulers.main)
.ignoreError()
.subscribeUntilDetached { view.showTagsReport(it) }
.subscribeUntilDetached {
view.showTagsReport(it)
view.updateEmptyView(it.currentMoneys)
}
}

interface View : Presenter.View {
interface View : Presenter.View, EmptyView {
fun showTagsReport(tagsReport: TagsReport)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ package com.mvcoding.expensius.feature.transaction
import com.mvcoding.expensius.RxSchedulers
import com.mvcoding.expensius.data.DataSource
import com.mvcoding.expensius.data.RealtimeData
import com.mvcoding.expensius.feature.LoadingView
import com.mvcoding.expensius.feature.ModelDisplayType
import com.mvcoding.expensius.feature.RealtimeItemsView
import com.mvcoding.expensius.feature.*
import com.mvcoding.expensius.model.Transaction
import com.mvcoding.mvp.Presenter
import rx.Observable
Expand All @@ -40,13 +38,13 @@ class TransactionsPresenter(
.subscribeOn(schedulers.io)
.observeOn(schedulers.main)
.doOnNext { view.hideLoading() }
.subscribeUntilDetached {
when (it) {
is RealtimeData.AllItems -> view.showItems(it.allItems)
is RealtimeData.AddedItems -> view.showAddedItems(it.addedItems, it.position)
is RealtimeData.ChangedItems -> view.showChangedItems(it.changedItems, it.position)
is RealtimeData.RemovedItems -> view.showRemovedItems(it.removedItems, it.position)
is RealtimeData.MovedItems -> view.showMovedItems(it.movedItems, it.fromPosition, it.toPosition)
.subscribeUntilDetached { realtimeData ->
when (realtimeData) {
is RealtimeData.AllItems -> view.showItems(realtimeData.allItems).also { view.updateEmptyView(realtimeData.allItems) }
is RealtimeData.AddedItems -> view.showAddedItems(realtimeData.addedItems, realtimeData.position)
is RealtimeData.ChangedItems -> view.showChangedItems(realtimeData.changedItems, realtimeData.position)
is RealtimeData.RemovedItems -> view.showRemovedItems(realtimeData.removedItems, realtimeData.position).also { view.updateEmptyView(realtimeData.allItems) }
is RealtimeData.MovedItems -> view.showMovedItems(realtimeData.movedItems, realtimeData.fromPosition, realtimeData.toPosition)
}
}

Expand All @@ -55,7 +53,7 @@ class TransactionsPresenter(
view.archivedTransactionsRequests().subscribeUntilDetached { view.displayArchivedTransactions() }
}

interface View : Presenter.View, RealtimeItemsView<Transaction>, LoadingView {
interface View : Presenter.View, RealtimeItemsView<Transaction>, LoadingView, EmptyView {
fun transactionSelects(): Observable<Transaction>
fun createTransactionRequests(): Observable<Unit>
fun archivedTransactionsRequests(): Observable<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@ import com.mvcoding.expensius.model.TagsReport
import com.mvcoding.expensius.model.extensions.aRemoteFilter
import com.mvcoding.expensius.model.extensions.aReportSettings
import com.mvcoding.expensius.model.extensions.aTagsReport
import com.mvcoding.expensius.model.extensions.empty
import com.mvcoding.expensius.rxSchedulers
import com.nhaarman.mockito_kotlin.*
import org.junit.Before
import org.junit.Test
import rx.Observable
import rx.Observable.error
import rx.Observable.just

class TagsReportPresenterTest {
val tagsReport = aTagsReport()
val reportSettings = aReportSettings()
val remoteFilter = aRemoteFilter(reportSettings.reportPeriod)

val tagsReportSource = mock<DataSource<TagsReport>>()
val reportSettingsSource = mock<DataSource<ReportSettings>>().apply { whenever(data()).thenReturn(Observable.just(reportSettings)) }
val secondaryRemoteFilterCache = mock<Cache<RemoteFilter>>().apply { whenever(data()).thenReturn(Observable.just(remoteFilter)) }
val reportSettingsSource = mock<DataSource<ReportSettings>>().apply { whenever(data()).thenReturn(just(reportSettings)) }
val secondaryRemoteFilterCache = mock<Cache<RemoteFilter>>().apply { whenever(data()).thenReturn(just(remoteFilter)) }
val view = mock<TagsReportPresenter.View>()
val presenter = TagsReportPresenter(tagsReportSource, reportSettingsSource, secondaryRemoteFilterCache, rxSchedulers())

@Before
fun setUp() {
whenever(tagsReportSource.data()).thenReturn(Observable.just(tagsReport))
whenever(tagsReportSource.data()).thenReturn(just(tagsReport))
}

@Test
Expand All @@ -54,11 +56,22 @@ class TagsReportPresenterTest {
presenter.attach(view)

verify(view).showTagsReport(tagsReport)
verify(view).hideEmptyView()
}

@Test
fun `shows empty view when report is empty`() {
val emptyTagsReport = tagsReport.empty()
whenever(tagsReportSource.data()).thenReturn(just(emptyTagsReport))
presenter.attach(view)

verify(view).showTagsReport(emptyTagsReport)
verify(view).showEmptyView()
}

@Test
fun `ignores errors`() {
whenever(tagsReportSource.data()).thenReturn(Observable.error(Throwable()))
whenever(tagsReportSource.data()).thenReturn(error(Throwable()))

presenter.attach(view)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ class TransactionsPresenterTest {
inOrder.verify(view).showMovedItems(movedTransactions, 0, 5)
}

@Test
fun `shows empty when there are no transactions`() {
presenter().attach(view)

receiveTransactions(emptyList())
inOrder.verify(view).showEmptyView()

receiveTransactions(someTransactions())
inOrder.verify(view).hideEmptyView()

receiveTransactionsRemoved(emptyList(), 0)
inOrder.verify(view).showEmptyView()
}

@Test
fun `displays transaction edit when selecting a transaction and display type is view`() {
val transaction = aTransaction()
Expand Down Expand Up @@ -125,13 +139,13 @@ class TransactionsPresenterTest {
verify(view).displayArchivedTransactions()
}

private fun receiveTransactions(tags: List<Transaction>) = transactionsSubject.onNext(RealtimeData.AllItems(tags))
private fun receiveTransactions(transactions: List<Transaction>) = transactionsSubject.onNext(RealtimeData.AllItems(transactions))
private fun requestCreateTransaction() = createTransactionRequestsSubject.onNext(Unit)
private fun requestArchivedTransactions() = displayArchivedTransactionsSubject.onNext(Unit)
private fun receiveTransactionsAdded(tags: List<Transaction>, position: Int) = transactionsSubject.onNext(RealtimeData.AddedItems(tags, tags, position))
private fun receiveTransactionsChanged(tags: List<Transaction>, position: Int) = transactionsSubject.onNext(RealtimeData.ChangedItems(tags, tags, position))
private fun receiveTransactionsRemoved(tags: List<Transaction>, position: Int) = transactionsSubject.onNext(RealtimeData.RemovedItems(tags, tags, position))
private fun receiveTransactionsMoved(tags: List<Transaction>, fromPosition: Int, toPosition: Int) = transactionsSubject.onNext(RealtimeData.MovedItems(tags, tags, fromPosition, toPosition))
private fun receiveTransactionsAdded(transactions: List<Transaction>, position: Int) = transactionsSubject.onNext(RealtimeData.AddedItems(transactions, transactions, position))
private fun receiveTransactionsChanged(transactions: List<Transaction>, position: Int) = transactionsSubject.onNext(RealtimeData.ChangedItems(transactions, transactions, position))
private fun receiveTransactionsRemoved(transactions: List<Transaction>, position: Int) = transactionsSubject.onNext(RealtimeData.RemovedItems(transactions, transactions, position))
private fun receiveTransactionsMoved(transactions: List<Transaction>, fromPosition: Int, toPosition: Int) = transactionsSubject.onNext(RealtimeData.MovedItems(transactions, transactions, fromPosition, toPosition))
private fun selectTransaction(transaction: Transaction) = transactionSelectsSubject.onNext(transaction)
private fun presenter(modelViewType: ModelDisplayType = VIEW_NOT_ARCHIVED) = TransactionsPresenter(modelViewType, transactionsSource, rxSchedulers())
}
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.21.6'
classpath 'io.fabric.tools:gradle:1.22.1'
}
}

Expand All @@ -43,8 +43,8 @@ android {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
multiDexEnabled true
versionCode 14
versionName "0.5.4"
versionCode 15
versionName "0.6.0"
manifestPlaceholders = [crashlytics: privateProperties['CRASHLYTICS']]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Mantas Varnagiris.
* Copyright (C) 2017 Mantas Varnagiris.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,14 +14,9 @@

package com.mvcoding.expensius.extension

import android.text.format.DateUtils
import org.joda.time.LocalDate
import org.joda.time.ReadableInstant

fun isYesterday(readableInstant: ReadableInstant): Boolean {
// TODO Implement
return false
}

fun isTomorrow(readableInstant: ReadableInstant): Boolean {
// TODO Implement
return false
}
fun isYesterday(readableInstant: ReadableInstant): Boolean = LocalDate.now().compareTo(LocalDate(readableInstant.millis + DateUtils.DAY_IN_MILLIS)) == 0
fun isTomorrow(readableInstant: ReadableInstant): Boolean = LocalDate.now().compareTo(LocalDate(readableInstant.millis - DateUtils.DAY_IN_MILLIS)) == 0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Mantas Varnagiris.
* Copyright (C) 2017 Mantas Varnagiris.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,15 +19,20 @@ import com.mvcoding.expensius.R
import com.mvcoding.expensius.extension.isTomorrow
import com.mvcoding.expensius.extension.isYesterday
import com.mvcoding.expensius.model.ReportPeriod
import net.danlew.android.joda.DateUtils.FORMAT_ABBREV_ALL
import net.danlew.android.joda.DateUtils.FORMAT_SHOW_DATE
import net.danlew.android.joda.DateUtils.FORMAT_SHOW_WEEKDAY
import net.danlew.android.joda.DateUtils.formatDateTime
import net.danlew.android.joda.DateUtils.isToday
import net.danlew.android.joda.DateUtils.*
import org.joda.time.DateTime
import org.joda.time.Interval
import org.joda.time.format.DateTimeFormatter
import org.joda.time.format.DateTimeFormatterBuilder

class DateFormatter(private val context: Context) {

val dateFormatter: DateTimeFormatter = DateTimeFormatterBuilder()
.appendMonthOfYearText()
.appendLiteral(" ")
.appendYear(0, 4)
.toFormatter()

fun formatDateRelativeToToday(timestamp: Long): String {
val dateTime = DateTime(timestamp)

Expand All @@ -43,5 +48,7 @@ class DateFormatter(private val context: Context) {
}

fun formatDateShort(dateTime: DateTime): String = formatDateTime(context, dateTime, FORMAT_SHOW_DATE or FORMAT_ABBREV_ALL)
fun formatInterval(reportPeriod: ReportPeriod, interval: Interval): String = interval.start.monthOfYear().asText
fun formatInterval(reportPeriod: ReportPeriod, interval: Interval): String = when (reportPeriod) {
ReportPeriod.MONTH -> dateFormatter.print(interval.start)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.mvcoding.expensius.model.ReportPeriod
import com.mvcoding.expensius.provideDateFormatter
import kotlinx.android.synthetic.main.activity_overview.*
import kotlinx.android.synthetic.main.toolbar.*
import kotlinx.android.synthetic.main.view_tags_report.*
import kotlinx.android.synthetic.main.view_tags_report_overview.*
import kotlinx.android.synthetic.main.view_transactions_overview.*
import kotlinx.android.synthetic.main.view_trend_report.*
Expand All @@ -54,6 +55,7 @@ class OverviewActivity : BaseActivity(), OverviewPresenter.View {
setContentView(R.layout.activity_overview)
removeUpArrowFromToolbar()
presenter.attach(this)
tagsReportView.isEnabled = false
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Mantas Varnagiris.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

package com.mvcoding.expensius.feature.reports.tags

import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout

class TagsReportOverviewView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
LinearLayout(context, attrs, defStyleAttr) {

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,38 @@
package com.mvcoding.expensius.feature.reports.tags

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.util.AttributeSet
import android.widget.LinearLayout
import android.view.MotionEvent
import android.view.ViewGroup
import android.widget.FrameLayout
import com.mvcoding.expensius.extension.doNotInEditMode
import com.mvcoding.expensius.extension.setGone
import com.mvcoding.expensius.extension.setVisible
import com.mvcoding.expensius.feature.BaseAdapter
import com.mvcoding.expensius.feature.ViewHolder
import com.mvcoding.expensius.feature.reports.provideTagsReportPresenter
import com.mvcoding.expensius.model.GroupedMoney
import com.mvcoding.expensius.model.NullModels.noMoney
import com.mvcoding.expensius.model.Tag
import com.mvcoding.expensius.model.TagsReport
import kotlinx.android.synthetic.main.view_tags_report.view.*
import java.math.BigDecimal

class TagsReportView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
LinearLayout(context, attrs, defStyleAttr), TagsReportPresenter.View {
FrameLayout(context, attrs, defStyleAttr), TagsReportPresenter.View {

private val presenter by lazy { provideTagsReportPresenter() }
private val adapter by lazy { Adapter() }

init {
orientation = VERTICAL
override fun onFinishInflate() {
super.onFinishInflate()
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = adapter
}

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean = !isEnabled

override fun onAttachedToWindow() {
super.onAttachedToWindow()
doNotInEditMode { presenter.attach(this) }
Expand All @@ -42,14 +58,24 @@ class TagsReportView @JvmOverloads constructor(context: Context, attrs: Attribut
}

override fun showTagsReport(tagsReport: TagsReport) {
removeAllViews()
val maxMoney = tagsReport.currentMoneys.firstOrNull()?.money ?: noMoney
tagsReport.currentMoneys.forEach {
val tagReportItemView = TagMoneyItemView.inflate(this)
addView(tagReportItemView)
tagReportItemView.setTag(it.group)
tagReportItemView.setMoney(it.money)
tagReportItemView.setProgress(it.money.amount.toFloat() / maxMoney.amount.toFloat())
adapter.maxMoneyAmount = (tagsReport.currentMoneys.firstOrNull()?.money ?: noMoney).amount
adapter.setItems(tagsReport.currentMoneys)
}

override fun showEmptyView(): Unit = emptyTextView.setVisible()
override fun hideEmptyView(): Unit = emptyTextView.setGone()

private class Adapter : BaseAdapter<GroupedMoney<Tag>, ViewHolder>() {
var maxMoneyAmount: BigDecimal = BigDecimal.ONE

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(TagMoneyItemView.inflate(parent))

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val view = holder.getView<TagMoneyItemView>()
val item = getItem(position)
view.setTag(item.group)
view.setMoney(item.money)
view.setProgress(item.money.amount.toFloat() / maxMoneyAmount.toFloat())
}
}
}

0 comments on commit f4efb02

Please sign in to comment.