From 6bef76b848e2340dc59812bc0b3f0003e05e6995 Mon Sep 17 00:00:00 2001 From: Levin Li Date: Sun, 6 Jun 2021 16:08:36 +0800 Subject: [PATCH] Some updates to RTL layout and display cutout and ripple effect --- .../celestia/ui/linkpreview/LPLinkView.kt | 5 + app/src/main/AndroidManifest.xml | 2 +- .../celestia/mobilecelestia/MainActivity.kt | 33 ++-- .../browser/BrowserCommonFragment.kt | 4 +- .../browser/BrowserNavigationFragment.kt | 4 +- .../browser/SubsystemBrowserFragment.kt | 4 +- .../celestia/CelestiaFragment.kt | 18 +- .../common/InsetAwareFragment.kt | 2 +- .../common/NavigationFragment.kt | 2 +- .../mobilecelestia/common/ProgressView.kt | 169 ++++++------------ .../common/RightNavgationFragment.kt | 40 +++-- .../common/SectionFooterView.kt | 40 ----- .../common/SectionHeaderView.kt | 40 ----- .../common/SeparatorRecyclerViewAdapter.kt | 27 ++- .../mobilecelestia/common/StepperView.kt | 16 +- .../mobilecelestia/common/ViewHolder.kt | 8 +- .../control/BottomControlFragment.kt | 26 ++- .../control/CameraControlContainerFragment.kt | 4 +- .../control/CameraControlFragment.kt | 4 +- .../EventFinderContainerFragment.kt | 4 +- .../eventfinder/EventFinderInputFragment.kt | 4 +- .../eventfinder/EventFinderResultFragment.kt | 4 +- .../EventFinderResultRecyclerViewAdapter.kt | 2 + .../favorite/DestinationDetailFragment.kt | 4 +- .../favorite/FavoriteFragment.kt | 4 +- .../favorite/FavoriteItemFragment.kt | 4 +- .../goto/GoToContainerFragment.kt | 4 +- .../mobilecelestia/goto/GoToInputFragment.kt | 4 +- .../mobilecelestia/help/HelpFragment.kt | 17 +- .../mobilecelestia/info/InfoFragment.kt | 37 ++-- .../resource/AsyncListFragment.kt | 4 +- .../resource/ResourceFragment.kt | 4 +- .../resource/ResourceItemFragment.kt | 16 +- .../search/SearchContainerFragment.kt | 2 +- .../mobilecelestia/search/SearchFragment.kt | 27 ++- .../mobilecelestia/settings/AboutFragment.kt | 4 +- .../settings/AboutRecyclerViewAdapter.kt | 1 + .../SettingsCommonRecyclerViewAdapter.kt | 6 +- .../settings/SettingsFragment.kt | 4 +- .../SettingsLanguageRecyclerViewAdapter.kt | 2 +- .../mobilecelestia/settings/SettingsModel.kt | 4 +- ...ttingsMultiSelectionRecyclerViewAdapter.kt | 2 +- ...tingsSingleSelectionRecyclerViewAdapter.kt | 2 +- .../settings/SimpleTextFragment.kt | 4 +- .../mobilecelestia/toolbar/ToolbarFragment.kt | 17 +- .../drawable/button_background_selector.xml | 28 +-- .../main/res/drawable/ic_action_back_tint.xml | 15 ++ .../res/drawable/ripple_button_background.xml | 17 ++ app/src/main/res/layout/activity_main.xml | 4 +- .../main/res/layout/common_action_button.xml | 20 +-- .../res/layout/common_progress_button.xml | 31 ++++ .../main/res/layout/common_section_footer.xml | 27 +++ .../main/res/layout/common_section_header.xml | 27 +++ .../main/res/layout/common_text_list_item.xml | 37 ++-- app/src/main/res/layout/dialog_text_input.xml | 3 +- .../layout/fragment_bottom_control_list.xml | 5 +- .../res/layout/fragment_resource_item.xml | 29 +-- .../res/layout/fragment_search_item_list.xml | 2 +- app/src/main/res/layout/stepper_view.xml | 10 +- app/src/main/res/values/attrs.xml | 2 + app/src/main/res/values/styles.xml | 39 ++-- 61 files changed, 497 insertions(+), 434 deletions(-) delete mode 100644 app/src/main/java/space/celestia/mobilecelestia/common/SectionFooterView.kt delete mode 100644 app/src/main/java/space/celestia/mobilecelestia/common/SectionHeaderView.kt create mode 100644 app/src/main/res/drawable/ic_action_back_tint.xml create mode 100644 app/src/main/res/drawable/ripple_button_background.xml create mode 100644 app/src/main/res/layout/common_progress_button.xml create mode 100644 app/src/main/res/layout/common_section_footer.xml create mode 100644 app/src/main/res/layout/common_section_header.xml diff --git a/LinkPreview/src/main/java/space/celestia/ui/linkpreview/LPLinkView.kt b/LinkPreview/src/main/java/space/celestia/ui/linkpreview/LPLinkView.kt index 7b5afa5d..3f2f6631 100644 --- a/LinkPreview/src/main/java/space/celestia/ui/linkpreview/LPLinkView.kt +++ b/LinkPreview/src/main/java/space/celestia/ui/linkpreview/LPLinkView.kt @@ -12,6 +12,7 @@ package space.celestia.ui.linkpreview import android.content.Context +import android.graphics.Color import android.os.Build import android.util.AttributeSet import android.util.TypedValue @@ -71,10 +72,14 @@ class LPLinkView(context: Context, val attrs: AttributeSet) : CardView(context, titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleLabelSize) titleView.setTextColor(ContextCompat.getColor(context, titleLabelColor)) titleView.text = metaData.title + titleView.textAlignment = TEXT_ALIGNMENT_VIEW_START + titleView.setBackgroundColor(Color.TRANSPARENT) val urlView = TextView(context) urlView.text = metaData.url.host urlView.setTextSize(TypedValue.COMPLEX_UNIT_PX, footerLabelSize) urlView.setTextColor(ContextCompat.getColor(context, footerLabelColor)) + urlView.textAlignment = TEXT_ALIGNMENT_VIEW_START + urlView.setBackgroundColor(Color.TRANSPARENT) (urlView.layoutParams as? MarginLayoutParams)?.topMargin = textContentSpacing diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4a848ed2..2e115711 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ diff --git a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt index f84b10b9..db76e41e 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt @@ -20,6 +20,7 @@ import android.net.Uri import android.os.Build import android.os.Bundle import android.provider.DocumentsContract +import android.util.LayoutDirection import android.util.Log import android.view.* import android.widget.Toast @@ -404,7 +405,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), val ltr = resources.configuration.layoutDirection != View.LAYOUT_DIRECTION_RTL val safeInsetEnd = if (ltr) cutout.safeInsetRight else cutout.safeInsetLeft - val safeInsetStart = if (ltr) cutout.safeInsetLeft else cutout.safeInsetRight val bottomView = findViewById(R.id.toolbar_bottom_container) val toolbarGuideLine = findViewById(R.id.toolbar_width_guideline) @@ -413,11 +413,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), endGuideLine.setGuidelineEnd((300 * density).toInt() + safeInsetEnd) toolbarGuideLine.setGuidelineEnd((220 * density).toInt() + safeInsetEnd) - (bottomView.layoutParams as? ConstraintLayout.LayoutParams)?.let { - it.marginStart = safeInsetStart + (16 * density).toInt() - it.bottomMargin = cutout.safeInsetBottom + (8 * density).toInt() - bottomView.layoutParams = it - } + bottomView.layoutParams.height = cutout.safeInsetBottom + (72 * density).toInt() } private fun removeCelestiaFragment() { @@ -1411,14 +1407,23 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), } private fun showTimeControl() { - showBottomFragment( - BottomControlFragment.newInstance( - listOf( - CelestiaAction.Slower, - CelestiaAction.PlayPause, - CelestiaAction.Faster, - CelestiaAction.Reverse - ))) + val actions: List + if (resources.configuration.layoutDirection == LayoutDirection.RTL) { + actions = listOf( + CelestiaAction.Faster, + CelestiaAction.PlayPause, + CelestiaAction.Slower, + CelestiaAction.Reverse + ) + } else { + actions = listOf( + CelestiaAction.Slower, + CelestiaAction.PlayPause, + CelestiaAction.Faster, + CelestiaAction.Reverse + ) + } + showBottomFragment(BottomControlFragment.newInstance(actions)) } private fun showScriptControl() { diff --git a/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserCommonFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserCommonFragment.kt index 99ddc606..21f55f48 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserCommonFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserCommonFragment.kt @@ -19,10 +19,10 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaBrowserItem -class BrowserCommonFragment : RightSubFragment() { +class BrowserCommonFragment : EndSubFragment() { private var listener: Listener? = null private var browserItem: CelestiaBrowserItem? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserNavigationFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserNavigationFragment.kt index dbd3ef24..cd8bb015 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserNavigationFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/browser/BrowserNavigationFragment.kt @@ -12,9 +12,9 @@ package space.celestia.mobilecelestia.browser import android.os.Bundle -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment -class BrowserNavigationFragment : RightNavgationFragment() { +class BrowserNavigationFragment : EndNavgationFragment() { private var path: String = "" override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/space/celestia/mobilecelestia/browser/SubsystemBrowserFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/browser/SubsystemBrowserFragment.kt index d3e92384..4bb6a36d 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/browser/SubsystemBrowserFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/browser/SubsystemBrowserFragment.kt @@ -13,13 +13,13 @@ package space.celestia.mobilecelestia.browser import android.os.Bundle import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment import space.celestia.mobilecelestia.core.CelestiaBrowserItem import space.celestia.mobilecelestia.core.CelestiaSelection import space.celestia.mobilecelestia.info.InfoFragment import space.celestia.mobilecelestia.info.model.InfoDescriptionItem -class SubsystemBrowserFragment : RightNavgationFragment(), BrowserRootFragment { +class SubsystemBrowserFragment : EndNavgationFragment(), BrowserRootFragment { private var currentPath = "" private var rootPath = "" diff --git a/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt index ca33bbbd..da5f54f3 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaFragment.kt @@ -197,28 +197,28 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - handleInsetChanged(view, currentSafeInsets) + handleInsetsChanged(view, currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) - handleInsetChanged(view, newInset) + handleInsetsChanged(view, newInsets) } - private fun handleInsetChanged(view: View, newInset: EdgeInsets) { + private fun handleInsetsChanged(view: View, newInsets: EdgeInsets) { if (!loadSuccess) { - savedInsets = newInset + savedInsets = newInsets return } - val insets = newInset.scaleBy(scaleFactor) + val insets = newInsets.scaleBy(scaleFactor) CelestiaView.callOnRenderThread { core.setSafeAreaInsets(insets) } val ltr = resources.configuration.layoutDirection != View.LAYOUT_DIRECTION_RTL - val safeInsetEnd = if (ltr) newInset.right else newInset.left + val safeInsetEnd = if (ltr) newInsets.right else newInsets.left val controlView = view.findViewById(currentControlViewID) ?: return val params = controlView.layoutParams as? ConstraintLayout.LayoutParams @@ -375,7 +375,7 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo Log.d(TAG, "Ready to display") - handleInsetChanged(thisView, currentSafeInsets) + handleInsetsChanged(thisView, currentSafeInsets) } override fun onCreateContextMenu( diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/InsetAwareFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/common/InsetAwareFragment.kt index ed10b5f3..2ad7ae41 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/InsetAwareFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/InsetAwareFragment.kt @@ -45,5 +45,5 @@ open class InsetAwareFragment: Fragment() { }) } - open fun onInsetChanged(view: View, newInset: EdgeInsets) {} + open fun onInsetChanged(view: View, newInsets: EdgeInsets) {} } \ No newline at end of file diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/NavigationFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/common/NavigationFragment.kt index c89746c3..99180ddc 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/NavigationFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/NavigationFragment.kt @@ -325,7 +325,7 @@ abstract class NavigationFragment: InsetAwareFragment(), Poppable, Toolbar.OnMen } } else { if (canGoBack) { - toolbar.setNavigationIcon(R.drawable.ic_action_arrow_back) + toolbar.setNavigationIcon(R.drawable.ic_action_back_tint) } else { toolbar.navigationIcon = null } diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/ProgressView.kt b/app/src/main/java/space/celestia/mobilecelestia/common/ProgressView.kt index 6ac34450..55c258b2 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/ProgressView.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/ProgressView.kt @@ -11,29 +11,30 @@ package space.celestia.mobilecelestia.common -import android.annotation.SuppressLint import android.content.Context -import android.graphics.* +import android.content.res.ColorStateList +import android.graphics.drawable.GradientDrawable +import android.graphics.drawable.LayerDrawable +import android.graphics.drawable.RippleDrawable import android.util.AttributeSet -import android.view.MotionEvent import android.view.View +import android.widget.FrameLayout import androidx.core.content.res.ResourcesCompat import space.celestia.mobilecelestia.R -import java.util.* -class ProgressView : View { - private var backgroundPaint: Paint - private var progressPaint: Paint +class ProgressView : FrameLayout { private var backgroundColor = 0 private var progressColor = 0 - private val cornerRadius = 10f - private val topX = 0f - private val topY = 0f + private var rippleColor = 0 + private var cornerRadius = 10 private var progress = 0f - constructor(context: Context?) : this(context, null) + private var rippleDrawable: RippleDrawable? = null + private var progressLayerId: Int = 0 - constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { + constructor(context: Context) : this(context, null) + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { val attributeArray = getContext().theme.obtainStyledAttributes(attrs, R.styleable.ProgressView, 0, 0) try { @@ -41,137 +42,73 @@ class ProgressView : View { attributeArray.getColor(R.styleable.ProgressView_backgroundColor, ResourcesCompat.getColor(resources, R.color.colorProgressBackground, null)) progressColor = attributeArray.getColor(R.styleable.ProgressView_progressColor, ResourcesCompat.getColor(resources, R.color.colorProgressForeground, null)) + rippleColor = + attributeArray.getColor(R.styleable.ProgressView_rippleColor, ResourcesCompat.getColor(resources, R.color.colorProgressForeground, null)) + cornerRadius = + attributeArray.getDimensionPixelSize(R.styleable.ProgressView_cornerRadius, (resources.displayMetrics.density * 4).toInt()) } finally { attributeArray.recycle() } - backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG) - backgroundPaint.color = backgroundColor - backgroundPaint.style = Paint.Style.FILL_AND_STROKE - progressPaint = Paint(Paint.ANTI_ALIAS_FLAG) - progressPaint.color = progressColor - progressPaint.style = Paint.Style.FILL_AND_STROKE } override fun setBackgroundColor(bgColor: Int) { backgroundColor = bgColor - backgroundPaint.color = bgColor - invalidate() + + updateDrawable() } fun setProgressColor(progColor: Int) { progressColor = progColor - progressPaint.color = progColor - invalidate() - } - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - val height: Int - val width: Int - val specWidth = MeasureSpec.getSize(widthMeasureSpec) - val specHeight = MeasureSpec.getSize(heightMeasureSpec) - val heightMode = MeasureSpec.getMode(heightMeasureSpec) - val widthMode = MeasureSpec.getMode(widthMeasureSpec) - height = when (heightMode) { - MeasureSpec.EXACTLY -> specHeight - MeasureSpec.UNSPECIFIED, MeasureSpec.AT_MOST -> resources.getDimensionPixelSize(R.dimen.progress_button_default_height) - else -> resources.getDimensionPixelSize(R.dimen.progress_button_default_height) - } - width = when (widthMode) { - MeasureSpec.EXACTLY -> specWidth - MeasureSpec.UNSPECIFIED, MeasureSpec.AT_MOST -> resources.getDimensionPixelSize(R.dimen.progress_button_default_width) - else -> resources.getDimensionPixelSize(R.dimen.progress_button_default_width) - } - setMeasuredDimension(width, height) + updateDrawable() } - @ExperimentalStdlibApi - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - drawDeterminateProgress(canvas) + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + + updateDrawable() } - @SuppressLint("ClickableViewAccessibility") - override fun onTouchEvent(event: MotionEvent?): Boolean { - if (event != null) { - when (event.actionMasked) { - MotionEvent.ACTION_DOWN -> { - alpha = 0.3f - } - MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { - alpha = 1f + fun updateDrawable() { + val isRTL = resources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL + + val backgroundDrawable = GradientDrawable() + backgroundDrawable.shape = GradientDrawable.RECTANGLE + backgroundDrawable.cornerRadius = cornerRadius.toFloat() + backgroundDrawable.color = ColorStateList(arrayOf(intArrayOf()), intArrayOf(backgroundColor)) + val progressDrawable = GradientDrawable() + progressDrawable.shape = GradientDrawable.RECTANGLE + progressDrawable.cornerRadius = cornerRadius.toFloat() + progressDrawable.color = ColorStateList(arrayOf(intArrayOf()), intArrayOf(progressColor)) + val layerDrawable = LayerDrawable(arrayOf(backgroundDrawable, progressDrawable)) + + layerDrawable.setLayerInset(0, 0, 0, 0, 0) + layerDrawable.setLayerInset(1, if (isRTL) (width - progress * width / 100).toInt() else 0, 0, if (isRTL) 0 else (width - progress * width / 100).toInt(), 0) + layerDrawable.setBounds(0, 0, width, height) + + if (rippleDrawable == null) { + val ripple = RippleDrawable(ColorStateList(arrayOf(intArrayOf()), intArrayOf(rippleColor)), layerDrawable, null) + rippleDrawable = ripple + for (i in 0 until ripple.numberOfLayers) { + if (ripple.getDrawable(i) == layerDrawable) { + progressLayerId = ripple.getId(i) + break } } - } - return super.onTouchEvent(event) - } - - private fun drawDeterminateProgress(canvas: Canvas) { - if (progress == 0f) { - onDrawInit(canvas) - } else if (progress > 0f && progress < 100f) { - onDrawProgress(canvas) + background = rippleDrawable } else { - onDrawFinished(canvas) + rippleDrawable?.setDrawableByLayerId(progressLayerId, layerDrawable) } - } - - private fun onDrawInit(canvas: Canvas) { - val bgRectf = RectF( - topX, topY, - canvas.width.toFloat(), canvas.height.toFloat() - ) - canvas.drawRoundRect( - bgRectf, cornerRadius, cornerRadius, - backgroundPaint - ) - } - - private fun onDrawProgress(canvas: Canvas) { - val bgRectf = RectF( - topX, topY, - canvas.width.toFloat(), canvas.height.toFloat() - ) - canvas.drawRoundRect( - bgRectf, cornerRadius, cornerRadius, - backgroundPaint - ) - val progressPoint = canvas.width / 100 * progress - val progRect = RectF( - topX, topY, progressPoint, - canvas.height.toFloat() - ) - canvas.drawRoundRect( - progRect, cornerRadius, cornerRadius, - progressPaint - ) - } - - private fun onDrawFinished(canvas: Canvas) { - val bgRectf = RectF( - topX, topY, - canvas.width.toFloat(), canvas.height.toFloat() - ) - canvas.drawRoundRect( - bgRectf, cornerRadius, cornerRadius, - backgroundPaint - ) - val progRect = RectF( - topX, topY, - canvas.width.toFloat(), canvas.height.toFloat() - ) - canvas.drawRoundRect( - progRect, cornerRadius, cornerRadius, - progressPaint - ) + invalidate() } fun setProgress(currentProgress: Float) { progress = currentProgress - invalidate() + updateDrawable() } fun reset() { progress = 0f - invalidate() + updateDrawable() } } \ No newline at end of file diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/RightNavgationFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/common/RightNavgationFragment.kt index c7701ac6..39f10285 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/RightNavgationFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/RightNavgationFragment.kt @@ -1,5 +1,5 @@ /* - * RightNavgationFragment.kt + * EndNavgationFragment.kt * * Copyright (C) 2001-2021, Celestia Development Team * @@ -12,32 +12,50 @@ package space.celestia.mobilecelestia.common import android.os.Bundle +import android.util.LayoutDirection import android.view.View +import androidx.appcompat.widget.Toolbar -abstract class RightNavgationFragment: NavigationFragment() { +abstract class EndNavgationFragment: NavigationFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - toolbar.setPadding(0, currentSafeInsets.top, currentSafeInsets.right, 0) + applyPadding(toolbar, currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) - toolbar.setPadding(0, newInset.top, newInset.right, 0) + applyPadding(toolbar, newInsets) + } + + private fun applyPadding(toolbar: Toolbar, insets: EdgeInsets) { + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + if (isRTL) + toolbar.setPadding(insets.left, insets.top, 0, 0) + else + toolbar.setPadding(0, insets.top, insets.right, 0) } } -abstract class RightSubFragment: NavigationFragment.SubFragment() { +abstract class EndSubFragment: NavigationFragment.SubFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - view.setPadding(0, 0, currentSafeInsets.right, currentSafeInsets.bottom) + applyPadding(view, currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) + + applyPadding(view, newInsets) + } - view.setPadding(0, 0, newInset.right, newInset.bottom) + private fun applyPadding(view: View, insets: EdgeInsets) { + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + if (isRTL) + view.setPadding(insets.left, 0, 0, insets.bottom) + else + view.setPadding(0, 0, insets.right, insets.bottom) } } \ No newline at end of file diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/SectionFooterView.kt b/app/src/main/java/space/celestia/mobilecelestia/common/SectionFooterView.kt deleted file mode 100644 index 6b464b11..00000000 --- a/app/src/main/java/space/celestia/mobilecelestia/common/SectionFooterView.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SectionFooterView.kt - * - * Copyright (C) 2001-2020, Celestia Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - */ - -package space.celestia.mobilecelestia.common - -import android.content.Context -import android.widget.FrameLayout -import android.widget.TextView -import androidx.core.content.res.ResourcesCompat -import space.celestia.mobilecelestia.R - -class SectionFooterView(context: Context): FrameLayout(context) { - val textView: TextView = TextView(context) - - init { - val density = resources.displayMetrics.density - - layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) - val paddingH = (footerHorizontalPadding * density).toInt() - val paddingV = (footerVerticalPadding * density).toInt() - setPadding(paddingH, paddingV, paddingH, paddingV) - - textView.setTextColor(ResourcesCompat.getColor(resources, R.color.colorSecondaryLabel, null)) - textView.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) - addView(textView) - } - - private companion object { - const val footerHorizontalPadding: Float = 16F - const val footerVerticalPadding: Float = 8F - } -} \ No newline at end of file diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/SectionHeaderView.kt b/app/src/main/java/space/celestia/mobilecelestia/common/SectionHeaderView.kt deleted file mode 100644 index 638629fe..00000000 --- a/app/src/main/java/space/celestia/mobilecelestia/common/SectionHeaderView.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SectionHeaderView.kt - * - * Copyright (C) 2001-2020, Celestia Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - */ - -package space.celestia.mobilecelestia.common - -import android.content.Context -import android.view.Gravity -import android.widget.FrameLayout -import android.widget.TextView -import androidx.core.content.res.ResourcesCompat -import space.celestia.mobilecelestia.R - -class SectionHeaderView(context: Context): FrameLayout(context) { - val textView: TextView = TextView(context) - - init { - val density = resources.displayMetrics.density - - layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, (headerHeight * density).toInt()) - val padding = (headerHorizontalPadding * density).toInt() - setPadding(padding, 0, padding, 0) - - textView.setTextColor(ResourcesCompat.getColor(resources, R.color.colorSecondaryLabel, null)) - textView.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL) - addView(textView) - } - - private companion object { - const val headerHeight: Float = 36F - const val headerHorizontalPadding: Float = 16F - } -} \ No newline at end of file diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/SeparatorRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/common/SeparatorRecyclerViewAdapter.kt index eb134c52..32954330 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/SeparatorRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/SeparatorRecyclerViewAdapter.kt @@ -11,8 +11,10 @@ package space.celestia.mobilecelestia.common +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R @@ -207,21 +209,25 @@ open class SeparatorHeaderRecyclerViewAdapter(sections: List = override fun bindVH(holder: RecyclerView.ViewHolder, item: RecyclerViewItem) { if (holder is HeaderViewHolder && item is HeaderRecyclerViewItem) { - holder.view.textView.text = item.title + holder.textView.text = item.title return } if (holder is FooterViewHolder && item is FooterRecyclerViewItem) { - holder.view.textView.text = item.title + holder.textView.text = item.title return } throw RuntimeException("$this must deal with item type $item") } override fun createVH(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { - if (viewType == HEADER) - return HeaderViewHolder(SectionHeaderView(parent.context)) - if (viewType == FOOTER) - return FooterViewHolder(SectionFooterView(parent.context)) + if (viewType == HEADER) { + val view = LayoutInflater.from(parent.context).inflate(R.layout.common_section_header, parent, false) + return HeaderViewHolder(view) + } + if (viewType == FOOTER) { + val view = LayoutInflater.from(parent.context).inflate(R.layout.common_section_footer, parent, false) + return FooterViewHolder(view) + } throw RuntimeException("$this must deal with item type $viewType") } @@ -229,8 +235,13 @@ open class SeparatorHeaderRecyclerViewAdapter(sections: List = updateSections(sections.transformed()) } - inner class HeaderViewHolder(val view: SectionHeaderView) : RecyclerView.ViewHolder(view) - inner class FooterViewHolder(val view: SectionFooterView) : RecyclerView.ViewHolder(view) + inner class HeaderViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val textView: TextView by lazy { itemView.findViewById(R.id.text) } + } + + inner class FooterViewHolder(val view: View) : RecyclerView.ViewHolder(view) { + val textView: TextView by lazy { itemView.findViewById(R.id.text) } + } companion object { const val HEADER = 99997 diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/StepperView.kt b/app/src/main/java/space/celestia/mobilecelestia/common/StepperView.kt index 3fa31099..9d2a2e8a 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/StepperView.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/StepperView.kt @@ -14,6 +14,7 @@ package space.celestia.mobilecelestia.common import android.annotation.SuppressLint import android.content.Context import android.util.AttributeSet +import android.util.LayoutDirection import android.view.MotionEvent import android.view.View import android.view.View.OnTouchListener @@ -21,8 +22,8 @@ import android.widget.LinearLayout import space.celestia.mobilecelestia.R class StepperView(context: Context, attrs: AttributeSet): LinearLayout(context, attrs) { - private val leftView by lazy { findViewById(R.id.stepper_left) } - private val rightView by lazy { findViewById(R.id.stepper_right) } + private val startView by lazy { findViewById(R.id.stepper_start) } + private val endView by lazy { findViewById(R.id.stepper_end) } var listener: Listener? = null @@ -30,10 +31,10 @@ class StepperView(context: Context, attrs: AttributeSet): LinearLayout(context, private val subViewListener: OnTouchListener = OnTouchListener { view, event -> when (event.actionMasked) { MotionEvent.ACTION_DOWN -> { - listener?.stepperTouchDown(this, view == leftView) + listener?.stepperTouchDown(this, view == startView) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { - listener?.stepperTouchUp(this, view == leftView) + listener?.stepperTouchUp(this, view == startView) } } view.onTouchEvent(event) @@ -42,8 +43,11 @@ class StepperView(context: Context, attrs: AttributeSet): LinearLayout(context, init { View.inflate(context, R.layout.stepper_view, this) - leftView.setOnTouchListener(subViewListener) - rightView.setOnTouchListener(subViewListener) + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + startView.setBackgroundResource(if (isRTL) R.drawable.stepper_right else R.drawable.stepper_left) + endView.setBackgroundResource(if (isRTL) R.drawable.stepper_left else R.drawable.stepper_right) + startView.setOnTouchListener(subViewListener) + endView.setOnTouchListener(subViewListener) } interface Listener { diff --git a/app/src/main/java/space/celestia/mobilecelestia/common/ViewHolder.kt b/app/src/main/java/space/celestia/mobilecelestia/common/ViewHolder.kt index 192c6d7f..356ee6a1 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/common/ViewHolder.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/common/ViewHolder.kt @@ -12,10 +12,12 @@ package space.celestia.mobilecelestia.common import android.graphics.drawable.Drawable +import android.util.LayoutDirection import android.view.LayoutInflater import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import androidx.constraintlayout.helper.widget.Flow import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R @@ -34,9 +36,7 @@ class CommonTextViewHolder(parent: ViewGroup): val detail: TextView get() = itemView.findViewById(R.id.detail) - fun configure(title: String?, detail: String? = null, accessory: Drawable? = null) { - this.title.text = title - this.detail.text = detail - this.accessory.setImageDrawable(accessory) + init { + itemView.findViewById(R.id.flow).setHorizontalBias(if (itemView.resources.configuration.layoutDirection == LayoutDirection.RTL) 1f else 0f) } } \ No newline at end of file diff --git a/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt index e12ffd3c..b3316e8d 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt @@ -13,6 +13,7 @@ package space.celestia.mobilecelestia.control import android.content.Context import android.os.Bundle +import android.util.LayoutDirection import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -20,6 +21,7 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R +import space.celestia.mobilecelestia.common.InsetAwareFragment import space.celestia.mobilecelestia.info.model.CelestiaAction fun CelestiaAction.imageID(): Int? { @@ -47,7 +49,7 @@ fun CelestiaAction.imageID(): Int? { class CelestiaActionItem(val action: CelestiaAction, val image: Int) -class BottomControlFragment : Fragment() { +class BottomControlFragment : InsetAwareFragment() { private var listener: Listener? = null private var items: List = listOf() @@ -85,6 +87,18 @@ class BottomControlFragment : Fragment() { return view } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + applyPadding(view, currentSafeInsets) + } + + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) + + applyPadding(view, newInsets) + } + override fun onAttach(context: Context) { super.onAttach(context) if (context is Listener) { @@ -99,6 +113,16 @@ class BottomControlFragment : Fragment() { listener = null } + private fun applyPadding(view: View, insets: EdgeInsets) { + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + val paddingStart = (16.0 * resources.displayMetrics.density + (if (isRTL) insets.right else insets.left)).toInt() + val paddingBottom = (8.0 * resources.displayMetrics.density + insets.bottom).toInt() + if (isRTL) + view.setPadding(0, 0, paddingStart, paddingBottom) + else + view.setPadding(paddingStart, 0, 0, paddingBottom) + } + interface Listener { fun onActionSelected(item: CelestiaAction) fun onBottomControlHide() diff --git a/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlContainerFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlContainerFragment.kt index 5198ab66..9eb6edf7 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlContainerFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlContainerFragment.kt @@ -12,9 +12,9 @@ package space.celestia.mobilecelestia.control import android.os.Bundle -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment -class CameraControlContainerFragment : RightNavgationFragment() { +class CameraControlContainerFragment : EndNavgationFragment() { override fun createInitialFragment(savedInstanceState: Bundle?): SubFragment { return CameraControlFragment.newInstance() } diff --git a/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlFragment.kt index e11cd815..115d7c4c 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/control/CameraControlFragment.kt @@ -19,14 +19,14 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.utils.CelestiaString enum class CameraControlAction(val value: Int) { Pitch0(32), Pitch1(26), Yaw0(28), Yaw1(30), Roll0(31), Roll1(33), Reverse(-1); } -class CameraControlFragment : RightSubFragment() { +class CameraControlFragment : EndSubFragment() { private var listener: Listener? = null override fun onCreateView( diff --git a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderContainerFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderContainerFragment.kt index 6e2d6713..28ce57e2 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderContainerFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderContainerFragment.kt @@ -12,9 +12,9 @@ package space.celestia.mobilecelestia.eventfinder import android.os.Bundle -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment -class EventFinderContainerFragment : RightNavgationFragment() { +class EventFinderContainerFragment : EndNavgationFragment() { override fun createInitialFragment(savedInstanceState: Bundle?): SubFragment { return EventFinderInputFragment.newInstance() } diff --git a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderInputFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderInputFragment.kt index 64ecd3fd..8580ece4 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderInputFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderInputFragment.kt @@ -21,12 +21,12 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaAppCore import space.celestia.mobilecelestia.utils.* import java.util.* -class EventFinderInputFragment : RightSubFragment() { +class EventFinderInputFragment : EndSubFragment() { private var listener: Listener? = null private var adapter: EventFinderInputRecyclerViewAdapter? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultFragment.kt index 500ccf6d..d6ab9435 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultFragment.kt @@ -19,11 +19,11 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaEclipseFinder import space.celestia.mobilecelestia.utils.CelestiaString -class EventFinderResultFragment : RightSubFragment() { +class EventFinderResultFragment : EndSubFragment() { private var listener: Listener? = null override fun onCreateView( diff --git a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultRecyclerViewAdapter.kt index 5d277d24..1d695a78 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/eventfinder/EventFinderResultRecyclerViewAdapter.kt @@ -12,6 +12,7 @@ package space.celestia.mobilecelestia.eventfinder import android.annotation.SuppressLint +import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.common.CommonSectionV2 @@ -55,6 +56,7 @@ class EventFinderResultRecyclerViewAdapter( override fun bindVH(holder: RecyclerView.ViewHolder, item: RecyclerViewItem) { if (item is EventFinderEclipseItem && holder is CommonTextViewHolder) { holder.title.text = "${item.eclipse.occulter.name} -> ${item.eclipse.receiver.name}" + holder.detail.visibility = View.VISIBLE holder.detail.text = formatter.format(createDateFromJulianDay(item.eclipse.startTimeJulian)) return } diff --git a/app/src/main/java/space/celestia/mobilecelestia/favorite/DestinationDetailFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/favorite/DestinationDetailFragment.kt index e54a61ef..c3429cd0 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/favorite/DestinationDetailFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/favorite/DestinationDetailFragment.kt @@ -18,11 +18,11 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaDestination import space.celestia.mobilecelestia.utils.CelestiaString -class DestinationDetailFragment : RightSubFragment() { +class DestinationDetailFragment : EndSubFragment() { private var item: CelestiaDestination? = null private var listener: Listener? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteFragment.kt index 80a3847f..3c83aefe 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteFragment.kt @@ -14,9 +14,9 @@ package space.celestia.mobilecelestia.favorite import android.content.Context import android.os.Bundle import androidx.appcompat.widget.Toolbar -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment -class FavoriteFragment : RightNavgationFragment(), Toolbar.OnMenuItemClickListener { +class FavoriteFragment : EndNavgationFragment(), Toolbar.OnMenuItemClickListener { private var listener: Listener? = null private var initialItem: FavoriteBaseItem? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteItemFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteItemFragment.kt index 4bab9485..edac5121 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteItemFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/favorite/FavoriteItemFragment.kt @@ -21,10 +21,10 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R import space.celestia.mobilecelestia.common.NavigationFragment -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.utils.CelestiaString -class FavoriteItemFragment : RightSubFragment() { +class FavoriteItemFragment : EndSubFragment() { private var listener: Listener? = null var favoriteItem: FavoriteBaseItem? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/goto/GoToContainerFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/goto/GoToContainerFragment.kt index 470ca51d..cec08eee 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/goto/GoToContainerFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/goto/GoToContainerFragment.kt @@ -12,9 +12,9 @@ package space.celestia.mobilecelestia.goto import android.os.Bundle -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment -class GoToContainerFragment : RightNavgationFragment() { +class GoToContainerFragment : EndNavgationFragment() { private lateinit var goToData: GoToInputFragment.GoToData override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/space/celestia/mobilecelestia/goto/GoToInputFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/goto/GoToInputFragment.kt index 3077e0a4..40a10582 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/goto/GoToInputFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/goto/GoToInputFragment.kt @@ -19,13 +19,13 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaGoToLocation import space.celestia.mobilecelestia.utils.* import java.io.Serializable import java.util.* -class GoToInputFragment : RightSubFragment() { +class GoToInputFragment : EndSubFragment() { class GoToData(var objectName: String, var longitude: Float, var latitude: Float, var distance: Double, var distanceUnit: CelestiaGoToLocation.DistanceUnit) : Serializable diff --git a/app/src/main/java/space/celestia/mobilecelestia/help/HelpFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/help/HelpFragment.kt index 2b624992..42a57727 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/help/HelpFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/help/HelpFragment.kt @@ -13,6 +13,7 @@ package space.celestia.mobilecelestia.help import android.content.Context import android.os.Bundle +import android.util.LayoutDirection import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -72,13 +73,13 @@ class HelpFragment : InsetAwareFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - view.setPadding(0, currentSafeInsets.top, currentSafeInsets.right, currentSafeInsets.bottom) + applyPadding(view, currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) - view.setPadding(0, newInset.top, newInset.right, newInset.bottom) + applyPadding(view, newInsets) } override fun onAttach(context: Context) { @@ -95,6 +96,14 @@ class HelpFragment : InsetAwareFragment() { listener = null } + private fun applyPadding(view: View, insets: EdgeInsets) { + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + if (isRTL) + view.setPadding(insets.left, insets.top, 0, insets.bottom) + else + view.setPadding(0, insets.top, insets.right, insets.bottom) + } + interface Listener { fun onHelpActionSelected(action: HelpAction) fun onHelpURLSelected(url: String) diff --git a/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt index 01e4412f..02f4bc84 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt @@ -15,6 +15,7 @@ import android.content.Context import android.content.res.Resources import android.graphics.Rect import android.os.Bundle +import android.util.LayoutDirection import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -27,7 +28,7 @@ import kotlinx.coroutines.withContext import okhttp3.Dispatcher import space.celestia.mobilecelestia.R import space.celestia.mobilecelestia.common.NavigationFragment -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaAppCore import space.celestia.mobilecelestia.core.CelestiaSelection import space.celestia.mobilecelestia.info.model.* @@ -84,19 +85,13 @@ class InfoFragment : NavigationFragment.SubFragment() { if (savedInstanceState == null) title = "" - if (embeddedInNavigation) - view.setPadding(0, 0, currentSafeInsets.right, currentSafeInsets.bottom) - else - view.setPadding(0, currentSafeInsets.top, currentSafeInsets.right, currentSafeInsets.bottom) + applyPadding(view,currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) - if (embeddedInNavigation) - view.setPadding(0, 0, newInset.right, newInset.bottom) - else - view.setPadding(0, newInset.top, newInset.right, newInset.bottom) + applyPadding(view, newInsets) } override fun onAttach(context: Context) { @@ -113,6 +108,15 @@ class InfoFragment : NavigationFragment.SubFragment() { listener = null } + private fun applyPadding(view: View, insets: EdgeInsets) { + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + val top = if (embeddedInNavigation) 0 else insets.top + if (isRTL) + view.setPadding(insets.left, top, 0, insets.bottom) + else + view.setPadding(0, top, insets.right, insets.bottom) + } + interface Listener { fun onInfoActionSelected(action: InfoActionItem, selection: CelestiaSelection) fun onInfoLinkMetaDataClicked(url: URL) @@ -185,7 +189,8 @@ class InfoFragment : NavigationFragment.SubFragment() { parent: RecyclerView, state: RecyclerView.State ) { - val density = Resources.getSystem().displayMetrics.density + val density = parent.resources.displayMetrics.density + val isRTL = parent.resources.configuration.layoutDirection == LayoutDirection.RTL val spacing = (16 * density).toInt() val pos = parent.getChildLayoutPosition(view) @@ -198,11 +203,11 @@ class InfoFragment : NavigationFragment.SubFragment() { outRect.top = 0 outRect.bottom = spacing if ((pos - firstSingleColumnItem) % 2 == 1) { - outRect.left = spacing / 2 - outRect.right = spacing + outRect.left = if (isRTL) spacing else (spacing / 2) + outRect.right = if (isRTL) (spacing / 2) else spacing } else { - outRect.left = spacing - outRect.right = spacing / 2 + outRect.left = if (isRTL) (spacing / 2) else spacing + outRect.right = if (isRTL) spacing else (spacing / 2) } } } diff --git a/app/src/main/java/space/celestia/mobilecelestia/resource/AsyncListFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/resource/AsyncListFragment.kt index 3fb5880b..0a73a4ba 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/resource/AsyncListFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/resource/AsyncListFragment.kt @@ -22,12 +22,12 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.CircularProgressDrawable import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.utils.CelestiaString import space.celestia.mobilecelestia.utils.createLoadingDrawable import space.celestia.mobilecelestia.utils.showAlert -open class AsyncListFragment: RightSubFragment() { +open class AsyncListFragment: EndSubFragment() { private var selectListener: Listener? = null private var imageView: ImageView? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceFragment.kt index 2a4fac46..47fbabf6 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceFragment.kt @@ -14,11 +14,11 @@ package space.celestia.mobilecelestia.resource import android.content.Context import android.os.Bundle import androidx.appcompat.widget.Toolbar -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment import space.celestia.mobilecelestia.resource.model.ResourceCategory import space.celestia.mobilecelestia.resource.model.ResourceItem -class ResourceFragment : RightNavgationFragment(), Toolbar.OnMenuItemClickListener { +class ResourceFragment : EndNavgationFragment(), Toolbar.OnMenuItemClickListener { private var listener: Listener? = null override fun createInitialFragment(savedInstanceState: Bundle?): SubFragment { diff --git a/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceItemFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceItemFragment.kt index 3ced4825..24d689fe 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceItemFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/resource/ResourceItemFragment.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import space.celestia.mobilecelestia.R import space.celestia.mobilecelestia.common.ProgressView -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaAppCore import space.celestia.mobilecelestia.resource.model.ResourceAPI import space.celestia.mobilecelestia.resource.model.ResourceAPIService @@ -39,11 +39,11 @@ import java.io.File import java.text.DateFormat import java.util.* -class ResourceItemFragment : RightSubFragment(), ResourceManager.Listener { +class ResourceItemFragment : EndSubFragment(), ResourceManager.Listener { private var item: ResourceItem? = null private lateinit var progressView: ProgressView private lateinit var progressViewText: TextView - private lateinit var goToButtonContainer: View + private lateinit var goToButton: View private lateinit var goToButtonTextView: TextView private var currentState: ResourceItemState = ResourceItemState.None @@ -105,10 +105,10 @@ class ResourceItemFragment : RightSubFragment(), ResourceManager.Listener { this.imageView = image this.authorsLabel = authors this.releaseDateLabel = releaseDate - goToButtonContainer = view.findViewById(R.id.button_container) + goToButton = view.findViewById(R.id.go_to_button) goToButtonTextView = view.findViewById(R.id.button) goToButtonTextView.text = CelestiaString("Go", "") - goToButtonContainer.visibility = View.GONE + goToButton.visibility = View.GONE updateContents() updateUI() @@ -278,12 +278,12 @@ class ResourceItemFragment : RightSubFragment(), ResourceManager.Listener { val objectName = item.objectName if (currentState == ResourceItemState.Installed && objectName != null && listener?.objectExistsWithName(objectName) == true) { - goToButtonContainer.visibility = View.VISIBLE - goToButtonContainer.setOnClickListener { + goToButton.visibility = View.VISIBLE + goToButton.setOnClickListener { listener?.onGoToObject(objectName) } } else { - goToButtonContainer.visibility = View.GONE + goToButton.visibility = View.GONE } } diff --git a/app/src/main/java/space/celestia/mobilecelestia/search/SearchContainerFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/search/SearchContainerFragment.kt index 279779b6..0cacfd27 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/search/SearchContainerFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/search/SearchContainerFragment.kt @@ -22,7 +22,7 @@ import space.celestia.mobilecelestia.core.CelestiaSelection import space.celestia.mobilecelestia.info.InfoFragment import space.celestia.mobilecelestia.info.model.InfoDescriptionItem -class SearchContainerFragment : RightNavgationFragment() { +class SearchContainerFragment : EndNavgationFragment() { override fun createInitialFragment(savedInstanceState: Bundle?): SubFragment { return SearchFragment.newInstance() } diff --git a/app/src/main/java/space/celestia/mobilecelestia/search/SearchFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/search/SearchFragment.kt index 3f3662ef..20e754bf 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/search/SearchFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/search/SearchFragment.kt @@ -17,6 +17,7 @@ import android.content.Context import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle +import android.util.LayoutDirection import android.view.* import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager @@ -35,7 +36,7 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.withContext import space.celestia.mobilecelestia.R import space.celestia.mobilecelestia.common.NavigationFragment -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.core.CelestiaAppCore @ExperimentalCoroutinesApi @@ -100,17 +101,25 @@ class SearchFragment : NavigationFragment.SubFragment() { showNavigationBar = false } - topPadding.layoutParams.height = currentSafeInsets.top - searchView.setPadding(0, 0, currentSafeInsets.right, 0) - listView.setPadding(0, 0, currentSafeInsets.right, currentSafeInsets.bottom) + applyPadding(currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) - topPadding.layoutParams.height = newInset.top - searchView.setPadding(0, 0, newInset.right, 0) - listView.setPadding(0, 0, newInset.right, newInset.bottom) + applyPadding(newInsets) + } + + fun applyPadding(insets: EdgeInsets) { + topPadding.layoutParams.height = insets.top + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + if (isRTL) { + searchView.setPadding(insets.left, 0, 0, 0) + listView.setPadding(insets.left, 0, 0, insets.bottom) + } else { + searchView.setPadding(0, 0, insets.right, 0) + listView.setPadding(0, 0, insets.right, insets.bottom) + } } @FlowPreview diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/AboutFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/AboutFragment.kt index bc533ecf..62594f8f 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/AboutFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/AboutFragment.kt @@ -19,13 +19,13 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.utils.AssetUtils import space.celestia.mobilecelestia.utils.CelestiaString import space.celestia.mobilecelestia.utils.versionCode import space.celestia.mobilecelestia.utils.versionName -class AboutFragment : RightSubFragment() { +class AboutFragment : EndSubFragment() { private var listener: Listener? = null override fun onCreateView( diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/AboutRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/AboutRecyclerViewAdapter.kt index 1e9f64f2..7acbec88 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/AboutRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/AboutRecyclerViewAdapter.kt @@ -95,6 +95,7 @@ class AboutRecyclerViewAdapter( when (item) { is VersionItem -> { holder.title.text = item.title + holder.detail.visibility = View.VISIBLE holder.detail.text = item.versionName } is ActionItem -> { diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsCommonRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsCommonRecyclerViewAdapter.kt index f3f19385..af6dc9e5 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsCommonRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsCommonRecyclerViewAdapter.kt @@ -80,15 +80,15 @@ class SettingsCommonRecyclerViewAdapter( if (holder is CommonTextViewHolder) { when (item) { is SettingsActionItem -> { - holder.configure(item.name) + holder.title.text = item.name } is SettingsUnknownTextItem -> { - holder.configure(item.name) + holder.title.text = item.name } is SettingsSwitchItem -> { val on = dataSource?.commonSettingSwitchState(item.key) ?: false holder.title.text = item.name - holder.accessory.visibility = if (on) View.VISIBLE else View.INVISIBLE + holder.accessory.visibility = if (on) View.VISIBLE else View.GONE } } return diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsFragment.kt index 3eb3dc84..f355ad08 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsFragment.kt @@ -14,10 +14,10 @@ package space.celestia.mobilecelestia.settings import android.os.Bundle import space.celestia.mobilecelestia.R import space.celestia.mobilecelestia.celestia.CelestiaView -import space.celestia.mobilecelestia.common.RightNavgationFragment +import space.celestia.mobilecelestia.common.EndNavgationFragment import space.celestia.mobilecelestia.core.CelestiaAppCore -class SettingsFragment : RightNavgationFragment() { +class SettingsFragment : EndNavgationFragment() { override fun createInitialFragment(savedInstanceState: Bundle?): SubFragment { return SettingsItemFragment.newInstance() } diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsLanguageRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsLanguageRecyclerViewAdapter.kt index 8827e1d4..e5b26302 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsLanguageRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsLanguageRecyclerViewAdapter.kt @@ -121,7 +121,7 @@ class SettingsLanguageRecyclerViewAdapter( override fun bindVH(holder: RecyclerView.ViewHolder, item: RecyclerViewItem) { if (item is SpecificLanguageItem && holder is CommonTextViewHolder) { holder.title.text = item.title - holder.accessory.visibility = if (dataSource?.currentOverrideLanguage() == item.language) View.VISIBLE else View.INVISIBLE + holder.accessory.visibility = if (dataSource?.currentOverrideLanguage() == item.language) View.VISIBLE else View.GONE return } if (item is LanguageItem && holder is CommonTextViewHolder) { diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsModel.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsModel.kt index 18b79298..ee63b92b 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsModel.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsModel.kt @@ -14,7 +14,7 @@ package space.celestia.mobilecelestia.settings import space.celestia.mobilecelestia.common.CommonSectionV2 import space.celestia.mobilecelestia.common.NavigationFragment import space.celestia.mobilecelestia.common.RecyclerViewItem -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment import space.celestia.mobilecelestia.utils.CelestiaString import space.celestia.mobilecelestia.utils.PreferenceManager import java.io.Serializable @@ -500,6 +500,6 @@ class SettingsCommonItem(override val name: String, val sections: List
) } } -open class SettingsBaseFragment: RightSubFragment() { +open class SettingsBaseFragment: EndSubFragment() { open fun reload() {} } diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsMultiSelectionRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsMultiSelectionRecyclerViewAdapter.kt index 1fb17109..a2d9a84b 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsMultiSelectionRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsMultiSelectionRecyclerViewAdapter.kt @@ -86,7 +86,7 @@ class SettingsMultiSelectionRecyclerViewAdapter( val core = CelestiaAppCore.shared() if (item is SettingsMultiSelectionItem.Selection && holder is CommonTextViewHolder) { holder.title.text = item.name - holder.accessory.visibility = if (core.getBooleanValueForPield(item.key)) View.VISIBLE else View.INVISIBLE + holder.accessory.visibility = if (core.getBooleanValueForPield(item.key)) View.VISIBLE else View.GONE return } if (item is MasterSwitch && holder is MasterViewHolder) { diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsSingleSelectionRecyclerViewAdapter.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsSingleSelectionRecyclerViewAdapter.kt index bd75a36c..3205ff1f 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsSingleSelectionRecyclerViewAdapter.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SettingsSingleSelectionRecyclerViewAdapter.kt @@ -63,7 +63,7 @@ class SettingsSingleSelectionRecyclerViewAdapter( val current = core.getIntValueForField(this.item.key) if (item is SettingsSingleSelectionItem.Selection && holder is CommonTextViewHolder) { holder.title.text = item.name - holder.accessory.visibility = if (current == item.value) View.VISIBLE else View.INVISIBLE + holder.accessory.visibility = if (current == item.value) View.VISIBLE else View.GONE return } super.bindVH(holder, item) diff --git a/app/src/main/java/space/celestia/mobilecelestia/settings/SimpleTextFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/settings/SimpleTextFragment.kt index 6217d776..1239dcbb 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/settings/SimpleTextFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/settings/SimpleTextFragment.kt @@ -17,9 +17,9 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import space.celestia.mobilecelestia.R -import space.celestia.mobilecelestia.common.RightSubFragment +import space.celestia.mobilecelestia.common.EndSubFragment -class SimpleTextFragment : RightSubFragment() { +class SimpleTextFragment : EndSubFragment() { private var textTitle: String? = null private var textDetail: String? = null diff --git a/app/src/main/java/space/celestia/mobilecelestia/toolbar/ToolbarFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/toolbar/ToolbarFragment.kt index 2adb91ae..ef5715e4 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/toolbar/ToolbarFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/toolbar/ToolbarFragment.kt @@ -13,6 +13,7 @@ package space.celestia.mobilecelestia.toolbar import android.content.Context import android.os.Bundle +import android.util.LayoutDirection import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -107,13 +108,13 @@ class ToolbarFragment : InsetAwareFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - view.setPadding(0, currentSafeInsets.top, currentSafeInsets.right, currentSafeInsets.bottom) + applyPadding(view, currentSafeInsets) } - override fun onInsetChanged(view: View, newInset: EdgeInsets) { - super.onInsetChanged(view, newInset) + override fun onInsetChanged(view: View, newInsets: EdgeInsets) { + super.onInsetChanged(view, newInsets) - view.setPadding(0, newInset.top, newInset.right, newInset.bottom) + applyPadding(view, newInsets) } override fun onAttach(context: Context) { @@ -125,6 +126,14 @@ class ToolbarFragment : InsetAwareFragment() { } } + private fun applyPadding(view: View, insets: EdgeInsets) { + val isRTL = resources.configuration.layoutDirection == LayoutDirection.RTL + if (isRTL) + view.setPadding(insets.left, insets.top, 0, insets.bottom) + else + view.setPadding(0, insets.top, insets.right, insets.bottom) + } + override fun onDetach() { super.onDetach() listener = null diff --git a/app/src/main/res/drawable/button_background_selector.xml b/app/src/main/res/drawable/button_background_selector.xml index b963f6f3..6ad0c696 100644 --- a/app/src/main/res/drawable/button_background_selector.xml +++ b/app/src/main/res/drawable/button_background_selector.xml @@ -10,27 +10,7 @@ ~ of the License, or (at your option) any later version. --> - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_action_back_tint.xml b/app/src/main/res/drawable/ic_action_back_tint.xml new file mode 100644 index 00000000..a91c2111 --- /dev/null +++ b/app/src/main/res/drawable/ic_action_back_tint.xml @@ -0,0 +1,15 @@ + + + + diff --git a/app/src/main/res/drawable/ripple_button_background.xml b/app/src/main/res/drawable/ripple_button_background.xml new file mode 100644 index 00000000..be0e1512 --- /dev/null +++ b/app/src/main/res/drawable/ripple_button_background.xml @@ -0,0 +1,17 @@ + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 51ff7bdb..6e9d5a80 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -109,9 +109,7 @@ - - - + style="@style/ActionButtonLabel" /> \ No newline at end of file diff --git a/app/src/main/res/layout/common_progress_button.xml b/app/src/main/res/layout/common_progress_button.xml new file mode 100644 index 00000000..79f8c934 --- /dev/null +++ b/app/src/main/res/layout/common_progress_button.xml @@ -0,0 +1,31 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/common_section_footer.xml b/app/src/main/res/layout/common_section_footer.xml new file mode 100644 index 00000000..c0bd472d --- /dev/null +++ b/app/src/main/res/layout/common_section_footer.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/app/src/main/res/layout/common_section_header.xml b/app/src/main/res/layout/common_section_header.xml new file mode 100644 index 00000000..44fa4c1f --- /dev/null +++ b/app/src/main/res/layout/common_section_header.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/app/src/main/res/layout/common_text_list_item.xml b/app/src/main/res/layout/common_text_list_item.xml index f3aa3982..28dff1f8 100644 --- a/app/src/main/res/layout/common_text_list_item.xml +++ b/app/src/main/res/layout/common_text_list_item.xml @@ -12,36 +12,51 @@ - + + - + android:orientation="horizontal" + app:constraint_referenced_ids="title,detail" + app:flow_horizontalStyle="spread_inside" + app:flow_wrapMode="chain" + app:flow_verticalGap="6dp" + app:flow_verticalAlign="center" + app:flow_horizontalGap="8dp" + app:flow_horizontalBias="0" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + android:inputType="textPersonName" + android:background="@android:color/transparent"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bottom_control_list.xml b/app/src/main/res/layout/fragment_bottom_control_list.xml index 4a4f6e9a..54d2d78a 100644 --- a/app/src/main/res/layout/fragment_bottom_control_list.xml +++ b/app/src/main/res/layout/fragment_bottom_control_list.xml @@ -16,13 +16,14 @@ tools:context=".control.BottomControlFragment" android:layout_width="wrap_content" android:layout_height="wrap_content" - style="@style/ControlViewBackground"> + style="@style/Container"> + android:layout_marginVertical="2dp" + style="@style/ControlViewBackground"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_resource_item.xml b/app/src/main/res/layout/fragment_resource_item.xml index a8ca08d2..20aca063 100644 --- a/app/src/main/res/layout/fragment_resource_item.xml +++ b/app/src/main/res/layout/fragment_resource_item.xml @@ -79,35 +79,14 @@ android:layout_height="8dp"/> - - - - - - - - + android:layout_height="wrap_content"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_search_item_list.xml b/app/src/main/res/layout/fragment_search_item_list.xml index bff23055..bc43620c 100644 --- a/app/src/main/res/layout/fragment_search_item_list.xml +++ b/app/src/main/res/layout/fragment_search_item_list.xml @@ -40,7 +40,7 @@ android:layout_gravity="center" android:padding="6dp" android:visibility="gone" - android:src="@drawable/ic_action_arrow_back" /> + android:src="@drawable/ic_action_back_tint" /> + android:clickable="true"> + android:clickable="true"> + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c942552e..88204a50 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -11,7 +11,7 @@ - + + + +