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

Commit 0a8da010 authored by Hasib Prince's avatar Hasib Prince
Browse files

Added ContentRating related repositories

parent 05d7a306
Loading
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -214,9 +214,6 @@ class MainActivity : AppCompatActivity() {
                            getString(R.string.unknown_error),
                            getString(R.string.age_rate_limit_message),
                            positiveButtonText = getString(R.string.ok),
                            positiveButtonAction = {
                                findNavController(binding.fragment.id).popBackStack()
                            }
                        ).show(supportFragmentManager, TAG)

                    }
+0 −77
Original line number Diff line number Diff line
/*
 *  Copyright MURENA SAS 2024
 *  Apps  Quickly and easily install Android apps onto your device!
 *
 *  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.apps.data

class ParentalControlRepository {

    fun isParentalControlEnabled(): Boolean {
        return true
    }

    fun getAllowedContentRatings(): List<String> {
        return listOf(
            "PEGI 3",
            "EVERYONE",
            "All ages",
            "General",
            "All ages",
            "For all",
            "PEGI 3",
            "Parental Guidance Recommended",
//            "EVERYONE",
//            "All ages",
//            "General",
//            "All ages",
//            "For all",
//            "Rated for 3+",
//            "PEGI 3",
//            "PEGI 7",
//            "Parental Guidance Recommended",
//            "EVERYONE",
//            "All ages",
//            "USK: Ages 6 and above",
//            "General",
//            "All ages",
//            "For all",
//            "Rated for 3+",
//            "Rated for 7+",
//            "PEGI 3",
//            "PEGI 7",
//            "PEGI 12",
//            "Parental Guidance Recommended",
//            "EVERYONE",
//            "EVERYONE 10+",
//            "TEEN",
//            "All ages",
//            "USK: Ages 6 and above",
//            "USK: Ages 12 and above",
//            "General",
//            "Parental Guidance",
//            "All ages",
//            "Rated 10+",
//            "Rated 12+",
//            "For all",
//            "Rated 12+",
//            "Rated for 3+",
//            "Rated for 7+",
//            "Rated for 12+"
        )
    }
}
 No newline at end of file
+4 −5
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class ContentRatingsRepository @Inject constructor(
) {

    private var _contentRatings = listOf<ContentRating>()
    val contentRatingsList: List<ContentRating>
    val contentRatings: List<ContentRating>
        get() = _contentRatings

    companion object {
@@ -63,12 +63,11 @@ class ContentRatingsRepository @Inject constructor(
            FileManager.moveFile("$cacheDir/",
                CONTENT_RATINGS_FILE_NAME, outputPath)
            val downloadedFile = File(outputPath + CONTENT_RATINGS_FILE_NAME)
            Timber.d("Blocked list file exists: ${downloadedFile.exists()}")
            val blockedAppInfoJson = String(downloadedFile.inputStream().readBytes())
            Timber.d("Blocked list file contents: $blockedAppInfoJson")
            val contentRatingJson = String(downloadedFile.inputStream().readBytes())
            Timber.d("ContentRatings file contents: $contentRatingJson")

            val contentRatingsListType = object : TypeToken<List<ContentRating>>() {}.type
            gson.fromJson(blockedAppInfoJson, contentRatingsListType)
            gson.fromJson(contentRatingJson, contentRatingsListType)
        } catch (exception: Exception) {
            Timber.e(exception.localizedMessage ?: "", exception)
            mutableListOf()
+59 −0
Original line number Diff line number Diff line
@@ -17,27 +17,43 @@
 *
 */

package foundation.e.apps.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.preference.DataStoreManager
import foundation.e.apps.domain.CheckAppAgeLimitUseCase
package foundation.e.apps.data.blockedApps

import android.content.Context
import android.net.Uri
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object UseCaseModule {

//    @Singleton
//    @Provides
//    fun provideGetAppsUseCase(
//        appsRepository: ApplicationRepository,
//        dataStoreManager: DataStoreManager
//    ): CheckAppAgeLimitUseCase {
//        return CheckAppAgeLimitUseCase(appsRepository, dataStoreManager)
//    }
@Singleton
class ParentalControlRepository @Inject constructor(
    @ApplicationContext private val context: Context
) {

    companion object {
        private const val URI_PARENTAL_CONTROL_PROVIDER =
            "content://foundation.e.parentalcontrol.provider/age"
    }

    fun getSelectedAgeGroup(): Ages? {
        val uri = Uri.parse(URI_PARENTAL_CONTROL_PROVIDER)
        val cursor = context.contentResolver.query(uri, null, null, null, null)

        cursor?.use {
            if (it.moveToFirst()) {
                val ageOrdinal = it.getInt(it.getColumnIndexOrThrow("age"))
                return Ages.values()[ageOrdinal]
            }
        }

        return null
    }
}

enum class Ages {
    THREE,
    SIX,
    ELEVEN,
    FIFTEEN,
    SEVENTEEN,
}
 No newline at end of file
+73 −0
Original line number Diff line number Diff line
/*
 *  Copyright MURENA SAS 2024
 *  Apps  Quickly and easily install Android apps onto your device!
 *
 *  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.apps.domain

import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.blockedApps.ContentRatingsRepository
import foundation.e.apps.data.blockedApps.ParentalControlRepository
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.data.preference.DataStoreManager
import timber.log.Timber
import javax.inject.Inject

class CheckAppAgeLimitUseCase @Inject constructor(
    private val applicationRepository: ApplicationRepository,
    private val dataStoreManager: DataStoreManager,
    private val contentRatingRepository: ContentRatingsRepository,
    private val parentalControlRepository: ParentalControlRepository
) {

    suspend operator fun invoke(fusedDownload: FusedDownload): Boolean {
        val authData = dataStoreManager.getAuthData()
        if (fusedDownload.contentRating?.title?.isEmpty() == true) {
            updateContentRating(fusedDownload, authData)
        }

        val selectedAgeGroup = parentalControlRepository.getSelectedAgeGroup()
        val allowedContentRating = contentRatingRepository.contentRatings.find {
            it.id == selectedAgeGroup.toString()
        }

        Timber.d("Selected age group: $selectedAgeGroup \n" +
                "Content rating: ${fusedDownload.contentRating?.title} \n" +
                "Allowed content rating: $allowedContentRating")
        return selectedAgeGroup != null
                && fusedDownload.contentRating?.title?.isNotEmpty() == true
                && allowedContentRating?.ratings?.contains(fusedDownload.contentRating!!.title) == false
    }

    private suspend fun updateContentRating(
        fusedDownload: FusedDownload,
        authData: AuthData
    ) {
        applicationRepository.getApplicationDetails(
            fusedDownload.id,
            fusedDownload.packageName,
            authData,
            fusedDownload.origin
        ).let { (appDetails, resultStatus) ->
            if (resultStatus == ResultStatus.OK) {
                fusedDownload.contentRating = appDetails.contentRating
            }
        }
    }
}
 No newline at end of file
Loading