pull/35/head^2
kunfei 5 years ago
parent a583d471a0
commit fa11376174
  1. 4
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  3. 3
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 11
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt
  8. 3
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt
  9. 24
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt
  11. 11
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  12. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  13. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  14. 4
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  15. 8
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  16. 8
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt
  17. 3
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -46,7 +46,7 @@
android:name=".help.permission.PermissionActivity"
android:theme="@style/Activity.Permission" />
<activity
android:name=".ui.book.source.edit.SourceEditActivity"
android:name=".ui.book.source.edit.BookSourceEditActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize|stateHidden" />
@ -63,7 +63,7 @@
<activity android:name=".ui.about.DonateActivity" />
<activity android:name=".ui.book.info.BookInfoActivity" />
<activity android:name="io.legado.app.ui.book.info.edit.BookInfoEditActivity" />
<activity android:name=".ui.book.source.debug.SourceDebugActivity" />
<activity android:name=".ui.book.source.debug.BookSourceDebugActivity" />
<activity android:name=".ui.book.source.manage.BookSourceActivity" />
<activity android:name=".ui.chapterlist.ChapterListActivity" />
<activity android:name=".ui.rss.read.ReadRssActivity" />

@ -67,4 +67,7 @@ interface BookSourceDao {
@get:Query("select min(customOrder) from book_sources")
val minOrder: Int
@get:Query("select max(customOrder) from book_sources")
val maxOrder: Int
}

@ -34,6 +34,9 @@ interface RssSourceDao {
@get:Query("select min(customOrder) from rssSources")
val minOrder: Int
@get:Query("select max(customOrder) from rssSources")
val maxOrder: Int
@Query("delete from rssSources where sourceUrl in (:sourceUrls)")
fun delSection(vararg sourceUrls: String)

@ -14,7 +14,7 @@ import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.source.edit.SourceEditActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.utils.getCompatDrawable
import io.legado.app.utils.getViewModel
@ -190,7 +190,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
}
tv_origin.onClick {
viewModel.bookData.value?.let {
startActivity<SourceEditActivity>(Pair("data", it.origin))
startActivity<BookSourceEditActivity>(Pair("data", it.origin))
}
}
tv_change_source.onClick {

@ -32,7 +32,7 @@ import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.config.*
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
import io.legado.app.ui.book.source.edit.SourceEditActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.replacerule.ReplaceRuleActivity
@ -114,7 +114,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
private fun initView() {
tv_chapter_name.onClick {
viewModel.webBook?.let {
startActivityForResult<SourceEditActivity>(
startActivityForResult<BookSourceEditActivity>(
requestCodeEditSource,
Pair("data", it.bookSource.bookSourceUrl)
)

@ -18,12 +18,13 @@ import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_source_debug) {
class BookSourceDebugActivity :
VMBaseActivity<BookSourceDebugModel>(R.layout.activity_source_debug) {
override val viewModel: SourceDebugModel
get() = getViewModel(SourceDebugModel::class.java)
override val viewModel: BookSourceDebugModel
get() = getViewModel(BookSourceDebugModel::class.java)
private lateinit var adapter: SourceDebugAdapter
private lateinit var adapter: BookSourceDebugAdapter
private val qrRequestCode = 101
override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -42,7 +43,7 @@ class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_s
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(recycler_view)
adapter = SourceDebugAdapter(this)
adapter = BookSourceDebugAdapter(this)
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.adapter = adapter
rotate_loading.loadingColor = accentColor

@ -6,7 +6,7 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import kotlinx.android.synthetic.main.item_log.view.*
class SourceDebugAdapter(context: Context) :
class BookSourceDebugAdapter(context: Context) :
SimpleRecyclerAdapter<String>(context, R.layout.item_log) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
holder.itemView.apply {

@ -6,7 +6,8 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.model.WebBook
import io.legado.app.model.webbook.SourceDebug
class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback {
class BookSourceDebugModel(application: Application) : BaseViewModel(application),
SourceDebug.Callback {
private var webBook: WebBook? = null

@ -22,7 +22,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.EditEntity
import io.legado.app.data.entities.rule.*
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.source.debug.SourceDebugActivity
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.getViewModel
@ -32,13 +32,13 @@ import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
import kotlin.math.abs
class SourceEditActivity :
VMBaseActivity<SourceEditViewModel>(R.layout.activity_book_source_edit, false),
class BookSourceEditActivity :
VMBaseActivity<BookSourceEditViewModel>(R.layout.activity_book_source_edit, false),
KeyboardToolPop.CallBack {
override val viewModel: SourceEditViewModel
get() = getViewModel(SourceEditViewModel::class.java)
override val viewModel: BookSourceEditViewModel
get() = getViewModel(BookSourceEditViewModel::class.java)
private val adapter = SourceEditAdapter()
private val adapter = BookSourceEditAdapter()
private val sourceEntities: ArrayList<EditEntity> = ArrayList()
private val searchEntities: ArrayList<EditEntity> = ArrayList()
private val findEntities: ArrayList<EditEntity> = ArrayList()
@ -55,11 +55,8 @@ class SourceEditActivity :
upRecyclerView(it)
})
if (viewModel.sourceLiveData.value == null) {
val sourceID = intent.getStringExtra("data")
if (sourceID == null) {
upRecyclerView(null)
} else {
sourceID.let { viewModel.setBookSource(sourceID) }
intent.getStringExtra("data")?.let {
viewModel.setBookSource(it)
}
} else {
upRecyclerView(viewModel.sourceLiveData.value)
@ -86,7 +83,7 @@ class SourceEditActivity :
R.id.menu_debug_source -> {
getSource()?.let {
viewModel.save(it) {
startActivity<SourceDebugActivity>(Pair("key", it.bookSourceUrl))
startActivity<BookSourceDebugActivity>(Pair("key", it.bookSourceUrl))
}
}
}
@ -120,6 +117,7 @@ class SourceEditActivity :
setEditEntities(tab?.position)
}
})
upRecyclerView(null)
}
private fun setEditEntities(tabPosition: Int?) {
@ -358,7 +356,7 @@ class SourceEditActivity :
val rect = Rect()
// 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this@SourceEditActivity.displayMetrics.heightPixels
val screenHeight = this@BookSourceEditActivity.displayMetrics.heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) {

@ -10,7 +10,7 @@ import io.legado.app.R
import io.legado.app.data.entities.EditEntity
import kotlinx.android.synthetic.main.item_source_edit.view.*
class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() {
class BookSourceEditAdapter : RecyclerView.Adapter<BookSourceEditAdapter.MyViewHolder>() {
var editEntities: ArrayList<EditEntity> = ArrayList()
set(value) {

@ -9,7 +9,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookSource
import io.legado.app.help.storage.OldRule
class SourceEditViewModel(application: Application) : BaseViewModel(application) {
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
val sourceLiveData: MutableLiveData<BookSource> = MutableLiveData()
@ -17,14 +17,17 @@ class SourceEditViewModel(application: Application) : BaseViewModel(application)
execute {
App.db.bookSourceDao().getBookSource(key)?.let {
sourceLiveData.postValue(it)
} ?: sourceLiveData.postValue(BookSource())
}
}
}
fun save(bookSource: BookSource, finally: (() -> Unit)? = null) {
execute {
if (bookSource.customOrder == 0) {
bookSource.customOrder = App.db.bookSourceDao().allCount()
sourceLiveData.value?.let {
bookSource.customOrder = it.customOrder
App.db.bookSourceDao().delete(it)
} ?: let {
bookSource.customOrder = App.db.bookSourceDao().maxOrder + 1
}
App.db.bookSourceDao().insert(bookSource)
}.onFinally {

@ -28,7 +28,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.lib.theme.view.ATEAutoCompleteTextView
import io.legado.app.service.CheckSourceService
import io.legado.app.ui.book.source.edit.SourceEditActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.utils.ACache
import io.legado.app.utils.applyTint
@ -76,7 +76,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_add_book_source -> {
this.startActivity<SourceEditActivity>()
this.startActivity<BookSourceEditActivity>()
}
R.id.menu_import_book_source_qr -> {
this.startActivityForResult<QrCodeActivity>(qrRequestCode)
@ -212,7 +212,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
}
override fun edit(bookSource: BookSource) {
startActivity<SourceEditActivity>(Pair("data", bookSource.bookSourceUrl))
startActivity<BookSourceEditActivity>(Pair("data", bookSource.bookSourceUrl))
}
override fun upOrder() {

@ -16,8 +16,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(bookSource: BookSource) {
execute {
val minXh = App.db.bookSourceDao().minOrder
bookSource.customOrder = minXh - 1
bookSource.customOrder = App.db.bookSourceDao().minOrder - 1
App.db.bookSourceDao().insert(bookSource)
}
}

@ -12,7 +12,7 @@ import io.legado.app.base.VMBaseFragment
import io.legado.app.data.entities.BookSource
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.source.edit.SourceEditActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.explore.ExploreShowActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.startActivity
@ -88,7 +88,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_
}
override fun editSource(sourceUrl: String) {
startActivity<SourceEditActivity>(Pair("data", sourceUrl))
startActivity<BookSourceEditActivity>(Pair("data", sourceUrl))
}
override fun toTop(source: BookSource) {

@ -50,11 +50,8 @@ class RssSourceEditActivity :
upRecyclerView(it)
})
if (viewModel.sourceLiveData.value == null) {
val sourceID = intent.getStringExtra("data")
if (sourceID == null) {
upRecyclerView(null)
} else {
sourceID.let { viewModel.setSource(sourceID) }
intent.getStringExtra("data")?.let {
viewModel.setSource(it)
}
} else {
upRecyclerView(viewModel.sourceLiveData.value)
@ -105,6 +102,7 @@ class RssSourceEditActivity :
window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener())
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.adapter = adapter
upRecyclerView(null)
}
private fun upRecyclerView(rssSource: RssSource?) {

@ -18,12 +18,18 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
execute {
App.db.rssSourceDao().getByKey(key)?.let {
sourceLiveData.postValue(it)
} ?: sourceLiveData.postValue(RssSource())
}
}
}
fun save(rssSource: RssSource, success: (() -> Unit)) {
execute {
sourceLiveData.value?.let {
rssSource.customOrder = it.customOrder
App.db.rssSourceDao().delete(it)
} ?: let {
rssSource.customOrder = App.db.rssSourceDao().maxOrder + 1
}
App.db.rssSourceDao().insert(rssSource)
}.onSuccess {
success()

@ -9,8 +9,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(rssSource: RssSource) {
execute {
val minXh = App.db.rssSourceDao().minOrder
rssSource.customOrder = minXh - 1
rssSource.customOrder = App.db.rssSourceDao().minOrder - 1
App.db.rssSourceDao().insert(rssSource)
}
}

Loading…
Cancel
Save