fixed behavior when opening tweets and profiles

This commit is contained in:
nuclearfog 2020-12-25 14:55:14 +01:00
parent a370ce10ea
commit e9e2af8baa
No known key found for this signature in database
GPG Key ID: D5490E4A81F97B14
4 changed files with 89 additions and 81 deletions

View File

@ -175,7 +175,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
statusAsync = new TweetAction(this, tweetId);
statusAsync.execute(Action.LD_DB);
} else {
statusAsync = new TweetAction(this, tweet.getId());
statusAsync = new TweetAction(this, tweetId);
statusAsync.execute(Action.LOAD);
setTweet(tweet);
}
@ -208,7 +208,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (tweet != null && statusAsync != null && statusAsync.getStatus() != RUNNING) {
if (tweet != null) {
// Delete tweet option
if (item.getItemId() == R.id.delete_tweet) {
if (!deleteDialog.isShowing()) {
@ -246,71 +246,69 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
@Override
public void onClick(View v) {
if (statusAsync != null && tweet != null && statusAsync.getStatus() != RUNNING) {
// answer to the tweet
if (v.getId() == 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_TEXT, tweetPrefix);
startActivity(tweetPopup);
// answer to the tweet
if (v.getId() == R.id.tweet_answer) {
String tweetPrefix = tweet.getUser().getScreenname() + " ";
Intent tweetPopup = new Intent(this, TweetPopup.class);
tweetPopup.putExtra(KEY_TWEETPOPUP_REPLYID, tweetId);
tweetPopup.putExtra(KEY_TWEETPOPUP_TEXT, tweetPrefix);
startActivity(tweetPopup);
}
// show user retweeting this tweet
else if (v.getId() == R.id.tweet_retweet) {
Intent userList = new Intent(this, UserDetail.class);
userList.putExtra(KEY_USERDETAIL_ID, tweet.getId());
userList.putExtra(KEY_USERDETAIL_MODE, USERLIST_RETWEETS);
startActivity(userList);
}
// open profile of the tweet author
else if (v.getId() == R.id.profileimage_detail) {
if (tweet != null) {
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
profile.putExtra(UserProfile.KEY_PROFILE_DATA, tweet.getUser());
startActivity(profile);
}
// retweet tweet
else if (v.getId() == R.id.tweet_retweet) {
Intent userList = new Intent(this, UserDetail.class);
userList.putExtra(KEY_USERDETAIL_ID, tweet.getId());
userList.putExtra(KEY_USERDETAIL_MODE, USERLIST_RETWEETS);
startActivity(userList);
}
// open replied tweet
else if (v.getId() == R.id.answer_reference_detail) {
if (tweet != null) {
Intent answerIntent = new Intent(getApplicationContext(), TweetActivity.class);
answerIntent.putExtra(KEY_TWEET_ID, tweet.getReplyId());
answerIntent.putExtra(KEY_TWEET_NAME, tweet.getReplyName());
startActivity(answerIntent);
}
// open profile of the tweet author
else if (v.getId() == R.id.profileimage_detail) {
if (tweet != null) {
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
profile.putExtra(UserProfile.KEY_PROFILE_DATA, tweet.getUser());
startActivity(profile);
}
// open tweet location coordinates
else if (v.getId() == R.id.tweet_location_coordinate) {
if (tweet != null) {
Intent locationIntent = new Intent(Intent.ACTION_VIEW);
locationIntent.setData(Uri.parse("geo:" + tweet.getLocationCoordinates()));
try {
startActivity(locationIntent);
} catch (ActivityNotFoundException err) {
Toast.makeText(getApplicationContext(), R.string.error_no_card_app, LENGTH_SHORT).show();
}
}
// open replied tweet
else if (v.getId() == R.id.answer_reference_detail) {
if (tweet != null) {
Intent answerIntent = new Intent(getApplicationContext(), TweetActivity.class);
answerIntent.putExtra(KEY_TWEET_ID, tweet.getReplyId());
answerIntent.putExtra(KEY_TWEET_NAME, tweet.getReplyName());
startActivity(answerIntent);
}
}
// open tweet location coordinates
else if (v.getId() == R.id.tweet_location_coordinate) {
if (tweet != null) {
Intent locationIntent = new Intent(Intent.ACTION_VIEW);
locationIntent.setData(Uri.parse("geo:" + tweet.getLocationCoordinates()));
try {
startActivity(locationIntent);
} catch (ActivityNotFoundException err) {
Toast.makeText(getApplicationContext(), R.string.error_no_card_app, LENGTH_SHORT).show();
}
}
}
// open tweet media
else if (v.getId() == R.id.tweet_media_attach) {
if (tweet != null) {
Intent mediaIntent = new Intent(this, MediaViewer.class);
mediaIntent.putExtra(KEY_MEDIA_LINK, tweet.getMediaLinks());
switch (tweet.getMediaType()) {
case IMAGE:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE);
break;
}
// open tweet media
else if (v.getId() == R.id.tweet_media_attach) {
if (tweet != null) {
Intent mediaIntent = new Intent(this, MediaViewer.class);
mediaIntent.putExtra(KEY_MEDIA_LINK, tweet.getMediaLinks());
switch (tweet.getMediaType()) {
case IMAGE:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE);
break;
case VIDEO:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_VIDEO);
break;
case VIDEO:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_VIDEO);
break;
case GIF:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_ANGIF);
break;
}
startActivity(mediaIntent);
case GIF:
mediaIntent.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_ANGIF);
break;
}
startActivity(mediaIntent);
}
}
}
@ -318,9 +316,9 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
@Override
public boolean onLongClick(View v) {
if (statusAsync != null && statusAsync.getStatus() != RUNNING && tweet != null) {
if (tweet != null && (statusAsync == null || statusAsync.getStatus() != RUNNING)) {
statusAsync = new TweetAction(this, tweet);
// retweet the tweet
// retweet this tweet
if (v.getId() == R.id.tweet_retweet) {
if (tweet.retweeted()) {
statusAsync.execute(Action.UNRETWEET);
@ -347,8 +345,8 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
@Override
public void onConfirm(DialogBuilder.DialogType type) {
if (type == DELETE_TWEET && tweet != null) {
statusAsync = new TweetAction(this, tweet.getId());
if (type == DELETE_TWEET) {
statusAsync = new TweetAction(this, tweetId);
statusAsync.execute(Action.DELETE);
}
}

View File

@ -119,6 +119,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
private FragmentAdapter adapter;
private GlobalSettings settings;
private UserAction profileAsync;
private TextView tweetTabTxt, favorTabTxt, txtUser, txtScrName;
private TextView txtLocation, txtCreated, lnkTxt, bioTxt, follow_back;
@ -129,9 +130,11 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
private TabLayout tabLayout;
private Dialog unfollowConfirm, blockConfirm, muteConfirm;
private UserAction profileAsync;
@Nullable
private Relation relation;
@Nullable
private User user;
private String username;
private long userId;
@ -419,38 +422,43 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
@Override
public void onClick(View v) {
if (user != null && relation != null) {
int viewId = v.getId();
if (viewId == R.id.following) {
if (v.getId() == R.id.following) {
if (user != null && relation != null) {
if (!(user.isLocked() || relation.isBlocked()) || relation.isFriend() || user.getId() == settings.getUserId()) {
Intent following = new Intent(this, UserDetail.class);
following.putExtra(KEY_USERDETAIL_ID, user.getId());
following.putExtra(KEY_USERDETAIL_MODE, USERLIST_FRIENDS);
startActivity(following);
}
} else if (viewId == R.id.follower) {
}
} else if (v.getId() == R.id.follower) {
if (user != null && relation != null) {
if (!(user.isLocked() || relation.isBlocked()) || relation.isFriend() || user.getId() == settings.getUserId()) {
Intent follower = new Intent(this, UserDetail.class);
follower.putExtra(KEY_USERDETAIL_ID, user.getId());
follower.putExtra(KEY_USERDETAIL_MODE, USERLIST_FOLLOWER);
startActivity(follower);
}
} else if (viewId == R.id.links) {
if (!user.getLink().isEmpty()) {
String link = user.getLink();
Intent browserIntent = new Intent(ACTION_VIEW, Uri.parse(link));
try {
startActivity(browserIntent);
} catch (ActivityNotFoundException err) {
Toast.makeText(this, R.string.error_connection_failed, LENGTH_SHORT).show();
}
}
} else if (v.getId() == R.id.links) {
if (user != null && !user.getLink().isEmpty()) {
String link = user.getLink();
Intent browserIntent = new Intent(ACTION_VIEW, Uri.parse(link));
try {
startActivity(browserIntent);
} catch (ActivityNotFoundException err) {
Toast.makeText(this, R.string.error_connection_failed, LENGTH_SHORT).show();
}
} else if (viewId == R.id.profile_img) {
}
} else if (v.getId() == R.id.profile_img) {
if (user != null) {
Intent mediaImage = new Intent(this, MediaViewer.class);
mediaImage.putExtra(KEY_MEDIA_LINK, new String[]{user.getImageLink()});
mediaImage.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE);
startActivity(mediaImage);
} else if (viewId == R.id.profile_banner) {
}
} else if (v.getId() == R.id.profile_banner) {
if (user != null) {
Intent mediaBanner = new Intent(this, MediaViewer.class);
mediaBanner.putExtra(KEY_MEDIA_LINK, new String[]{user.getBannerLink() + BANNER_IMG_HIGH_RES});
mediaBanner.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE);

View File

@ -78,6 +78,8 @@ public class GlobalSettings {
private static final String PROXY_PASS = "proxy_pass";
private static final String TREND_LOC = "location";
private static final String TREND_ID = "world_id";
// file name of the preferences
private static final String NAME = "settings";
// Default App settings

View File

@ -200,5 +200,5 @@
<string name="dialog_button_yes">yes</string>
<string name="dialog_button_no">no</string>
<string name="dialog_button_cancel">cancel</string>
<string name="dialog_button_ok">ok</string>
<string name="dialog_button_ok">OK</string>
</resources>