Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ dependencies {
implementation(libs.activity)
api("org.wordpress:aztec:v1.6.2")
implementation("com.github.bumptech.glide:glide:4.16.0")
implementation(libs.androidx.hilt.common)

// TEST
testImplementation(libs.junit)
Expand Down Expand Up @@ -176,4 +177,12 @@ dependencies {
//admob
implementation("com.google.android.gms:play-services-ads:23.2.0")
implementation("com.google.firebase:firebase-ads:18.0.0")

//widget
implementation ("androidx.glance:glance-appwidget:1.0.0")

//workmanager
implementation("androidx.work:work-runtime-ktx:2.7.1")
implementation("androidx.hilt:hilt-work:1.0.0")
implementation("androidx.hilt:hilt-compiler:1.0.0")
}
17 changes: 17 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
android:theme="@style/Theme.KekKek"
tools:targetApi="31">

<!-- 위젯 브로드캐스트 리시버 -->
<receiver android:name=".widget.WidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</receiver>

<service
android:name=".core.firemseeage.MessageService"
android:enabled="true"
Expand All @@ -27,17 +38,21 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<!--
Set custom default icon. This is used when no icon is set for incoming notification messages.
See README(https://goo.gl/l4GJaQ) for more.
-->

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification_white" />

<!--
Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. See README(https://goo.gl/6BKBk7) for more.
-->

<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/primary_blue" />
Expand Down Expand Up @@ -72,6 +87,7 @@
android:exported="true"
android:windowSoftInputMode="adjustUnspecified">
</activity>

<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
Expand All @@ -86,6 +102,7 @@
android:scheme="kakao ${KAKAO_NATIVE_API_KEY}" />
</intent-filter>
</activity>

<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:label="오픈소스 라이선스" />
Expand Down
60 changes: 60 additions & 0 deletions app/src/main/java/com/stopsmoke/kekkek/widget/WidgetProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.stopsmoke.kekkek.widget

import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.widget.RemoteViews
import com.google.firebase.firestore.FirebaseFirestore
import com.stopsmoke.kekkek.R
import com.stopsmoke.kekkek.core.domain.repository.UserRepository
import com.stopsmoke.kekkek.presentation.MainActivity

class WidgetProvider : AppWidgetProvider() {

override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId)
}
}

companion object {
private fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
val views = RemoteViews(context.packageName, R.layout.widget_smoketime)

// Firestore에서 데이터 가져오기
val db = FirebaseFirestore.getInstance()
db.collection("users").document("user_id") // user_id를 실제 사용자 ID로 바꾸어야 함
.get()
.addOnSuccessListener { document ->
if (document != null) {
val totalMinutesTime = document.getLong("totalMinutesTime") ?: 0
val formattedTime = formatElapsedTime(totalMinutesTime)
views.setTextViewText(R.id.widget_time, formattedTime)
} else {
views.setTextViewText(R.id.widget_time, "Error loading data")
}
appWidgetManager.updateAppWidget(appWidgetId, views)
}
.addOnFailureListener {
views.setTextViewText(R.id.widget_time, "Error loading data")
appWidgetManager.updateAppWidget(appWidgetId, views)
}

// 위젯 클릭 시 앱 열기
val intent = Intent(context, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
views.setOnClickPendingIntent(R.id.widget_smoketime, pendingIntent)

appWidgetManager.updateAppWidget(appWidgetId, views)
}

private fun formatElapsedTime(totalMinutes: Long): String {
val hours = totalMinutes / 60
val minutes = totalMinutes % 60
return "${hours}시간 ${minutes}분"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions app/src/main/res/layout/widget_smoketime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_smoketime"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="20dp">

<ImageView
android:id="@+id/widget_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@mipmap/ic_kekkek" />

<TextView
android:id="@+id/widget_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/widget_image"
android:layout_marginTop="0dp"
android:fontFamily="@font/pretendard_bold"
android:text="금연한 시간"
android:textColor="@color/primary_blue"
android:textSize="20sp"
android:textStyle="bold" />

<TextView
android:id="@+id/widget_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/widget_title"
android:layout_marginTop="10dp"
android:fontFamily="@font/pretendard_semi_bold"
android:text="Loading..."
android:textColor="@color/gray_gray1"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/xml/widget_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="110dp"
android:minHeight="80dp"
android:updatePeriodMillis="600000"
android:initialLayout="@layout/widget_smoketime"
android:widgetCategory="home_screen"
android:previewImage="@drawable/widget_smoketime_preview"
android:resizeMode="none"
android:minResizeWidth="110dp"
android:minResizeHeight="40dp">
</appwidget-provider>
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ googleOssLicenses = "17.0.1"
activityVersion = "1.8.0"

kotlinPluginSerialization = "1.6.10"
hiltCommon = "1.2.0"


[libraries]
Expand Down Expand Up @@ -72,6 +73,7 @@ androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", ve

android-gms-oos-licenses = { group = "com.google.android.gms", name = "play-services-oss-licenses", version.ref = "googleOssLicenses" }
activity = { group = "androidx.activity", name = "activity", version.ref = "activityVersion" }
androidx-hilt-common = { group = "androidx.hilt", name = "hilt-common", version.ref = "hiltCommon" }


[plugins]
Expand Down