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
|
2022-01-30 23:38:33 +01:00
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
2022-01-30 20:05:36 +01:00
|
|
|
import io.heckel.ntfy.R
|
|
|
|
import io.heckel.ntfy.db.Repository
|
2022-01-30 23:38:33 +01:00
|
|
|
import io.heckel.ntfy.db.Subscription
|
2022-02-09 22:20:24 +01:00
|
|
|
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
|
2022-01-30 23:38:33 +01:00
|
|
|
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)
|
2022-01-30 23:38:33 +01:00
|
|
|
subscriptionId = intent.getLongExtra(DetailActivity.EXTRA_SUBSCRIPTION_ID, 0)
|
2022-01-30 20:05:36 +01:00
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
settingsFragment = SettingsFragment() // Empty constructor!
|
2022-01-30 23:38:33 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-01-30 23:38:33 +01:00
|
|
|
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())
|
|
|
|
|
2022-01-30 23:38:33 +01:00
|
|
|
// 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 {
|
2022-02-01 01:34:34 +01:00
|
|
|
loadView(subscription)
|
2022-01-30 23:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-30 20:05:36 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 01:34:34 +01:00
|
|
|
private fun loadView(subscription: Subscription) {
|
|
|
|
// ...
|
2022-01-30 23:38:33 +01:00
|
|
|
}
|
2022-01-30 20:05:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
private const val TAG = "NtfyDetailSettingsActiv"
|
|
|
|
}
|
|
|
|
}
|