performance improvement, removed unnecessary code

This commit is contained in:
nuclearfog 2021-01-06 16:08:34 +01:00
parent 81d0ce3058
commit bcb2aeb258
No known key found for this signature in database
GPG Key ID: D5490E4A81F97B14
15 changed files with 231 additions and 293 deletions

View File

@ -48,7 +48,6 @@ public class ListPopup extends AppCompatActivity implements OnClickListener, OnD
private CompoundButton visibility;
private View progressCircle;
private Dialog leaveDialog;
@Nullable
private UserList userList;
@ -68,17 +67,14 @@ public class ListPopup extends AppCompatActivity implements OnClickListener, OnD
GlobalSettings settings = GlobalSettings.getInstance(this);
AppStyles.setTheme(settings, root, settings.getPopupColor());
Bundle extras = getIntent().getExtras();
if (extras != null) {
Object data = extras.getSerializable(KEY_LIST_EDITOR_DATA);
if (data instanceof UserList) {
userList = (UserList) data;
titleInput.setText(userList.getTitle());
subTitleInput.setText(userList.getDescription());
visibility.setChecked(!userList.isPrivate());
popupTitle.setText(R.string.menu_edit_list);
updateButton.setText(R.string.update_list);
}
Object data = getIntent().getSerializableExtra(KEY_LIST_EDITOR_DATA);
if (data instanceof UserList) {
userList = (UserList) data;
titleInput.setText(userList.getTitle());
subTitleInput.setText(userList.getDescription());
visibility.setChecked(!userList.isPrivate());
popupTitle.setText(R.string.menu_edit_list);
updateButton.setText(R.string.update_list);
}
leaveDialog = DialogBuilder.create(this, LISTPOPUP_LEAVE, this);
updateButton.setOnClickListener(this);

View File

@ -101,12 +101,10 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener,
View load = View.inflate(this, R.layout.item_load, null);
View cancelButton = load.findViewById(R.id.kill_button);
Bundle param = getIntent().getExtras();
if (param != null && param.containsKey(KEY_DM_PREFIX)) {
String prefix = param.getString(KEY_DM_PREFIX);
String prefix = getIntent().getStringExtra(KEY_DM_PREFIX);
if (prefix != null) {
receiver.append(prefix);
}
send.setImageResource(R.drawable.right);
media.setImageResource(R.drawable.image_add);
leaveDialog = DialogBuilder.create(this, MSG_POPUP_LEAVE, this);

View File

@ -58,6 +58,11 @@ import static org.nuclearfog.twidda.database.GlobalSettings.PROFILE_IMG_HIGH_RES
*/
public class ProfileEditor extends AppCompatActivity implements OnClickListener, OnDismissListener, OnDialogClick {
/**
* key to preload user data
*/
public static final String KEY_USER_DATA = "profile-editor-data";
/**
* Permission to read images from external storage
*/
@ -137,6 +142,11 @@ public class ProfileEditor extends AppCompatActivity implements OnClickListener,
loadingCircle.setContentView(load);
cancelButton.setVisibility(VISIBLE);
Object data = getIntent().getSerializableExtra(KEY_USER_DATA);
if (data instanceof User) {
user = (User) data;
setUser(user);
}
profile_image.setOnClickListener(this);
profile_banner.setOnClickListener(this);
addBannerBtn.setOnClickListener(this);
@ -145,16 +155,6 @@ public class ProfileEditor extends AppCompatActivity implements OnClickListener,
}
@Override
protected void onStart() {
super.onStart();
if (editorAsync == null) {
editorAsync = new UserUpdater(this, UserUpdater.Action.READ);
editorAsync.execute();
}
}
@Override
protected void onDestroy() {
if (editorAsync != null && editorAsync.getStatus() == RUNNING)
@ -203,7 +203,7 @@ public class ProfileEditor extends AppCompatActivity implements OnClickListener,
link.setError(errMsg);
} else {
UserHolder userHolder = new UserHolder(username, userLink, userLoc, userBio, profileLink, bannerLink);
editorAsync = new UserUpdater(this, UserUpdater.Action.WRITE);
editorAsync = new UserUpdater(this);
editorAsync.execute(userHolder);
}
}
@ -292,12 +292,32 @@ public class ProfileEditor extends AppCompatActivity implements OnClickListener,
}
}
/**
* called after user profile was updated successfully
*/
public void onSuccess(User user) {
Intent data = new Intent();
data.putExtra(RETURN_PROFILE_DATA, user);
Toast.makeText(this, R.string.info_profile_updated, Toast.LENGTH_SHORT).show();
setResult(RETURN_PROFILE_CHANGED, data);
finish();
}
/**
* called after an error occurs
*
* @param err Engine Exception
*/
public void onError(EngineException err) {
ErrorHandler.handleFailure(this, err);
}
/**
* Set current user's information
*
* @param user Current user
*/
public void setUser(User user) {
private void setUser(User user) {
if (user.hasProfileImage()) {
String pbLink = user.getImageLink();
if (!user.hasDefaultProfileImage())
@ -320,29 +340,6 @@ public class ProfileEditor extends AppCompatActivity implements OnClickListener,
this.user = user;
}
/**
* called after user profile was updated successfully
*/
public void onSuccess(User user) {
Intent data = new Intent();
data.putExtra(RETURN_PROFILE_DATA, user);
Toast.makeText(this, R.string.info_profile_updated, Toast.LENGTH_SHORT).show();
setResult(RETURN_PROFILE_CHANGED, data);
finish();
}
/**
* called after an error occurs
*
* @param err Engine Exception
*/
public void onError(EngineException err) {
ErrorHandler.handleFailure(this, err);
if (user == null) {
finish();
}
}
/**
* Get images from storage or ask for permission
*

View File

@ -55,19 +55,15 @@ public class SearchPage extends AppCompatActivity implements OnTabSelectedListen
setSupportActionBar(tool);
settings = GlobalSettings.getInstance(this);
AppStyles.setTheme(settings, root);
adapter = new FragmentAdapter(getSupportFragmentManager());
tabLayout.setupWithViewPager(pager);
tabLayout.addOnTabSelectedListener(this);
pager.setAdapter(adapter);
Bundle param = getIntent().getExtras();
if (param != null && param.containsKey(KEY_SEARCH_QUERY)) {
search = param.getString(KEY_SEARCH_QUERY);
adapter.setupSearchPage(search);
AppStyles.setTabIcons(tabLayout, settings, R.array.search_tab_icons);
}
search = getIntent().getStringExtra(KEY_SEARCH_QUERY);
adapter.setupSearchPage(search);
AppStyles.setTabIcons(tabLayout, settings, R.array.search_tab_icons);
AppStyles.setTheme(settings, root);
}

View File

@ -105,7 +105,6 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
private TweetAction statusAsync;
@Nullable
private Tweet tweet;
private long tweetId;
@Override
@ -132,24 +131,17 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
mediaButton = findViewById(R.id.tweet_media_attach);
sensitive_media = findViewById(R.id.tweet_sensitive);
tool.setTitle("");
setSupportActionBar(tool);
Bundle param = getIntent().getExtras();
FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
if (param != null) {
String username;
Object data = param.getSerializable(KEY_TWEET_DATA);
if (data instanceof Tweet) {
tweet = (Tweet) data;
username = tweet.getUser().getScreenname();
tweetId = tweet.getId();
} else {
tweetId = param.getLong(KEY_TWEET_ID);
username = param.getString(KEY_TWEET_NAME, "");
}
adapter.setupTweetPage(tweetId, username);
Object data = getIntent().getSerializableExtra(KEY_TWEET_DATA);
long tweetId = getIntent().getLongExtra(KEY_TWEET_ID, -1);
String username;
if (data instanceof Tweet) {
tweet = (Tweet) data;
username = tweet.getUser().getScreenname();
} else {
username = getIntent().getStringExtra(KEY_TWEET_NAME);
}
FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
adapter.setupTweetPage(tweetId, username);
pager.setOffscreenPageLimit(1);
pager.setAdapter(adapter);
@ -162,6 +154,8 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
tweetText.setMovementMethod(LinkAndScrollMovement.getInstance());
tweetText.setLinkTextColor(settings.getHighlightColor());
deleteDialog = DialogBuilder.create(this, DELETE_TWEET, this);
tool.setTitle("");
setSupportActionBar(tool);
AppStyles.setTheme(settings, root);
replyName.setOnClickListener(this);
@ -187,6 +181,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
}
// Load Tweet from database first if no tweet is defined
else {
long tweetId = getIntent().getLongExtra(KEY_TWEET_ID, -1);
statusAsync = new TweetAction(this, tweetId);
statusAsync.execute(Action.LD_DB);
}

View File

@ -133,7 +133,6 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
private Location location;
private List<String> mediaPath;
private MediaType selectedFormat = MediaType.NONE;
private String prefix = "";
private long inReplyId = 0;
@Override
@ -156,12 +155,12 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
settings = GlobalSettings.getInstance(this);
mediaPath = new LinkedList<>();
Bundle param = getIntent().getExtras();
if (param != null) {
inReplyId = param.getLong(KEY_TWEETPOPUP_REPLYID, 0);
prefix = param.getString(KEY_TWEETPOPUP_TEXT, "");
Intent data = getIntent();
inReplyId = data.getLongExtra(KEY_TWEETPOPUP_REPLYID, 0);
String prefix = data.getStringExtra(KEY_TWEETPOPUP_TEXT);
if (prefix != null)
tweetText.append(prefix);
}
previewBtn.setImageResource(R.drawable.image);
mediaBtn.setImageResource(R.drawable.image_add);
locationBtn.setImageResource(R.drawable.location);
@ -416,7 +415,7 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
* show confirmation dialog when closing edited tweet
*/
private void showClosingMsg() {
if (!prefix.equals(tweetText.getText().toString()) || !mediaPath.isEmpty()) {
if (tweetText.length() > 0 || !mediaPath.isEmpty()) {
if (!closingDialog.isShowing()) {
closingDialog.show();
}

View File

@ -1,5 +1,6 @@
package org.nuclearfog.twidda.activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@ -54,29 +55,26 @@ public class UserDetail extends AppCompatActivity {
ViewPager pager = findViewById(R.id.user_pager);
GlobalSettings settings = GlobalSettings.getInstance(this);
FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
Bundle param = getIntent().getExtras();
if (param != null && param.containsKey(KEY_USERDETAIL_ID) && param.containsKey(KEY_USERDETAIL_MODE)) {
long id = param.getLong(KEY_USERDETAIL_ID);
switch (param.getInt(KEY_USERDETAIL_MODE)) {
case USERLIST_FRIENDS:
toolbar.setTitle(R.string.userlist_following);
adapter.setupFriendsPage(id);
break;
Intent data = getIntent();
long id = data.getLongExtra(KEY_USERDETAIL_ID, -1);
switch (data.getIntExtra(KEY_USERDETAIL_MODE, 0)) {
case USERLIST_FRIENDS:
toolbar.setTitle(R.string.userlist_following);
adapter.setupFriendsPage(id);
break;
case USERLIST_FOLLOWER:
toolbar.setTitle(R.string.userlist_follower);
adapter.setupFollowerPage(id);
break;
case USERLIST_FOLLOWER:
toolbar.setTitle(R.string.userlist_follower);
adapter.setupFollowerPage(id);
break;
case USERLIST_RETWEETS:
toolbar.setTitle(R.string.toolbar_userlist_retweet);
adapter.setupRetweeterPage(id);
break;
}
case USERLIST_RETWEETS:
toolbar.setTitle(R.string.toolbar_userlist_retweet);
adapter.setupRetweeterPage(id);
break;
}
setSupportActionBar(toolbar);
AppStyles.setTheme(settings, root);

View File

@ -74,18 +74,13 @@ public class UserLists extends AppCompatActivity implements TabLayout.OnTabSelec
mTab.setupWithViewPager(pager);
mTab.addOnTabSelectedListener(this);
Bundle param = getIntent().getExtras();
if (param != null) {
if (param.containsKey(KEY_USERLIST_OWNER_ID)) {
long ownerId = param.getLong(KEY_USERLIST_OWNER_ID);
isHome = ownerId == settings.getCurrentUserId();
adapter.setupListPage(ownerId, "");
} else if (param.containsKey(KEY_USERLIST_OWNER_NAME)) {
String ownerName = param.getString(KEY_USERLIST_OWNER_NAME);
adapter.setupListPage(-1, ownerName);
}
AppStyles.setTabIcons(mTab, settings, R.array.userlist_tab_icons);
}
Intent data = getIntent();
long ownerId = data.getLongExtra(KEY_USERLIST_OWNER_ID, -1);
String ownerName = data.getStringExtra(KEY_USERLIST_OWNER_NAME);
isHome = ownerId == settings.getCurrentUserId();
adapter.setupListPage(ownerId, ownerName);
AppStyles.setTabIcons(mTab, settings, R.array.userlist_tab_icons);
}

View File

@ -56,6 +56,7 @@ import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_LINK;
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.ProfileEditor.KEY_USER_DATA;
import static org.nuclearfog.twidda.activity.SearchPage.KEY_SEARCH_QUERY;
import static org.nuclearfog.twidda.activity.TweetActivity.KEY_TWEET_ID;
import static org.nuclearfog.twidda.activity.TweetActivity.KEY_TWEET_NAME;
@ -92,15 +93,15 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
public static final String KEY_PROFILE_ID = "profile_id";
/**
* Alternative Key for the screen name
*/
public static final String KEY_PROFILE_NAME = "profile_name";
/**
* key for user object, alternative to {@link #KEY_PROFILE_ID} and {@link #KEY_PROFILE_NAME}
* key for user object
*/
public static final String KEY_PROFILE_DATA = "profile_data";
/**
* key to prevent this activity to reload profile information as they are up to date
*/
public static final String KEY_PROFILE_DISABLE_RELOAD = "profile_no_reload";
/**
* request code for {@link ProfileEditor}
*/
@ -140,10 +141,6 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
@Nullable
private User user;
private String username;
private long userId;
private boolean isHomeProfile;
@Override
protected void onCreate(@Nullable Bundle b) {
@ -167,8 +164,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
follow_back = findViewById(R.id.follow_back);
pager = findViewById(R.id.profile_pager);
tool.setTitle("");
setSupportActionBar(tool);
settings = GlobalSettings.getInstance(this);
following.setCompoundDrawablesWithIntrinsicBounds(R.drawable.following, 0, 0, 0);
@ -184,6 +180,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
bioTxt.setLinkTextColor(settings.getHighlightColor());
AppStyles.setTheme(settings, root);
tool.setTitle("");
setSupportActionBar(tool);
adapter = new FragmentAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(2);
@ -192,21 +190,15 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
blockConfirm = DialogBuilder.create(this, PROFILE_BLOCK, this);
muteConfirm = DialogBuilder.create(this, PROFILE_MUTE, this);
Bundle param = getIntent().getExtras();
if (param != null) {
Object data = param.getSerializable(KEY_PROFILE_DATA);
if (data instanceof User) {
user = (User) data;
userId = user.getId();
username = user.getScreenname();
} else {
userId = param.getLong(KEY_PROFILE_ID, -1);
username = param.getString(KEY_PROFILE_NAME, "");
}
adapter.setupProfilePage(userId, username);
tabTweetCount = AppStyles.createTabIcon(tabLayout, settings, R.array.profile_tab_icons);
isHomeProfile = userId == settings.getCurrentUserId();
Intent i = getIntent();
user = (User) i.getSerializableExtra(KEY_PROFILE_DATA);
if (user != null) {
adapter.setupProfilePage(user.getId());
} else {
long userId = i.getLongExtra(KEY_PROFILE_ID, 0);
adapter.setupProfilePage(userId);
}
tabTweetCount = AppStyles.createTabIcon(tabLayout, settings, R.array.profile_tab_icons);
tabLayout.addOnTabSelectedListener(this);
following.setOnClickListener(this);
@ -221,12 +213,17 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
protected void onStart() {
super.onStart();
if (profileAsync == null) {
profileAsync = new UserAction(this, userId, username);
Intent data = getIntent();
if (user == null) {
long userId = data.getLongExtra(KEY_PROFILE_ID, 0);
profileAsync = new UserAction(this, userId);
profileAsync.execute(PROFILE_DB);
} else {
profileAsync.execute(PROFILE_lOAD);
setUser(user);
if (!data.getBooleanExtra(KEY_PROFILE_DISABLE_RELOAD, false)) {
profileAsync = new UserAction(this, user.getId());
profileAsync.execute(PROFILE_lOAD);
}
}
}
}
@ -271,10 +268,23 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
AppStyles.setMenuItemColor(followIcon, Color.YELLOW);
followIcon.setTitle(R.string.menu_follow_requested);
}
if (user.isLocked() && !isHomeProfile) {
if (user.isLocked() && !user.isCurrentUser()) {
MenuItem listItem = m.findItem(R.id.profile_lists);
listItem.setVisible(false);
}
if (user.isCurrentUser()) {
MenuItem dmIcon = m.findItem(R.id.profile_message);
MenuItem setting = m.findItem(R.id.profile_settings);
dmIcon.setVisible(true);
setting.setVisible(true);
} else {
MenuItem followIcon = m.findItem(R.id.profile_follow);
MenuItem blockIcon = m.findItem(R.id.profile_block);
MenuItem muteIcon = m.findItem(R.id.profile_mute);
followIcon.setVisible(true);
blockIcon.setVisible(true);
muteIcon.setVisible(true);
}
}
if (relation != null) {
if (relation.isFriend()) {
@ -300,78 +310,66 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
follow_back.setVisibility(VISIBLE);
}
}
if (isHomeProfile) {
MenuItem dmIcon = m.findItem(R.id.profile_message);
MenuItem setting = m.findItem(R.id.profile_settings);
dmIcon.setVisible(true);
setting.setVisible(true);
} else {
MenuItem followIcon = m.findItem(R.id.profile_follow);
MenuItem blockIcon = m.findItem(R.id.profile_block);
MenuItem muteIcon = m.findItem(R.id.profile_mute);
followIcon.setVisible(true);
blockIcon.setVisible(true);
muteIcon.setVisible(true);
}
return super.onPrepareOptionsMenu(m);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
// write tweet
if (item.getItemId() == R.id.profile_tweet) {
Intent tweet = new Intent(this, TweetPopup.class);
if (!isHomeProfile && user != null) {
// add username to tweet
String tweetPrefix = user.getScreenname() + " ";
tweet.putExtra(KEY_TWEETPOPUP_TEXT, tweetPrefix);
if (user != null) {
// write tweet
if (item.getItemId() == R.id.profile_tweet) {
Intent tweet = new Intent(this, TweetPopup.class);
if (!user.isCurrentUser()) {
// add username to tweet
String tweetPrefix = user.getScreenname() + " ";
tweet.putExtra(KEY_TWEETPOPUP_TEXT, tweetPrefix);
}
startActivity(tweet);
}
startActivity(tweet);
}
// follow / unfollow user
else if (item.getItemId() == R.id.profile_follow) {
if (user != null && relation != null) {
if (!relation.isFriend()) {
profileAsync = new UserAction(this, user);
profileAsync.execute(ACTION_FOLLOW);
} else if (!unfollowConfirm.isShowing()) {
unfollowConfirm.show();
// follow / unfollow user
else if (item.getItemId() == R.id.profile_follow) {
if (relation != null) {
if (!relation.isFriend()) {
profileAsync = new UserAction(this, user.getId());
profileAsync.execute(ACTION_FOLLOW);
} else if (!unfollowConfirm.isShowing()) {
unfollowConfirm.show();
}
}
}
}
// mute user
else if (item.getItemId() == R.id.profile_mute) {
if (user != null && relation != null) {
if (relation.isMuted()) {
profileAsync = new UserAction(this, user);
profileAsync.execute(ACTION_UNMUTE);
} else if (!muteConfirm.isShowing()) {
muteConfirm.show();
// mute user
else if (item.getItemId() == R.id.profile_mute) {
if (relation != null) {
if (relation.isMuted()) {
profileAsync = new UserAction(this, user.getId());
profileAsync.execute(ACTION_UNMUTE);
} else if (!muteConfirm.isShowing()) {
muteConfirm.show();
}
}
}
}
// block user
else if (item.getItemId() == R.id.profile_block) {
if (user != null && relation != null) {
if (relation.isBlocked()) {
profileAsync = new UserAction(this, user);
profileAsync.execute(ACTION_UNBLOCK);
} else if (!blockConfirm.isShowing()) {
blockConfirm.show();
// block user
else if (item.getItemId() == R.id.profile_block) {
if (relation != null) {
if (relation.isBlocked()) {
profileAsync = new UserAction(this, user.getId());
profileAsync.execute(ACTION_UNBLOCK);
} else if (!blockConfirm.isShowing()) {
blockConfirm.show();
}
}
}
}
// open profile editor
else if (item.getItemId() == R.id.profile_settings) {
Intent editProfile = new Intent(this, ProfileEditor.class);
startActivityForResult(editProfile, REQUEST_PROFILE_CHANGED);
}
// open direct message
else if (item.getItemId() == R.id.profile_message) {
if (user != null) {
// open profile editor
else if (item.getItemId() == R.id.profile_settings) {
Intent editProfile = new Intent(this, ProfileEditor.class);
editProfile.putExtra(KEY_USER_DATA, user);
startActivityForResult(editProfile, REQUEST_PROFILE_CHANGED);
}
// open direct message
else if (item.getItemId() == R.id.profile_message) {
Intent dmPage;
if (isHomeProfile) {
if (user.isCurrentUser()) {
dmPage = new Intent(this, DirectMessage.class);
} else {
dmPage = new Intent(this, MessagePopup.class);
@ -379,12 +377,12 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
}
startActivity(dmPage);
}
}
// open users list
else if (item.getItemId() == R.id.profile_lists) {
Intent listPage = new Intent(this, UserLists.class);
listPage.putExtra(KEY_USERLIST_OWNER_ID, userId);
startActivity(listPage);
// open users list
else if (item.getItemId() == R.id.profile_lists) {
Intent listPage = new Intent(this, UserLists.class);
listPage.putExtra(KEY_USERLIST_OWNER_ID, user.getId());
startActivity(listPage);
}
}
return super.onOptionsItemSelected(item);
}
@ -445,9 +443,9 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
// open following page
if (v.getId() == R.id.following) {
if (user != null && relation != null) {
if (!user.isLocked() || relation.isFriend() || isHomeProfile) {
if (!user.isLocked() || user.isCurrentUser() || relation.isFriend()) {
Intent following = new Intent(this, UserDetail.class);
following.putExtra(KEY_USERDETAIL_ID, userId);
following.putExtra(KEY_USERDETAIL_ID, user.getId());
following.putExtra(KEY_USERDETAIL_MODE, USERLIST_FRIENDS);
startActivity(following);
}
@ -456,9 +454,9 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
// open follower page
else if (v.getId() == R.id.follower) {
if (user != null && relation != null) {
if (!user.isLocked() || relation.isFriend() || isHomeProfile) {
if (!user.isLocked() || user.isCurrentUser() || relation.isFriend()) {
Intent follower = new Intent(this, UserDetail.class);
follower.putExtra(KEY_USERDETAIL_ID, userId);
follower.putExtra(KEY_USERDETAIL_ID, user.getId());
follower.putExtra(KEY_USERDETAIL_MODE, USERLIST_FOLLOWER);
startActivity(follower);
}
@ -500,7 +498,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
@Override
public void onConfirm(DialogBuilder.DialogType type) {
if (user != null) {
profileAsync = new UserAction(this, user);
profileAsync = new UserAction(this, user.getId());
// confirmed unfollowing user
if (type == PROFILE_UNFOLLOW) {
profileAsync.execute(ACTION_UNFOLLOW);

View File

@ -105,28 +105,25 @@ public class FragmentAdapter extends FragmentStatePagerAdapter {
}
/**
* setup adapter for viewing user tweets and favs
* setup adapter for viewing user tweets and favorites
*
* @param userId ID of the user
* @param username screen name of the user
* @param userId ID of the user
*/
public void setupProfilePage(long userId, String username) {
Bundle usr_tweet = new Bundle();
Bundle usr_favor = new Bundle();
if (userId > 0) {
usr_tweet.putLong(KEY_FRAG_TWEET_ID, userId);
usr_favor.putLong(KEY_FRAG_TWEET_ID, userId);
} else {
usr_tweet.putString(KEY_FRAG_TWEET_SEARCH, username);
usr_favor.putString(KEY_FRAG_TWEET_SEARCH, username);
}
usr_tweet.putInt(KEY_FRAG_TWEET_MODE, TWEET_FRAG_TWEETS);
usr_favor.putInt(KEY_FRAG_TWEET_MODE, TWEET_FRAG_FAVORS);
public void setupProfilePage(long userId) {
fragments = new ListFragment[2];
fragments[0] = new TweetFragment();
fragments[1] = new TweetFragment();
Bundle usr_tweet = new Bundle();
usr_tweet.putLong(KEY_FRAG_TWEET_ID, userId);
usr_tweet.putInt(KEY_FRAG_TWEET_MODE, TWEET_FRAG_TWEETS);
fragments[0].setArguments(usr_tweet);
fragments[1] = new TweetFragment();
Bundle usr_favor = new Bundle();
usr_favor.putLong(KEY_FRAG_TWEET_ID, userId);
usr_favor.putInt(KEY_FRAG_TWEET_MODE, TWEET_FRAG_FAVORS);
fragments[1].setArguments(usr_favor);
notifyDataSetChanged();
}
@ -250,7 +247,8 @@ public class FragmentAdapter extends FragmentStatePagerAdapter {
/**
* setup adapter for a page of tweets and users in an user list
*
* @param listId ID of an user list
* @param listId ID of an user list
* @param ownerOfList true if current user owns this list
*/
public void setupListContentPage(long listId, boolean ownerOfList) {
Bundle tweetParam = new Bundle();

View File

@ -15,6 +15,8 @@ import org.nuclearfog.twidda.activity.TweetActivity;
import org.nuclearfog.twidda.activity.TweetPopup;
import org.nuclearfog.twidda.activity.UserLists;
import org.nuclearfog.twidda.activity.UserProfile;
import org.nuclearfog.twidda.backend.engine.TwitterEngine;
import org.nuclearfog.twidda.backend.items.User;
import java.lang.ref.WeakReference;
import java.util.regex.Pattern;
@ -24,7 +26,8 @@ import static org.nuclearfog.twidda.activity.TweetActivity.KEY_TWEET_ID;
import static org.nuclearfog.twidda.activity.TweetActivity.KEY_TWEET_NAME;
import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_TEXT;
import static org.nuclearfog.twidda.activity.UserLists.KEY_USERLIST_OWNER_NAME;
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_NAME;
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_DATA;
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_DISABLE_RELOAD;
/**
* This class handles deep links and starts activities to show the content
@ -38,10 +41,12 @@ public class LinkLoader extends AsyncTask<Uri, Integer, LinkLoader.DataHolder> {
private static final Pattern LIST_PATH = Pattern.compile("[\\w]+/lists");
private WeakReference<MainActivity> callback;
private TwitterEngine mTwitter;
public LinkLoader(MainActivity callback) {
super();
this.callback = new WeakReference<>(callback);
mTwitter = TwitterEngine.getInstance(callback);
}
@Override
@ -99,7 +104,9 @@ public class LinkLoader extends AsyncTask<Uri, Integer, LinkLoader.DataHolder> {
int end = path.indexOf('/');
if (end > 0)
path = path.substring(0, end);
data.putString(KEY_PROFILE_NAME, path);
User user = mTwitter.getUser(path);
data.putSerializable(KEY_PROFILE_DATA, user);
data.putBoolean(KEY_PROFILE_DISABLE_RELOAD, true);
dataHolder = new DataHolder(data, UserProfile.class);
} else if (TWEET_PATH.matcher(path).matches()) {
String username = '@' + path.substring(0, path.indexOf('/'));

View File

@ -61,28 +61,17 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
private TwitterEngine mTwitter;
private AppDatabase db;
private long userId;
private String screenName;
/**
* @param callback Callback to return the result
* @param user twitter user information
* @param userId ID of the twitter user
*/
public UserAction(UserProfile callback, User user) {
this(callback, user.getId(), user.getScreenname());
}
/**
* @param callback Callback to return the result
* @param userId ID of the twitter user
* @param screenName username alternative to User ID
*/
public UserAction(UserProfile callback, long userId, String screenName) {
public UserAction(UserProfile callback, long userId) {
super();
this.callback = new WeakReference<>(callback);
mTwitter = TwitterEngine.getInstance(callback);
db = new AppDatabase(callback);
this.userId = userId;
this.screenName = screenName;
}
@ -102,11 +91,11 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
case PROFILE_lOAD:
// load user information from twitter
user = mTwitter.getUser(userId, screenName);
user = mTwitter.getUser(userId);
publishProgress(user);
db.storeUser(user);
// load user relations from twitter
Relation relation = mTwitter.getConnection(userId, screenName);
Relation relation = mTwitter.getConnection(userId);
if (!relation.isHome()) {
boolean muteUser = relation.isBlocked() || relation.isMuted();
db.muteUser(userId, muteUser);
@ -147,7 +136,7 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
db.muteUser(userId, false);
break;
}
return mTwitter.getConnection(userId, screenName);
return mTwitter.getConnection(userId);
} catch (EngineException twException) {
this.twException = twException;
return null;

View File

@ -25,17 +25,10 @@ public class UserUpdater extends AsyncTask<UserHolder, Void, User> {
private WeakReference<ProfileEditor> callback;
private TwitterEngine mTwitter;
private AppDatabase db;
private Action action;
public enum Action {
READ,
WRITE
}
public UserUpdater(ProfileEditor callback, Action action) {
public UserUpdater(ProfileEditor callback) {
super();
this.action = action;
this.callback = new WeakReference<>(callback);
mTwitter = TwitterEngine.getInstance(callback);
db = new AppDatabase(callback);
@ -53,15 +46,9 @@ public class UserUpdater extends AsyncTask<UserHolder, Void, User> {
@Override
protected User doInBackground(UserHolder[] holder) {
try {
switch (action) {
case READ:
return mTwitter.getCurrentUser();
case WRITE:
User user = mTwitter.updateProfile(holder[0]);
db.storeUser(user);
return user;
}
User user = mTwitter.updateProfile(holder[0]);
db.storeUser(user);
return user;
} catch (EngineException twException) {
this.twException = twException;
}
@ -75,11 +62,7 @@ public class UserUpdater extends AsyncTask<UserHolder, Void, User> {
if (activity != null) {
activity.setLoading(false);
if (user != null) {
if (action == Action.READ) {
activity.setUser(user);
} else {
activity.onSuccess(user);
}
activity.onSuccess(user);
} else if (twException != null) {
activity.onError(twException);
}

View File

@ -406,36 +406,30 @@ public class TwitterEngine {
/**
* Get User Context
* Get User
*
* @param userId User ID
* @param username User screen name, if user ID is defined, username can be empty
* @param userId User ID
* @return User Object
* @throws EngineException if Access is unavailable
*/
public User getUser(long userId, String username) throws EngineException {
public User getUser(long userId) throws EngineException {
try {
if (userId > 0) {
return new User(twitter.showUser(userId), twitter.getId());
} else {
return new User(twitter.showUser(username), twitter.getId());
}
return new User(twitter.showUser(userId), twitter.getId());
} catch (Exception err) {
throw new EngineException(err);
}
}
/**
* Get current user
* Get User
*
* @return curent user
* @param username screen name of the user
* @return User Object
* @throws EngineException if Access is unavailable
*/
public User getCurrentUser() throws EngineException {
public User getUser(String username) throws EngineException {
try {
long currentUserId = twitter.getId();
return new User(twitter.showUser(currentUserId), currentUserId);
return new User(twitter.showUser(username), twitter.getId());
} catch (Exception err) {
throw new EngineException(err);
}
@ -445,18 +439,13 @@ public class TwitterEngine {
/**
* Efficient Access of Connection Information
*
* @param userId User ID compared with Home ID
* @param username User screen name
* @param userId User ID compared with Home ID
* @return User Properties
* @throws EngineException if Connection is unavailable
*/
public Relation getConnection(long userId, String username) throws EngineException {
public Relation getConnection(long userId) throws EngineException {
try {
if (userId > 0) {
return new Relation(twitter.showFriendship(twitter.getId(), userId));
} else {
return new Relation(twitter.showFriendship(twitter.getScreenName(), username));
}
return new Relation(twitter.showFriendship(twitter.getId(), userId));
} catch (Exception err) {
throw new EngineException(err);
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorAccent">@android:color/white</item>
<item name="android:colorBackground">@android:color/black</item>
<item name="android:windowAnimationStyle">@style/TransactionPending</item>