Skip to content

Commit

Permalink
Beta 0.5.2, added link id database
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Jan 26, 2018
1 parent e7677f1 commit d535c4a
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId "io.github.feelfreelinux.wykopmobilny"
minSdkVersion 17
targetSdkVersion 27
versionCode 21
versionName "0.5.1.1"
versionCode 22
versionName "0.5.2"

def credentialsPropertiesFile = rootProject.file("credentials.properties")
def credentialsProperties = new Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ class LinksRepository(val retrofit: Retrofit, val userTokenRefresher: UserTokenR
.retryWhen(userTokenRefresher)
.compose<List<LinkCommentResponse>>(ErrorHandlerTransformer())
.map { it.map { LinkCommentMapper.map(it) } }
.map {
val list = it
it.forEach {
val commentId = it.id
if (commentId == it.parentId) it.childCommentCount = list.filter { commentId == it.parentId }.size - 1
}
it
}


override fun getLink(linkId: Int): Single<Link> =
linksApi.getLink(linkId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Link(
val status: String,
var userVote: String?,
var userFavorite: Boolean,
val app: String?
val app: String?,
var gotSelected : Boolean
) : Parcelable {
constructor(source: Parcel) : this(
source.readInt(),
Expand All @@ -47,8 +48,9 @@ class Link(
source.readString(),
source.readString(),
1 == source.readInt(),
source.readString()
)
source.readString(),
1 == source.readInt()
)

override fun describeContents() = 0

Expand All @@ -73,6 +75,7 @@ class Link(
writeString(userVote)
writeInt((if (userFavorite) 1 else 0))
writeString(app)
writeInt((if (gotSelected) 1 else 0))
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class LinkComment(
val embed: Embed?,
val app: String?,
var isCollapsed : Boolean,
var isParentCollapsed : Boolean
var isParentCollapsed : Boolean,
var childCommentCount : Int
) : Parcelable {
constructor(source: Parcel) : this(
source.readInt(),
Expand All @@ -42,7 +43,8 @@ class LinkComment(
source.readParcelable<Embed>(Embed::class.java.classLoader),
source.readString(),
1 == source.readInt(),
1 == source.readInt()
1 == source.readInt(),
source.readInt()
)

override fun describeContents() = 0
Expand All @@ -65,7 +67,7 @@ class LinkComment(
writeString(app)
writeInt((if (isCollapsed) 1 else 0))
writeInt((if (isParentCollapsed) 1 else 0))

writeInt(childCommentCount)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LinkCommentMapper {
value.userVote, value.parentId, value.canVote,
value.linkId,
if (value.embed != null) EmbedMapper.map(value.embed) else null,
value.app, false, false)
value.app, false, false, 0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LinkMapper {
value.commentsCount, value.relatedCount,
if (value.author != null) AuthorMapper.map(value.author) else null, value.date, value.preview,
value.plus18, value.canVote, value.isHot,
value.status, value.userVote, value.userFavorite ?: false, value.app)
value.status, value.userVote, value.userFavorite ?: false, value.app, false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders
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.models.dataclass.LinkComment
import io.github.feelfreelinux.wykopmobilny.ui.modules.NewNavigatorApi
import io.github.feelfreelinux.wykopmobilny.ui.widgets.link.comment.LinkCommentPresenter
Expand All @@ -14,14 +15,14 @@ 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) {
fun bindView(comment : LinkComment, isUserAuthor: Boolean, highlightCommentId: Int) {
val margin = if (comment.id != comment.parentId) 8f else 0f
val px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, margin, view.resources.displayMetrics)
view.setPadding(px.toInt(), 0, 0, 0)
val margin = if (comment.id != comment.parentId) view.resources.getDimensionPixelSize(R.dimen.comment_section_left_margin) else 0
view.setPadding(margin, 0, 0, 0)
view.linkComment.collapseListener = collapseListener
view.replyTextView.setOnClickListener { linkCommentReplyListener.invoke(comment) }
view.linkComment.setLinkCommentData(comment, linkCommentPresenter, userManagerApi, settingsPreferencesApi)
view.linkComment.setStyleForComment(isUserAuthor, highlightCommentId)
view.hiddenRepliesView.isVisible = comment.isCollapsed
view.hiddenRepliesView.isVisible = comment.isCollapsed && comment.childCommentCount > 0
view.messageTextView.text = view.resources.getString(R.string.hidden_replies, comment.childCommentCount)
view.hiddenRepliesView.setOnClickListener {
view.linkComment.expandComment()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ 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.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.getActivityContext
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.loadImage
import io.github.feelfreelinux.wykopmobilny.utils.textview.removeHtml
import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate
import kotlinx.android.synthetic.main.link_layout.view.*


class LinkViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
val linksPreferences by lazy { LinksPreferences(view.context) }
fun bindView(link : Link) {
view.apply {
val typedValue = TypedValue()
context.theme.resolveAttribute(R.attr.linkViewClicked, typedValue, true)
title.text = link.title.removeHtml()
image.isVisible = link.preview != null
link.preview?.let { image.loadImage(link.preview.stripImageCompression()) }
Expand All @@ -30,7 +31,17 @@ class LinkViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
commentsCountTextView.text = link.commentsCount.toString()
dateTextView.text = link.date.toPrettyDate()
hotBadgeStrip.isVisible = link.isHot
val gotPreviouslySelected = linksPreferences.readLinksIds.contains("link_${link.id}")
if (gotPreviouslySelected) {
constraintLayout.setBackgroundColor(ContextCompat.getColor(context, typedValue.resourceId))
} else {
constraintLayout.setBackgroundColor(Color.TRANSPARENT)
}
setOnClickListener {
if (!gotPreviouslySelected) {
constraintLayout.setBackgroundColor(ContextCompat.getColor(context, typedValue.resourceId))
linksPreferences.readLinksIds = linksPreferences.readLinksIds.plusElement("link_${link.id}")
}
view.getActivityContext()!!.startActivity(LinkDetailsActivity.createIntent(view.getActivityContext()!!, link))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package io.github.feelfreelinux.wykopmobilny.ui.widgets
import android.content.Context
import android.graphics.Bitmap
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.widget.ImageView
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import io.github.feelfreelinux.wykopmobilny.glide.GlideApp
import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferences
import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.getActivityContext


class WykopImageView: ImageView {
Expand Down Expand Up @@ -44,13 +46,19 @@ class WykopImageView: ImageView {
setImageBitmap(null)
}

val screenMetrics by lazy {
val metrics = DisplayMetrics()
getActivityContext()!!.windowManager.defaultDisplay.getMetrics(metrics)
metrics
}

var openImageListener : () -> Unit = {}
var onResizedListener : (Boolean) -> Unit = {}
var showResizeView : (Boolean) -> Unit = {}


override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val proportion = settingsPreferencesApi.cutImageProportion.toFloat() / 100
val proportion = (screenMetrics.heightPixels.toFloat() * (settingsPreferencesApi.cutImageProportion.toFloat() / 100)) / screenMetrics.widthPixels.toFloat()
val widthSpec = MeasureSpec.getSize(if (settingsPreferencesApi.showMinifiedImages && !forceDisableMinimizedMode) widthMeasureSpec/2 else widthMeasureSpec)
if (drawable != null) {
val measuredMultipler = (drawable.intrinsicHeight.toFloat() / drawable.intrinsicWidth.toFloat())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.dialogs.showExceptionDialog
import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.getActivityContext
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.printout
import io.github.feelfreelinux.wykopmobilny.utils.textview.URLClickedListener
import io.github.feelfreelinux.wykopmobilny.utils.textview.prepareBody
import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi
Expand Down Expand Up @@ -73,7 +74,7 @@ class LinkCommentWidget(context: Context, attrs: AttributeSet) : CardView(contex
buttonsToolbar.isVisible = false
}
commentContentTextView.isVisible = !comment.body.isNullOrEmpty()
if (comment.id != comment.parentId) {
if ((comment.id != comment.parentId) || comment.childCommentCount == 0) {
showHiddenCommentsCountCard(false)
collapseButton.isVisible = false
} else collapseButton.isVisible = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.feelfreelinux.wykopmobilny.utils

import android.content.Context

class LinksPreferences(context : Context) : Preferences(context, false) {
var readLinksIds by stringSetPref(defaultValue = HashSet())
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class SettingsPreferences(context : Context) : Preferences(context, true), Setti
override var useAmoledTheme by booleanPref(defaultValue = false)
override var showMinifiedImages by booleanPref(defaultValue = false)
override var cutImages by booleanPref(defaultValue = true)
override var cutImageProportion by intPref(defaultValue = 110)

override var cutImageProportion by intPref(defaultValue = 60)
override var showNotifications by booleanPref(defaultValue = true)
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/link_comment_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:layout_marginLeft="@dimen/comment_section_left_margin">

<TextView
android:id="@+id/messageTextView"
style="@style/EntryContentTextView"
android:text="Odpowiedzi do komentarza zostały ukryte."
android:layout_width="match_parent"
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/layout/link_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="android.support.v7.widget.CardView"
style="@style/EntryCardView"
android:background="?attr/cardviewStatelist"
android:addStatesFromChildren="true"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand All @@ -19,7 +24,6 @@
android:scaleType="centerCrop"
android:clickable="false"
android:focusable="false"
android:duplicateParentState="true"
android:src="@drawable/ic_wykopmobilny"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand All @@ -38,7 +42,6 @@
android:maxLines="2"
android:clickable="false"
android:focusable="false"
android:duplicateParentState="true"
app:layout_constraintStart_toEndOf="@id/image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand All @@ -55,7 +58,6 @@
android:maxLines="3"
android:clickable="false"
android:focusable="false"
android:duplicateParentState="true"
app:layout_constraintStart_toEndOf="@id/image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title"
Expand Down Expand Up @@ -104,6 +106,8 @@
<TextView
android:id="@+id/commentsCountTextView"
style="@style/MikroButton"
android:clickable="false"
android:focusable="false"
android:background="?attr/voteButtonStatelist"
android:drawableStart="?attr/commentDrawable"
app:layout_constraintEnd_toStartOf="@+id/diggCountTextView"
Expand All @@ -118,6 +122,8 @@
app:layout_constraintEnd_toStartOf="@id/moreOptionsTextView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:clickable="false"
android:focusable="false"
tools:text="2137"/>

<TextView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<attr name="separatorColor" format="reference"/>
<attr name="expandImageGradient" format="reference"/>
<attr name="shadowUpGradient" format="reference"/>
<attr name="linkViewClicked" format="color"/>

<!-- DRAWABLES -->
<attr name="expandDrawable" format="reference"/>
<attr name="collapseDrawable" format="reference"/>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<color name="cardView.Dark">#2c2c2c</color>
<color name="cardList.Dark">#181818</color>
<color name="cardViewSelected.Dark">#252525</color>
<color name="linkItemClicked.Dark">#222222</color>
<color name="linkItemClicked">#f3f3f3</color>

<color name="cardView.Amoled">#080808</color>
<color name="cardList.Amoled">#000000</color>
<color name="cardViewSelected.Amoled">#000000</color>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
<string name="voters_list">Lista plusujących</string>
<string name="bury">Zakop</string>
<string name="app_config_images">Ustawienia obrazków</string>
<string name="app_config_images_cut_image_proportion">Proporcje przycięcia obrazka (szerokość/wysokosć)</string>
<string name="app_config_images_cut">Przycinaj obrazek</string>
<string name="app_config_images_cut_image_proportion">Maksymalna wysokość obrazka (% wysokości ekranu)</string>
<string name="app_config_images_cut">Zwijaj długie obrazki</string>
<string name="app_config_images_minified">Wyświetlaj obrazki w trybie miniaturki</string>
<string name="bury_list">Lista zakopujących (%1$d)</string>
<string name="dig_list">Lista wykopujących (%1$d)</string>
Expand Down Expand Up @@ -142,6 +142,7 @@
<string name="reason_fake_info">Informacja nieprawdziwa</string>
<string name="reason_wrong_content">Treść nieodpowiednia</string>
<string name="reason_unsuitable_content">Nie nadaje się</string>
<string name="hidden_replies">%1$d ukrytych odpowiedzi</string>

<string name="license">Publikacja aplikacji na licencji MIT</string>
<string name="report_bug">Zgłoś błąd pod tagiem #owmbugi</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<item name="surveyBarStroke">@drawable/survey_bar_stroke</item>
<item name="expandDrawable">@drawable/comment_expand_light</item>
<item name="collapseDrawable">@drawable/comment_collapse_light</item>
<item name="linkViewClicked">@color/linkItemClicked</item>

<item name="markdownFormatQuote">@drawable/ic_format_quote</item>
<item name="markdownFormatBold">@drawable/ic_format_bold</item>
Expand Down Expand Up @@ -101,6 +102,7 @@
<item name="expandImageGradient">@drawable/gradient_expand_image</item>
<item name="shadowUpGradient">@drawable/gradient_separator_input</item>
<item name="adminNickColor">@android:color/white</item>
<item name="linkViewClicked">@color/linkItemClicked.Dark</item>

<item name="voteButtonStatelist">@drawable/button_vote_background_state_list_dark</item>
<item name="voteMinusButtonStatelist">@drawable/button_minus_vote_background_state_list_dark</item>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/xml/app_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<com.pavelsikun.seekbarpreference.SeekBarPreferenceCompat
android:key="cutImageProportion"
android:title="@string/app_config_images_cut_image_proportion"
android:defaultValue="110"
android:defaultValue="60"
sample:msbp_minValue="20"
sample:msbp_maxValue="250"
sample:msbp_maxValue="150"
sample:msbp_interval="10"
sample:msbp_measurementUnit="%"
sample:msbp_dialogEnabled="false"/>
Expand Down

0 comments on commit d535c4a

Please sign in to comment.