sad fucked up

This commit is contained in:
Finnley Somdahl 2024-01-13 12:06:45 -06:00
parent cc5b512441
commit 14d08b9491
2 changed files with 12 additions and 10 deletions

View file

@ -157,15 +157,7 @@ class MainActivity : AppCompatActivity() {
if (!isOnline(this)) {
snackString(this@MainActivity.getString(R.string.no_internet_connection))
startActivity(Intent(this, NoInternet::class.java))
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.edit()
.putBoolean("offlineMode", true)
.apply()
} else {
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.edit()
.putBoolean("offlineMode", false)
.apply()
val model: AnilistHomeViewModel by viewModels()
model.genres.observe(this) { it ->
if (it != null) {

View file

@ -9,6 +9,7 @@ import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
import ani.dantotsu.App
import ani.dantotsu.R
import ani.dantotsu.currContext
import ani.dantotsu.databinding.FragmentOfflineBinding
import ani.dantotsu.isOnline
import ani.dantotsu.navBarHeight
@ -16,6 +17,7 @@ import ani.dantotsu.startMainActivity
import ani.dantotsu.statusBarHeight
class OfflineFragment : Fragment() {
private var offline = false
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -26,15 +28,23 @@ class OfflineFragment : Fragment() {
topMargin = statusBarHeight
bottomMargin = navBarHeight
}
val offline = App.context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("offlineMode", false) ?: false
binding.noInternet.text =
if (!isOnline(requireContext())) getString(R.string.no_internet) else "OFFLINE MODE"
binding.refreshButton.setOnClickListener {
if (!isOnline(requireContext()) && offline) {
println("Offline: $offline")
println("Online: ${isOnline(requireContext())}")
if (isOnline(requireContext()) && !offline) {
startMainActivity(requireActivity())
}
}
return binding.root
}
override fun onResume() {
super.onResume()
offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("offlineMode", false) ?: false
}
}