diff --git a/app/build.gradle b/app/build.gradle index a403631ad..9268bb0fe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -129,4 +129,8 @@ dependencies { //颜色选择 implementation 'com.jaredrummler:colorpicker:1.1.0' + //对话框 + implementation 'com.afollestad.material-dialogs:core:3.0.0-rc3' + implementation 'com.afollestad.material-dialogs:input:3.0.0-rc3' + implementation 'com.afollestad.material-dialogs:files:3.0.0-rc3' } diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index b348cfeaa..732ebc06c 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -2,6 +2,7 @@ package io.legado.app.data.dao import androidx.paging.DataSource import androidx.room.Dao +import androidx.room.Insert import androidx.room.Query import io.legado.app.data.entities.BookGroup @@ -11,5 +12,9 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun observeAll(): DataSource.Factory + @get:Query("SELECT MAX(groupId) FROM book_groups") + val maxId: Int + @Insert + fun insert(bookGroup: BookGroup) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 82c198fc2..6f4030cf0 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -54,7 +54,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar upTheme(false) } .setNegativeButton(R.string.cancel) { _, _ -> upTheme(false) } - .show().upTint + .show().upTint() } } else { upTheme(false) @@ -74,7 +74,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar upTheme(true) } .setNegativeButton(R.string.cancel) { _, _ -> upTheme(true) } - .show().upTint + .show().upTint() } } else { upTheme(true) @@ -105,7 +105,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar Handler().postDelayed({ activity?.recreate() }, 100) } .setNegativeButton(R.string.cancel, null) - .show().upTint + .show().upTint() } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 49a74f6c0..8392c9686 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -9,6 +9,8 @@ import androidx.paging.LivePagedListBuilder import androidx.paging.PagedList import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.input.input import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment @@ -17,6 +19,8 @@ import io.legado.app.data.entities.BookGroup import io.legado.app.lib.theme.ThemeStore import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_title_bar.* +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.jetbrains.anko.textColor class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { @@ -42,6 +46,30 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) bookGroupAdapter = BookGroupAdapter() rv_book_group.adapter = bookGroupAdapter + bookGroupAdapter.callBack = object : BookGroupAdapter.CallBack { + override fun open(groupId: Int) { + when (groupId) { + -10 -> context?.let { + MaterialDialog(it).show { + title(text = "新建分组") + input(hint = "分组名称") { _, charSequence -> + run { + GlobalScope.launch { + App.db.bookGroupDao().insert( + BookGroup( + App.db.bookGroupDao().maxId + 1, + charSequence.toString() + ) + ) + } + } + } + positiveButton(R.string.ok) + } + } + } + } + } rv_bookshelf.layoutManager = LinearLayoutManager(context) rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL)) bookshelfAdapter = BookshelfAdapter() diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt index 0816a2f4a..3d131fbd1 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt @@ -101,6 +101,6 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour } override fun edit(bookSource: BookSource) { - context?.let { it.startActivity(Pair("data", bookSource.origin)) } + context?.startActivity(Pair("data", bookSource.origin)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt b/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt index 300309ca7..e956f1368 100644 --- a/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/AlertDialogExtensions.kt @@ -3,5 +3,6 @@ package io.legado.app.utils import androidx.appcompat.app.AlertDialog import io.legado.app.lib.theme.ATH -val AlertDialog.upTint: AlertDialog - get() = ATH.setAlertDialogTint(this) \ No newline at end of file +fun AlertDialog.upTint(): AlertDialog { + return ATH.setAlertDialogTint(this) +} diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt new file mode 100644 index 000000000..ac26c4355 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -0,0 +1,13 @@ +package io.legado.app.utils + +import android.content.Context +import android.view.View +import android.view.inputmethod.InputMethodManager +import io.legado.app.App + +fun View.hidehideSoftInput() = run { + val imm = App.INSTANCE.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager + imm?.let { + imm.hideSoftInputFromWindow(this.windowToken, 0) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_input.xml b/app/src/main/res/layout/dialog_input.xml new file mode 100644 index 000000000..e867c1792 --- /dev/null +++ b/app/src/main/res/layout/dialog_input.xml @@ -0,0 +1,39 @@ + + + + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 3b8558198..1d6fd88d1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -48,13 +48,7 @@ @color/md_grey_900 - +