Skip to content

Commit

Permalink
Yeah... it changed. lol
Browse files Browse the repository at this point in the history
  • Loading branch information
ForceTower committed Aug 22, 2024
1 parent 81cc19b commit c87a37b
Show file tree
Hide file tree
Showing 252 changed files with 14,674 additions and 14,470 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

Expand Down
268 changes: 135 additions & 133 deletions app/src/main/java/com/forcetower/uefs/GooglePlayGamesInstance.kt
Original file line number Diff line number Diff line change
@@ -1,133 +1,135 @@
/*
* This file is part of the UNES Open Source Project.
* UNES is licensed under the GNU GPLv3.
*
* Copyright (c) 2020. João Paulo Sena <joaopaulo761@gmail.com>
*
* 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
* 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 com.forcetower.uefs

import android.app.Activity
import android.content.ContextWrapper
import androidx.annotation.StringRes
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
import com.forcetower.core.lifecycle.Event
import com.google.android.gms.games.PlayGames
import kotlinx.coroutines.tasks.await

class GooglePlayGamesInstance(
private val activity: Activity
) : ContextWrapper(activity) {
private var playerName: String? = null
val signInClient = PlayGames.getGamesSignInClient(activity)
val achievementsClient = PlayGames.getAchievementsClient(activity)

private val preferences = PreferenceManager.getDefaultSharedPreferences(this)
private var playerUnlockedSwitch: Boolean = false

private val _status = MutableLiveData<Event<GameConnectionStatus>>()
val connectionStatus: LiveData<Event<GameConnectionStatus>>
get() = _status

/**
* Deve ser chamado quando o usuário de conectar com a conta do google para que o objeto possa
* criar todas as dependencias
*/
fun onConnected() {
_status.postValue(Event(GameConnectionStatus.CONNECTED))
preferences.edit().putBoolean("google_play_games_enabled_v2", true).apply()
unlockAchievement(R.string.achievement_comeou_o_jogo)
if (playerUnlockedSwitch) {
unlockAchievement(R.string.achievement_agora_eu_entendi_agora_eu_saquei)
}
}

/**
* Deve ser chamado quando o usuário optar por sair do jogo
*/
fun onDisconnected() {
_status.postValue(Event(GameConnectionStatus.DISCONNECTED))
preferences.edit().putBoolean("google_play_games_enabled_v2", false).apply()
}

/**
* Chame este método para desconectar o usuário do google play games
*/
fun disconnect() {
// removed. i guess
}

/**
* Chame este método quando ocorrer uma troca de conta... Por causa de motivos...
*/
fun changePlayerName(other: String) {
playerUnlockedSwitch = playerName != null && other != playerName
playerName = other
if (playerUnlockedSwitch) {
unlockAchievement(R.string.achievement_agora_eu_entendi_agora_eu_saquei)
}
}

/**
* Retorna se existe alguem conectado às contas do google ou não
*/
suspend fun isConnected(): Boolean {
return PlayGames.getGamesSignInClient(activity).isAuthenticated.await().isAuthenticated
}

/**
* Descobre se o Google Play Games está ativado ou desativado
*/
fun isPlayGamesEnabled(): Boolean {
return preferences.getBoolean("google_play_games_enabled_v2", false)
}

/**
* Desbloqueia uma conquista
*/
fun unlockAchievement(@StringRes resource: Int) {
unlockAchievement(getString(resource))
}

fun unlockAchievement(achievement: String) {
achievementsClient?.unlock(achievement)
}

fun revealAchievement(@StringRes resource: Int) {
val id = getString(resource)
achievementsClient?.reveal(id)
}

fun incrementAchievement(@StringRes resource: Int, step: Int) {
val id = getString(resource)
achievementsClient?.increment(id, step)
}

fun updateProgress(@StringRes resource: Int, value: Int) {
val id = getString(resource)
achievementsClient?.setSteps(id, value)
}

fun updateProgress(id: String, value: Int) {
achievementsClient?.setSteps(id, value)
}
}

