kiwix / kiwix-android

Kiwix for Android
https://android.kiwix.org
GNU General Public License v3.0
828 stars 444 forks source link

Convert HotspotNotificationManager.java to Kotlin #2324

Closed NullByte08 closed 3 years ago

NullByte08 commented 3 years ago

Is your feature request related to a problem? Please describe.

HotspotNotificationManage class is in Java.

Describe the solution you'd like

convert it to Kotlin

Additional context

Parent issue #1826

Arjupta commented 3 years ago

@macgills can I take up this issue

macgills commented 3 years ago

@NullByte08 are you still working on this?

NullByte08 commented 3 years ago

@macgills I am facing some issues with detekt. Let me post them in a moment.

NullByte08 commented 3 years ago

@macgills

It was showing some Dagger errors before, something like Dagger cannot inject in private fields I changed @field:Inject var notificationManager: NotificationManager, to @set:Inject var notificationManager: NotificationManager,

now it is showing this error. Let me try and rectify these.

Commit failed `0 files committed, 11 files failed to commit: converted HotspotNotificationManager.java to Kotlin Running lint... Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details > Task :buildSrc:compileKotlin UP-TO-DATE > Task :buildSrc:compileJava NO-SOURCE > Task :buildSrc:compileGroovy NO-SOURCE > Task :buildSrc:pluginDescriptors UP-TO-DATE > Task :buildSrc:processResources NO-SOURCE > Task :buildSrc:classes UP-TO-DATE > Task :buildSrc:inspectClassesForKotlinIC UP-TO-DATE > Task :buildSrc:jar UP-TO-DATE > Task :buildSrc:assemble UP-TO-DATE > Task :buildSrc:compileTestKotlin NO-SOURCE > Task :buildSrc:pluginUnderTestMetadata UP-TO-DATE > Task :buildSrc:compileTestJava NO-SOURCE > Task :buildSrc:compileTestGroovy NO-SOURCE > Task :buildSrc:processTestResources NO-SOURCE > Task :buildSrc:testClasses UP-TO-DATE > Task :buildSrc:test NO-SOURCE > Task :buildSrc:validatePlugins UP-TO-DATE > Task :buildSrc:check UP-TO-DATE > Task :buildSrc:build UP-TO-DATE > Configure project :app [directory 'F:\Kiwix\kiwix-android\app\build', directory 'F:\Kiwix\kiwix-android\core\build', directory 'F:\Kiwix\kiwix-android\custom\build'] > Task :app:ktlintAndroidTestDebugSourceSetCheck NO-SOURCE > Task :app:ktlintAndroidTestSourceSetCheck UP-TO-DATE > Task :app:ktlintDebugSourceSetCheck NO-SOURCE > Task :app:ktlintKotlinScriptCheck UP-TO-DATE > Task :app:ktlintMainSourceSetCheck > Task :app:ktlintReleaseSourceSetCheck NO-SOURCE > Task :app:ktlintTestDebugSourceSetCheck NO-SOURCE > Task :app:ktlintTestReleaseSourceSetCheck NO-SOURCE > Task :app:ktlintTestSourceSetCheck UP-TO-DATE > Task :app:ktlintCheck > Task :core:ktlintAndroidTestDebugSourceSetCheck NO-SOURCE > Task :core:ktlintAndroidTestSourceSetCheck NO-SOURCE > Task :core:ktlintDebugSourceSetCheck NO-SOURCE > Task :core:ktlintKotlinScriptCheck UP-TO-DATE > Task :core:ktlintMainSourceSetCheck UP-TO-DATE > Task :core:ktlintReleaseSourceSetCheck NO-SOURCE > Task :core:ktlintTestDebugSourceSetCheck NO-SOURCE > Task :core:ktlintTestReleaseSourceSetCheck NO-SOURCE > Task :core:ktlintTestSourceSetCheck UP-TO-DATE > Task :core:ktlintCheck UP-TO-DATE > Task :custom:ktlintAndroidTestCustomexampleDebugSourceSetCheck NO-SOURCE > Task :custom:ktlintAndroidTestCustomexampleSourceSetCheck NO-SOURCE > Task :custom:ktlintAndroidTestDebugSourceSetCheck NO-SOURCE > Task :custom:ktlintAndroidTestSourceSetCheck NO-SOURCE > Task :custom:ktlintCustomexampleDebugSourceSetCheck NO-SOURCE > Task :custom:ktlintCustomexampleReleaseSourceSetCheck NO-SOURCE > Task :custom:ktlintCustomexampleSourceSetCheck NO-SOURCE > Task :custom:ktlintDebugSourceSetCheck NO-SOURCE > Task :custom:ktlintKotlinScriptCheck UP-TO-DATE > Task :custom:ktlintMainSourceSetCheck UP-TO-DATE > Task :custom:ktlintReleaseSourceSetCheck NO-SOURCE > Task :custom:ktlintTestCustomexampleDebugSourceSetCheck NO-SOURCE > Task :custom:ktlintTestCustomexampleReleaseSourceSetCheck NO-SOURCE > Task :custom:ktlintTestCustomexampleSourceSetCheck NO-SOURCE > Task :custom:ktlintTestDebugSourceSetCheck NO-SOURCE > Task :custom:ktlintTestReleaseSourceSetCheck NO-SOURCE > Task :custom:ktlintTestSourceSetCheck UP-TO-DATE > Task :custom:ktlintCheck UP-TO-DATE > Task :app:detekt Property 'complexity>LongParameterList>threshold' is deprecated. Use 'functionThreshold' and 'constructorThreshold' instead. > Task :core:detekt UP-TO-DATE > Task :custom:detekt UP-TO-DATE > Task :app:copyGitHooks UP-TO-DATE > Task :app:installGitHooks SKIPPED > Task :app:preBuild UP-TO-DATE > Task :app:preDebugBuild UP-TO-DATE > Task :core:copyGitHooks UP-TO-DATE > Task :core:installGitHooks SKIPPED > Task :core:objectboxPrepareBuild UP-TO-DATE > Task :core:preBuild UP-TO-DATE > Task :core:preDebugBuild UP-TO-DATE > Task :core:compileDebugAidl NO-SOURCE > Task :app:compileDebugAidl NO-SOURCE > Task :core:packageDebugRenderscript NO-SOURCE > Task :app:compileDebugRenderscript NO-SOURCE > Task :app:generateDebugBuildConfig UP-TO-DATE > Task :app:writeDebugApplicationId UP-TO-DATE > Task :app:generateSafeArgsDebug UP-TO-DATE > Task :app:generateDebugResValues UP-TO-DATE > Task :app:generateDebugResources UP-TO-DATE > Task :core:generateDebugResValues UP-TO-DATE > Task :app:createDebugCompatibleScreenManifests UP-TO-DATE > Task :core:compileDebugRenderscript NO-SOURCE > Task :core:generateDebugResources UP-TO-DATE > Task :core:packageDebugResources UP-TO-DATE > Task :app:mergeDebugResources UP-TO-DATE > Task :app:extractDeepLinksDebug UP-TO-DATE > Task :core:extractDeepLinksDebug UP-TO-DATE > Task :core:processDebugManifest UP-TO-DATE > Task :app:processDebugManifest > Task :core:compileDebugLibraryResources UP-TO-DATE > Task :core:parseDebugLocalResources UP-TO-DATE > Task :core:generateDebugRFile UP-TO-DATE > Task :app:processDebugResources > Task :core:generateDebugBuildConfig UP-TO-DATE > Task :core:generateDebugR2 UP-TO-DATE > Task :core:generateSafeArgsDebug UP-TO-DATE > Task :core:kaptGenerateStubsDebugKotlin UP-TO-DATE > Task :core:kaptDebugKotlin UP-TO-DATE > Task :core:compileDebugKotlin UP-TO-DATE > Task :core:javaPreCompileDebug UP-TO-DATE > Task :core:compileDebugJavaWithJavac UP-TO-DATE > Task :core:bundleLibCompileToJarDebug UP-TO-DATE > Task :app:javaPreCompileDebug UP-TO-DATE > Task :app:prepareLintJar UP-TO-DATE > Task :core:prepareLintJarForPublish UP-TO-DATE > Task :custom:copyGitHooks UP-TO-DATE > Task :custom:installGitHooks SKIPPED > Task :custom:preBuild UP-TO-DATE > Task :custom:preCustomexampleDebugBuild UP-TO-DATE > Task :custom:compileCustomexampleDebugAidl NO-SOURCE > Task :custom:generateCustomexampleDebugBuildConfig UP-TO-DATE > Task :custom:compileCustomexampleDebugRenderscript NO-SOURCE > Task :custom:writeCustomexampleDebugApplicationId UP-TO-DATE > Task :custom:generateSafeArgsCustomexampleDebug UP-TO-DATE > Task :custom:generateCustomexampleDebugResValues UP-TO-DATE > Task :custom:generateCustomexampleDebugResources UP-TO-DATE > Task :custom:mergeCustomexampleDebugResources UP-TO-DATE > Task :app:kaptGenerateStubsDebugKotlin > Task :custom:createCustomexampleDebugCompatibleScreenManifests UP-TO-DATE > Task :custom:extractDeepLinksCustomexampleDebug UP-TO-DATE > Task :custom:processCustomexampleDebugManifest UP-TO-DATE > Task :custom:javaPreCompileCustomexampleDebug UP-TO-DATE > Task :custom:prepareLintJar UP-TO-DATE > Task :custom:processCustomexampleDebugResources > Task :app:kaptDebugKotlin warning: Supported source version 'RELEASE_6' from annotation processor 'org.jetbrains.kotlin.kapt3.base.ProcessorWrapper' less than -source '1.8'[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: com.yahoo.squidb.processor.ModelSpecProcessor (NON_INCREMENTAL). > Task :custom:kaptGenerateStubsCustomexampleDebugKotlin > Task :custom:kaptCustomexampleDebugKotlin > Task :app:compileDebugKotlin w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (21, 20): 'ProgressDialog' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (75, 31): 'ProgressDialog' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (148, 22): 'ProgressDialog' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (183, 49): Type mismatch: inferred type is ServiceConnection? but ServiceConnection was expected w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (190, 21): Type mismatch: inferred type is ServiceConnection? but ServiceConnection was expected w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (217, 52): 'getColor(Int): Int' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\ZimHostActivity.kt: (225, 52): 'getColor(Int): Int' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\wifihotspot\HotspotNotificationManager.kt: (63, 31): 'constructor Builder(Context!)' is deprecated. Deprecated in Java > Task :app:compileDebugJavaWithJavac F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\wifihotspot\HotspotService.java:37: error: cannot find symbol import static org.kiwix.kiwixmobile.webserver.wifihotspot.HotspotNotificationManager.HOTSPOT_NOTIFICATION_ID; ^ symbol: class HotspotNotificationManager location: package org.kiwix.kiwixmobile.webserver.wifihotspot F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\wifihotspot\HotspotService.java:37: error: static import only from classes and interfaces import static org.kiwix.kiwixmobile.webserver.wifihotspot.HotspotNotificationManager.HOTSPOT_NOTIFICATION_ID; ^ F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\wifihotspot\HotspotService.java:45: error: package HotspotStateReceiver does not exist implements IpAddressCallbacks, HotspotStateReceiver.Callback { ^ F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\wifihotspot\HotspotService.java:57: error: cannot find symbol HotspotNotificationManager hotspotNotificationManager; ^ symbol: class HotspotNotificationManager location: class HotspotService F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\webserver\wifihotspot\HotspotService.java:59: error: cannot find symbol HotspotStateReceiver hotspotStateReceiver; ^ symbol: class HotspotStateReceiver location: class HotspotService F:\Kiwix\kiwix-android\app\build\generated\source\kapt\debug\org\kiwix\kiwixmobile\di\components\DaggerKiwixComponent.java:109: error: cannot find symbol import org.kiwix.kiwixmobile.webserver.wifihotspot.HotspotNotificationManager; ^ symbol: class HotspotNotificationManager location: package org.kiwix.kiwixmobile.webserve ... `
macgills commented 3 years ago

