pref: 优化透明主题界面
This commit is contained in:
parent
5dc4d6d107
commit
e78f29223a
|
|
@ -20,6 +20,7 @@ import android.widget.TextView
|
|||
import androidx.annotation.CallSuper
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.Keep
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import butterknife.ButterKnife
|
||||
import cn.jzvd.Jzvd
|
||||
|
|
@ -67,6 +68,16 @@ abstract class BaseActivity : SwipeBackActivity(), ExtraRefreshable, CoroutineSc
|
|||
return false
|
||||
}
|
||||
|
||||
fun showDialog(builder: AlertDialog.Builder.() -> Unit): AlertDialog {
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.apply(builder)
|
||||
.create()
|
||||
if (isActivityRunning) {
|
||||
dialog.show()
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
VoicePlayerView.Manager.release()
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ import android.net.Uri
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.SeekBar
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.palette.graphics.Palette
|
||||
|
|
@ -26,6 +27,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.request.target.CustomTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
import com.huanchengfly.tieba.post.*
|
||||
import com.huanchengfly.tieba.post.BaseApplication.Companion.translucentBackground
|
||||
|
|
@ -81,9 +83,18 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
@BindView(R.id.button_back)
|
||||
lateinit var backBtn: View
|
||||
|
||||
@BindView(R.id.bottom_sheet)
|
||||
lateinit var bottomSheet: LinearLayout
|
||||
|
||||
@BindView(R.id.button_finish)
|
||||
lateinit var finishBtn: View
|
||||
|
||||
@BindView(R.id.mask)
|
||||
lateinit var maskView: View
|
||||
|
||||
@BindView(R.id.experimental_tip)
|
||||
lateinit var experimentalTipView: View
|
||||
|
||||
@BindView(R.id.color_theme)
|
||||
lateinit var colorTheme: ViewGroup
|
||||
|
||||
|
|
@ -230,8 +241,17 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
@SuppressLint("ApplySharedPref", "ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
(findViewById(R.id.tip) as TextView).apply {
|
||||
text = HtmlCompat.fromHtml(getString(R.string.tip_translucent_theme), HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||
experimentalTipView.setOnClickListener {
|
||||
showDialog {
|
||||
setTitle(R.string.title_translucent_theme_experimental_feature)
|
||||
setMessage(
|
||||
HtmlCompat.fromHtml(
|
||||
getString(R.string.tip_translucent_theme),
|
||||
HtmlCompat.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
)
|
||||
setNegativeButton(R.string.btn_close, null)
|
||||
}
|
||||
}
|
||||
listOf(
|
||||
findViewById(R.id.custom_color),
|
||||
|
|
@ -267,7 +287,7 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
ThemeUtils.refreshUI(this)
|
||||
}
|
||||
(findViewById(R.id.select_color_recycler_view) as RecyclerView).apply {
|
||||
addItemDecoration(HorizontalSpacesDecoration(0, 0, 16.dpToPx(), 16.dpToPx(), false))
|
||||
addItemDecoration(HorizontalSpacesDecoration(0, 0, 12.dpToPx(), 12.dpToPx(), false))
|
||||
layoutManager = MyLinearLayoutManager(
|
||||
this@TranslucentThemeActivity,
|
||||
MyLinearLayoutManager.HORIZONTAL,
|
||||
|
|
@ -292,6 +312,25 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
mUri = Uri.fromFile(file)
|
||||
invalidateFinishBtn()
|
||||
}
|
||||
val bottomSheetBehavior =
|
||||
(bottomSheet.layoutParams as CoordinatorLayout.LayoutParams).behavior as BottomSheetBehavior
|
||||
bottomSheetBehavior.addBottomSheetCallback(object :
|
||||
BottomSheetBehavior.BottomSheetCallback() {
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {}
|
||||
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
maskView.alpha = slideOffset
|
||||
maskView.visibility = if (slideOffset < 0.01f) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
maskView.setOnClickListener {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
refreshBackground()
|
||||
refreshTheme()
|
||||
fetchWallpapers()
|
||||
|
|
@ -308,7 +347,6 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onColorSelected(dialogId: Int, color: Int) {
|
||||
appPreferences.translucentPrimaryColor = toString(color)
|
||||
ThemeUtils.refreshUI(this)
|
||||
|
|
@ -316,7 +354,6 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
|
||||
override fun onDialogDismissed(dialogId: Int) {}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.select_color -> return true
|
||||
|
|
@ -351,7 +388,7 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
|||
})
|
||||
}
|
||||
|
||||
fun invalidateFinishBtn() {
|
||||
private fun invalidateFinishBtn() {
|
||||
if (mUri != null) {
|
||||
finishBtn.visibility = View.VISIBLE
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ import kotlinx.coroutines.Deferred
|
|||
import retrofit2.http.GET
|
||||
|
||||
interface LiteApiInterface {
|
||||
@GET("https://raw.githubusercontent.com/HuanCheng65/huancheng65.github.io/master/TiebaLite/wallpapers.json")
|
||||
@GET("https://huancheng65.github.io/TiebaLite/wallpapers.json")
|
||||
fun wallpapersAsync(): Deferred<ApiResult<List<String>>>
|
||||
}
|
||||
|
|
@ -43,11 +43,14 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
@BindView(R.id.recycler_view)
|
||||
lateinit var mRecyclerView: RecyclerView
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.refresh)
|
||||
var mRefreshLayout: SmartRefreshLayout? = null
|
||||
lateinit var mRefreshLayout: SmartRefreshLayout
|
||||
|
||||
private val virtualLayoutManager: VirtualLayoutManager by lazy { VirtualLayoutManager(attachContext) }
|
||||
private val virtualLayoutManager: VirtualLayoutManager by lazy {
|
||||
VirtualLayoutManager(
|
||||
attachContext
|
||||
)
|
||||
}
|
||||
private val delegateAdapter: DelegateAdapter by lazy { DelegateAdapter(virtualLayoutManager) }
|
||||
private lateinit var forumAdapter: NewForumAdapter
|
||||
private lateinit var forumTopsLayoutAdapter: ForumTopsLayoutAdapter
|
||||
|
|
@ -57,13 +60,13 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
if (preload) {
|
||||
PreLoader.listenData<ForumPageBean>(preloadId, DataHolder())
|
||||
} else if (mDataBean == null) {
|
||||
mRefreshLayout?.autoRefresh()
|
||||
mRefreshLayout.autoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFragmentVisibleChange(isVisible: Boolean) {
|
||||
if (isVisible && mDataBean == null) {
|
||||
mRefreshLayout?.autoRefresh()
|
||||
mRefreshLayout.autoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +120,7 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
goodClassifyLayoutAdapter.adapter.onSwitchListener = this
|
||||
}
|
||||
|
||||
public override fun getLayoutId(): Int {
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.fragment_forum
|
||||
}
|
||||
|
||||
|
|
@ -142,8 +145,8 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mRefreshLayout!!.setOnRefreshListener { refresh() }
|
||||
mRefreshLayout!!.setOnLoadMoreListener { loadMore() }
|
||||
mRefreshLayout.setOnRefreshListener { refresh() }
|
||||
mRefreshLayout.setOnLoadMoreListener { loadMore() }
|
||||
mRecyclerView.apply {
|
||||
layoutManager = virtualLayoutManager
|
||||
adapter = delegateAdapter
|
||||
|
|
@ -169,19 +172,23 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
}
|
||||
|
||||
private fun loadMore() {
|
||||
TiebaApi.getInstance().forumPage(forumName!!, page + 1, sortType, classifyId).enqueue(object : Callback<ForumPageBean> {
|
||||
TiebaApi.getInstance().forumPage(forumName!!, page + 1, sortType, classifyId)
|
||||
.enqueue(object : Callback<ForumPageBean> {
|
||||
override fun onFailure(call: Call<ForumPageBean>, t: Throwable) {
|
||||
mRefreshLayout?.finishLoadMore(false)
|
||||
mRefreshLayout.finishLoadMore(false)
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call<ForumPageBean>, response: Response<ForumPageBean>) {
|
||||
override fun onResponse(
|
||||
call: Call<ForumPageBean>,
|
||||
response: Response<ForumPageBean>
|
||||
) {
|
||||
page += 1
|
||||
val forumPageBean = response.body()!!
|
||||
mRefreshLayout?.finishLoadMore()
|
||||
mRefreshLayout.finishLoadMore()
|
||||
mDataBean = forumPageBean
|
||||
pageSize = forumPageBean.page?.pageSize?.toInt()!!
|
||||
forumAdapter.addData(forumPageBean)
|
||||
mRefreshLayout?.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -191,7 +198,8 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
delegateAdapter.clear()
|
||||
delegateAdapter.notifyDataSetChanged()
|
||||
page = 1
|
||||
TiebaApi.getInstance().forumPage(forumName!!, page, sortType, classifyId).enqueue(object : Callback<ForumPageBean> {
|
||||
TiebaApi.getInstance().forumPage(forumName!!, page, sortType, classifyId)
|
||||
.enqueue(object : Callback<ForumPageBean> {
|
||||
override fun onFailure(call: Call<ForumPageBean>, t: Throwable) {
|
||||
var errorCode = -1
|
||||
if (t is TiebaException) {
|
||||
|
|
@ -202,41 +210,48 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
(attachContext as OnRefreshedListener).onFailure(errorCode, t.message)
|
||||
}
|
||||
}
|
||||
mRefreshLayout?.finishRefresh(false)
|
||||
mRefreshLayout.finishRefresh(false)
|
||||
if (errorCode == -1) {
|
||||
Util.showNetworkErrorSnackbar(mRecyclerView) {
|
||||
mRefreshLayout?.autoRefresh()
|
||||
mRefreshLayout.autoRefresh()
|
||||
}
|
||||
return
|
||||
}
|
||||
Toast.makeText(attachContext, attachContext.getString(R.string.toast_error, errorCode, t.message), Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(
|
||||
attachContext,
|
||||
attachContext.getString(R.string.toast_error, errorCode, t.message),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call<ForumPageBean>, response: Response<ForumPageBean>) {
|
||||
override fun onResponse(
|
||||
call: Call<ForumPageBean>,
|
||||
response: Response<ForumPageBean>
|
||||
) {
|
||||
val forumPageBean = response.body()!!
|
||||
if (!isGood) {
|
||||
if (attachContext is OnRefreshedListener) {
|
||||
(attachContext as OnRefreshedListener).onSuccess(forumPageBean)
|
||||
}
|
||||
}
|
||||
mRefreshLayout?.finishRefresh()
|
||||
mRefreshLayout.finishRefresh()
|
||||
mDataBean = forumPageBean
|
||||
pageSize = forumPageBean.page?.pageSize?.toInt()!!
|
||||
forumAdapter.setData(forumPageBean)
|
||||
mRefreshLayout?.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
reloadAdapters()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
mRefreshLayout?.autoRefresh()
|
||||
mRefreshLayout.autoRefresh()
|
||||
}
|
||||
|
||||
override fun onSwitch(which: Int) {
|
||||
if (isGood && mDataBean != null) {
|
||||
classifyId = mDataBean!!.forum?.goodClassify?.get(which)?.classId!!
|
||||
mRefreshLayout?.autoRefresh()
|
||||
mRefreshLayout.autoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +267,7 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
internal inner class DataHolder : DataListener<ForumPageBean?> {
|
||||
override fun onDataArrived(forumPageBean: ForumPageBean?) {
|
||||
if (forumPageBean == null) {
|
||||
mRefreshLayout?.autoRefresh()
|
||||
mRefreshLayout.autoRefresh()
|
||||
return
|
||||
}
|
||||
if (!isGood) {
|
||||
|
|
@ -260,11 +275,11 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
(attachContext as OnRefreshedListener).onSuccess(forumPageBean)
|
||||
}
|
||||
}
|
||||
mRefreshLayout?.finishRefresh()
|
||||
mRefreshLayout.finishRefresh()
|
||||
mDataBean = forumPageBean
|
||||
pageSize = forumPageBean.page?.pageSize?.toInt()!!
|
||||
forumAdapter.setData(forumPageBean)
|
||||
mRefreshLayout?.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
reloadAdapters()
|
||||
}
|
||||
}
|
||||
|
|
@ -277,7 +292,11 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
const val PARAM_PRELOAD_ID = "preload_id"
|
||||
const val DEFAULT_CLASSIFY_ID = "0"
|
||||
private const val DEFAULT_PAGE_SIZE = 30
|
||||
fun newInstance(forumName: String?, isGood: Boolean, sortType: ForumSortType): ForumFragment {
|
||||
fun newInstance(
|
||||
forumName: String?,
|
||||
isGood: Boolean,
|
||||
sortType: ForumSortType
|
||||
): ForumFragment {
|
||||
val args = Bundle()
|
||||
args.putString(PARAM_FORUM_NAME, forumName)
|
||||
args.putBoolean(PARAM_IS_GOOD, isGood)
|
||||
|
|
@ -288,7 +307,12 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
return fragment
|
||||
}
|
||||
|
||||
fun newInstance(forumName: String?, isGood: Boolean, sortType: ForumSortType, preloadId: Int): ForumFragment {
|
||||
fun newInstance(
|
||||
forumName: String?,
|
||||
isGood: Boolean,
|
||||
sortType: ForumSortType,
|
||||
preloadId: Int
|
||||
): ForumFragment {
|
||||
val args = Bundle()
|
||||
args.putString(PARAM_FORUM_NAME, forumName)
|
||||
args.putBoolean(PARAM_IS_GOOD, isGood)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?colorControlHighlight">
|
||||
<item android:drawable="@drawable/bg_radius_10dp" />
|
||||
</ripple>
|
||||
|
|
@ -49,10 +49,18 @@
|
|||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<View
|
||||
android:alpha="0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#60000000"
|
||||
android:id="@+id/mask" />
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout
|
||||
android:background="@drawable/bg_top_radius_10dp"
|
||||
app:backgroundTint="@color/theme_color_card_light"
|
||||
app:behavior_peekHeight="120dp"
|
||||
android:id="@+id/bottom_sheet"
|
||||
app:layout_behavior="@string/bottom_sheet_behavior"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -200,7 +208,7 @@
|
|||
android:minHeight="16dp"
|
||||
android:progressDrawable="@drawable/bg_seekbar_round"
|
||||
app:progressTint="@color/default_color_primary"
|
||||
app:progressBackgroundTint="@color/default_color_divider"
|
||||
app:progressBackgroundTint="@color/color_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
|
@ -221,7 +229,7 @@
|
|||
android:minHeight="16dp"
|
||||
android:progressDrawable="@drawable/bg_seekbar_round"
|
||||
app:progressTint="@color/default_color_primary"
|
||||
app:progressBackgroundTint="@color/default_color_divider"
|
||||
app:progressBackgroundTint="@color/color_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
|
@ -247,13 +255,40 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
android:layout_marginTop="12dp"
|
||||
app:tint="@color/color_text_secondary"
|
||||
android:id="@+id/tip"
|
||||
android:textSize="14sp"
|
||||
<LinearLayout
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/experimental_tip"
|
||||
android:padding="12dp"
|
||||
android:background="@drawable/bg_radius_10dp_ripple"
|
||||
android:backgroundTint="@color/color_divider"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintImageView
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="12dp"
|
||||
android:src="@drawable/ic_round_warning"
|
||||
app:tint="@color/red_accent" />
|
||||
|
||||
<TextView
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_translucent_theme_experimental_feature"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/color_text_secondary" />
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintImageView
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="12dp"
|
||||
android:src="@drawable/ic_round_help_green"
|
||||
app:tint="@color/color_text_secondary" />
|
||||
</LinearLayout>
|
||||
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:clipToPadding="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
|
|
|||
|
|
@ -458,4 +458,5 @@
|
|||
<string name="dark_color">深色</string>
|
||||
<string name="light_color">浅色</string>
|
||||
<string name="title_translucent_theme_wallpapers">推荐壁纸</string>
|
||||
<string name="title_translucent_theme_experimental_feature">透明主题当前仍为实验性特性</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue