add About activity
This commit is contained in:
parent
466c0a4f96
commit
a3180bc3bb
9 changed files with 319 additions and 4 deletions
|
@ -0,0 +1,117 @@
|
|||
package com.simplemobiletools.commons.activities
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.View
|
||||
import com.simplemobiletools.commons.BuildConfig
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.helpers.APP_NAME
|
||||
import kotlinx.android.synthetic.main.activity_about.*
|
||||
import java.util.*
|
||||
|
||||
class AboutActivity : SimpleActivity() {
|
||||
var appName = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_about)
|
||||
appName = intent.getStringExtra(APP_NAME) ?: ""
|
||||
|
||||
setupEmail()
|
||||
setupMoreApps()
|
||||
setupRateUs()
|
||||
setupInvite()
|
||||
setupLicense()
|
||||
setupDonate()
|
||||
setupFacebook()
|
||||
setupGPlus()
|
||||
setupCopyright()
|
||||
}
|
||||
|
||||
private fun setupEmail() {
|
||||
val email = getString(R.string.email)
|
||||
val href = "<a href=\"mailto:$email?subject=$appName\">$email</a>"
|
||||
about_email.text = Html.fromHtml(href)
|
||||
about_email.movementMethod = LinkMovementMethod.getInstance()
|
||||
}
|
||||
|
||||
private fun setupMoreApps() {
|
||||
about_more_apps.setOnClickListener {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/dev?id=9070296388022589266")))
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCopyright() {
|
||||
val versionName = BuildConfig.VERSION_NAME
|
||||
val year = Calendar.getInstance().get(Calendar.YEAR)
|
||||
val copyrightText = String.format(getString(R.string.copyright), versionName, year)
|
||||
about_copyright.text = copyrightText
|
||||
}
|
||||
|
||||
private fun setupRateUs() {
|
||||
if (config.isFirstRun) {
|
||||
about_rate_us.visibility = View.GONE
|
||||
} else {
|
||||
about_rate_us.setOnClickListener {
|
||||
val uri = Uri.parse("market://details?id=$packageName")
|
||||
try {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, uri))
|
||||
} catch (ignored: ActivityNotFoundException) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getStoreUrl())))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setupInvite() {
|
||||
about_invite.setOnClickListener {
|
||||
val text = String.format(getString(R.string.share_text), appName, getStoreUrl())
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_SUBJECT, appName)
|
||||
putExtra(Intent.EXTRA_TEXT, text)
|
||||
type = "text/plain"
|
||||
startActivity(Intent.createChooser(this, getString(R.string.invite_via)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setupLicense() {
|
||||
about_license.setOnClickListener {
|
||||
/*val intent = Intent(applicationContext, LicenseActivity::class.java)
|
||||
startActivity(intent)*/
|
||||
}
|
||||
}
|
||||
|
||||
fun setupDonate() {
|
||||
about_donate.setOnClickListener {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("http://simplemobiletools.github.io/donate")))
|
||||
}
|
||||
}
|
||||
|
||||
fun setupFacebook() {
|
||||
about_facebook.setOnClickListener {
|
||||
var link = "https://www.facebook.com/simplemobiletools"
|
||||
try {
|
||||
packageManager.getPackageInfo("com.facebook.katana", 0)
|
||||
link = "fb://page/150270895341774"
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
|
||||
}
|
||||
}
|
||||
|
||||
fun setupGPlus() {
|
||||
about_gplus.setOnClickListener {
|
||||
val link = "https://plus.google.com/communities/104880861558693868382"
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStoreUrl() = "https://play.google.com/store/apps/details?id=$packageName"
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.simplemobiletools.commons.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.helpers.APP_NAME
|
||||
import com.simplemobiletools.commons.helpers.Config
|
||||
|
||||
open class SimpleActivity : AppCompatActivity() {
|
||||
lateinit var config: Config
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
config = Config.newInstance(applicationContext)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
finish()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
fun startAboutActivity(appNameId: Int) {
|
||||
Intent(applicationContext, AboutActivity::class.java).apply {
|
||||
putExtra(APP_NAME, getString(appNameId))
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,10 @@ package com.simplemobiletools.commons.extensions
|
|||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import com.simplemobiletools.commons.helpers.PREFS_KEY
|
||||
|
||||
fun Context.toast(id: Int, length: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, id, length).show()
|
||||
|
||||
fun Context.toast(msg: String, length: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, msg, length).show()
|
||||
|
||||
fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.simplemobiletools.commons.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.simplemobiletools.commons.extensions.getSharedPrefs
|
||||
|
||||
class Config private constructor(context: Context) {
|
||||
private val mPrefs: SharedPreferences
|
||||
|
||||
companion object {
|
||||
fun newInstance(context: Context) = Config(context)
|
||||
}
|
||||
|
||||
init {
|
||||
mPrefs = context.getSharedPrefs()
|
||||
}
|
||||
|
||||
var isFirstRun: Boolean
|
||||
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
|
||||
set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply()
|
||||
|
||||
var isDarkTheme: Boolean
|
||||
get() = mPrefs.getBoolean(IS_DARK_THEME, false)
|
||||
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.simplemobiletools.commons.helpers
|
||||
|
||||
val APP_NAME = "app_name"
|
||||
|
||||
// shared preferences
|
||||
val PREFS_KEY = "Prefs"
|
||||
val IS_FIRST_RUN = "is_first_run"
|
||||
val IS_DARK_THEME = "is_dark_theme"
|
127
library/src/main/res/layout/activity_about.xml
Normal file
127
library/src/main/res/layout/activity_about.xml
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/about_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/about_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_website"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="web"
|
||||
android:text="@string/website"
|
||||
android:textColorLink="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_email_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_website"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:text="@string/email_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_email_label"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:text="@string/email"
|
||||
android:textColorLink="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_more_apps"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_email"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/more_apps_underlined"
|
||||
android:textColor="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_invite"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_more_apps"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/invite_friends_underlined"
|
||||
android:textColor="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_rate_us"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_invite"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/rate_us_underlined"
|
||||
android:textColor="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_license"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_rate_us"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/third_party_licences_underlined"
|
||||
android:textColor="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_donate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_license"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/donate_underlined"
|
||||
android:textColor="@color/color_primary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_follow_us"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/about_donate"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/follow_us"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/about_facebook"
|
||||
android:layout_width="@dimen/social_logo"
|
||||
android:layout_height="@dimen/social_logo"
|
||||
android:layout_below="@+id/about_follow_us"
|
||||
android:src="@mipmap/facebook"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/about_gplus"
|
||||
android:layout_width="@dimen/social_logo"
|
||||
android:layout_height="@dimen/social_logo"
|
||||
android:layout_below="@+id/about_follow_us"
|
||||
android:layout_marginLeft="@dimen/medium_margin"
|
||||
android:layout_marginRight="@dimen/medium_margin"
|
||||
android:layout_toEndOf="@+id/about_facebook"
|
||||
android:layout_toRightOf="@+id/about_facebook"
|
||||
android:src="@mipmap/gplus"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_copyright"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_below="@+id/about_gplus"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="v1.0\nCopyright © Simple Mobile Tools 2016"/>
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
|
@ -29,8 +29,7 @@ dependencies {
|
|||
compile 'com.android.support:appcompat-v7:25.0.1'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
debugCompile project(path: ':library', configuration: 'debug')
|
||||
releaseCompile project(path: ':library', configuration: 'release')
|
||||
compile project(':library')
|
||||
}
|
||||
|
||||
buildscript {
|
||||
|
|
|
@ -15,5 +15,7 @@
|
|||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.simplemobiletools.commons.activities.AboutActivity"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.simplemobiletools.commons.samples.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.simplemobiletools.commons.activities.SimpleActivity
|
||||
import com.simplemobiletools.commons.samples.R
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
class MainActivity : SimpleActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
Loading…
Reference in a new issue