mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
feat: 优化代码
This commit is contained in:
parent
54b3add99a
commit
e0e412e85a
@ -54,6 +54,7 @@ android {
|
||||
if (project.hasProperty("RELEASE_STORE_FILE")) {
|
||||
signingConfig signingConfigs.myConfig
|
||||
}
|
||||
applicationIdSuffix '.release'
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
@ -123,7 +124,7 @@ dependencies {
|
||||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
||||
|
||||
//room
|
||||
def room_version = '2.2.3'
|
||||
def room_version = '2.2.4'
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
|
||||
@ -175,7 +176,7 @@ dependencies {
|
||||
//MarkDown
|
||||
implementation 'ru.noties.markwon:core:3.0.2'
|
||||
|
||||
// 转换繁体
|
||||
//转换繁体
|
||||
implementation 'com.github.houbb:opencc4j:1.4.0'
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,35 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:453392274790:android:c1481c1c3d3f51eff624a7",
|
||||
"android_client_info": {
|
||||
"package_name": "io.legado.app.release"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
|
@ -1,69 +0,0 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "453392274790",
|
||||
"firebase_url": "https://legado-fca69.firebaseio.com",
|
||||
"project_id": "legado-fca69",
|
||||
"storage_bucket": "legado-fca69.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:453392274790:android:1d2b1eefbe0e78cff624a7",
|
||||
"android_client_info": {
|
||||
"package_name": "io.legado.app"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:453392274790:android:c4eac14b1410eec5f624a7",
|
||||
"android_client_info": {
|
||||
"package_name": "io.legado.app.debug"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
@ -6,7 +6,7 @@ import android.view.MenuItem
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseActivity
|
||||
import io.legado.app.utils.openUrl
|
||||
import io.legado.app.utils.shareText
|
||||
import org.jetbrains.anko.share
|
||||
|
||||
class AboutActivity : BaseActivity(R.layout.activity_about) {
|
||||
|
||||
@ -27,9 +27,9 @@ class AboutActivity : BaseActivity(R.layout.activity_about) {
|
||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_scoring -> openUrl("market://details?id=$packageName")
|
||||
R.id.menu_share_it -> shareText(
|
||||
"App Share",
|
||||
getString(R.string.app_share_description)
|
||||
R.id.menu_share_it -> share(
|
||||
getString(R.string.app_share_description),
|
||||
getString(R.string.app_name)
|
||||
)
|
||||
}
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
|
@ -15,6 +15,8 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.view.SupportMenuInflater
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.appcompat.view.menu.MenuItemImpl
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.view.size
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legado.app.R
|
||||
@ -22,9 +24,11 @@ import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.base.adapter.SimpleRecyclerAdapter
|
||||
import io.legado.app.utils.isAbsUrl
|
||||
import io.legado.app.utils.sendToClip
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.android.synthetic.main.item_fillet_text.view.*
|
||||
import kotlinx.android.synthetic.main.popup_action_menu.view.*
|
||||
import org.jetbrains.anko.sdk27.listeners.onClick
|
||||
import org.jetbrains.anko.share
|
||||
import org.jetbrains.anko.toast
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@ -48,10 +52,27 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
recycler_view.adapter = adapter
|
||||
val menu = MenuBuilder(context)
|
||||
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
onInitializeMenu(menu)
|
||||
}
|
||||
adapter.setItems(menu.visibleItems)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val popupMenu = PopupMenu(context, iv_menu_more)
|
||||
onInitializeMenu(popupMenu.menu)
|
||||
if (popupMenu.menu.size > 0) {
|
||||
iv_menu_more.visible()
|
||||
popupMenu.setOnMenuItemClickListener { item ->
|
||||
item.intent?.let {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
|
||||
context.startActivity(it)
|
||||
}
|
||||
}
|
||||
this@TextActionMenu.dismiss()
|
||||
true
|
||||
}
|
||||
}
|
||||
iv_menu_more.onClick {
|
||||
popupMenu.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class Adapter(context: Context) :
|
||||
@ -81,6 +102,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
private fun onMenuItemSelected(item: MenuItemImpl) {
|
||||
when (item.itemId) {
|
||||
R.id.menu_copy -> context.sendToClip(callBack.selectedText)
|
||||
R.id.menu_share_str -> context.share(callBack.selectedText)
|
||||
R.id.menu_browser -> {
|
||||
try {
|
||||
val intent = if (callBack.selectedText.isAbsUrl()) {
|
||||
@ -98,12 +120,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
context.toast(e.localizedMessage ?: "ERROR")
|
||||
}
|
||||
}
|
||||
else -> item.intent?.let {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
|
||||
context.startActivity(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
callBack.onMenuActionFinally()
|
||||
}
|
||||
|
@ -25,9 +25,13 @@ import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.ATH
|
||||
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
|
||||
import io.legado.app.ui.widget.KeyboardToolPop
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.getViewModel
|
||||
import io.legado.app.utils.shareWithQr
|
||||
import kotlinx.android.synthetic.main.activity_book_source_edit.*
|
||||
import org.jetbrains.anko.displayMetrics
|
||||
import org.jetbrains.anko.share
|
||||
import org.jetbrains.anko.startActivity
|
||||
import org.jetbrains.anko.toast
|
||||
import kotlin.math.abs
|
||||
@ -84,9 +88,7 @@ class BookSourceEditActivity :
|
||||
}
|
||||
}
|
||||
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }
|
||||
R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr ->
|
||||
shareText(getString(R.string.share_book_source), sourceStr)
|
||||
}
|
||||
R.id.menu_share_str -> GSON.toJson(getSource())?.let { share(it) }
|
||||
R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr ->
|
||||
shareWithQr(getString(R.string.share_book_source), sourceStr)
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ 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 kotlinx.coroutines.launch
|
||||
import org.apache.commons.text.StringEscapeUtils
|
||||
import org.jetbrains.anko.share
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.safety.Whitelist
|
||||
|
||||
@ -54,7 +54,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
|
||||
when (item.itemId) {
|
||||
R.id.menu_rss_star -> viewModel.favorite()
|
||||
R.id.menu_share_it -> viewModel.rssArticle?.let {
|
||||
shareText("链接分享", it.link)
|
||||
share(it.link)
|
||||
}
|
||||
R.id.menu_aloud -> readAloud()
|
||||
}
|
||||
|
@ -21,9 +21,13 @@ import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.ATH
|
||||
import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity
|
||||
import io.legado.app.ui.widget.KeyboardToolPop
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.getViewModel
|
||||
import io.legado.app.utils.shareWithQr
|
||||
import kotlinx.android.synthetic.main.activity_rss_source_edit.*
|
||||
import org.jetbrains.anko.displayMetrics
|
||||
import org.jetbrains.anko.share
|
||||
import org.jetbrains.anko.startActivity
|
||||
import org.jetbrains.anko.toast
|
||||
import kotlin.math.abs
|
||||
@ -101,7 +105,7 @@ class RssSourceEditActivity :
|
||||
}
|
||||
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }
|
||||
R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr ->
|
||||
shareText(getString(R.string.share_rss_source), sourceStr)
|
||||
share(sourceStr)
|
||||
}
|
||||
R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr ->
|
||||
shareWithQr(getString(R.string.share_rss_source), sourceStr)
|
||||
|
@ -92,17 +92,6 @@ val Context.navigationBarHeight: 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)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetWorldReadable")
|
||||
fun Context.shareWithQr(title: String, text: String) {
|
||||
QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L
|
||||
|
@ -1,8 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recycler_view"
|
||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/shape_card_view"
|
||||
android:padding="5dp" />
|
||||
android:padding="5dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/iv_menu_more"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:src="@drawable/ic_more_vert"
|
||||
android:tint="@color/tv_text_default"
|
||||
android:visibility="gone"
|
||||
android:contentDescription="@string/more_menu"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
|
@ -13,4 +13,7 @@
|
||||
android:id="@+id/menu_browser"
|
||||
android:title="@string/browser" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_share_str"
|
||||
android:title="@string/share" />
|
||||
</menu>
|
Loading…
Reference in New Issue
Block a user