Skip to content

Commit 5fb62af

Browse files
committed
convert AboutActivity to kotlin
1 parent e5d02f5 commit 5fb62af

File tree

2 files changed

+100
-110
lines changed

2 files changed

+100
-110
lines changed

app/src/main/java/com/simplemobiletools/notes/activities/AboutActivity.java

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.simplemobiletools.notes.activities
2+
3+
import android.content.ActivityNotFoundException
4+
import android.content.Intent
5+
import android.net.Uri
6+
import android.os.Bundle
7+
import android.text.Html
8+
import android.text.method.LinkMovementMethod
9+
import android.view.View
10+
import com.simplemobiletools.notes.BuildConfig
11+
import com.simplemobiletools.notes.R
12+
import kotlinx.android.synthetic.main.activity_about.*
13+
import java.util.*
14+
15+
class AboutActivity : SimpleActivity() {
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
setContentView(R.layout.activity_about)
19+
20+
setupEmail()
21+
setupCopyright()
22+
setupRateUs()
23+
setupInvite()
24+
setupLicense()
25+
setupFacebook()
26+
setupGPlus()
27+
}
28+
29+
private fun setupEmail() {
30+
val email = getString(R.string.email)
31+
val appName = getString(R.string.app_name)
32+
val href = "<a href=\"mailto:$email?subject=$appName\">$email</a>"
33+
about_email.text = Html.fromHtml(href)
34+
about_email.movementMethod = LinkMovementMethod.getInstance()
35+
}
36+
37+
private fun setupCopyright() {
38+
val versionName = BuildConfig.VERSION_NAME
39+
val year = Calendar.getInstance().get(Calendar.YEAR)
40+
val copyrightText = String.format(getString(R.string.copyright), versionName, year)
41+
about_copyright.text = copyrightText
42+
}
43+
44+
private fun setupRateUs() {
45+
if (config.isFirstRun) {
46+
about_rate_us.visibility = View.GONE
47+
} else {
48+
about_rate_us.setOnClickListener {
49+
val uri = Uri.parse("market://details?id=$packageName")
50+
try {
51+
startActivity(Intent(Intent.ACTION_VIEW, uri))
52+
} catch (ignored: ActivityNotFoundException) {
53+
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getStoreUrl())))
54+
}
55+
}
56+
}
57+
}
58+
59+
fun setupInvite() {
60+
about_invite.setOnClickListener {
61+
val text = String.format(getString(R.string.share_text), getString(R.string.app_name), getStoreUrl())
62+
Intent().apply {
63+
action = Intent.ACTION_SEND
64+
putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name))
65+
putExtra(Intent.EXTRA_TEXT, text)
66+
type = "text/plain"
67+
startActivity(Intent.createChooser(this, getString(R.string.invite_via)))
68+
}
69+
}
70+
}
71+
72+
fun setupLicense() {
73+
about_license.setOnClickListener {
74+
val intent = Intent(applicationContext, LicenseActivity::class.java)
75+
startActivity(intent)
76+
}
77+
}
78+
79+
fun setupFacebook() {
80+
about_facebook.setOnClickListener {
81+
var link = "https://www.facebook.com/simplemobiletools"
82+
try {
83+
packageManager.getPackageInfo("com.facebook.katana", 0)
84+
link = "fb://page/150270895341774"
85+
} catch (ignored: Exception) {
86+
}
87+
88+
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
89+
}
90+
}
91+
92+
fun setupGPlus() {
93+
about_gplus.setOnClickListener {
94+
val link = "https://plus.google.com/communities/104880861558693868382"
95+
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
96+
}
97+
}
98+
99+
private fun getStoreUrl() = "https://play.google.com/store/apps/details?id=$packageName"
100+
}

0 commit comments

Comments
 (0)