parent
2589cb2e30
commit
f1c23387c0
@ -1,51 +0,0 @@ |
||||
package io.legado.app.ui.about |
||||
|
||||
import android.content.Intent |
||||
import android.net.Uri |
||||
import android.os.Bundle |
||||
import android.view.View |
||||
import androidx.preference.Preference |
||||
import androidx.preference.PreferenceFragmentCompat |
||||
import io.legado.app.App |
||||
import io.legado.app.R |
||||
import io.legado.app.utils.shareText |
||||
import io.legado.app.utils.toast |
||||
|
||||
class AboutFragment : PreferenceFragmentCompat() { |
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
||||
addPreferencesFromResource(R.xml.about) |
||||
findPreference<Preference>("check_update")?.summary = getString(R.string.version) + " " + App.INSTANCE.versionName |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
listView.overScrollMode = View.OVER_SCROLL_NEVER |
||||
} |
||||
|
||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean { |
||||
when (preference?.key) { |
||||
"contributors" -> openIntent(Intent.ACTION_VIEW, getString(R.string.contributors_url)) |
||||
"update_log" -> UpdateLog().show(childFragmentManager, "update_log") |
||||
"check_update" -> openIntent(Intent.ACTION_VIEW, getString(R.string.latest_release_url)) |
||||
"mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com") |
||||
"git" -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url)) |
||||
"home_page" -> openIntent(Intent.ACTION_VIEW, getString(R.string.home_page_url)) |
||||
"share_app" -> activity?.shareText( |
||||
"App Share", |
||||
getString(R.string.app_share_description) |
||||
) |
||||
} |
||||
return super.onPreferenceTreeClick(preference) |
||||
} |
||||
|
||||
private fun openIntent(intentName: String, address: String) { |
||||
try { |
||||
val intent = Intent(intentName) |
||||
intent.data = Uri.parse(address) |
||||
startActivity(intent) |
||||
} catch (e: Exception) { |
||||
toast(R.string.can_not_open) |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,134 @@ |
||||
package io.legado.app.ui.about |
||||
|
||||
import android.graphics.drawable.Drawable |
||||
import android.os.Build |
||||
import android.text.Html |
||||
|
||||
import androidx.annotation.DrawableRes |
||||
import androidx.annotation.StringRes |
||||
|
||||
class ActionItem(builder: Builder) { |
||||
var onClickAction: ActionListener? = null |
||||
internal set |
||||
var onLongClickAction: ActionListener? = null |
||||
internal set |
||||
var text: CharSequence? = null |
||||
@StringRes |
||||
var textRes = 0 |
||||
var subText: CharSequence? = null |
||||
@StringRes |
||||
var subTextRes = 0 |
||||
var icon: Drawable? = null |
||||
@DrawableRes |
||||
var iconRes = 0 |
||||
private var showIcon = true |
||||
|
||||
init { |
||||
this.text = builder.text |
||||
this.textRes = builder.textRes |
||||
|
||||
this.subText = builder.subText |
||||
this.subTextRes = builder.subTextRes |
||||
|
||||
this.icon = builder.icon |
||||
this.iconRes = builder.iconRes |
||||
this.showIcon = builder.showIcon |
||||
|
||||
this.onClickAction = builder.onClickAction |
||||
this.onLongClickAction = builder.onLongClickAction |
||||
} |
||||
|
||||
fun shouldShowIcon(): Boolean { |
||||
return showIcon |
||||
} |
||||
|
||||
class Builder { |
||||
internal var onClickAction: ActionListener? = null |
||||
internal var onLongClickAction: ActionListener? = null |
||||
internal var text: CharSequence? = null |
||||
@StringRes |
||||
internal var textRes = 0 |
||||
internal var subText: CharSequence? = null |
||||
@StringRes |
||||
internal var subTextRes = 0 |
||||
internal var icon: Drawable? = null |
||||
@DrawableRes |
||||
internal var iconRes = 0 |
||||
internal var showIcon = true |
||||
|
||||
fun text(text: CharSequence): Builder { |
||||
this.text = text |
||||
this.textRes = 0 |
||||
return this |
||||
} |
||||
|
||||
fun text(@StringRes text: Int): Builder { |
||||
this.textRes = text |
||||
this.text = null |
||||
return this |
||||
} |
||||
|
||||
fun text(textHtml: String): Builder { |
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
||||
this.text = Html.fromHtml(textHtml, Html.FROM_HTML_MODE_LEGACY) |
||||
} else { |
||||
this.text = Html.fromHtml(textHtml) |
||||
} |
||||
this.textRes = 0 |
||||
return this |
||||
} |
||||
|
||||
fun subText(subText: CharSequence): Builder { |
||||
this.subText = subText |
||||
this.subTextRes = 0 |
||||
return this |
||||
} |
||||
|
||||
fun subText(@StringRes subTextRes: Int): Builder { |
||||
this.subText = null |
||||
this.subTextRes = subTextRes |
||||
return this |
||||
} |
||||
|
||||
fun subTextHtml(subTextHtml: String): Builder { |
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
||||
this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY) |
||||
} else { |
||||
this.subText = Html.fromHtml(subTextHtml) |
||||
} |
||||
this.subTextRes = 0 |
||||
return this |
||||
} |
||||
|
||||
fun icon(icon: Drawable): Builder { |
||||
this.icon = icon |
||||
this.iconRes = 0 |
||||
return this |
||||
} |
||||
|
||||
fun icon(@DrawableRes iconRes: Int): Builder { |
||||
this.icon = null |
||||
this.iconRes = iconRes |
||||
return this |
||||
} |
||||
|
||||
fun showIcon(showIcon: Boolean): Builder { |
||||
this.showIcon = showIcon |
||||
return this |
||||
} |
||||
|
||||
fun setOnClickAction(onClickAction: ActionListener): Builder { |
||||
this.onClickAction = onClickAction |
||||
return this |
||||
} |
||||
|
||||
fun setOnLongClickAction(onLongClickAction: ActionListener): Builder { |
||||
this.onLongClickAction = onLongClickAction |
||||
return this |
||||
} |
||||
|
||||
fun build(): ActionItem { |
||||
return ActionItem(this) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,111 @@ |
||||
package io.legado.app.ui.about |
||||
|
||||
import android.content.Context |
||||
import android.util.TypedValue |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.View.GONE |
||||
import android.view.ViewGroup |
||||
import android.widget.ImageView |
||||
import android.widget.TextView |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import com.drakeet.multitype.ItemViewBinder |
||||
import io.legado.app.R |
||||
|
||||
class ActionItemViewBinder(private val context: Context) : |
||||
ItemViewBinder<ActionItem, ActionItemViewBinder.ViewHolder>() { |
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, item: ActionItem) { |
||||
val text = item.text |
||||
val textRes = item.textRes |
||||
|
||||
holder.text.visibility = View.VISIBLE |
||||
when { |
||||
text != null -> { |
||||
holder.text.text = text |
||||
holder.text.setLineSpacing(0f, holder.text.lineSpacingMultiplier) |
||||
} |
||||
textRes != 0 -> { |
||||
holder.text.setText(textRes) |
||||
holder.text.setLineSpacing(0f, holder.text.lineSpacingMultiplier) |
||||
} |
||||
else -> holder.text.visibility = GONE |
||||
} |
||||
|
||||
val subText = item.subText |
||||
val subTextRes = item.subTextRes |
||||
|
||||
holder.subText.visibility = View.VISIBLE |
||||
when { |
||||
subText != null -> holder.subText.text = subText |
||||
subTextRes != 0 -> holder.subText.setText(subTextRes) |
||||
else -> holder.subText.visibility = GONE |
||||
} |
||||
|
||||
if (item.shouldShowIcon()) { |
||||
holder.icon.visibility = View.VISIBLE |
||||
val drawable = item.icon |
||||
val drawableRes = item.iconRes |
||||
if (drawable != null) { |
||||
holder.icon.setImageDrawable(drawable) |
||||
} else if (drawableRes != 0) { |
||||
holder.icon.setImageResource(drawableRes) |
||||
} |
||||
} else { |
||||
holder.icon.visibility = GONE |
||||
} |
||||
|
||||
if (item.onClickAction != null || item.onLongClickAction != null) { |
||||
val outValue = TypedValue() |
||||
context.theme.resolveAttribute( |
||||
R.attr.selectableItemBackground, |
||||
outValue, |
||||
true |
||||
) |
||||
holder.view.setBackgroundResource(outValue.resourceId) |
||||
} else { |
||||
holder.view.setBackgroundResource(0) |
||||
} |
||||
holder.setOnClickAction(item.onClickAction) |
||||
holder.setOnLongClickAction(item.onLongClickAction) |
||||
} |
||||
|
||||
override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder { |
||||
return ViewHolder( |
||||
inflater.inflate(R.layout.about_page_action_item, parent, false) |
||||
) |
||||
} |
||||
|
||||
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view), View.OnClickListener, |
||||
View.OnLongClickListener { |
||||
val icon: ImageView = view.findViewById(R.id.mal_item_image) |
||||
val text: TextView = view.findViewById(R.id.mal_item_text) |
||||
val subText: TextView = view.findViewById(R.id.mal_action_item_subtext) |
||||
private var onClickAction: ActionListener? = null |
||||
private var onLongClickAction: ActionListener? = null |
||||
|
||||
fun setOnClickAction(onClickAction: ActionListener?) { |
||||
this.onClickAction = onClickAction |
||||
view.setOnClickListener(if (onClickAction != null) this else null) |
||||
} |
||||
|
||||
fun setOnLongClickAction(onLongClickAction: ActionListener?) { |
||||
this.onLongClickAction = onLongClickAction |
||||
view.setOnLongClickListener(if (onLongClickAction != null) this else null) |
||||
} |
||||
|
||||
override fun onClick(v: View) { |
||||
if (onClickAction != null) { |
||||
onClickAction!!.action() |
||||
} |
||||
} |
||||
|
||||
override fun onLongClick(v: View): Boolean { |
||||
if (onLongClickAction != null) { |
||||
onLongClickAction!!.action() |
||||
return true |
||||
} |
||||
return false |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,5 @@ |
||||
package io.legado.app.ui.about |
||||
|
||||
interface ActionListener { |
||||
fun action() |
||||
} |
@ -0,0 +1,5 @@ |
||||
package io.legado.app.ui.about |
||||
|
||||
import androidx.annotation.StringRes |
||||
|
||||
class Category(val title: String? = null, @StringRes val titleRes: Int = 0) |
@ -0,0 +1,41 @@ |
||||
package io.legado.app.ui.about |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import android.widget.TextView |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import com.drakeet.multitype.ItemViewBinder |
||||
import io.legado.app.R |
||||
import io.legado.app.lib.theme.ColorUtils |
||||
import io.legado.app.lib.theme.accentColor |
||||
import io.legado.app.lib.theme.backgroundColor |
||||
import org.jetbrains.anko.backgroundColor |
||||
import org.jetbrains.anko.textColor |
||||
|
||||
class CategoryViewBinder : ItemViewBinder<Category, CategoryViewBinder.ViewHolder>() { |
||||
|
||||
override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder { |
||||
return ViewHolder(inflater.inflate(R.layout.about_page_item_category, parent, false)) |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, item: Category) { |
||||
val title = item.title |
||||
val titleRes = item.titleRes |
||||
when { |
||||
title != null -> holder.category.text = title |
||||
titleRes != 0 -> holder.category.setText(titleRes) |
||||
} |
||||
holder.category.text = item.title |
||||
} |
||||
|
||||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||
|
||||
var category: TextView = itemView.findViewById(R.id.category) |
||||
|
||||
init { |
||||
category.textColor = itemView.context.accentColor |
||||
itemView.backgroundColor = ColorUtils.darkenColor(itemView.context.backgroundColor) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingTop="@dimen/about_page_baseline_half" |
||||
android:paddingBottom="@dimen/about_page_baseline_half" |
||||
android:paddingEnd="@dimen/about_page_baseline" |
||||
android:paddingStart="@dimen/about_page_baseline" |
||||
android:paddingRight="@dimen/about_page_baseline" |
||||
android:orientation="horizontal" |
||||
android:paddingLeft="@dimen/about_page_baseline"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/mal_item_image" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:minWidth="@dimen/about_page_action_item_image_width" |
||||
android:minHeight="@dimen/about_page_action_item_image_height" |
||||
android:layout_gravity="center" |
||||
android:layout_marginEnd="@dimen/about_page_baseline" |
||||
android:adjustViewBounds="false" |
||||
android:contentDescription="@null" |
||||
android:cropToPadding="false" |
||||
android:scaleType="centerInside" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:minHeight="@dimen/about_page_action_item_image_height" |
||||
android:layout_gravity="center_vertical" |
||||
android:gravity="center_vertical" |
||||
android:layout_weight="1" |
||||
android:orientation="vertical"> |
||||
|
||||
<TextView |
||||
style="@style/AboutPage.Item.MainContent" |
||||
android:id="@+id/mal_item_text" |
||||
tools:text="Version" /> |
||||
|
||||
<TextView |
||||
style="@style/AboutPage.Item.SubContent" |
||||
android:id="@+id/mal_action_item_subtext" |
||||
android:visibility="gone" |
||||
tools:visibility="visible" |
||||
tools:text="Current Version Of App" /> |
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
@ -0,0 +1,10 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/category" |
||||
style="@style/AboutPage.Item.Category" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
tools:text="value"> |
||||
|
||||
</TextView> |
@ -0,0 +1,68 @@ |
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" > |
||||
|
||||
<com.google.android.material.appbar.AppBarLayout |
||||
android:id="@+id/headerLayout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="@dimen/about_page_header_height" > |
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout |
||||
android:id="@+id/collapsingToolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
app:contentScrim="?attr/colorPrimary" |
||||
app:scrimAnimationDuration="500" |
||||
app:expandedTitleTextAppearance="@style/AboutPage.Header.ToolbarTitleExpanded" |
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/headerContentLayout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" |
||||
android:gravity="center" |
||||
app:layout_collapseMode="parallax"> |
||||
|
||||
<ImageView |
||||
style="@style/AboutPage.Header.Icon" |
||||
android:id="@+id/icon" |
||||
tools:ignore="ContentDescription" |
||||
tools:src="#000000"/> |
||||
|
||||
<TextView |
||||
style="@style/AboutPage.Header.Slogan" |
||||
android:id="@+id/slogan"/> |
||||
|
||||
<TextView |
||||
style="@style/AboutPage.Header.Version" |
||||
android:id="@+id/version" |
||||
tools:text="Version 1.2.3"/> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<androidx.appcompat.widget.Toolbar |
||||
android:id="@+id/toolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="?attr/actionBarSize" |
||||
android:theme="?attr/actionBarStyle" |
||||
app:layout_collapseMode="pin"/> |
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout> |
||||
|
||||
</com.google.android.material.appbar.AppBarLayout> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recyclerView" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:paddingBottom="@dimen/about_page_baseline" |
||||
android:clipToPadding="false" |
||||
android:descendantFocusability="beforeDescendants" |
||||
app:layoutManager="LinearLayoutManager" |
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/> |
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
@ -1,9 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
<item |
||||
android:id="@+id/menu_scoring" |
||||
android:title="@string/scoring" |
||||
app:showAsAction="always" /> |
||||
</menu> |
@ -1,51 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="contributors" |
||||
android:title="开发人员" |
||||
android:summary="gedoor,Invinciblelee等, 详情请在github中查看" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="check_update" |
||||
android:title="@string/check_update" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="update_log" |
||||
android:title="@string/update_log" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="qq" |
||||
android:title="@string/join_qq_group" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="mail" |
||||
android:title="@string/send_mail" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="git" |
||||
android:title="@string/git_hub" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="home_page" |
||||
android:title="@string/home_page" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="share_app" |
||||
android:title="@string/share_app" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="disclaimer" |
||||
android:title="@string/disclaimer" |
||||
app:iconSpaceReserved="false" /> |
||||
|
||||
</androidx.preference.PreferenceScreen> |
Loading…
Reference in new issue