Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50ffbbe6 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

Merge branch '256-app_list_tooltip' into 'main'

256 : Add tooltip info about apps lists.

See merge request !91
parents 837e4ffa 227c31ab
Loading
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.privacycentralapp.common

import android.content.Context
import android.content.res.ColorStateList
import android.text.Spannable
import android.text.SpannableString
import android.text.style.DynamicDrawableSpan
import android.text.style.ImageSpan
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.TooltipCompat
import foundation.e.privacycentralapp.R

fun setToolTipForAsterisk(
    textView: TextView,
    @StringRes textId: Int,
    @StringRes tooltipTextId: Int
) {
    textView.text = asteriskAsInfoIconSpannable(textView.context, textId, textView.textColors)
    TooltipCompat.setTooltipText(textView, textView.context.getString(tooltipTextId))

    textView.setOnClickListener { it.performLongClick() }
}

private fun asteriskAsInfoIconSpannable(
    context: Context,
    @StringRes textId: Int,
    tint: ColorStateList
): Spannable {
    val spannable = SpannableString(context.getString(textId))
    val index = spannable.lastIndexOf("*")
    if (index != -1) {
        AppCompatResources.getDrawable(context, R.drawable.ic_info_16dp)?.let {
            it.setTintList(tint)
            it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight)
            spannable.setSpan(
                ImageSpan(it, DynamicDrawableSpan.ALIGN_CENTER),
                index,
                index + 1,
                Spannable.SPAN_INCLUSIVE_INCLUSIVE
            )
        }
    }
    return spannable
}
 No newline at end of file
+8 −1
Original line number Diff line number Diff line
@@ -33,10 +33,11 @@ import foundation.e.privacycentralapp.PrivacyCentralApplication
import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.common.NavToolbarFragment
import foundation.e.privacycentralapp.common.ToggleAppsAdapter
import foundation.e.privacycentralapp.common.extensions.toText
import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar
import foundation.e.privacycentralapp.common.setToolTipForAsterisk
import foundation.e.privacycentralapp.databinding.FragmentInternetActivityPolicyBinding
import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode
import foundation.e.privacycentralapp.common.extensions.toText
import kotlinx.coroutines.launch
import java.util.Locale

@@ -82,6 +83,12 @@ class InternetPrivacyFragment : NavToolbarFragment(R.layout.fragment_internet_ac
            viewModel.submitAction(InternetPrivacyViewModel.Action.UseHiddenIPAction)
        }

        setToolTipForAsterisk(
            textView = binding.ipscramblingSelectApps,
            textId = R.string.ipscrambling_select_app,
            tooltipTextId = R.string.ipscrambling_app_list_infos
        )

        binding.ipscramblingSelectLocation.apply {
            adapter = ArrayAdapter(
                requireContext(), android.R.layout.simple_spinner_item,
+7 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import foundation.e.privacycentralapp.common.AppsAdapter
import foundation.e.privacycentralapp.common.GraphHolder
import foundation.e.privacycentralapp.common.NavToolbarFragment
import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar
import foundation.e.privacycentralapp.common.setToolTipForAsterisk
import foundation.e.privacycentralapp.databinding.FragmentTrackersBinding
import foundation.e.privacycentralapp.databinding.TrackersItemGraphBinding
import foundation.e.privacycentralapp.domain.entities.TrackersPeriodicStatistics
@@ -82,6 +83,12 @@ class TrackersFragment :
            viewModel.submitAction(TrackersViewModel.Action.CloseQuickPrivacyDisabledMessage)
        }

        setToolTipForAsterisk(
            textView = binding.trackersAppsListTitle,
            textId = R.string.trackers_applist_title,
            tooltipTextId = R.string.trackers_applist_infos
        )

        viewLifecycleOwner.lifecycleScope.launch {
            viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                render(viewModel.state.value)
+20 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 E FOUNDATION
  ~
  ~ This program is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
  -->
<vector android:height="16dp" android:viewportHeight="24"
    android:viewportWidth="24" android:width="16dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#000000" android:pathData="M11,7H13V9H11V7ZM11,11H13V17H11V11ZM12,2C6.48,2 2,6.48 2,12C2,17.52 6.48,22 12,22C17.52,22 22,17.52 22,12C22,6.48 17.52,2 12,2ZM12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20Z"/>
</vector>
+5 −3
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:background="@color/background"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
@@ -103,7 +105,7 @@
            <TextView
                android:id="@+id/ipscrambling_select_apps"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_width="wrap_content"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="16dp"
                android:text="@string/ipscrambling_select_app"
Loading