Skip to content

Commit

Permalink
detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfriend committed Oct 19, 2023
1 parent 7180198 commit e9f31ba
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 651 deletions.
37 changes: 25 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
Expand All @@ -19,7 +22,7 @@ plugins {
// Others experiencing it: https://github.com/gradle/gradle/issues/3593
// Mozilla decided to live with the duplication: https://github.com/mozilla-mobile/focus-android/issues/1886
// Possible solution that requires changing to Gradle Kotlin DSL: https://github.com/gradle/gradle/issues/1697
id "io.gitlab.arturbosch.detekt" version "1.16.0"
id "io.gitlab.arturbosch.detekt" version "1.23.1"
}

allprojects {
Expand All @@ -38,29 +41,39 @@ allprojects {
}

subprojects {
def detektVersion = "1.16.0"

apply plugin: 'io.gitlab.arturbosch.detekt'

detekt {
toolVersion = detektVersion
buildUponDefaultConfig = true // preconfigure defaults
allRules = false // activate all available (even unstable) rules.
config = files("$rootProject.projectDir/detekt-config.yml")
baseline = file("$rootProject.projectDir/detekt-baseline.xml")

reports {
html {
enabled = true
destination = file("$project.buildDir/reports/detekt.html")
}
}
}

// enable detekt formatting rules
dependencies {
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion"
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1"
detektPlugins "io.gitlab.arturbosch.detekt:detekt-rules-style:1.23.1"
}
tasks.withType(Detekt).configureEach {
jvmTarget = "1.8"
reports {
html.required = true
}
}
tasks.withType(DetektCreateBaselineTask).configureEach {
jvmTarget = "1.8"
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}


//buildCache {
// local {
// directory = new File(rootDir, '.gradle/build-cache')
// removeUnusedEntriesAfterDays = 30
// }
//}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ import io.reactivex.Single
@Dao
interface CardDao {
@Transaction
@Query("""
SELECT
Card.*,
CASE Card.id WHEN CAST(:ftsTerm AS INTEGER) then 1 ELSE 0 END AS _rank
FROM Card
LEFT OUTER JOIN (
SELECT Rule.cardPk as cardPk from Rule
JOIN RuleFts on RuleFts.docid = Rule.id
WHERE RuleFts MATCH :ftsTerm
) AS rule_fts ON rule_fts.cardPk = Card.pk
LEFT OUTER JOIN (
SELECT docid as cardPk FROM CardFts WHERE CardFts MATCH :ftsTerm
) AS card_fts ON card_fts.cardPk = Card.pk
WHERE
Card.deck in (:decks)
AND COALESCE(rule_fts.cardPk, card_fts.cardPk) IS NOT NULL
GROUP BY Card.pk
ORDER BY _rank DESC, Card.pk ASC
""")
@Query(
"""
SELECT
Card.*,
CASE Card.id WHEN CAST(:ftsTerm AS INTEGER) then 1 ELSE 0 END AS _rank
FROM Card
LEFT OUTER JOIN (
SELECT Rule.cardPk as cardPk from Rule
JOIN RuleFts on RuleFts.docid = Rule.id
WHERE RuleFts MATCH :ftsTerm
) AS rule_fts ON rule_fts.cardPk = Card.pk
LEFT OUTER JOIN (
SELECT docid as cardPk FROM CardFts WHERE CardFts MATCH :ftsTerm
) AS card_fts ON card_fts.cardPk = Card.pk
WHERE
Card.deck in (:decks)
AND COALESCE(rule_fts.cardPk, card_fts.cardPk) IS NOT NULL
GROUP BY Card.pk
ORDER BY _rank DESC, Card.pk ASC
"""
)
fun getCardsByDeckAndQuery(
decks: Array<Deck>,
ftsTerm: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import com.fueledbycaffeine.bunnypedia.database.model.CardWithRules
import com.fueledbycaffeine.bunnypedia.database.model.Deck
import io.reactivex.Single
import timber.log.Timber
import java.util.Locale

class CardStore(private val dao: CardDao) {
fun getCards(decks: Set<Deck>, query: String): DataSource.Factory<Int, CardWithRules> {
return if (query.isNotEmpty()) {
// String IDs must be matched with the prefix 0s, so build terms including those leading 0s
val ftsTerm = if (query.matches("^\\d+$".toRegex()) && query.length < 4) {
val terms = (query.length..4).map { size ->
String.format("%0${size}d*", query.toInt())
String.format(Locale.US, "%0${size}d*", query.toInt())
}
terms.joinToString(" OR ")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ import com.fueledbycaffeine.bunnypedia.database.model.RankType.ENLISTED
import com.fueledbycaffeine.bunnypedia.database.model.RankType.OFFICER

enum class Rank(val type: RankType, val grade: Int) {
// Enlisted
E1(ENLISTED, 1), // Seaman Recruit
E2(ENLISTED, 2), // Seaman Apprentice
E3(ENLISTED, 3), // Seaman
E4(ENLISTED, 4), // Petty Officer 3rd Class
E5(ENLISTED, 5), // Petty Officer 2nd Class
E6(ENLISTED, 6), // Petty Officer 1st Class
E7(ENLISTED, 7), // Chief Petty Officer
E8(ENLISTED, 8), // Senior Chief Petty Officer
E9(ENLISTED, 9), // Master Chief Petty Officer
// Officer
O1(OFFICER, 1), // Ensign
O2(OFFICER, 2), // Lieutenant JG
O3(OFFICER, 3), // Lieutenant
O4(OFFICER, 4), // Lieutenant Commander
O5(OFFICER, 5), // Commander
O6(OFFICER, 6), // Captain
O7(OFFICER, 7), // Lower Rear Admiral
O8(OFFICER, 8), // Upper Rear Admiral
O9(OFFICER, 9), // Vice Admiral
E1(ENLISTED, 1), // Seaman Recruit
E2(ENLISTED, 2), // Seaman Apprentice
E3(ENLISTED, 3), // Seaman
E4(ENLISTED, 4), // Petty Officer 3rd Class
E5(ENLISTED, 5), // Petty Officer 2nd Class
E6(ENLISTED, 6), // Petty Officer 1st Class
E7(ENLISTED, 7), // Chief Petty Officer
E8(ENLISTED, 8), // Senior Chief Petty Officer
E9(ENLISTED, 9), // Master Chief Petty Officer
O1(OFFICER, 1), // Ensign
O2(OFFICER, 2), // Lieutenant JG
O3(OFFICER, 3), // Lieutenant
O4(OFFICER, 4), // Lieutenant Commander
O5(OFFICER, 5), // Commander
O6(OFFICER, 6), // Captain
O7(OFFICER, 7), // Lower Rear Admiral
O8(OFFICER, 8), // Upper Rear Admiral
O9(OFFICER, 9), // Vice Admiral
;

val description: Int @StringRes get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ enum class ZodiacSign(val element: ZodiacElement, val number: Int) {
}
}

@Suppress("NoMultipleSpaces")
val range: Pair<MonthDay, MonthDay> get() = when (this) {
CAPRICORN -> MonthDay.of(Month.DECEMBER, 22) to MonthDay.of(Month.JANUARY, 20)
AQUARIUS -> MonthDay.of(Month.JANUARY, 21) to MonthDay.of(Month.FEBRUARY, 19)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import dagger.android.support.AndroidSupportInjectionModule
import javax.inject.Singleton

@Singleton
@Component(modules = [
AndroidSupportInjectionModule::class,
AppModule::class,
ActivityModule::class,
DatabaseModule::class
])
@Component(
modules = [
AndroidSupportInjectionModule::class,
AppModule::class,
ActivityModule::class,
DatabaseModule::class
]
)
internal interface AppComponent : AndroidInjector<App> {
@Suppress("DEPRECATION")
@Component.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ import timber.log.Timber
class DatabaseModule {
@Provides
fun provideDatabase(context: Context): AppDatabase {
return Room.databaseBuilder(
return Room
.databaseBuilder(
context,
AppDatabase::class.java,
DATABASE_NAME
)
.createFromAsset("databases/$DATABASE_NAME", object : RoomDatabase.PrepackagedDatabaseCallback() {
override fun onOpenPrepackagedDatabase(db: SupportSQLiteDatabase) {
Timber.i("Copying packaged db asset: ${db.path}")
.createFromAsset(
"databases/$DATABASE_NAME",
object : RoomDatabase.PrepackagedDatabaseCallback() {
override fun onOpenPrepackagedDatabase(db: SupportSQLiteDatabase) {
Timber.i("Copying packaged db asset: ${db.path}")
}
}
})
)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fueledbycaffeine.bunnypedia.ui.card.list

import androidx.paging.PagedListAdapter
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import com.fueledbycaffeine.bunnypedia.R
import com.fueledbycaffeine.bunnypedia.database.model.CardWithRules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.fueledbycaffeine.bunnypedia.ui.card.list

import androidx.core.content.ContextCompat
import android.view.View
import androidx.core.content.ContextCompat
import com.bumptech.glide.RequestManager
import com.bumptech.glide.request.target.Target
import com.fueledbycaffeine.bunnypedia.R
import com.fueledbycaffeine.bunnypedia.database.model.CardWithRules
import com.fueledbycaffeine.bunnypedia.util.ColorUtil
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.card_view_grid_item.*
import kotlinx.android.synthetic.main.card_view_grid_item.image
import kotlinx.android.synthetic.main.card_view_grid_item.title
import kotlinx.android.synthetic.main.card_view_grid_item.titleBackground

class CardGridViewHolder(override val containerView: View) : CardViewHolder(containerView), LayoutContainer {
override fun bind(requestManager: RequestManager, cardAndRules: CardWithRules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.fueledbycaffeine.bunnypedia.ext.android.stripHtmlTags
import com.fueledbycaffeine.bunnypedia.util.ColorUtil
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.card_view_list_item.*
import java.util.Locale

class CardListViewHolder(override val containerView: View) : CardViewHolder(containerView), LayoutContainer {
override fun bind(requestManager: RequestManager, cardAndRules: CardWithRules) {
Expand All @@ -20,7 +21,7 @@ class CardListViewHolder(override val containerView: View) : CardViewHolder(cont
.into(image)

val (card, rules) = cardAndRules
cardNumber.text = String.format("#%s", card.id)
cardNumber.text = String.format(Locale.US, "#%s", card.id)
title.text = card.title
cardText.text = rules.firstOrNull()?.text?.stripHtmlTags() ?: ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fueledbycaffeine.bunnypedia.ui.card.list

import android.view.View
import com.bumptech.glide.RequestManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.RequestManager
import com.fueledbycaffeine.bunnypedia.database.model.CardWithRules

abstract class CardViewHolder(view: View) : RecyclerView.ViewHolder(view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ object ColorUtil {
fun getLuminance(@ColorInt color: Int): Double {
return 1 - (
0.299 * Color.red(color) +
0.587 * Color.green(color) +
0.114 * Color.blue(color)
) / 255
0.587 * Color.green(color) +
0.114 * Color.blue(color)
) / 255
}

@ColorInt fun contrastColor(@ColorInt color: Int): Int {
@ColorInt
fun contrastColor(@ColorInt color: Int): Int {
val luminance = getLuminance(color)
val white = if (luminance < 0.5) 0 else 255
return Color.argb(255, white, white, white)
}

@ColorInt fun darkenColor(@ColorInt color: Int, byAmount: Float): Int {
@ColorInt
fun darkenColor(@ColorInt color: Int, byAmount: Float): Int {
val hsv = FloatArray(3)
Color.colorToHSV(color, hsv)
hsv[2] *= (1 - byAmount)
Expand Down
Loading

0 comments on commit e9f31ba

Please sign in to comment.