Initial commit: HotDeal Alarm Android App
Features: - Multi-site hot deal scraping (Ppomppu, Clien, Ruriweb, Coolenjoy) - Site filter with color-coded badges - Board display names (e.g., ppomppu8 -> 알리뽐뿌) - Anti-bot protection with request delays and User-Agent rotation - Keyword matching and notifications - Material Design 3 UI
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.hotdeal.alarm.widget
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.RemoteViews
|
||||
import com.hotdeal.alarm.R
|
||||
import com.hotdeal.alarm.presentation.main.MainActivity
|
||||
|
||||
/**
|
||||
* 핫딜 위젯 프로바이더
|
||||
*/
|
||||
class HotDealWidget : AppWidgetProvider() {
|
||||
|
||||
companion object {
|
||||
const val ACTION_REFRESH = "com.hotdeal.alarm.widget.REFRESH"
|
||||
}
|
||||
|
||||
override fun onUpdate(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetIds: IntArray
|
||||
) {
|
||||
appWidgetIds.forEach { appWidgetId ->
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
super.onReceive(context, intent)
|
||||
|
||||
when (intent.action) {
|
||||
ACTION_REFRESH -> {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val appWidgetIds = appWidgetManager.getAppWidgetIds(
|
||||
intent.component ?: return
|
||||
)
|
||||
onUpdate(context, appWidgetManager, appWidgetIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAppWidget(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int
|
||||
) {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_hot_deal)
|
||||
|
||||
// 클릭으로 앱 열기
|
||||
val pendingIntent = android.app.PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
Intent(context, MainActivity::class.java),
|
||||
android.app.PendingIntent.FLAG_UPDATE_CURRENT or android.app.PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_container, pendingIntent)
|
||||
|
||||
// 새로고침 버튼
|
||||
val refreshIntent = Intent(context, HotDealWidget::class.java).apply {
|
||||
action = ACTION_REFRESH
|
||||
}
|
||||
val refreshPendingIntent = android.app.PendingIntent.getBroadcast(
|
||||
context,
|
||||
0,
|
||||
refreshIntent,
|
||||
android.app.PendingIntent.FLAG_UPDATE_CURRENT or android.app.PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.btn_refresh, refreshPendingIntent)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user