From f7a02cf14193c4190b0414b08fef5fce7b89de3a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 11:16:53 +0800 Subject: [PATCH] up --- .../source/edit/BookSourceEditActivity.kt | 14 +++----------- .../legado/app/ui/rss/read/ReadRssActivity.kt | 13 +------------ .../rss/source/edit/RssSourceEditActivity.kt | 4 ++++ .../io/legado/app/utils/ContextExtensions.kt | 19 +++++++++++++++++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index aeb83a093..4bab3e780 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -29,6 +29,7 @@ import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -87,17 +88,8 @@ class BookSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } - R.id.menu_share_str -> { - GSON.toJson(getSource())?.let { sourceStr -> - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, sourceStr) - startActivity(Intent.createChooser(textIntent, "Source Share")) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } + R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr -> + shareText("分享书源", sourceStr) } R.id.menu_rule_summary -> { try { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 0cab40e01..951d190f7 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.rss.read import android.annotation.SuppressLint -import android.content.Intent import android.os.Bundle import android.view.KeyEvent import android.view.Menu @@ -15,8 +14,8 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* -import org.jetbrains.anko.toast class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -126,14 +125,4 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } - private fun shareText(title: String, text: String) { - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(textIntent, title)) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index d1704848e..2b5d88b7a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -25,6 +25,7 @@ import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -103,6 +104,9 @@ class RssSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } + R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> + shareText("分享RSS源", sourceStr) + } } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index f47a0a2a8..ff917b09f 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -1,13 +1,16 @@ package io.legado.app.utils import android.content.Context +import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.content.edit +import io.legado.app.R import org.jetbrains.anko.defaultSharedPreferences +import org.jetbrains.anko.toast fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) @@ -48,7 +51,8 @@ fun Context.getCompatColor(@ColorRes id: Int): Int = ContextCompat.getColor(this fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(this, id) -fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = ContextCompat.getColorStateList(this, id) +fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = + ContextCompat.getColorStateList(this, id) fun Context.getStatusBarHeight(): Int { val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") @@ -60,6 +64,17 @@ fun Context.getNavigationBarHeight(): Int { return resources.getDimensionPixelSize(resourceId) } +fun Context.shareText(title: String, text: String) { + try { + val textIntent = Intent(Intent.ACTION_SEND) + textIntent.type = "text/plain" + textIntent.putExtra(Intent.EXTRA_TEXT, text) + startActivity(Intent.createChooser(textIntent, title)) + } catch (e: Exception) { + toast(R.string.can_not_share) + } +} + val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") @@ -67,4 +82,4 @@ val Context.isTransparentStatusBar: Boolean get() = getPrefBoolean("transparentStatusBar", true) val Context.isShowRSS: Boolean - get() = getPrefBoolean("showRss", true) \ No newline at end of file + get() = getPrefBoolean("showRss", true) \ No newline at end of file