kopia lustrzana https://github.com/ge0rg/aprsdroid
add a preliminary prefs wrapper
rodzic
129d166474
commit
c62f896c48
|
@ -24,7 +24,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
with DialogInterface.OnClickListener {
|
||||
val TAG = "APRSdroid"
|
||||
|
||||
lazy val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
lazy val prefs = new PrefsWrapper(this)
|
||||
lazy val storage = StorageDatabase.open(this)
|
||||
lazy val postcursor = storage.getPosts("100")
|
||||
|
||||
|
@ -85,7 +85,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
}
|
||||
if (!checkConfig())
|
||||
return
|
||||
val callsign = prefs.getString("callsign", "").trim()
|
||||
val callsign = prefs.getCallsign()
|
||||
val callssid = AprsPacket.formatCallSsid(callsign, prefs.getString("ssid", ""))
|
||||
setTitle(getString(R.string.app_name) + ": " + callssid)
|
||||
setupButtons(AprsService.running)
|
||||
|
@ -108,7 +108,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
|
||||
def passcodeWarning(call : String, pass : String) {
|
||||
import Backend._
|
||||
if ((defaultBackendInfo(prefs).need_passcode == PASSCODE_OPTIONAL) &&
|
||||
if ((defaultBackendInfo(prefs.prefs).need_passcode == PASSCODE_OPTIONAL) &&
|
||||
!AprsPacket.passcodeAllowed(call, pass, false))
|
||||
Toast.makeText(this, R.string.anon_warning, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
import Backend._
|
||||
// a valid passcode must be entered for "required",
|
||||
// "" and "-1" are accepted as well for "optional"
|
||||
defaultBackendInfo(prefs).need_passcode match {
|
||||
defaultBackendInfo(prefs.prefs).need_passcode match {
|
||||
case PASSCODE_NONE => false
|
||||
case PASSCODE_OPTIONAL =>
|
||||
!AprsPacket.passcodeAllowed(call, pass, true)
|
||||
|
@ -127,7 +127,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
}
|
||||
|
||||
def checkConfig() : Boolean = {
|
||||
val callsign = prefs.getString("callsign", "").trim()
|
||||
val callsign = prefs.getCallsign()
|
||||
val passcode = prefs.getString("passcode", "")
|
||||
if (callsign == "") {
|
||||
openPrefs(R.string.firstrun)
|
||||
|
@ -190,7 +190,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
override def onClick(d : DialogInterface, which : Int) {
|
||||
which match {
|
||||
case DialogInterface.BUTTON_POSITIVE =>
|
||||
prefs.edit().putBoolean("firstrun", false).commit();
|
||||
prefs.prefs.edit().putBoolean("firstrun", false).commit();
|
||||
checkConfig()
|
||||
case _ =>
|
||||
finish()
|
||||
|
@ -202,7 +202,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
|
||||
view.getId match {
|
||||
case R.id.singlebtn =>
|
||||
passcodeWarning(getCallsign(), prefs.getString("passcode", ""))
|
||||
passcodeWarning(prefs.getCallsign(), prefs.getString("passcode", ""))
|
||||
startService(AprsService.intent(this, AprsService.SERVICE_ONCE))
|
||||
case R.id.startstopbtn =>
|
||||
val is_running = AprsService.running
|
||||
|
@ -216,10 +216,6 @@ class APRSdroid extends Activity with OnClickListener
|
|||
//status.setText(view.asInstanceOf[Button].getText)
|
||||
}
|
||||
}
|
||||
|
||||
def getCallsign() = {
|
||||
prefs.getString("callsign", "").trim()
|
||||
}
|
||||
}
|
||||
|
||||
class UrlOpener(ctx : Context, url : String) extends DialogInterface.OnClickListener {
|
||||
|
|
|
@ -34,7 +34,7 @@ class AprsService extends Service with LocationListener {
|
|||
import AprsService._
|
||||
val TAG = "AprsService"
|
||||
|
||||
lazy val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
lazy val prefs = new PrefsWrapper(this)
|
||||
|
||||
lazy val locMan = getSystemService(Context.LOCATION_SERVICE).asInstanceOf[LocationManager]
|
||||
|
||||
|
@ -87,13 +87,13 @@ class AprsService extends Service with LocationListener {
|
|||
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,
|
||||
upd_int * 60000, upd_dist * 1000, this)
|
||||
|
||||
val callssid = AprsPacket.formatCallSsid(prefs.getString("callsign", null), prefs.getString("ssid", ""))
|
||||
val callssid = AprsPacket.formatCallSsid(prefs.getCallsign(), prefs.getString("ssid", ""))
|
||||
val message = "%s: %d min, %d km".format(callssid, upd_int, upd_dist)
|
||||
ServiceNotifier.instance.start(this, message)
|
||||
}
|
||||
|
||||
def startPoster() {
|
||||
poster = AprsIsUploader.instanciateUploader(this, prefs)
|
||||
poster = AprsIsUploader.instanciateUploader(this, prefs.prefs)
|
||||
poster.start()
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ class AprsService extends Service with LocationListener {
|
|||
val i = new Intent(UPDATE)
|
||||
i.putExtra(LOCATION, location)
|
||||
|
||||
val callsign = prefs.getString("callsign", null).trim()
|
||||
val callsign = prefs.getCallsign()
|
||||
val callssid = AprsPacket.formatCallSsid(callsign, prefs.getString("ssid", ""))
|
||||
var symbol = prefs.getString("symbol", "")
|
||||
if (symbol.length != 2)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.aprsdroid.app
|
||||
|
||||
import _root_.android.content.Context
|
||||
import _root_.android.preference.PreferenceManager
|
||||
|
||||
class PrefsWrapper(val context : Context) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
// wrap the "dumb" methods
|
||||
def getString(key : String, defValue : String) = prefs.getString(key, defValue)
|
||||
def getBoolean(key : String, defValue : Boolean) = prefs.getBoolean(key, defValue)
|
||||
|
||||
// safely read integers
|
||||
def getStringInt(key : String, defValue : Int) = {
|
||||
try { prefs.getString(key, null).trim.toInt } catch { case _ => defValue }
|
||||
}
|
||||
|
||||
// return commonly used prefs
|
||||
def getCallsign() = prefs.getString("callsign", "").trim()
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue