How do we set default values for the Server Preferences?

Hi group:
I have a custom fork of Collect, but my Android knowledge is very sketchy. I'm trying to work out how to set default values in the Preferences - specifically the Server Settings -> Server Type. I have my own server type option available in the Server Type menu (via "server_platform_other"), but a raw install always sets this value to "ODK Aggregate", and it would be nice not to have to change it after every new installation.
Can anyone point me to where in the code I can change the default setting for this value to server_platform_other?
Thanks
Nik

Hi @Blitheringeejit! It might be easier to configure collect the way you want on one device, save those settings to disk, and bundle those settings with your fork. https://docs.opendatakit.org/collect-import-export/#saving-qr-code-locally has a description of how to save the settings.

Hi Yaw: thanks for replying.
I appreciate the idea, but I'm not sure whether/how I can bundle a settings file into a Collect APK..?
If I have to load a settings file after installing from the APK, then there's no real benefit over changing the settings manually post-installation, which I can already do. But if I can bundle a settings file in an APK, please let me know how, as that would be useful in this and other respects.
But if bundling a settings file in the APK isn't possible, there must be some line in the source which is making "ODK Aggregate" the default setting for the Platform option - it isn't selected just because it's the first option in the list (I checked by changing the list order!). I can customise the other platform settings, and in an earlier build (just before migration to AS3), I could customise the server platform setting too. But the mechanism I used for doing so doesn't work in the latest version with AS3.
Is this actually a bug?
Thanks
Nik

Just got a chance to look at the code at https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/preferences/ServerPreferences.java#L62. I bet if you change the ordering there on a fresh install, it'll work.

Hi Yaw: thanks for the response, much appreciated.
I tried removing both the alternative options (simpler than reordering) as follows:

private void addPreferencesResource(CharSequence value) {
            // other
            addOtherPreferences();
   }

...but this made no difference to either the Server Preferences available or the default selection.
I do wonder if this is a bug - the original function you point to is:

private void addPreferencesResource(CharSequence value) {
        if (value == null || value.equals(getString(R.string.protocol_odk_default))) {
            setDefaultAggregatePaths();
            addAggregatePreferences();
        } else if (value.equals(getString(R.string.protocol_google_sheets))) {
            addGooglePreferences();
        } else {
            // other
            addOtherPreferences();
        }
    }

This seems to me to be saying "If 'value' is whatever string is defined as the default protocol, select Aggregate as the protocol". This effectively forces Aggregate to be the default, whatever protocol is defined in the code as "protocol_odk_default".
AFAICS this makes it impossible to change the default protocol setting in the code..? Isn't this a bug?
Grateful for any thoughts on this - I'm a bit out of my comfort zone!
Thanks
Nik

@Akshay_Patel Is this something you could help with?

@Blitheringeejit I did a couple of tweaks to set "other" sever as default. I have manually tested it on my setup.
Can you go through the changes, verify the behavior?


Hope this is helpful for you.
@yanokwa Any thoughts about this approach?

2 Likes

So THAT'S where the preference default values live! That's brilliant Akshay, much appreciated - it works perfectly.
Thanks
Nik

2 Likes