deep link bug fix

This commit is contained in:
nuclearfog 2020-06-10 21:45:45 +02:00
parent 52a0a9b455
commit 51031dcd44
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
3 changed files with 49 additions and 16 deletions

View File

@ -67,7 +67,7 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
public static final String KEY_TWEET_ID = "tweetID";
public static final String KEY_TWEET_NAME = "username";
public static final Pattern linkPattern = Pattern.compile("https://twitter.com/\\w+/status/\\d+");
public static final Pattern LINK_PATTERN = Pattern.compile("https://twitter.com/\\w+/status/\\d+");
private TextView tweet_api, tweetDate, tweetText, scrName, usrName, tweetLocName;
private Button rtwButton, favButton, replyName, tweetLocGPS;
@ -315,17 +315,25 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
@Override
public void onLinkClick(String tag) {
if (linkPattern.matcher(tag).matches()) {
String name = tag.substring(20, tag.indexOf('/', 20));
long id = Long.parseLong(tag.substring(tag.lastIndexOf('/') + 1));
String shortLink = tag;
int cut = shortLink.indexOf('?');
if (cut > 0) {
shortLink = shortLink.substring(0, cut);
}
if (LINK_PATTERN.matcher(shortLink).matches()) {
String name = shortLink.substring(20, shortLink.indexOf('/', 20));
long id = Long.parseLong(shortLink.substring(shortLink.lastIndexOf('/') + 1));
Intent intent = new Intent(this, TweetDetail.class);
intent.putExtra(KEY_TWEET_ID, id);
intent.putExtra(KEY_TWEET_NAME, name);
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tag));
Uri link = Uri.parse(tag);
Intent intent = new Intent(Intent.ACTION_VIEW, link);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, R.string.error_connection_failed, LENGTH_SHORT).show();
}
}
}

View File

@ -55,6 +55,9 @@ import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_TYPE;
import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_IMAGE;
import static org.nuclearfog.twidda.activity.MessagePopup.KEY_DM_PREFIX;
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.TwitterList.KEY_USERLIST_OWNER_ID;
import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_ID;
@ -363,17 +366,27 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
@Override
public void onLinkClick(String link) {
if (TweetDetail.linkPattern.matcher(link).matches()) {
public void onLinkClick(String tag) {
String shortLink = tag;
int cut = shortLink.indexOf('?');
if (cut > 0) {
shortLink = shortLink.substring(0, cut);
}
if (LINK_PATTERN.matcher(shortLink).matches()) {
String name = shortLink.substring(20, shortLink.indexOf('/', 20));
long id = Long.parseLong(shortLink.substring(shortLink.lastIndexOf('/') + 1));
Intent intent = new Intent(this, TweetDetail.class);
intent.setData(Uri.parse(link));
intent.putExtra(KEY_TWEET_ID, id);
intent.putExtra(KEY_TWEET_NAME, name);
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
if (intent.resolveActivity(getPackageManager()) != null)
Uri link = Uri.parse(tag);
Intent intent = new Intent(Intent.ACTION_VIEW, link);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
else
} else {
Toast.makeText(this, R.string.error_connection_failed, LENGTH_SHORT).show();
}
}
}

View File

@ -40,6 +40,9 @@ import static android.os.AsyncTask.Status.RUNNING;
import static android.widget.Toast.LENGTH_SHORT;
import static org.nuclearfog.twidda.activity.MessagePopup.KEY_DM_PREFIX;
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.UserProfile.KEY_PROFILE_ID;
public class MessageFragment extends Fragment implements OnRefreshListener, OnItemSelected {
@ -104,14 +107,23 @@ public class MessageFragment extends Fragment implements OnRefreshListener, OnIt
@Override
public void onLinkClick(String link) {
if (getContext() != null && !reload.isRefreshing()) {
if (TweetDetail.linkPattern.matcher(link).matches()) {
public void onLinkClick(String tag) {
if (getContext() != null) {
String shortLink = tag;
int cut = shortLink.indexOf('?');
if (cut > 0) {
shortLink = shortLink.substring(0, cut);
}
if (LINK_PATTERN.matcher(shortLink).matches()) {
String name = shortLink.substring(20, shortLink.indexOf('/', 20));
long id = Long.parseLong(shortLink.substring(shortLink.lastIndexOf('/') + 1));
Intent intent = new Intent(getContext(), TweetDetail.class);
intent.setData(Uri.parse(link));
intent.putExtra(KEY_TWEET_ID, id);
intent.putExtra(KEY_TWEET_NAME, name);
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
Uri link = Uri.parse(tag);
Intent intent = new Intent(Intent.ACTION_VIEW, link);
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
startActivity(intent);
} else {