Skip to content

Commit

Permalink
Merge pull request #113 from amardeshbd/develop
Browse files Browse the repository at this point in the history
Initial Release for 2.0
  • Loading branch information
hossain-khan authored Jun 16, 2020
2 parents 4c29a8c + 8430e9d commit a51956d
Show file tree
Hide file tree
Showing 68 changed files with 422 additions and 672 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Kotlin lint (use `./gradlew ktlintFormat` on error)
run: ./gradlew ktlintCheck

- name: Build with Gradle
run: ./gradlew build
run: ./gradlew assembleDebug

- name: Archive APK
uses: actions/upload-artifact@v1
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/android_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Android Lint

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
working-directory: ./android-app

steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

# Save gradle cache between runs, see https://github.com/actions/cache/blob/master/examples.md#java---gradle
# Include hashFiles so that cache does continue to grow with old dependencies in it.
- name: Copy gradle cache
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Kotlin lint (use `./gradlew ktlintFormat` on error)
run: ./gradlew ktlintCheck

- name: Android Lint
run: ./gradlew lint
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ Currently following key features are being used.

### Preview

Here is a snapshot of the app in early stages _(taken on June 10th)_
Here is a snapshot of the app in early stages _(taken on June 14th)_

<img src="https://user-images.githubusercontent.com/99822/84335138-28ed3380-ab62-11ea-9f10-0a61bfde1f44.gif" width="50%">
<img src="https://user-images.githubusercontent.com/99822/84598731-d8642780-ae3a-11ea-99e9-15ce12f00eb4.gif" width="50%">
9 changes: 6 additions & 3 deletions android-app/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[*.{kt, kts}]
# Disable Ktlint import ordering temporarily because of AndroidStudio Kotlin formatting bug. read more here:
# https://youtrack.jetbrains.com/issue/KT-10974 & https://github.com/pinterest/ktlint/issues/527
disabled_rules=import-ordering
kotlin_imports_layout=idea # This is not working at the moment (may required ktlint plugin update)
max_line_length=120
disabled_rules = import-ordering
kotlin_imports_layout = idea # This is not working at the moment (may required ktlint plugin update)
max_line_length = 120

[*.xml]
max_line_length = 120
1 change: 1 addition & 0 deletions android-app/.idea/dictionaries/hossain.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions android-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
id 'dagger.hilt.android.plugin'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
id 'org.jlleitschuh.gradle.ktlint'
Expand All @@ -20,8 +21,8 @@ android {
applicationId "com.blacklivesmatter.policebrutality"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 6
versionName "1.5"
versionCode 7
versionName "2.0"

resConfigs "en"

Expand Down Expand Up @@ -69,6 +70,12 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}

lintOptions { // https://developer.android.com/studio/write/lint.html
checkAllWarnings true
warningsAsErrors true
ignore 'GradleDependency', 'NewerVersionAvailable', 'UnusedIds'
}
}

dependencies {
Expand All @@ -84,7 +91,6 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
implementation "androidx.navigation:navigation-fragment-ktx:$rootProject.navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$rootProject.navigationVersion"
implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
implementation "androidx.cardview:cardview:$rootProject.cardViewVersion"
implementation "androidx.preference:preference:$rootProject.preferenceVersion"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-rc01"
Expand All @@ -93,24 +99,27 @@ dependencies {
implementation "com.google.firebase:firebase-analytics-ktx:$rootProject.firebaseAnalyticsVersion"
implementation "com.google.firebase:firebase-crashlytics:$rootProject.firebaseCrashlyticsVersion"

// Work Manager
implementation "androidx.work:work-runtime-ktx:$rootProject.workVersion"

// Room Database
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"


// Glide - image loading
kapt "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"

implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
// Google Gson for JSON
implementation "com.google.code.gson:gson:2.8.6"

// Dagger 2 - DI
implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
implementation "com.google.dagger:dagger-android:$rootProject.dagger2Version"
implementation "com.google.dagger:dagger-android-support:$rootProject.dagger2Version"
kapt "com.google.dagger:dagger-android-processor:$rootProject.dagger2Version"
kapt "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"
// Dagger Hilt (android dependency injection)
implementation "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$rootProject.androidXHiltVersion"
implementation "androidx.hilt:hilt-work:$rootProject.androidXHiltVersion"
kapt "androidx.hilt:hilt-compiler:$rootProject.androidXHiltVersion"

// Retrofit
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
Expand All @@ -119,12 +128,14 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttpVersion"

implementation "com.jakewharton.timber:timber:$rootProject.timberVersion"
// Timber for logging
implementation "com.jakewharton.timber:timber:4.7.1"

// 310BP - Backport of the Java SE 8 date-time classes
implementation "org.threeten:threetenbp:1.4.4" // https://www.threeten.org/threetenbp/

// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation "com.squareup.leakcanary:leakcanary-android:2.3"
debugImplementation "com.squareup.leakcanary:leakcanary-android:2.4"

// Unit testing
testImplementation "junit:junit:$rootProject.junitVersion"
Expand Down
17 changes: 15 additions & 2 deletions android-app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.blacklivesmatter.policebrutality">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -11,13 +12,15 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PoliceBrutality">
android:theme="@style/Theme.PoliceBrutality"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".ui.launcher.LauncherActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.PoliceBrutality.Launcher"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -31,6 +34,16 @@
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<!--
Remove the default initializer for Dagger Hilt DI to work for injecting `Worker`s
https://developer.android.com/topic/libraries/architecture/workmanager/advanced/custom-configuration#remove-default
-->
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package com.blacklivesmatter.policebrutality

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import com.blacklivesmatter.policebrutality.di.component.AppComponent
import com.blacklivesmatter.policebrutality.di.component.DaggerAppComponent
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.blacklivesmatter.policebrutality.logging.TimberDebugTree
import com.blacklivesmatter.policebrutality.logging.TimberReleaseTree
import com.blacklivesmatter.policebrutality.ui.common.ThemeHelper
import dagger.android.AndroidInjector
import dagger.android.support.DaggerApplication
import kotlin.math.abs
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber
import javax.inject.Inject

class BrutalityIncidentApplication : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
// Build app component
val appComponent: AppComponent = DaggerAppComponent.builder()
.application(this)
.build()

// Inject the application instance
appComponent.inject(this)
return appComponent
}
@HiltAndroidApp
class BrutalityIncidentApplication : Application(), Configuration.Provider {
@Inject
lateinit var workerFactory: HiltWorkerFactory

override fun onCreate() {
super.onCreate()
Expand All @@ -28,30 +23,20 @@ class BrutalityIncidentApplication : DaggerApplication() {
// Because it's #BlackLivesMatter
ThemeHelper.applyTheme(AppCompatDelegate.MODE_NIGHT_YES)

if (BuildConfig.DEBUG) {
installLogging()
}
installLogging()
}

private fun installLogging() {
// Include logging in release builds so we can test from client.
// See https://github.com/JakeWharton/timber/blob/master/timber-sample/src/main/java/com/example/timber/ExampleApp.java
Timber.plant(object : Timber.DebugTree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
val newMessage = "[${getThreadName()}] $message"
super.log(priority, tag, newMessage, t)
}
override fun getWorkManagerConfiguration(): Configuration {
return Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()
}

/**
* Returns name of current thread, with some well known thread names replaced to make easier to understand.
*/
private fun getThreadName(): String {
var name = Thread.currentThread().name
if (name.length > 10) {
name = name.substring(0, 10) + "." + abs(name.hashCode() % 100)
}
return name
}
})
private fun installLogging() {
if (BuildConfig.DEBUG) {
Timber.plant(TimberDebugTree())
} else {
Timber.plant(TimberReleaseTree())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package com.blacklivesmatter.policebrutality

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.blacklivesmatter.policebrutality.databinding.ActivityMainBinding
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.android.support.DaggerAppCompatActivity
import javax.inject.Inject
import dagger.hilt.android.AndroidEntryPoint

/**
* The container activity for the app using "single-activity" pattern.
* This activity hosts fragments and the flow is managed by AndroidX Jetpack navigation library.
*/
class MainActivity : DaggerAppCompatActivity() {

@Inject
lateinit var viewModelFactory: ViewModelProvider.Factory

private lateinit var viewModel: MainViewModel
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private val viewModel: MainViewModel by viewModels()
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
viewModel = ViewModelProvider(this, viewModelFactory).get(MainViewModel::class.java)

val navView: BottomNavigationView = findViewById(R.id.nav_view)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
package com.blacklivesmatter.policebrutality.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.blacklivesmatter.policebrutality.config.DATABASE_NAME
import com.blacklivesmatter.policebrutality.data.model.Incident
import com.blacklivesmatter.policebrutality.worker.SeedDatabaseWorker

/**
* The Room database for this app
Expand All @@ -19,44 +12,4 @@ import com.blacklivesmatter.policebrutality.worker.SeedDatabaseWorker
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun incidentDao(): IncidentDao

companion object {

// For Singleton instantiation
@Volatile
private var instance: AppDatabase? = null

fun getInstance(context: Context): AppDatabase {
return instance ?: synchronized(this) {
instance ?: buildDatabase(context).also { instance = it }
}
}

private fun buildDatabase(context: Context): AppDatabase {
return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
.addCallback(object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
populateDatabase(context)
}

override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
super.onDestructiveMigration(db)
populateDatabase(context)
}
})
// https://developer.android.com/training/data-storage/room/migrating-db-versions#kotlin
.fallbackToDestructiveMigration()
.build()
}

/**
* Create and pre-populate the database. See this article for more details:
* https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1#4785
*/
private fun populateDatabase(context: Context) {
val request = OneTimeWorkRequestBuilder<SeedDatabaseWorker>().build()
WorkManager.getInstance(context).enqueue(request)
}
}
}
Loading

0 comments on commit a51956d

Please sign in to comment.