-
Notifications
You must be signed in to change notification settings - Fork 0
Keep node running when the app is in background #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
1636d74
refactor: move logic and shared states from viewmodel to WalletRepo.k…
jvsena42 2f46752
refactor: move logic and shared states from viewmodel to LightningRep…
jvsena42 b993a25
refactor: move logic and shared states from viewmodel to LightningRep…
jvsena42 0a322f7
refactor: move logic and shared states from viewmodel to repository
jvsena42 52f8341
refactor: remove reference
jvsena42 345f3d7
fix: dependency injection
jvsena42 8dc59ad
feat: add comments
jvsena42 dc57927
Merge branch 'master' into feat/keep-node-in-background
jvsena42 fc97264
feat: create the LightningNodeService.kt
jvsena42 cba301f
feat: check if the node is running before call start
jvsena42 9e5b571
feat: create the notification channel
jvsena42 82af9c1
refactor: remove stop call from view
jvsena42 5866cd8
feat: start service
jvsena42 490b192
feat: refresh bip 21
jvsena42 b62b4a7
feat: add retry
jvsena42 611b185
refactor: remove comment
jvsena42 0553436
refactor: deprecate walletViewModel
jvsena42 f229fb4
test: WalletRepoTest.kt WIP
jvsena42 8a01b5d
test: WalletRepoTest.kt
jvsena42 ae511c4
test: update tests
jvsena42 6a45eb1
test: LightningRepoTest.kt
jvsena42 1081307
test: update WalletViewModelTest.kt
jvsena42 0e63f35
refactor: restoring wallet state access
jvsena42 15b1c1f
refactor: remove imports
jvsena42 273ef07
fix: clear states when wipe wallet
jvsena42 f1b363e
Merge branch 'master' into feat/keep-node-in-background
jvsena42 4f5932d
fix: only trigger onInputChanged if the primary display has changed
jvsena42 931c68f
fix: keep states
jvsena42 c129e4c
fix: continue button label
jvsena42 ac631f6
fix: keep the balance input state while the qr code is displayed and …
jvsena42 43a0ee3
fix: keep the balance input state while the qr code is displayed and …
jvsena42 51c00e6
fix: keep the balance input state while the qr code is displayed and …
jvsena42 7d35202
fix: set ime option as done
jvsena42 1d5d72d
Merge pull request #127 from synonymdev/fix/edit-invoice-keep-state
ovitrif 9a041c9
refactor: change notification name and ID
jvsena42 c1c4d25
refactor: use initNotificationChannel
jvsena42 a1f7736
fix: add service permission
jvsena42 9766445
fix: move initAppStoragePath before service call
jvsena42 6a2cf13
fix: Round icon
jvsena42 6d95584
refactor: remove unused code
jvsena42 dc8bd92
fix: isRefreshing state update
jvsena42 761960c
refactor: updateBip21Invoice overload
jvsena42 b56085c
refactor:remove unnecessary setWalletExistsState calls
jvsena42 0971b2d
refactor: sync node only at specific events
jvsena42 fc1b041
refactor: restore observeLdkWallet logic
jvsena42 c0de93c
fix: call syncState and sync balance also before sync
jvsena42 2ef9e33
Merge branch 'master' into feat/keep-node-in-background
jvsena42 65579be
fix: solve conflicts
jvsena42 0d6ef4b
fix: sync balances at start
jvsena42 d305dd1
fix: stop node and reset lone state when wipe the wallet
jvsena42 37a6fd8
fix: log
jvsena42 e53e1a0
fix: move notification methods to LightningNodeService and add execut…
jvsena42 0fe84dd
fix: clear bip 21 state at start of refreshBip21
jvsena42 36de195
feat: add button to stop the service
jvsena42 29ba400
feat: move service intent to MainActivity
jvsena42 17af26a
test: update tests
jvsena42 531a167
test: update tests
jvsena42 cea53d0
test: update tests
jvsena42 1bfc621
test: update tests
jvsena42 47bc392
test: update tests
jvsena42 20824d7
test: update tests
jvsena42 509f51d
test: update tests
jvsena42 e5cba64
Merge branch 'master' into feat/keep-node-in-background
jvsena42 1262b70
test: implement bg image
jvsena42 17b4bf6
feat: fading animation
jvsena42 3e7aab6
feat: move softKeyboard logic to a keyboardAsState method
jvsena42 7ceda66
Merge pull request #132 from synonymdev/feat/bg-edit-invoice
ovitrif 3a04a15
feat: preview
jvsena42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
125 changes: 125 additions & 0 deletions
125
app/src/main/java/to/bitkit/androidServices/LightningNodeService.kt
This file contains hidden or 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,125 @@ | ||
| package to.bitkit.androidServices | ||
|
|
||
| import android.app.Notification | ||
| import android.app.PendingIntent | ||
| import android.app.Service | ||
| import android.content.Intent | ||
| import android.os.IBinder | ||
| import androidx.core.app.NotificationCompat | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.SupervisorJob | ||
| import kotlinx.coroutines.cancel | ||
| import kotlinx.coroutines.launch | ||
| import to.bitkit.App | ||
| import to.bitkit.R | ||
| import to.bitkit.repositories.LightningRepo | ||
| import to.bitkit.repositories.WalletRepo | ||
| import to.bitkit.ui.MainActivity | ||
| import to.bitkit.utils.Logger | ||
| import javax.inject.Inject | ||
|
|
||
| @AndroidEntryPoint | ||
| class LightningNodeService : Service() { | ||
|
|
||
| private val serviceScope = CoroutineScope(SupervisorJob() + Dispatchers.Main) | ||
|
|
||
| @Inject | ||
| lateinit var lightningRepo: LightningRepo | ||
|
|
||
| @Inject | ||
| lateinit var walletRepo: WalletRepo | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
| startForeground(NOTIFICATION_ID, createNotification()) | ||
| setupService() | ||
| } | ||
|
|
||
| private fun setupService() { | ||
| serviceScope.launch { | ||
| launch { | ||
| lightningRepo.start( | ||
| eventHandler = { event -> | ||
| walletRepo.refreshBip21ForEvent(event) | ||
| } | ||
| ).onSuccess { | ||
| val notification = createNotification() | ||
| startForeground(NOTIFICATION_ID, notification) | ||
|
|
||
| walletRepo.setWalletExistsState() | ||
| walletRepo.refreshBip21() | ||
| walletRepo.syncBalances() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Update the createNotification method in LightningNodeService.kt | ||
| private fun createNotification( | ||
| contentText: String = "Bitkit is running in background so you can receive Lightning payments" | ||
| ): Notification { | ||
| val notificationIntent = Intent(this, MainActivity::class.java).apply { | ||
| flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP | ||
| } | ||
| val pendingIntent = PendingIntent.getActivity( | ||
| this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE | ||
| ) | ||
|
|
||
| // Create stop action that will close both service and app | ||
| val stopIntent = Intent(this, LightningNodeService::class.java).apply { | ||
| action = ACTION_STOP_SERVICE_AND_APP | ||
| } | ||
| val stopPendingIntent = PendingIntent.getService( | ||
| this, 0, stopIntent, PendingIntent.FLAG_IMMUTABLE | ||
| ) | ||
|
|
||
| return NotificationCompat.Builder(this, CHANNEL_ID_NODE) | ||
| .setContentTitle(getString(R.string.app_name)) | ||
| .setContentText(contentText) | ||
| .setSmallIcon(R.drawable.ic_launcher_fg_regtest) | ||
| .setContentIntent(pendingIntent) | ||
| .addAction( | ||
| R.drawable.ic_x, | ||
| "Stop App", // TODO: Get from resources | ||
| stopPendingIntent | ||
| ) | ||
| .build() | ||
| } | ||
|
|
||
| // Update the onStartCommand method | ||
| override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
| Logger.debug("onStartCommand", context = TAG) | ||
| when (intent?.action) { | ||
| ACTION_STOP_SERVICE_AND_APP -> { | ||
| Logger.debug("ACTION_STOP_SERVICE_AND_APP detected", context = TAG) | ||
| // Close all activities | ||
| App.currentActivity?.value?.finishAffinity() | ||
| // Stop the service | ||
| stopSelf() | ||
| return START_NOT_STICKY | ||
| } | ||
| } | ||
| return START_STICKY | ||
| } | ||
|
|
||
| override fun onDestroy() { | ||
| Logger.debug("onDestroy", context = TAG) | ||
| serviceScope.launch { | ||
| lightningRepo.stop().onSuccess { | ||
| serviceScope.cancel() | ||
| } | ||
| } | ||
| super.onDestroy() | ||
| } | ||
|
|
||
| override fun onBind(intent: Intent?): IBinder? = null | ||
|
|
||
| companion object { | ||
| private const val NOTIFICATION_ID = 1 | ||
| const val CHANNEL_ID_NODE = "bitkit_notification_channel_node" | ||
| const val TAG = "LightningNodeService" | ||
| const val ACTION_STOP_SERVICE_AND_APP = "to.bitkit.androidServices.action.STOP_SERVICE_AND_APP" | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| @file:Suppress("unused") | ||
|
|
||
| package to.bitkit.di | ||
|
|
||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import org.lightningdevkit.ldknode.Network | ||
| import to.bitkit.env.Env | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object EnvModule { | ||
|
|
||
| @Provides | ||
| fun provideNetwork(): Network { | ||
| return Env.network | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.