Skip to content
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

Feature/about kotlin #1122

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import com.github.spotbugs.snom.SpotBugsTask
plugins {
id 'com.android.application'
id 'com.github.spotbugs'
id 'org.jetbrains.kotlin.android'
}

spotbugs {
Expand Down Expand Up @@ -127,3 +128,7 @@ tasks.withType(SpotBugsTask) {
html.enabled = true
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions.jvmTarget = "11"
}
99 changes: 0 additions & 99 deletions app/src/main/java/protect/card_locker/AboutActivity.java

This file was deleted.

102 changes: 102 additions & 0 deletions app/src/main/java/protect/card_locker/AboutActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package protect.card_locker

import android.os.Bundle
import android.view.MenuItem
import android.view.View
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import protect.card_locker.databinding.AboutActivityBinding

class AboutActivity : CatimaAppCompatActivity() {
private var binding: AboutActivityBinding? = null
private var content: AboutContent? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = AboutActivityBinding.inflate(layoutInflater)
.also { this.binding = it }
val content = AboutContent(this)
.also { this.content = it }
Comment on lines +15 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what this does or link me to a good resource explaining it? I'm pretty new to Kotlin and the explanations I'm finding online don't really explain this well to me. Given I will have to maintain this code, I need to understand what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basicly, it will be the instance of the object. https://kotlinlang.org/docs/scope-functions.html#also

producing an instance has 'also' the sideeffect that the field variable is set.
coupling things

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so:

Call AboutContent's constructor and assign whatever it gives back to the variable content. Then set this.content to the newly created content variable. Right?

I don't quite understand why that's cleaner than just directly doing:

this.content = AboutContent(this)

though. Is this some kind of best practice I don't know about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to use a not nullable variable. in the this scope it is nullable. You would unnecessarily check if it null, after instantiating


title = content.pageTitle

setContentView(binding.root)
setSupportActionBar(binding.toolbar)
enableToolbarBackButton()

val copyright = binding.creditsSub
copyright.text = content.copyright
val versionHistory = binding.versionHistorySub
versionHistory.text = content.versionHistory

binding.versionHistory.tag = "https://catima.app/changelog/"
binding.translate.tag = "https://hosted.weblate.org/engage/catima/"
binding.license.tag = "https://github.com/CatimaLoyalty/Android/blob/master/LICENSE"
binding.repo.tag = "https://github.com/CatimaLoyalty/Android/"
binding.privacy.tag = "https://catima.app/privacy-policy/"
binding.reportError.tag = "https://github.com/CatimaLoyalty/Android/issues"
binding.rate.tag = "https://play.google.com/store/apps/details?id=me.hackerchick.catima"

bindClickListeners()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId
if (id == android.R.id.home) {
finish()
}
return super.onOptionsItemSelected(item)
}

override fun onDestroy() {
super.onDestroy()
content?.destroy()
content = null
clearClickListeners()
binding = null
}

private fun bindClickListeners() {
val binding = binding ?: return
TheLastProject marked this conversation as resolved.
Show resolved Hide resolved

val openExternalBrowser = View.OnClickListener { view: View ->
val tag = view.tag
if (tag is String && tag.startsWith("https://")) {
OpenWebLinkHandler().openBrowser(this, tag)
}
}

binding.versionHistory.setOnClickListener(openExternalBrowser)
binding.translate.setOnClickListener(openExternalBrowser)
binding.license.setOnClickListener(openExternalBrowser)
binding.repo.setOnClickListener(openExternalBrowser)
binding.privacy.setOnClickListener(openExternalBrowser)
binding.reportError.setOnClickListener(openExternalBrowser)
binding.rate.setOnClickListener(openExternalBrowser)
binding.credits.setOnClickListener { showCredits() }
}

private fun clearClickListeners() {
val binding = binding ?: return
binding.versionHistory.setOnClickListener(null)
binding.translate.setOnClickListener(null)
binding.license.setOnClickListener(null)
binding.repo.setOnClickListener(null)
binding.privacy.setOnClickListener(null)
binding.reportError.setOnClickListener(null)
binding.rate.setOnClickListener(null)
binding.credits.setOnClickListener(null)
}

private fun showCredits() {
val content = content ?: return
TheLastProject marked this conversation as resolved.
Show resolved Hide resolved
MaterialAlertDialogBuilder(this)
.setTitle(R.string.credits)
.setMessage(content.contributorInfo)
.setPositiveButton(R.string.ok, null)
.show()
}

companion object {
private const val TAG = "Catima"
}
}
111 changes: 0 additions & 111 deletions app/src/main/java/protect/card_locker/AboutContent.java

This file was deleted.

Loading