Unverified Commit 68cdb880 authored by Andrew Dobis's avatar Andrew Dobis Committed by GitHub

Added double tap likes (#211)

* fixed visual dark mode bug

* added double tap liking

* fixed conflict with sensitive media

* removed old test that is no longer relevant
parent 6a30b1a2
......@@ -34,6 +34,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.Timeout
import org.junit.runner.RunWith
import kotlin.concurrent.thread
@RunWith(AndroidJUnit4::class)
......@@ -561,23 +562,6 @@ class MockedServerTest {
onView(second(withId(R.id.sensitiveWarning))).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test
fun performClickOnPostPicture() {
onView(withId(R.id.list)).perform(scrollToPosition<PostViewHolder>(1))
Thread.sleep(1000)
onView(second(withId(R.id.sensitiveWarning))).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
Thread.sleep(1000)
onView(withId(R.id.list))
.perform(actionOnItemAtPosition<PostViewHolder>
(1, clickChildViewWithId(R.id.postPicture)))
Thread.sleep(1000)
onView(second(withId(R.id.sensitiveWarning))).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test
fun performClickOnSensitiveWarningTabs() {
......@@ -596,20 +580,32 @@ class MockedServerTest {
}
@Test
fun performClickOnPostPictureTabs() {
onView(withId(R.id.list)).perform(scrollToPosition<PostViewHolder>(0))
fun doubleTapLikerWorks() {
ActivityScenario.launch(MainActivity::class.java)
Thread.sleep(1000)
onView(first(withId(R.id.sensitiveWarning))).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
Thread.sleep(1000)
//Get initial like count
val likes = getText(first(withId(R.id.nlikes)))
val nlikes = likes!!.split(" ")[0].toInt()
//Remove sensitive media warning
onView(withId(R.id.list))
.perform(actionOnItemAtPosition<PostViewHolder>
(0, clickChildViewWithId(R.id.sensitiveWarning)))
Thread.sleep(100)
//Like the post
onView(withId(R.id.list))
.perform(actionOnItemAtPosition<PostViewHolder>
(0, clickChildViewWithId(R.id.postPicture)))
Thread.sleep(1000)
onView(withId(R.id.list))
.perform(actionOnItemAtPosition<PostViewHolder>
(0, clickChildViewWithId(R.id.postPicture)))
//...
Thread.sleep(100)
onView(first(withId(R.id.sensitiveWarning))).check(matches(withEffectiveVisibility(Visibility.GONE)))
//Profit
onView(first(withId(R.id.nlikes))).check(matches((withText("${nlikes + 1} Likes"))))
}
}
......@@ -50,6 +50,9 @@ class PostFragment : Fragment() {
current_status?.activateCommenter(holder, api, "Bearer $accessToken")
current_status?.showComments(holder, api, "Bearer $accessToken")
//Activate double tap liking
current_status?.activateDoubleTapLiker(holder, api, "Bearer $accessToken", current_status.favourited)
return root
}
......
......@@ -120,6 +120,9 @@ open class PostsFeedFragment : FeedFragment<Status, PostViewHolder>() {
//Activate liker
post.activateLiker(holder, api, credential, post.favourited)
//Activate double tap liking
post.activateDoubleTapLiker(holder, api, credential, post.favourited)
//Show comments
post.showComments(holder, api, credential)
......@@ -165,4 +168,5 @@ class PostViewHolder(val postView: View, val context: android.content.Context) :
val viewComment : TextView = postView.findViewById(R.id.ViewComments)
val postDate : TextView = postView.findViewById(R.id.postDate)
val postDomain : TextView = postView.findViewById(R.id.postDomain)
val sensitiveW : TextView = postView.findViewById(R.id.sensitiveWarning)
}
......@@ -5,6 +5,7 @@ import android.content.Context
import android.graphics.ColorMatrixColorFilter
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.os.Handler
import android.text.Spanned
import android.text.method.LinkMovementMethod
import android.view.View
......@@ -42,7 +43,7 @@ import kotlinx.android.synthetic.main.post_fragment.view.*
import java.io.Serializable
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import kotlin.collections.ArrayList
/*
......@@ -297,6 +298,37 @@ data class Status(
}
}
fun activateDoubleTapLiker(
holder : PostViewHolder,
api: PixelfedAPI,
credential: String,
isLiked: Boolean
) {
holder.apply {
var clicked = false
postPic.setOnClickListener {
//Check that the post isn't hidden
if(sensitiveW.visibility == GONE) {
//Check for double click
if(clicked) {
if (isLiked) {
// Button is active, unlike
unLikePostCall(holder, api, credential, this@Status)
} else {
// Button is inactive, like
likePostCall(holder, api, credential, this@Status)
}
} else {
clicked = true
//Reset clicked to false after 500ms
postPic.handler.postDelayed(fun() { clicked = false }, 500)
}
}
}
}
}
fun activateLiker(
holder : PostViewHolder,
api: PixelfedAPI,
......
......@@ -115,6 +115,9 @@ abstract class PostUtils {
//Update shown like count and internal like toggle
holder.nlikes.text = resp.getNLikes(holder.context)
holder.liker.isChecked = resp.favourited
//Notify the user, that the action was successful
Toast.makeText(holder.context, holder.context.getString(R.string.liked_post), Toast.LENGTH_SHORT).show()
} else {
Log.e("RESPONSE_CODE", response.code().toString())
holder.liker.isChecked = false
......@@ -144,6 +147,9 @@ abstract class PostUtils {
//Update shown like count and internal like toggle
holder.nlikes.text = resp.getNLikes(holder.context)
holder.liker.isChecked = resp.favourited
//Notify the user, that the action was successful
Toast.makeText(holder.context, holder.context.getString(R.string.unliked_post), Toast.LENGTH_SHORT).show()
} else {
Log.e("RESPONSE_CODE", response.code().toString())
holder.liker.isChecked = true
......
......@@ -62,6 +62,9 @@
<string name="image_download_failed">Download has failed, please try again</string>
<string name="image_download_downloading">Downloading…</string>
<string name="image_download_success">Image downloaded successfully</string>
<!-- Post action feedback -->
<string name="liked_post">Post successfully liked!</string>
<string name="unliked_post">Post successfully unliked</string>
<!-- Post attributes -->
<string name="no_description">No description</string>
<string name="likes">"%1$s Likes"</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment