From 976158c06a7fff7fb72af05062479cfdc5fd4b12 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Wed, 6 Oct 2021 14:16:08 +0200 Subject: [PATCH] Partial redesign Signed-off-by: Balazs Toldi --- .idea/deploymentTargetDropDown.xml | 10 +- app/src/main/AndroidManifest.xml | 2 +- .../balazs/anotherfeedreader/MainActivity.kt | 184 ++++++++++-------- .../toldi/balazs/anotherfeedreader/WebView.kt | 36 +++- 4 files changed, 141 insertions(+), 91 deletions(-) diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index f47ae74..f765335 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,17 +1,17 @@ - + - + - + - - + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 098ad69..6d92e9d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,7 +3,7 @@ package="eu.toldi.balazs.anotherfeedreader"> - + val article = articleList.value[index] - Column( - - Modifier - .clickable { - Log.i(null, article.title.toString()) - WebView.webURL = article.url.toString() - WebView.barTitle = feedData.name.toString() - startActivity( - Intent( - baseContext, - WebView::class.java - ) - ) - } - .padding( - horizontal = 3.dp - ) - ) { - showArticle(article = article) - } - + showArticle(article = article) } } } @@ -154,68 +140,113 @@ class MainActivity : ComponentActivity() { @Composable fun showArticle(article: Article) { - Column { - if (article.imageURL != null) { - Image( - painter = rememberImagePainter(article.imageURL), - contentDescription = null, - contentScale = ContentScale.Crop, - alignment = Alignment.Center, - modifier = Modifier - .height(200.dp) - .fillMaxWidth() - .fillMaxHeight() - ) - } - Row { - if (article.author != null) { + val haptic = LocalHapticFeedback.current + Card( + Modifier + .pointerInput(Unit) { + detectTapGestures( + onLongPress = { + val share = + Intent.createChooser(Intent().apply { + action = Intent.ACTION_SEND + putExtra( + Intent.EXTRA_TEXT, + article.url + ) + putExtra( + Intent.EXTRA_TITLE, + article.title + ) + type = "text/plain" + }, null) + startActivity(share) + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + } + ) + } + .clickable { + WebView.webURL = article.url.toString() + WebView.barTitle = + article.feedName.toString() + startActivity( + Intent( + baseContext, + WebView::class.java + ) + ) + } + .padding( + start = 6.dp, + top = 2.dp, + bottom = 6.dp, + end = 6.dp + ), + elevation = 10.dp, + backgroundColor = MaterialTheme.colors.surface + ) { + Column { + if (article.imageURL != null) { + Image( + painter = rememberImagePainter(article.imageURL), + contentDescription = null, + contentScale = ContentScale.Crop, + alignment = Alignment.Center, + modifier = Modifier + .height(200.dp) + .fillMaxWidth() + .fillMaxHeight() + ) + } + Row { + if (article.author != null) { + Text( + text = (fun(): String { + if (article.author.length > 25) + return article.author.dropLast(article.author.length - 25) + else return article.author + }).invoke(), + fontSize = 11.sp + ) + } else Text("") + article.feedName?.let { + Text( + text = (fun(): String { + return if (it.length > 25) + return it.dropLast(it.length - 25) + else return it + }).invoke(), + fontSize = 11.sp, + textAlign = TextAlign.Center, + modifier = Modifier.padding(horizontal = 10.dp), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + if (article.pubDate != null) { + Text( + article.pubDate.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)), + fontSize = 11.sp, + textAlign = TextAlign.Right, + //modifier = Modifier.width(350.dp) + ) + } else Text("") + } + if (article.title != null) { Text( - text = (fun(): String { - if (article.author.length > 25) - return article.author.dropLast(article.author.length - 25) - else return article.author - }).invoke(), - fontSize = 11.sp + text = article.title.trim(), + fontSize = 20.sp, + maxLines = 2, + overflow = TextOverflow.Ellipsis ) } else Text("") - article.feedName?.let { + if (article.description != null) { Text( - text = (fun(): String { - return if (it.length > 25) - return it.dropLast(it.length - 25) - else return it - }).invoke(), - fontSize = 11.sp, - textAlign = TextAlign.Center, - modifier = Modifier.padding(horizontal = 10.dp), - maxLines = 1, + text = article.description, + fontSize = 17.sp, + maxLines = 2, overflow = TextOverflow.Ellipsis ) } - if (article.pubDate != null) { - Text( - article.pubDate.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)), - fontSize = 11.sp, - textAlign = TextAlign.Right, - //modifier = Modifier.width(350.dp) - ) - } else Text("") - } - if (article.title != null) { - Text( - text = article.title.trim(), - fontSize = 20.sp, - maxLines = 2, - overflow = TextOverflow.Ellipsis - ) - } else Text("") - if (article.description != null) { - Text( - text = article.description, - fontSize = 17.sp, - maxLines = 2, - overflow = TextOverflow.Ellipsis - ) } } } @@ -277,7 +308,6 @@ class MainActivity : ComponentActivity() { description = "Ez az cikk azért létezik, hogy kipróbájam a cikkek megjelenítését.", author = "Toldi Balázs", pubDate = LocalDateTime.now(), - imageURL = "https://cloud.toldi.eu/index.php/apps/files_sharing/publicpreview/Aicw77SAJYBiM8B?x=1920&y=571&a=true&file=P2.JPG&scalingup=0", feedName = "Teszt feed" ) Column( diff --git a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/WebView.kt b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/WebView.kt index 09ae7d4..81659d6 100644 --- a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/WebView.kt +++ b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/WebView.kt @@ -19,7 +19,9 @@ import eu.toldi.balazs.anotherfeedreader.views.CustomWebViewClient import android.net.Uri import android.content.Intent +import androidx.compose.foundation.layout.Row import androidx.compose.material.icons.filled.ArrowLeft +import androidx.compose.material.icons.filled.Share import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat.startActivity @@ -63,15 +65,33 @@ class WebView : ComponentActivity() { } }, actions = { - IconButton(onClick = { + Row { + IconButton(onClick = { - val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(webURL)) - startActivity(browserIntent) - }) { - Icon( - Icons.Filled.OpenInBrowser, - contentDescription = "Open in browser" - ) + val share = Intent.createChooser(Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_TEXT, webURL) + type = "text/plain" + + }, null) + startActivity(share) + + }) { + Icon( + Icons.Filled.Share, + contentDescription = "Share" + ) + } + IconButton(onClick = { + + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(webURL)) + startActivity(browserIntent) + }) { + Icon( + Icons.Filled.OpenInBrowser, + contentDescription = "Open in browser" + ) + } } } )