From 82484ed5851dd79fefec1090b9d9fe83608b5dc3 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 22 Feb 2019 13:32:56 +0100 Subject: Change allowed apps to also scroll the general settings --- .../openvpn/fragments/Settings_Allowed_Apps.kt | 33 +++++++-- .../res/layout/allowed_application_settings.xml | 65 ++++++++++++++++++ main/src/main/res/layout/allowed_vpn_apps.xml | 78 ++++------------------ 3 files changed, 104 insertions(+), 72 deletions(-) create mode 100644 main/src/main/res/layout/allowed_application_settings.xml (limited to 'main/src') diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt index 02f8fd77..dd2aa3b7 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt @@ -46,6 +46,8 @@ class Settings_Allowed_Apps : Fragment(), AdapterView.OnItemClickListener, Compo private lateinit var mProfile: VpnProfile private lateinit var mDefaultAllowTextView: TextView private lateinit var mListAdapter: PackageAdapter + private lateinit var mSettingsView: View + override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) { val avh = view.tag as AppViewHolder @@ -109,9 +111,10 @@ class Settings_Allowed_Apps : Fragment(), AdapterView.OnItemClickListener, Compo override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val v = inflater.inflate(R.layout.allowed_vpn_apps, container, false) - mDefaultAllowTextView = v.findViewById(R.id.default_allow_text) as TextView + mSettingsView = inflater.inflate(R.layout.allowed_application_settings, container, false) + mDefaultAllowTextView = mSettingsView.findViewById(R.id.default_allow_text) as TextView - val vpnOnDefaultSwitch = v.findViewById(R.id.default_allow) as Switch + val vpnOnDefaultSwitch = mSettingsView.findViewById(R.id.default_allow) as Switch vpnOnDefaultSwitch.setOnCheckedChangeListener { buttonView, isChecked -> changeDisallowText(isChecked) @@ -120,7 +123,7 @@ class Settings_Allowed_Apps : Fragment(), AdapterView.OnItemClickListener, Compo vpnOnDefaultSwitch.isChecked = mProfile.mAllowedAppsVpnAreDisallowed - val vpnAllowBypassSwitch = v.findViewById(R.id.allow_bypass) as Switch + val vpnAllowBypassSwitch = mSettingsView.findViewById(R.id.allow_bypass) as Switch vpnAllowBypassSwitch.setOnCheckedChangeListener { buttonView, isChecked -> mProfile.mAllowAppVpnBypass = isChecked } @@ -225,18 +228,28 @@ class Settings_Allowed_Apps : Fragment(), AdapterView.OnItemClickListener, Compo } override fun getCount(): Int { - return mFilteredData.size + return mFilteredData.size + 1 } override fun getItem(position: Int): Any { - return mFilteredData[position] + return mFilteredData[position - 1] } override fun getItemId(position: Int): Long { - return mFilteredData[position].packageName.hashCode().toLong() + if (position == 0) + return "settings".hashCode().toLong() + return mFilteredData[position - 1].packageName.hashCode().toLong() } override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? { + if (position == 0) { + return mSettingsView + } else + return getViewApp(position - 1, convertView, parent) + + } + + fun getViewApp(position: Int, convertView: View?, parent: ViewGroup): View? { val viewHolder = AppViewHolder.createOrRecycle(mInflater, convertView, parent) viewHolder.mInfo = mFilteredData[position] val mInfo = mFilteredData[position] @@ -260,6 +273,14 @@ class Settings_Allowed_Apps : Fragment(), AdapterView.OnItemClickListener, Compo return mFilter } + override fun getViewTypeCount(): Int { + return 2; + } + + override fun getItemViewType(position: Int): Int { + return if (position == 0) 0 else 1 + } + private inner class ItemFilter : Filter() { override fun performFiltering(constraint: CharSequence): Filter.FilterResults { diff --git a/main/src/main/res/layout/allowed_application_settings.xml b/main/src/main/res/layout/allowed_application_settings.xml new file mode 100644 index 00000000..96170965 --- /dev/null +++ b/main/src/main/res/layout/allowed_application_settings.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/allowed_vpn_apps.xml b/main/src/main/res/layout/allowed_vpn_apps.xml index 45ff66d6..7f5e7b8b 100644 --- a/main/src/main/res/layout/allowed_vpn_apps.xml +++ b/main/src/main/res/layout/allowed_vpn_apps.xml @@ -5,82 +5,28 @@ - - - - - - - - - - - - - + android:layout_height="match_parent" + android:orientation="vertical" + tools:ignore="RtlCompat"> - + android:drawSelectorOnTop="false" + android:scrollbarStyle="outsideOverlay" + android:visibility="gone" /> + android:gravity="center" + android:orientation="vertical" + android:visibility="visible"> + android:singleLine="true" + android:text="@string/loading" + android:textAppearance="?android:attr/textAppearanceSmall" /> -- cgit v1.2.3