diff --git a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java index 8efdfba..e23c76b 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java +++ b/app/src/main/java/eu/droogers/smsmatrix/MainActivity.java @@ -22,6 +22,8 @@ public class MainActivity extends Activity { private EditText username; private EditText device; private EditText hsUrl; + private EditText syncDelay; + private EditText syncTimeout; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,12 +37,16 @@ public class MainActivity extends Activity { username = (EditText) findViewById(R.id.editText_username); device = (EditText) findViewById(R.id.editText_device); hsUrl = (EditText) findViewById(R.id.editText_hsUrl); + syncDelay = (EditText) findViewById(R.id.editText_syncDelay); + syncTimeout = (EditText) findViewById(R.id.editText_syncTimeout); botUsername.setText(sp.getString("botUsername", "")); botPassword.setText(sp.getString("botPassword", "")); username.setText(sp.getString("username", "")); device.setText(sp.getString("device", "")); hsUrl.setText(sp.getString("hsUrl", "")); + syncDelay.setText(sp.getString("syncDelay", "")); + syncTimeout.setText(sp.getString("syncTimeout", "")); Button saveButton = (Button) findViewById(R.id.button_save); @@ -54,6 +60,8 @@ public class MainActivity extends Activity { editor.putString("username", username.getText().toString()); editor.putString("device", device.getText().toString()); editor.putString("hsUrl", hsUrl.getText().toString()); + editor.putString("syncDelay", syncDelay.getText().toString()); + editor.putString("syncTimeout", syncTimeout.getText().toString()); editor.apply(); Log.e(TAG, "onClick: " + botUsername.getText().toString() ); diff --git a/app/src/main/java/eu/droogers/smsmatrix/Matrix.java b/app/src/main/java/eu/droogers/smsmatrix/Matrix.java index ef6a45f..360218a 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/Matrix.java +++ b/app/src/main/java/eu/droogers/smsmatrix/Matrix.java @@ -41,6 +41,8 @@ import static android.content.ContentValues.TAG; */ public class Matrix { + private final int syncDelay; + private final int syncTimeout; HomeServerConnectionConfig hsConfig; Context context; MXSession session; @@ -56,7 +58,7 @@ public class Matrix { private String realUserid; - public Matrix (final Context context, String url, String botUsername, String botPassword, String username, String device) { + public Matrix(final Context context, String url, String botUsername, String botPassword, String username, String device, String syncDelay, String syncTimeout) { this.context = context; hsConfig = new HomeServerConnectionConfig(Uri.parse(url)); @@ -64,6 +66,8 @@ public class Matrix { deviceName = device; this.botUsername = botUsername; botHSUrl = url; + this.syncDelay = Integer.parseInt(syncDelay); + this.syncTimeout = Integer.parseInt(syncTimeout); login(botUsername, botPassword); } @@ -99,8 +103,8 @@ public class Matrix { // NetworkConnectivityReceiver nwMan = new NetworkConnectivityReceiver(); session = new MXSession(hsConfig, dh, context); - session.setSyncDelay(12000); - session.setSyncTimeout(30*60*1000); + session.setSyncDelay(syncDelay * 1000); + session.setSyncTimeout(syncTimeout * 60 * 1000); Log.e(TAG, "onLogin:" + session.getSyncTimeout()); diff --git a/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java b/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java index cc1b111..1e29f60 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java +++ b/app/src/main/java/eu/droogers/smsmatrix/MatrixService.java @@ -21,6 +21,8 @@ public class MatrixService extends Service { private String username; private String device; private String hsUrl; + private String syncDelay; + private String syncTimeout; @Override public void onCreate() { @@ -35,9 +37,11 @@ public class MatrixService extends Service { username = sp.getString("username", ""); device = sp.getString("device", ""); hsUrl = sp.getString("hsUrl", ""); + syncDelay = sp.getString("syncDelay", ""); + syncTimeout = sp.getString("syncTimeout", ""); - if (mx == null && !botUsername.isEmpty() && !botPassword.isEmpty() && !username.isEmpty() && !device.isEmpty() && !hsUrl.isEmpty()) { - mx = new Matrix(getApplication(), hsUrl, botUsername, botPassword, username, device); + if (mx == null && !botUsername.isEmpty() && !botPassword.isEmpty() && !username.isEmpty() && !device.isEmpty() && !hsUrl.isEmpty() && !syncDelay.isEmpty() && !syncTimeout.isEmpty()) { + mx = new Matrix(getApplication(), hsUrl, botUsername, botPassword, username, device, syncDelay, syncTimeout); Log.e(TAG, "onStartCommand222: " + hsUrl ); Toast.makeText(this, "service starting:", Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4830c46..b386f52 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -100,6 +100,40 @@ android:hint="Sms_mobiel" android:inputType="textPersonName" /> + + + + + + + +