pull/37/head
kunfei 5 years ago
parent ac07667336
commit c6d09c7aa1
  1. 29
      app/src/main/AndroidManifest.xml
  2. 61
      app/src/main/java/io/legado/app/receiver/ReceivingSharedActivity.kt
  3. 19
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  4. 29
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt

@ -58,20 +58,7 @@
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity android:name=".ui.config.ConfigActivity" />
<activity android:name=".ui.replacerule.ReplaceRuleActivity" />
<activity
android:name="io.legado.app.ui.book.search.SearchActivity"
android:label="@string/receiving_shared_label">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name="io.legado.app.ui.book.search.SearchActivity" />
<activity android:name=".ui.about.AboutActivity" />
<activity android:name=".ui.qrcode.QrCodeActivity" />
<activity android:name=".ui.about.DonateActivity" />
@ -97,6 +84,20 @@
<activity android:name=".ui.rss.source.manage.RssSourceActivity" />
<activity android:name=".ui.rss.source.debug.RssSourceDebugActivity" />
<activity android:name=".ui.rss.article.RssArticlesActivity" />
<activity
android:name=".receiver.ReceivingSharedActivity"
android:label="@string/receiving_shared_label">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<service android:name=".service.CheckSourceService" />
<service android:name=".service.DownloadService" />

@ -0,0 +1,61 @@
package io.legado.app.receiver
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.main.MainActivity
import org.jetbrains.anko.startActivity
class ReceivingSharedActivity : AppCompatActivity() {
private val receivingType = "text/plain"
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
initIntent()
}
private fun initIntent() {
if (Intent.ACTION_SEND == intent.action && intent.type == receivingType) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
if (openUrl(it)) {
startActivity<SearchActivity>(Pair("key", it))
}
finish()
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& Intent.ACTION_PROCESS_TEXT == intent.action
&& intent.type == receivingType
) {
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let {
if (openUrl(it)) {
startActivity<SearchActivity>(Pair("key", it))
}
finish()
}
}
}
private fun openUrl(text: String): Boolean {
if (text.isBlank()) {
return false
}
val urls = text.split("\\s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val result = StringBuilder()
for (url in urls) {
if (url.matches("http.+".toRegex()))
result.append("\n").append(url.trim { it <= ' ' })
}
return if (result.length > 1) {
val intent = Intent()
intent.setClass(this@ReceivingSharedActivity, MainActivity::class.java)
this.startActivity(intent)
false
} else {
true
}
}
}

@ -1,7 +1,5 @@
package io.legado.app.ui.book.search
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData
@ -129,21 +127,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
}
private fun initIntent() {
if (Intent.ACTION_SEND == intent.action && intent.type == "text/plain") {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
search_view.setQuery(it, true)
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& Intent.ACTION_PROCESS_TEXT == intent.action
&& intent.type == "text/plain"
) {
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let {
search_view.setQuery(it, true)
}
} else {
intent.getStringExtra("key")?.let {
search_view.setQuery(it, true)
}
intent.getStringExtra("key")?.let {
search_view.setQuery(it, true)
}
}

@ -1,6 +1,8 @@
package io.legado.app.ui.config
import android.content.ComponentName
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import androidx.preference.ListPreference
@ -10,6 +12,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.help.BookHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefString
@ -17,6 +20,12 @@ import io.legado.app.utils.getPrefString
class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener,
SharedPreferences.OnSharedPreferenceChangeListener {
private val packageManager = App.INSTANCE.packageManager
private val componentName = ComponentName(
App.INSTANCE,
SearchActivity::class.java.name
)
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config)
bindPreferenceSummaryToValue(findPreference("downloadPath"))
@ -41,6 +50,9 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange
when (key) {
"downloadPath" -> BookHelp.upDownloadPath()
"recordLog" -> LogUtils.upLevel()
"process_text" -> sharedPreferences?.let {
setProcessTextEnable(it.getBoolean("process_text", true))
}
}
}
@ -77,4 +89,21 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange
}
}
private fun isProcessTextEnabled(): Boolean {
return packageManager.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
}
private fun setProcessTextEnable(enable: Boolean) {
if (enable) {
packageManager.setComponentEnabledSetting(
componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP
)
} else {
packageManager.setComponentEnabledSetting(
componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
)
}
}
}
Loading…
Cancel
Save