Add deprecated warnings

This commit is contained in:
世界 2024-10-29 12:25:53 +08:00
parent 6c31dca1d3
commit 0b18d9f14c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 44 additions and 0 deletions

View file

@ -8,14 +8,23 @@ import androidx.annotation.StringRes
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayoutMediator
import io.nekohasekai.libbox.DeprecatedNoteIterator
import io.nekohasekai.libbox.Libbox
import io.nekohasekai.sfa.R
import io.nekohasekai.sfa.bg.BoxService
import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.databinding.FragmentDashboardBinding
import io.nekohasekai.sfa.ktx.errorDialogBuilder
import io.nekohasekai.sfa.ktx.launchCustomTab
import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.ui.dashboard.GroupsFragment
import io.nekohasekai.sfa.ui.dashboard.OverviewFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
@ -49,6 +58,7 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
}
Status.Started -> {
checkDeprecatedNotes()
enablePager()
binding.fab.setImageResource(R.drawable.ic_stop_24)
binding.fab.show()
@ -99,6 +109,38 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
binding = null
}
private fun checkDeprecatedNotes() {
GlobalScope.launch(Dispatchers.IO) {
runCatching {
val notes = Libbox.newStandaloneCommandClient().deprecatedNotes
if (notes.hasNext()) {
withContext(Dispatchers.Main) {
loopShowDeprecatedNotes(notes)
}
}
}.onFailure {
activity?.errorDialogBuilder(it)?.show()
}
}
}
private fun loopShowDeprecatedNotes(notes: DeprecatedNoteIterator) {
if (notes.hasNext()) {
val note = notes.next()
val builder = MaterialAlertDialogBuilder(requireContext())
builder.setTitle(getString(R.string.service_error_title_deprecated_warning))
builder.setMessage(note.message())
builder.setPositiveButton(R.string.ok) { _, _ ->
loopShowDeprecatedNotes(notes)
}
builder.setNeutralButton(R.string.service_error_deprecated_warning_documentation) { _, _ ->
requireContext().launchCustomTab(note.migrationLink)
loopShowDeprecatedNotes(notes)
}
builder.show()
}
}
private fun enablePager() {
val activity = activity ?: return
val binding = binding ?: return

View file

@ -75,6 +75,8 @@
<string name="service_error_title_start_command_server">Start command server</string>
<string name="service_error_title_create_service">Create service</string>
<string name="service_error_title_start_service">Start service</string>
<string name="service_error_title_deprecated_warning">Deprecated Warning</string>
<string name="service_error_deprecated_warning_documentation">Documentation</string>
<string name="status_status">Status</string>
<string name="status_memory">Memory</string>