Skip to content

Commit

Permalink
[ADDED] #188 #190 Limit for latest incidents
Browse files Browse the repository at this point in the history
It doesn't make sense to show all incidents for latest.
  • Loading branch information
hossain-khan committed Jul 9, 2020
1 parent 6450966 commit b81f6b9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ val TODAY: OffsetDateTime by lazy {
*/
const val DATABASE_NAME = "incidents-db"

/**
* Number of maximum incidents to load when showing latest incidents.
*/
const val LATEST_INCIDENT_LIMIT = 50

/**
* Fallback data file incidents, used to preload [AppDatabase].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class BrutalityIncidentRepository @Inject constructor(
return incidentDao.getIncidentsByDate(timeStamp)
}

override fun getIncidentsRecentFirst(): LiveData<List<Incident>> {
return incidentDao.getIncidentsRecentFirst()
override fun getIncidentsRecentFirst(limit: Int): LiveData<List<Incident>> {
return incidentDao.getIncidentsRecentFirst(limit)
}

override fun getLocations(): LiveData<List<LocationIncidents>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ interface IncidentDao {
@Query("SELECT * FROM incidents WHERE DATE(date) = DATE(DATETIME(:timestamp, 'unixepoch')) ORDER BY name")
fun getIncidentsByDate(timestamp: Long): LiveData<List<Incident>>

@Query("SELECT * FROM incidents WHERE 1 ORDER BY date DESC")
fun getIncidentsRecentFirst(): LiveData<List<Incident>>
@Query("SELECT * FROM incidents WHERE 1 ORDER BY date DESC LIMIT :limit")
fun getIncidentsRecentFirst(limit: Int): LiveData<List<Incident>>

@Query("SELECT COUNT(id) FROM incidents")
suspend fun getTotalRecords(): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface IncidentRepository {
fun getIncidents(): LiveData<List<Incident>>
fun getStateIncidents(state: String): LiveData<List<Incident>>
fun getIncidentsByDate(timeStamp: Long): LiveData<List<Incident>>
fun getIncidentsRecentFirst(): LiveData<List<Incident>>
fun getIncidentsRecentFirst(limit: Int): LiveData<List<Incident>>
fun getLocations(): LiveData<List<LocationIncidents>>
fun getTotalIncidentsOnDate(timeStamp: Long): LiveData<Int>
fun getIncidentDates(): LiveData<List<String>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.blacklivesmatter.policebrutality.analytics.Analytics
import com.blacklivesmatter.policebrutality.config.LATEST_INCIDENT_LIMIT
import com.blacklivesmatter.policebrutality.config.PREF_KEY_SHARE_CAPABILITY_REMINDER_SHOWN
import com.blacklivesmatter.policebrutality.data.IncidentRepository
import com.blacklivesmatter.policebrutality.data.model.Incident
Expand Down Expand Up @@ -72,7 +73,7 @@ class IncidentViewModel @ViewModelInject constructor(
}

private fun selectedMostRecentIncidents() {
_incidents.addSource(incidentRepository.getIncidentsRecentFirst()) {
_incidents.addSource(incidentRepository.getIncidentsRecentFirst(limit = LATEST_INCIDENT_LIMIT)) {
Timber.d("Incidents Updated ")
_incidents.value = it
}
Expand Down

0 comments on commit b81f6b9

Please sign in to comment.