enum class GameConnectionStatus {
CONNECTED, DISCONNECTED, LOADING
}
/*
* This file is part of the UNES Open Source Project.
* UNES is licensed under the GNU GPLv3.
*
* Copyright (c) 2020. João Paulo Sena <joaopaulo761@gmail.com>
*
* 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
* 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 com.forcetower.uefs

import android.app.Activity
import android.content.ContextWrapper
import androidx.annotation.StringRes
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
import com.forcetower.core.lifecycle.Event
import com.google.android.gms.games.PlayGames
import kotlinx.coroutines.tasks.await

class GooglePlayGamesInstance(
private val activity: Activity
) : ContextWrapper(activity) {
private var playerName: String? = null
val signInClient = PlayGames.getGamesSignInClient(activity)
val achievementsClient = PlayGames.getAchievementsClient(activity)

private val preferences = PreferenceManager.getDefaultSharedPreferences(this)
private var playerUnlockedSwitch: Boolean = false

private val _status = MutableLiveData<Event<GameConnectionStatus>>()
val connectionStatus: LiveData<Event<GameConnectionStatus>>
get() = _status

/**
* Deve ser chamado quando o usuário de conectar com a conta do google para que o objeto possa
* criar todas as dependencias
*/
fun onConnected() {
_status.postValue(Event(GameConnectionStatus.CONNECTED))
preferences.edit().putBoolean("google_play_games_enabled_v2", true).apply()
unlockAchievement(R.string.achievement_comeou_o_jogo)
if (playerUnlockedSwitch) {
unlockAchievement(R.string.achievement_agora_eu_entendi_agora_eu_saquei)
}
}

/**
* Deve ser chamado quando o usuário optar por sair do jogo
*/
fun onDisconnected() {
_status.postValue(Event(GameConnectionStatus.DISCONNECTED))
preferences.edit().putBoolean("google_play_games_enabled_v2", false).apply()
}

/**
* Chame este método para desconectar o usuário do google play games
*/
fun disconnect() {
// removed. i guess
}

/**
* Chame este método quando ocorrer uma troca de conta... Por causa de motivos...
*/
fun changePlayerName(other: String) {
playerUnlockedSwitch = playerName != null && other != playerName
playerName = other
if (playerUnlockedSwitch) {
unlockAchievement(R.string.achievement_agora_eu_entendi_agora_eu_saquei)
}
}

/**
* Retorna se existe alguem conectado às contas do google ou não
*/
suspend fun isConnected(): Boolean {
return PlayGames.getGamesSignInClient(activity).isAuthenticated.await().isAuthenticated
}

/**
* Descobre se o Google Play Games está ativado ou desativado
*/
fun isPlayGamesEnabled(): Boolean {
return preferences.getBoolean("google_play_games_enabled_v2", false)
}

/**
* Desbloqueia uma conquista
*/
fun unlockAchievement(@StringRes resource: Int) {
unlockAchievement(getString(resource))
}

fun unlockAchievement(achievement: String) {
achievementsClient?.unlock(achievement)
}

fun revealAchievement(@StringRes resource: Int) {
val id = getString(resource)
achievementsClient?.reveal(id)
}

fun incrementAchievement(@StringRes resource: Int, step: Int) {
val id = getString(resource)
achievementsClient?.increment(id, step)
}

fun updateProgress(@StringRes resource: Int, value: Int) {
val id = getString(resource)
achievementsClient?.setSteps(id, value)
}

fun updateProgress(id: String, value: Int) {
achievementsClient?.setSteps(id, value)
}
}

enum class GameConnectionStatus {
CONNECTED,
DISCONNECTED,
LOADING
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/forcetower/uefs/LaunchViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import com.forcetower.uefs.core.task.successOr
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.forcetower.unes.usecases.auth.HasEnrolledAccessUseCase
import dev.forcetower.unes.usecases.version.NotifyNewVersionUseCase
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlinx.coroutines.launch

@HiltViewModel
class LaunchViewModel @Inject constructor(
Expand Down
Loading

0 comments on commit c87a37b

Please sign in to comment.