-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Support parsing the link tag as enclosure
- Loading branch information
Showing
20 changed files
with
483 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/skyd/anivu/model/bean/LinkEnclosureBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.skyd.anivu.model.bean | ||
|
||
import com.skyd.anivu.base.BaseBean | ||
|
||
data class LinkEnclosureBean( | ||
val link: String, | ||
) : BaseBean |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/skyd/anivu/model/bean/settings/SettingsSwitchBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.skyd.anivu.model.bean.settings | ||
|
||
import android.graphics.drawable.Drawable | ||
import com.skyd.anivu.base.BaseBean | ||
|
||
data class SettingsSwitchBean( | ||
val title: String, | ||
val description: String, | ||
val icon: Drawable, | ||
val isChecked: () -> Boolean = { false }, | ||
val onCheckedChanged: ((Boolean) -> Unit)? = null, | ||
) : BaseBean |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/skyd/anivu/model/preference/rss/ParseLinkTagAsEnclosurePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.skyd.anivu.model.preference.rss | ||
|
||
import android.content.Context | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import com.skyd.anivu.base.BasePreference | ||
import com.skyd.anivu.ext.dataStore | ||
import com.skyd.anivu.ext.put | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
object ParseLinkTagAsEnclosurePreference : BasePreference<Boolean> { | ||
private const val PARSE_LINK_TAG_AS_ENCLOSURE = "parseLinkTagAsEnclosure" | ||
override val default = true | ||
|
||
val key = booleanPreferencesKey(PARSE_LINK_TAG_AS_ENCLOSURE) | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: Boolean) { | ||
scope.launch(Dispatchers.IO) { | ||
context.dataStore.put(key, value) | ||
} | ||
} | ||
|
||
override fun fromPreferences(preferences: Preferences): Boolean = preferences[key] ?: default | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/skyd/anivu/ui/adapter/variety/proxy/LinkEnclosure1Proxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.skyd.anivu.ui.adapter.variety.proxy | ||
|
||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import com.skyd.anivu.databinding.ItemLinkEnclosure1Binding | ||
import com.skyd.anivu.ext.copy | ||
import com.skyd.anivu.model.bean.LinkEnclosureBean | ||
import com.skyd.anivu.ui.adapter.variety.LinkEnclosure1ViewHolder | ||
import com.skyd.anivu.ui.adapter.variety.VarietyAdapter | ||
|
||
|
||
class LinkEnclosure1Proxy( | ||
private val onDownload: (LinkEnclosureBean) -> Unit, | ||
) : VarietyAdapter.Proxy<LinkEnclosureBean, ItemLinkEnclosure1Binding, LinkEnclosure1ViewHolder>() { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = | ||
LinkEnclosure1ViewHolder( | ||
ItemLinkEnclosure1Binding | ||
.inflate(LayoutInflater.from(parent.context), parent, false), | ||
) | ||
|
||
override fun onBindViewHolder( | ||
holder: LinkEnclosure1ViewHolder, | ||
data: LinkEnclosureBean, | ||
index: Int, | ||
action: ((Any?) -> Unit)? | ||
) { | ||
val context = holder.itemView.context | ||
holder.binding.apply { | ||
tvEnclosure1Url.text = data.link | ||
tvEnclosure1Url.setOnClickListener { | ||
data.link.copy(context) | ||
} | ||
btnEnclosure1Download.setOnClickListener { | ||
onDownload(data) | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/skyd/anivu/ui/adapter/variety/proxy/settings/SettingsSwitchProxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.skyd.anivu.ui.adapter.variety.proxy.settings | ||
|
||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import com.skyd.anivu.databinding.ItemSettingsSwitchBinding | ||
import com.skyd.anivu.model.bean.settings.SettingsSwitchBean | ||
import com.skyd.anivu.ui.adapter.variety.SettingsSwitchViewHolder | ||
import com.skyd.anivu.ui.adapter.variety.VarietyAdapter | ||
|
||
|
||
class SettingsSwitchProxy( | ||
private val adapter: VarietyAdapter, | ||
) : VarietyAdapter.Proxy<SettingsSwitchBean, ItemSettingsSwitchBinding, SettingsSwitchViewHolder>() { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingsSwitchViewHolder { | ||
val holder = SettingsSwitchViewHolder( | ||
ItemSettingsSwitchBinding | ||
.inflate(LayoutInflater.from(parent.context), parent, false), | ||
) | ||
|
||
holder.itemView.setOnClickListener { | ||
val data = adapter.dataList.getOrNull(holder.bindingAdapterPosition) | ||
if (data !is SettingsSwitchBean) return@setOnClickListener | ||
holder.binding.apply { | ||
switchSettingsSwitch.isChecked = !switchSettingsSwitch.isChecked | ||
data.onCheckedChanged?.invoke(switchSettingsSwitch.isChecked) | ||
} | ||
} | ||
return holder | ||
} | ||
|
||
override fun onBindViewHolder( | ||
holder: SettingsSwitchViewHolder, | ||
data: SettingsSwitchBean, | ||
index: Int, | ||
action: ((Any?) -> Unit)? | ||
) { | ||
holder.binding.apply { | ||
tvSettingsSwitchTitle.text = data.title | ||
tvSettingsSwitchDesc.text = data.description | ||
ivSettingsSwitchIcon.setImageDrawable(data.icon) | ||
switchSettingsSwitch.isChecked = data.isChecked() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.