Skip to content

Commit

Permalink
added tapsell ad
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Apr 22, 2023
1 parent cb370a3 commit 47d58b5
Show file tree
Hide file tree
Showing 15 changed files with 415 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
local.properties
/.idea/
/app/release/
/app/src/irMarket/java/io/github/yamin8000/dooz/ad/AdConstants.kt
21 changes: 19 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ android {
applicationId "io.github.yamin8000.dooz"
minSdk 24
targetSdk 33
versionCode 5
versionName "1.0.4"
versionCode 6
versionName "1.0.5"
vectorDrawables {
useSupportLibrary true
}
}

flavorDimensions "version"
productFlavors {
irMarket {
dimension "version"
manifestPlaceholders = [launcherActivity: "io.github.yamin8000.dooz.content.AdMainActivity"]
}

free {
dimension "version"
applicationIdSuffix ".free"
manifestPlaceholders = [launcherActivity: "io.github.yamin8000.dooz.content.FreeMainActivity"]
}
}

buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
Expand All @@ -62,6 +76,7 @@ android {

buildFeatures {
compose true
buildConfig true
}

composeOptions {
Expand Down Expand Up @@ -94,4 +109,6 @@ dependencies {
implementation("androidx.navigation:navigation-compose:$nav_version")
//datastore
implementation("androidx.datastore:datastore-preferences:1.0.0")
//ad
irMarketImplementation("ir.tapsell.plus:tapsell-plus-sdk-android:2.1.8")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Dooz/Dooz.app.main
* FreeMainActivity.kt Copyrighted by Yamin Siahmargooei at 2023/4/22
* FreeMainActivity.kt Last modified at 2023/4/22
* This file is part of Dooz/Dooz.app.main.
* Copyright (C) 2023 Yamin Siahmargooei
*
* Dooz/Dooz.app.main 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.
*
* Dooz/Dooz.app.main 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 Dooz. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yamin8000.dooz.content

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat

class FreeMainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
setContent {
MainNavigation(adContent = { })
}
WindowCompat.setDecorFitsSystemWindows(window, false)
}
}
53 changes: 53 additions & 0 deletions app/src/irMarket/java/io/github/yamin8000/dooz/ad/AdComposables.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Owl/Owl.app.main
* AdComposables.kt Copyrighted by Yamin Siahmargooei at 2023/4/22
* AdComposables.kt Last modified at 2023/4/22
* This file is part of Owl/Owl.app.main.
* Copyright (C) 2023 Yamin Siahmargooei
*
* Owl/Owl.app.main 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.
*
* Owl/Owl.app.main 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 Owl. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yamin8000.dooz.ad

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import io.github.yamin8000.dooz.R

@Composable
fun TapsellAdContent(
modifier: Modifier = Modifier,
onCreated: (ViewGroup) -> Unit,
onUpdate: (ViewGroup) -> Unit
) {
val context = LocalContext.current
Surface {
AndroidView(
modifier = modifier,
update = onUpdate,
factory = {
val view = LayoutInflater.from(context)
.inflate(R.layout.standard_banner, null, false)
.findViewById<ViewGroup>(R.id.standardBanner)
onCreated(view)
view
}
)
}
}
81 changes: 81 additions & 0 deletions app/src/irMarket/java/io/github/yamin8000/dooz/ad/AdHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Owl/Owl.app.main
* AdHelper.kt Copyrighted by Yamin Siahmargooei at 2023/4/22
* AdHelper.kt Last modified at 2023/4/22
* This file is part of Owl/Owl.app.main.
* Copyright (C) 2023 Yamin Siahmargooei
*
* Owl/Owl.app.main 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.
*
* Owl/Owl.app.main 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 Owl. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yamin8000.dooz.ad

import android.app.Activity
import android.view.ViewGroup
import io.github.yamin8000.dooz.util.Utility.log
import ir.tapsell.plus.AdRequestCallback
import ir.tapsell.plus.AdShowListener
import ir.tapsell.plus.TapsellPlus
import ir.tapsell.plus.TapsellPlusBannerType
import ir.tapsell.plus.model.TapsellPlusAdModel
import ir.tapsell.plus.model.TapsellPlusErrorModel
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

object AdHelper {

suspend fun showTapsellAd(
activity: Activity,
adId: String,
adView: ViewGroup?
) = suspendCoroutine<Unit> {
TapsellPlus.showStandardBannerAd(
activity,
adId,
adView,
object : AdShowListener() {
override fun onOpened(tapsellPlusAdModel: TapsellPlusAdModel) {
super.onOpened(tapsellPlusAdModel)
log(tapsellPlusAdModel.responseId)
}

override fun onError(tapsellPlusErrorModel: TapsellPlusErrorModel) {
super.onError(tapsellPlusErrorModel)
log(tapsellPlusErrorModel.errorMessage)
}
})
}

suspend fun requestTapsellAd(
activity: Activity
) = suspendCancellableCoroutine { cancellableContinuation ->
TapsellPlus.requestStandardBannerAd(
activity,
AdConstants.STANDARD_BANNER_ZONE_ID,
TapsellPlusBannerType.BANNER_320x50,
object : AdRequestCallback() {
override fun response(ad: TapsellPlusAdModel?) {
super.response(ad)
cancellableContinuation.resume(ad?.responseId ?: "")
}

override fun error(error: String?) {
super.error(error)
log(error ?: "Unknown Tapsell Ad Request error")
}
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Dooz/Dooz.app.main
* AdMainActivity.kt Copyrighted by Yamin Siahmargooei at 2023/4/22
* AdMainActivity.kt Last modified at 2023/4/22
* This file is part of Dooz/Dooz.app.main.
* Copyright (C) 2023 Yamin Siahmargooei
*
* Dooz/Dooz.app.main 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.
*
* Dooz/Dooz.app.main 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 Dooz. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yamin8000.dooz.content

import android.os.Bundle
import android.view.ViewGroup
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import io.github.yamin8000.dooz.ad.AdConstants
import io.github.yamin8000.dooz.ad.AdHelper
import io.github.yamin8000.dooz.ad.TapsellAdContent
import io.github.yamin8000.dooz.util.Utility.log
import ir.tapsell.plus.TapsellPlus
import ir.tapsell.plus.TapsellPlusInitListener
import ir.tapsell.plus.model.AdNetworkError
import ir.tapsell.plus.model.AdNetworks

class AdMainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
initTapsellAd()
setContent {
MainNavigation(adContent = { AdContent() })
}
WindowCompat.setDecorFitsSystemWindows(window, false)
}


@Composable
fun AdContent() {
var adView by remember { mutableStateOf<ViewGroup?>(null) }
var adId: String by remember { mutableStateOf("") }

LaunchedEffect(Unit) {
adId = AdHelper.requestTapsellAd(this@AdMainActivity)
AdHelper.showTapsellAd(this@AdMainActivity, adId, adView)
}

TapsellAdContent(
modifier = Modifier
.wrapContentHeight()
.padding(4.dp)
.fillMaxWidth(),
onCreated = { adView = it },
onUpdate = { adView = it }
)
}

private fun initTapsellAd() {
log("ad init")
TapsellPlus.initialize(this, AdConstants.TAPSELL_KEY, object : TapsellPlusInitListener {
override fun onInitializeSuccess(ads: AdNetworks?) {
log(ads?.name ?: "Unknown ad name")
}

override fun onInitializeFailed(ads: AdNetworks?, error: AdNetworkError?) {
log(error?.errorMessage ?: "Unknown tapsell init error")
}
})
}
}
27 changes: 27 additions & 0 deletions app/src/irMarket/res/layout/standard_banner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Dooz/Dooz.app.main
~ standard_banner.xml Copyrighted by Yamin Siahmargooei at 2023/4/22
~ standard_banner.xml Last modified at 2023/4/22
~ This file is part of Dooz/Dooz.app.main.
~ Copyright (C) 2023 Yamin Siahmargooei
~
~ Dooz/Dooz.app.main 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.
~
~ Dooz/Dooz.app.main 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 Dooz. If not, see <https://www.gnu.org/licenses/>.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/standardBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" />
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".content.App"
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/Theme.App.Starting"
android:windowSoftInputMode="adjustResize"
tools:targetApi="s">
<activity
android:name=".content.MainActivity"
android:name="${launcherActivity}"
android:configChanges="locale|fontScale|orientation|screenSize|keyboardHidden|keyboard|locale|screenLayout|screenSize|layoutDirection"
android:exported="true"
android:theme="@style/Theme.App.Starting">
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/io/github/yamin8000/dooz/content/About.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ fun AboutContent(onBackClick: () -> Unit) {
Alignment.CenterHorizontally
)
) {
PersianText(stringResource(R.string.version_name))
val version = stringResource(R.string.version_name)
PersianText("$version - ${BuildConfig.FLAVOR}")
PersianText(BuildConfig.VERSION_NAME)
}
PersianText(
Expand Down
Loading

0 comments on commit 47d58b5

Please sign in to comment.