Moved default preference values into resource file.

This commit is contained in:
Felix Ableitner 2015-02-14 14:39:10 +01:00
parent 2eb163951b
commit 748c8c27c5
5 changed files with 21 additions and 10 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources translatable="false">
<string name="default_scan_interval">15</string>
<string name="default_max_connections">1000000</string>
</resources>

View file

@ -9,13 +9,14 @@
<EditTextPreference
android:title="@string/scan_interval_seconds"
android:key="scan_interval_seconds"
android:defaultValue="15"
android:defaultValue="@string/default_scan_interval"
android:inputType="number"
android:numeric="integer" />
<EditTextPreference
android:title="@string/max_connections"
android:key="max_connections"
android:defaultValue="@string/default_max_connections"
android:inputType="number"
android:numeric="integer" />

View file

@ -9,6 +9,7 @@ import android.preference.PreferenceManager
import android.util.Log
import com.google.common.collect.HashBiMap
import com.nutomic.ensichat.R
import com.nutomic.ensichat.fragments.SettingsFragment
import com.nutomic.ensichat.protocol.ChatService.InterfaceHandler
import com.nutomic.ensichat.protocol._
import com.nutomic.ensichat.protocol.messages.{ConnectionInfo, Message}
@ -92,8 +93,9 @@ class BluetoothInterface(service: ChatService, crypto: Crypto, mainHandler: Hand
btAdapter.startDiscovery()
}
val scanInterval = PreferenceManager.getDefaultSharedPreferences(service)
.getString("scan_interval_seconds", "15").toInt * 1000
val pm = PreferenceManager.getDefaultSharedPreferences(service)
val scanInterval = pm.getString(SettingsFragment.KeyScanInterval,
service.getResources.getString(R.string.default_scan_interval)).toInt * 1000
mainHandler.postDelayed(new Runnable {
override def run(): Unit = discover()
}, scanInterval)

View file

@ -36,9 +36,10 @@ class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListene
val pm = PreferenceManager.getDefaultSharedPreferences(getActivity)
name.setSummary(pm.getString(KeyUserName, ""))
scanInterval.setSummary(pm.getString(KeyScanInterval, "15"))
maxConnections.setDefaultValue(Int.MaxValue)
maxConnections.setSummary(pm.getString(MaxConnections, Int.MaxValue.toString))
scanInterval.setSummary(pm.getString(KeyScanInterval,
getResources.getString(R.string.default_scan_interval)))
maxConnections.setSummary(pm.getString(MaxConnections,
getResources.getString(R.string.default_max_connections)))
}
/**

View file

@ -211,10 +211,9 @@ class ChatService extends Service {
* @return True if the connection is valid
*/
def onConnectionOpened(msg: Message): Boolean = {
val maxConnections = PreferenceManager
.getDefaultSharedPreferences(this)
.getString(SettingsFragment.MaxConnections, Int.MaxValue.toString)
.toInt
val pm = PreferenceManager.getDefaultSharedPreferences(this)
val maxConnections = pm.getString(SettingsFragment.MaxConnections,
getResources.getString(R.string.default_max_connections)).toInt
if (connections().size == maxConnections) {
Log.i(Tag, "Maximum number of connections reached")
false