-
Notifications
You must be signed in to change notification settings - Fork 816
IDE-101 Refactor CatroidApplication to kotlin #4925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hannesweilharter
wants to merge
17
commits into
Catrobat:develop
Choose a base branch
from
hannesweilharter:IDE-101
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c8e39b3
IDE-101 refactor CatroidApplication to Kotlin
hannesweilharter 1e03d38
IDE-101 refactor CatroidApplication to Kotlin
hannesweilharter a5cc12f
IDE-101 fix warnings and check if issue was resolved
hannesweilharter ab17123
IDE-101 remove unused import
hannesweilharter e722ad7
IDE-101 revert changes
hannesweilharter 00f6bcd
IDE-101 change getAppContext function
hannesweilharter 898fb84
IDE-101 update getAppContext function, remove !!
hannesweilharter 1a3319b
IDE-101 refactor PowerMockUtil back to Java
hannesweilharter 5f9bec7
IDE-101 PowerMockUtil refactoring back to Kotlin with some adaptions,…
hannesweilharter 6ea9d09
IDE-101 fix static analysis warnings
hannesweilharter 5c4f090
IDE-101 small null safety update, update copyright years
hannesweilharter 5a1402b
IDE-101 resolve conflicts with base branch
hannesweilharter c6d0b4e
IDE-101 bring up to date
hannesweilharter ad2dc96
IDE-101 fix warnings
hannesweilharter 7fb5fff
IDE-101 fix warnings and failing tests
hannesweilharter ab9924e
IDE-101 revert unintended changes
hannesweilharter 7830175
IDE-101 implement requested changes
hannesweilharter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 0 additions & 101 deletions
101
catroid/src/main/java/org/catrobat/catroid/CatroidApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,101 +0,0 @@ | ||
| /* | ||
| * Catroid: An on-device visual programming system for Android devices | ||
| * Copyright (C) 2010-2025 The Catrobat Team | ||
| * (<http://developer.catrobat.org/credits>) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * An additional term exception under section 7 of the GNU Affero | ||
| * General Public License, version 3, is available at | ||
| * http://developer.catrobat.org/license_additional_term | ||
| * | ||
| * This program 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 Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package org.catrobat.catroid; | ||
|
|
||
| import android.annotation.TargetApi; | ||
| import android.app.Application; | ||
| import android.content.Context; | ||
| import android.os.Build; | ||
| import android.os.StrictMode; | ||
| import android.util.Log; | ||
|
|
||
| import com.google.android.gms.analytics.GoogleAnalytics; | ||
| import com.google.android.gms.analytics.Tracker; | ||
| import com.huawei.agconnect.AGConnectInstance; | ||
| import com.huawei.agconnect.config.AGConnectServicesConfig; | ||
| import com.huawei.hms.mlsdk.common.MLApplication; | ||
|
|
||
| import org.catrobat.catroid.koin.CatroidKoinHelperKt; | ||
| import org.catrobat.catroid.utils.Utils; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| public class CatroidApplication extends Application { | ||
|
|
||
| private static final String TAG = CatroidApplication.class.getSimpleName(); | ||
|
|
||
| private static Context context; | ||
| public static String defaultSystemLanguage; | ||
|
|
||
| private static GoogleAnalytics googleAnalytics; | ||
| private static Tracker googleTracker; | ||
|
|
||
| @TargetApi(31) | ||
| @Override | ||
| public void onCreate() { | ||
| super.onCreate(); | ||
| Log.d(TAG, "CatroidApplication onCreate"); | ||
| Log.d(TAG, "git commit info: " + BuildConfig.GIT_COMMIT_INFO); | ||
|
|
||
| if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
| StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() | ||
| .detectNonSdkApiUsage() | ||
| .penaltyLog() | ||
| .build()); | ||
| } | ||
|
|
||
| context = getApplicationContext(); | ||
|
|
||
| CatroidKoinHelperKt.start(this, CatroidKoinHelperKt.getMyModules()); | ||
|
|
||
| Utils.fetchSpeechRecognitionSupportedLanguages(this); | ||
|
|
||
| defaultSystemLanguage = Locale.getDefault().toLanguageTag(); | ||
|
|
||
| googleAnalytics = GoogleAnalytics.getInstance(this); | ||
| googleAnalytics.setDryRun(BuildConfig.DEBUG); | ||
|
|
||
| setupHuaweiMobileServices(); | ||
| } | ||
|
|
||
| private void setupHuaweiMobileServices() { | ||
| if (AGConnectInstance.getInstance() == null) { | ||
| AGConnectInstance.initialize(this); | ||
| } | ||
|
|
||
| String apiKey = AGConnectServicesConfig.fromContext(this).getString("client/api_key"); | ||
| MLApplication.getInstance().setApiKey(apiKey); | ||
| } | ||
|
|
||
| public synchronized Tracker getDefaultTracker() { | ||
| if (googleTracker == null) { | ||
| googleTracker = googleAnalytics.newTracker(R.xml.global_tracker); | ||
| } | ||
|
|
||
| return googleTracker; | ||
| } | ||
|
|
||
| public static Context getAppContext() { | ||
| return CatroidApplication.context; | ||
| } | ||
| } | ||
107 changes: 107 additions & 0 deletions
107
catroid/src/main/java/org/catrobat/catroid/CatroidApplication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Catroid: An on-device visual programming system for Android devices | ||
| * Copyright (C) 2010-2026 The Catrobat Team | ||
| * (<http://developer.catrobat.org/credits>) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * An additional term exception under section 7 of the GNU Affero | ||
| * General Public License, version 3, is available at | ||
| * http://developer.catrobat.org/license_additional_term | ||
| * | ||
| * This program 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 Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.catrobat.catroid | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import android.app.Application | ||
| import android.content.Context | ||
| import android.os.Build | ||
| import android.os.StrictMode | ||
| import android.util.Log | ||
| import androidx.annotation.VisibleForTesting | ||
| import com.google.android.gms.analytics.GoogleAnalytics | ||
| import com.google.android.gms.analytics.Tracker | ||
| import com.huawei.agconnect.AGConnectInstance | ||
| import com.huawei.agconnect.config.AGConnectServicesConfig | ||
| import com.huawei.hms.mlsdk.common.MLApplication | ||
| import org.catrobat.catroid.koin.myModules | ||
| import org.catrobat.catroid.koin.start | ||
| import org.catrobat.catroid.utils.Utils | ||
| import java.util.Locale | ||
|
|
||
| open class CatroidApplication : Application() { | ||
|
|
||
| @SuppressLint("VisibleForTests") | ||
| override fun onCreate() { | ||
| super.onCreate() | ||
| Log.d(TAG, "CatroidApplication onCreate") | ||
| Log.d(TAG, "git commit info: " + BuildConfig.GIT_COMMIT_INFO) | ||
|
|
||
| if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
Check warningCode scanning / Android Lint Obsolete SDK_INT Version Check Warning
Unnecessary; SDK_INT is always >= 28
|
||
| StrictMode.setVmPolicy( | ||
| StrictMode.VmPolicy.Builder() | ||
| .detectNonSdkApiUsage() | ||
| .penaltyLog() | ||
| .build() | ||
| ) | ||
| } | ||
|
|
||
| appContext = applicationContext | ||
| start(this, myModules) | ||
|
|
||
| Utils.fetchSpeechRecognitionSupportedLanguages(this) | ||
| defaultSystemLanguage = Locale.getDefault().toLanguageTag() | ||
|
|
||
| googleAnalytics = GoogleAnalytics.getInstance(this) | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| googleAnalytics.setDryRun(BuildConfig.DEBUG) | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| setupHuaweiMobileServices() | ||
| } | ||
|
|
||
| private fun setupHuaweiMobileServices() { | ||
| if (AGConnectInstance.getInstance() == null) { | ||
| AGConnectInstance.initialize(this) | ||
| } | ||
| val apiKey = AGConnectServicesConfig.fromContext(this).getString("client/api_key") | ||
| MLApplication.getInstance().apiKey = apiKey | ||
| } | ||
|
|
||
| @get:Synchronized | ||
| val defaultTracker: Tracker | ||
| @SuppressLint("VisibleForTests") | ||
| get() { | ||
| googleTracker = googleAnalytics.newTracker(R.xml.global_tracker) | ||
| return googleTracker | ||
| } | ||
|
|
||
| companion object { | ||
| private val TAG = CatroidApplication::class.java.simpleName | ||
| private var appContext: Context? = null | ||
| @JvmField | ||
| var defaultSystemLanguage: String? = null | ||
| @SuppressLint("VisibleForTests") | ||
| private lateinit var googleAnalytics: GoogleAnalytics | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| @SuppressLint("VisibleForTests") | ||
| private lateinit var googleTracker: Tracker | ||
|
|
||
| @VisibleForTesting | ||
| @JvmStatic | ||
| fun setAppContextForTesting(context: Context) { | ||
|
harshsomankar123-tech marked this conversation as resolved.
|
||
| appContext = context | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun getAppContext(): Context = appContext ?: throw IllegalStateException("CatroidApplication.appContext not initialized. Ensure onCreate() has been called.") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.