Skip to content

Commit

Permalink
Added workers to update widgets data
Browse files Browse the repository at this point in the history
  • Loading branch information
svignesh93 committed Nov 6, 2021
1 parent c9aa5bf commit 3b9ab23
Show file tree
Hide file tree
Showing 13 changed files with 468 additions and 227 deletions.
21 changes: 20 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

android {
Expand Down Expand Up @@ -45,9 +46,27 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'

// Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

// Work Manager
implementation "androidx.work:work-runtime-ktx:$work_version"
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt 'androidx.hilt:hilt-compiler:1.0.0'

// Hilt - Instrumentation test helpers
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
kaptAndroidTest "com.google.dagger:hilt-compiler:$hilt_version"

// Hilt - Local unit test helpers
testImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
kaptTest "com.google.dagger:hilt-compiler:$hilt_version"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.litekite.sample">

<application
android:name=".app.WidgetsApp"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -26,6 +28,12 @@
android:supportsRtl="true"
android:theme="@style/Theme.AppWidgets">

<!-- If you want to disable android.startup completely. -->
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove" />

<activity
android:name=".main.MainActivity"
android:exported="true">
Expand All @@ -37,15 +45,15 @@
</activity>

<activity
android:name=".appwidget.AppWidgetConfigActivity"
android:name=".appwidget.weather.AppWidgetConfigActivity"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>

<receiver
android:name=".appwidget.WeatherAppWidgetProvider"
android:name=".appwidget.weather.WeatherAppWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/kotlin/com/litekite/sample/app/WidgetsApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021 LiteKite Startup. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.litekite.sample.app

import android.app.Application
import android.content.res.Configuration
import android.util.Log
import androidx.hilt.work.HiltWorkerFactory
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import androidx.work.Configuration as WorkManagerConfig

@HiltAndroidApp
class WidgetsApp : Application(), WorkManagerConfig.Provider {

@Inject
lateinit var workerFactory: HiltWorkerFactory

companion object {
val TAG: String = WidgetsApp::class.java.simpleName
}

override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate:")
}

override fun getWorkManagerConfiguration(): WorkManagerConfig {
return WorkManagerConfig.Builder()
.setMinimumLoggingLevel(Log.DEBUG)
.setWorkerFactory(workerFactory)
.build()
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
Log.d(TAG, "onConfigurationChanged:")
}

override fun onTerminate() {
super.onTerminate()
Log.d(TAG, "onTerminate:")
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.litekite.sample.appwidget
package com.litekite.sample.appwidget.weather

import android.app.Activity
import android.appwidget.AppWidgetManager
Expand Down
Loading

0 comments on commit 3b9ab23

Please sign in to comment.