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

Commit 28cd3f5e authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

Merge branch '4859_privacy_rating_dot' into 'epic_176-all-refactorAndGplay'

App lounge: Add indicator to privacy and rating

See merge request ecorp/apps/apps!16
parents cf7a16f8 e802a177
Loading
Loading
Loading
Loading
+56 −4
Original line number Diff line number Diff line
@@ -20,12 +20,15 @@ package foundation.e.apps.application

import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.Html
import android.util.Log
import android.view.View
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
@@ -233,11 +236,17 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
            // Ratings widgets
            binding.ratingsInclude.apply {
                if (it.ratings.usageQualityScore != -1.0) {
                    val rating =
                        applicationViewModel.handleRatingFormat(it.ratings.usageQualityScore)
                    appRating.text =
                        getString(
                            R.string.rating_out_of,
                            applicationViewModel.handleRatingFormat(it.ratings.usageQualityScore)
                            R.string.rating_out_of, rating
                        )

                    appRating.setCompoundDrawablesWithIntrinsicBounds(
                        null, null, getRatingDrawable(rating), null
                    )
                    appRating.compoundDrawablePadding = 15
                }
                appRatingLayout.setOnClickListener {
                    ApplicationDialogFragment(
@@ -248,10 +257,16 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
                }

                if (it.ratings.privacyScore != -1.0) {
                    val privacyScore = it.ratings.privacyScore.toInt().toString()
                    appPrivacyScore.text = getString(
                        R.string.privacy_rating_out_of,
                        it.ratings.privacyScore.toInt().toString()
                        privacyScore
                    )

                    appPrivacyScore.setCompoundDrawablesRelativeWithIntrinsicBounds(
                        null, null, getPrivacyDrawable(privacyScore), null
                    )
                    appPrivacyScore.compoundDrawablePadding = 15
                }
                appPrivacyScoreLayout.setOnClickListener {
                    ApplicationDialogFragment(
@@ -319,7 +334,6 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
                        getString(R.string.trackers_title),
                        trackers
                    ).show(childFragmentManager, TAG)

                }
            }

@@ -348,4 +362,42 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
        }
        return shareIntent
    }

    private fun getPrivacyDrawable(privacyRating: String): Drawable? {
        val rating = privacyRating.toInt()

        var dotColor = ContextCompat.getColor(requireContext(), R.color.colorGreen)
        if (rating <= 3) {
            dotColor = ContextCompat.getColor(requireContext(), R.color.colorRed)
        } else if (rating <= 6) {
            dotColor = ContextCompat.getColor(requireContext(), R.color.colorYellow)
        }

        return applyDotAccent(dotColor)
    }

    private fun getRatingDrawable(reviewRating: String): Drawable? {
        val rating = reviewRating.toDouble()

        var dotColor = ContextCompat.getColor(requireContext(), R.color.colorGreen)
        if (rating <= 2.0) {
            dotColor = ContextCompat.getColor(requireContext(), R.color.colorRed)
        } else if (rating <= 3.4) {
            dotColor = ContextCompat.getColor(requireContext(), R.color.colorYellow)
        }

        return applyDotAccent(dotColor)
    }

    private fun applyDotAccent(dotColor: Int): Drawable? {
        val circleDrawable =
            ContextCompat.getDrawable(requireContext(), R.drawable.ic_rating_privacy_circle)

        circleDrawable?.colorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
            dotColor,
            BlendModeCompat.SRC_ATOP
        )

        return circleDrawable
    }
}
+28 −0
Original line number Diff line number Diff line
<!--
  ~ Apps  Quickly and easily install Android apps onto your device!
  ~ Copyright (C) 2021  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 xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="11dp"
    android:height="11dp"
    android:viewportWidth="11"
    android:viewportHeight="11"
    android:tint="@color/colorAccent">
    <path
        android:pathData="M5.2093,5.8407m-5.0443,0a5.0443,5.0443 0,1 1,10.0885 0a5.0443,5.0443 0,1 1,-10.0885 0"
        android:fillColor="@color/colorAccent"/>
</vector>
+7 −1
Original line number Diff line number Diff line
@@ -32,4 +32,10 @@

    <!-- Application Page-->
    <color name="app_info_text_color_grey">#A4AEB7</color>

    <!-- Rating Dot -->
    <color name="colorGreen">#34A853</color>
    <color name="colorRed">#FB3846</color>
    <color name="colorYellow">#FFEB3B</color>

</resources>
 No newline at end of file