Skip to content

Commit

Permalink
Fatal bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Jan 29, 2018
1 parent 909403c commit aac69e2
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 34 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 24
versionName "0.5.3.1"
versionCode 25
versionName "0.5.3.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 @@ -10,7 +10,6 @@ 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.URLClickedListener
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
Expand All @@ -19,15 +18,10 @@ 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), URLClickedListener {

override fun handleUrl(url: String) {
linkHandlerApi.handleUrl(url)
}
val navigatorApi: NewNavigatorApi) : RecyclerView.ViewHolder(view) {

fun bindView(message: PMMessage) {
flipMessage(message.isSentFromUser)

view.apply {
val prettyDate = message.date.toPrettyDate()
date.text = prettyDate
Expand All @@ -36,7 +30,7 @@ class PMMessageViewHolder(val view: View,
date.text = context.getString(R.string.date_with_user_app, prettyDate, message.app)
}

body.prepareBody(message.body, this@PMMessageViewHolder)
body.prepareBody(message.body, { linkHandlerApi.handleUrl(it) })
embedImage.forceDisableMinimizedMode = true
embedImage.setEmbed(message.embed, settingsPreferencesApi, navigatorApi)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class MainNavigationActivity : BaseActivity(), MainNavigationView, NavigationVie
.setButtonDoNotShowAgain(R.string.do_not_show_again)
.setButtonUpdate(R.string.update)
.start()

if (settingsApi.showNotifications) {
// Schedules notification service
WykopNotificationsJob.schedule(settingsApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.feelfreelinux.wykopmobilny.base.Schedulers
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Entry
import io.github.feelfreelinux.wykopmobilny.ui.modules.NewNavigatorApi
import io.github.feelfreelinux.wykopmobilny.utils.ClipboardHelperApi
import io.github.feelfreelinux.wykopmobilny.utils.printout
import io.github.feelfreelinux.wykopmobilny.utils.textview.removeHtml
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.WykopLinkHandlerApi

Expand Down Expand Up @@ -82,6 +83,7 @@ class EntryPresenter(val schedulers: Schedulers,
}

fun handleLink(url : String) {
printout("DDD")
linkHandler.handleUrl(url, false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import io.github.feelfreelinux.wykopmobilny.utils.api.getGroupColor
import io.github.feelfreelinux.wykopmobilny.utils.appendNewSpan
import io.github.feelfreelinux.wykopmobilny.utils.getActivityContext
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.textview.URLClickedListener
import io.github.feelfreelinux.wykopmobilny.utils.textview.prepareBody
import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi
import kotlinx.android.synthetic.main.dialog_voters.view.*
import kotlinx.android.synthetic.main.entry_layout.view.*
import kotlinx.android.synthetic.main.entry_menu_bottomsheet.view.*

class EntryWidget(context: Context, attrs: AttributeSet) : CardView(context, attrs), EntryView, URLClickedListener {
class EntryWidget(context: Context, attrs: AttributeSet) : CardView(context, attrs), EntryView {

private lateinit var userManagerApi: UserManagerApi
private lateinit var presenter: EntryPresenter
Expand Down Expand Up @@ -115,8 +114,7 @@ class EntryWidget(context: Context, attrs: AttributeSet) : CardView(context, att
private fun setupBody() {
if (entry.body.isNotEmpty()) {
entryContentTextView.isVisible = true
entryContentTextView.prepareBody(entry.body, this)
if (shouldEnableClickListener) entryContentTextView.setOnClickListener { presenter.openDetails(entry.embed?.isRevealed ?: false) }
entryContentTextView.prepareBody(entry.body, { presenter.handleLink(it) }, { if (shouldEnableClickListener) presenter.openDetails(true) })
} else entryContentTextView.isVisible = false

if (entry.survey != null) {
Expand All @@ -129,10 +127,6 @@ class EntryWidget(context: Context, attrs: AttributeSet) : CardView(context, att
survey.setSurvey(surveyData, userManagerApi)
}

override fun handleUrl(url: String) {
presenter.handleLink(url)
}

override fun showErrorDialog(e: Throwable) =
context.showExceptionDialog(e)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlinx.android.synthetic.main.dialog_voters.view.*
import kotlinx.android.synthetic.main.entry_comment_layout.view.*
import kotlinx.android.synthetic.main.entry_comment_menu_bottomsheet.view.*

class CommentWidget : CardView, CommentView, URLClickedListener {
class CommentWidget : CardView, CommentView {
constructor(context: Context) : super(context)

constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
Expand Down Expand Up @@ -103,14 +103,10 @@ class CommentWidget : CardView, CommentView, URLClickedListener {
replyTextView.setOnClickListener { addReceiver() }
if (comment.body.isNotEmpty()) {
entryContentTextView.isVisible = true
entryContentTextView.prepareBody(comment.body, this)
entryContentTextView.prepareBody(comment.body, { presenter.handleLink(it) })
} else entryContentTextView.isVisible = false
}

override fun handleUrl(url: String) {
presenter.handleLink(url)
}

fun addReceiver() {
addReceiverListener?.invoke(comment.author)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,20 @@ class LinkWidget(context: Context, attrs: AttributeSet) : CardView(context, attr
private fun setupHeader() {
dateTextView.text = link.date.toPrettyDate()
hotBadgeStrip.isVisible = link.isHot
avatarView.setAuthor(link.author!!)
val author = link.author
if (author != null) {
avatarView.isVisible = true
userTextView.isVisible = true
avatarView.setAuthor(link.author!!)
userTextView.text = link.author!!.nick
userTextView.setTextColor(context.getGroupColor(link.author!!.group))
} else {
avatarView.isVisible = false
userTextView.isVisible = false
}
dateTextView.text = link.date.toPrettyDate()
urlTextView.text = URL(link.sourceUrl).host.removePrefix("www.")
userTextView.text = link.author!!.nick
userTextView.setTextColor(context.getGroupColor(link.author!!.group))

tagsTextView.prepareBody(link.tags.convertToTagsHtml(), this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.view.Window;
import android.widget.TextView;

import static io.github.feelfreelinux.wykopmobilny.utils.LogHelperKt.printout;

/**
* Handles URL clicks on TextViews. Unlike the default implementation, this:
* <p>
Expand All @@ -35,6 +37,7 @@ public class BetterLinkMovementMethod extends LinkMovementMethod {
private static final int LINKIFY_NONE = -2;

private OnLinkClickListener onLinkClickListener;
private OnTextClickListener onTextClickListener;
private OnLinkLongClickListener onLinkLongClickListener;
private final RectF touchedLineBounds = new RectF();
private boolean isUrlHighlighted;
Expand All @@ -52,6 +55,10 @@ public interface OnLinkClickListener {
boolean onClick(TextView textView, String url);
}

public interface OnTextClickListener {
void onClick();
}

public interface OnLinkLongClickListener {
/**
* @param textView The TextView on which a long-click was registered.
Expand Down Expand Up @@ -166,6 +173,16 @@ public BetterLinkMovementMethod setOnLinkClickListener(OnLinkClickListener click
return this;
}

public BetterLinkMovementMethod setOnTextClickListener(OnTextClickListener clickListener) {
if (this == singleInstance) {
throw new UnsupportedOperationException("Setting a click listener on the instance returned by getInstance() is not supported to avoid memory " +
"leaks. Please use newInstance() or any of the linkify() methods instead.");
}

this.onTextClickListener = clickListener;
return this;
}

/**
* Set a listener that will get called whenever any link is clicked on the TextView.
*/
Expand Down Expand Up @@ -240,8 +257,12 @@ public void onTimerReached() {

case MotionEvent.ACTION_UP:
// Register a click only if the touch started and ended on the same URL.
if (!wasLongPressRegistered && touchStartedOverALink && clickableSpanUnderTouch == clickableSpanUnderTouchOnActionDown) {
dispatchUrlClick(textView, clickableSpanUnderTouch);
if (!wasLongPressRegistered) {
if (touchStartedOverALink && clickableSpanUnderTouch == clickableSpanUnderTouchOnActionDown) {
dispatchUrlClick(textView, clickableSpanUnderTouch);
} else {
onTextClickListener.onClick();
}
}
cleanupOnTouchUp(textView);

Expand Down Expand Up @@ -386,6 +407,7 @@ 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface URLClickedListener {
fun handleUrl(url : String)
}

class SpoilerAwareLinkSpan(val url : String) : URLSpan(url) {
class ClickableSpanNoUnderline(val url : String) : URLSpan(url) {
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fun TextView.prepareBody(html: String, listener : URLClickedListener) {
val method = BetterLinkMovementMethod.linkifyHtml(this)
method.setOnLinkClickListener({
textView, url ->
textView.isEnabled = false
if (url.startsWith("spoiler:")) {
val text = url.substringAfter("spoiler:")
context.createAlertBuilder().apply {
Expand All @@ -21,7 +20,29 @@ fun TextView.prepareBody(html: String, listener : URLClickedListener) {
create().show()
}
} else listener.handleUrl(url)
textView.isEnabled = true
false
true
})
}

fun TextView.prepareBody(html: String, urlClickListener : (String) -> Unit, clickListener : (() -> Unit)? = null) {
text = SpannableStringBuilder(html.toSpannable())
val method = BetterLinkMovementMethod.linkifyHtml(this)
clickListener?.let {
method.setOnTextClickListener {
clickListener()
}
}
method.setOnLinkClickListener({
_, url ->
if (url.startsWith("spoiler:")) {
val text = url.substringAfter("spoiler:")
context.createAlertBuilder().apply {
setTitle("Spoiler")
setMessage(URLDecoder.decode(text, "UTF-8"))
setPositiveButton(android.R.string.ok, null)
create().show()
}
} else urlClickListener(url)
true
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.modules.links.linkdetails.LinkDet
import io.github.feelfreelinux.wykopmobilny.ui.modules.mikroblog.entry.EntryActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.pm.conversation.ConversationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.tag.TagActivity
import io.github.feelfreelinux.wykopmobilny.utils.printout
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.linkparser.ConversationLinkParser
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.linkparser.EntryLinkParser
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.linkparser.LinkParser
Expand Down Expand Up @@ -69,6 +70,7 @@ class WykopLinkHandler(val context: Activity, private val navigatorApi: NewNavig
}

private fun handleLink(url: String, refreshNotifications : Boolean) {

val intent = getLinkIntent(url, context)
if (intent != null) {
if (refreshNotifications) context.startActivityForResult(intent, NewNavigator.STARTED_FROM_NOTIFICATIONS_CODE)
Expand Down

0 comments on commit aac69e2

Please sign in to comment.