Kotlin Coding Practices
See original GitHub issueI’m glad to see that you guys have moved onto Kotlin, but a lot of the code still adopts a Java like structure. There are a few things I’m going to bring up for you to consider:
All links are based on the latest commit as of this issue
Why wrap constants in a singleton object? You can just add the values directly on the top level and also add the const
keyword so that they are truly constants added where it is used in the byte code.
if (piracyChecker != null) piracyChecker!!.start()
should be
privacyChecker?.start()
Embrace the null operation rather than enforcing non nulls due to using var
The privacy checker as a whole probably shouldn’t be nullable. Just instantiate it lazily so its not done when the check is disabled.
- System Information
fun checkNetworkConnection(): Boolean? {
var isConnected = false
try {
val process = Runtime.getRuntime().exec("ping -c 1 www.google.com")
val returnVal = process.waitFor()
isConnected = returnVal == 0
} catch (e: Exception) {
// Suppress error
}
return isConnected
}
You can make this return a nonnull Boolean. At the same time, this has an O(1) retrieval time and no parameters. Kotlin’s guidelines would suggest you use the var get() syntax but that is up to you. You also probably shouldn’t use something like this to begin with especially if it is in the ui thread, but I didn’t look any further into it.
A whole bunch of the other functions here all require Context, so use extension functions. And furthermore, none of these should be wrapped in a singleton
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
I’ll close this issue for now and list whatever things I either don’t get or might be wrong. I’ll submit a PR later for small functions that can be changed without ambiguity.
@nicholaschum Okay I’ll try to make time to push something later today. A few things to note:
Your main purpose for this library is to be able to send an intent for Substratum. Recently (or since last time I checked) you’ve added a bunch of other intents, presumably to help against privacy. I’m not sure if they’re implemented yet so unless there is more info I won’t be adding it.
As for the class, it’s really only meant to launch a function, so I’m going to create an extension function which you’ll see later. I’d say that the majority of themers have their custom ui anyways, so having the extension would make it easier to integrate.
Whether you’d also consider adding a simple UI class as another activity is up to you.