Skip to content

Commit

Permalink
Display title, author name in header view
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr committed Oct 1, 2020
1 parent 03db5a1 commit 8790672
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ import org.wordpress.android.util.AniUtils
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T
import org.wordpress.android.util.AppLog.T.READER
import org.wordpress.android.util.DateTimeUtils
import org.wordpress.android.util.DisplayUtils
import org.wordpress.android.util.HtmlUtils
import org.wordpress.android.util.NetworkUtils
Expand Down Expand Up @@ -1414,9 +1413,6 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
readerWebView.setIsPrivatePost(post!!.isPrivate)
readerWebView.setBlogSchemeIsHttps(UrlUtils.isHttps(post!!.blogUrl))

val txtTitle = view!!.findViewById<TextView>(R.id.text_title)
val txtDateline = view!!.findViewById<TextView>(R.id.text_dateline)

val tagStrip = view!!.findViewById<ReaderTagStrip>(R.id.tag_strip)
val headerView = view!!.findViewById<ReaderPostDetailHeaderView>(R.id.header_view)
if (!canShowFooter()) {
Expand Down Expand Up @@ -1501,14 +1497,6 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
}
}

txtTitle.text = if (post!!.hasTitle()) post!!.title else getString(R.string.reader_untitled_post)

val timestamp = DateTimeUtils.javaDateToTimeSpan(
post!!.displayDate,
WordPress.getContext()
)
txtDateline.text = timestamp

val postDetailsHeaderUiState = createPostDetailsHeaderUiState(post!!, headerView)
headerView.updatePost(postDetailsHeaderUiState)

Expand All @@ -1530,8 +1518,13 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
ReaderActivityLauncher.showReaderBlogPreview(context, post)
}
val hasAccessToken = accountStore.hasAccessToken()
val textTitle = post
.takeIf { post.hasTitle() }
?.title ?: getString(string.reader_untitled_post)

return ReaderPostDetailsHeaderUiState(
textTitle,
post.authorName,
postUiStateBuilder.mapPostToPostHeaderUiState(
post,
onPostHeaderClicked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class ReaderPostUiStateBuilder @Inject constructor(
)
}

fun mapPostToPostHeaderUiState(
fun mapPostToBlogSectionUiState(
post: ReaderPost,
onPostHeaderViewClicked: (Long, Long) -> Unit
): ReaderBlogSectionUiState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.wordpress.android.util.setVisible
import javax.inject.Inject

/**
* topmost view in post detail - shows blavatar, author name, blog name, and follow button
* topmost view in post detail
*/
class ReaderPostDetailHeaderView @JvmOverloads constructor(
context: Context,
Expand All @@ -40,11 +40,16 @@ class ReaderPostDetailHeaderView @JvmOverloads constructor(
updateBlavatar(blogSectionUiState)
updateFollowButton(uiState.followButtonUiState)

uiHelpers.setTextOrHide(text_title, uiState.title)
uiHelpers.setTextOrHide(text_author, uiState.authorName)
uiHelpers.setTextOrHide(text_author_and_blog_name, blogSectionUiState.blogName)
uiHelpers.setTextOrHide(text_blog_url, blogSectionUiState.blogUrl)
uiHelpers.updateVisibility(dot_separator, blogSectionUiState.dotSeparatorVisibility)
uiHelpers.setTextOrHide(text_dateline, blogSectionUiState.dateLine)

dot_separator.setVisible(blogSectionUiState.dotSeparatorVisibility)
text_by.setVisible(uiState.authorName != null)

layout_post_header.setBackgroundResource(
layout_post_header.context.getDrawableResIdFromAttribute(
blogSectionUiState.blogSectionClickData?.background ?: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.wordpress.android.ui.reader.views.uistates

import org.wordpress.android.ui.utils.UiString

sealed class ReaderPostDetailsHeaderViewUiState {
data class ReaderPostDetailsHeaderUiState(
val title: UiString?,
val authorName: String?,
val blogSectionUiState: ReaderBlogSectionUiState,
val followButtonUiState: FollowButtonUiState
) : ReaderPostDetailsHeaderViewUiState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,11 @@
android:orientation="vertical"
android:paddingTop="@dimen/margin_medium">

<org.wordpress.android.widgets.WPTextView
android:id="@+id/text_title"
style="@style/ReaderTextView.Post.Title.Detail"
tools:text="text_title" />

<LinearLayout
android:id="@+id/layout_dateline"
<org.wordpress.android.ui.reader.views.ReaderTagStrip
android:id="@+id/tag_strip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<org.wordpress.android.widgets.WPTextView
android:id="@+id/text_dateline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/margin_large"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?attr/wpColorOnSurfaceMedium"
tools:text="text_dateline" />

<org.wordpress.android.ui.reader.views.ReaderTagStrip
android:id="@+id/tag_strip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
android:layout_gravity="center_vertical" />

<org.wordpress.android.ui.reader.views.ReaderWebView
android:id="@+id/reader_webview"
Expand Down
42 changes: 31 additions & 11 deletions WordPress/src/main/res/layout/reader_post_detail_header_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_title"
style="@style/ReaderTextView.Post.Title.Detail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="text_title" />

<include layout="@layout/reader_post_header"
android:id="@+id/layout_post_header"
android:layout_width="0dp"
Expand All @@ -17,21 +25,33 @@
android:visibility="visible"
android:clickable="true"
android:focusable="true"
android:layout_marginTop="@dimen/margin_medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/header_follow_button"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/text_title" />

<!--<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_header_subtitle"
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/material_emphasis_high_type"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?attr/colorOnSurface"
android:layout_marginStart="@dimen/margin_extra_large"
app:layout_constraintStart_toEndOf="@id/image_header_blavatar"
app:layout_constraintTop_toBottomOf="@id/text_header_title"
tools:text="text_header_blog_name"/>-->
android:layout_marginTop="@dimen/margin_large"
android:text="@string/reader_post_details_header_by"
android:includeFontPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_post_header"
tools:text="By"/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_author"
style="@style/ReaderTextView.Site.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:layout_marginStart="@dimen/margin_small"
android:includeFontPadding="false"
app:layout_constraintStart_toEndOf="@id/text_by"
app:layout_constraintTop_toBottomOf="@id/layout_post_header"
tools:text="text_author"/>

<org.wordpress.android.ui.reader.views.ReaderFollowButton
android:id="@+id/header_follow_button"
Expand All @@ -40,7 +60,7 @@
android:visibility="gone"
android:layout_marginStart="@dimen/margin_extra_large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_title"
app:wpShowFollowButtonCaption="false"
tools:visibility="visible"/>

Expand Down
1 change: 1 addition & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@
<string name="reader_expandable_tags_view_overflow_indicator_expand_title" translatable="false">%1$s+</string>
<string name="reader_expandable_tags_view_overflow_indicator_collapse_title">Hide</string>
<string name="reader_discover_interests_header">You might like</string>
<string name="reader_post_details_header_by">By</string>
<string name="show_n_hidden_items_desc">%1$s more items</string>

<!-- editor -->
Expand Down

0 comments on commit 8790672

Please sign in to comment.