-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35a910d
commit f502c1c
Showing
5 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/coding/meet/unityadsapp/MyRewardedAds.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.coding.meet.unityadsapp | ||
|
||
import android.app.Activity | ||
import com.unity3d.ads.* | ||
|
||
class MyRewardedAds(private val activity: Activity) { | ||
|
||
fun loadRewardedAds(placementId : String){ | ||
UnityAds.load(placementId, object : IUnityAdsLoadListener{ | ||
override fun onUnityAdsAdLoaded(placementId: String?) { | ||
} | ||
|
||
override fun onUnityAdsFailedToLoad( | ||
placementId: String?, | ||
error: UnityAds.UnityAdsLoadError?, | ||
message: String?, | ||
) { | ||
} | ||
}) | ||
} | ||
fun showRewardedAds(placementId : String,afterCodeRewardCoin: () ->Unit ){ | ||
UnityAds.show(activity,placementId, UnityAdsShowOptions(), | ||
object : IUnityAdsShowListener{ | ||
override fun onUnityAdsShowFailure( | ||
placementIds: String?, | ||
error: UnityAds.UnityAdsShowError?, | ||
message: String?, | ||
) { | ||
activity.longToastShow("error = $message") | ||
loadRewardedAds(placementId) | ||
} | ||
|
||
override fun onUnityAdsShowStart(placementId: String?) { | ||
activity.longToastShow("onUnityAdsShowStart") | ||
|
||
} | ||
|
||
override fun onUnityAdsShowClick(placementId: String?) { | ||
activity.longToastShow("onUnityAdsShowClick") | ||
|
||
} | ||
|
||
override fun onUnityAdsShowComplete( | ||
placementIds: String?, | ||
state: UnityAds.UnityAdsShowCompletionState?, | ||
) { | ||
if (state == UnityAds.UnityAdsShowCompletionState.COMPLETED){ | ||
// Reward the user for watching the ad to completion | ||
afterCodeRewardCoin() | ||
}else{ | ||
//Do not reward the user for skipping the ad | ||
activity.longToastShow("Do not reward the user for skipping the ad") | ||
|
||
} | ||
loadRewardedAds(placementId) | ||
} | ||
|
||
}) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/coding/meet/unityadsapp/SharedPreferenceManger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.coding.meet.unityadsapp | ||
|
||
import android.content.Context | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
class SharedPreferenceManger(context: Context) { | ||
private val preference = context.getSharedPreferences( | ||
context.packageName, | ||
AppCompatActivity.MODE_PRIVATE | ||
) | ||
private val editor = preference.edit() | ||
|
||
|
||
private val keyTotalRewardedCoin = "totalRewardedCoin" | ||
|
||
var totalRewardedCoin | ||
get() = preference.getInt(keyTotalRewardedCoin, 0) | ||
set(value) { | ||
editor.putInt(keyTotalRewardedCoin, value) | ||
editor.commit() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters