From 239b60ee810e24757326ae50cdca248caec000b4 Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Sat, 20 Jun 2020 10:49:13 +0200 Subject: [PATCH] added deep link for sharing tweets, layout fix --- .../twidda/activity/SearchPage.java | 4 +- .../twidda/activity/TweetDetail.java | 5 ++- .../twidda/activity/TweetPopup.java | 6 +-- .../twidda/activity/UserProfile.java | 5 ++- .../twidda/backend/LinkContentLoader.java | 41 +++++++++++-------- app/src/main/res/drawable/save_img.xml | 2 +- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/SearchPage.java b/app/src/main/java/org/nuclearfog/twidda/activity/SearchPage.java index 03371751..0e4fdda1 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/SearchPage.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/SearchPage.java @@ -22,7 +22,7 @@ import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.adapter.FragmentAdapter; import org.nuclearfog.twidda.database.GlobalSettings; -import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_PREFIX; +import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_TEXT; /** * Twitter search Activity @@ -98,7 +98,7 @@ public class SearchPage extends AppCompatActivity implements OnTabSelectedListen if (item.getItemId() == R.id.search_tweet) { Intent intent = new Intent(this, TweetPopup.class); if (search.startsWith("#")) - intent.putExtra(KEY_TWEETPOPUP_PREFIX, search); + intent.putExtra(KEY_TWEETPOPUP_TEXT, search + " "); startActivity(intent); } return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java b/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java index 680bbbcd..cfe1f959 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java @@ -53,8 +53,8 @@ import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_ANGIF; import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_IMAGE; import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_VIDEO; import static org.nuclearfog.twidda.activity.SearchPage.KEY_SEARCH_QUERY; -import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_PREFIX; import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_REPLYID; +import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_TEXT; import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_ID; import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_MODE; import static org.nuclearfog.twidda.activity.UserDetail.USERLIST_RETWEETS; @@ -218,9 +218,10 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, if (statusAsync != null && tweet != null && statusAsync.getStatus() != RUNNING) { switch (v.getId()) { case R.id.tweet_answer: + String tweetPrefix = tweet.getUser().getScreenname() + " "; Intent tweetPopup = new Intent(this, TweetPopup.class); tweetPopup.putExtra(KEY_TWEETPOPUP_REPLYID, tweet.getId()); - tweetPopup.putExtra(KEY_TWEETPOPUP_PREFIX, tweet.getUser().getScreenname()); + tweetPopup.putExtra(KEY_TWEETPOPUP_TEXT, tweetPrefix); startActivity(tweetPopup); break; diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/TweetPopup.java b/app/src/main/java/org/nuclearfog/twidda/activity/TweetPopup.java index 886433ca..c533bf82 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/TweetPopup.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/TweetPopup.java @@ -55,7 +55,7 @@ import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_VIDEO; public class TweetPopup extends AppCompatActivity implements OnClickListener, LocationListener, OnDismissListener { public static final String KEY_TWEETPOPUP_REPLYID = "tweet_replyID"; - public static final String KEY_TWEETPOPUP_PREFIX = "tweet_prefix"; + public static final String KEY_TWEETPOPUP_TEXT = "tweet_text"; private enum MediaType { NONE, @@ -110,8 +110,8 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo Bundle param = getIntent().getExtras(); if (param != null) { inReplyId = param.getLong(KEY_TWEETPOPUP_REPLYID, 0); - if (param.containsKey(KEY_TWEETPOPUP_PREFIX)) { - String addition = param.getString(KEY_TWEETPOPUP_PREFIX) + " "; + if (param.containsKey(KEY_TWEETPOPUP_TEXT)) { + String addition = param.getString(KEY_TWEETPOPUP_TEXT); tweetText.append(addition); } } diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java index 55f76b98..29a198ba 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java @@ -58,7 +58,7 @@ import static org.nuclearfog.twidda.activity.SearchPage.KEY_SEARCH_QUERY; import static org.nuclearfog.twidda.activity.TweetDetail.KEY_TWEET_ID; import static org.nuclearfog.twidda.activity.TweetDetail.KEY_TWEET_NAME; import static org.nuclearfog.twidda.activity.TweetDetail.LINK_PATTERN; -import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_PREFIX; +import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_TEXT; import static org.nuclearfog.twidda.activity.TwitterList.KEY_USERLIST_OWNER_ID; import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_ID; import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_MODE; @@ -267,9 +267,10 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, if (user != null && properties != null) { switch (item.getItemId()) { case R.id.profile_tweet: + String tweetPrefix = user.getScreenname() + " "; Intent tweet = new Intent(this, TweetPopup.class); if (user.getId() != settings.getUserId()) - tweet.putExtra(KEY_TWEETPOPUP_PREFIX, user.getScreenname()); + tweet.putExtra(KEY_TWEETPOPUP_TEXT, tweetPrefix); startActivity(tweet); break; diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/LinkContentLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/LinkContentLoader.java index e30fad57..5774ccdb 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/LinkContentLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/LinkContentLoader.java @@ -12,6 +12,7 @@ import org.nuclearfog.twidda.activity.DirectMessage; import org.nuclearfog.twidda.activity.MainActivity; import org.nuclearfog.twidda.activity.SearchPage; import org.nuclearfog.twidda.activity.TweetDetail; +import org.nuclearfog.twidda.activity.TweetPopup; import org.nuclearfog.twidda.activity.TwitterList; import org.nuclearfog.twidda.activity.UserProfile; @@ -21,6 +22,7 @@ import java.util.regex.Pattern; import static org.nuclearfog.twidda.activity.SearchPage.KEY_SEARCH_QUERY; import static org.nuclearfog.twidda.activity.TweetDetail.KEY_TWEET_ID; import static org.nuclearfog.twidda.activity.TweetDetail.KEY_TWEET_NAME; +import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_TEXT; import static org.nuclearfog.twidda.activity.TwitterList.KEY_USERLIST_OWNER_NAME; import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_NAME; @@ -57,15 +59,15 @@ public class LinkContentLoader extends AsyncTask 1) { path = path.substring(1); - if (path.startsWith("home")) { + if (path.equals("home")) { publishProgress(0); - } else if (path.startsWith("i/trends")) { + } else if (path.equals("i/trends") || path.equals("trends") || path.equals("explore")) { publishProgress(1); - } else if (path.startsWith("notifications")) { + } else if (path.equals("notifications")) { publishProgress(2); - } else if (path.startsWith("messages")) { + } else if (path.equals("messages")) { dataHolder = new DataHolder(null, DirectMessage.class); - } else if (path.startsWith("search")) { + } else if (path.equals("search")) { if (link.isHierarchical()) { String search = link.getQueryParameter("q"); if (search != null) { @@ -73,21 +75,24 @@ public class LinkContentLoader extends AsyncTask 0) { - String search = '#' + path.substring(cut + 1); - data.putString(KEY_SEARCH_QUERY, search); - dataHolder = new DataHolder(data, SearchPage.class); + } else if (path.equals("intent/tweet")) { + if (link.isHierarchical()) { + String tweet = link.getQueryParameter("text"); + if (tweet != null) { + data.putString(KEY_TWEETPOPUP_TEXT, tweet); + dataHolder = new DataHolder(data, TweetPopup.class); + } } + } else if (path.startsWith("hashtag/")) { + String search = '#' + path.substring(8); + data.putString(KEY_SEARCH_QUERY, search); + dataHolder = new DataHolder(data, SearchPage.class); } else if (USER_PATH.matcher(path).matches()) { - if (!path.equals("explore")) { - int end = path.indexOf('/'); - if (end > 0) - path = path.substring(0, end); - data.putString(KEY_PROFILE_NAME, path); - dataHolder = new DataHolder(data, UserProfile.class); - } + int end = path.indexOf('/'); + if (end > 0) + path = path.substring(0, end); + data.putString(KEY_PROFILE_NAME, path); + dataHolder = new DataHolder(data, UserProfile.class); } else if (TWEET_PATH.matcher(path).matches()) { String username = '@' + path.substring(0, path.indexOf('/')); long tweetId = Long.parseLong(path.substring(path.lastIndexOf('/') + 1)); diff --git a/app/src/main/res/drawable/save_img.xml b/app/src/main/res/drawable/save_img.xml index 5e4030f4..7c2f066c 100644 --- a/app/src/main/res/drawable/save_img.xml +++ b/app/src/main/res/drawable/save_img.xml @@ -4,6 +4,6 @@ android:viewportWidth="20" android:viewportHeight="20">