Skip to content

Commit

Permalink
auto start
Browse files Browse the repository at this point in the history
  • Loading branch information
jvde-github committed Dec 14, 2024
1 parent 5a302bc commit 99e90e4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/src/main/java/com/jvdegithub/aiscatcher/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
public class MainActivity<binding> extends AppCompatActivity implements AisCatcherJava.AisCallback, DeviceManager.DeviceCallback {

private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
private boolean firstRun = true;

private LogBook logbook;
private LocationHelper locationHelper;
Expand Down Expand Up @@ -200,6 +201,17 @@ private void onWeb () {
startActivity(browserIntent);
}

protected void AutoStart() {
if(!Settings.getAutoStart(this)) return;
if(DeviceManager.getDeviceType() != DeviceManager.DeviceType.RTLSDR &&
DeviceManager.getDeviceType() != DeviceManager.DeviceType.AIRSPY &&
DeviceManager.getDeviceType() != DeviceManager.DeviceType.AIRSPYHF)
return;

if (!AisService.isRunning(getApplicationContext())) {
onPlayStop();
}
}
protected void onResume () {

super.onResume();
Expand All @@ -210,6 +222,11 @@ protected void onResume () {
} else {
updateUIwithStop();
}

if(firstRun) {
firstRun = false;
AutoStart();
}
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/jvdegithub/aiscatcher/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ static void setDefault(Context context) {

preferences.edit().putString("sSHARINGKEY", "").commit();
preferences.edit().putBoolean("sSHARING", false).commit();
preferences.edit().putBoolean("sAUTOSTART", false).commit();

preferences.edit().putBoolean("w1SWITCH", false).commit();
preferences.edit().putString("w1PORT", "8100").commit();


preferences.edit().putString("oCGF_WIDE", "Default").commit();
preferences.edit().putString("oMODEL_TYPE", "Default").commit();
preferences.edit().putBoolean("oFP_DS", false).commit();
Expand Down Expand Up @@ -299,6 +299,12 @@ static public int getCGFSetting(Context context)
return 1;
}

static public boolean getAutoStart(Context context)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return preferences.getBoolean("sAUTOSTART",false);
}

static public boolean getFixedPointDownsampling(Context context)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
android:defaultValue="False"
android:title="Force Dark Mode"/>

<SwitchPreferenceCompat
android:key="sAUTOSTART"
android:summary="Auto Start when USB device is available"
android:defaultValue="False"
android:title="Auto Start"/>

</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 99e90e4

Please sign in to comment.