Skip to content

Commit

Permalink
native ads added with google templates
Browse files Browse the repository at this point in the history
  • Loading branch information
VolgoAK committed Aug 24, 2019
1 parent 336a84f commit c7d3b6d
Show file tree
Hide file tree
Showing 23 changed files with 1,253 additions and 45 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.attiladroid.shlypa"
minSdkVersion 18
minSdkVersion 21
targetSdkVersion 28
versionCode 23
versionName "1.1.42"
Expand Down Expand Up @@ -44,6 +44,7 @@ ext {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(project(':nativetemplates'))
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Expand All @@ -53,11 +54,11 @@ dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"

//firebase
implementation "com.google.firebase:firebase-core:17.1.0"
implementation 'com.google.android.gms:play-services-ads:18.1.1'
implementation "com.google.android.gms:play-services-ads:$google_ads_version"
//implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
implementation "com.google.firebase:firebase-messaging:20.0.0"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/sergey/shlypa2/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.sergey.shlypa2

import androidx.multidex.MultiDexApplication
import android.app.Application
import cat.ereza.customactivityoncrash.config.CaocConfig
import com.crashlytics.android.Crashlytics
import com.example.sergey.shlypa2.di.appModule
Expand All @@ -18,7 +18,7 @@ import timber.log.Timber
/**
* Created by alex on 4/4/18.
*/
class App : MultiDexApplication() {
class App : Application() {


override fun onCreate() {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/sergey/shlypa2/ads/AdsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.content.Context
import android.os.Bundle
import com.example.sergey.shlypa2.extensions.debug
import com.google.ads.mediation.admob.AdMobAdapter
import com.google.android.gms.ads.AdLoader
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.formats.UnifiedNativeAd
import org.json.JSONObject
import timber.log.Timber

Expand Down Expand Up @@ -78,6 +80,18 @@ class AdsManager(
}
}

fun getNativeAd(context: Context, onLoaded: (UnifiedNativeAd) -> Unit): AdLoader? {
val request = buildRequest() ?: return null
val loader = AdLoader.Builder(context, NATIVE_TEST_ID)
.forUnifiedNativeAd { nativeAd ->
onLoaded.invoke(nativeAd)
}
.build()

loader.loadAd(request)
return loader
}

/**
* Creates ad request if showing ads is allowed by the consentManager
* otherwise returns null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,29 @@ package com.example.sergey.shlypa2.screens.features_testing


import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.motion.widget.MotionScene
import com.bumptech.glide.Glide
import androidx.fragment.app.Fragment
import com.example.sergey.shlypa2.R
import com.example.sergey.shlypa2.extensions.onTransitionCompletedOnce
import com.example.sergey.shlypa2.utils.Functions
import com.flurry.sdk.t
import kotlinx.android.synthetic.main.activity_game_result.*
import kotlinx.android.synthetic.main.fragment_game.*
import kotlinx.android.synthetic.main.fragment_game.view.*
import kotlinx.android.synthetic.main.fragment_round_start.*
import kotlinx.android.synthetic.main.fragment_rules.*

import org.koin.androidx.viewmodel.ext.android.viewModel
import com.example.sergey.shlypa2.ads.AdsManager
import kotlinx.android.synthetic.main.fragment_testing.*
import org.koin.android.ext.android.inject


class MotionTestFragment : Fragment() {

private val adsManager by inject<AdsManager>()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_round_start, container, false)
return inflater.inflate(R.layout.fragment_testing, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//tv_winner.text = "Good guys"
tvRoundName.text = "First round"
tvRoundRules.text =
"""Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|Suspendisse nisl massa, scelerisque at ex congue, congue fringilla magna.
|Cras viverra enim non neque commodo pretium. Suspendisse dictum lectus libero,
|ut ultrices mi ornare non. Aliquam erat volutpat. Maecenas venenatis at sem ac vestibulum.
""".trimMargin()
Glide.with(this)
.load(Functions.imageNameToUrl("round_avatars/silence.png"))
.into(civRulesAvatar)

/*rootGame.setTransition(R.id.start, R.id.end)
rootGame.transitionToEnd()
rootGame.onTransitionCompletedOnce {
tvGuideLabel.setText(R.string.skip)
rootGame.setTransition(R.id.start, R.id.endSkip)
rootGame.transitionToEnd()
}*/
adsManager.getNativeAd(requireContext()) {
my_template.setNativeAd(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import com.example.sergey.shlypa2.extensions.extraNotNull
import com.example.sergey.shlypa2.extensions.observeSafe
import com.example.sergey.shlypa2.extensions.selectTheme
import com.example.sergey.shlypa2.extensions.setThemeApi21
import com.example.sergey.shlypa2.screens.features_testing.MotionTestFragment
import com.example.sergey.shlypa2.screens.main.pages.LoadStateFragment
import com.example.sergey.shlypa2.screens.main.pages.RulesFragment
import com.example.sergey.shlypa2.screens.main.pages.WelcomeFragment
import com.example.sergey.shlypa2.screens.players.PlayersActivity
import com.example.sergey.shlypa2.screens.settings.SettingsActivity
Expand Down Expand Up @@ -137,8 +137,8 @@ class FirstActivity : AppCompatActivity() {
}

private fun startRulesFragment() {
val fragment = RulesFragment()
// val fragment = MotionTestFragment()
// val fragment = RulesFragment()
val fragment = MotionTestFragment()
supportFragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/fragment_testing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<com.google.android.ads.nativetemplates.TemplateView
android:id="@+id/my_template"
app:gnt_template_type="@layout/gnt_medium_template_view"
android:layout_width="match_parent"
android:layout_height="500dp" />

</LinearLayout>
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

buildscript {
ext.kotlin_version = '1.3.21'
ext.google_ads_version = '18.1.1'
ext.constraint_layout_version = '2.0.0-beta2'
repositories {
google()
jcenter()
Expand Down
39 changes: 39 additions & 0 deletions nativetemplates/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26

defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pgcfg'
consumerProguardFiles 'proguard-rules.pgcfg'
}
}

lintOptions {
resourcePrefix 'gnt_'
}
}



dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
implementation "com.google.android.gms:play-services-ads:$google_ads_version"
}
22 changes: 22 additions & 0 deletions nativetemplates/proguard-rules.pgcfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep,includedescriptorclasses public class com.google.android.ads.nativetemplates { *; }
Loading

0 comments on commit c7d3b6d

Please sign in to comment.