-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
sample/src/main/java/com/deliveryhero/whetstone/MainService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.deliveryhero.whetstone | ||
|
||
import android.app.Service | ||
import android.content.Intent | ||
import android.os.IBinder | ||
import androidx.core.app.NotificationCompat | ||
import com.deliveryhero.whetstone.injector.ContributesInjector | ||
import com.deliveryhero.whetstone.scope.ServiceScope | ||
import javax.inject.Inject | ||
|
||
@ContributesInjector(ServiceScope::class) | ||
class MainService : Service() { | ||
|
||
@Inject | ||
lateinit var dependency: MainDependency | ||
|
||
override fun onCreate() { | ||
Whetstone.inject(this) | ||
super.onCreate() | ||
} | ||
|
||
override fun onBind(intent: Intent?): IBinder? = null | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
|
||
val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) | ||
.setContentTitle("${this.javaClass.simpleName} is running") | ||
.setContentText(dependency.getMessage("Service")) | ||
.setSmallIcon(R.drawable.ic_baseline_textsms_24) | ||
.setAutoCancel(true) | ||
.build() | ||
startForeground(1, notification) | ||
|
||
return START_NOT_STICKY | ||
} | ||
|
||
companion object { | ||
const val NOTIFICATION_CHANNEL_ID = "MainChannel" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM9,11L7,11L7,9h2v2zM13,11h-2L11,9h2v2zM17,11h-2L15,9h2v2z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
whetstone/src/main/java/com/deliveryhero/whetstone/component/ServiceComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.deliveryhero.whetstone.component | ||
|
||
import android.app.Service | ||
import com.deliveryhero.whetstone.SingleIn | ||
import com.deliveryhero.whetstone.injector.MembersInjectorMap | ||
import com.deliveryhero.whetstone.scope.ApplicationScope | ||
import com.deliveryhero.whetstone.scope.ServiceScope | ||
import com.squareup.anvil.annotations.ContributesSubcomponent | ||
import com.squareup.anvil.annotations.ContributesTo | ||
import dagger.BindsInstance | ||
import dagger.Module | ||
import dagger.multibindings.Multibinds | ||
|
||
/** | ||
* A Dagger component that has the lifetime of the [android.app.Service]. | ||
*/ | ||
@ContributesSubcomponent(scope = ServiceScope::class, parentScope = ApplicationScope::class) | ||
@SingleIn(ServiceScope::class) | ||
public interface ServiceComponent { | ||
public fun getMembersInjectorMap(): MembersInjectorMap | ||
|
||
/** | ||
* Interface for creating a [ServiceComponent]. | ||
*/ | ||
@ContributesSubcomponent.Factory | ||
public interface Factory { | ||
public fun create(@BindsInstance service: Service): ServiceComponent | ||
} | ||
|
||
@ContributesTo(ApplicationScope::class) | ||
public interface ParentComponent { | ||
public fun getServiceComponentFactory(): Factory | ||
} | ||
} | ||
|
||
@Module | ||
@ContributesTo(ServiceScope::class) | ||
public interface ServiceModule { | ||
|
||
@Multibinds | ||
public fun membersInjectors(): MembersInjectorMap | ||
} |
6 changes: 6 additions & 0 deletions
6
whetstone/src/main/java/com/deliveryhero/whetstone/scope/ServiceScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.deliveryhero.whetstone.scope | ||
|
||
/** | ||
* Scope marker class for bindings that should exist for the life of a [android.app.Service]. | ||
*/ | ||
public class ServiceScope private constructor() |