added ability to use application offline
This commit is contained in:
parent
d08a79e981
commit
8c3845a07e
|
@ -104,6 +104,15 @@ class LoginActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.offlineButton.setOnClickListener {
|
||||
sharedPreferences.edit().putString("currentGroup", "offline").apply()
|
||||
sharedPreferences.edit().putStringSet("groups", setOf("offline")).apply()
|
||||
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun fillUpLanguagesSpinner() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
|
@ -108,8 +109,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
}
|
||||
val net = Net()
|
||||
net.server = sharedPreferences.getString("server", "")!!
|
||||
|
||||
if (!net.serverIsAvailable(this)) {
|
||||
val currentGroup = sharedPreferences.getString("currentGroup", "offline")!!
|
||||
if ( currentGroup != "offline" && !net.serverIsAvailable(this)) {
|
||||
noInternetConnectionAvailableNotification(this)
|
||||
} else {
|
||||
synchronize()
|
||||
|
@ -393,16 +394,35 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
return true
|
||||
}
|
||||
|
||||
private fun isOffline(): Boolean {
|
||||
val sharedPreferences = EncryptedSharedPreferences.create(
|
||||
"sensitive",
|
||||
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
|
||||
applicationContext,
|
||||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||
)
|
||||
return sharedPreferences.getString("currentGroup", "") == "offline"
|
||||
}
|
||||
|
||||
override fun onNavigationItemSelected(item: MenuItem): Boolean {
|
||||
lateinit var intent: Intent
|
||||
when (item.itemId) {
|
||||
R.id.nav_account -> {
|
||||
if (isOffline()) {
|
||||
Toast.makeText(this, getString(R.string.online_only_feature), Toast.LENGTH_SHORT).show()
|
||||
return false
|
||||
}
|
||||
intent = Intent(this, AccountSettingsActivity::class.java)
|
||||
settingsActivityLauncher.launch(intent)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.nav_groups -> {
|
||||
if (isOffline()) {
|
||||
Toast.makeText(this, getString(R.string.online_only_feature), Toast.LENGTH_SHORT).show()
|
||||
return false
|
||||
}
|
||||
intent = Intent(this, MyGroupsActivity::class.java)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@ class NavigatorActivity : Activity() {
|
|||
|
||||
var intent = Intent(this, MainActivity::class.java)
|
||||
|
||||
if (!isInGroup()) {
|
||||
if (!isInGroup() && !isOffline()) {
|
||||
intent = Intent(this, GroupActivity::class.java)
|
||||
}
|
||||
|
||||
if (!isAuthenticated()) {
|
||||
if (!isAuthenticated() && !isOffline()) {
|
||||
intent = Intent(this, LoginActivity::class.java);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,10 @@ class NavigatorActivity : Activity() {
|
|||
finish();
|
||||
}
|
||||
|
||||
private fun isOffline(): Boolean {
|
||||
return sharedPreferences.getString("currentGroup", "")!! == "offline"
|
||||
}
|
||||
|
||||
private fun isAuthenticated(): Boolean {
|
||||
return sharedPreferences.getString("token", "") != ""
|
||||
}
|
||||
|
|
|
@ -37,17 +37,23 @@ class SettingsActivity : AppCompatActivity() {
|
|||
net.language = sharedPreferences.getString("language", "")!!
|
||||
net.server = sharedPreferences.getString("server", "")!!
|
||||
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setUpImageCompressionSeekBar()
|
||||
|
||||
|
||||
if (isOffline()) {
|
||||
binding.currentGroupSetting.visibility = View.GONE
|
||||
} else {
|
||||
groupsNames = mutableListOf()
|
||||
|
||||
for (myGroup in myGroups) {
|
||||
groupsNames.add(net.getGroupName(myGroup.toInt()))
|
||||
}
|
||||
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setUpImageCompressionSeekBar()
|
||||
fillUpCurrentGroupSpinner()
|
||||
}
|
||||
|
||||
binding.saveButton.setOnClickListener {
|
||||
sharedPreferences.edit().putString("currentGroup", net.getGroupId(binding.currentGroupSpinner.selectedItem.toString())).apply()
|
||||
|
@ -62,14 +68,16 @@ class SettingsActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun isOffline(): Boolean {
|
||||
return sharedPreferences.getString("currentGroup", "offline") == "offline"
|
||||
}
|
||||
|
||||
private fun setUpImageCompressionSeekBar() {
|
||||
val compressionFactor = sharedPreferences.getInt("imageCompression", 1)
|
||||
binding.imageCompressionFactorSeekBar.progress = compressionFactor - 1
|
||||
}
|
||||
|
||||
private fun fillUpCurrentGroupSpinner() {
|
||||
|
||||
|
||||
if (currentGroup == "offline") {
|
||||
binding.currentGroupSetting.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -117,6 +117,7 @@
|
|||
<string name="no_internet_connection">No internet connection available. Please, connect to a network.</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="logout">Log out</string>
|
||||
<string name="online_only_feature">This feature is online only</string>
|
||||
<string-array name="languages">
|
||||
<item>en-US</item>
|
||||
<item>ru-RU</item>
|
||||
|
|
|
@ -115,6 +115,7 @@
|
|||
<string name="no_internet_connection">No internet connection available. Please, connect to a network.</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="logout">Log out</string>
|
||||
<string name="online_only_feature">This feature is online only</string>
|
||||
<string-array name="languages">
|
||||
<item>en-US</item>
|
||||
<item>ru-RU</item>
|
||||
|
|
Loading…
Reference in New Issue