diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index efbb504e4..331ef1707 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -163,14 +163,10 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList private ViewTransition mViewTransition; // Header @Nullable - private FrameLayout mHeader; - @Nullable - private View mColorBg; + private LinearLayout mHeader; @Nullable private LoadImageView mThumb; @Nullable - private TextView mTitle; - @Nullable private TextView mUploader; @Nullable private TextView mCategory; @@ -587,10 +583,8 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList mTip.setCompoundDrawables(null, drawable, null, null); mTip.setOnClickListener(this); - mHeader = (FrameLayout) ViewUtils.$$(mainView, R.id.header); - mColorBg = ViewUtils.$$(mHeader, R.id.color_bg); + mHeader = (LinearLayout) ViewUtils.$$(mainView, R.id.header); mThumb = (LoadImageView) ViewUtils.$$(mHeader, R.id.thumb); - mTitle = (TextView) ViewUtils.$$(mHeader, R.id.title); mUploader = (TextView) ViewUtils.$$(mHeader, R.id.uploader); mCategory = (TextView) ViewUtils.$$(mHeader, R.id.category); mActionGroup = (ViewGroup) ViewUtils.$$(mHeader, R.id.action_card); @@ -659,11 +653,9 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList if (prepareData()) { if (mGalleryDetail != null) { bindViewSecond(); - setTransitionName(); adjustViewVisibility(STATE_NORMAL, false); } else if (mGalleryInfo != null) { bindViewFirst(); - setTransitionName(); adjustViewVisibility(STATE_REFRESH_HEADER, false); } else { adjustViewVisibility(STATE_REFRESH, false); @@ -690,9 +682,7 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList mViewTransition = null; mHeader = null; - mColorBg = null; mThumb = null; - mTitle = null; mUploader = null; mCategory = null; mActionGroup = null; @@ -784,33 +774,6 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList return true; } - private boolean createCircularReveal() { - if (mColorBg == null) { - return false; - } - - int w = mColorBg.getWidth(); - int h = mColorBg.getHeight(); - if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) { - Resources resources = getContext().getResources(); - int keylineMargin = resources.getDimensionPixelSize(R.dimen.keyline_margin); - int thumbWidth = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_width); - int thumbHeight = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_height); - - int x = thumbWidth / 2 + keylineMargin; - int y = thumbHeight / 2 + keylineMargin; - - int radiusX = Math.max(Math.abs(x), Math.abs(w - x)); - int radiusY = Math.max(Math.abs(y), Math.abs(h - y)); - float radius = (float) Math.hypot(radiusX, radiusY); - - ViewAnimationUtils.createCircularReveal(mColorBg, x, y, 0, radius).setDuration(300).start(); - return true; - } else { - return false; - } - } - private void adjustViewVisibility(int state, boolean animation) { if (state == mState) { return; @@ -848,27 +811,20 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList mViewTransition.showView(2, animation); break; } - - if ((oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) && - (state == STATE_NORMAL || state == STATE_REFRESH_HEADER) && ResourcesKt.resolveBoolean(getTheme(), androidx.appcompat.R.attr.isLightTheme, false)) { - if (!createCircularReveal()) { - SimpleHandler.getInstance().post(this::createCircularReveal); - } - } } private void bindViewFirst() { if (mGalleryDetail != null) { return; } - if (mThumb == null || mTitle == null || mUploader == null || mCategory == null) { + if (mThumb == null || mUploader == null || mCategory == null) { return; } if (ACTION_GALLERY_INFO.equals(mAction) && mGalleryInfo != null) { GalleryInfo gi = mGalleryInfo; mThumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb); - mTitle.setText(EhUtils.getSuitableTitle(gi)); + setTitle(EhUtils.getSuitableTitle(gi)); mUploader.setText(gi.uploader); mUploader.setAlpha(gi.disowned ? .5f : 1f); mCategory.setText(EhUtils.getCategory(gi.category)); @@ -916,7 +872,7 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList }) .show(); } - if (mThumb == null || mTitle == null || mUploader == null || mCategory == null || + if (mThumb == null || mUploader == null || mCategory == null || mLanguage == null || mPages == null || mSize == null || mPosted == null || mFavoredTimes == null || mRatingText == null || mRating == null || mTorrent == null || mNewerVersion == null) { return; @@ -925,7 +881,7 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList Resources resources = getResources(); mThumb.load(EhCacheKeyFactory.getThumbKey(gd.gid), gd.thumb); - mTitle.setText(EhUtils.getSuitableTitle(gd)); + setTitle(EhUtils.getSuitableTitle(gd)); mUploader.setText(gd.uploader); mUploader.setAlpha(gd.disowned ? .5f : 1f); mCategory.setText(EhUtils.getCategory(gd.category)); @@ -1093,10 +1049,8 @@ public class GalleryDetailScene extends ToolbarScene implements View.OnClickList private void setTransitionName() { long gid = getGid(); - if (gid != -1 && mThumb != null && - mTitle != null && mUploader != null && mCategory != null) { + if (gid != -1 && mThumb != null && mUploader != null && mCategory != null) { ViewCompat.setTransitionName(mThumb, TransitionNameFactory.getThumbTransitionName(gid)); - ViewCompat.setTransitionName(mTitle, TransitionNameFactory.getTitleTransitionName(gid)); ViewCompat.setTransitionName(mUploader, TransitionNameFactory.getUploaderTransitionName(gid)); ViewCompat.setTransitionName(mCategory, TransitionNameFactory.getCategoryTransitionName(gid)); } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt index 08e54b376..fc6b2a1e2 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt @@ -129,7 +129,7 @@ class HistoryScene : ToolbarScene() { override fun onCreateViewWithToolbar( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { val view = inflater.inflate(R.layout.scene_history, container, false) val content = ViewUtils.`$$`(view, R.id.content) val recyclerView = ViewUtils.`$$`(content, R.id.recycler_view) as EasyRecyclerView diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/ToolbarScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/ToolbarScene.kt index 0357cc339..498d3e49d 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/ToolbarScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/ToolbarScene.kt @@ -13,112 +13,75 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.hippo.ehviewer.ui.scene -package com.hippo.ehviewer.ui.scene; +import android.os.Bundle +import android.view.LayoutInflater +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import androidx.appcompat.widget.Toolbar +import com.hippo.ehviewer.R -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; +abstract class ToolbarScene : BaseScene() { + private var mToolbar: Toolbar? = null + private var mTempTitle: CharSequence? = null -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.appcompat.widget.Toolbar; + abstract fun onCreateViewWithToolbar( + inflater: LayoutInflater, + container: ViewGroup?, savedInstanceState: Bundle? + ): View -import com.hippo.ehviewer.R; - -public abstract class ToolbarScene extends BaseScene { - - @Nullable - private Toolbar mToolbar; - - private CharSequence mTempTitle; - - @Nullable - public View onCreateViewWithToolbar(LayoutInflater inflater, - @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return null; + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, savedInstanceState: Bundle? + ): View? { + val view = inflater.inflate(R.layout.scene_toolbar, container, false) as ViewGroup + mToolbar = view.findViewById(R.id.toolbar) + val contentView = onCreateViewWithToolbar(inflater, view, savedInstanceState) + return view.apply { addView(contentView, 1) } } - @Nullable - @Override - public final View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.scene_toolbar, container, false); - Toolbar toolbar = view.findViewById(R.id.toolbar); - FrameLayout contentPanel = view.findViewById(R.id.content_panel); - - View contentView = onCreateViewWithToolbar(inflater, contentPanel, savedInstanceState); - if (contentView == null) { - return null; - } else { - mToolbar = toolbar; - contentPanel.addView(contentView, 0); - return view; - } + override fun onDestroyView() { + super.onDestroyView() + mToolbar = null } - @Override - public void onDestroyView() { - super.onDestroyView(); - mToolbar = null; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - if (mToolbar != null) { - if (mTempTitle != null) { - mToolbar.setTitle(mTempTitle); - mTempTitle = null; - } - - int menuResId = getMenuResId(); + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + mToolbar?.apply { + mTempTitle?.let { title = it } + val menuResId = getMenuResId() if (menuResId != 0) { - mToolbar.inflateMenu(menuResId); - mToolbar.setOnMenuItemClickListener(ToolbarScene.this::onMenuItemClick); + inflateMenu(menuResId) + setOnMenuItemClickListener { item: MenuItem -> onMenuItemClick(item) } } - mToolbar.setNavigationOnClickListener(v -> onNavigationClick()); + setNavigationOnClickListener { onNavigationClick() } } } - public int getMenuResId() { - return 0; + open fun getMenuResId(): Int { + return 0 } - public boolean onMenuItemClick(MenuItem item) { - return false; + open fun onMenuItemClick(item: MenuItem): Boolean { + return false } - public void onNavigationClick() { + open fun onNavigationClick() {} + + fun setNavigationIcon(@DrawableRes resId: Int) { + mToolbar?.setNavigationIcon(resId) } - public void setNavigationIcon(@DrawableRes int resId) { - if (mToolbar != null) { - mToolbar.setNavigationIcon(resId); - } + fun setTitle(@StringRes resId: Int) { + setTitle(getString(resId)) } - public void setNavigationIcon(@Nullable Drawable icon) { - if (mToolbar != null) { - mToolbar.setNavigationIcon(icon); - } + fun setTitle(title: CharSequence?) { + mToolbar?.title = title + mTempTitle = title } - - public void setTitle(@StringRes int resId) { - setTitle(getString(resId)); - } - - public void setTitle(CharSequence title) { - if (mToolbar != null) { - mToolbar.setTitle(title); - } else { - mTempTitle = title; - } - } -} +} \ No newline at end of file diff --git a/app/src/main/res/layout-television/gallery_detail_header.xml b/app/src/main/res/layout-television/gallery_detail_header.xml index d43091797..e46606b28 100644 --- a/app/src/main/res/layout-television/gallery_detail_header.xml +++ b/app/src/main/res/layout-television/gallery_detail_header.xml @@ -17,247 +17,211 @@ ~ --> - + android:layout_height="wrap_content" + android:orientation="vertical"> + android:layout_height="wrap_content"> - - - - - - - - - - - - - - + android:layout_marginBottom="@dimen/keyline_margin" + app:fitsSystemWindowsInsets="top"> - + - + + + + + + + + + android:padding="8dp"> - - - - - - + android:gravity="left" + android:singleLine="true" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + - + - + - - - + - + + - + - + - + - + - + - - - + android:layout_height="wrap_content" + android:layout_weight="1" + android:clickable="true" + android:focusable="true" + android:insetLeft="40dp" + android:insetTop="16dp" + android:insetRight="40dp" + android:text="@string/read"> - - - - -