diff options
author | cyBerta <cyberta@riseup.net> | 2023-10-29 15:58:52 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2023-10-29 15:58:52 +0100 |
commit | 50defeaff2a8468ee44db7e09752e334e4d1ba2c (patch) | |
tree | cca77a33f5b3266b9b0462136057ae47f6b146d4 /main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java | |
parent | 45f67a08b481f2f727556a36e28d17a3f68d435a (diff) | |
parent | 87aac67b611f616aebfb722679b40e3f49576f01 (diff) |
Merge branch 'schwabe_master' into ssh_new_master
Diffstat (limited to 'main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java')
-rw-r--r-- | main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java index c7ee5df1..fa9438cb 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java @@ -5,12 +5,14 @@ package de.blinkt.openvpn.fragments; +import android.Manifest; import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.graphics.drawable.Drawable; @@ -20,6 +22,9 @@ import android.os.Build; import android.os.Bundle; import android.os.PersistableBundle; +import androidx.activity.result.ActivityResultCallback; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.fragment.app.ListFragment; @@ -85,6 +90,8 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn private ArrayAdapter<VpnProfile> mArrayadapter; private Intent mLastIntent; private VpnProfile defaultVPN; + private View mPermissionView; + private ActivityResultLauncher<String> mPermReceiver; @Override public void updateState(String state, String logmessage, final int localizedResId, ConnectionStatus level, Intent intent) { @@ -130,6 +137,13 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn super.onCreate(savedInstanceState); setHasOptionsMenu(true); setListAdapter(); + + registerPermissionReceiver(); + } + + private void registerPermissionReceiver() { + mPermReceiver = registerForActivityResult(new ActivityResultContracts.RequestPermission(), + result -> checkForNotificationPermission(requireView())); } @RequiresApi(api = Build.VERSION_CODES.N_MR1) @@ -225,9 +239,10 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn @RequiresApi(Build.VERSION_CODES.N_MR1) ShortcutInfo createShortcut(VpnProfile profile) { Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); - shortcutIntent.setClass(getActivity(), LaunchVPN.class); + shortcutIntent.setClass(requireContext(), LaunchVPN.class); shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); shortcutIntent.setAction(Intent.ACTION_MAIN); + shortcutIntent.putExtra(LaunchVPN.EXTRA_START_REASON, "shortcut"); shortcutIntent.putExtra("EXTRA_HIDELOG", true); PersistableBundle versionExtras = new PersistableBundle(); @@ -278,10 +293,24 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn if (fab_import != null) fab_import.setOnClickListener(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) + checkForNotificationPermission(v); + + return v; } + private void checkForNotificationPermission(View v) { + mPermissionView = v.findViewById(R.id.notification_permission); + boolean permissionGranted = (requireActivity().checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED); + mPermissionView.setVisibility(permissionGranted ? View.GONE : View.VISIBLE); + + mPermissionView.setOnClickListener((view) -> { + mPermReceiver.launch(Manifest.permission.POST_NOTIFICATIONS); + }); + } + private void setListAdapter() { if (mArrayadapter == null) { mArrayadapter = new VPNArrayAdapter(getActivity(), R.layout.vpn_list_item, R.id.vpn_item_title); @@ -485,11 +514,9 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn onAddOrDuplicateProfile(profile); } - if (resultCode != Activity.RESULT_OK) return; - if (requestCode == START_VPN_CONFIG) { String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID); @@ -536,6 +563,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn Intent intent = new Intent(getActivity(), LaunchVPN.class); intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); + intent.putExtra(LaunchVPN.EXTRA_START_REASON, "main profile list"); intent.setAction(Intent.ACTION_MAIN); startActivity(intent); } @@ -640,9 +668,9 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn public Drawable getDrawable(String source) { Drawable d = null; if ("ic_menu_add".equals(source)) - d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_add_grey); + d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_add_grey, requireActivity().getTheme()); else if ("ic_menu_archive".equals(source)) - d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_import_grey); + d = requireActivity().getResources().getDrawable(R.drawable.ic_menu_import_grey, requireActivity().getTheme()); if (d != null) { |