diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/hits/HitsRepository.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/hits/HitsRepository.kt index 4d20e1e1e..88dc621b9 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/hits/HitsRepository.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/hits/HitsRepository.kt @@ -6,23 +6,24 @@ import io.github.feelfreelinux.wykopmobilny.api.links.LinksRetrofitApi import io.github.feelfreelinux.wykopmobilny.models.dataclass.Link import io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2.LinkMapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.LinkResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi import io.reactivex.Single import retrofit2.Retrofit -class HitsRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher) : HitsApi { +class HitsRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher, val linksPreferencesApi: LinksPreferencesApi) : HitsApi { private val hitsApi by lazy { retrofit.create(HitsRetrofitApi::class.java) } override fun byMonth(year: Int, month: Int): Single> = hitsApi.byMonth(year, month) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun currentDay(): Single> = hitsApi.currentDay() .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } @@ -30,20 +31,20 @@ class HitsRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRe hitsApi.byYear(year) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun currentWeek(): Single> = hitsApi.currentWeek() .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun popular(): Single> = hitsApi.popular() .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/links/LinksRepository.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/links/LinksRepository.kt index c18182406..adbf1b337 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/links/LinksRepository.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/links/LinksRepository.kt @@ -7,32 +7,33 @@ import io.github.feelfreelinux.wykopmobilny.api.getRequestBody import io.github.feelfreelinux.wykopmobilny.models.dataclass.* import io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2.* import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.* +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi import io.reactivex.Single import okhttp3.MultipartBody import okhttp3.RequestBody import retrofit2.Retrofit import java.lang.reflect.Type -class LinksRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher) : LinksApi { +class LinksRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher, val linksPreferencesApi: LinksPreferencesApi) : LinksApi { private val linksApi by lazy { retrofit.create(LinksRetrofitApi::class.java) } override fun getPromoted(page : Int): Single> = linksApi.getPromoted(page) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun getUpcoming(page : Int, sortBy: String): Single> = linksApi.getUpcoming(page, sortBy) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun getObserved(page : Int): Single> = linksApi.getObserved(page) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun getLinkComments(linkId: Int, sortBy: String) = linksApi.getLinkComments(linkId, sortBy) @@ -53,7 +54,7 @@ class LinksRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenR linksApi.getLink(linkId) .retryWhen(userTokenRefresher) .compose(ErrorHandlerTransformer()) - .map { LinkMapper.map(it) } + .map { LinkMapper.map(it, linksPreferencesApi) } override fun commentVoteUp(linkId: Int): Single = linksApi.commentVoteUp(linkId) diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/mywykop/MyWykopRepository.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/mywykop/MyWykopRepository.kt index 229423a24..4e11aa11b 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/mywykop/MyWykopRepository.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/mywykop/MyWykopRepository.kt @@ -5,27 +5,28 @@ import io.github.feelfreelinux.wykopmobilny.api.errorhandler.ErrorHandlerTransfo import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryLink import io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2.EntryLinkMapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.EntryLinkResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi import io.reactivex.Single import retrofit2.Retrofit -class MyWykopRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher) : MyWykopApi { +class MyWykopRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher, val linksPreferencesApi : LinksPreferencesApi) : MyWykopApi { private val mywykopApi by lazy { retrofit.create(MyWykopRetrofitApi::class.java) } override fun getIndex(page : Int): Single> = mywykopApi.getIndex(page) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { EntryLinkMapper.map(it) } } + .map { it.map { EntryLinkMapper.map(it, linksPreferencesApi) } } override fun byUsers(page : Int): Single> = mywykopApi.byUsers(page) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { EntryLinkMapper.map(it) } } + .map { it.map { EntryLinkMapper.map(it, linksPreferencesApi) } } override fun byTags(page : Int): Single> = mywykopApi.byTags(page) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { EntryLinkMapper.map(it) } } + .map { it.map { EntryLinkMapper.map(it, linksPreferencesApi) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/search/SearchRepository.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/search/SearchRepository.kt index aedb48ca2..014e39bc1 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/search/SearchRepository.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/search/SearchRepository.kt @@ -8,16 +8,17 @@ import io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2.LinkMapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.AuthorResponse import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.EntryResponse import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.LinkResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi import retrofit2.Retrofit -class SearchRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher) : SearchApi { +class SearchRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher, val linksPreferencesApi: LinksPreferencesApi) : SearchApi { private val searchApi by lazy { retrofit.create(SearchRetrofitApi::class.java) } override fun searchLinks(page: Int, query: String) = searchApi .searchLinks(page, query) .retryWhen(userTokenRefresher) .compose>(ErrorHandlerTransformer()) - .map { it.map { LinkMapper.map(it) } } + .map { it.map { LinkMapper.map(it, linksPreferencesApi) } } override fun searchEntries(page: Int, query: String) = searchApi .searchEntries(page, query) diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/tag/TagRepository.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/tag/TagRepository.kt index d7675a921..62224ce74 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/tag/TagRepository.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/api/tag/TagRepository.kt @@ -9,10 +9,11 @@ import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.ObservedTag import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.TagStateResponse import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.TagEntriesResponse import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.TagLinksResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi import io.reactivex.Single import retrofit2.Retrofit -class TagRepository(retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher) : TagApi { +class TagRepository(retrofit: Retrofit, val userTokenRefresher: UserTokenRefresher, val linksPreferencesApi: LinksPreferencesApi) : TagApi { private val tagApi by lazy { retrofit.create(TagRetrofitApi::class.java) } override fun getTagEntries(tag : String, page : Int) = tagApi.getTagEntries(tag, page) @@ -23,7 +24,7 @@ class TagRepository(retrofit: Retrofit, val userTokenRefresher: UserTokenRefresh override fun getTagLinks(tag : String, page : Int) = tagApi.getTagLinks(tag, page) .retryWhen(userTokenRefresher) .flatMap(ErrorHandler()) - .map { TagLinksMapper.map(it)} + .map { TagLinksMapper.map(it, linksPreferencesApi)} override fun getObservedTags() : Single> = tagApi.getObservedTags() diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/NetworkModule.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/NetworkModule.kt index 3b818719b..941db312c 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/NetworkModule.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/NetworkModule.kt @@ -14,10 +14,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.modules.Navigator import io.github.feelfreelinux.wykopmobilny.ui.modules.NavigatorApi import io.github.feelfreelinux.wykopmobilny.ui.modules.notifications.WykopNotificationManager import io.github.feelfreelinux.wykopmobilny.ui.modules.notifications.WykopNotificationManagerApi -import io.github.feelfreelinux.wykopmobilny.utils.ClipboardHelper -import io.github.feelfreelinux.wykopmobilny.utils.ClipboardHelperApi -import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferences -import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi +import io.github.feelfreelinux.wykopmobilny.utils.* import io.github.feelfreelinux.wykopmobilny.utils.api.CredentialsPreferences import io.github.feelfreelinux.wykopmobilny.utils.api.CredentialsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManager @@ -63,6 +60,9 @@ class NetworkModule { @Provides fun provideSettingsPreferences(context: Context) : SettingsPreferencesApi = SettingsPreferences(context) + @Provides + fun provideLinksPreferencesApi(context: Context) : LinksPreferencesApi = LinksPreferences(context) + @Provides fun provideUserManagerApi(credentialsPreferencesApi: CredentialsPreferencesApi) : UserManagerApi = UserManager(credentialsPreferencesApi) diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/RepositoryModule.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/RepositoryModule.kt index e539480d3..78646ffae 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/RepositoryModule.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/di/modules/RepositoryModule.kt @@ -24,6 +24,7 @@ import io.github.feelfreelinux.wykopmobilny.api.tag.TagApi import io.github.feelfreelinux.wykopmobilny.api.tag.TagRepository import io.github.feelfreelinux.wykopmobilny.api.user.LoginApi import io.github.feelfreelinux.wykopmobilny.api.user.LoginRepository +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.api.CredentialsPreferencesApi import retrofit2.Retrofit @@ -36,13 +37,13 @@ class RepositoryModule { fun provideNotificationsApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : NotificationsApi = NotificationsRepository(retrofit, userTokenRefresher) @Provides - fun provideMyWykopApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : MyWykopApi = MyWykopRepository(retrofit, userTokenRefresher) + fun provideMyWykopApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher, linksPreferencesApi: LinksPreferencesApi) : MyWykopApi = MyWykopRepository(retrofit, userTokenRefresher, linksPreferencesApi) @Provides - fun provideLinksApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : LinksApi = LinksRepository(retrofit, userTokenRefresher) + fun provideLinksApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher, linksPreferencesApi: LinksPreferencesApi) : LinksApi = LinksRepository(retrofit, userTokenRefresher, linksPreferencesApi) @Provides - fun provideTagApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : TagApi = TagRepository(retrofit, userTokenRefresher) + fun provideTagApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher, linksPreferencesApi: LinksPreferencesApi) : TagApi = TagRepository(retrofit, userTokenRefresher, linksPreferencesApi) @Provides fun provideUserApi(retrofit: Retrofit, credentialsPreferencesApi : CredentialsPreferencesApi) : LoginApi @@ -55,8 +56,8 @@ class RepositoryModule { fun provideSuggestApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : SuggestApi = SuggestRepository(retrofit, userTokenRefresher) @Provides - fun provideSearchApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : SearchApi = SearchRepository(retrofit, userTokenRefresher) + fun provideSearchApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher, linksPreferencesApi: LinksPreferencesApi) : SearchApi = SearchRepository(retrofit, userTokenRefresher, linksPreferencesApi) @Provides - fun provideHitsApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher) : HitsApi = HitsRepository(retrofit, userTokenRefresher) + fun provideHitsApi(retrofit: Retrofit, userTokenRefresher: UserTokenRefresher, linksPreferencesApi: LinksPreferencesApi) : HitsApi = HitsRepository(retrofit, userTokenRefresher, linksPreferencesApi) } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/dataclass/Notification.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/dataclass/Notification.kt index e21d1800a..8df32042b 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/dataclass/Notification.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/dataclass/Notification.kt @@ -1,10 +1,20 @@ package io.github.feelfreelinux.wykopmobilny.models.dataclass -data class Notification( +class Notification( + val id : Int, val author : Author?, val body : String, val date : String, val type : String, val url : String?, var new : Boolean -) \ No newline at end of file +) { + override fun equals(other: Any?): Boolean { + return if (other !is Notification) false + else (other.id == id) + } + + override fun hashCode(): Int { + return id + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/ConversationMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/ConversationMapper.kt index e5fffe8dd..c18f975da 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/ConversationMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/ConversationMapper.kt @@ -3,11 +3,12 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.Conversation import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.ConversationResponse +import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate class ConversationMapper { companion object : Mapper { override fun map(value: ConversationResponse): Conversation { - return Conversation(AuthorMapper.map(value.receiver), value.lastUpdate) + return Conversation(AuthorMapper.map(value.receiver), value.lastUpdate.toPrettyDate()) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryCommentMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryCommentMapper.kt index bbce46789..afccf06a6 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryCommentMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryCommentMapper.kt @@ -3,6 +3,7 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryComment import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.EntryCommentResponse +import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate class EntryCommentMapper { companion object : Mapper { @@ -12,7 +13,7 @@ class EntryCommentMapper { 0, AuthorMapper.map(value.author), value.body ?: "", - value.date, + value.date.toPrettyDate(), value.userVote > 0, if (value.embed != null) EmbedMapper.map(value.embed) else null, value.voteCount, diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryLinkMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryLinkMapper.kt index a9032ec28..5888423ea 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryLinkMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryLinkMapper.kt @@ -3,12 +3,13 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryLink import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.EntryLinkResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi class EntryLinkMapper { - companion object : Mapper { - override fun map(value: EntryLinkResponse): EntryLink { + companion object { + fun map(value: EntryLinkResponse, linksPreferencesApi : LinksPreferencesApi): EntryLink { return EntryLink( - if (value.link != null) LinkMapper.map(value.link) else null, + if (value.link != null) LinkMapper.map(value.link, linksPreferencesApi) else null, if (value.entry != null) EntryMapper.map(value.entry) else null ) } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryMapper.kt index b07a96194..8bce99a02 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/EntryMapper.kt @@ -3,12 +3,13 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.EntryResponse +import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate class EntryMapper { companion object : Mapper { override fun map(value: EntryResponse): Entry { return Entry(value.id, AuthorMapper.map(value.author), - value.body ?: "", value.date, + value.body ?: "", value.date.toPrettyDate(), value.userVote > 0, value.favorite, if (value.survey != null) SurveyMapper.map(value.survey) else null, if (value.embed != null) EmbedMapper.map(value.embed) else null, diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkCommentMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkCommentMapper.kt index a4397d41f..53e545430 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkCommentMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkCommentMapper.kt @@ -3,11 +3,12 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.LinkComment import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.LinkCommentResponse +import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate class LinkCommentMapper { companion object : Mapper { override fun map(value: LinkCommentResponse): LinkComment { - return LinkComment(value.id, AuthorMapper.map(value.author), value.date, + return LinkComment(value.id, AuthorMapper.map(value.author), value.date.toPrettyDate(), value.body, value.blocked, value.favorite, value.voteCount, value.voteCountPlus, diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkMapper.kt index 871ee37a2..616745fb1 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/LinkMapper.kt @@ -3,18 +3,22 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.Link import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.LinkResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi +import io.github.feelfreelinux.wykopmobilny.utils.api.stripImageCompression +import io.github.feelfreelinux.wykopmobilny.utils.textview.removeHtml +import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate class LinkMapper { - companion object : Mapper { - override fun map(value: LinkResponse): Link { + companion object { + fun map(value: LinkResponse, linksPreferencesApi: LinksPreferencesApi): Link { return Link(value.id, - value.title, - value.description ?: "", value.tags, value.sourceUrl, + value.title.removeHtml(), + value.description?.removeHtml() ?: "", value.tags, value.sourceUrl, value.voteCount, value.buryCount, emptyList(), value.commentsCount, value.relatedCount, - if (value.author != null) AuthorMapper.map(value.author) else null, value.date, value.preview, + if (value.author != null) AuthorMapper.map(value.author) else null, value.date.toPrettyDate(), value.preview?.stripImageCompression(), value.plus18, value.canVote, value.isHot, - value.status, value.userVote, value.userFavorite ?: false, value.app, false) + value.status, value.userVote, value.userFavorite ?: false, value.app, linksPreferencesApi.readLinksIds.contains("link_${value.id}")) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/NotificationMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/NotificationMapper.kt index 7849b6244..e99ed9ebd 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/NotificationMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/NotificationMapper.kt @@ -8,6 +8,7 @@ class NotificationMapper { companion object : Mapper { override fun map(value: NotificationResponse): Notification { return Notification( + value.id, if (value.author != null) AuthorMapper.map(value.author) else null, value.body, value.date, diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/PMMessageMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/PMMessageMapper.kt index 9d2d9f7b0..4164d0632 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/PMMessageMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/PMMessageMapper.kt @@ -3,11 +3,12 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.PMMessage import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.PMMessageResponse +import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate class PMMessageMapper { companion object : Mapper { override fun map(value: PMMessageResponse): PMMessage { - return PMMessage(value.date, value.body ?: "", + return PMMessage(value.date.toPrettyDate(), value.body ?: "", if (value.embed != null) EmbedMapper.map(value.embed) else null, value.direction != "received", value.app) diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/TagLinksMapper.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/TagLinksMapper.kt index 3e7c53903..cb1f294f4 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/TagLinksMapper.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/models/mapper/apiv2/TagLinksMapper.kt @@ -3,11 +3,12 @@ package io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2 import io.github.feelfreelinux.wykopmobilny.models.dataclass.TagLinks import io.github.feelfreelinux.wykopmobilny.models.mapper.Mapper import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.TagLinksResponse +import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi class TagLinksMapper { - companion object : Mapper { - override fun map(value: TagLinksResponse): TagLinks { - return TagLinks(value.data!!.map { LinkMapper.map(it) }, value.meta) + companion object { + fun map(value: TagLinksResponse, linksPreferencesApi: LinksPreferencesApi): TagLinks { + return TagLinks(value.data!!.map { LinkMapper.map(it, linksPreferencesApi) }, value.meta) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryDetailAdapter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryDetailAdapter.kt index e3e461d13..f90eed36f 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryDetailAdapter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryDetailAdapter.kt @@ -8,6 +8,7 @@ import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.CommentViewHolder import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.EntryViewHolder +import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.RecyclableViewHolder import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.EntryPresenterFactory import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.comment.CommentPresenterFactory import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi @@ -55,4 +56,10 @@ class EntryDetailAdapter @Inject constructor(val userManagerApi: UserManagerApi, else -> CommentViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.comment_list_item, parent, false), addReceiverListener, settingsPreferencesApi, userManagerApi, commentPresenterFactory.create()) } } + + override fun onViewRecycled(holder: RecyclerView.ViewHolder?) { + (holder as? RecyclableViewHolder)?.cleanRecycled() + super.onViewRecycled(holder) + } + } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryLinkAdapter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryLinkAdapter.kt index ed2319814..ba5f290f8 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryLinkAdapter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/EntryLinkAdapter.kt @@ -6,8 +6,10 @@ import android.view.ViewGroup import io.github.feelfreelinux.wykopmobilny.R import io.github.feelfreelinux.wykopmobilny.base.adapter.AdvancedProgressAdapter import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryLink +import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.CommentViewHolder import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.EntryViewHolder import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.LinkViewHolder +import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.RecyclableViewHolder import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.EntryPresenterFactory import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi @@ -40,4 +42,9 @@ class EntryLinkAdapter @Inject constructor(val userManagerApi: UserManagerApi, v } } + override fun onViewRecycled(holder: RecyclerView.ViewHolder?) { + (holder as? RecyclableViewHolder)?.cleanRecycled() + super.onViewRecycled(holder) + } + } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/FeedAdapter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/FeedAdapter.kt index 81473008c..1dc91ab04 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/FeedAdapter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/FeedAdapter.kt @@ -1,11 +1,13 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters +import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup import io.github.feelfreelinux.wykopmobilny.R import io.github.feelfreelinux.wykopmobilny.base.adapter.SimpleBaseProgressAdapter import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.EntryViewHolder +import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.RecyclableViewHolder import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.EntryPresenterFactory import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi @@ -18,4 +20,9 @@ class FeedAdapter @Inject constructor(val userManagerApi: UserManagerApi, val se override fun createViewHolder(parent: ViewGroup): EntryViewHolder = EntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.entry_list_item, parent, false), userManagerApi, settingsPreferencesApi, entryPresenterFactory.create()) + + override fun onViewRecycled(holder: RecyclerView.ViewHolder?) { + (holder as? RecyclableViewHolder)?.cleanRecycled() + super.onViewRecycled(holder) + } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/LinkAdapter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/LinkAdapter.kt index 01091c03d..58f74518a 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/LinkAdapter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/LinkAdapter.kt @@ -1,11 +1,13 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters +import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup import io.github.feelfreelinux.wykopmobilny.R import io.github.feelfreelinux.wykopmobilny.base.adapter.SimpleBaseProgressAdapter import io.github.feelfreelinux.wykopmobilny.models.dataclass.Link import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.LinkViewHolder +import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.RecyclableViewHolder import javax.inject.Inject class LinkAdapter @Inject constructor() : SimpleBaseProgressAdapter() { @@ -15,4 +17,9 @@ class LinkAdapter @Inject constructor() : SimpleBaseProgressAdapter LinkCommentViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.link_comment_list_item, parent, false), onReplyClickedListener, collapseListener, presenterFactory.create(), userManagerApi, settingsPreferencesApi) } } + + override fun onViewRecycled(holder: RecyclerView.ViewHolder?) { + (holder as? RecyclableViewHolder)?.cleanRecycled() + super.onViewRecycled(holder) + } } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/PMMessageAdapter.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/PMMessageAdapter.kt index 1517ba493..aeaa2d857 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/PMMessageAdapter.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/PMMessageAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import io.github.feelfreelinux.wykopmobilny.R import io.github.feelfreelinux.wykopmobilny.models.dataclass.PMMessage import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.PMMessageViewHolder +import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.RecyclableViewHolder import io.github.feelfreelinux.wykopmobilny.ui.modules.NewNavigatorApi import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.WykopLinkHandlerApi @@ -23,4 +24,8 @@ class PMMessageAdapter @Inject constructor(val settingsPreferencesApi: SettingsP override fun onBindViewHolder(holder: PMMessageViewHolder, position: Int) = holder.bindView(messages[position]) + override fun onViewRecycled(holder: PMMessageViewHolder?) { + (holder as? RecyclableViewHolder)?.cleanRecycled() + super.onViewRecycled(holder) + } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/CommentViewHolder.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/CommentViewHolder.kt index 1c00ffccb..34eea95ef 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/CommentViewHolder.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/CommentViewHolder.kt @@ -2,17 +2,25 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders import android.support.v7.widget.RecyclerView import android.view.View +import io.github.feelfreelinux.wykopmobilny.glide.GlideApp import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryComment import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.comment.CommentPresenter import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi import kotlinx.android.synthetic.main.comment_list_item.view.* +import kotlinx.android.synthetic.main.entry_comment_layout.view.* -class CommentViewHolder(val view: View, private val addReceiverListener : (Author) -> Unit, val settingsPreferencesApi: SettingsPreferencesApi, val userManagerApi: UserManagerApi, val commentPresenter: CommentPresenter) : RecyclerView.ViewHolder(view) { +class CommentViewHolder(val view: View, private val addReceiverListener : (Author) -> Unit, val settingsPreferencesApi: SettingsPreferencesApi, val userManagerApi: UserManagerApi, val commentPresenter: CommentPresenter) : RecyclableViewHolder(view) { fun bindView(comment : EntryComment, isAuthorComment: Boolean, commentId : Int?) { view.entryComment.addReceiverListener = addReceiverListener view.entryComment.setCommentData(comment, userManagerApi, settingsPreferencesApi, commentPresenter) view.entryComment.setStyleForComment(isAuthorComment, commentId ?: -1) } + + override fun cleanRecycled() { + view.apply { + GlideApp.with(this).clear(view.entryComment.entryImageView) + } + } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/EntryViewHolder.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/EntryViewHolder.kt index d7e5edbb5..7d6dd8e2e 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/EntryViewHolder.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/EntryViewHolder.kt @@ -2,18 +2,26 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders import android.support.v7.widget.RecyclerView import android.view.View +import io.github.feelfreelinux.wykopmobilny.glide.GlideApp import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.EntryPresenter import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi +import kotlinx.android.synthetic.main.entry_layout.view.* import kotlinx.android.synthetic.main.entry_list_item.view.* -class EntryViewHolder(val view: View, val userManagerApi: UserManagerApi, val settingsPreferencesApi: SettingsPreferencesApi, val entryPresenter: EntryPresenter) : RecyclerView.ViewHolder(view) { +class EntryViewHolder(val view: View, val userManagerApi: UserManagerApi, val settingsPreferencesApi: SettingsPreferencesApi, val entryPresenter: EntryPresenter) : RecyclableViewHolder(view) { fun bindView(entry : Entry, enableClickListener : Boolean = true) { view.entry.apply { shouldEnableClickListener = enableClickListener setEntryData(entry, userManagerApi, settingsPreferencesApi, entryPresenter) } } + + override fun cleanRecycled() { + view.apply { + GlideApp.with(this).clear(view.entry.entryImageView) + } + } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkCommentViewHolder.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkCommentViewHolder.kt index 69bde8a0b..04bf18bde 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkCommentViewHolder.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkCommentViewHolder.kt @@ -4,6 +4,7 @@ import android.support.v7.widget.RecyclerView import android.util.TypedValue import android.view.View import io.github.feelfreelinux.wykopmobilny.R +import io.github.feelfreelinux.wykopmobilny.glide.GlideApp import io.github.feelfreelinux.wykopmobilny.models.dataclass.LinkComment import io.github.feelfreelinux.wykopmobilny.ui.modules.NewNavigatorApi import io.github.feelfreelinux.wykopmobilny.ui.widgets.link.comment.LinkCommentPresenter @@ -13,7 +14,7 @@ import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi import kotlinx.android.synthetic.main.link_comment_layout.view.* import kotlinx.android.synthetic.main.link_comment_list_item.view.* -class LinkCommentViewHolder(val view: View, val linkCommentReplyListener : (LinkComment) -> Unit, val collapseListener : (Boolean, Int) -> Unit, val linkCommentPresenter: LinkCommentPresenter, val userManagerApi: UserManagerApi, val settingsPreferencesApi: SettingsPreferencesApi) : RecyclerView.ViewHolder(view) { +class LinkCommentViewHolder(val view: View, val linkCommentReplyListener : (LinkComment) -> Unit, val collapseListener : (Boolean, Int) -> Unit, val linkCommentPresenter: LinkCommentPresenter, val userManagerApi: UserManagerApi, val settingsPreferencesApi: SettingsPreferencesApi) : RecyclableViewHolder(view) { fun bindView(comment : LinkComment, isUserAuthor: Boolean, highlightCommentId: Int) { view.linkComment.collapseListener = collapseListener view.replyTextView.setOnClickListener { linkCommentReplyListener.invoke(comment) } @@ -26,4 +27,10 @@ class LinkCommentViewHolder(val view: View, val linkCommentReplyListener : (Link } view.linkComment.showHiddenCommentsCountCard = { view.hiddenRepliesView.isVisible = it } } + + override fun cleanRecycled() { + view.apply { + GlideApp.with(this).clear(view.linkComment.commentImageView) + } + } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkViewHolder.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkViewHolder.kt index ef91d4ed4..2d4cbfb2d 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkViewHolder.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/LinkViewHolder.kt @@ -1,36 +1,29 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders -import android.graphics.Color -import android.support.v4.content.ContextCompat -import android.support.v7.widget.RecyclerView -import android.util.TypedValue import android.view.View -import io.github.feelfreelinux.wykopmobilny.R +import io.github.feelfreelinux.wykopmobilny.glide.GlideApp import io.github.feelfreelinux.wykopmobilny.models.dataclass.Link import io.github.feelfreelinux.wykopmobilny.ui.modules.links.linkdetails.LinkDetailsActivity import io.github.feelfreelinux.wykopmobilny.utils.* -import io.github.feelfreelinux.wykopmobilny.utils.api.stripImageCompression -import io.github.feelfreelinux.wykopmobilny.utils.textview.removeHtml import kotlinx.android.synthetic.main.link_layout.view.* -class LinkViewHolder(val view: View) : RecyclerView.ViewHolder(view) { +class LinkViewHolder(val view: View) : RecyclableViewHolder(view) { val linksPreferences by lazy { LinksPreferences(view.context) } fun bindView(link : Link) { view.apply { - title.text = link.title.removeHtml() + title.text = link.title image.isVisible = link.preview != null - link.preview?.let { image.loadImage(link.preview.stripImageCompression()) } - description.text = link.description.removeHtml() + link.preview?.let { image.loadImage(link.preview) } + description.text = link.description diggCountTextView.voteCount = link.voteCount diggCountTextView.isEnabled = false diggCountTextView.setVoteState(link.userVote) commentsCountTextView.text = link.commentsCount.toString() - dateTextView.text = link.date.toPrettyDate() + dateTextView.text = link.date hotBadgeStrip.isVisible = link.isHot - val gotPreviouslySelected = linksPreferences.readLinksIds.contains("link_${link.id}") - if (gotPreviouslySelected) { + if (link.gotSelected) { image.alpha = 0.6f title.alpha = 0.6f description.alpha = 0.6f @@ -40,15 +33,26 @@ class LinkViewHolder(val view: View) : RecyclerView.ViewHolder(view) { description.alpha = 1f } setOnClickListener { - if (!gotPreviouslySelected) { + view.getActivityContext()!!.startActivity(LinkDetailsActivity.createIntent(view.getActivityContext()!!, link)) + if (!link.gotSelected) { image.alpha = 0.6f title.alpha = 0.6f description.alpha = 0.6f + link.gotSelected = true linksPreferences.readLinksIds = linksPreferences.readLinksIds.plusElement("link_${link.id}") } - view.getActivityContext()!!.startActivity(LinkDetailsActivity.createIntent(view.getActivityContext()!!, link)) } - requestLayout() + } + } + + override fun cleanRecycled() { + view.apply { + title.text = null + description.text = null + diggCountTextView.text = null + commentsCountTextView.text = null + setOnClickListener(null) + GlideApp.with(this).clear(image) } } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/PMMessageViewHolder.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/PMMessageViewHolder.kt index eba4225d7..3794201f4 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/PMMessageViewHolder.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/PMMessageViewHolder.kt @@ -6,28 +6,27 @@ import android.util.TypedValue import android.view.View import android.widget.RelativeLayout import io.github.feelfreelinux.wykopmobilny.R +import io.github.feelfreelinux.wykopmobilny.glide.GlideApp import io.github.feelfreelinux.wykopmobilny.models.dataclass.PMMessage import io.github.feelfreelinux.wykopmobilny.ui.modules.NewNavigatorApi import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi import io.github.feelfreelinux.wykopmobilny.utils.getActivityContext import io.github.feelfreelinux.wykopmobilny.utils.textview.prepareBody -import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.WykopLinkHandlerApi import kotlinx.android.synthetic.main.pmmessage_sent_layout.view.* class PMMessageViewHolder(val view: View, val linkHandlerApi: WykopLinkHandlerApi, val settingsPreferencesApi: SettingsPreferencesApi, - val navigatorApi: NewNavigatorApi) : RecyclerView.ViewHolder(view) { + val navigatorApi: NewNavigatorApi) : RecyclableViewHolder(view) { fun bindView(message: PMMessage) { flipMessage(message.isSentFromUser) view.apply { - val prettyDate = message.date.toPrettyDate() - date.text = prettyDate + date.text = message.date message.app?.let { - date.text = context.getString(R.string.date_with_user_app, prettyDate, message.app) + date.text = context.getString(R.string.date_with_user_app, message.date, message.app) } body.prepareBody(message.body, { linkHandlerApi.handleUrl(it) }) @@ -77,7 +76,13 @@ class PMMessageViewHolder(val view: View, } view.cardView.layoutParams = cardViewParams - view.invalidate() - view.requestLayout() + } + + override fun cleanRecycled() { + view.apply { + date.text = null + body.text = null + GlideApp.with(this).clear(embedImage) + } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/RecyclableViewHolder.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/RecyclableViewHolder.kt new file mode 100644 index 000000000..10df77727 --- /dev/null +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/adapters/viewholders/RecyclableViewHolder.kt @@ -0,0 +1,8 @@ +package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders + +import android.support.v7.widget.RecyclerView +import android.view.View + +abstract class RecyclableViewHolder(view : View) : RecyclerView.ViewHolder(view) { + abstract fun cleanRecycled() +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/hits/HitsFragment.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/hits/HitsFragment.kt index 043af37e3..77f5ea399 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/hits/HitsFragment.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/links/hits/HitsFragment.kt @@ -115,6 +115,7 @@ class HitsFragment : BaseFragment(), HitsView { monthSelection = dataFragment.data!!.monthSelection } loadingView.isVisible = false + feedAdapter.disableLoading() } else { loadData() loadingView.isVisible = true diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/BaseNotificationsListFragment.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/BaseNotificationsListFragment.kt index 0738d6c55..da6bc3fde 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/BaseNotificationsListFragment.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/BaseNotificationsListFragment.kt @@ -64,8 +64,8 @@ abstract class BaseNotificationsListFragment : BaseFragment(), NotificationsList if (notifications.isNotEmpty()) { loadingView.isVisible = false swiperefresh.isRefreshing = false - notificationAdapter.addData(notifications, shouldClearAdapter) - } + notificationAdapter.addData(notifications.filterNot { notificationAdapter.data.contains(it) }, shouldClearAdapter) + } else notificationAdapter.disableLoading() } override fun showReadToast() { diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/hashtags/HashTagsNotificationsListFragment.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/hashtags/HashTagsNotificationsListFragment.kt index e416d4d52..65b02a8e5 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/hashtags/HashTagsNotificationsListFragment.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/hashtags/HashTagsNotificationsListFragment.kt @@ -40,6 +40,7 @@ class HashTagsNotificationsListFragment : BaseNotificationsListFragment() { loadingView.isVisible = false presenter.page = pagedModel.page notificationAdapter.addData(pagedModel.model, true) + notificationAdapter.disableLoading() } else { loadingView.isVisible = true onRefresh() diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/notification/NotificationsListFragment.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/notification/NotificationsListFragment.kt index b4b0df18f..3eee903d1 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/notification/NotificationsListFragment.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/notificationslist/notification/NotificationsListFragment.kt @@ -47,6 +47,7 @@ class NotificationsListFragment : BaseNotificationsListFragment() { loadingView.isVisible = false presenter.page = entryFragmentData.data!!.page notificationAdapter.addData(entryFragmentData.data!!.model, true) + notificationAdapter.disableLoading() } else { loadingView.isVisible = true onRefresh() diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/pm/conversation/ConversationActivity.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/pm/conversation/ConversationActivity.kt index 01a3caa39..761910347 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/pm/conversation/ConversationActivity.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/modules/pm/conversation/ConversationActivity.kt @@ -62,6 +62,7 @@ class ConversationActivity : BaseActivity(), ConversationView, InputToolbarListe prepare() adapter = conversationAdapter (layoutManager as LinearLayoutManager).reverseLayout = true + setHasFixedSize(false) } if (conversationDataFragment.data == null) { @@ -82,7 +83,7 @@ class ConversationActivity : BaseActivity(), ConversationView, InputToolbarListe swiperefresh.isRefreshing = false receiver = conversation.receiver toolbar.apply { - subtitle = conversation.messages.last().date.toPrettyDate() + subtitle = conversation.messages.last().date avatarview.setAuthor(conversation.receiver) avatarview.isVisible = true } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/AuthorHeaderView.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/AuthorHeaderView.kt index 45ef8a733..3bdae2054 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/AuthorHeaderView.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/AuthorHeaderView.kt @@ -27,11 +27,10 @@ class AuthorHeaderView : ConstraintLayout { setTextColor(context.getGroupColor(group)) } authorAvatarView.setAuthor(this) - val prettyDate = if (date.isNotEmpty()) date.toPrettyDate() else "" - entryDateTextView.text = prettyDate + entryDateTextView.text = date app?.let { - entryDateTextView.text = context.getString(R.string.date_with_user_app, prettyDate, app) + entryDateTextView.text = context.getString(R.string.date_with_user_app, date, app) } } } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/link/LinkWidget.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/link/LinkWidget.kt index 4f8c44c20..20f73c598 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/link/LinkWidget.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/ui/widgets/link/LinkWidget.kt @@ -63,7 +63,7 @@ class LinkWidget(context: Context, attrs: AttributeSet) : CardView(context, attr } private fun setupHeader() { - dateTextView.text = link.date.toPrettyDate() + dateTextView.text = link.date hotBadgeStrip.isVisible = link.isHot val author = link.author if (author != null) { @@ -76,9 +76,7 @@ class LinkWidget(context: Context, attrs: AttributeSet) : CardView(context, attr avatarView.isVisible = false userTextView.isVisible = false } - dateTextView.text = link.date.toPrettyDate() urlTextView.text = URL(link.sourceUrl).host.removePrefix("www.") - tagsTextView.prepareBody(link.tags.convertToTagsHtml(), this) } @@ -116,20 +114,6 @@ class LinkWidget(context: Context, attrs: AttributeSet) : CardView(context, attr } } - fun setWykopColorDrawable(isButtonSelected : Boolean) { - if (isButtonSelected) { - diggCountTextView.setTextColor(Color.WHITE) - diggCountTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_wypok_activ, 0, 0, 0); - } else { - diggCountTextView.setTextColor(description.currentTextColor) - val typedArray = context.obtainStyledAttributes(arrayOf( - R.attr.wypokDrawable).toIntArray()) - diggCountTextView.setCompoundDrawablesWithIntrinsicBounds(typedArray.getDrawable(0), null, null, null) - typedArray.recycle() - - } - } - override fun showVoteCount(digResponse: DigResponse) { link.buryCount = digResponse.buries link.voteCount = digResponse.diggs diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/Extensions.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/Extensions.kt index 009356401..353101dd1 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/Extensions.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/Extensions.kt @@ -48,6 +48,9 @@ fun View.getActivityContext() : Activity? { fun RecyclerView.prepare() { setHasFixedSize(true) // For better performance + setItemViewCacheSize(30) + isDrawingCacheEnabled = true + drawingCacheQuality = View.DRAWING_CACHE_QUALITY_HIGH layoutManager = LinearLayoutManager(context) } @@ -61,7 +64,6 @@ fun View.disableFor(millis: Long){ fun ImageView.loadImage(url : String) { GlideApp.with(context) .load(url) - .transition(GenericTransitionOptions.with(R.anim.fade_in)) .into(this) } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/LinksPreferences.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/LinksPreferences.kt index cf13bdfb1..63abf71a2 100644 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/LinksPreferences.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/LinksPreferences.kt @@ -1,7 +1,12 @@ package io.github.feelfreelinux.wykopmobilny.utils import android.content.Context +import javax.inject.Inject -class LinksPreferences(context : Context) : Preferences(context, false) { - var readLinksIds by stringSetPref(defaultValue = HashSet()) +interface LinksPreferencesApi { + var readLinksIds: Set +} + +class LinksPreferences (context : Context) : Preferences(context, false), LinksPreferencesApi { + override var readLinksIds by stringSetPref(defaultValue = HashSet()) } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/api/ApiUtils.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/api/ApiUtils.kt index 48955ecf2..d93047e09 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/api/ApiUtils.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/api/ApiUtils.kt @@ -55,7 +55,7 @@ fun getGenderStripResource(authorSex : String) : Int = fun String.stripImageCompression() : String { val extension = substringAfterLast(".") val baseUrl = substringBeforeLast(",") - return baseUrl + "." + extension + return baseUrl + if (!baseUrl.endsWith(extension)) "." + extension else "" } fun String.encryptMD5() : String{ diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/BetterLinkMovementMethod.java b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/BetterLinkMovementMethod.java index cea836979..d8a5b1069 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/BetterLinkMovementMethod.java +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/BetterLinkMovementMethod.java @@ -261,7 +261,7 @@ public void onTimerReached() { if (touchStartedOverALink && clickableSpanUnderTouch == clickableSpanUnderTouchOnActionDown) { dispatchUrlClick(textView, clickableSpanUnderTouch); } else { - onTextClickListener.onClick(); + if (onTextClickListener != null) onTextClickListener.onClick(); } } cleanupOnTouchUp(textView); @@ -407,7 +407,6 @@ protected void dispatchUrlClick(TextView textView, ClickableSpan clickableSpan) boolean handled = onLinkClickListener != null && onLinkClickListener.onClick(textView, clickableSpanWithText.text()); if (!handled) { - printout("AAAAA"); // Let Android handle this click. clickableSpanWithText.span().onClick(textView); } diff --git a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/HtmlUtils.kt b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/HtmlUtils.kt index 60aa48839..c6ce62361 100755 --- a/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/HtmlUtils.kt +++ b/app/src/main/kotlin/io/github/feelfreelinux/wykopmobilny/utils/textview/HtmlUtils.kt @@ -1,3 +1,4 @@ + package io.github.feelfreelinux.wykopmobilny.utils.textview import android.os.Build