Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Commit 359c44d

Browse files
committed
Minor fix and easy reload of ads
1 parent 4b6c9c3 commit 359c44d

File tree

15 files changed

+286
-141
lines changed

15 files changed

+286
-141
lines changed

.README.md.swp

24 KB
Binary file not shown.

Firebase/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ dependencies {
3737

3838
implementation platform('com.google.firebase:firebase-bom:29.0.0')
3939

40-
implementation 'com.google.firebase:firebase-analytics-ktx'
40+
implementation 'com.google.firebase:firebase-analytics-ktx:20.0.0'
41+
implementation 'com.google.firebase:firebase-installations-ktx:17.0.0'
42+
4143
implementation 'androidx.work:work-runtime-ktx:2.7.0'
4244

4345
implementation 'androidx.core:core-ktx:1.3.2'
@@ -46,4 +48,4 @@ dependencies {
4648
testImplementation 'junit:junit:4.+'
4749
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4850
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
49-
}
51+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.frogsquare.firebase
2+
3+
object Common {
4+
5+
const val RC_GOOGLE: Int = 0x0004
6+
const val RC_FACEBOOK: Int = 0x0005
7+
8+
const val INTENT_REQUEST_ID: Int = 0x0006
9+
const val NOTIFICATION_REQUEST_ID: Int = 0x0007
10+
11+
const val PROGRESS_NOTIFICATION_ID: Int = 0x0008
12+
const val COMPLETE_NOTIFICATION_ID: Int = 0x0009
13+
14+
const val DEFAULT_CHANNEL_ID: String = "default"
15+
const val SHARED_PREFERENCE_NAME: String = "GDFirebase.sharedPreferences"
16+
}

Firebase/src/main/kotlin/com/frogsquare/firebase/Firebase.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import com.google.firebase.analytics.FirebaseAnalytics.Event.*
2222
import com.google.firebase.analytics.FirebaseAnalytics.Param.*
2323
import com.google.firebase.analytics.ktx.analytics
2424
import com.google.firebase.analytics.ktx.logEvent
25+
import com.google.firebase.installations.ktx.installations
2526
import com.google.firebase.ktx.Firebase
2627
import com.google.firebase.ktx.app
28+
import org.godotengine.godot.plugin.SignalInfo
2729
import java.util.concurrent.TimeUnit
2830

2931
private const val TAG: String = "GDFirebase"
@@ -49,7 +51,7 @@ class GDFirebase constructor(godot: Godot): GodotPlugin(godot) {
4951

5052
init {
5153
preferences = myContext.getSharedPreferences(
52-
Utils.SHARED_PREFERENCE_NAME,
54+
Common.SHARED_PREFERENCE_NAME,
5355
Context.MODE_PRIVATE
5456
)
5557

@@ -287,6 +289,13 @@ class GDFirebase constructor(godot: Godot): GodotPlugin(godot) {
287289
}
288290
}
289291

292+
@UsedByGodot
293+
fun requestInstallationId() {
294+
Firebase.installations.id.addOnSuccessListener { id ->
295+
emitSignal("installation_id", id)
296+
}
297+
}
298+
290299
@UsedByGodot
291300
fun share(text: String, subject: String) {
292301
val intent = Intent()
@@ -298,7 +307,10 @@ class GDFirebase constructor(godot: Godot): GodotPlugin(godot) {
298307
}
299308

300309
intent.type = "text/plain"
301-
activity?.startActivity(intent)
310+
311+
runOnUiThread {
312+
activity?.startActivity(intent)
313+
}
302314
}
303315

304316
private fun transaction(event: String, params: Dictionary) {
@@ -337,6 +349,12 @@ class GDFirebase constructor(godot: Godot): GodotPlugin(godot) {
337349
}
338350
}
339351

352+
override fun getPluginSignals(): MutableSet<SignalInfo> {
353+
return mutableSetOf(
354+
SignalInfo("installation_id", String::class.javaObjectType)
355+
)
356+
}
357+
340358
override fun getPluginName(): String {
341359
return "GDFirebase"
342360
}

Firebase/src/main/kotlin/com/frogsquare/firebase/Notifications.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import androidx.core.app.NotificationCompat
1414
import org.godotengine.godot.Dictionary
1515

1616
private const val TAG: String = "GDFirebase"
17-
private const val NOTIFICATION_REQUEST_ID = 8001
1817

1918
object Notifications {
2019
@JvmStatic
@@ -29,7 +28,7 @@ object Notifications {
2928

3029
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
3130
val notificationChannel = NotificationChannel(
32-
channelId ?: Utils.DEFAULT_CHANNEL_ID,
31+
channelId ?: Common.DEFAULT_CHANNEL_ID,
3332
"${channelId ?: "Base"} Notifications",
3433
NotificationManager.IMPORTANCE_DEFAULT
3534
)
@@ -41,7 +40,7 @@ object Notifications {
4140
val notificationIconId = Utils.getMipmapID(context, "notification_icon")
4241
val icon = BitmapFactory.decodeResource(context.resources, iconId)
4342

44-
val builder = NotificationCompat.Builder(context, channelId ?: Utils.DEFAULT_CHANNEL_ID)
43+
val builder = NotificationCompat.Builder(context, channelId ?: Common.DEFAULT_CHANNEL_ID)
4544
.setDefaults(Notification.DEFAULT_ALL)
4645
.setSmallIcon(if (notificationIconId <= 0) iconId else notificationIconId)
4746
.setLargeIcon(icon)
@@ -84,11 +83,11 @@ object Notifications {
8483
builder.color = it as Int
8584
}
8685

87-
manager.notify(NOTIFICATION_REQUEST_ID, builder.build())
86+
manager.notify(Common.NOTIFICATION_REQUEST_ID, builder.build())
8887
}
8988

9089
@JvmStatic
9190
@Suppress("UNUSED", "UNUSED_PARAMETER")
9291
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
9392
fun showNotificationInTime(context: Context, params: Dictionary, delay: Long) {}
94-
}
93+
}

Firebase/src/main/kotlin/com/frogsquare/firebase/Utils.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ import java.net.MalformedURLException
2121
import java.net.URL
2222
import java.io.*
2323

24-
private const val INTENT_REQUEST_ID = 6001
2524

2625
@Suppress("UNUSED")
2726
object Utils {
28-
const val SHARED_PREFERENCE_NAME: String = "GDFirebase.sharedPreferences"
29-
const val DEFAULT_CHANNEL_ID: String = "default"
30-
3127
@JvmStatic
3228
fun getXmlID(context: Context, name: String): Int {
3329
return getResourceID(context, name, "xml")
@@ -69,7 +65,7 @@ object Utils {
6965

7066
return PendingIntent.getActivity(
7167
context,
72-
INTENT_REQUEST_ID,
68+
Common.INTENT_REQUEST_ID,
7369
intent,
7470
PendingIntent.FLAG_UPDATE_CURRENT
7571
)
@@ -120,7 +116,10 @@ object Utils {
120116

121117
@JvmStatic
122118
fun loadPreferences(context: Context, params: Dictionary) {
123-
val prefs = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE)
119+
val prefs = context.getSharedPreferences(
120+
Common.SHARED_PREFERENCE_NAME,
121+
Context.MODE_PRIVATE
122+
)
124123
val prefsEditor = prefs.edit()
125124

126125
for (pair in params) {
@@ -152,7 +151,7 @@ object Utils {
152151
fun createDefaultChannel(manager: NotificationManager) {
153152
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
154153
val channel = NotificationChannel(
155-
DEFAULT_CHANNEL_ID,
154+
Common.DEFAULT_CHANNEL_ID,
156155
"Default",
157156
NotificationManager.IMPORTANCE_DEFAULT
158157
)
@@ -180,6 +179,21 @@ object Utils {
180179
return ret
181180
}
182181

182+
@JvmStatic
183+
fun dictionaryToJson(data: Dictionary): JSONObject {
184+
val json = JSONObject()
185+
186+
try {
187+
for (pair in data) {
188+
json.put(pair.key, pair.value)
189+
}
190+
} catch (e: JSONException) {
191+
Log.e("GDFirebase", "JSON Exception ${e.message}\n"+Log.getStackTraceString(e))
192+
}
193+
194+
return json
195+
}
196+
183197
@JvmStatic
184198
fun readFromFile(context: Context, path: String): String {
185199
var filepath = path
@@ -217,4 +231,4 @@ object Utils {
217231

218232
return ret.toString()
219233
}
220-
}
234+
}

0 commit comments

Comments
 (0)