diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c0318cae..39ddc4987 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,7 +46,7 @@ android:name=".help.permission.PermissionActivity" android:theme="@style/Activity.Permission" /> @@ -63,7 +63,7 @@ - + diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 334bb7a82..0c8e4d65e 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index b33f82b60..d30b861da 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 3f78488de..b9bb67838 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -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(R.layout.activity_boo } tv_origin.onClick { viewModel.bookData.value?.let { - startActivity(Pair("data", it.origin)) + startActivity(Pair("data", it.origin)) } } tv_change_source.onClick { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 3b2400e56..c763ae746 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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(R.layout.activity_boo private fun initView() { tv_chapter_name.onClick { viewModel.webBook?.let { - startActivityForResult( + startActivityForResult( requestCodeEditSource, Pair("data", it.bookSource.bookSourceUrl) ) diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt similarity index 90% rename from app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt rename to app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index de2ef20e7..dafeaa218 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -18,12 +18,13 @@ import kotlinx.coroutines.launch import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast -class SourceDebugActivity : VMBaseActivity(R.layout.activity_source_debug) { +class BookSourceDebugActivity : + VMBaseActivity(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(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 diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt similarity index 90% rename from app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt index 94147a5f1..2ec4e9518 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugAdapter.kt @@ -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(context, R.layout.item_log) { override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { holder.itemView.apply { diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt similarity index 91% rename from app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugModel.kt rename to app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt index a17565820..ced985aa9 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/SourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt similarity index 95% rename from app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt rename to app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 4eb28dcea..e2fdd270f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -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(R.layout.activity_book_source_edit, false), +class BookSourceEditActivity : + VMBaseActivity(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 = ArrayList() private val searchEntities: ArrayList = ArrayList() private val findEntities: ArrayList = 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(Pair("key", it.bookSourceUrl)) + startActivity(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) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt similarity index 96% rename from app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt index 434f2071a..37939e803 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt @@ -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() { +class BookSourceEditAdapter : RecyclerView.Adapter() { var editEntities: ArrayList = ArrayList() set(value) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt similarity index 83% rename from app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditViewModel.kt rename to app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index c3af29a6a..8bff89145 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -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 = 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 { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 258e8b52d..ecdb0ad7b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -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(R.layout.activity override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add_book_source -> { - this.startActivity() + this.startActivity() } R.id.menu_import_book_source_qr -> { this.startActivityForResult(qrRequestCode) @@ -212,7 +212,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } override fun edit(bookSource: BookSource) { - startActivity(Pair("data", bookSource.bookSourceUrl)) + startActivity(Pair("data", bookSource.bookSourceUrl)) } override fun upOrder() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 31accc240..a51b589b3 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 6889124f3..ea23c0909 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -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(R.layout.fragment_find_ } override fun editSource(sourceUrl: String) { - startActivity(Pair("data", sourceUrl)) + startActivity(Pair("data", sourceUrl)) } override fun toTop(source: BookSource) { 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 0636afda6..81ff0b823 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 @@ -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?) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 0f002d627..aec9924ea 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 8915a6cd8..b0ad309d6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -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) } }