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

Commit b3e1b20f authored by Aayush Gupta's avatar Aayush Gupta
Browse files

App Lounge: Move and improve app specific logic for permissions

parent 9be3af9f
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -436,7 +436,7 @@ class FusedAPIImpl @Inject constructor(
            author = this.developerName,
            category = this.categoryName,
            description = this.description,
            perms = this.permissions.transformPermsToString(),
            perms = this.permissions,
            icon_image_path = this.iconArtwork.url,
            last_modified = this.updatedOn,
            latest_version_code = this.versionCode,
@@ -454,18 +454,6 @@ class FusedAPIImpl @Inject constructor(
        )
    }

    fun getYouTubeUrl(youTubeImg: String): String {
        val ytURL = "https://www.youtube.com/watch?v="
        val splitID = youTubeImg.split("https://i.ytimg.com/vi/")[1]
        val id = splitID.split("/")[0]
        return ytURL + id
    }

    private fun MutableList<String>.transformPermsToString(): String {
        val list = this.toString().replace(", ", "\n")
        return list.substring(1, list.length - 1)
    }

    private fun MutableList<Artwork>.transformToList(): List<String> {
        val list = mutableListOf<String>()
        this.forEach {
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ data class FusedApp(
    val author: String = String(),
    val category: String = String(),
    val description: String = String(),
    var perms: String = String(),
    var perms: List<String> = emptyList(),
    var trackers: List<String> = emptyList(),
    val icon_image_path: String = String(),
    val last_modified: String = String(),
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
                    ApplicationDialogFragment(
                        R.drawable.ic_perm,
                        getString(R.string.permissions),
                        it.perms
                        applicationViewModel.transformPermsToString(it.perms.toMutableList())
                    ).show(childFragmentManager, TAG)
                }
                appTrackers.setOnClickListener {
+22 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import foundation.e.apps.api.fused.data.Origin
import foundation.e.apps.api.fused.data.Status
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
@@ -71,4 +72,25 @@ class ApplicationViewModel @Inject constructor(
            )
        }
    }

    fun getYouTubeUrl(youTubeImg: String): String {
        val ytURL = "https://www.youtube.com/watch?v="
        val splitID = youTubeImg.split("https://i.ytimg.com/vi/")[1]
        val id = splitID.split("/")[0]
        return ytURL + id
    }

    fun transformPermsToString(permissions: MutableList<String>): String {
        // Filter list to only keep platform permissions
        val filteredList = permissions.filter {
            it.startsWith("android.permission.")
        }
        // Remove prefix as we only have platform permissions remaining
        val list = filteredList.map {
            it.replace("[^>]*permission\\.".toRegex(), "")
        }
        // Make it a dialog-friendly string and return it
        val permString = list.toString().replace(", ", "\n")
        return permString.substring(1, permString.length - 1)
    }
}