Skip to content

Commit

Permalink
fix: Small post-General interest cleanup (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Strat <[email protected]>
  • Loading branch information
evan10s and evan10s authored Sep 9, 2024
1 parent 5edbfff commit 950d282
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Add a brief description of the changes in this PR -->


- [ ] I prefixed my PR title with the change type, generally `feat: ` or `fix: ` (e.g., `feat: Add merchandise distribution`)
16 changes: 16 additions & 0 deletions .github/workflows/task-list-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://github.com/Shopify/task-list-checker
name: pr
permissions:
statuses: write
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
task-list-checker:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.user.login != 'dependabot[bot]' }}
steps:
- name: Check for incomplete task list items
uses: Shopify/task-list-checker@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ android {
getByName("release") {
isMinifyEnabled = false
}
getByName("debug") {
isDebuggable = true
isMinifyEnabled = false
isShrinkResources = false
}
}
buildFeatures {
compose = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ApiaryMobileApplication : Application() {
override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) {
if (BuildConfig.BUILD_TYPE == "debug") {
Timber.plant(Timber.DebugTree())
} else {
SentryAndroid.init(this) { options ->
Expand Down
4 changes: 4 additions & 0 deletions attendance/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ android {
getByName("release") {
isMinifyEnabled = false
}
getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
}
}
buildFeatures {
compose = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class AttendanceViewModel @Inject constructor(
) {
meetingsRepository.getEvents().onSuccess {
attendableEvents.value = this.data.events
.sortedByDescending { it.startTime }
Timber.d(this.data.events.toString())
}.onError {
Timber.e(this.toString(), "Could not fetch attendable events due to an error")
error.value = "Unable to fetch events"
Expand Down
4 changes: 4 additions & 0 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ android {
getByName("release") {
isMinifyEnabled = false
}
getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
}
}
buildFeatures {
compose = true
Expand Down
4 changes: 4 additions & 0 deletions base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ android {
getByName("release") {
isMinifyEnabled = false
}
getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
}
}
buildFeatures {
compose = true
Expand Down
8 changes: 6 additions & 2 deletions base/src/main/java/org/robojackets/apiary/base/model/Event.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.robojackets.apiary.base.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import java.util.Date

@JsonClass(generateAdapter = true)
data class EventsHolder(
Expand All @@ -16,8 +18,10 @@ data class EventHolder(
data class Event(
val id: Int,
val name: String,
// val startTime: Instant,
// val endTime: Instant
@Json(name = "start_time")
val startTime: Date?,
@Json(name = "end_time")
val endTime: Date?
) {
fun toAttendable(): Attendable {
return Attendable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ fun BuzzCardPrompt(
cardType = nfcLib.getCardType(it)

if (cardType == CardType.DESFireEV1 || cardType == CardType.DESFireEV3) {
val desFireEV1 = DESFireFactory.getInstance().getDESFire(nfcLib.customModules)
val desfire = DESFireFactory.getInstance().getDESFire(nfcLib.customModules)

// Below info figured out by :ross: mostly using the NFC TagInfo app
val buzzApplication = 0xBBBBCD
val buzzFile = 0x01
var buzzData = ByteArray(48)
val buzzString: String?

desFireEV1.selectApplication(buzzApplication)
buzzData = desFireEV1.readData(buzzFile, 0, buzzData.size)
desfire.selectApplication(buzzApplication)
buzzData = desfire.readData(buzzFile, 0, buzzData.size)

// a string containing "gtid=proxID", such as "901234567=123456"
buzzString = String(buzzData, StandardCharsets.UTF_8)
Expand Down Expand Up @@ -122,7 +122,7 @@ fun BuzzCardPrompt(
lastTap = buzzCardTap
onBuzzCardTap(buzzCardTap)
} else {
Timber.i("Unknown card type ($cardType) presented")
Timber.w("Unknown card type ($cardType) presented")
error = NotABuzzCard
}
} catch (e: NxpNfcLibException) {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
classpath("com.android.tools.build:gradle:8.6.0-rc01")
classpath("com.android.tools.build:gradle:8.6.0")
classpath("com.google.dagger:hilt-android-gradle-plugin:2.51.1") // This version needs to
// match the version for other Hilt dependencies defined in Dependencies.kt
classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1")
Expand Down Expand Up @@ -92,4 +92,4 @@ dependencyAnalysis {
excludeClasses(".*\\.internal\\..*")
}
}
}
}
4 changes: 4 additions & 0 deletions gitversion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major-version-bump-message: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s-,/\\\\]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)"
minor-version-bump-message: "^(feat)(\\([\\w\\s-,/\\\\]*\\))?:"
patch-version-bump-message: "^(fix|perf)(\\([\\w\\s-,/\\\\]*\\))?:"
no-bump-message: "^(no_release)(\\([\\w\\s-,/\\\\]*\\))?:"
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Dec 15 17:03:27 EST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
4 changes: 4 additions & 0 deletions merchandise/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ android {
getByName("release") {
isMinifyEnabled = false
}
getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
}
}
buildFeatures {
compose = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class MerchandiseItemsHolder(
val merchandise: List<MerchandiseItem> = emptyList()
val merchandise: List<MerchandiseItem>
)

@JsonClass(generateAdapter = true)
data class MerchandiseItemHolder(
val merchandise: MerchandiseItem
)

@JsonClass(generateAdapter = true)
data class MerchandiseItem(
val id: Int,
val name: String,
val distributable: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MerchandiseViewModel @Inject constructor(

fun checkUserAccess(
forceRefresh: Boolean = false,
onSuccess: () -> Unit = {}
onSuccess: () -> Unit = {},
) {
if (user.value != null && !forceRefresh) {
return
Expand Down Expand Up @@ -128,20 +128,17 @@ class MerchandiseViewModel @Inject constructor(

fun loadMerchandiseItems(
forceRefresh: Boolean = false,
selectedItemId: Int? = null,
) {
merchandiseItemsListError.value = null
if (merchandiseItems.value?.isNotEmpty() == true && !forceRefresh) {
Timber.d("Using cached merchandise items")
selectedItemId?.let { selectItemForDistribution(it) }
return
}

loadingMerchandiseItems.value = true
viewModelScope.launch {
merchandiseRepository.listMerchandiseItems().onSuccess {
merchandiseItems.value = this.data.merchandise
selectedItemId?.let { selectItemForDistribution(it) }
loadingMerchandiseItems.value = false
}.onError {
Timber.e(this.toString(), "Could not fetch merchandise items due to an error")
Expand All @@ -154,6 +151,50 @@ class MerchandiseViewModel @Inject constructor(
}
}
}
@Suppress("TooGenericExceptionCaught")
fun selectMerchandiseItemForDistribution(itemId: Int) {
loadingMerchandiseItems.value = true
viewModelScope.launch {
merchandiseRepository.getMerchandiseItem(itemId).onSuccess {
selectedItem.value = this.data.merchandise

if (!this.data.merchandise.distributable) {
Timber.w("Merchandise item is not distributable: ${this.data.merchandise}")
error.value = "${this.data.merchandise.name} is not distributable"
}
loadingMerchandiseItems.value = false
}.onError {
// `this.errorBody` can only be consumed once. If you add a log statement
// including it, then the deserializeErrorBody call will fail
var errorModel: ApiErrorMessage? = null
try {
// Sandwich docs on deserializing errors: https://skydoves.github.io/sandwich/retrofit/#error-body-deserialization
// <A, B> where A is the return type of the outer API call (getMerchandiseItem)
// and B is the type to parse the error body as
// If Android Studio is constantly suggesting to import the deserializeErrorBody
// method, or you get build errors like "None of the following candidates is
// applicable because of receiver type mismatch," it's probably because
// you're specifying the wrong type for A
errorModel =
this.deserializeErrorBody<MerchandiseItemHolder, ApiErrorMessage>()
} catch (e: Exception) {
Timber.e(e, "Could not deserialize error body")
}
Timber.d("status: ${errorModel?.status}, message: ${errorModel?.message}")

Timber.w("Could not fetch merchandise item details: ${errorModel?.message}")
error.value = errorModel?.message ?: "Unable to load merchandise item details"
loadingMerchandiseItems.value = false
}.onException {
Timber.e(
this.throwable,
"Could not fetch merchandise item details due to an exception"
)
error.value = "Unable to load merchandise item details"
loadingMerchandiseItems.value = false
}
}
}

fun navigateToMerchandiseItemDistribution(item: MerchandiseItem) {
navManager.navigate(NavigationActions.Merchandise.merchandiseIndexToDistribution(item.id))
Expand All @@ -163,16 +204,6 @@ class MerchandiseViewModel @Inject constructor(
navManager.navigate(NavigationActions.Merchandise.merchandiseDistributionToIndex())
}

private fun selectItemForDistribution(merchandiseItemId: Int) {
val item = merchandiseItems.value?.find { it.id == merchandiseItemId }
if (item != null) {
selectedItem.value = item
} else {
error.value = "Could not find merchandise item with ID $merchandiseItemId"
Timber.e("Could not find merchandise item with ID $merchandiseItemId")
}
}

@Suppress("TooGenericExceptionCaught")
fun onBuzzCardTap(buzzCardTap: BuzzCardTap) {
if (screenState.value != MerchandiseDistributionScreenState.ReadyForTap) {
Expand Down Expand Up @@ -225,7 +256,10 @@ class MerchandiseViewModel @Inject constructor(

error.value = errorModel?.message ?: "Failed to fetch distribution status"
}.onException {
Timber.e(this.throwable, "Failed to fetch distribution status due to an exception")
Timber.e(
this.throwable,
"Failed to fetch distribution status due to an exception"
)
error.value = "Failed to fetch distribution status"
screenState.value = MerchandiseDistributionScreenState.ShowPickupStatusDialog
}
Expand Down Expand Up @@ -275,14 +309,18 @@ class MerchandiseViewModel @Inject constructor(
error.value = errorModel?.message ?: "Error recording merchandise distribution"
screenState.value = MerchandiseDistributionScreenState.ShowDistributionErrorDialog
}.onException {
Timber.e(this.throwable, "Unable to record merchandise distribution due to an exception")
Timber.e(
this.throwable,
"Unable to record merchandise distribution due to an exception"
)
error.value = "Error recording merchandise distribution"
screenState.value = MerchandiseDistributionScreenState.ShowDistributionErrorDialog
}
}
}

fun dismissPickupDialog() {
error.value = null
screenState.value = MerchandiseDistributionScreenState.ReadyForTap
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.robojackets.apiary.merchandise.network

import com.skydoves.sandwich.ApiResponse
import org.robojackets.apiary.merchandise.model.DistributionHolder
import org.robojackets.apiary.merchandise.model.MerchandiseItemHolder
import org.robojackets.apiary.merchandise.model.MerchandiseItemsHolder
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
Expand All @@ -13,6 +14,11 @@ interface MerchandiseApiService {
@GET("/api/v1/merchandise")
suspend fun getMerchandiseItems(): ApiResponse<MerchandiseItemsHolder>

@GET("/api/v1/merchandise/{itemId}")
suspend fun getMerchandiseItem(
@Path("itemId") itemId: Int,
): ApiResponse<MerchandiseItemHolder>

@GET("/api/v1/merchandise/{itemId}/distribute/{gtid}")
suspend fun getDistributionStatus(
@Path("itemId") itemId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MerchandiseRepository @Inject constructor(
val merchandiseApiService: MerchandiseApiService,
) {
suspend fun listMerchandiseItems() = merchandiseApiService.getMerchandiseItems()
suspend fun getMerchandiseItem(itemId: Int) = merchandiseApiService.getMerchandiseItem(itemId)
suspend fun getDistributionStatus(itemId: Int, gtid: Int) =
merchandiseApiService.getDistributionStatus(itemId, gtid)
suspend fun distributeItem(itemId: Int, gtid: Int, providedVia: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ fun PreviewCurrentlySelectedItem() {
CurrentlySelectedItem(
MerchandiseItem(
2,
"Test item with a super duper long name so it will get cut off"
"Test item with a super duper long name so it will get cut off",
true,
)
) {}
}
Expand Down
Loading

0 comments on commit 950d282

Please sign in to comment.