mirror of
https://github.com/etesync/android
synced 2025-05-29 04:08:48 +00:00
Add support for setting custom servers
This makes it easier to host your own etesync server.
This commit is contained in:
parent
b3ef3b1ad2
commit
f6007019e8
@ -140,6 +140,7 @@ dependencies {
|
|||||||
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
|
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
|
||||||
compile 'org.apache.commons:commons-collections4:4.1'
|
compile 'org.apache.commons:commons-collections4:4.1'
|
||||||
provided 'org.projectlombok:lombok:1.16.16'
|
provided 'org.projectlombok:lombok:1.16.16'
|
||||||
|
compile 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
|
||||||
|
|
||||||
// for tests
|
// for tests
|
||||||
androidTestCompile('com.android.support.test:runner:0.5') {
|
androidTestCompile('com.android.support.test:runner:0.5') {
|
||||||
|
@ -20,6 +20,7 @@ import com.etesync.syncadapter.model.Settings;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
|
import java.net.URI;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -57,7 +58,7 @@ public class HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient create(@Nullable Context context, @NonNull AccountSettings settings, @NonNull final Logger logger) {
|
public static OkHttpClient create(@Nullable Context context, @NonNull AccountSettings settings, @NonNull final Logger logger) {
|
||||||
return create(context, logger, Constants.serviceUrl.getHost(), settings.getAuthToken());
|
return create(context, logger, settings.getUri().getHost(), settings.getAuthToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient create(@NonNull Context context, @NonNull Logger logger) {
|
public static OkHttpClient create(@NonNull Context context, @NonNull Logger logger) {
|
||||||
@ -72,8 +73,8 @@ public class HttpClient {
|
|||||||
return create(context, App.log);
|
return create(context, App.log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient create(@Nullable Context context, String authToken) {
|
public static OkHttpClient create(@Nullable Context context, @NonNull URI uri, String authToken) {
|
||||||
return create(context, App.log, Constants.serviceUrl.getHost(), authToken);
|
return create(context, App.log, uri.getHost(), authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class AccountSettingsActivity extends BaseActivity {
|
|||||||
prefPassword.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
prefPassword.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
LoginCredentials credentials = newValue != null ? new LoginCredentials(account.name, (String) newValue) : null;
|
LoginCredentials credentials = newValue != null ? new LoginCredentials(settings.getUri(), account.name, (String) newValue) : null;
|
||||||
LoginCredentialsChangeFragment.newInstance(account, credentials).show(getFragmentManager(), null);
|
LoginCredentialsChangeFragment.newInstance(account, credentials).show(getFragmentManager(), null);
|
||||||
getLoaderManager().restartLoader(0, getArguments(), AccountSettingsFragment.this);
|
getLoaderManager().restartLoader(0, getArguments(), AccountSettingsFragment.this);
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,20 +18,20 @@ import com.etesync.syncadapter.App;
|
|||||||
import com.etesync.syncadapter.Constants;
|
import com.etesync.syncadapter.Constants;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class LoginCredentials implements Parcelable {
|
public class LoginCredentials implements Parcelable {
|
||||||
public final URI uri;
|
public final URI uri;
|
||||||
public final String userName, password;
|
public final String userName, password;
|
||||||
|
|
||||||
public LoginCredentials(String userName, String password) {
|
public LoginCredentials(URI uri, String userName, String password) {
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
|
||||||
URI uri = null;
|
if (uri == null) {
|
||||||
try {
|
try {
|
||||||
uri = new URI(Constants.serviceUrl.toString());
|
uri = new URI(Constants.serviceUrl.toString());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
App.log.severe("Should never happen, it's a constant");
|
App.log.severe("Should never happen, it's a constant");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CheckedTextView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -25,10 +26,20 @@ import com.etesync.syncadapter.R;
|
|||||||
import com.etesync.syncadapter.ui.WebViewActivity;
|
import com.etesync.syncadapter.ui.WebViewActivity;
|
||||||
import com.etesync.syncadapter.ui.widget.EditPassword;
|
import com.etesync.syncadapter.ui.widget.EditPassword;
|
||||||
|
|
||||||
|
import net.cachapa.expandablelayout.ExpandableLayout;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
public class LoginCredentialsFragment extends Fragment {
|
public class LoginCredentialsFragment extends Fragment {
|
||||||
EditText editUserName;
|
EditText editUserName;
|
||||||
EditPassword editUrlPassword;
|
EditPassword editUrlPassword;
|
||||||
|
|
||||||
|
CheckedTextView showAdvanced;
|
||||||
|
EditText customServer;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
@ -36,6 +47,8 @@ public class LoginCredentialsFragment extends Fragment {
|
|||||||
|
|
||||||
editUserName = (EditText) v.findViewById(R.id.user_name);
|
editUserName = (EditText) v.findViewById(R.id.user_name);
|
||||||
editUrlPassword = (EditPassword) v.findViewById(R.id.url_password);
|
editUrlPassword = (EditPassword) v.findViewById(R.id.url_password);
|
||||||
|
showAdvanced = (CheckedTextView) v.findViewById(R.id.show_advanced);
|
||||||
|
customServer = (EditText) v.findViewById(R.id.custom_server);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
@ -77,6 +90,22 @@ public class LoginCredentialsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final ExpandableLayout advancedLayout = (ExpandableLayout) v.findViewById(R.id.advanced_layout);
|
||||||
|
|
||||||
|
showAdvanced.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if (showAdvanced.isChecked()) {
|
||||||
|
showAdvanced.setChecked(false);
|
||||||
|
advancedLayout.collapse();
|
||||||
|
} else {
|
||||||
|
showAdvanced.setChecked(true);
|
||||||
|
advancedLayout.expand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +124,21 @@ public class LoginCredentialsFragment extends Fragment {
|
|||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid ? new LoginCredentials(userName, password) : null;
|
URI uri = null;
|
||||||
|
if (showAdvanced.isChecked()) {
|
||||||
|
String server = customServer.getText().toString();
|
||||||
|
// If this field is null, just use the default
|
||||||
|
if (!server.isEmpty()) {
|
||||||
|
HttpUrl url = HttpUrl.parse(server);
|
||||||
|
if (url != null) {
|
||||||
|
uri = url.uri();
|
||||||
|
} else {
|
||||||
|
customServer.setError(getString(R.string.login_custom_server_error));
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid ? new LoginCredentials(uri, userName, password) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public class SetupEncryptionFragment extends DialogFragment {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Crypto.CryptoManager cryptoManager;
|
Crypto.CryptoManager cryptoManager;
|
||||||
OkHttpClient httpClient = HttpClient.create(getContext(), config.authtoken);
|
OkHttpClient httpClient = HttpClient.create(getContext(), config.url, config.authtoken);
|
||||||
|
|
||||||
UserInfoManager userInfoManager = new UserInfoManager(httpClient, HttpUrl.get(config.url));
|
UserInfoManager userInfoManager = new UserInfoManager(httpClient, HttpUrl.get(config.url));
|
||||||
UserInfoManager.UserInfo userInfo = userInfoManager.get(config.userName);
|
UserInfoManager.UserInfo userInfo = userInfoManager.get(config.userName);
|
||||||
|
@ -56,6 +56,31 @@
|
|||||||
android:text="@string/login_forgot_password"
|
android:text="@string/login_forgot_password"
|
||||||
android:textColor="@color/orangeA700"/>
|
android:textColor="@color/orangeA700"/>
|
||||||
|
|
||||||
|
<CheckedTextView
|
||||||
|
android:id="@+id/show_advanced"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="14dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
|
||||||
|
android:text="@string/login_toggle_advanced" />
|
||||||
|
|
||||||
|
<net.cachapa.expandablelayout.ExpandableLayout
|
||||||
|
android:id="@+id/advanced_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/custom_server"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/login_custom_server"
|
||||||
|
android:inputType="textUri"/>
|
||||||
|
|
||||||
|
</net.cachapa.expandablelayout.ExpandableLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
@ -168,6 +168,9 @@
|
|||||||
<string name="login_email_address">Email</string>
|
<string name="login_email_address">Email</string>
|
||||||
<string name="login_email_address_error">Valid email address required</string>
|
<string name="login_email_address_error">Valid email address required</string>
|
||||||
<string name="login_password">Password</string>
|
<string name="login_password">Password</string>
|
||||||
|
<string name="login_custom_server">Custom Server URL</string>
|
||||||
|
<string name="login_custom_server_error">Invalid URL found, did you forget to include https://?</string>
|
||||||
|
<string name="login_toggle_advanced">Show advanced settings</string>
|
||||||
<string name="login_encryption_password">Encryption Password</string>
|
<string name="login_encryption_password">Encryption Password</string>
|
||||||
<string name="login_encryption_check_password">* Please double-check the password, as it can\'t be changed if wrong.</string>
|
<string name="login_encryption_check_password">* Please double-check the password, as it can\'t be changed if wrong.</string>
|
||||||
<string name="login_encryption_extra_info">This password is used to encrypt your data, unlike the previous one, which is used to log into the service.\nYou are asked to choose a separate encryption password for security reasons. For more information, plesae refer to the FAQ at: %s</string>
|
<string name="login_encryption_extra_info">This password is used to encrypt your data, unlike the previous one, which is used to log into the service.\nYou are asked to choose a separate encryption password for security reasons. For more information, plesae refer to the FAQ at: %s</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user