Skip to content

Commit 5f05397

Browse files
.
1 parent 46283e4 commit 5f05397

File tree

14 files changed

+261
-38
lines changed

14 files changed

+261
-38
lines changed

.idea/deploymentTargetSelector.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
android {
1313
namespace = "com.rk.taskmanager"
1414
compileSdk = 36
15+
buildFeatures.buildConfig = true
1516

1617
dependenciesInfo {
1718
includeInApk = isIzzyOrFdroid.not()
@@ -60,7 +61,6 @@ android {
6061
signingConfig = signingConfigs.getByName("release")
6162
}
6263
debug{
63-
applicationIdSuffix = ".debug"
6464
versionNameSuffix = "-DEBUG"
6565
}
6666
}
@@ -71,8 +71,8 @@ android {
7171
targetSdk = 36
7272

7373
//versioning
74-
versionCode = 18
75-
versionName = "1.1.8"
74+
versionCode = 20
75+
versionName = "1.2.0"
7676
vectorDrawables {
7777
useSupportLibrary = true
7878
}
@@ -125,4 +125,8 @@ dependencies {
125125
implementation(libs.accompanist.swiperefresh)
126126
implementation(libs.google.material)
127127
implementation(project(":taskmanagerd"))
128+
implementation(libs.androidx.javascriptengine)
129+
130+
//its time to make some money 💵💵💵💵💵💵💵💵
131+
implementation(libs.play.services.ads)
128132
}

app/proguard-rules.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@
4242
native * shizuku* (...);
4343
native * rikka* (...);
4444
}
45+

app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
android:enableOnBackInvokedCallback="true"
2020
tools:targetApi="33">
2121

22+
<meta-data
23+
android:name="com.google.android.gms.ads.APPLICATION_ID"
24+
android:value="ca-app-pub-4934006287453841~9251579802"/>
25+
26+
<meta-data
27+
android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
28+
android:value="true"/>
29+
30+
<meta-data
31+
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
32+
android:value="true"/>
33+
34+
35+
2236
<provider
2337
android:name="rikka.shizuku.ShizukuProvider"
2438
android:authorities="${applicationId}.shizuku"
@@ -27,8 +41,6 @@
2741
android:exported="true"
2842
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />
2943

30-
<!-- android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" is to protect this provider from accessing by normal apps -->
31-
3244
<activity
3345
android:name=".MainActivity"
3446
android:exported="true"

app/src/main/java/com/rk/Daemon.kt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,18 @@ suspend fun startDaemon(
223223
try {
224224
when (mode) {
225225
WorkingMode.SHIZUKU.id -> {
226-
val loading = LoadingPopup(ctx = context)
227-
loading.setMessage(strings.starting_daemon.getString())
228-
loading.show()
229-
230226
if (!ShizukuShell.isShizukuRunning()) {
231-
loading.hide()
232227
return@withContext DaemonResult.SHIZUKU_NOT_RUNNING
233228
}
234229

235230
if (!ShizukuShell.isPermissionGranted()) {
236-
loading.hide()
237231
return@withContext DaemonResult.SHIZUKU_PERMISSION_DENIED
238232
}
239233

234+
val loading = LoadingPopup(ctx = context)
235+
loading.setMessage(strings.starting_daemon.getString())
236+
loading.show()
237+
240238
val processResult = ShizukuShell.newProcess(
241239
cmd = arrayOf(daemonFile.absolutePath, "-p", port.toString(), "-D"),
242240
env = arrayOf(),
@@ -257,21 +255,15 @@ suspend fun startDaemon(
257255
}
258256

259257
WorkingMode.ROOT.id -> {
260-
val loading = LoadingPopup(ctx = context)
261-
loading.setMessage(strings.starting_daemon.getString())
262-
loading.show()
263-
264258
if (!isSuInPath()) {
265-
loading.hide()
266259
return@withContext DaemonResult.SU_NOT_IN_PATH
267260
}
261+
268262
val cmd = arrayOf("su", "-c", daemonFile.absolutePath, "-p", port.toString(), "-D")
269263
val result = newProcess(cmd = cmd, env = arrayOf(), workingDir = "/")
270264
if (result.first == 0) {
271-
loading.hide()
272265
DaemonResult.OK
273266
} else {
274-
loading.hide()
275267
DaemonResult.DAEMON_REFUSED.also {
276268
it.message = result.second
277269
}

app/src/main/java/com/rk/taskmanager/MainActivity.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import androidx.navigation.NavController
1313
import androidx.navigation.compose.NavHost
1414
import androidx.navigation.compose.composable
1515
import androidx.navigation.compose.rememberNavController
16+
import com.google.android.gms.ads.MobileAds
1617
import com.rk.DaemonResult
1718
import com.rk.daemon_messages
1819
import com.rk.isConnected
1920
import com.rk.send_daemon_messages
2021
import com.rk.startDaemon
22+
import com.rk.taskmanager.ads.loadAd
2123
import com.rk.taskmanager.animations.NavigationAnimationTransitions
2224
import com.rk.taskmanager.screens.MainScreen
2325
import com.rk.taskmanager.screens.ProcessInfo
@@ -49,12 +51,24 @@ class MainActivity : ComponentActivity() {
4951
private set
5052
}
5153

52-
private var navControllerRef: WeakReference<NavController?> = WeakReference(null)
54+
var navControllerRef: WeakReference<NavController?> = WeakReference(null)
55+
private set
56+
var isinitialized = false
57+
private set
5358

5459
@OptIn(ExperimentalMaterial3Api::class)
5560
override fun onCreate(savedInstanceState: Bundle?) {
5661
super.onCreate(savedInstanceState)
5762
enableEdgeToEdge()
63+
64+
lifecycleScope.launch(Dispatchers.IO) {
65+
MobileAds.initialize(this@MainActivity)
66+
isinitialized = true
67+
loadAd(this@MainActivity)
68+
}
69+
70+
71+
5872
scope = this.lifecycleScope
5973
instance = this
6074

@@ -98,7 +112,7 @@ class MainActivity : ComponentActivity() {
98112
send_daemon_messages.emit("SWAP_PING")
99113
}
100114
}
101-
val delayMs = if (selectedscreen.intValue == 0) {
115+
val delayMs = if (selectedscreen.intValue == 0 && MainActivity.instance?.navControllerRef?.get()?.currentDestination?.route == SettingsRoutes.Home.route) {
102116
Settings.updateFrequency.toLong()
103117
} else {
104118
Settings.updateFrequency.toLong() * 2
@@ -163,6 +177,7 @@ class MainActivity : ComponentActivity() {
163177
}
164178
}
165179
viewModel.refreshProcessesAuto()
180+
loadAd(this)
166181
}
167182
}
168183

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.rk.taskmanager.ads
2+
3+
import android.app.Activity
4+
import android.content.Context
5+
import android.util.Log
6+
import androidx.lifecycle.lifecycleScope
7+
import com.google.android.gms.ads.AdError
8+
import com.google.android.gms.ads.AdRequest
9+
import com.google.android.gms.ads.LoadAdError
10+
import com.google.android.gms.ads.rewarded.RewardedAd
11+
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
12+
import com.google.android.gms.ads.FullScreenContentCallback
13+
import com.google.android.gms.ads.OnUserEarnedRewardListener
14+
import com.google.android.gms.common.api.internal.LifecycleActivity
15+
import com.rk.taskmanager.MainActivity
16+
import kotlinx.coroutines.Dispatchers
17+
import kotlinx.coroutines.GlobalScope
18+
import kotlinx.coroutines.launch
19+
20+
const val TEST_UNIT_AD_ID = "ca-app-pub-3940256099942544/5224354917"
21+
const val REWARDED_AD_UNIT_ID = "ca-app-pub-4934006287453841/1573729325"
22+
23+
private var rewardedAd: RewardedAd? = null
24+
private const val TAG = "AD_MANAGER"
25+
26+
fun isAdAvailable(): Boolean = rewardedAd != null
27+
28+
fun loadAd(activity: MainActivity){
29+
if (rewardedAd != null){
30+
return
31+
}
32+
if (MainActivity.instance?.isinitialized == false){
33+
return
34+
}
35+
activity.lifecycleScope.launch(Dispatchers.Main.immediate) {
36+
RewardedAd.load(
37+
activity,
38+
REWARDED_AD_UNIT_ID,
39+
AdRequest.Builder().build(),
40+
object : RewardedAdLoadCallback() {
41+
override fun onAdLoaded(ad: RewardedAd) {
42+
Log.d(TAG, "Ad was loaded.")
43+
rewardedAd = ad
44+
}
45+
46+
override fun onAdFailedToLoad(adError: LoadAdError) {
47+
Log.d(TAG, adError.message)
48+
rewardedAd = null
49+
}
50+
},
51+
)
52+
}
53+
54+
}
55+
56+
57+
fun showAd(activity: MainActivity, callback: () -> Unit) {
58+
if (MainActivity.instance?.isinitialized == false){
59+
return
60+
}
61+
activity.lifecycleScope.launch(Dispatchers.Main.immediate) {
62+
if (rewardedAd != null) {
63+
var userEarnedReward = false
64+
65+
// Set up the full-screen callback BEFORE showing
66+
rewardedAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
67+
override fun onAdDismissedFullScreenContent() {
68+
Log.d(TAG, "Ad was dismissed.")
69+
rewardedAd = null
70+
71+
// Only invoke callback if user actually earned the reward
72+
if (userEarnedReward) {
73+
callback.invoke()
74+
}
75+
76+
// Load next ad
77+
loadAd(activity)
78+
}
79+
80+
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
81+
Log.d(TAG, "Ad failed to show: ${adError.message}")
82+
rewardedAd = null
83+
loadAd(activity)
84+
}
85+
86+
override fun onAdShowedFullScreenContent() {
87+
Log.d(TAG, "Ad showed fullscreen content.")
88+
}
89+
}
90+
91+
// Show the ad with reward listener
92+
rewardedAd?.show(activity) { rewardItem ->
93+
Log.d(TAG, "User earned the reward: ${rewardItem.amount} ${rewardItem.type}")
94+
userEarnedReward = true
95+
// Don't call callback here - wait for onAdDismissedFullScreenContent
96+
}
97+
} else {
98+
Log.d(TAG, "Ad not ready, loading a new one...")
99+
loadAd(activity)
100+
}
101+
}
102+
}

app/src/main/java/com/rk/taskmanager/screens/Resources.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import com.patrykandpatrick.vico.core.common.component.TextComponent
3838
import com.patrykandpatrick.vico.core.common.shader.ShaderProvider
3939
import com.rk.components.SettingsToggle
4040
import com.rk.components.rememberMarker
41+
import com.rk.taskmanager.MainActivity
42+
import com.rk.taskmanager.SettingsRoutes
4143
import com.rk.taskmanager.TaskManager
4244
import kotlinx.coroutines.Dispatchers
4345
import kotlinx.coroutines.withContext
@@ -122,7 +124,7 @@ suspend fun updateRamAndSwapGraph(usagePercent: Int, usageBytes: Long, totalByte
122124

123125

124126
// Update chart model with both lines
125-
if (selectedscreen.intValue == 0) {
127+
if (selectedscreen.intValue == 0 && MainActivity.instance?.navControllerRef?.get()?.currentDestination?.route == SettingsRoutes.Home.route) {
126128
RamModelProducer.runTransaction {
127129
lineSeries {
128130
series(x = xValues, y = ramYValues) // RAM line
@@ -141,7 +143,7 @@ suspend fun updateCpuGraph(usage: Int) {
141143
cpuYValues.removeFirst()
142144
cpuYValues.addLast(CpuUsage)
143145

144-
if (selectedscreen.intValue == 0) {
146+
if (selectedscreen.intValue == 0 && MainActivity.instance?.navControllerRef?.get()?.currentDestination?.route == SettingsRoutes.Home.route) {
145147
CpuModelProducer.runTransaction {
146148
lineSeries {
147149
series(x = xValues, y = cpuYValues)

0 commit comments

Comments
 (0)