From d3c3f05e436097314b6da63c47e288ef5f6e8248 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 9 Aug 2016 15:48:16 +0800 Subject: [PATCH] improved link click --- build.gradle | 2 +- .../library/twitter/TwitterUpload.java | 6 +- .../twidere/task/twitter/UpdateStatusTask.kt | 29 ++-- .../org/mariotaku/twidere/util/Utils.java | 17 +- .../twidere/view/TimelineContentTextView.java | 109 ------------- .../twidere/view/holder/StatusViewHolder.kt | 4 +- .../adapter/ParcelableActivitiesAdapter.kt | 2 +- .../twidere/app/TwidereApplication.kt | 0 .../twidere/fragment/UserFragment.kt | 10 +- .../twidere/loader/ConversationLoader.kt | 0 .../loader/DummyParcelableStatusesLoader.kt | 0 .../twidere/loader/GroupTimelineLoader.kt | 0 .../loader/IntentExtrasStatusesLoader.kt | 0 .../twidere/loader/MediaTimelineLoader.kt | 0 .../loader/MicroBlogAPIStatusesLoader.kt | 0 .../loader/ParcelableStatusesLoader.kt | 0 .../twidere/loader/ParcelableUserLoader.kt | 0 .../twidere/loader/PublicTimelineLoader.kt | 0 .../twidere/loader/TweetSearchLoader.kt | 0 .../twidere/loader/UserFavoritesLoader.kt | 0 .../twidere/loader/UserListTimelineLoader.kt | 0 .../twidere/loader/UserMentionsLoader.kt | 0 .../twidere/loader/UserTimelineLoader.kt | 0 .../menu/SupportStatusShareProvider.kt | 0 .../org/mariotaku/twidere/model/Response.kt | 0 .../mariotaku/twidere/model/SingleResponse.kt | 0 .../mariotaku/twidere/model/SupportTabSpec.kt | 0 .../twidere/view/TimelineContentTextView.kt | 145 ++++++++++++++++++ .../holder/ActivityTitleSummaryViewHolder.kt | 0 29 files changed, 178 insertions(+), 146 deletions(-) delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/TimelineContentTextView.java rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/app/TwidereApplication.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/ConversationLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/GroupTimelineLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/MediaTimelineLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/ParcelableUserLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/PublicTimelineLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/TweetSearchLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/UserFavoritesLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/UserListTimelineLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/UserMentionsLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/loader/UserTimelineLoader.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/menu/SupportStatusShareProvider.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/model/Response.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/model/SingleResponse.kt (100%) rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/model/SupportTabSpec.kt (100%) create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt rename twidere/src/main/{java => kotlin}/org/mariotaku/twidere/view/holder/ActivityTitleSummaryViewHolder.kt (100%) diff --git a/build.gradle b/build.gradle index e29ec2fc3..bbdbc9352 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ subprojects { if (project.hasProperty('android')) { android { compileSdkVersion 24 - buildToolsVersion '24.0.0' + buildToolsVersion '24.0.1' lintOptions { abortOnError false diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterUpload.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterUpload.java index c9c629115..d93eec65c 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterUpload.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterUpload.java @@ -28,6 +28,8 @@ import org.mariotaku.restfu.annotation.method.POST; import org.mariotaku.restfu.annotation.param.KeyValue; import org.mariotaku.restfu.annotation.param.Param; import org.mariotaku.restfu.annotation.param.Params; +import org.mariotaku.restfu.annotation.param.Queries; +import org.mariotaku.restfu.annotation.param.Query; import org.mariotaku.restfu.annotation.param.Raw; import org.mariotaku.restfu.http.BodyType; import org.mariotaku.restfu.http.mime.Body; @@ -59,8 +61,8 @@ public interface TwitterUpload { MediaUploadResponse finalizeUploadMedia(@Param("media_id") String mediaId) throws MicroBlogException; @GET("/media/upload.json") - @Params(@KeyValue(key = "command", value = "STATUS")) - MediaUploadResponse getUploadMediaStatus(@Param("media_id") String mediaId) throws MicroBlogException; + @Queries(@KeyValue(key = "command", value = "STATUS")) + MediaUploadResponse getUploadMediaStatus(@Query("media_id") String mediaId) throws MicroBlogException; @POST("/media/metadata/create.json") ResponseCode createMetadata(@Raw NewMediaMetadata metadata) throws MicroBlogException; diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt index 417afbd31..a0d7085cd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt @@ -454,24 +454,21 @@ class UpdateStatusTask(internal val context: Context, internal val stateCallback upload.appendUploadMedia(response.id, segmentIndex, bulk) } response = upload.finalizeUploadMedia(response.id) - run { - var info: MediaUploadResponse.ProcessingInfo? = response.processingInfo - while (info != null && shouldWaitForProcess(info)) { - val checkAfterSecs = info.checkAfterSecs - if (checkAfterSecs <= 0) { - break - } - try { - Thread.sleep(TimeUnit.SECONDS.toMillis(checkAfterSecs)) - } catch (e: InterruptedException) { - break - } - - response = upload.getUploadMediaStatus(response.id) - info = response.processingInfo + var info: MediaUploadResponse.ProcessingInfo? = response.processingInfo + while (info != null && shouldWaitForProcess(info)) { + val checkAfterSecs = info.checkAfterSecs + if (checkAfterSecs <= 0) { + break } + try { + Thread.sleep(TimeUnit.SECONDS.toMillis(checkAfterSecs)) + } catch (e: InterruptedException) { + break + } + + response = upload.getUploadMediaStatus(response.id) + info = response.processingInfo } - val info = response.processingInfo if (info != null && MediaUploadResponse.ProcessingInfo.State.FAILED == info.state) { val exception = MicroBlogException() val errorInfo = info.error diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index a195f7175..a912abe04 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -214,7 +214,6 @@ import edu.tsinghua.hotmobi.model.NotificationEvent; import static org.mariotaku.twidere.provider.TwidereDataStore.DIRECT_MESSAGES_URIS; import static org.mariotaku.twidere.provider.TwidereDataStore.STATUSES_URIS; import static org.mariotaku.twidere.util.TwidereLinkify.PATTERN_TWITTER_PROFILE_IMAGES; -import static org.mariotaku.twidere.util.TwidereLinkify.TWITTER_PROFILE_IMAGES_AVAILABLE_SIZES; @SuppressWarnings("unused") public final class Utils implements Constants { @@ -1335,8 +1334,9 @@ public final class Utils implements Constants { public static String getOriginalTwitterProfileImage(final String url) { if (url == null) return null; - if (PATTERN_TWITTER_PROFILE_IMAGES.matcher(url).matches()) - return replaceLast(url, "_" + TWITTER_PROFILE_IMAGES_AVAILABLE_SIZES, ""); + final Matcher matcher = PATTERN_TWITTER_PROFILE_IMAGES.matcher(url); + if (matcher.matches()) + return matcher.replaceFirst("$1$2/profile_images/$3/$4$6"); return url; } @@ -1496,8 +1496,10 @@ public final class Utils implements Constants { public static String getTwitterProfileImageOfSize(final String url, final String size) { if (url == null) return null; - if (PATTERN_TWITTER_PROFILE_IMAGES.matcher(url).matches()) - return replaceLast(url, "_" + TWITTER_PROFILE_IMAGES_AVAILABLE_SIZES, String.format("_%s", size)); + final Matcher matcher = PATTERN_TWITTER_PROFILE_IMAGES.matcher(url); + if (matcher.matches()) { + return matcher.replaceFirst("$1$2/profile_images/$3/$4_" + size + "$6"); + } return url; } @@ -1711,11 +1713,6 @@ public final class Utils implements Constants { return top - actionBarHeight; } - public static String replaceLast(final String text, final String regex, final String replacement) { - if (text == null || regex == null || replacement == null) return text; - return text.replaceFirst("(?s)" + regex + "(?!.*?" + regex + ")", replacement); - } - public static void restartActivity(final Activity activity) { if (activity == null) return; final int enterAnim = android.R.anim.fade_in; diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/TimelineContentTextView.java b/twidere/src/main/java/org/mariotaku/twidere/view/TimelineContentTextView.java deleted file mode 100644 index 5fe171fa8..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/TimelineContentTextView.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.view; - -import android.content.Context; -import android.support.v7.widget.AppCompatTextView; -import android.text.Layout; -import android.text.Spannable; -import android.text.method.LinkMovementMethod; -import android.text.method.MovementMethod; -import android.text.style.ClickableSpan; -import android.util.AttributeSet; -import android.view.MotionEvent; - -import org.mariotaku.twidere.util.EmojiSupportUtils; - -/** - * Returns true when not clicking links - * Created by mariotaku on 15/11/20. - */ -public class TimelineContentTextView extends AppCompatTextView { - private boolean mFirstNotLink; - - public TimelineContentTextView(Context context) { - super(context); - EmojiSupportUtils.initForTextView(this); - } - - public TimelineContentTextView(Context context, AttributeSet attrs) { - super(context, attrs); - EmojiSupportUtils.initForTextView(this); - } - - public TimelineContentTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - EmojiSupportUtils.initForTextView(this); - } - - @Override - public boolean dispatchTouchEvent(MotionEvent event) { - // FIXME simple workaround to https://code.google.com/p/android/issues/detail?id=191430 - // Android clears TextView when setText(), so setText before touch - if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isTextSelectable()) { - if (getSelectionEnd() != getSelectionStart()) { - final CharSequence text = getText(); - setText(null); - setText(text); - } - } - return super.dispatchTouchEvent(event); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (isTextSelectable()) { - return super.onTouchEvent(event); - } - switch (event.getActionMasked()) { - case MotionEvent.ACTION_DOWN: { - Layout layout = getLayout(); - final float x = event.getX() - getPaddingLeft() + getScrollX(); - final float y = event.getY() - getPaddingTop() + getScrollY(); - final int line = layout.getLineForVertical(Math.round(y)); - int offset = layout.getOffsetForHorizontal(line, x); - final CharSequence text = getText(); - if (text instanceof Spannable) { - final ClickableSpan[] spans = ((Spannable) text).getSpans(offset, offset, ClickableSpan.class); - mFirstNotLink = spans.length == 0; - } else { - mFirstNotLink = true; - } - break; - } - case MotionEvent.ACTION_UP: { - mFirstNotLink = false; - break; - } - } - if (mFirstNotLink) { - super.onTouchEvent(event); - return false; - } else { - return super.onTouchEvent(event); - } - } - - @Override - protected MovementMethod getDefaultMovementMethod() { - return LinkMovementMethod.getInstance(); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.kt b/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.kt index e22f604a5..cda0d03f6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.kt +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.kt @@ -606,8 +606,8 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View) val holder = holderRef.get() ?: return false val listener = holder.statusClickListener ?: return false val position = holder.layoutPosition - when (v.id) { - R.id.itemContent -> { + when (v) { + holder.itemContent -> { if (!holder.isCardActionsShown) { holder.showCardActions() return true diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.kt index cb431290c..cdfda00d9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.kt @@ -399,7 +399,7 @@ class ParcelableActivitiesAdapter( } override fun onStatusLongClick(holder: IStatusViewHolder, position: Int): Boolean { - return false + return true } override fun onUserProfileClick(holder: IStatusViewHolder, position: Int) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index d7ad7bb9b..e137bb600 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -526,7 +526,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener } else { lm.restartLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks) } - if (accountKey == null || userKey == null && screenName == null) { + if (userKey == null && screenName == null) { cardContent!!.visibility = View.GONE errorContainer!!.visibility = View.GONE } @@ -625,7 +625,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener userFragmentView.setWindowInsetsListener { left, top, right, bottom -> - profileContentContainer!!.setPadding(0, top, 0, 0) + profileContentContainer.setPadding(0, top, 0, 0) profileBannerSpace.statusBarHeight = top if (profileBannerSpace.toolbarHeight == 0) { @@ -636,13 +636,13 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener profileBannerSpace.toolbarHeight = toolbarHeight } } - profileContentContainer!!.setOnSizeChangedListener { view, w, h, oldw, oldh -> + profileContentContainer.setOnSizeChangedListener { view, w, h, oldw, oldh -> val toolbarHeight = toolbar.measuredHeight - userProfileDrawer!!.setPadding(0, toolbarHeight, 0, 0) + userProfileDrawer.setPadding(0, toolbarHeight, 0, 0) profileBannerSpace.toolbarHeight = toolbarHeight } - userProfileDrawer!!.setDrawerCallback(this) + userProfileDrawer.setDrawerCallback(this) pagerAdapter = SupportTabsAdapter(activity, childFragmentManager) diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/ConversationLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/ConversationLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/GroupTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupTimelineLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/GroupTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupTimelineLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/MediaTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaTimelineLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/MediaTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaTimelineLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableUserLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUserLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableUserLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUserLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/PublicTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/PublicTimelineLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/PublicTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/PublicTimelineLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/TweetSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/TweetSearchLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserFavoritesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/UserFavoritesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListTimelineLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/UserListTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListTimelineLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserMentionsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserMentionsLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/UserMentionsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserMentionsLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserTimelineLoader.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/loader/UserTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserTimelineLoader.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/menu/SupportStatusShareProvider.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/menu/SupportStatusShareProvider.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/menu/SupportStatusShareProvider.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/menu/SupportStatusShareProvider.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/Response.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/Response.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/model/Response.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/model/Response.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/SingleResponse.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/SingleResponse.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/model/SingleResponse.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/model/SingleResponse.kt diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/SupportTabSpec.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/SupportTabSpec.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/model/SupportTabSpec.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/model/SupportTabSpec.kt diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt new file mode 100644 index 000000000..22e3db205 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TimelineContentTextView.kt @@ -0,0 +1,145 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.support.v7.widget.AppCompatTextView +import android.text.Spannable +import android.text.method.MovementMethod +import android.text.style.ClickableSpan +import android.util.AttributeSet +import android.view.KeyEvent +import android.view.MotionEvent +import android.widget.TextView +import org.mariotaku.twidere.util.EmojiSupportUtils + +/** + * Returns true when not clicking links + * Created by mariotaku on 15/11/20. + */ +class TimelineContentTextView : AppCompatTextView { + + constructor(context: Context) : super(context) { + EmojiSupportUtils.initForTextView(this) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + EmojiSupportUtils.initForTextView(this) + } + + constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { + EmojiSupportUtils.initForTextView(this) + } + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + // FIXME simple workaround to https://code.google.com/p/android/issues/detail?id=191430 + // Android clears TextView when setText(), so setText before touch + if (event.actionMasked == MotionEvent.ACTION_DOWN && isTextSelectable) { + if (selectionEnd != selectionStart) { + val text = text + setText(null) + setText(text) + } + } + return super.dispatchTouchEvent(event) + } + + override fun onTouchEvent(event: MotionEvent): Boolean { + if (isTextSelectable) { + return super.onTouchEvent(event) + } + return super.onTouchEvent(event) + } + + override fun getDefaultMovementMethod(): MovementMethod { + return InternalMovementMethod() + } + + override fun setClickable(clickable: Boolean) { + super.setClickable(false) + } + + override fun setLongClickable(longClickable: Boolean) { + super.setLongClickable(false) + } + + internal class InternalMovementMethod : MovementMethod { + private var targetSpan: ClickableSpan? = null + + override fun initialize(widget: TextView, text: Spannable) { + + } + + override fun onKeyDown(widget: TextView, text: Spannable, keyCode: Int, keyEvent: KeyEvent): Boolean { + return false + } + + override fun onKeyUp(widget: TextView, text: Spannable, keyCode: Int, keyEvent: KeyEvent): Boolean { + return false + } + + override fun onKeyOther(widget: TextView, text: Spannable, keyEvent: KeyEvent): Boolean { + return false + } + + override fun onTakeFocus(widget: TextView, text: Spannable, direction: Int) { + + } + + override fun onTrackballEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean { + return false + } + + override fun onTouchEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean { + when (event.actionMasked) { + MotionEvent.ACTION_DOWN -> { + val layout = widget.layout + val x = event.x - widget.paddingLeft + widget.scrollX + val y = event.y - widget.paddingTop + widget.scrollY + val line = layout.getLineForVertical(Math.round(y)) + val offset = layout.getOffsetForHorizontal(line, x) + if (x <= layout.getLineWidth(line)) { + targetSpan = text.getSpans(offset, offset, ClickableSpan::class.java).firstOrNull() + } else { + targetSpan = null + } + } + MotionEvent.ACTION_UP -> { + targetSpan?.onClick(widget) + val handled = targetSpan != null + targetSpan = null + return handled + } + MotionEvent.ACTION_CANCEL -> { + targetSpan = null + } + } + return targetSpan != null + } + + override fun onGenericMotionEvent(widget: TextView, text: Spannable, event: MotionEvent): Boolean { + return false + } + + override fun canSelectArbitrarily(): Boolean { + return false + } + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/ActivityTitleSummaryViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/ActivityTitleSummaryViewHolder.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/view/holder/ActivityTitleSummaryViewHolder.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/ActivityTitleSummaryViewHolder.kt