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

Verified Commit 0f4df43b authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

Merge branch 'main' into 2112-nsfw_opensource_apps

# Conflicts:
#	app/src/main/java/foundation/e/apps/data/application/data/Application.kt
#	app/src/main/res/values/strings.xml
parents 7ebe73b3 f4cc0d92
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@
    <ID>LongParameterList:ApplicationViewModel.kt$ApplicationViewModel$( id: String, packageName: String, origin: Origin, isFdroidLink: Boolean, authObjectList: List&lt;AuthObject&gt;, retryBlock: (failedObjects: List&lt;AuthObject&gt;) -&gt; Boolean, )</ID>
    <ID>LongParameterList:CleanApkRetrofit.kt$CleanApkRetrofit$( @Query("keyword") keyword: String, @Query("source") source: String = APP_SOURCE_FOSS, @Query("type") type: String = APP_TYPE_ANY, @Query("nres") nres: Int = 20, @Query("page") page: Int = 1, @Query("by") by: String? = null, )</ID>
    <ID>LongParameterList:EglExtensionProvider.kt$EglExtensionProvider$( egl10: EGL10, eglDisplay: EGLDisplay, eglConfig: EGLConfig?, ai: IntArray, ai1: IntArray?, set: MutableSet&lt;String&gt; )</ID>
    <ID>LongParameterList:MainActivityViewModel.kt$MainActivityViewModel$( private val appLoungeDataStore: AppLoungeDataStore, private val applicationRepository: ApplicationRepository, private val appManagerWrapper: AppManagerWrapper, private val appLoungePackageManager: AppLoungePackageManager, private val pwaManager: PWAManager, private val ecloudRepository: EcloudRepository, private val blockedAppRepository: BlockedAppRepository, private val appInstallProcessor: AppInstallProcessor, )</ID>
    <ID>LongParameterList:MainActivityViewModel.kt$MainActivityViewModel$( private val appLoungeDataStore: AppLoungeDataStore, private val applicationRepository: ApplicationRepository, private val appManagerWrapper: AppManagerWrapper, private val appLoungePackageManager: AppLoungePackageManager, private val pwaManager: PWAManager, private val ecloudRepository: EcloudRepository, private val blockedAppRepository: BlockedAppRepository, private val contentRatingsRepository: ContentRatingsRepository, private val appInstallProcessor: AppInstallProcessor, )</ID>
    <ID>LongParameterList:UpdatesManagerImpl.kt$UpdatesManagerImpl$( @ApplicationContext private val context: Context, private val appLoungePackageManager: AppLoungePackageManager, private val applicationRepository: ApplicationRepository, private val faultyAppRepository: FaultyAppRepository, private val appLoungePreference: AppLoungePreference, private val fdroidRepository: FdroidRepository, private val blockedAppRepository: BlockedAppRepository, )</ID>
    <ID>LongParameterList:UpdatesWorker.kt$UpdatesWorker$( @Assisted private val context: Context, @Assisted private val params: WorkerParameters, private val updatesManagerRepository: UpdatesManagerRepository, private val dataStoreManager: DataStoreManager, private val authenticatorRepository: AuthenticatorRepository, private val appInstallProcessor: AppInstallProcessor, private val blockedAppRepository: BlockedAppRepository, )</ID>
    <ID>MagicNumber:AnonymousLoginManager.kt$AnonymousLoginManager$200</ID>
+34 −2
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ class MainActivity : AppCompatActivity() {
        }

        viewModel.updateAppWarningList()
        viewModel.updateContentRatings()

        observeEvents()
    }
