fixed offline mode (#124)
This commit is contained in:
parent
e65fa8d565
commit
e7631e021e
2 changed files with 88 additions and 81 deletions
|
@ -154,10 +154,17 @@ class MainActivity : AppCompatActivity() {
|
||||||
bottomMargin = navBarHeight
|
bottomMargin = navBarHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val offline = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
|
.getBoolean("offlineMode", false)
|
||||||
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))
|
||||||
} else {
|
} else {
|
||||||
|
if (offline){
|
||||||
|
snackString(this@MainActivity.getString(R.string.no_internet_connection))
|
||||||
|
startActivity(Intent(this, NoInternet::class.java))
|
||||||
|
}
|
||||||
|
else {
|
||||||
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) {
|
||||||
|
@ -247,6 +254,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val index = Helper.downloadManager(this@MainActivity).downloadIndex
|
val index = Helper.downloadManager(this@MainActivity).downloadIndex
|
||||||
val downloadCursor = index.getDownloads()
|
val downloadCursor = index.getDownloads()
|
||||||
|
|
|
@ -31,11 +31,10 @@ class OfflineFragment : Fragment() {
|
||||||
offline = requireContext().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 (offline) "Offline Mode" else getString(R.string.no_internet)
|
||||||
|
binding.refreshButton.visibility = if (offline) View.GONE else View.VISIBLE
|
||||||
binding.refreshButton.setOnClickListener {
|
binding.refreshButton.setOnClickListener {
|
||||||
println("Offline: $offline")
|
if (isOnline(requireContext())) {
|
||||||
println("Online: ${isOnline(requireContext())}")
|
|
||||||
if (isOnline(requireContext()) && !offline) {
|
|
||||||
startMainActivity(requireActivity())
|
startMainActivity(requireActivity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue