pull/71/head
kunfei 5 years ago
parent 528c8b42bb
commit fbe6a6cbc5
  1. 10
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  2. 10
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  3. 40
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  4. 2
      app/src/main/res/menu/source_edit.xml
  5. 3
      app/src/main/res/values/strings.xml

@ -26,10 +26,7 @@ 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.GSON
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import io.legado.app.utils.shareText
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_source_edit.*
import org.jetbrains.anko.displayMetrics
import org.jetbrains.anko.startActivity
@ -89,7 +86,10 @@ class BookSourceEditActivity :
}
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }
R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr ->
shareText("分享书源", sourceStr)
shareText(getString(R.string.share_book_source), sourceStr)
}
R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr ->
shareWithQr(getString(R.string.share_book_source), sourceStr)
}
R.id.menu_rule_summary -> {
try {

@ -22,10 +22,7 @@ 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.GSON
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import io.legado.app.utils.shareText
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_rss_source_edit.*
import org.jetbrains.anko.displayMetrics
import org.jetbrains.anko.startActivity
@ -105,7 +102,10 @@ class RssSourceEditActivity :
}
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) }
R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr ->
shareText("分享RSS源", sourceStr)
shareText(getString(R.string.share_rss_source), sourceStr)
}
R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr ->
shareWithQr(getString(R.string.share_rss_source), sourceStr)
}
}
return super.onCompatOptionsItemSelected(item)

@ -1,16 +1,25 @@
package io.legado.app.utils
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.content.edit
import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder
import com.google.zxing.EncodeHintType
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.BuildConfig
import io.legado.app.R
import org.jetbrains.anko.defaultSharedPreferences
import org.jetbrains.anko.toast
import java.io.File
import java.io.FileOutputStream
fun Context.getPrefBoolean(key: String, defValue: Boolean = false) =
defaultSharedPreferences.getBoolean(key, defValue)
@ -75,6 +84,37 @@ fun Context.shareText(title: String, text: String) {
}
}
@SuppressLint("SetWorldReadable")
fun Context.shareWithQr(title: String, text: String) {
QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L
val bitmap = QRCodeEncoder.syncEncodeQRCode(text, 600)
QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H
if (bitmap == null) {
toast(R.string.text_too_long_qr_error)
} else {
try {
val file = File(externalCacheDir, "qr.png")
val fOut = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut)
fOut.flush()
fOut.close()
file.setReadable(true, false)
val contentUri = FileProvider.getUriForFile(
this,
"${BuildConfig.APPLICATION_ID}.fileProvider",
file
)
val intent = Intent(Intent.ACTION_SEND)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(Intent.EXTRA_STREAM, contentUri)
intent.type = "image/png"
startActivity(Intent.createChooser(intent, title))
} catch (e: Exception) {
toast(e.localizedMessage ?: "ERROR")
}
}
}
val Context.isNightTheme: Boolean
get() = getPrefBoolean("isNightTheme")

@ -35,7 +35,7 @@
app:showAsAction="never" />
<item
android:id="@+id/menu_share_it"
android:id="@+id/menu_share_qr"
android:title="@string/qr_share"
app:showAsAction="never" />

@ -579,5 +579,8 @@
<string name="prev_sentence">上一句</string>
<string name="next_sentence">下一句</string>
<string name="other_folder">其它目录</string>
<string name="text_too_long_qr_error">文字太多,生成二维码失败</string>
<string name="share_rss_source">分享RSS源</string>
<string name="share_book_source">分享书源</string>
</resources>

Loading…
Cancel
Save