@@ -194,7 +195,11 @@ class MainActivity : AppCompatActivity() {
                }

                launch {
                    observerErrorEvent()
                    observeErrorEvent()
                }

                launch {
                    observeErrorDialogEvent()
                }

                launch {
@@ -204,10 +209,26 @@ class MainActivity : AppCompatActivity() {
                launch {
                    observeNoInternetEvent()
                }

                launch {
                    observeAgeLimitRestrictionEvent()
                }
            }
        }
    }

    private suspend fun observeAgeLimitRestrictionEvent() {
        EventBus.events.filter {
            it is AppEvent.AgeLimitRestrictionEvent
        }.collectLatest {
            ApplicationDialogFragment(
                getString(R.string.restricted_app, it.data as String),
                getString(R.string.age_rate_limit_message, it.data as String),
                positiveButtonText = getString(R.string.ok),
            ).show(supportFragmentManager, TAG)
        }
    }

    private fun observePurchaseDeclined() {
        viewModel.purchaseDeclined.observe(this) {
            if (it.isNotEmpty()) {
@@ -355,7 +376,7 @@ class MainActivity : AppCompatActivity() {
        findNavController(R.id.fragment).navigate(action)
    }

    private suspend fun observerErrorEvent() {
    private suspend fun observeErrorEvent() {
        EventBus.events.filter { appEvent ->
            appEvent is AppEvent.ErrorMessageEvent
        }.collectLatest {
@@ -363,6 +384,17 @@ class MainActivity : AppCompatActivity() {
        }
    }

    private suspend fun observeErrorDialogEvent() {
        EventBus.events.filter { appEvent ->
            appEvent is AppEvent.ErrorMessageDialogEvent
        }.collectLatest {
            ApplicationDialogFragment(
                title = getString(R.string.unknown_error),
                message = getString(it.data as Int)
            ).show(supportFragmentManager, TAG)
        }
    }

    private suspend fun observeSignatureMissMatchError() {
        EventBus.events.filter { appEvent ->
            appEvent is AppEvent.SignatureMissMatchError
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ data class Application(
    var isGplayReplaced: Boolean = false,
    @SerializedName(value = "on_fdroid")
    val isFDroidApp: Boolean = false,
    val contentRating: ContentRating = ContentRating(),
    var contentRating: ContentRating = ContentRating(),
    @SerializedName(value = "antifeatures")
    val antiFeatures: List<Map<String, String>> = emptyList()
) {
+29 −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.data.blockedApps

import com.google.gson.annotations.SerializedName

data class ContentRatingGroup(
    val id: String,
    @SerializedName("age_group")
    val ageGroup: String,
    var ratings: List<String>
)
+89 −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.data.blockedApps

import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken
import foundation.e.apps.data.install.FileManager
import timber.log.Timber
import java.io.File
import java.io.IOException
import javax.inject.Inject
import javax.inject.Named

class ContentRatingParser @Inject constructor(
    private val gson: Gson,
    @Named("cacheDir") private val cacheDir: String
) {

    companion object {
        private const val CONTENT_RATINGS_FILE_NAME = "content_ratings.json"
    }

    fun parseContentRatingData(): List<ContentRatingGroup> {
        return try {
            val outputPath = moveFile()
            val contentRatingJson = readJsonFromFile(outputPath)
            Timber.d("ContentRatings file contents: $contentRatingJson")
            parseJsonOfContentRatingGroup(contentRatingJson)
        } catch (exception: IOException) {
            handleException(exception)
        } catch (exception: JsonSyntaxException) {
            handleException(exception)
        }
    }

    private fun readJsonFromFile(outputPath: String): String {
        val downloadedFile =
            File(outputPath + CONTENT_RATINGS_FILE_NAME)
        val contentRatingJson = String(downloadedFile.inputStream().readBytes())

        return contentRatingJson
    }

    private fun moveFile(): String {
        val outputPath = "$cacheDir/content_ratings/"
        FileManager.moveFile(
            "$cacheDir/",
            CONTENT_RATINGS_FILE_NAME, outputPath
        )

        return outputPath
    }

    private fun parseJsonOfContentRatingGroup(contentRatingJson: String): List<ContentRatingGroup> {
        val contentRatingsListTypeGroup = object : TypeToken<List<ContentRatingGroup>>() {}.type
        val contentRatingGroups: List<ContentRatingGroup> =
            gson.fromJson(contentRatingJson, contentRatingsListTypeGroup)

        return contentRatingGroups.map {
            it.ratings = it.ratings.map { rating ->
                rating.lowercase()
            }
            it
        }
    }

    private fun handleException(exception: Exception): List<ContentRatingGroup> {
        Timber.e(exception.localizedMessage ?: "", exception)
        return listOf()
    }
}
Loading