summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2015-10-09 12:20:57 +0200
committerArne Schwabe <arne@rfc2549.org>2015-10-09 13:49:40 +0200
commit233cb40aec40b44452533f2a8d66ddfcd9e890bf (patch)
treec91a0ec6f89276bf8089668e3beef3de4fa0f452 /main/src
parenta6df3b558263421da030286b12d595f7dd0111f9 (diff)
Fix connection list (closes #398)
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java147
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Settings_Connections.java6
-rw-r--r--main/src/main/res/layout/connections.xml3
-rw-r--r--main/src/main/res/layout/server_card.xml23
-rwxr-xr-xmain/src/main/res/values/strings.xml2
5 files changed, 130 insertions, 51 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java b/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java
index c0bda8d1..74c103f8 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java
@@ -28,9 +28,6 @@ import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.Connection;
-/**
- * Created by arne on 30.10.14.
- */
public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.ConnectionsHolder> {
private final Context mContext;
private final VpnProfile mProfile;
@@ -58,8 +55,10 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
private final ImageButton mDeleteButton;
private final EditText mConnectText;
private final SeekBar mConnectSlider;
+ private final ConnectionsAdapter mConnectionsAdapter;
+ private Connection mConnection;
- public ConnectionsHolder(View card) {
+ public ConnectionsHolder(View card, ConnectionsAdapter connectionsAdapter) {
super(card);
mServerNameView = (EditText) card.findViewById(R.id.servername);
mPortNumberView = (EditText) card.findViewById(R.id.portnumber);
@@ -72,6 +71,94 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
mConnectSlider = (SeekBar) card.findViewById(R.id.connect_silder);
mConnectText = (EditText) card.findViewById(R.id.connect_timeout);
+ mConnectionsAdapter = connectionsAdapter;
+
+ addListeners();
+ }
+
+ public void addListeners() {
+ mRemoteSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ mConnection.mEnabled = isChecked;
+ mConnectionsAdapter.displayWarningIfNoneEnabled();
+ }
+ });
+
+ mProtoGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ if (checkedId == R.id.udp_proto)
+ mConnection.mUseUdp = true;
+ else if (checkedId == R.id.tcp_proto)
+ mConnection.mUseUdp = false;
+ }
+ });
+ mCustomOptionCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ mConnection.mUseCustomConfig = isChecked;
+ mCustomOptionsLayout.setVisibility(mConnection.mUseCustomConfig ? View.VISIBLE : View.GONE);
+ }
+ });
+
+
+
+ mServerNameView.addTextChangedListener(new OnTextChangedWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ mConnection.mServerName = s.toString();
+ }
+
+ });
+
+ mPortNumberView.addTextChangedListener(new OnTextChangedWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ mConnection.mServerPort = s.toString();
+ }
+ });
+
+ mCustomOptionText.addTextChangedListener(new OnTextChangedWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ mConnection.mCustomConfiguration = s.toString();
+ }
+ });
+
+ mConnectSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if (fromUser) {
+ mConnectText.setText(String.valueOf(progress));
+ mConnection.mConnectTimeout = progress;
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+ });
+ mConnectText.addTextChangedListener(new OnTextChangedWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ try {
+ int t = Integer.valueOf(String.valueOf(s));
+ mConnectSlider.setProgress(t);
+ mConnection.mConnectTimeout = t;
+ } catch (Exception ignored) {
+
+ }
+ }
+ });
+
+
}
}
@@ -87,7 +174,7 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
} else { // TYPE_FOOTER
card = li.inflate(R.layout.server_footer, viewGroup, false);
}
- return new ConnectionsHolder(card);
+ return new ConnectionsHolder(card, this);
}
@@ -110,10 +197,14 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
return;
}
final Connection connection = mConnections[position];
+
+ cH.mConnection = connection;
+
cH.mPortNumberView.setText(connection.mServerPort);
cH.mServerNameView.setText(connection.mServerName);
cH.mPortNumberView.setText(connection.mServerPort);
cH.mRemoteSwitch.setChecked(connection.mEnabled);
+
if (connection.mConnectTimeout==0) {
cH.mConnectText.setText("");
} else {
@@ -121,37 +212,13 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
}
cH.mConnectSlider.setProgress(connection.mConnectTimeout);
- cH.mRemoteSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- connection.mEnabled = isChecked;
- displayWarningifNoneEnabled();
- }
- });
-
cH.mProtoGroup.check(connection.mUseUdp ? R.id.udp_proto : R.id.tcp_proto);
- cH.mProtoGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- if (checkedId == R.id.udp_proto)
- connection.mUseUdp = true;
- else if (checkedId == R.id.tcp_proto)
- connection.mUseUdp = false;
- }
- });
cH.mCustomOptionsLayout.setVisibility(connection.mUseCustomConfig ? View.VISIBLE : View.GONE);
cH.mCustomOptionText.setText(connection.mCustomConfiguration);
cH.mCustomOptionCB.setChecked(connection.mUseCustomConfig);
- cH.mCustomOptionCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- connection.mUseCustomConfig = isChecked;
- cH.mCustomOptionsLayout.setVisibility(connection.mUseCustomConfig ? View.VISIBLE : View.GONE);
- }
- });
cH.mDeleteButton.setOnClickListener(
new View.OnClickListener() {
@@ -228,6 +295,7 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
}
+
private void removeRemote(int idx) {
Connection[] mConnections2 = Arrays.copyOf(mConnections, mConnections.length - 1);
for (int i = idx + 1; i < mConnections.length; i++) {
@@ -242,15 +310,6 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
return mConnections.length + 1; //for footer
}
- public void displayWarningifNoneEnabled() {
- int showWarning = View.VISIBLE;
- for (Connection conn : mConnections) {
- if (conn.mEnabled)
- showWarning = View.GONE;
- }
- mConnectionFragment.setWarningVisible(showWarning);
- }
-
@Override
public int getItemViewType(int position) {
if (position == mConnections.length)
@@ -263,9 +322,19 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
mConnections = Arrays.copyOf(mConnections, mConnections.length + 1);
mConnections[mConnections.length - 1] = new Connection();
notifyItemInserted(mConnections.length - 1);
- displayWarningifNoneEnabled();
+ displayWarningIfNoneEnabled();
}
+ protected void displayWarningIfNoneEnabled() {
+ int showWarning = View.VISIBLE;
+ for (Connection conn : mConnections) {
+ if (conn.mEnabled)
+ showWarning = View.GONE;
+ }
+ mConnectionFragment.setWarningVisible(showWarning);
+ }
+
+
public void saveProfile() {
mProfile.mConnections = mConnections;
}
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Connections.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Connections.java
index 619d39a6..e0353f36 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Connections.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Connections.java
@@ -5,13 +5,11 @@
package de.blinkt.openvpn.fragments;
-import android.app.Fragment;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
-import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -23,8 +21,6 @@ import android.widget.ImageButton;
import android.widget.TextView;
import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.ProfileManager;
public class Settings_Connections extends Settings_Fragment implements View.OnClickListener {
private ConnectionsAdapter mConnectionsAdapter;
@@ -74,7 +70,7 @@ public class Settings_Connections extends Settings_Fragment implements View.OnCl
mUseRandomRemote.setChecked(mProfile.mRemoteRandom);
- mConnectionsAdapter.displayWarningifNoneEnabled();
+ mConnectionsAdapter.displayWarningIfNoneEnabled();
return v;
}
diff --git a/main/src/main/res/layout/connections.xml b/main/src/main/res/layout/connections.xml
index 57c575d8..7559bdc0 100644
--- a/main/src/main/res/layout/connections.xml
+++ b/main/src/main/res/layout/connections.xml
@@ -60,13 +60,14 @@
android:layout_margin="10dp"
android:background="@drawable/white_rect"
android:drawableLeft="@drawable/ic_dialog_alert"
+ android:drawableStart="@drawable/ic_dialog_alert"
android:drawablePadding="10dp"
android:elevation="2dp"
android:gravity="center_vertical"
android:padding="@dimen/stdpadding"
android:text="@string/remote_no_server_selected"
android:visibility="visible"
- tools:visibility="gone" />
+ tools:visibility="visible" />
<include layout="@layout/connection_fab" />
diff --git a/main/src/main/res/layout/server_card.xml b/main/src/main/res/layout/server_card.xml
index bad9a3c6..e3ebdf98 100644
--- a/main/src/main/res/layout/server_card.xml
+++ b/main/src/main/res/layout/server_card.xml
@@ -38,6 +38,8 @@
<TextView
+ android:layout_toLeftOf="@id/port_label"
+ android:layout_toStartOf="@id/port_label"
android:id="@+id/server_label"
style="@style/item"
android:text="@string/address"
@@ -54,7 +56,8 @@
android:layout_below="@id/port_label"
android:inputType="numberDecimal"
android:text="1194"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
+ android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
+ tools:ignore="HardcodedText" />
<EditText
@@ -69,7 +72,8 @@
android:inputType="textUri"
android:singleLine="true"
android:text="openvpn.blinkt.de"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
+ android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
+ tools:ignore="HardcodedText" />
<TextView
android:id="@+id/protocol"
@@ -77,7 +81,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/servername"
android:paddingTop="10dp"
- android:text="Protocol" />
+ android:text="@string/protocol" />
<RadioGroup
android:id="@+id/udptcpradiogroup"
@@ -85,13 +89,17 @@
android:layout_height="wrap_content"
android:layout_below="@id/protocol"
android:orientation="horizontal"
+ android:paddingStart="20dp"
+ android:paddingEnd="20dp"
+ android:paddingRight="20dp"
android:paddingLeft="20dp">
<RadioButton
android:id="@+id/udp_proto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="UDP" />
+ android:text="UDP"
+ tools:ignore="HardcodedText" />
<Space
android:layout_width="20dp"
@@ -101,7 +109,8 @@
android:id="@+id/tcp_proto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="TCP" />
+ android:text="TCP"
+ tools:ignore="HardcodedText" />
</RadioGroup>
@@ -189,6 +198,8 @@
android:layout_height="wrap_content"
android:layout_below="@id/use_customoptions"
android:orientation="vertical"
+ android:paddingRight="10dp"
+ android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingStart="10dp">
@@ -214,7 +225,7 @@
android:layout_alignRight="@+id/portnumber"
android:layout_below="@+id/portnumber"
android:layout_gravity="right|bottom"
- android:text="Enable" />
+ android:text="@string/enabled_connection_entry" />
<ImageButton
android:id="@+id/remove_connection"
diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml
index c1c3a638..185923f6 100755
--- a/main/src/main/res/values/strings.xml
+++ b/main/src/main/res/values/strings.xml
@@ -388,5 +388,7 @@
<string name="connect_timeout">Connect Timeout</string>
<string name="no_allowed_app">No allowed app app added. Addding ourselves (%s) to have at least one app in the allowed app list to not allow all apps</string>
<string name="query_permissions_sdcard">OpenVPN for Android can try to discover the missing file(s) on the sdcard automatically. Tap this message start the permission request.</string>
+ <string name="protocol">Protocol</string>
+ <string name="enabled_connection_entry">Enabled</string>
</resources>