Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swipe row to open in browser #428

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/src/main/java/com/capyreader/app/common/ContextOpenLinkExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import java.net.URL

fun Context.openLink(url: Uri, appPreferences: AppPreferences? = null) {
if (appPreferences != null && appPreferences.openLinksInternally.get()) {
Expand All @@ -13,7 +14,15 @@ fun Context.openLink(url: Uri, appPreferences: AppPreferences? = null) {

intent.launchUrl(this, url)
} else {
val intent = Intent(Intent.ACTION_VIEW, url)
startActivity(intent)
openLinkExternally(url)
}
}

fun Context.openLinkExternally(url: URL) {
openLinkExternally(Uri.parse(url.toString()))
}

private fun Context.openLinkExternally(url: Uri) {
val intent = Intent(Intent.ACTION_VIEW, url)
startActivity(intent)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.capyreader.app.ui.articles.list

import android.content.Context
import android.net.Uri
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.OpenInNew
import androidx.compose.material.icons.outlined.Circle
import androidx.compose.material.icons.rounded.Circle
import androidx.compose.material.icons.rounded.Star
Expand All @@ -13,13 +16,16 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import com.capyreader.app.R
import com.capyreader.app.common.AppPreferences
import com.capyreader.app.ui.settings.panels.RowSwipeOption
import com.capyreader.app.common.asState
import com.capyreader.app.common.openLink
import com.capyreader.app.common.openLinkExternally
import com.capyreader.app.ui.articles.ArticleActions
import com.capyreader.app.ui.articles.LocalArticleActions
import com.capyreader.app.ui.articles.list.ArticleRowSwipeState.SwipeAction
import com.capyreader.app.ui.settings.panels.RowSwipeOption
import com.jocmp.capy.Article
import org.koin.compose.koinInject

Expand All @@ -45,6 +51,7 @@ internal fun rememberArticleRowSwipeState(
): ArticleRowSwipeState {
val actions = LocalArticleActions.current
val state = rememberSwipeToDismissBoxState()
val context = LocalContext.current
val swipeStart by appPreferences.articleListOptions.swipeStart.asState()
val swipeEnd by appPreferences.articleListOptions.swipeEnd.asState()

Expand All @@ -53,6 +60,7 @@ internal fun rememberArticleRowSwipeState(

val swipeAction = when (preference) {
RowSwipeOption.TOGGLE_STARRED -> starAction(article, actions)
RowSwipeOption.OPEN_EXTERNALLY -> openExternally(context, article)
else -> readAction(article, actions)
}

Expand All @@ -76,6 +84,14 @@ fun swipePreference(
}
}

private fun openExternally(context: Context, article: Article) =
SwipeAction(
Icons.AutoMirrored.Rounded.OpenInNew,
R.string.article_view_open_externally,
) {
context.openLinkExternally(article.url)
}

private fun starAction(article: Article, actions: ArticleActions): SwipeAction {
return when {
article.starred -> SwipeAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.capyreader.app.R
enum class RowSwipeOption {
DISABLED,
TOGGLE_READ,
TOGGLE_STARRED;
TOGGLE_STARRED,
OPEN_EXTERNALLY;

val translationKey: Int
get() = when (this) {
DISABLED -> R.string.article_list_row_swipe_disabled
TOGGLE_READ -> R.string.article_list_row_swipe_toggle_read
TOGGLE_STARRED -> R.string.article_list_row_swipe_toggle_starred
OPEN_EXTERNALLY -> R.string.article_list_row_swipe_open_externally
}

companion object {
Expand All @@ -22,6 +24,7 @@ enum class RowSwipeOption {
DISABLED,
TOGGLE_READ,
TOGGLE_STARRED,
OPEN_EXTERNALLY,
)
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@
<string name="settings_enable_refresh_call_to_action">Periodic refresh must be enabled first</string>
<string name="settings_notifications_select_none">Select None</string>
<string name="settings_notifications_select_all">Select All</string>
<string name="article_list_row_swipe_open_externally">Open article in browser</string>
<string name="article_view_open_externally">Open externally</string>
</resources>
Loading