sad fucked up
This commit is contained in:
parent
cc5b512441
commit
14d08b9491
2 changed files with 12 additions and 10 deletions
|
@ -157,15 +157,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
if (!isOnline(this)) {
|
if (!isOnline(this)) {
|
||||||
snackString(this@MainActivity.getString(R.string.no_internet_connection))
|
snackString(this@MainActivity.getString(R.string.no_internet_connection))
|
||||||
startActivity(Intent(this, NoInternet::class.java))
|
startActivity(Intent(this, NoInternet::class.java))
|
||||||
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
|
||||||
.edit()
|
|
||||||
.putBoolean("offlineMode", true)
|
|
||||||
.apply()
|
|
||||||
} else {
|
} else {
|
||||||
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
|
||||||
.edit()
|
|
||||||
.putBoolean("offlineMode", false)
|
|
||||||
.apply()
|
|
||||||
val model: AnilistHomeViewModel by viewModels()
|
val model: AnilistHomeViewModel by viewModels()
|
||||||
model.genres.observe(this) { it ->
|
model.genres.observe(this) { it ->
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import androidx.core.view.updateLayoutParams
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import ani.dantotsu.App
|
import ani.dantotsu.App
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
|
import ani.dantotsu.currContext
|
||||||
import ani.dantotsu.databinding.FragmentOfflineBinding
|
import ani.dantotsu.databinding.FragmentOfflineBinding
|
||||||
import ani.dantotsu.isOnline
|
import ani.dantotsu.isOnline
|
||||||
import ani.dantotsu.navBarHeight
|
import ani.dantotsu.navBarHeight
|
||||||
|
@ -16,6 +17,7 @@ import ani.dantotsu.startMainActivity
|
||||||
import ani.dantotsu.statusBarHeight
|
import ani.dantotsu.statusBarHeight
|
||||||
|
|
||||||
class OfflineFragment : Fragment() {
|
class OfflineFragment : Fragment() {
|
||||||
|
private var offline = false
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
@ -26,15 +28,23 @@ class OfflineFragment : Fragment() {
|
||||||
topMargin = statusBarHeight
|
topMargin = statusBarHeight
|
||||||
bottomMargin = navBarHeight
|
bottomMargin = navBarHeight
|
||||||
}
|
}
|
||||||
val offline = App.context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
?.getBoolean("offlineMode", false) ?: false
|
?.getBoolean("offlineMode", false) ?: false
|
||||||
binding.noInternet.text =
|
binding.noInternet.text =
|
||||||
if (!isOnline(requireContext())) getString(R.string.no_internet) else "OFFLINE MODE"
|
if (!isOnline(requireContext())) getString(R.string.no_internet) else "OFFLINE MODE"
|
||||||
binding.refreshButton.setOnClickListener {
|
binding.refreshButton.setOnClickListener {
|
||||||
if (!isOnline(requireContext()) && offline) {
|
println("Offline: $offline")
|
||||||
|
println("Online: ${isOnline(requireContext())}")
|
||||||
|
if (isOnline(requireContext()) && !offline) {
|
||||||
startMainActivity(requireActivity())
|
startMainActivity(requireActivity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
|
?.getBoolean("offlineMode", false) ?: false
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue