1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* 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);
}
}
|