diff --git a/app/src/main/java/io/legado/app/base/BaseFragment.kt b/app/src/main/java/io/legado/app/base/BaseFragment.kt index c19033aa8..c0b41fc40 100644 --- a/app/src/main/java/io/legado/app/base/BaseFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseFragment.kt @@ -6,7 +6,11 @@ import android.view.* import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment +import io.legado.app.R +import io.legado.app.constant.Theme +import io.legado.app.utils.UIUtils import io.legado.app.utils.applyTint +import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -52,6 +56,7 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID), supportToolbar?.let { it.menu.apply { onCompatCreateOptionsMenu(this) + UIUtils.setToolbarMoreIconCustomColor(toolbar, UIUtils.getMenuColor(requireContext())) applyTint(requireContext()) } 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 da2672841..7b163b3e6 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 @@ -19,6 +19,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ColorUtils import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.IconListPreference +import io.legado.app.ui.widget.prefs.NameListPreference import io.legado.app.utils.* @@ -33,6 +34,12 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar preferenceScreen.removePreference(it) } } + findPreference(PreferKey.themeMode)?.let { + it.setOnPreferenceChangeListener { _, _ -> + view?.post { App.INSTANCE.applyDayNight() } + true + } + } upPreferenceSummary("barElevation", AppConfig.elevation.toString()) } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 181ec0330..e8b2870cb 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -1,8 +1,13 @@ package io.legado.app.ui.main +import android.graphics.drawable.Drawable +import android.os.Build import android.os.Bundle import android.view.KeyEvent import android.view.MenuItem +import android.widget.Toolbar +import androidx.annotation.RequiresApi +import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -26,6 +31,7 @@ import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.view_title_bar.* class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, 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 f51bdc0a6..329c19e85 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 @@ -1,12 +1,15 @@ package io.legado.app.ui.main.bookshelf import android.annotation.SuppressLint +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem import android.view.View import androidx.appcompat.widget.SearchView +import androidx.appcompat.widget.Toolbar +import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 88bb95afe..d948923e8 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -13,7 +13,7 @@ import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey -import io.legado.app.help.AppConfig +import io.legado.app.help.channel import io.legado.app.lib.theme.ATH import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity @@ -79,13 +79,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. observeEvent(EventBus.WEB_SERVICE_STOP) { webServicePre?.isChecked = false } - findPreference(PreferKey.themeMode)?.let { - it.setOnPreferenceChangeListener { _, _ -> - view?.post { App.INSTANCE.applyDayNight() } - true - } - } - if (AppConfig.isGooglePlay) { + if (requireContext().channel == "google") { findPreference("aboutCategory") ?.removePreference(findPreference("donate")) } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 2d45bcd70..4acd423d1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.SubMenu import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -17,6 +18,7 @@ import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_rss_artivles.* import org.jetbrains.anko.startActivityForResult +import java.util.LinkedHashMap class RssSortActivity : VMBaseActivity(R.layout.activity_rss_artivles) { @@ -25,6 +27,8 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a private val editSource = 12319 private val fragments = linkedMapOf() private lateinit var adapter: TabFragmentPageAdapter + private val channels = LinkedHashMap() + private var groupMenu: Menu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { adapter = TabFragmentPageAdapter(supportFragmentManager) @@ -34,6 +38,7 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a title_bar.title = it }) viewModel.initData(intent) { + upChannelMenu() upFragments() } } @@ -43,6 +48,12 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + groupMenu = menu + upChannelMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let { @@ -54,15 +65,44 @@ class RssSortActivity : VMBaseActivity(R.layout.activity_rss_a } } } + if (item.groupId == R.id.source_channel) { + var key = item.title.toString(); + var i = fragments.keys.indexOf(key) + if (i >= 0) + view_pager.currentItem = i + } return super.onCompatOptionsItemSelected(item) } + private fun upChannelMenu() { + // 加入频道列表 + groupMenu?.removeGroup(R.id.source_channel) + var sourceChannel = viewModel.rssSource?.sourceGroup + channels.clear() + sourceChannel?.split("\n\n")?.forEach { c -> + val d = c.split("::") + if (d.size > 1) { + channels[d[0]] = d[1] + var item = groupMenu?.add(R.id.source_channel, Menu.NONE, Menu.NONE, d[0]) + item?.isCheckable = true + var keys = fragments.keys + item?.isChecked = keys.indexOf(d[0]) == view_pager.currentItem + } + } + } + private fun upFragments() { fragments.clear() viewModel.rssSource?.sortUrls()?.forEach { fragments[it.key] = RssArticlesFragment.create(it.key, it.value) } - if (fragments.size == 1) { + var sortUrlsSize = fragments.size + if (sortUrlsSize <= 1) { + channels?.forEach { + fragments[it.key] = RssArticlesFragment.create(it.key, it.value) + } + } + if (sortUrlsSize == 1) { tab_layout.gone() } else { tab_layout.visible() diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt index 6226ab30a..9152be216 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -55,11 +55,17 @@ class Preference(context: Context, attrs: AttributeSet) : iconView.setImageDrawable(icon) iconView.setColorFilter(context.accentColor) } + + val paddingView = it.findViewById(R.id.preference_padding) + if (paddingView != null) { + paddingView.isVisible = view.isVisible && tvSummary != null && tvSummary.isVisible + } } if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) { val lay = it.findViewById(R.id.preference_widget) if (lay is FrameLayout) { + var needRequestLayout = false var v = it.itemView.findViewById(viewId) if (v == null) { val inflater: LayoutInflater = context.layoutInflater @@ -68,7 +74,8 @@ class Preference(context: Context, attrs: AttributeSet) : lay.addView(childView) lay.isVisible = true v = lay.findViewById(viewId) - } + } else + needRequestLayout = true if (weightWidth > 0 || weightHeight > 0) { val lp = lay.layoutParams @@ -79,7 +86,8 @@ class Preference(context: Context, attrs: AttributeSet) : lp.width = (context.resources.displayMetrics.density * weightWidth).roundToInt() lay.layoutParams = lp - } + } else if (needRequestLayout) + v.requestLayout() return v } diff --git a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt index 9f13d543d..9167eda46 100644 --- a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt @@ -19,13 +19,8 @@ fun Menu.applyTint(context: Context, theme: Theme = Theme.Auto): Menu = this.let if (menu is MenuBuilder) { menu.setOptionalIconsVisible(true) } - val primaryTextColor = context.primaryTextColor val defaultTextColor = context.getCompatColor(R.color.tv_text_default) - val tintColor = when (theme) { - Theme.Dark -> context.getCompatColor(R.color.md_white_1000) - Theme.Light -> context.getCompatColor(R.color.md_black_1000) - else -> primaryTextColor - } + val tintColor = UIUtils.getMenuColor(context, theme) menu.forEach { item -> (item as MenuItemImpl).let { impl -> //overflow:展开的item diff --git a/app/src/main/java/io/legado/app/utils/UIUtils.kt b/app/src/main/java/io/legado/app/utils/UIUtils.kt new file mode 100644 index 000000000..9b2db69ff --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/UIUtils.kt @@ -0,0 +1,42 @@ +package io.legado.app.utils + +import android.content.Context +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +import android.os.Build +import androidx.appcompat.widget.Toolbar +import androidx.core.content.ContextCompat +import io.legado.app.R +import io.legado.app.constant.Theme +import io.legado.app.lib.theme.primaryTextColor + +@Suppress("unused") +object UIUtils { + + /** 设置更多工具条图标和颜色 */ + fun setToolbarMoreIconCustomColor(toolbar: Toolbar, color: Int? = null) { + if (toolbar == null) + return + val moreIcon = ContextCompat.getDrawable(toolbar.context, R.drawable.ic_more) + if(moreIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (color != null ) { + moreIcon.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP) + } + toolbar.overflowIcon = moreIcon + } + } + + + fun getMenuColor(context: Context, theme: Theme = Theme.Auto, requiresOverflow: Boolean = false): Int { + val defaultTextColor = context.getCompatColor(R.color.tv_text_default) + if (requiresOverflow) + return defaultTextColor + val primaryTextColor = context.primaryTextColor + return when (theme) { + Theme.Dark -> context.getCompatColor(R.color.md_white_1000) + Theme.Light -> context.getCompatColor(R.color.md_black_1000) + else -> primaryTextColor + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_add.xml b/app/src/main/res/drawable/ic_add.xml index c7542ba87..97328c410 100644 --- a/app/src/main/res/drawable/ic_add.xml +++ b/app/src/main/res/drawable/ic_add.xml @@ -1,11 +1,9 @@ - - - - - \ No newline at end of file + + + diff --git a/app/src/main/res/drawable/ic_add_online.xml b/app/src/main/res/drawable/ic_add_online.xml index 8a3cc9b8b..c7f649fd4 100644 --- a/app/src/main/res/drawable/ic_add_online.xml +++ b/app/src/main/res/drawable/ic_add_online.xml @@ -1,11 +1,15 @@ - - - - - \ No newline at end of file + + + + + diff --git a/app/src/main/res/drawable/ic_arrange.xml b/app/src/main/res/drawable/ic_arrange.xml index ce2d50152..cf0600e77 100644 --- a/app/src/main/res/drawable/ic_arrange.xml +++ b/app/src/main/res/drawable/ic_arrange.xml @@ -1,17 +1,21 @@ - - - - - - - \ No newline at end of file + + + + + + + diff --git a/app/src/main/res/drawable/ic_download_line.xml b/app/src/main/res/drawable/ic_download_line.xml index 3b0ae72ea..7f9bcad59 100644 --- a/app/src/main/res/drawable/ic_download_line.xml +++ b/app/src/main/res/drawable/ic_download_line.xml @@ -1,14 +1,12 @@ - - - - - - \ No newline at end of file + + + + diff --git a/app/src/main/res/drawable/ic_groups.xml b/app/src/main/res/drawable/ic_groups.xml index 0ebcd4526..f79df8df8 100644 --- a/app/src/main/res/drawable/ic_groups.xml +++ b/app/src/main/res/drawable/ic_groups.xml @@ -1,20 +1,9 @@ - - - - - - - - \ No newline at end of file + + + diff --git a/app/src/main/res/drawable/ic_groups_menu.xml b/app/src/main/res/drawable/ic_groups_menu.xml new file mode 100644 index 000000000..165d4b705 --- /dev/null +++ b/app/src/main/res/drawable/ic_groups_menu.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_more.xml b/app/src/main/res/drawable/ic_more.xml new file mode 100644 index 000000000..b0357ce02 --- /dev/null +++ b/app/src/main/res/drawable/ic_more.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_search.xml b/app/src/main/res/drawable/ic_search.xml index 921e00d7a..f207ed0a4 100644 --- a/app/src/main/res/drawable/ic_search.xml +++ b/app/src/main/res/drawable/ic_search.xml @@ -1,17 +1,15 @@ - - - - + + + + + diff --git a/app/src/main/res/drawable/ic_view_quilt.xml b/app/src/main/res/drawable/ic_view_quilt.xml index a0fb3d300..eecbde250 100644 --- a/app/src/main/res/drawable/ic_view_quilt.xml +++ b/app/src/main/res/drawable/ic_view_quilt.xml @@ -1,26 +1,18 @@ - - - - - - - - \ No newline at end of file + + + + + + diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 50bb20d12..f96b8d507 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -61,8 +61,8 @@ android:id="@+id/tv_name" android:layout_width="0dp" android:layout_height="wrap_content" - android:paddingLeft="12dp" - android:paddingRight="12dp" + android:paddingLeft="4dp" + android:paddingRight="4dp" android:paddingBottom="4dp" android:includeFontPadding="false" android:gravity="top|center_horizontal" diff --git a/app/src/main/res/layout/item_bookshelf_list.xml b/app/src/main/res/layout/item_bookshelf_list.xml index b381aaa90..3d6f71213 100644 --- a/app/src/main/res/layout/item_bookshelf_list.xml +++ b/app/src/main/res/layout/item_bookshelf_list.xml @@ -14,8 +14,8 @@ android:layout_width="60dp" android:layout_height="80dp" android:layout_marginStart="16dp" - android:layout_marginTop="12dp" - android:layout_marginBottom="8dp" + android:layout_marginTop="16dp" + android:layout_marginBottom="12dp" android:contentDescription="@string/img_cover" android:scaleType="centerCrop" android:src="@drawable/image_cover_default" @@ -56,10 +56,11 @@ android:id="@+id/tv_name" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginLeft="8dp" - android:layout_marginTop="8dp" + android:layout_marginLeft="10dp" + android:layout_marginTop="12dp" android:includeFontPadding="false" - android:paddingLeft="4dp" + android:paddingBottom="4dp" + android:paddingLeft="2dp" android:singleLine="true" android:text="@string/book_name" android:textColor="@color/tv_text_default" @@ -74,15 +75,14 @@ android:id="@+id/iv_author" android:layout_width="@dimen/desc_icon_size" android:layout_height="@dimen/desc_icon_size" - android:layout_marginLeft="8dp" android:contentDescription="@string/author" android:paddingStart="2dp" android:paddingEnd="2dp" android:src="@drawable/ic_author" app:layout_constraintBottom_toBottomOf="@+id/tv_author" - app:layout_constraintLeft_toRightOf="@+id/iv_cover" + app:layout_constraintLeft_toLeftOf="@+id/tv_name" app:layout_constraintTop_toTopOf="@+id/tv_author" - app:tint="@color/tv_text_secondary" + app:tint="@color/tv_text_summary" tools:ignore="RtlHardcoded,RtlSymmetry" /> - \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml index b06e2e37b..f3765bf58 100644 --- a/app/src/main/res/layout/item_rss.xml +++ b/app/src/main/res/layout/item_rss.xml @@ -20,6 +20,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" + android:textSize="13sp" + android:gravity="top|center_horizontal" + android:lines="2" + android:ellipsize="end" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/iv_icon" /> diff --git a/app/src/main/res/layout/view_preference.xml b/app/src/main/res/layout/view_preference.xml index f825afe26..acae86b8e 100644 --- a/app/src/main/res/layout/view_preference.xml +++ b/app/src/main/res/layout/view_preference.xml @@ -28,6 +28,7 @@ android:orientation="vertical" android:layout_weight="1.0" android:layout_width="0dp" + android:layout_gravity="center_vertical" android:layout_height="wrap_content"> + + diff --git a/app/src/main/res/menu/rss_articles.xml b/app/src/main/res/menu/rss_articles.xml index 03d187bcd..831b908a5 100644 --- a/app/src/main/res/menu/rss_articles.xml +++ b/app/src/main/res/menu/rss_articles.xml @@ -12,4 +12,8 @@ android:title="@string/clear" app:showAsAction="never" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index c7eb91ae9..8ac7aa66a 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -7,7 +7,7 @@ @color/md_grey_900 @color/md_grey_850 @color/md_grey_800 - #AA111111 + #10303030 #69000000 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 8d6199035..d74c3a850 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -16,7 +16,7 @@ @color/md_grey_50 @color/md_grey_100 @color/md_grey_200 - #AAFFFFFF + #7fffffff #00000000 #10000000 diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 94bef734c..5b4af51f5 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -12,6 +12,15 @@ app:icons="@array/icons" app:iconSpaceReserved="false" /> + + - - - @@ -86,15 +75,15 @@