Skip to content

Commit

Permalink
Added quote and entry reply buttons. Beta 0.6 (Finally!)
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Feb 13, 2018
1 parent 678bb80 commit 3fc26be
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 17 deletions.
7 changes: 4 additions & 3 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 26
versionName "0.5.4"
versionCode 27
versionName "0.6"

def credentialsPropertiesFile = rootProject.file("credentials.properties")
def credentialsProperties = new Properties()
Expand Down Expand Up @@ -90,7 +90,7 @@ dependencies {
implementation "com.android.support:support-v4:$versions.supportLibrary"
implementation "com.android.support:customtabs:$versions.supportLibrary"
implementation "com.android.support.constraint:constraint-layout:$versions.constraintLayout"

implementation "com.google.android.gms:play-services-gcm:11.6.0"
// Utils
implementation "com.bugsnag:bugsnag-android:4.1.3"
implementation "org.ocpsoft.prettytime:prettytime:$versions.prettytime"
Expand All @@ -107,6 +107,7 @@ dependencies {
// RxJava
implementation "io.reactivex.rxjava2:rxandroid:$versions.rxandroid"
implementation "io.reactivex.rxjava2:rxjava:$versions.rxjava"
implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'

// AppUpdater
implementation "com.github.javiersantos:AppUpdater:$versions.appUpdater"
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

<service
android:name="com.evernote.android.job.gcm.PlatformGcmService"
tools:node="remove"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.feelfreelinux.wykopmobilny
import android.content.Context
import com.bugsnag.android.Bugsnag
import com.evernote.android.job.JobManager
import com.jakewharton.threetenabp.AndroidThreeTen
import com.squareup.leakcanary.LeakCanary
import com.squareup.leakcanary.RefWatcher
import dagger.android.AndroidInjector
Expand Down Expand Up @@ -31,6 +32,7 @@ class WykopApp : DaggerApplication() {

override fun onCreate() {
super.onCreate()
AndroidThreeTen.init(this)
refWatcher = LeakCanary.install(this)
JobManager.create(this).addJobCreator(jobCreator)
if (!BuildConfig.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EntryCommentAdapter @Inject constructor(val presenterFactory: CommentPrese
}

override fun createViewHolder(parent: ViewGroup): CommentViewHolder =
CommentViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.comment_list_item, parent, false), {}, settingsPreferencesApi, userManagerApi, presenterFactory.create())
CommentViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.comment_list_item, parent, false), {}, {}, settingsPreferencesApi, userManagerApi, presenterFactory.create())

override fun onViewRecycled(holder: RecyclerView.ViewHolder?) {
(holder as? RecyclableViewHolder)?.cleanRecycled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.ViewGroup
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry
import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryComment
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
Expand All @@ -24,6 +25,8 @@ class EntryDetailAdapter @Inject constructor(val userManagerApi: UserManagerApi,
private const val COMMENT_HOLDER = 1
}
lateinit var addReceiverListener: (Author) -> Unit
lateinit var quoteCommentListener: (EntryComment) -> Unit

var entry: Entry? = null
var commentId : Int? = null

Expand Down Expand Up @@ -52,8 +55,8 @@ class EntryDetailAdapter @Inject constructor(val userManagerApi: UserManagerApi,

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
ENTRY_HOLDER -> EntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.entry_list_item, parent, false), userManagerApi, settingsPreferencesApi, entryPresenterFactory.create())
else -> CommentViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.comment_list_item, parent, false), addReceiverListener, settingsPreferencesApi, userManagerApi, commentPresenterFactory.create())
ENTRY_HOLDER -> EntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.entry_list_item, parent, false), userManagerApi, addReceiverListener, settingsPreferencesApi, entryPresenterFactory.create())
else -> CommentViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.comment_list_item, parent, false), addReceiverListener, quoteCommentListener, settingsPreferencesApi, userManagerApi, commentPresenterFactory.create())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EntryLinkAdapter @Inject constructor(val userManagerApi: UserManagerApi, v

override fun createViewHolder(viewType: Int, parent: ViewGroup): RecyclerView.ViewHolder =
when (viewType) {
ENTRY_VIEWTYPE -> EntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.entry_list_item, parent, false), userManagerApi, settingsPreferencesApi, entryPresenterFactory.create())
ENTRY_VIEWTYPE -> EntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.entry_list_item, parent, false), userManagerApi, null, settingsPreferencesApi, entryPresenterFactory.create())
else -> LinkViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.link_layout, parent, false))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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())
EntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.entry_list_item, parent, false), userManagerApi, null, settingsPreferencesApi, entryPresenterFactory.create())

