Skip to content

Commit

Permalink
v7.7 (#57)
Browse files Browse the repository at this point in the history
* Add i-mobile ads SDK

* Manage properties

* Add banner view

* Add interstitial view

* Specify adjust option

* Update version

* Fix ads display

* Update version
  • Loading branch information
aqua-ix authored Jun 12, 2023
1 parent c365512 commit b1d3b5e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 22 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "comviewaquahp.google.sites.youbimiku"
minSdkVersion 21
targetSdkVersion 33
versionCode 25
versionName "7.5"
versionCode 27
versionName "7.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
packagingOptions {
Expand All @@ -24,10 +24,12 @@ android {
buildTypes {
debug {
minifyEnabled false
manifestPlaceholders = [ imobile_Testing: "true" ]
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [ imobile_Testing: "false" ]
}
}
productFlavors {
Expand Down Expand Up @@ -83,6 +85,9 @@ dependencies {
implementation platform('com.google.firebase:firebase-bom:31.2.2')
implementation 'com.google.firebase:firebase-config-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'

implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation files('libs/imobileSdkAds.jar')
}

secrets {
Expand Down
Binary file added app/libs/imobileSdkAds.jar
Binary file not shown.
14 changes: 10 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID "/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".Application"
Expand All @@ -11,12 +12,17 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fullBackupContent="true">
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="${gmsAppId}" />
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="i-mobile_Testing"
android:value="${imobile_Testing}" />
<meta-data
android:name="i-mobile_DebugLogging"
android:value="${imobile_Testing}" />

<activity
android:name=".MainActivity"
Expand Down
78 changes: 70 additions & 8 deletions app/src/main/java/com/aqua_ix/youbimiku/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.*
import android.widget.FrameLayout
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -17,16 +16,21 @@ import com.aallam.openai.api.chat.ChatMessage
import com.aallam.openai.api.chat.ChatRole
import com.aallam.openai.api.model.ModelId
import com.aallam.openai.client.OpenAI
import com.aqua_ix.youbimiku.BuildConfig.*
import com.aqua_ix.youbimiku.config.*
import com.aqua_ix.youbimiku.databinding.ActivityMainBinding
import com.github.bassaer.chatmessageview.model.Message
import com.google.android.play.core.review.ReviewManagerFactory
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import com.aqua_ix.youbimiku.databinding.ActivityMainBinding
import jp.co.imobile.sdkads.android.FailNotificationReason
import jp.co.imobile.sdkads.android.ImobileSdkAd
import jp.co.imobile.sdkads.android.ImobileSdkAdListener
import kotlinx.coroutines.*


class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
private lateinit var userAccount: User
private lateinit var mikuAccount: User
Expand All @@ -44,8 +48,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
CoroutineExceptionHandler { value, throwable ->
Log.e(TAG, throwable.message.toString())
}
private val scope =
CoroutineScope(Dispatchers.Default + job + exceptionHandler) // exceptionHandlerを渡す
private val scope = CoroutineScope(Dispatchers.Default + job + exceptionHandler)
var openAITaskJob: Job? = null

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -56,10 +60,12 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
detectIntent = DetectIntent(this, getDialogFlowSession())

initChatView()
initBanner()
initInterstitial()
initRemoteConfig()
showInAppReviewIfNeeded()

openAI = OpenAI(BuildConfig.openAIKey)
openAI = OpenAI(OPENAI_API_KEY)
setup()
}

Expand All @@ -85,6 +91,53 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
binding.chatView.setMessageMaxWidth(640)
}

private fun initBanner() {
if (FLAVOR == "noAds") {
return
}
ImobileSdkAd.registerSpotInline(
this,
IMOBILE_PID,
IMOBILE_MID,
IMOBILE_BANNER_SID
)
ImobileSdkAd.start(IMOBILE_BANNER_SID)

val imobileBannerLayout = FrameLayout(this)
val imobileBannerLayoutParam: FrameLayout.LayoutParams =
FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
)
imobileBannerLayoutParam.gravity = Gravity.TOP or Gravity.CENTER
imobileBannerLayout.visibility = View.INVISIBLE
addContentView(imobileBannerLayout, imobileBannerLayoutParam)
ImobileSdkAd.showAd(this, IMOBILE_BANNER_SID, imobileBannerLayout, true)

val mlp = binding.chatView.layoutParams as ViewGroup.MarginLayoutParams

ImobileSdkAd.setImobileSdkAdListener(IMOBILE_BANNER_SID, object : ImobileSdkAdListener() {
override fun onAdShowCompleted() {
Log.d(TAG, "ImobileSdkAd($IMOBILE_BANNER_SID) onAdReadyCompleted")
imobileBannerLayout.visibility = View.VISIBLE
mlp.topMargin = imobileBannerLayout.height
}
override fun onFailed(reason: FailNotificationReason) {
Log.d(TAG, "ImobileSdkAd($IMOBILE_BANNER_SID) onFailed: $reason")
imobileBannerLayout.visibility = View.INVISIBLE
mlp.topMargin = 0
}
})
}

private fun initInterstitial() {
if (FLAVOR == "noAds") {
return
}
ImobileSdkAd.registerSpotFullScreen(this, IMOBILE_PID, IMOBILE_MID, IMOBILE_INTERSTITIAL_SID)
ImobileSdkAd.start(IMOBILE_INTERSTITIAL_SID)
}

private fun getMikuAccount(): User {
return if (getAIModel(this) == (AIModelConfig.OPEN_AI.name)) {
val face = BitmapFactory.decodeResource(resources, R.drawable.normal)
Expand Down Expand Up @@ -323,8 +376,13 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
when (getAIModel(this)) {
AIModelConfig.OPEN_AI.name ->
scope.launch {
if(openAITaskJob?.isActive == true) {
return@launch
}
openAITaskJob = launch {
openAITask(text)
}
setOpenAIRequestCount(applicationContext, ++count)
openAITask(text)
}
else ->
scope.launch {
Expand All @@ -333,6 +391,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
}

if (count >= remoteConfig.getDouble(RemoteConfigKey.AD_DISPLAY_REQUEST_TIMES)) {
ImobileSdkAd.showAd(this, IMOBILE_INTERSTITIAL_SID)
setOpenAIRequestCount(applicationContext, 0)
}
}
Expand Down Expand Up @@ -411,16 +470,19 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, DialogListener {
}

public override fun onPause() {
ImobileSdkAd.stop(IMOBILE_BANNER_SID)
super.onPause()
}

public override fun onResume() {
ImobileSdkAd.start(IMOBILE_BANNER_SID)
super.onResume()
}

public override fun onDestroy() {
detectIntent.resetContexts()
scope.coroutineContext.cancel()
ImobileSdkAd.activityDestroy()
super.onDestroy()
}

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/aqua_ix/youbimiku/TranslateUtil.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aqua_ix.youbimiku

import com.aqua_ix.youbimiku.R
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
Expand All @@ -10,7 +9,7 @@ class TranslateUtil {
companion object {
fun translateEnToJa(text: String): String {
try {
val url = URL("${BuildConfig.translateEndPoint}?text=$text&target=ja")
val url = URL("${BuildConfig.TRANSLATE_END_POINT}?text=$text&target=ja")
val urlConnection = url.openConnection() as HttpURLConnection
urlConnection.requestMethod = "GET"
urlConnection.connect()
Expand All @@ -29,7 +28,7 @@ class TranslateUtil {

fun translateJaToEn(text: String): String {
try {
val url = URL("${BuildConfig.translateEndPoint}?text=$text&target=en")
val url = URL("${BuildConfig.TRANSLATE_END_POINT}?text=$text&target=en")
val urlConnection = url.openConnection() as HttpURLConnection
urlConnection.requestMethod = "GET"
urlConnection.connect()
Expand Down
11 changes: 6 additions & 5 deletions secrets.defaults.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
gmsAppId=XXXXXXXX
adBannerUnitId=XXXXXXXX
adInterstitialUnitId=XXXXXXXX
translateEndPoint=XXXXXXXX
openAIKey=XXXXXXXX
OPENAI_API_KEY=OPENAI_API_KEY
TRANSLATE_END_POINT=TRANSLATE_END_POINT
IMOBILE_PID=IMOBILE_PID
IMOBILE_MID=IMOBILE_MID
IMOBILE_BANNER_SID=IMOBILE_BANNER_SID
IMOBILE_INTERSTITIAL_SID=IMOBILE_INTERSTITIAL_SID

0 comments on commit b1d3b5e

Please sign in to comment.