Skip to content

Commit

Permalink
Merge pull request #98 from amardeshbd/develop
Browse files Browse the repository at this point in the history
Release 1.5 (final)
  • Loading branch information
hossain-khan authored Jun 14, 2020
2 parents c5b985f + 6aaf147 commit 4c29a8c
Show file tree
Hide file tree
Showing 27 changed files with 236 additions and 35 deletions.
4 changes: 4 additions & 0 deletions android-app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<activity
android:name="com.blacklivesmatter.policebrutality.MainActivity"
android:label="@string/app_name" />

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>

</manifest>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ class BrutalityIncidentRepository @Inject constructor(
Timber.i("Adding/updating ${incidents.size} incidents.")
incidentDao.insertAll(incidents)
}

override suspend fun removeStaleIncidents(latestIncidents: List<Incident>) {
val latestIds = latestIncidents.map { it.id }
val affectedRows = incidentDao.deleteItemByIds(latestIds)
Timber.i("Removed $affectedRows stale records from database.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import androidx.room.Query
import com.blacklivesmatter.policebrutality.data.model.Incident
import com.blacklivesmatter.policebrutality.data.model.LocationIncidents

/**
* Data access object interface for Room.
*
* See:
* - https://developer.android.com/training/data-storage/room
* - https://developer.android.com/topic/libraries/architecture/room
*/
@Dao
interface IncidentDao {
@Query("SELECT * FROM incidents ORDER BY name")
Expand All @@ -33,4 +40,7 @@ interface IncidentDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(incidents: List<Incident>)

@Query("DELETE FROM incidents WHERE id NOT IN (:ids)")
suspend fun deleteItemByIds(ids: List<String>): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ interface IncidentRepository {
*/
suspend fun getIncidentsCoroutine(): List<Incident>
suspend fun addIncidents(incidents: List<Incident>)

/**
* Should remove all stale incidents except the [latestIncidents] provided here.
*/
suspend fun removeStaleIncidents(latestIncidents: List<Incident>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ import androidx.room.ColumnInfo
data class LocationIncidents constructor(
@ColumnInfo(name = "state") val stateName: String,
@ColumnInfo(name = "total_incidents") val totalIncidents: Int
)
) {
val totalIncidentsText: String
get() = totalIncidents.toString().trim()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.blacklivesmatter.policebrutality.data.IncidentRepository
import com.blacklivesmatter.policebrutality.data.model.Incident
import com.blacklivesmatter.policebrutality.data.model.LocationIncidents
import com.blacklivesmatter.policebrutality.ui.extensions.LiveEvent
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.launch
import org.threeten.bp.Instant
import org.threeten.bp.OffsetDateTime
Expand Down Expand Up @@ -84,8 +85,23 @@ class LocationViewModel @Inject constructor(
Timber.d("Refresh requested")
viewModelScope.launch {
isOperationInProgress.set(false)
val incidents: List<Incident> = incidentRepository.getIncidentsCoroutine()
val incidents: List<Incident> = try {
incidentRepository.getIncidentsCoroutine()
} catch (error: Exception) {
// Report error so that I get notified to fix it.
FirebaseCrashlytics.getInstance().recordException(error)
emptyList()
}

if (incidents.isEmpty()) {
// Something went wrong, DO NOT proceed
_refreshEvent.value = RefreshEvent.Error(IllegalStateException("Unable to refresh content"))
return@launch
}

Timber.d("Received total ${incidents.size} incidents, updating local cache.")
incidentRepository.addIncidents(incidents)
incidentRepository.removeStaleIncidents(incidents)
_refreshEvent.value = RefreshEvent.Success(incidents.size)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,15 @@ class MoreInfoFragment : DaggerFragment() {
}
R.id.toolbar_menu_share -> {
Timber.d("Share app menu item selected.")
// TODO - update this whenever app is published at
// https://play.google.com/store/apps/details?id=com.blacklivesmatter.policebrutality
// TODO https://github.com/amardeshbd/android-police-brutality-incidents/issues/55
Snackbar.make(
viewDataBinding.root,
"Sharing coming soon: This app is pending approval on Google Play Store. " +
"Thanks for caring! ❤️",
Snackbar.LENGTH_LONG
).show()
"Thanks for caring! ❤️" +
"\nShare this App with friends?",
Snackbar.LENGTH_INDEFINITE
).setAction(R.string.button_cta_share_app, { startActivity(IntentBuilder.shareApp(resources)) })
.show()
analytics.logEvent(Analytics.ACTION_SHARE_APP)

return true
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.blacklivesmatter.policebrutality.ui.util

import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.net.Uri
import com.blacklivesmatter.policebrutality.BuildConfig
import com.blacklivesmatter.policebrutality.R
import com.blacklivesmatter.policebrutality.config.PB_LINK_WEB
import com.blacklivesmatter.policebrutality.data.model.Incident

Expand Down Expand Up @@ -90,4 +93,24 @@ ${incident.links.joinToString(separator = " \n * ", prefix = " * ")}
val shareIntent = Intent.createChooser(sendIntent, null)
return shareIntent
}

fun shareApp(resources: Resources): Intent {
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_android_app_with_friends_body_title))
putExtra(
Intent.EXTRA_TEXT, resources.getString(
R.string.share_android_app_with_friends_body_content,
BuildConfig.APPLICATION_ID,
resources.getString(R.string.hash_tag_blacklivesmatter),
resources.getString(R.string.hash_tag_justiceforgeorgefloyd),
resources.getString(R.string.hash_tag_policebrutality)
)
)
type = "text/plain"
}

val shareAppIntent = Intent.createChooser(sendIntent, null)
return shareAppIntent
}
}
7 changes: 7 additions & 0 deletions android-app/app/src/main/res/font/alfa_slab_one.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Alfa Slab One"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>
7 changes: 7 additions & 0 deletions android-app/app/src/main/res/font/handlee.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Handlee"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>
15 changes: 11 additions & 4 deletions android-app/app/src/main/res/layout/activity_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/view_spacing_xxlarge">
Expand All @@ -10,12 +11,14 @@
style="?textAppearanceHeadline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/view_spacing_large"
android:layout_marginTop="@dimen/view_spacing_xxlarge"
android:shadowColor="?attr/colorAccent"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="2"
android:text="@string/hash_tag_blacklivesmatter"
android:textAlignment="center"
app:fontFamily="@font/alfa_slab_one"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -31,17 +34,21 @@
android:shadowDy="2"
android:shadowRadius="2"
android:text="@string/hash_tag_justiceforgeorgefloyd"
android:textAlignment="center"
app:fontFamily="@font/alfa_slab_one"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/materialTextView" />
app:layout_constraintTop_toBottomOf="@+id/materialTextView"
tools:text="#JustticeForGeorgeFloyedForEver" />

<com.google.android.material.textview.MaterialTextView
style="?textAppearanceBody1"
style="?textAppearanceHeadline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="... a collection of Police brutality incidents during George Floyd protests ✊"
android:text="@string/app_splash_subtitle_about_cause"
android:textAlignment="center"
android:textStyle="bold"
app:fontFamily="@font/handlee"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="?actionBarSize">
<!--
Looks like there is a issue with AppBarLayout, it gets hidden without the margin
Expand All @@ -50,13 +52,7 @@
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toTopOf="parent"
tools:background="#dac"
tools:itemCount="7"
tools:listitem="@layout/list_item_location" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/incident_title"
style="@style/TextAppearance.MaterialComponents.Body1"
style="?textAppearanceHeadline6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="@dimen/list_item_vertical_margin"
Expand All @@ -58,12 +58,13 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/incident_location"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
style="?textAppearanceSubtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_item_vertical_margin"
android:text="@{@string/incident_location_at_display_text(incident.city, incident.state)}"
android:textAlignment="textEnd"
android:textColor="@color/grey_500"
android:visibility="@{safeUnbox(isDateBased)? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
app:layout_constraintTop_toBottomOf="@+id/incident_title"
Expand All @@ -73,7 +74,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/incident_date"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
style="?textAppearanceSubtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_item_vertical_margin"
Expand All @@ -82,6 +83,7 @@
android:drawablePadding="@dimen/list_item_horizontal_margin"
android:text="@{incident.dateText}"
android:textAlignment="textEnd"
android:textColor="@color/grey_500"
app:layout_constraintEnd_toStartOf="@+id/incident_location"
app:layout_constraintTop_toBottomOf="@+id/incident_title"
app:layout_goneMarginEnd="0dp"
Expand Down
25 changes: 21 additions & 4 deletions android-app/app/src/main/res/layout/list_item_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin">
android:layout_margin="@dimen/view_spacing_larger">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_start"
Expand All @@ -37,13 +37,29 @@
android:orientation="vertical"
app:layout_constraintGuide_end="@dimen/list_item_horizontal_margin" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/total_incidents_number"
style="@style/TextAppearance.MaterialComponents.Headline3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:alpha=".5"
android:text="@{data.totalIncidentsText}"
android:textAlignment="textEnd"
android:textStyle="italic"
app:fontFamily="sans-serif-thin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
app:layout_constraintTop_toTopOf="parent"
tools:text="128" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/name"
style="@style/TextAppearance.MaterialComponents.Headline6"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/view_spacing_medium"
android:text="@{data.stateName}"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
app:layout_constraintEnd_toStartOf="@+id/total_incidents_number"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toTopOf="parent"
tools:text="State Name" />
Expand All @@ -54,9 +70,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_item_vertical_margin"
android:layout_marginEnd="@dimen/view_spacing_medium"
android:text="@{@string/total_reported_incident_for_location(data.totalIncidents)}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
app:layout_constraintEnd_toStartOf="@+id/total_incidents_number"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toBottomOf="@+id/name"
tools:text="Total 13 reported incidents." />
Expand Down
5 changes: 5 additions & 0 deletions android-app/app/src/main/res/values-land/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="activity_horizontal_margin">48dp</dimen>
<dimen name="activity_vertical_margin">48dp</dimen>
</resources>
16 changes: 16 additions & 0 deletions android-app/app/src/main/res/values-sw600dp-land/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Here's how other smallest width values correspond to typical screen sizes:
* 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
* 480dp: a large phone screen ~5" (480x800 mdpi).
* 600dp: a 7” tablet (600x1024 mdpi).
* 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
See https://developer.android.com/training/multiscreen/screensizes
-->
<resources>
<dimen name="activity_horizontal_margin">128dp</dimen>
<dimen name="activity_vertical_margin">128dp</dimen>
</resources>
16 changes: 16 additions & 0 deletions android-app/app/src/main/res/values-sw600dp-port/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Here's how other smallest width values correspond to typical screen sizes:
* 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
* 480dp: a large phone screen ~5" (480x800 mdpi).
* 600dp: a 7” tablet (600x1024 mdpi).
* 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
See https://developer.android.com/training/multiscreen/screensizes
-->
<resources>
<dimen name="activity_horizontal_margin">64dp</dimen>
<dimen name="activity_vertical_margin">64dp</dimen>
</resources>
16 changes: 16 additions & 0 deletions android-app/app/src/main/res/values-sw720dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Here's how other smallest width values correspond to typical screen sizes:
* 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
* 480dp: a large phone screen ~5" (480x800 mdpi).
* 600dp: a 7” tablet (600x1024 mdpi).
* 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
See https://developer.android.com/training/multiscreen/screensizes
-->
<resources>
<dimen name="activity_horizontal_margin">128dp</dimen>
<dimen name="activity_vertical_margin">128dp</dimen>
</resources>
Loading

0 comments on commit 4c29a8c

Please sign in to comment.