From c6779c8047b214d8b27be189b8d6c53484a36566 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 13 Nov 2016 10:50:36 +0100 Subject: [PATCH] convert AboutActivity to kotlin --- .../gallery/activities/AboutActivity.java | 110 ------------------ .../gallery/activities/AboutActivity.kt | 100 ++++++++++++++++ 2 files changed, 100 insertions(+), 110 deletions(-) delete mode 100644 app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/activities/AboutActivity.kt diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java deleted file mode 100644 index 51c49523e..000000000 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.simplemobiletools.gallery.activities; - -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.res.Resources; -import android.net.Uri; -import android.os.Bundle; -import android.text.Html; -import android.text.method.LinkMovementMethod; -import android.view.View; -import android.widget.TextView; - -import com.simplemobiletools.gallery.BuildConfig; -import com.simplemobiletools.gallery.Config; -import com.simplemobiletools.gallery.R; - -import java.util.Calendar; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; - -public class AboutActivity extends SimpleActivity { - @BindView(R.id.about_copyright) TextView mCopyright; - @BindView(R.id.about_email) TextView mEmailTV; - @BindView(R.id.about_rate_us) View mRateUs; - - private static Resources mRes; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_about); - ButterKnife.bind(this); - mRes = getResources(); - - setupEmail(); - setupCopyright(); - setupRateUs(); - } - - private void setupEmail() { - final String email = mRes.getString(R.string.email); - final String appName = mRes.getString(R.string.app_name); - final String href = "" + email + ""; - mEmailTV.setText(Html.fromHtml(href)); - mEmailTV.setMovementMethod(LinkMovementMethod.getInstance()); - } - - private void setupCopyright() { - final String versionName = BuildConfig.VERSION_NAME; - final int year = Calendar.getInstance().get(Calendar.YEAR); - final String copyrightText = String.format(mRes.getString(R.string.copyright), versionName, year); - mCopyright.setText(copyrightText); - } - - private void setupRateUs() { - if (Config.newInstance(getApplicationContext()).getIsFirstRun()) { - mRateUs.setVisibility(View.GONE); - } - } - - @OnClick(R.id.about_invite) - public void inviteFriend() { - final Intent intent = new Intent(); - final String text = String.format(getString(R.string.share_text), getString(R.string.app_name), getStoreUrl()); - intent.setAction(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name)); - intent.putExtra(Intent.EXTRA_TEXT, text); - intent.setType("text/plain"); - startActivity(Intent.createChooser(intent, getString(R.string.invite_via))); - } - - @OnClick(R.id.about_rate_us) - public void rateUsClicked() { - final Uri uri = Uri.parse("market://details?id=" + getPackageName()); - try { - startActivity(new Intent(Intent.ACTION_VIEW, uri)); - } catch (ActivityNotFoundException ignored) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getStoreUrl()))); - } - } - - @OnClick(R.id.about_license) - public void licenseClicked() { - final Intent intent = new Intent(getApplicationContext(), LicenseActivity.class); - startActivity(intent); - } - - @OnClick(R.id.about_facebook) - public void facebookClicked() { - String link = "https://www.facebook.com/simplemobiletools"; - try { - getPackageManager().getPackageInfo("com.facebook.katana", 0); - link = "fb://page/150270895341774"; - } catch (Exception ignored) { - } - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link))); - } - - @OnClick(R.id.about_gplus) - public void googlePlusClicked() { - final String link = "https://plus.google.com/communities/104880861558693868382"; - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link))); - } - - private String getStoreUrl() { - return "https://play.google.com/store/apps/details?id=" + getPackageName(); - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/AboutActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/AboutActivity.kt new file mode 100644 index 000000000..e8f34aa98 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/AboutActivity.kt @@ -0,0 +1,100 @@ +package com.simplemobiletools.gallery.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.gallery.BuildConfig +import com.simplemobiletools.gallery.R +import kotlinx.android.synthetic.main.activity_about.* +import java.util.* + +class AboutActivity : SimpleActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_about) + + setupEmail() + setupCopyright() + setupRateUs() + setupInvite() + setupLicense() + setupFacebook() + setupGPlus() + } + + private fun setupEmail() { + val email = getString(R.string.email) + val appName = getString(R.string.app_name) + val href = "$email" + about_email.text = Html.fromHtml(href) + about_email.movementMethod = LinkMovementMethod.getInstance() + } + + 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 (mConfig.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), getString(R.string.app_name), getStoreUrl()) + Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name)) + 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 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" +}