Look around the codebase for other examples when you are having difficulty. In this scenario you may have seen other files with field injection

@Inject
lateinit var myInjectedObject: AnObject

yeah it looks like there are compilation issues to work through. Make sure you test code locally, if you are stuck you can push up code that is non functional but it is not the ideal scenario

NullByte08 commented 3 years ago

@macgills Why does detekt keep picking errors from files I have not even changed?

Commit Error `ask :app:compileDebugKotlin w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\intro\CustomViewPager.kt: (31, 23): '@JvmOverloads' annotation has no effect for methods without default arguments w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\local_file_transfer\WifiDirectManager.kt: (25, 25): 'WpsInfo' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\local_file_transfer\WifiDirectManager.kt: (224, 11): 'setup: Int' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\local_file_transfer\WifiDirectManager.kt: (224, 19): 'WpsInfo' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\local_file_transfer\WifiDirectManager.kt: (224, 27): 'PBC: Int' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\local_file_transfer\adapter\WifiPeerListAdapter.kt: (25, 87): Elvis operator (?:) always returns the left operand of non-nullable type Long w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\main\KiwixMainActivity.kt: (68, 50): Parameter 'controller' is never used, could be renamed to _ w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\main\KiwixMainActivity.kt: (68, 62): Parameter 'destination' is never used, could be renamed to _ w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\main\KiwixMainActivity.kt: (68, 75): Parameter 'arguments' is never used, could be renamed to _ w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\nav\destination\reader\KiwixReaderFragment.kt: (240, 32): Parameter 'zimFileUri' is never used w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\zim_manager\ConnectivityBroadcastReceiver.kt: (35, 53): 'CONNECTIVITY_ACTION: String' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\zim_manager\DefaultLanguageProvider.kt: (27, 37): 'locale: Locale!' is deprecated. Deprecated in Java w: F:\Kiwix\kiwix-android\app\src\main\java\org\kiwix\kiwixmobile\zim_manager\library_view\LibraryFragment.kt: (219, 11): 'requireFragmentManager(): FragmentManager' is deprecated. Deprecated in Java > Task :app:compileDebugJavaWithJavac Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. > Task :app:lintDebug Wrote HTML report to file:///F:/Kiwix/kiwix-android/app/build/reports/lint-results-debug.html Wrote XML report to file:///F:/Kiwix/kiwix-android/app/build/reports/lint-results-debug.xml > Task :app:lintDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:lintDebug'. > Lint found errors in the project; aborting build. Fix the issues identified by lint, or add the following to your build script to proceed with errors: ... android { lintOptions { abortOnError false } } ... Errors found: F:\Kiwix\kiwix-android\app\src\main\res\layout\activity_zim_host.xml:34:`

I have resolved the errors 4-5 times, and every time I try to make a commit it shows new errors in some new files.

macgills commented 3 years ago

detekt is not failing now

* What went wrong: Execution failed for task ':app:lintDebug'. > Lint found errors in the project; aborting build.

most of that output is compiler warnings

gouri-panda commented 3 years ago

@NullByte08 What's your progress on this ticket?

macgills commented 3 years ago

@gouri-panda I assume you want to take this ticket over? There hasn't been activity for 21 days so I am happy enough to reassign

gouri-panda commented 3 years ago

@gouri-panda I assume you want to take this ticket over? There hasn't been activity for 21 days so I am happy enough to reassign

Thank you @macgills