Skip to content

Commit

Permalink
[feature] Support display title, date and author on the read screen
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed May 29, 2024
1 parent 4871f1d commit dc7955b
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 16
versionName = "1.1-beta38"
versionName = "1.1-beta39"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.skyd.anivu.model.bean.ArticleWithEnclosureBean
import com.skyd.anivu.model.db.dao.ArticleDao
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

Expand All @@ -13,6 +14,7 @@ class ReadRepository @Inject constructor(
) : BaseRepository() {
fun requestArticleWithEnclosure(articleId: String): Flow<ArticleWithEnclosureBean?> {
return articleDao.getArticleWithEnclosures(articleId = articleId)
.filterNotNull()
.flowOn(Dispatchers.IO)
}
}
60 changes: 42 additions & 18 deletions app/src/main/java/com/skyd/anivu/ui/fragment/read/ReadFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import com.skyd.anivu.ext.addInsetsByPadding
import com.skyd.anivu.ext.collectIn
import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.getOrDefault
import com.skyd.anivu.ext.gone
import com.skyd.anivu.ext.ifNullOfBlank
import com.skyd.anivu.ext.openBrowser
import com.skyd.anivu.ext.popBackStackWithLifecycle
import com.skyd.anivu.ext.startWith
import com.skyd.anivu.ext.toDateTimeString
import com.skyd.anivu.ext.toHtml
import com.skyd.anivu.ext.visible
import com.skyd.anivu.model.bean.ArticleWithEnclosureBean
import com.skyd.anivu.model.bean.LinkEnclosureBean
import com.skyd.anivu.model.preference.rss.ParseLinkTagAsEnclosurePreference
Expand Down Expand Up @@ -86,25 +89,46 @@ class ReadFragment : BaseFragment<FragmentReadBinding>() {
}

is ArticleState.Success -> {
binding.topAppBar.menu?.apply {
findItem(R.id.action_read_fragment_open_in_browser)?.isEnabled = true
findItem(R.id.action_read_fragment_share)?.isEnabled = true
}
val article = articleState.article
binding.tvReadFragmentContent.post {
binding.tvReadFragmentContent.text = article.article.content
.ifNullOfBlank { article.article.description.orEmpty() }
.toHtml(
imageGetter = ImageGetter(
context = requireContext(),
maxWidth = { binding.tvReadFragmentContent.width },
onSuccess = { _, _ ->
binding.tvReadFragmentContent.text =
binding.tvReadFragmentContent.text
}
),
tagHandler = null,
)

with(binding) {
topAppBar.menu?.apply {
findItem(R.id.action_read_fragment_open_in_browser)?.isEnabled = true
findItem(R.id.action_read_fragment_share)?.isEnabled = true
}

tvReadFragmentTitle.text = article.article.title

val date = article.article.date
if (date == null) {
tvReadFragmentDate.gone()
} else {
tvReadFragmentDate.visible()
tvReadFragmentDate.text = date.toDateTimeString(context = requireContext())
}

val author = article.article.author
if (author.isNullOrBlank()) {
tvReadFragmentAuthor.gone()
} else {
tvReadFragmentAuthor.text = author
tvReadFragmentAuthor.visible()
}

tvReadFragmentContent.post {
tvReadFragmentContent.text = article.article.content
.ifNullOfBlank { article.article.description.orEmpty() }
.toHtml(
imageGetter = ImageGetter(
context = requireContext(),
maxWidth = { tvReadFragmentContent.width },
onSuccess = { _, _ ->
tvReadFragmentContent.text = tvReadFragmentContent.text
}
),
tagHandler = null,
)
}
}

enclosureBottomSheet?.updateData(getEnclosuresList(requireContext(), article))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ internal fun Modifier.detectControllerGestures(
},
onGesture = onGesture@{ _: Offset, pan: Offset, zoom: Float, rotation: Float ->
with(transformState()) {
transformStateCallback.onVideoOffset(videoOffset + pan)
transformStateCallback.onVideoOffset(videoOffset + pan / videoZoom)
transformStateCallback.onVideoRotate(videoRotate + rotation)
transformStateCallback.onVideoZoom(videoZoom * zoom)
}
Expand Down
57 changes: 53 additions & 4 deletions app/src/main/res/layout/fragment_read.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,61 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<TextView
android:id="@+id/tv_read_fragment_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textIsSelectable="true" />
android:orientation="vertical">

<TextView
android:id="@+id/tv_read_fragment_title"
style="?attr/textAppearanceTitleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3"
android:paddingHorizontal="16dp"
android:paddingTop="16dp"
android:paddingBottom="6dp" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingHorizontal="16dp">

<TextView
android:id="@+id/tv_read_fragment_date"
style="?attr/textAppearanceLabelLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="8dp"
android:singleLine="true"
android:textColor="?attr/colorOnSurfaceVariant"
android:textIsSelectable="true" />

<TextView
android:id="@+id/tv_read_fragment_author"
style="?attr/textAppearanceLabelLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginBottom="8dp"
android:singleLine="true"
android:textColor="?attr/colorOnSurfaceVariant"
android:textIsSelectable="true" />
</LinearLayout>

<TextView
android:id="@+id/tv_read_fragment_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingTop="6dp"
android:paddingBottom="16dp"
android:textIsSelectable="true" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<string name="import_opml_screen_opml_not_selected">请选择一个 OPML 文件</string>
<string name="data_fragment_sync_category">同步</string>
<string name="import_export_screen_description">通过 OPML 文件来导入与导出订阅数据</string>
<string name="player_speed">速度</string>
<plurals name="import_opml_result">
<item quantity="other">导入了 %d 项,花费 %.2f 秒</item>
</plurals>
Expand Down

0 comments on commit dc7955b

Please sign in to comment.