override fun onViewRecycled(holder: RecyclerView.ViewHolder?) {
(holder as? RecyclableViewHolder)?.cleanRecycled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ 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) : RecyclableViewHolder(view) {
class CommentViewHolder(val view: View, private val addReceiverListener : (Author) -> Unit, val quoteListener : (EntryComment) -> Unit, val settingsPreferencesApi: SettingsPreferencesApi, val userManagerApi: UserManagerApi, val commentPresenter: CommentPresenter) : RecyclableViewHolder(view) {
fun bindView(comment : EntryComment, isAuthorComment: Boolean, commentId : Int?, shouldEnableClickListener : Boolean = false) {
view.entryComment.shouldEnableClickListener = shouldEnableClickListener
view.entryComment.addReceiverListener = addReceiverListener
view.entryComment.setCommentData(comment, userManagerApi, settingsPreferencesApi, commentPresenter)
view.entryComment.setStyleForComment(isAuthorComment, commentId ?: -1)
view.entryComment.quoteCommentListener = quoteListener
}

override fun cleanRecycled() {
Expand All @@ -26,6 +27,7 @@ class CommentViewHolder(val view: View, private val addReceiverListener : (Autho
view.entryComment.shouldEnableClickListener = false
view.entryComment.entryContentTextView.text = null
view.entryComment.addReceiverListener = null
view.entryComment.quoteCommentListener = null
view.entryComment.setOnClickListener(null)
}
}
Expand Down
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.view.View
import io.github.feelfreelinux.wykopmobilny.glide.GlideApp
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry
import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.EntryPresenter
import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi
Expand All @@ -11,10 +12,11 @@ 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) : RecyclableViewHolder(view) {
class EntryViewHolder(val view: View, val userManagerApi: UserManagerApi, val entryReplyListener : ((Author) -> Unit)?, val settingsPreferencesApi: SettingsPreferencesApi, val entryPresenter: EntryPresenter) : RecyclableViewHolder(view) {
fun bindView(entry : Entry, enableClickListener : Boolean = true) {
view.entry.apply {
shouldEnableClickListener = enableClickListener
replyListener = entryReplyListener
setEntryData(entry, userManagerApi, settingsPreferencesApi, entryPresenter)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ abstract class BaseInputActivity<T : BaseInputPresenter> : BaseActivity(), BaseI
if (contains("<a href=\"spoiler:")) {
textBody += removeSpoilerHtml().removeHtml()
} else textBody += removeHtml()
selectionPosition = if (!contains("\n")) textBody.length else 0
selectionPosition = if (!startsWith("#")) textBody.length else {
textBody = "\n$textBody"
0
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class EntryActivity : BaseActivity(), EntryDetailView, InputToolbarListener, Swi
setSupportActionBar(toolbar)
adapter.commentId = intent.getIntExtra(EXTRA_COMMENT_ID, -1)
adapter.addReceiverListener = { inputToolbar.addAddressant(it.nick) }
adapter.quoteCommentListener = {
inputToolbar.addQuoteText(it.body, it.author.nick)
}

supportActionBar?.apply {
title = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NotificationsListViewPagerAdapter(val resources : Resources, fragmentManag
override fun getPageTitle(position: Int): CharSequence {
super.getPageTitle(position)
return when(position) {
0 -> resources.getString(R.string.notifications_title)
0 -> resources.getString(R.string.notifications_directed)
else -> resources.getString(R.string.hashtags_notifications_title)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import android.view.View
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.api.entries.TypedInputStream
import io.github.feelfreelinux.wykopmobilny.api.suggest.SuggestApi
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author
import io.github.feelfreelinux.wykopmobilny.ui.suggestions.HashTagsSuggestionsAdapter
import io.github.feelfreelinux.wykopmobilny.ui.suggestions.UsersSuggestionsAdapter
import io.github.feelfreelinux.wykopmobilny.ui.suggestions.WykopSuggestionsTokenizer
import io.github.feelfreelinux.wykopmobilny.ui.widgets.markdown_toolbar.MarkdownToolbarListener
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.textview.removeHtml
import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi
import kotlinx.android.synthetic.main.input_toolbar.view.*

Expand Down Expand Up @@ -149,6 +151,13 @@ class InputToolbar : ConstraintLayout, MarkdownToolbarListener {
selectionPosition = textBody.length
}

fun addQuoteText(quote : String, quoteAuthor : String) {
defaultText = ""
body.requestFocus()
textBody += "\n> @$quoteAuthor: ${quote.removeHtml()}"
selectionPosition = textBody.length
}

fun setCustomHint(hint : String) {
body.hint = hint
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.util.TypedValue
import android.view.Gravity
import android.view.View
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Survey
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Voter
Expand All @@ -35,6 +36,7 @@ class EntryWidget(context: Context, attrs: AttributeSet) : CardView(context, att
private lateinit var settingsPreferencesApi : SettingsPreferencesApi
private lateinit var votersDialogListener : (List<Voter>) -> Unit
var shouldEnableClickListener = true
var replyListener : ((Author) -> Unit)? = null

init {
View.inflate(context, R.layout.entry_layout, this)
Expand Down Expand Up @@ -85,11 +87,15 @@ class EntryWidget(context: Context, attrs: AttributeSet) : CardView(context, att
}
}


replyTextView.isVisible = !shouldEnableClickListener
if (shouldEnableClickListener) {
replyTextView.setOnClickListener(null)
setOnClickListener {
presenter.openDetails(entry.embed?.isRevealed ?: false)
}
} else {
replyTextView.setOnClickListener { replyListener?.invoke(entry.author) }

}

voteButton.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CommentWidget : CardView, CommentView {
lateinit var comment : EntryComment

var addReceiverListener: ((Author) -> Unit)? = null
var quoteCommentListener: ((EntryComment) -> Unit)? = null

lateinit var presenter : CommentPresenter
var shouldEnableClickListener = false
private lateinit var userManagerApi: UserManagerApi
Expand Down Expand Up @@ -100,6 +102,7 @@ class CommentWidget : CardView, CommentView {
private fun setupBody() {
moreOptionsTextView.setOnClickListener { openOptionsMenu() }
replyTextView.setOnClickListener { addReceiver() }
quoteTextView.setOnClickListener { quoteCommentListener?.invoke(comment) }
val clickListener = { presenter.handleLink(url) }
if (shouldEnableClickListener) setOnClickListener { clickListener() }
if (comment.body.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ import android.webkit.MimeTypeMap
import android.widget.ImageView
import com.bumptech.glide.GenericTransitionOptions
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.glide.GlideApp
import io.github.feelfreelinux.wykopmobilny.utils.api.parseDate
import io.github.feelfreelinux.wykopmobilny.utils.api.parseDateJavaTime
import org.ocpsoft.prettytime.PrettyTime
import org.threeten.bp.Duration
import org.threeten.bp.Instant
import org.threeten.bp.LocalDate
import org.threeten.bp.Period
import java.util.*


Expand Down Expand Up @@ -64,6 +70,7 @@ fun View.disableFor(millis: Long){
fun ImageView.loadImage(url : String) {
GlideApp.with(context)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.override(Target.SIZE_ORIGINAL)
.into(this)
}
Expand All @@ -72,6 +79,14 @@ fun String.toPrettyDate() : String {
return PrettyTime(Locale("pl")).format(parseDate(this))
}
fun String.toDurationPrettyDate() : String {
val duration = Period.between(parseDateJavaTime(this), LocalDate.now())
if (duration.years > 1 && duration.months > 0) {
return "${duration.years} lata ${duration.months} mies."
} else if (duration.years == 1 && duration.months > 0) {
return "${duration.years} rok ${duration.months} mies."
} else if (duration.years == 0) {
return "${duration.months} mies."
}
return PrettyTime(Locale("pl")).formatDurationUnrounded(parseDate(this))
}
fun Uri.queryFileName(contentResolver: ContentResolver) : String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import android.net.Uri
import android.util.TypedValue
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.utils.printout
import org.threeten.bp.LocalDate
import org.threeten.bp.ZoneId
import org.threeten.bp.format.DateTimeFormatter
import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.util.*
Expand All @@ -16,6 +19,11 @@ fun parseDate(date : String) : Date {
return format.parse(date)
}

fun parseDateJavaTime(date : String) : LocalDate {
val format = DateTimeFormatter.ofPattern("yyyy-MM-dd kk:mm:ss", Locale.GERMANY)
return LocalDate.parse(date, format.withZone(ZoneId.of("Europe/Warsaw")))
}

fun getGroupColor(role : Int, isUsingDarkTheme : Boolean = true) : Int = when(role) {
0 -> Color.parseColor("#339933")
1 -> Color.parseColor("#ff5917")
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/entry_comment_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<TextView
android:id="@+id/quoteTextView"
style="@style/MikroButton"
android:background="?attr/voteButtonStatelist"
android:drawableStart="?attr/markdownFormatQuote"
app:layout_constraintStart_toEndOf="@id/replyTextView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<io.github.feelfreelinux.wykopmobilny.ui.widgets.buttons.PlusVoteButton
android:id="@+id/voteButton"
style="@style/MikroButton"
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/entry_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<TextView
android:id="@+id/replyTextView"
style="@style/MikroButton"
android:background="?attr/voteButtonStatelist"
android:drawableStart="?attr/replyDrawable"
app:layout_constraintStart_toEndOf="@id/favoriteButton"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<io.github.feelfreelinux.wykopmobilny.ui.widgets.buttons.FavoriteButton
android:id="@+id/favoriteButton"
style="@style/MikroButton"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<string name="sortby_newest">Najnowsze komentarze</string>
<string name="sortby_best">Najlepsze komentarze</string>
<string name="sortby_oldest">Najstarsze komentarze</string>
<string name="notifications_directed">Do mnie</string>

<string name="upcoming_sortby_comments">Komentowane</string>
<string name="upcoming_sortby_votes">Wykopywane</string>
Expand Down

0 comments on commit 3fc26be

Please sign in to comment.