Format code, add google-services.json as Github secret

This commit is contained in:
Matte23
2020-10-30 11:09:31 +01:00
parent b3fb785f95
commit 361631b6ac
4 changed files with 37 additions and 20 deletions

View File

@@ -42,7 +42,8 @@ class SettingsActivity : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
class SettingsFragment : PreferenceFragmentCompat(),
class SettingsFragment :
PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
@@ -104,11 +105,10 @@ class SettingsActivity : AppCompatActivity() {
activity?.let { PollWork.enqueue(it) }
if (sharedPreferences.getBoolean(
"notify_new_circulars",
true
) && !sharedPreferences.getBoolean("enable_polling", false)
) {
val notifyNewCirculars = sharedPreferences.getBoolean("notify_new_circulars", true)
val enablePolling = sharedPreferences.getBoolean("enable_polling", false)
if (notifyNewCirculars && !enablePolling) {
val serverID = ServerAPI.getInstance(requireContext()).serverID()
val serverToken = ServerAPI.Companion.Servers.values()[serverID].toString()

View File

@@ -74,11 +74,10 @@ class ServerAPI(
}
fun getInstance(context: Context): ServerAPI {
val preferenceManager = PreferenceManager.getDefaultSharedPreferences(context)
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val serverID = sharedPreferences.getString("school", "0")?.toInt() ?: 0
val server = Servers.values()[
preferenceManager.getString("school", "0")?.toInt() ?: 0
]
val server = Servers.values()[serverID]
return instance ?: synchronized(this) {
instance ?: ServerAPI(createServer(server)).also { instance = it }
@@ -89,11 +88,10 @@ class ServerAPI(
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val newServer = Servers.values()[index]
if (sharedPreferences.getBoolean(
"notify_new_circulars",
true
) && !sharedPreferences.getBoolean("enable_polling", false)
)
val notifyNewCirculars = sharedPreferences.getBoolean("notify_new_circulars", true)
val enablePolling = sharedPreferences.getBoolean("enable_polling", false)
if (notifyNewCirculars && !enablePolling)
FirebaseTopicUtils.selectTopic(newServer.toString(), context)
instance?.changeServer(createServer(newServer))

View File

@@ -65,11 +65,10 @@ class PollWork(appContext: Context, workerParams: WorkerParameters) :
fun enqueue(context: Context) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
if (sharedPreferences.getBoolean(
"notify_new_circulars",
true
) && sharedPreferences.getBoolean("enable_polling", false)
) {
val notifyNewCirculars = sharedPreferences.getBoolean("notify_new_circulars", true)
val enablePolling = sharedPreferences.getBoolean("enable_polling", false)
if (notifyNewCirculars && enablePolling) {
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(
pollWorkName,