-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
pfaffenrodt
wants to merge
15
commits into
CatimaLoyalty:main
Choose a base branch
from
pfaffenrodt:feature/about-kotlin
base: main
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
Feature/about kotlin #1122
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
453adab
Enable kotlin compiler
pfaffenrodt 046b65a
Rename .java to .kt
pfaffenrodt 5ce7d1f
AboutContent auto convert to kotlin
pfaffenrodt 820b787
Optimize Kotlin code.
pfaffenrodt 4b6806d
Rename .java to .kt
pfaffenrodt 82d0160
OpenWebLinkHandler auto convert to kotlin
pfaffenrodt 3f2a469
OpenWebLinkHandler remove not required nullability
pfaffenrodt 43a82ce
Rename .java to .kt
pfaffenrodt 851acd8
AboutActivity auto convert to kotlin
pfaffenrodt 8f16942
Optimize Kotlin code of AboutActivity
pfaffenrodt 9f6661d
Rename .java to .kt
pfaffenrodt dc6543d
Convert ThirdPartyInfo to kotlin
pfaffenrodt 6a3a16c
Add format and html extension for string resource ids
pfaffenrodt ef99f40
Rename open to openBrowser
pfaffenrodt 3f56441
Prefer nullpointer instead of doing nothing
pfaffenrodt 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
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,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 } | ||
|
||
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
111
app/src/main/java/protect/card_locker/AboutContent.java
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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#alsoproducing an instance has 'also' the sideeffect that the field variable is set.
coupling things
There was a problem hiding this comment.
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 variablecontent
. Then setthis.content
to the newly createdcontent
variable. Right?I don't quite understand why that's cleaner than just directly doing:
though. Is this some kind of best practice I don't know about?
There was a problem hiding this comment.
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