Skip to content

Commit

Permalink
🔀 :: (#698) 급식 위젯
Browse files Browse the repository at this point in the history
  • Loading branch information
parkuiery committed Aug 3, 2024
2 parents 07b31fd + 704beef commit a568631
Show file tree
Hide file tree
Showing 55 changed files with 1,006 additions and 150 deletions.
10 changes: 8 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()

versionCode = 15
versionName = "1.3.6"
versionCode = 16
versionName = "1.3.7"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -66,6 +66,8 @@ dependencies {
implementation(project(ProjectPaths.Core.PROJECT))
implementation(project(ProjectPaths.Core.SCHOOL))
implementation(project(ProjectPaths.Core.UI))
implementation(project(ProjectPaths.Core.NOTIFICATION))
implementation(project(ProjectPaths.Core.DEVICE))
implementation(project(ProjectPaths.Core.WIDGET))

implementation(project(ProjectPaths.DATA))
Expand Down Expand Up @@ -125,6 +127,10 @@ dependencies {

implementation(libs.app.update)

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)
implementation(libs.firebase.analytics)

implementation(libs.androidx.work.runtime.ktx)

implementation(libs.androidx.hilt.work)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.DmsMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="om.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_logo_image"/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />

<receiver
android:name="team.aliens.dms.android.core.widget.meal.MealWidgetReceiver"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/team/aliens/dms/android/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import androidx.activity.compose.setContent
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import team.aliens.dms.android.core.designsystem.DmsTheme
import team.aliens.dms.android.core.jwt.di.IsJwtAvailable
import team.aliens.dms.android.core.notification.DeviceTokenManager
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -24,6 +29,9 @@ class MainActivity : ComponentActivity() {
@Inject
lateinit var isJwtAvailable: StateFlow<Boolean>

@Inject
lateinit var deviceTokenManager: DeviceTokenManager

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -46,6 +54,10 @@ class MainActivity : ComponentActivity() {
)
}
}

lifecycleScope.launch {
deviceTokenManager.fetchDeviceToken()
}
}

private fun checkAppUpdate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package team.aliens.dms.android.app.service

import android.os.Build
import androidx.annotation.RequiresApi
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import team.aliens.dms.android.core.notification.DeviceTokenManager
import team.aliens.dms.android.core.notification.NotificationManager
import javax.inject.Inject

@AndroidEntryPoint
class DmsMessagingService : FirebaseMessagingService() {

@Inject
lateinit var deviceTokenManager: DeviceTokenManager

private val notificationManager: NotificationManager by lazy {
NotificationManager(context = this)
}

override fun onNewToken(deviceToken: String) {
super.onNewToken(deviceToken)
CoroutineScope(Dispatchers.IO).launch {
deviceTokenManager.saveDeviceToken(deviceToken = deviceToken)
}
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
message.notification?.run {
notificationManager.setNotificationContent(
title = title,
body = body,
)
}
notificationManager.sendNotification()
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">DMS</string>
<string name="default_notification_channel_id">team.aliens.dms.android</string>
</resources>
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// TODO: Remove once KTIJ-19369 is fixed
@file:Suppress("DSL_SCOPE_VIOLATION")

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath(libs.google.services)
}
}

plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/ProjectPaths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ object ProjectPaths {
const val SCHOOL = ":core:school"
const val UI = ":core:ui"
const val FILE = ":core:file"
const val NOTIFICATION = ":core:notification"
const val DEVICE = ":core:device"
const val WIDGET = ":core:widget"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

@Composable
fun Button(
private fun Button(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
Expand All @@ -63,7 +63,7 @@ fun Button(
contentColor = contentColor,
shadowElevation = shadowElevation,
border = border,
interactionSource = interactionSource
interactionSource = interactionSource,
) {
CompositionLocalProvider(LocalContentColor provides contentColor) {
ProvideTextStyle(value = DmsTheme.typography.button) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package team.aliens.dms.android.core.designsystem

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Picker(
items: List<String>,
state: PickerState = rememberPickerState(),
modifier: Modifier = Modifier,
startIndex: Int = 0,
visibleItemsCount: Int = 3,
textModifier: Modifier = Modifier,
textStyle: TextStyle = LocalTextStyle.current,
) {
val visibleItemsMiddle = visibleItemsCount / 2
val listScrollCount = Integer.MAX_VALUE
val listScrollMiddle = listScrollCount / 2
val listStartIndex = listScrollMiddle - listScrollMiddle % items.size - visibleItemsMiddle + startIndex

fun getItem(index: Int) = items[index % items.size]

val listState = rememberLazyListState(initialFirstVisibleItemIndex = listStartIndex)
val flingBehavior = rememberSnapFlingBehavior(lazyListState = listState)

val itemHeightPixels = remember { mutableIntStateOf(0) }
val itemHeightDp = pixelsToDp(itemHeightPixels.value)

val fadingEdgeGradient = remember {
Brush.verticalGradient(
0f to Color.Transparent,
0.5f to Color.Black,
1f to Color.Transparent
)
}

LaunchedEffect(listState) {
snapshotFlow { listState.firstVisibleItemIndex }
.map { index -> getItem(index + visibleItemsMiddle) }
.distinctUntilChanged()
.collect { item -> state.selectedItem = item }
}

Box(modifier = modifier) {
LazyColumn(
state = listState,
flingBehavior = flingBehavior,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxWidth()
.height(itemHeightDp * visibleItemsCount)
.fadingEdge(fadingEdgeGradient)
) {
items(listScrollCount) { index ->
Text(
text = getItem(index),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = textStyle,
modifier = Modifier
.onSizeChanged { size -> itemHeightPixels.value = size.height }
.then(textModifier)
)
}
}
}
}

private fun Modifier.fadingEdge(brush: Brush) = this
.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
.drawWithContent {
drawContent()
drawRect(brush = brush, blendMode = BlendMode.DstIn)
}

@Composable
private fun pixelsToDp(pixels: Int) = with(LocalDensity.current) { pixels.toDp() }

@Composable
fun rememberPickerState() = remember { PickerState() }

class PickerState {
var selectedItem by mutableStateOf("")
}
1 change: 1 addition & 0 deletions core/device/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions core/device/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
}

android {
namespace = "team.aliens.dms.android.core.device"
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = Versions.java
targetCompatibility = Versions.java
}

kotlinOptions {
jvmTarget = Versions.java.toString()
}
}

dependencies {
implementation(project(ProjectPaths.Core.DATASTORE))

implementation(libs.androidx.core)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso)

implementation(libs.androidx.datastore.preferences)

implementation(libs.hilt)
ksp(libs.hilt.compiler)
}
Empty file added core/device/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/device/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading

0 comments on commit a568631

Please sign in to comment.