Skip to content

Commit

Permalink
Add android application with onCreate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Oct 7, 2023
1 parent 1c13457 commit 00bb277
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

<application
android:name=".GotifyApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/kotlin/com/github/gotify/GotifyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.gotify

import android.app.Application
import android.app.NotificationManager
import android.os.Build
import androidx.preference.PreferenceManager
import com.github.gotify.log.LoggerHelper
import com.github.gotify.log.UncaughtExceptionHandler
import com.github.gotify.settings.ThemeHelper
import org.tinylog.kotlin.Logger

class GotifyApplication : Application() {
override fun onCreate() {
LoggerHelper.init(this)
Logger.info("${javaClass.simpleName}: onCreate")

val theme = PreferenceManager.getDefaultSharedPreferences(this)
.getString(getString(R.string.setting_key_theme), getString(R.string.theme_default))!!
ThemeHelper.setTheme(this, theme)
UncaughtExceptionHandler.registerCurrentThread()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationSupport.createForegroundChannel(
this,
this.getSystemService(NotificationManager::class.java)
)
}

super.onCreate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.github.gotify.init

import android.Manifest
import android.app.AlarmManager
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
Expand All @@ -13,8 +11,6 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.preference.PreferenceManager
import com.github.gotify.NotificationSupport
import com.github.gotify.R
import com.github.gotify.Settings
import com.github.gotify.api.ApiException
Expand All @@ -23,12 +19,9 @@ import com.github.gotify.api.Callback.SuccessCallback
import com.github.gotify.api.ClientFactory
import com.github.gotify.client.model.User
import com.github.gotify.client.model.VersionInfo
import com.github.gotify.log.LoggerHelper
import com.github.gotify.log.UncaughtExceptionHandler
import com.github.gotify.login.LoginActivity
import com.github.gotify.messages.MessagesActivity
import com.github.gotify.service.WebSocketService
import com.github.gotify.settings.ThemeHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.livinglifetechway.quickpermissionskotlin.runWithPermissions
import com.livinglifetechway.quickpermissionskotlin.util.QuickPermissionsOptions
Expand All @@ -48,18 +41,6 @@ internal class InitializationActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
LoggerHelper.init(this)
val theme = PreferenceManager.getDefaultSharedPreferences(this)
.getString(getString(R.string.setting_key_theme), getString(R.string.theme_default))!!
ThemeHelper.setTheme(this, theme)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationSupport.createForegroundChannel(
this,
(this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
)
}
UncaughtExceptionHandler.registerCurrentThread()
settings = Settings(this)
Logger.info("Entering ${javaClass.simpleName}")

Expand Down

0 comments on commit 00bb277

Please sign in to comment.