Skip to content

Commit

Permalink
[feature|fix] Support to open the article link in a browser; fix a cr…
Browse files Browse the repository at this point in the history
…ash when feed url and article link are same but articleId is not same
  • Loading branch information
SkyD666 committed Feb 18, 2024
1 parent 4f9679e commit d2569db
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ android {
}
release {
signingConfig = signingConfigs.getByName("release") // signing
isMinifyEnabled = true
isShrinkResources = true
isMinifyEnabled = false
isShrinkResources = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
android:name=".App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/locales_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AniVu"
Expand Down
21 changes: 15 additions & 6 deletions app/src/main/java/com/skyd/anivu/model/db/dao/ArticleDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ interface ArticleDao {
val hiltEntryPoint =
EntryPointAccessors.fromApplication(appContext, ArticleDaoEntryPoint::class.java)
articleWithEnclosureList.forEach {
if (queryArticleByLink(
link = it.article.link,
feedUrl = it.article.feedUrl,
) == null
) {
// 可能会出现link、feedUrl都一样,但是uuid不一样的情况
var newArticle = queryArticleByLink(
link = it.article.link,
feedUrl = it.article.feedUrl,
)
if (newArticle == null) {
innerUpdateArticle(it.article)
newArticle = it.article
} else {
// 除了uuid,其他的字段都更新
newArticle = it.article.copy(articleId = newArticle.articleId)
innerUpdateArticle(newArticle)
}
hiltEntryPoint.enclosureDao.insertListIfNotExist(it.enclosures)

hiltEntryPoint.enclosureDao.insertListIfNotExist(
it.enclosures.map { enclosure -> enclosure.copy(articleId = newArticle.articleId) }
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ class Article1Proxy : VarietyAdapter.Proxy<ArticleBean, ItemArticle1Binding, Art
}
}
data.date?.toDateTimeString().let { dateTime ->
if (!dateTime.isNullOrBlank()) {
if (dateTime.isNullOrBlank()) {
tvArticle1Date.gone()
} else {
tvArticle1Date.visible()
tvArticle1Date.text = dateTime
}
}
data.author.let { author ->
if (author.isNullOrBlank()) {
tvArticle1Author.gone()
} else {
tvArticle1Author.visible()
tvArticle1Author.text = author
}
}
if (data.image.isNullOrBlank()) {
cvArticle1Image.gone()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ArticleViewModel @Inject constructor(
articleRepo.refreshArticleList(intent.url).map {
ArticlePartialStateChange.RefreshArticleList.Success
}.startWith(ArticlePartialStateChange.RefreshArticleList.Loading).catchMap {
it.printStackTrace()
ArticlePartialStateChange.RefreshArticleList.Failed(it.message.toString())
}
},
Expand Down
24 changes: 24 additions & 0 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 @@ -16,6 +16,7 @@ import com.skyd.anivu.ext.addInsetsByMargin
import com.skyd.anivu.ext.addInsetsByPadding
import com.skyd.anivu.ext.collectIn
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.toHtml
Expand Down Expand Up @@ -43,17 +44,25 @@ class ReadFragment : BaseFragment<FragmentReadBinding>() {
when (val articleState = readState.articleState) {
is ArticleState.Failed -> {
enclosureBottomSheet?.updateData(emptyList())
binding.topAppBar.menu?.findItem(R.id.action_read_fragment_open_in_browser)
?.isEnabled = false
}

ArticleState.Init -> {
enclosureBottomSheet?.updateData(emptyList())
binding.topAppBar.menu?.findItem(R.id.action_read_fragment_open_in_browser)
?.isEnabled = false
}

ArticleState.Loading -> {
enclosureBottomSheet?.updateData(emptyList())
binding.topAppBar.menu?.findItem(R.id.action_read_fragment_open_in_browser)
?.isEnabled = false
}

is ArticleState.Success -> {
binding.topAppBar.menu?.findItem(R.id.action_read_fragment_open_in_browser)
?.isEnabled = true
val article = articleState.article
binding.tvReadFragmentContent.post {
binding.tvReadFragmentContent.text = article.article.content
Expand Down Expand Up @@ -96,7 +105,22 @@ class ReadFragment : BaseFragment<FragmentReadBinding>() {

override fun FragmentReadBinding.initView() {
topAppBar.setNavigationOnClickListener { findNavController().popBackStackWithLifecycle() }
topAppBar.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_read_fragment_open_in_browser -> {
val articleState = feedViewModel.viewState.value.articleState
if (articleState is ArticleState.Success) {
val link = articleState.article.article.link
if (!link.isNullOrBlank()) {
requireContext().openBrowser(link)
}
}
true
}

else -> false
}
}
tvReadFragmentContent.movementMethod = LinkMovementMethod.getInstance()

fabReadFragment.setOnClickListener {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_public_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM440,798L440,720Q407,720 383.5,696.5Q360,673 360,640L360,600L168,408Q165,426 162.5,444Q160,462 160,480Q160,601 239.5,692Q319,783 440,798ZM716,696Q736,674 752,648.5Q768,623 778.5,595.5Q789,568 794.5,539Q800,510 800,480Q800,382 745.5,301Q691,220 600,184L600,200Q600,233 576.5,256.5Q553,280 520,280L440,280L440,360Q440,377 428.5,388.5Q417,400 400,400L320,400L320,480L560,480Q577,480 588.5,491.5Q600,503 600,520L600,640L640,640Q666,640 687,655.5Q708,671 716,696Z" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_read.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:menu="@menu/menu_read"
app:navigationContentDescription="@string/back"
app:navigationIcon="@drawable/ic_arrow_back_24"
app:subtitleCentered="true"
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/layout/item_article_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
tools:text="title" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/tv_article_1_date"
android:id="@+id/tv_article_1_author"
style="?attr/textAppearanceLabelSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -32,6 +32,19 @@
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_article_1_title"
tools:text="orion321" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/tv_article_1_date"
style="?attr/textAppearanceLabelSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="@id/tv_article_1_title"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_article_1_author"
tools:text="2024年2月4日 22点10分" />

<com.google.android.material.textview.MaterialTextView
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/menu/menu_read.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_read_fragment_open_in_browser"
android:icon="@drawable/ic_public_24"
android:title="@string/read_fragment_open_browser"
app:showAsAction="ifRoom" />
</menu>
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 @@ -60,4 +60,5 @@
<string name="clear_input_text">清除</string>
<string name="article_fragment_search_article">搜索文章</string>
<string name="feed_fragment_search_feed">搜索订阅</string>
<string name="read_fragment_open_browser">在浏览器中打开</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@
<string name="clear_input_text">Clear</string>
<string name="article_fragment_search_article">Search articles</string>
<string name="feed_fragment_search_feed">Search feeds</string>
<string name="read_fragment_open_browser">Open in browser</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/locales_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en" />
<locale android:name="zh" />
</locale-config>

0 comments on commit d2569db

Please sign in to comment.