diff options
author | pacien | 2020-12-08 18:03:20 +0100 |
---|---|---|
committer | pacien | 2020-12-08 18:03:20 +0100 |
commit | 355251694d63640f028f3e2c17235d12a8573df6 (patch) | |
tree | 966ffd45ec29797afb440ead00586f4fcdf15589 /app/src/main/java/org/pacien/tincapp/activities/configure | |
parent | 2760703484f9b12f8c21c395915f9780b1ae7e9e (diff) | |
download | tincapp-355251694d63640f028f3e2c17235d12a8573df6.tar.gz |
ConfigurationAccessService: prevent service from being stopped when app loses focus
This makes the ConfigurationAccessService (formerly ConfigurationFtpService) start in foreground
through the use of a persistent notification so that it isn't stopped by the system after the app
loses the focus on the user's screen, which happens when the user switches to an FTP client
application on the same device.
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/activities/configure')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationFtpServerFragment.kt) | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationFtpServerFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt index b97a15e..9fee749 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationFtpServerFragment.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt | |||
@@ -26,43 +26,43 @@ import android.view.ViewGroup | |||
26 | import androidx.databinding.Observable | 26 | import androidx.databinding.Observable |
27 | import androidx.databinding.ObservableBoolean | 27 | import androidx.databinding.ObservableBoolean |
28 | import org.pacien.tincapp.activities.BaseFragment | 28 | import org.pacien.tincapp.activities.BaseFragment |
29 | import org.pacien.tincapp.databinding.ConfigureToolsConfigurationFtpServerFragmentBinding | 29 | import org.pacien.tincapp.databinding.ConfigureToolsConfigurationAccessFragmentBinding |
30 | import org.pacien.tincapp.service.ConfigurationFtpService | 30 | import org.pacien.tincapp.service.ConfigurationAccessService |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * @author pacien | 33 | * @author pacien |
34 | */ | 34 | */ |
35 | class ConfigurationFtpServerFragment : BaseFragment() { | 35 | class ConfigurationAccessServerFragment : BaseFragment() { |
36 | private val ftpServerStartListener = object : Observable.OnPropertyChangedCallback() { | 36 | private val ftpServerStartListener = object : Observable.OnPropertyChangedCallback() { |
37 | override fun onPropertyChanged(sender: Observable, propertyId: Int) { | 37 | override fun onPropertyChanged(sender: Observable, propertyId: Int) { |
38 | binding.ftpEnabled = (sender as ObservableBoolean).get() | 38 | binding.ftpEnabled = (sender as ObservableBoolean).get() |
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | private lateinit var binding: ConfigureToolsConfigurationFtpServerFragmentBinding | 42 | private lateinit var binding: ConfigureToolsConfigurationAccessFragmentBinding |
43 | 43 | ||
44 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | 44 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { |
45 | binding = ConfigureToolsConfigurationFtpServerFragmentBinding.inflate(inflater, container, false) | 45 | binding = ConfigureToolsConfigurationAccessFragmentBinding.inflate(inflater, container, false) |
46 | binding.ftpUsername = ConfigurationFtpService.FTP_USERNAME | 46 | binding.ftpUsername = ConfigurationAccessService.FTP_USERNAME |
47 | binding.ftpPassword = ConfigurationFtpService.FTP_PASSWORD | 47 | binding.ftpPassword = ConfigurationAccessService.FTP_PASSWORD |
48 | binding.ftpPort = ConfigurationFtpService.FTP_PORT | 48 | binding.ftpPort = ConfigurationAccessService.FTP_PORT |
49 | binding.toggleFtpState = { toggleServer() } | 49 | binding.toggleFtpState = { toggleServer() } |
50 | return binding.root | 50 | return binding.root |
51 | } | 51 | } |
52 | 52 | ||
53 | override fun onResume() { | 53 | override fun onResume() { |
54 | super.onResume() | 54 | super.onResume() |
55 | ConfigurationFtpService.runningState.addOnPropertyChangedCallback(ftpServerStartListener) | 55 | ConfigurationAccessService.runningState.addOnPropertyChangedCallback(ftpServerStartListener) |
56 | binding.ftpEnabled = ConfigurationFtpService.runningState.get() | 56 | binding.ftpEnabled = ConfigurationAccessService.runningState.get() |
57 | } | 57 | } |
58 | 58 | ||
59 | override fun onPause() { | 59 | override fun onPause() { |
60 | ConfigurationFtpService.runningState.removeOnPropertyChangedCallback(ftpServerStartListener) | 60 | ConfigurationAccessService.runningState.removeOnPropertyChangedCallback(ftpServerStartListener) |
61 | super.onPause() | 61 | super.onPause() |
62 | } | 62 | } |
63 | 63 | ||
64 | private fun toggleServer() { | 64 | private fun toggleServer() { |
65 | val targetServiceIntent = Intent(requireContext(), ConfigurationFtpService::class.java) | 65 | val targetServiceIntent = Intent(requireContext(), ConfigurationAccessService::class.java) |
66 | 66 | ||
67 | if (binding.ftpEnabled) | 67 | if (binding.ftpEnabled) |
68 | requireContext().stopService(targetServiceIntent) | 68 | requireContext().stopService(targetServiceIntent) |