Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Minor fixes #1340

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import com.hippo.ehviewer.client.data.GalleryInfo.Companion.LOCAL_FAVORITED
import com.hippo.ehviewer.client.data.GalleryInfo.Companion.NOT_FAVORITED

object GalleryListParser {
suspend fun parse(body: String) = parseGalleryInfoList(body).apply {
galleryInfoList.onEach {
if (it.favoriteSlot == NOT_FAVORITED && EhDB.containLocalFavorites(it.gid)) {
it.favoriteSlot = LOCAL_FAVORITED
suspend fun parse(body: String) = runCatching {
parseGalleryInfoList(body).apply {
galleryInfoList.onEach {
if (it.favoriteSlot == NOT_FAVORITED && EhDB.containLocalFavorites(it.gid)) {
it.favoriteSlot = LOCAL_FAVORITED
}
it.generateSLang()
}
it.generateSLang()
}
}
}.getOrDefault(GalleryListResult())
}

class GalleryListResult(
val prev: String?,
val next: String?,
val galleryInfoList: ArrayList<BaseGalleryInfo>,
val prev: String? = null,
val next: String? = null,
val galleryInfoList: ArrayList<BaseGalleryInfo> = arrayListOf(),
)

private external fun parseGalleryInfoList(e: String): GalleryListResult
8 changes: 4 additions & 4 deletions app/src/main/java/com/hippo/ehviewer/ui/ConfigureActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.hippo.ehviewer.ui

import android.os.Bundle
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.SideEffect
Expand Down Expand Up @@ -47,8 +47,8 @@ class ConfigureActivity : EhActivity() {
BASE_SETTINGS_SCREEN
},
enterTransition = { slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Up, tween(200)) },
exitTransition = { ExitTransition.None },
popEnterTransition = { EnterTransition.None },
exitTransition = { fadeOut(tween(200)) },
popEnterTransition = { fadeIn(tween(200)) },
popExitTransition = { slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Down, tween(200)) },
) {
composable(SIGN_IN_ROUTE_NAME) {
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ class FavoritesScene : SearchBarScene() {
mAdapter?.type = Settings.listMode
}

private val SceneFavoritesBinding.fastScroller get() = contentLayout.fastScroller
private val SceneFavoritesBinding.refreshLayout get() = contentLayout.refreshLayout
private val SceneFavoritesBinding.recyclerView get() = contentLayout.recyclerView
private val SceneFavoritesBinding.progress get() = contentLayout.progress
private val SceneFavoritesBinding.tip get() = contentLayout.tip

override fun onCreateViewWithToolbar(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -332,14 +338,18 @@ class FavoritesScene : SearchBarScene() {
when (val state = it.refresh) {
is LoadState.Loading -> {
showSearchBar()
transition.showView(1)
if (!binding.refreshLayout.isRefreshing) {
transition.showView(1)
}
}
is LoadState.Error -> {
binding.refreshLayout.isRefreshing = false
binding.tip.text = ExceptionUtils.getReadableString(state.error)
transition.showView(2)
}
is LoadState.NotLoading -> {
delay(500)
binding.refreshLayout.isRefreshing = false
if (mAdapter?.itemCount == 0) {
binding.tip.text = empty
transition.showView(2)
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class GalleryAdapter(
) : PagingDataAdapter<BaseGalleryInfo, GalleryHolder>(diffCallback) {
private val resources = recyclerView.context.resources
private val layoutManager: AutoStaggeredGridLayoutManager = AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL)
private val mPaddingTopSB: Int = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar)
private var mListDecoration: ItemDecoration? = null
private var mGirdDecoration: MarginItemDecoration? = null
private var mType = TYPE_INVALID
Expand Down Expand Up @@ -142,16 +141,6 @@ class GalleryAdapter(
recyclerView.adapter = this
recyclerView.layoutManager = layoutManager
type = Settings.listMode
adjustPaddings()
}

private fun adjustPaddings() {
recyclerView.setPadding(
recyclerView.paddingLeft,
recyclerView.paddingTop + mPaddingTopSB,
recyclerView.paddingRight,
recyclerView.paddingBottom,
)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ class GalleryListScene : SearchBarScene() {
}
}

private val SceneGalleryListBinding.fastScroller get() = contentLayout.fastScroller
private val SceneGalleryListBinding.refreshLayout get() = contentLayout.refreshLayout
private val SceneGalleryListBinding.recyclerView get() = contentLayout.recyclerView
private val SceneGalleryListBinding.progress get() = contentLayout.progress
private val SceneGalleryListBinding.tip get() = contentLayout.tip

override fun onCreateViewWithToolbar(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -330,7 +336,7 @@ class GalleryListScene : SearchBarScene() {
mSearchFab.parent as View,
),
)
mViewTransition = BringOutTransition(binding.contentLayout, binding.searchLayout)
mViewTransition = BringOutTransition(binding.contentLayout.contentView, binding.searchLayout)
binding.fastScroller.setOnDragHandlerListener(object : OnDragHandlerListener {
override fun onStartDragHandler() {
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END)
Expand Down Expand Up @@ -372,9 +378,12 @@ class GalleryListScene : SearchBarScene() {
when (val state = it.refresh) {
is LoadState.Loading -> {
showSearchBar()
transition.showView(1)
if (!binding.refreshLayout.isRefreshing) {
transition.showView(1)
}
}
is LoadState.Error -> {
binding.refreshLayout.isRefreshing = false
binding.tip.text = ExceptionUtils.getReadableString(state.error)
transition.showView(2)
if (state.error.cause is CloudflareBypassException) {
Expand All @@ -390,6 +399,7 @@ class GalleryListScene : SearchBarScene() {
}
is LoadState.NotLoading -> {
delay(500)
binding.refreshLayout.isRefreshing = false
if (mAdapter?.itemCount == 0) {
if (mUrlBuilder.mode == MODE_SUBSCRIPTION) {
binding.tip.text = noWatch
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/com/hippo/ehviewer/util/ClipboardUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*/
package com.hippo.ehviewer.util

import android.app.Activity
import android.content.ClipData
import android.content.ClipDescription
import android.content.ClipboardManager
import android.content.Context
import android.content.ContextWrapper
import android.os.Build
import android.view.textclassifier.TextClassifier
import androidx.core.os.persistableBundleOf
Expand Down Expand Up @@ -49,8 +51,9 @@ fun Context.addTextToClipboard(text: CharSequence?, isSensitive: Boolean, useToa
}
// Avoid double notify user since system have done that on Tiramisu above
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
if (this is MainActivity) {
showTip(R.string.copied_to_clipboard, BaseScene.LENGTH_SHORT, useToast)
val activity = findActivity()
if (activity is MainActivity) {
activity.showTip(R.string.copied_to_clipboard, BaseScene.LENGTH_SHORT, useToast)
}
}
}
Expand All @@ -63,3 +66,15 @@ fun ClipboardManager.getUrlFromClipboard(context: Context): String? {
val string = item?.coerceToText(context).toString()
return string.ifEmpty { null }
}

/**
* Find the closest Activity in a given Context.
*/
internal fun Context.findActivity(): Activity {
var context = this
while (context is ContextWrapper) {
if (context is Activity) return context
context = context.baseContext
}
throw IllegalStateException("findActivity() should be called in the context of an Activity")
}
46 changes: 3 additions & 43 deletions app/src/main/res/layout/scene_favorites.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,9 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<TextView
android:id="@+id/tip"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="228dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center_horizontal" />

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progress"
style="@style/ProgressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

<androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:paddingTop="16dp"
app:fitsSystemWindowsInsets="top"
app:layout_behavior="@string/searchbar_scrolling_view_behavior">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false" />

</androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout>

<com.hippo.ehviewer.ui.legacy.FastScroller
android:id="@+id/fast_scroller"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:paddingStart="20dp"
android:paddingTop="128dp"
android:paddingEnd="4dp"
android:paddingBottom="8dp" />
<include
android:id="@+id/content_layout"
layout="@layout/widget_content_layout" />

<com.hippo.ehviewer.ui.legacy.FabLayout
android:id="@+id/fab_layout"
Expand Down
71 changes: 33 additions & 38 deletions app/src/main/res/layout/scene_gallery_comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,44 @@
android:text="@string/no_one_comments_gallery"
app:fitsSystemWindowsInsets="bottom" />

<FrameLayout
<LinearLayout
android:id="@+id/edit_panel"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/colorPrimaryContainer"
android:elevation="4dp"
android:orientation="horizontal"
android:visibility="invisible"
app:fitsSystemWindowsInsets="bottom">

<LinearLayout
android:id="@+id/edit_panel"
android:layout_width="match_parent"
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/colorPrimaryContainer"
android:elevation="4dp"
android:orientation="horizontal"
android:visibility="invisible"
app:fitsSystemWindowsInsets="bottom">

<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:gravity="start|center_vertical"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:maxHeight="168dp"
android:minHeight="56dp"
android:padding="@dimen/keyline_margin"
android:textColor="?colorOnPrimaryContainer"
android:textSize="16sp" />
android:layout_weight="1"
android:background="@null"
android:gravity="start|center_vertical"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:maxHeight="168dp"
android:minHeight="56dp"
android:padding="@dimen/keyline_margin"
android:textColor="?colorOnPrimaryContainer"
android:textSize="16sp" />

<ImageView
android:id="@+id/send"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="16dp"
app:tint="?colorOnPrimaryContainer" />
<ImageView
android:id="@+id/send"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="16dp"
app:tint="?colorOnPrimaryContainer" />

</LinearLayout>
</FrameLayout>
</LinearLayout>

<com.hippo.ehviewer.ui.legacy.FabLayout
android:id="@+id/fab_layout"
Expand Down
51 changes: 2 additions & 49 deletions app/src/main/res/layout/scene_gallery_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,9 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<FrameLayout
<include
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:paddingTop="16dp"
app:layout_behavior="@string/searchbar_scrolling_view_behavior">

<TextView
android:id="@+id/tip"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="228dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center_horizontal" />

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progress"
style="@style/ProgressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

<androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
app:fitsSystemWindowsInsets="top">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false" />

</androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout>
</FrameLayout>

<com.hippo.ehviewer.ui.legacy.FastScroller
android:id="@+id/fast_scroller"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:paddingStart="20dp"
android:paddingTop="128dp"
android:paddingEnd="4dp"
android:paddingBottom="8dp" />
layout="@layout/widget_content_layout" />

<com.hippo.ehviewer.ui.legacy.SearchLayout
android:id="@+id/search_layout"
Expand Down
Loading