From 6e97e11435c22e2c5e26d660d14dd2bda61275b0 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Fri, 20 Mar 2020 13:34:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=88=91=E7=9A=84UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/config/ThemeConfigFragment.kt | 7 +++++++ .../main/java/io/legado/app/ui/main/my/MyFragment.kt | 6 ------ .../java/io/legado/app/ui/widget/prefs/Preference.kt | 12 ++++++++++-- app/src/main/res/layout/view_preference.xml | 12 +++++++----- app/src/main/res/values/colors.xml | 2 +- app/src/main/res/xml/pref_config_read.xml | 2 +- app/src/main/res/xml/pref_config_theme.xml | 9 +++++++++ app/src/main/res/xml/pref_main.xml | 11 ----------- 8 files changed, 35 insertions(+), 26 deletions(-) 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/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index f3087f5e7..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 @@ -79,12 +79,6 @@ 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 (requireContext().channel == "google") { findPreference("aboutCategory") ?.removePreference(findPreference("donate")) 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 0190dcd9f..4bd3610b5 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 @@ -44,11 +44,17 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr 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 @@ -57,7 +63,8 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr lay.addView(childView) lay.isVisible = true v = lay.findViewById(viewId) - } + } else + needRequestLayout = true if (weightWidth > 0 || weightHeight > 0) { val lp = lay.layoutParams @@ -66,7 +73,8 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr if (weightWidth > 0) lp.width = (context.resources.displayMetrics.density * weightWidth).roundToInt() lay.layoutParams = lp - } + } else if (needRequestLayout) + v.requestLayout() return v } diff --git a/app/src/main/res/layout/view_preference.xml b/app/src/main/res/layout/view_preference.xml index 87b10ef5b..2b67899f9 100644 --- a/app/src/main/res/layout/view_preference.xml +++ b/app/src/main/res/layout/view_preference.xml @@ -7,7 +7,7 @@ android:paddingLeft="16dp" android:paddingTop="10dp" android:paddingRight="16dp" - android:paddingBottom="4dp" + android:paddingBottom="10dp" android:minHeight="42dp" android:clickable="true" android:orientation="horizontal" @@ -27,11 +27,11 @@ android:orientation="vertical" android:layout_weight="1.0" android:layout_width="0dp" + android:layout_gravity="center_vertical" android:layout_height="wrap_content"> + + @color/md_grey_50 @color/md_grey_100 @color/md_grey_200 - @color/md_grey_50 + #7fffffff #00000000 #10000000 diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index ef360b43c..6be6d1e50 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -60,7 +60,7 @@ android:key="selectText" app:iconSpaceReserved="false" /> - diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index bf90dd7ab..ef95487f9 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" /> + + - - From 764bb1b624f92cea76fdc5d5fbc30f06f358e704 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Fri, 20 Mar 2020 14:42:51 +0800 Subject: [PATCH 2/5] =?UTF-8?q?UI=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/drawable/ic_search.xml | 29 +++++++--------- .../main/res/layout/item_bookshelf_grid.xml | 4 +-- .../main/res/layout/item_bookshelf_list.xml | 34 +++++++++---------- app/src/main/res/layout/item_rss.xml | 4 +++ 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/app/src/main/res/drawable/ic_search.xml b/app/src/main/res/drawable/ic_search.xml index 921e00d7a..b6805e004 100644 --- a/app/src/main/res/drawable/ic_search.xml +++ b/app/src/main/res/drawable/ic_search.xml @@ -1,17 +1,12 @@ - - - - + + + + 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..d715009d6 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="16dp" + 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" /> From 1ece88762e4dffcb5224a72a77021257484d93b0 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Fri, 20 Mar 2020 15:59:39 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainActivity.kt | 6 +++ .../ui/main/bookshelf/BookshelfFragment.kt | 4 ++ .../main/java/io/legado/app/utils/UIUtils.kt | 27 ++++++++++++ app/src/main/res/drawable/ic_add.xml | 20 ++++----- app/src/main/res/drawable/ic_add_online.xml | 26 ++++++----- app/src/main/res/drawable/ic_arrange.xml | 38 +++++++++------- .../main/res/drawable/ic_download_line.xml | 26 +++++------ app/src/main/res/drawable/ic_groups.xml | 29 ++++-------- app/src/main/res/drawable/ic_more.xml | 15 +++++++ app/src/main/res/drawable/ic_search.xml | 17 ++++--- app/src/main/res/drawable/ic_view_quilt.xml | 44 ++++++++----------- .../main/res/layout/item_bookshelf_list.xml | 9 +--- 12 files changed, 147 insertions(+), 114 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/UIUtils.kt create mode 100644 app/src/main/res/drawable/ic_more.xml 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 0aa49ede7..859f63d9e 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 @@ -25,6 +30,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 55dca8d77..ec3debf64 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 @@ -58,6 +61,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b setSupportToolbar(toolbar) initView() initBookGroupData() + UIUtils.setToolbarMoreIconCustomColor(toolbar) } override fun onCompatCreateOptionsMenu(menu: Menu) { 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..e5ffa1881 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/UIUtils.kt @@ -0,0 +1,27 @@ +package io.legado.app.utils + +import android.graphics.ColorFilter +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 + +@Suppress("unused") +object UIUtils { + + /** 设置更多工具条图标和颜色 */ + fun setToolbarMoreIconCustomColor(toolbar: Toolbar, colorId: 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 (colorId != null ) { + moreIcon.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(toolbar.context, colorId), PorterDuff.Mode.SRC_ATOP) + } + toolbar.overflowIcon = moreIcon + } + } + +} \ 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..165d4b705 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_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 b6805e004..f207ed0a4 100644 --- a/app/src/main/res/drawable/ic_search.xml +++ b/app/src/main/res/drawable/ic_search.xml @@ -1,12 +1,15 @@ + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + android:pathData="M11,5.49A5.49,5.49 0,1 1,7.1 7.1,5.44 5.44,0 0,1 11,5.49M11,4a7,7 0,1 0,4.94 2A7,7 0,0 0,11 4Z" + android:fillColor="#202020"/> + + android:pathData="M17.14,16.39a0.74,0.74 0,0 0,-0.53 0.22,0.75 0.75,0 0,0 0,1.06l2.11,2.11a0.74,0.74 0,0 0,0.53 0.22,0.73 0.73,0 0,0 0.53,-0.22 0.75,0.75 0,0 0,0 -1.06l-2.11,-2.11a0.74,0.74 0,0 0,-0.53 -0.22Z"/> 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_list.xml b/app/src/main/res/layout/item_bookshelf_list.xml index d715009d6..3d6f71213 100644 --- a/app/src/main/res/layout/item_bookshelf_list.xml +++ b/app/src/main/res/layout/item_bookshelf_list.xml @@ -56,7 +56,7 @@ android:id="@+id/tv_name" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginLeft="16dp" + android:layout_marginLeft="10dp" android:layout_marginTop="12dp" android:includeFontPadding="false" android:paddingBottom="4dp" @@ -175,12 +175,5 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" /> - \ No newline at end of file From b758beaf0980676698a603ec89c8154187b7c945 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Fri, 20 Mar 2020 16:42:52 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=B0=83=E6=95=B4UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/BaseFragment.kt | 5 ++++ .../ui/main/bookshelf/BookshelfFragment.kt | 1 - .../io/legado/app/utils/MenuExtensions.kt | 7 +----- .../main/java/io/legado/app/utils/UIUtils.kt | 23 +++++++++++++++---- app/src/main/res/drawable/ic_groups.xml | 12 +++++----- app/src/main/res/drawable/ic_groups_menu.xml | 9 ++++++++ app/src/main/res/menu/main_bookshelf.xml | 2 +- 7 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 app/src/main/res/drawable/ic_groups_menu.xml 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/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index ec3debf64..5cf6de284 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 @@ -61,7 +61,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b setSupportToolbar(toolbar) initView() initBookGroupData() - UIUtils.setToolbarMoreIconCustomColor(toolbar) } override fun onCompatCreateOptionsMenu(menu: Menu) { 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 index e5ffa1881..9b2db69ff 100644 --- a/app/src/main/java/io/legado/app/utils/UIUtils.kt +++ b/app/src/main/java/io/legado/app/utils/UIUtils.kt @@ -1,27 +1,42 @@ package io.legado.app.utils -import android.graphics.ColorFilter +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, colorId: Int? = null) { + 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 (colorId != null ) { - moreIcon.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(toolbar.context, colorId), PorterDuff.Mode.SRC_ATOP) + 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_groups.xml b/app/src/main/res/drawable/ic_groups.xml index 165d4b705..f79df8df8 100644 --- a/app/src/main/res/drawable/ic_groups.xml +++ b/app/src/main/res/drawable/ic_groups.xml @@ -1,9 +1,9 @@ + android:width="16dp" + android:height="16dp" + android:viewportWidth="16" + android:viewportHeight="16"> + android:fillColor="#FF000000" + android:pathData="M15,0L6.15,0a1,1 0,0 0,-1 1L5.15,2.25L1,2.25a1,1 0,0 0,-1 1v9.5a1,1 0,0 0,1 1L5.17,13.75L5.17,15a1,1 0,0 0,1 1L15,16a1,1 0,0 0,1 -1L16,11a1,1 0,0 0,-1 -1L6.15,10a1,1 0,0 0,-1 1v1.25L1.48,12.25L1.48,3.75L5.17,3.75L5.17,5a1,1 0,0 0,1 1L15,6a1,1 0,0 0,1 -1L16,1a1,1 0,0 0,-1 -1ZM6.65,4.5v-3h7.87v3ZM6.65,14.5v-3h7.87v3Z"/> 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/menu/main_bookshelf.xml b/app/src/main/res/menu/main_bookshelf.xml index 1c63a7629..867eab0f4 100644 --- a/app/src/main/res/menu/main_bookshelf.xml +++ b/app/src/main/res/menu/main_bookshelf.xml @@ -28,7 +28,7 @@ From f4effb2ca7c0b035c5e53a48f6ec73c7d0db8b54 Mon Sep 17 00:00:00 2001 From: yangyxd Date: Wed, 6 May 2020 17:40:17 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=86=E5=88=ABrss?= =?UTF-8?q?=E5=88=86=E7=BB=84=E4=B8=AD=E7=9A=84=E9=A2=91=E9=81=93=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=9C=A8=E8=8F=9C=E5=8D=95=E4=B8=AD=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=88=87=E6=8D=A2=E9=A2=91=E9=81=93=EF=BC=88=E4=B8=8E?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84sortUrls=E4=B8=8D=E5=86=B2=E7=AA=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/rss/article/RssSortActivity.kt | 42 ++++++++++++++++++- app/src/main/res/menu/rss_articles.xml | 4 ++ 2 files changed, 45 insertions(+), 1 deletion(-) 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/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