mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 06:47:02 +05:30
Merge pull request #27 from msfjarvis/comments
Add comment open action and cleanup unused code
This commit is contained in:
commit
6867d84ca9
9 changed files with 38 additions and 152 deletions
|
@ -11,11 +11,11 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@drawable/ic_launcher_round"
|
android:roundIcon="@drawable/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Lobsters">
|
android:theme="@style/Theme.MaterialComponents">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/Theme.Lobsters.NoActionBar">
|
android:theme="@style/Theme.MaterialComponents.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,11 @@ fun LobstersApp(
|
||||||
if (lastIndex == index) {
|
if (lastIndex == index) {
|
||||||
viewModel.getMorePosts()
|
viewModel.getMorePosts()
|
||||||
}
|
}
|
||||||
LobstersItem(item) { post ->
|
LobstersItem(
|
||||||
urlLauncher.launch(post.url)
|
item,
|
||||||
}
|
linkOpenAction = { post -> urlLauncher.launch(post.url) },
|
||||||
|
commentOpenAction = { post -> urlLauncher.launch(post.commentsUrl) },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumnFor
|
import androidx.compose.foundation.lazy.LazyColumnFor
|
||||||
|
@ -26,14 +25,17 @@ import dev.msfjarvis.lobsters.model.Submitter
|
||||||
fun LazyItemScope.LobstersItem(
|
fun LazyItemScope.LobstersItem(
|
||||||
post: LobstersPost,
|
post: LobstersPost,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onClick: (LobstersPost) -> Unit,
|
linkOpenAction: (LobstersPost) -> Unit,
|
||||||
|
commentOpenAction: (LobstersPost) -> Unit,
|
||||||
) {
|
) {
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = modifier.padding(horizontal = 8.dp)
|
modifier = modifier.padding(horizontal = 8.dp)
|
||||||
.fillParentMaxWidth()
|
.fillParentMaxWidth()
|
||||||
.clickable(onClick = { onClick.invoke(post) }),
|
.clickable(
|
||||||
|
onClick = { linkOpenAction.invoke(post) },
|
||||||
|
onLongClick = { commentOpenAction.invoke(post) }
|
||||||
|
),
|
||||||
text = {
|
text = {
|
||||||
Column {
|
|
||||||
Text(
|
Text(
|
||||||
text = post.title,
|
text = post.title,
|
||||||
color = Color(0xFF7395D9),
|
color = Color(0xFF7395D9),
|
||||||
|
@ -44,7 +46,7 @@ fun LazyItemScope.LobstersItem(
|
||||||
modifier = Modifier.padding(vertical = 8.dp),
|
modifier = Modifier.padding(vertical = 8.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
) {
|
) {
|
||||||
post.tags.forEach { tag ->
|
post.tags.take(4).forEach { tag ->
|
||||||
Text(
|
Text(
|
||||||
text = tag,
|
text = tag,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
@ -60,7 +62,6 @@ fun LazyItemScope.LobstersItem(
|
||||||
modifier = Modifier.padding(bottom = 4.dp),
|
modifier = Modifier.padding(bottom = 4.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ fun PreviewLobstersItem() {
|
||||||
)
|
)
|
||||||
LobstersTheme {
|
LobstersTheme {
|
||||||
LazyColumnFor(items = listOf(post)) { item ->
|
LazyColumnFor(items = listOf(post)) { item ->
|
||||||
LobstersItem(post = item, onClick = {})
|
LobstersItem(post = item, linkOpenAction = {}, commentOpenAction = {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,17 +0,0 @@
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
<!-- Base application theme. -->
|
|
||||||
<style name="Theme.Lobsters" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
|
||||||
<!-- Primary brand color. -->
|
|
||||||
<item name="colorPrimary">@color/purple_200</item>
|
|
||||||
<item name="colorPrimaryVariant">@color/black</item>
|
|
||||||
<item name="colorOnPrimary">@color/black</item>
|
|
||||||
<!-- Secondary brand color. -->
|
|
||||||
<item name="colorSecondary">@color/teal_200</item>
|
|
||||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
|
||||||
<item name="colorOnSecondary">@color/black</item>
|
|
||||||
<!-- Status bar color. -->
|
|
||||||
<item name="android:windowLightStatusBar">false</item>
|
|
||||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
|
||||||
<!-- Customize your theme here. -->
|
|
||||||
</style>
|
|
||||||
</resources>
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="purple_200">#FFBB86FC</color>
|
|
||||||
<color name="purple_500">#FF6200EE</color>
|
|
||||||
<color name="purple_700">#FF3700B3</color>
|
|
||||||
<color name="teal_200">#FF03DAC5</color>
|
|
||||||
<color name="teal_700">#FF018786</color>
|
|
||||||
<color name="black">#FF000000</color>
|
|
||||||
<color name="white">#FFFFFFFF</color>
|
|
||||||
</resources>
|
|
|
@ -1,26 +0,0 @@
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
<!-- Base application theme. -->
|
|
||||||
<style name="Theme.Lobsters" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
|
||||||
<!-- Primary brand color. -->
|
|
||||||
<item name="colorPrimary">@color/white</item>
|
|
||||||
<item name="colorPrimaryVariant">@color/white</item>
|
|
||||||
<item name="colorOnPrimary">@color/white</item>
|
|
||||||
<!-- Secondary brand color. -->
|
|
||||||
<item name="colorSecondary">@color/teal_200</item>
|
|
||||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
|
||||||
<item name="colorOnSecondary">@color/black</item>
|
|
||||||
<!-- Status bar color. -->
|
|
||||||
<item name="android:windowLightStatusBar">true</item>
|
|
||||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
|
||||||
<!-- Customize your theme here. -->
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="Theme.Lobsters.NoActionBar">
|
|
||||||
<item name="windowActionBar">false</item>
|
|
||||||
<item name="windowNoTitle">true</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="Theme.Lobsters.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
|
||||||
|
|
||||||
<style name="Theme.Lobsters.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
|
||||||
</resources>
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2020 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package dev.msfjarvis.lobsters.data.source
|
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
object DateTimeTypeConverters {
|
|
||||||
@TypeConverter
|
|
||||||
@JvmStatic
|
|
||||||
fun toLocalDateTime(value: String?): LocalDateTime? {
|
|
||||||
return value?.let { LocalDateTime.parse(value) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
@JvmStatic
|
|
||||||
fun fromLocalDateTime(value: LocalDateTime?): String? {
|
|
||||||
return value?.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,10 +2,6 @@ package dev.msfjarvis.lobsters.data.source
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import dev.msfjarvis.lobsters.model.KeybaseSignature
|
|
||||||
import dev.msfjarvis.lobsters.model.KeybaseSignatureJsonAdapter
|
|
||||||
import dev.msfjarvis.lobsters.model.LobstersPost
|
|
||||||
import dev.msfjarvis.lobsters.model.LobstersPostJsonAdapter
|
|
||||||
import dev.msfjarvis.lobsters.model.Submitter
|
import dev.msfjarvis.lobsters.model.Submitter
|
||||||
import dev.msfjarvis.lobsters.model.SubmitterJsonAdapter
|
import dev.msfjarvis.lobsters.model.SubmitterJsonAdapter
|
||||||
|
|
||||||
|
@ -25,30 +21,6 @@ object LobstersApiTypeConverters {
|
||||||
return value?.let { SubmitterJsonAdapter(moshi).toJson(value) }
|
return value?.let { SubmitterJsonAdapter(moshi).toJson(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
@JvmStatic
|
|
||||||
fun toKeybaseSignature(value: String?): KeybaseSignature? {
|
|
||||||
return value?.let { KeybaseSignatureJsonAdapter(moshi).fromJson(value) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
@JvmStatic
|
|
||||||
fun fromKeybaseSignature(value: KeybaseSignature?): String? {
|
|
||||||
return value?.let { KeybaseSignatureJsonAdapter(moshi).toJson(value) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
@JvmStatic
|
|
||||||
fun toLobstersPost(value: String?): LobstersPost? {
|
|
||||||
return value?.let { LobstersPostJsonAdapter(moshi).fromJson(value) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
@JvmStatic
|
|
||||||
fun fromLobstersPost(value: LobstersPost?): String? {
|
|
||||||
return value?.let { LobstersPostJsonAdapter(moshi).toJson(value) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun toTagList(value: String?): List<String>? {
|
fun toTagList(value: String?): List<String>? {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import androidx.room.Database
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
import dev.msfjarvis.lobsters.data.model.LobstersEntity
|
import dev.msfjarvis.lobsters.data.model.LobstersEntity
|
||||||
import dev.msfjarvis.lobsters.model.LobstersPost
|
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [
|
entities = [
|
||||||
|
@ -15,7 +14,6 @@ import dev.msfjarvis.lobsters.model.LobstersPost
|
||||||
)
|
)
|
||||||
@TypeConverters(
|
@TypeConverters(
|
||||||
LobstersApiTypeConverters::class,
|
LobstersApiTypeConverters::class,
|
||||||
DateTimeTypeConverters::class,
|
|
||||||
)
|
)
|
||||||
abstract class PostsDatabase : RoomDatabase() {
|
abstract class PostsDatabase : RoomDatabase() {
|
||||||
abstract fun postsDao(): PostsDao
|
abstract fun postsDao(): PostsDao
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue