summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.java101
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.kt80
2 files changed, 80 insertions, 101 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.java b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.java
deleted file mode 100644
index 2f5521a5..00000000
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2012-2016 Arne Schwabe
- * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- */
-
-package de.blinkt.openvpn.fragments;
-
-import android.os.Build;
-import android.os.Bundle;
-import androidx.annotation.Nullable;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Checkable;
-import android.widget.ImageButton;
-import android.widget.TextView;
-
-import de.blinkt.openvpn.R;
-
-public class Settings_Connections extends Settings_Fragment implements View.OnClickListener {
- private ConnectionsAdapter mConnectionsAdapter;
- private TextView mWarning;
- private Checkable mUseRandomRemote;
- private RecyclerView mRecyclerView;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
-
- setHasOptionsMenu(true);
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
- inflater.inflate(R.menu.connections, menu);
- super.onCreateOptionsMenu(menu, inflater);
- }
-
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.connections, container, false);
-
- mWarning = (TextView) v.findViewById(R.id.noserver_active_warning);
- mRecyclerView = (RecyclerView) v.findViewById(R.id.connection_recycler_view);
-
- int dpwidth = (int) (container.getWidth()/getResources().getDisplayMetrics().density);
- int columns = dpwidth/290;
- columns = Math.max(1, columns);
-
- mConnectionsAdapter = new ConnectionsAdapter(getActivity(), this, mProfile);
-
- //mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(columns, StaggeredGridLayoutManager.VERTICAL));
- mRecyclerView.setHasFixedSize(true);
- mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false));
- mRecyclerView.setAdapter(mConnectionsAdapter);
-
- ImageButton fab_button = (ImageButton) v.findViewById(R.id.add_new_remote);
- if(fab_button!=null)
- fab_button.setOnClickListener(this);
-
- mUseRandomRemote = (Checkable) v.findViewById(R.id.remote_random);
- mUseRandomRemote.setChecked(mProfile.mRemoteRandom);
-
-
- mConnectionsAdapter.displayWarningIfNoneEnabled();
-
- return v;
- }
-
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.add_new_remote) {
- mConnectionsAdapter.addRemote();
- }
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId()==R.id.add_new_remote)
- mConnectionsAdapter.addRemote();
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- protected void savePreferences() {
- mConnectionsAdapter.saveProfile();
- mProfile.mRemoteRandom = mUseRandomRemote.isChecked();
- }
-
- public void setWarningVisible(int showWarning) {
- mWarning.setVisibility(showWarning);
- }
-}
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.kt
new file mode 100644
index 00000000..75b87157
--- /dev/null
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Connections.kt
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2012-2016 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+package de.blinkt.openvpn.fragments
+
+import android.os.Build
+import android.os.Bundle
+import android.view.*
+import android.widget.Checkable
+import android.widget.ImageButton
+import android.widget.TextView
+import de.blinkt.openvpn.fragments.Settings_Fragment
+import de.blinkt.openvpn.fragments.ConnectionsAdapter
+import androidx.recyclerview.widget.RecyclerView
+import androidx.recyclerview.widget.LinearLayoutManager
+import de.blinkt.openvpn.R
+
+class Settings_Connections : Settings_Fragment(), View.OnClickListener {
+ private lateinit var mConnectionsAdapter: ConnectionsAdapter
+ private lateinit var mWarning: TextView
+ private lateinit var mUseRandomRemote: Checkable
+ private lateinit var mRecyclerView: RecyclerView
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setHasOptionsMenu(true)
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
+ inflater.inflate(R.menu.connections, menu)
+ super.onCreateOptionsMenu(menu, inflater)
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
+ )
+ : View? {
+ val v = inflater.inflate(R.layout.connections, container, false)
+ mWarning = v.findViewById<View>(R.id.noserver_active_warning) as TextView
+ mRecyclerView = v.findViewById<View>(R.id.connection_recycler_view) as RecyclerView
+ val dpwidth = (container!!.width / resources.displayMetrics.density).toInt()
+ var columns = dpwidth / 290
+ columns = 1.coerceAtLeast(columns)
+ mConnectionsAdapter = ConnectionsAdapter(activity, this, mProfile)
+
+ //mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(columns, StaggeredGridLayoutManager.VERTICAL));
+ mRecyclerView.setHasFixedSize(true)
+ mRecyclerView.layoutManager =
+ LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
+ mRecyclerView.adapter = mConnectionsAdapter
+ val fab_button = v.findViewById<View>(R.id.add_new_remote) as ImageButton
+ fab_button.setOnClickListener(this)
+ mUseRandomRemote = v.findViewById<View>(R.id.remote_random) as Checkable
+ mUseRandomRemote.isChecked = mProfile.mRemoteRandom
+ mConnectionsAdapter.displayWarningIfNoneEnabled()
+ return v
+ }
+
+ override fun onClick(v: View) {
+ if (v.id == R.id.add_new_remote) {
+ mConnectionsAdapter.addRemote()
+ }
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if (item.itemId == R.id.add_new_remote) mConnectionsAdapter.addRemote()
+ return super.onOptionsItemSelected(item)
+ }
+
+ override fun savePreferences() {
+ mConnectionsAdapter.saveProfile()
+ mProfile.mRemoteRandom = mUseRandomRemote.isChecked
+ }
+
+ fun setWarningVisible(showWarning: Int) {
+ mWarning.visibility = showWarning
+ }
+} \ No newline at end of file