e-ntfy-android/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt

88 lines
3 KiB
Kotlin
Raw Normal View History

2022-01-30 20:05:36 +01:00
package io.heckel.ntfy.ui
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceFragmentCompat
2022-01-30 20:05:36 +01:00
import io.heckel.ntfy.R
import io.heckel.ntfy.db.Repository
import io.heckel.ntfy.db.Subscription
import io.heckel.ntfy.util.Log
2022-01-30 20:05:36 +01:00
import io.heckel.ntfy.service.SubscriberServiceManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/**
* Subscription settings
2022-02-05 01:52:34 +01:00
*
* THIS IS CURRENTLY UNUSED.
2022-01-30 20:05:36 +01:00
*/
class DetailSettingsActivity : AppCompatActivity() {
private lateinit var repository: Repository
private lateinit var serviceManager: SubscriberServiceManager
private lateinit var settingsFragment: SettingsFragment
private var subscriptionId: Long = 0
2022-01-30 20:05:36 +01:00
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Log.d(TAG, "Create $this")
repository = Repository.getInstance(this)
serviceManager = SubscriberServiceManager(this)
subscriptionId = intent.getLongExtra(DetailActivity.EXTRA_SUBSCRIPTION_ID, 0)
2022-01-30 20:05:36 +01:00
if (savedInstanceState == null) {
settingsFragment = SettingsFragment() // Empty constructor!
settingsFragment.arguments = Bundle().apply {
this.putLong(DetailActivity.EXTRA_SUBSCRIPTION_ID, subscriptionId)
}
2022-01-30 20:05:36 +01:00
supportFragmentManager
.beginTransaction()
.replace(R.id.settings_layout, settingsFragment)
.commit()
}
title = getString(R.string.detail_settings_title)
// Show 'Back' button
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
override fun onSupportNavigateUp(): Boolean {
finish() // Return to previous activity when nav "back" is pressed!
return true
}
2022-01-30 20:05:36 +01:00
class SettingsFragment : PreferenceFragmentCompat() {
private lateinit var repository: Repository
private lateinit var serviceManager: SubscriberServiceManager
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.detail_preferences, rootKey)
// Dependencies (Fragments need a default constructor)
repository = Repository.getInstance(requireActivity())
serviceManager = SubscriberServiceManager(requireActivity())
// Load subscription and users
val subscriptionId = arguments?.getLong(DetailActivity.EXTRA_SUBSCRIPTION_ID) ?: return
lifecycleScope.launch(Dispatchers.IO) {
val subscription = repository.getSubscription(subscriptionId) ?: return@launch
activity?.runOnUiThread {
loadView(subscription)
}
}
2022-01-30 20:05:36 +01:00
}
private fun loadView(subscription: Subscription) {
// ...
}
2022-01-30 20:05:36 +01:00
}
companion object {
private const val TAG = "NtfyDetailSettingsActiv"
}
}