performance improvements
This commit is contained in:
parent
c95fca519a
commit
6a3c7bd2a2
@ -37,7 +37,6 @@ import java.util.regex.Pattern;
|
||||
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
import static org.nuclearfog.twidda.activity.ListPopup.KEY_LIST_DESCR;
|
||||
import static org.nuclearfog.twidda.activity.ListPopup.KEY_LIST_ID;
|
||||
import static org.nuclearfog.twidda.activity.ListPopup.KEY_LIST_TITLE;
|
||||
import static org.nuclearfog.twidda.activity.ListPopup.KEY_LIST_VISIB;
|
||||
import static org.nuclearfog.twidda.backend.ListAction.Action.DELETE;
|
||||
@ -59,12 +58,17 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
/**
|
||||
* Key for the list ID, required
|
||||
*/
|
||||
public static final String KEY_LISTDETAIL_ID = "list-id";
|
||||
public static final String KEY_LIST_ID = "list-id";
|
||||
|
||||
/**
|
||||
* Key to check if this list is owned by the current user
|
||||
*/
|
||||
public static final String KEY_CURRENT_USER_OWNS = "list-owner";
|
||||
public static final String KEY_LIST_OWNER = "list-owner";
|
||||
|
||||
/**
|
||||
* Key to get user list object
|
||||
*/
|
||||
public static final String KEY_LIST_DATA = "list_data";
|
||||
|
||||
/**
|
||||
* Request code for list editing
|
||||
@ -113,20 +117,28 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
|
||||
Bundle param = getIntent().getExtras();
|
||||
if (param != null) {
|
||||
listId = param.getLong(KEY_LISTDETAIL_ID);
|
||||
boolean currentUserOwnsList = param.getBoolean(KEY_CURRENT_USER_OWNS, false);
|
||||
adapter.setupListContentPage(listId, currentUserOwnsList);
|
||||
Tab tweetTab = tablayout.getTabAt(0);
|
||||
Tab userTab = tablayout.getTabAt(1);
|
||||
Tab subscrTab = tablayout.getTabAt(2);
|
||||
if (tweetTab != null && userTab != null && subscrTab != null) {
|
||||
tweetTab.setIcon(R.drawable.list);
|
||||
userTab.setIcon(R.drawable.user);
|
||||
subscrTab.setIcon(R.drawable.subscriber);
|
||||
boolean currentUserOwnsList;
|
||||
if (param.containsKey(KEY_LIST_DATA)) {
|
||||
userList = (UserList) param.getSerializable(KEY_LIST_DATA);
|
||||
currentUserOwnsList = userList.isListOwner();
|
||||
listId = userList.getId();
|
||||
} else {
|
||||
currentUserOwnsList = param.getBoolean(KEY_LIST_OWNER, false);
|
||||
listId = param.getLong(KEY_LIST_ID);
|
||||
}
|
||||
toolbar.setTitle("");
|
||||
setSupportActionBar(toolbar);
|
||||
adapter.setupListContentPage(listId, currentUserOwnsList);
|
||||
}
|
||||
|
||||
Tab tweetTab = tablayout.getTabAt(0);
|
||||
Tab userTab = tablayout.getTabAt(1);
|
||||
Tab subscrTab = tablayout.getTabAt(2);
|
||||
if (tweetTab != null && userTab != null && subscrTab != null) {
|
||||
tweetTab.setIcon(R.drawable.list);
|
||||
userTab.setIcon(R.drawable.user);
|
||||
subscrTab.setIcon(R.drawable.subscriber);
|
||||
}
|
||||
toolbar.setTitle("");
|
||||
setSupportActionBar(toolbar);
|
||||
FontTool.setViewFontAndColor(settings, root);
|
||||
}
|
||||
|
||||
@ -135,6 +147,11 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (listLoaderTask == null && userList == null) {
|
||||
if (userList != null) {
|
||||
toolbar.setTitle(userList.getTitle());
|
||||
toolbar.setSubtitle(userList.getDescription());
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
loadList();
|
||||
}
|
||||
}
|
||||
@ -190,7 +207,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.menu_list_edit) {
|
||||
Intent editList = new Intent(this, ListPopup.class);
|
||||
editList.putExtra(KEY_LIST_ID, userList.getId());
|
||||
editList.putExtra(ListPopup.KEY_LIST_ID, userList.getId());
|
||||
editList.putExtra(KEY_LIST_TITLE, userList.getTitle());
|
||||
editList.putExtra(KEY_LIST_DESCR, userList.getDescription());
|
||||
editList.putExtra(KEY_LIST_VISIB, !userList.isPrivate());
|
||||
@ -351,11 +368,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
* load list information
|
||||
*/
|
||||
private void loadList() {
|
||||
Bundle param = getIntent().getExtras();
|
||||
if (param != null) {
|
||||
long listId = param.getLong(KEY_LISTDETAIL_ID);
|
||||
listLoaderTask = new ListAction(this, LOAD);
|
||||
listLoaderTask.execute(listId);
|
||||
}
|
||||
listLoaderTask = new ListAction(this, LOAD);
|
||||
listLoaderTask.execute(listId);
|
||||
}
|
||||
}
|
@ -73,12 +73,17 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
|
||||
/**
|
||||
* ID of the tweet to open. required
|
||||
*/
|
||||
public static final String KEY_TWEET_ID = "tweetID";
|
||||
public static final String KEY_TWEET_ID = "tweet_tweet_id";
|
||||
|
||||
/**
|
||||
* screen name of the author. optional
|
||||
*/
|
||||
public static final String KEY_TWEET_NAME = "username";
|
||||
public static final String KEY_TWEET_NAME = "tweet_author";
|
||||
|
||||
/**
|
||||
* key for a tweet object
|
||||
*/
|
||||
public static final String KEY_TWEET_DATA = "tweet_data";
|
||||
|
||||
/**
|
||||
* regex pattern of a tweet URL
|
||||
@ -96,6 +101,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
|
||||
private TweetAction statusAsync;
|
||||
@Nullable
|
||||
private Tweet tweet;
|
||||
private long tweetId;
|
||||
|
||||
|
||||
@Override
|
||||
@ -127,8 +133,15 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
|
||||
Bundle param = getIntent().getExtras();
|
||||
FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
|
||||
if (param != null) {
|
||||
long tweetId = param.getLong(KEY_TWEET_ID);
|
||||
String username = param.getString(KEY_TWEET_NAME, "");
|
||||
String username;
|
||||
if (param.containsKey(KEY_TWEET_DATA)) {
|
||||
tweet = (Tweet) param.getSerializable(KEY_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);
|
||||
}
|
||||
|
||||
@ -156,12 +169,14 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Bundle param = getIntent().getExtras();
|
||||
if (statusAsync == null && param != null) {
|
||||
if (param.containsKey(KEY_TWEET_ID)) {
|
||||
long tweetId = param.getLong(KEY_TWEET_ID);
|
||||
if (statusAsync == null) {
|
||||
if (tweet == null) {
|
||||
statusAsync = new TweetAction(this, tweetId);
|
||||
statusAsync.execute(Action.LD_DB);
|
||||
} else {
|
||||
statusAsync = new TweetAction(this, tweet.getId());
|
||||
statusAsync.execute(Action.LOAD);
|
||||
setTweet(tweet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -250,7 +265,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
|
||||
else if (v.getId() == R.id.profileimage_detail) {
|
||||
if (tweet != null) {
|
||||
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
|
||||
profile.putExtra(UserProfile.KEY_PROFILE_ID, tweet.getUser().getId());
|
||||
profile.putExtra(UserProfile.KEY_PROFILE_DATA, tweet.getUser());
|
||||
startActivity(profile);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,8 @@ import static org.nuclearfog.twidda.backend.UserAction.Action.ACTION_MUTE;
|
||||
import static org.nuclearfog.twidda.backend.UserAction.Action.ACTION_UNBLOCK;
|
||||
import static org.nuclearfog.twidda.backend.UserAction.Action.ACTION_UNFOLLOW;
|
||||
import static org.nuclearfog.twidda.backend.UserAction.Action.ACTION_UNMUTE;
|
||||
import static org.nuclearfog.twidda.backend.UserAction.Action.LDR_PROFILE;
|
||||
import static org.nuclearfog.twidda.backend.UserAction.Action.PROFILE_DB;
|
||||
import static org.nuclearfog.twidda.backend.UserAction.Action.PROFILE_lOAD;
|
||||
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.PROFILE_BLOCK;
|
||||
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.PROFILE_MUTE;
|
||||
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.PROFILE_UNFOLLOW;
|
||||
@ -96,6 +97,11 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
|
||||
*/
|
||||
public static final String KEY_PROFILE_NAME = "profile_name";
|
||||
|
||||
/**
|
||||
* key for user object
|
||||
*/
|
||||
public static final String KEY_PROFILE_DATA = "profile_data";
|
||||
|
||||
/**
|
||||
* request code for {@link ProfileEditor}
|
||||
*/
|
||||
@ -126,6 +132,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
|
||||
private UserAction profileAsync;
|
||||
private Relation relation;
|
||||
private User user;
|
||||
private String username;
|
||||
private long userId;
|
||||
|
||||
|
||||
@Override
|
||||
@ -189,8 +197,14 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
|
||||
|
||||
Bundle param = getIntent().getExtras();
|
||||
if (param != null) {
|
||||
long userId = param.getLong(KEY_PROFILE_ID, -1);
|
||||
String username = param.getString(KEY_PROFILE_NAME, "");
|
||||
if (param.containsKey(KEY_PROFILE_DATA)) {
|
||||
user = (User) param.getSerializable(KEY_PROFILE_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);
|
||||
}
|
||||
Tab tweetTab = tabLayout.getTabAt(0);
|
||||
@ -212,12 +226,14 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Bundle param = getIntent().getExtras();
|
||||
if (profileAsync == null && param != null) {
|
||||
long userId = param.getLong(KEY_PROFILE_ID, -1);
|
||||
String username = param.getString(KEY_PROFILE_NAME, "");
|
||||
if (profileAsync == null) {
|
||||
profileAsync = new UserAction(this, userId, username);
|
||||
profileAsync.execute(LDR_PROFILE);
|
||||
if (user == null) {
|
||||
profileAsync.execute(PROFILE_DB);
|
||||
} else {
|
||||
profileAsync.execute(PROFILE_lOAD);
|
||||
setUser(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,10 @@ public class TweetAction extends AsyncTask<TweetAction.Action, Tweet, TweetActio
|
||||
* Load tweet
|
||||
*/
|
||||
LOAD,
|
||||
/**
|
||||
* load tweet from database first
|
||||
*/
|
||||
LD_DB,
|
||||
/**
|
||||
* retweet tweet
|
||||
*/
|
||||
@ -82,14 +86,16 @@ public class TweetAction extends AsyncTask<TweetAction.Action, Tweet, TweetActio
|
||||
@Override
|
||||
protected Action doInBackground(Action[] action) {
|
||||
try {
|
||||
boolean updateStatus = false;
|
||||
switch (action[0]) {
|
||||
case LOAD:
|
||||
boolean updateStatus = false;
|
||||
case LD_DB:
|
||||
Tweet tweet = db.getStatus(tweetId);
|
||||
if (tweet != null) {
|
||||
publishProgress(tweet);
|
||||
updateStatus = true;
|
||||
}
|
||||
|
||||
case LOAD:
|
||||
tweet = mTwitter.getStatus(tweetId);
|
||||
publishProgress(tweet);
|
||||
if (updateStatus) {
|
||||
|
@ -25,7 +25,11 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
|
||||
/**
|
||||
* Load profile information
|
||||
*/
|
||||
LDR_PROFILE,
|
||||
PROFILE_lOAD,
|
||||
/**
|
||||
* load profile from database first
|
||||
*/
|
||||
PROFILE_DB,
|
||||
/**
|
||||
* follow user
|
||||
*/
|
||||
@ -86,7 +90,7 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
|
||||
protected Relation doInBackground(Action[] action) {
|
||||
try {
|
||||
switch (action[0]) {
|
||||
case LDR_PROFILE:
|
||||
case PROFILE_DB:
|
||||
// load user information from database
|
||||
User user;
|
||||
if (userId > 0) {
|
||||
@ -95,6 +99,8 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
|
||||
publishProgress(user);
|
||||
}
|
||||
}
|
||||
|
||||
case PROFILE_lOAD:
|
||||
// load user information from twitter
|
||||
user = mTwitter.getUser(userId, screenName);
|
||||
publishProgress(user);
|
||||
|
@ -2,7 +2,6 @@ package org.nuclearfog.twidda.backend.engine;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
import static org.nuclearfog.twidda.backend.engine.EngineException.ErrorType.NOT_AUTHORIZED;
|
||||
import static org.nuclearfog.twidda.backend.engine.EngineException.ErrorType.RESOURCE_NOT_FOUND;
|
||||
import static org.nuclearfog.twidda.backend.engine.EngineException.ErrorType.USER_NOT_FOUND;
|
||||
|
||||
@ -157,7 +156,7 @@ public class EngineException extends Exception {
|
||||
* @return true if resource not found or access denied
|
||||
*/
|
||||
public boolean resourceNotFound() {
|
||||
return errorType == RESOURCE_NOT_FOUND || errorType == NOT_AUTHORIZED || errorType == USER_NOT_FOUND;
|
||||
return errorType == RESOURCE_NOT_FOUND || errorType == USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ 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;
|
||||
import static org.nuclearfog.twidda.activity.TweetActivity.LINK_PATTERN;
|
||||
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID;
|
||||
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_DATA;
|
||||
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.DEL_MESSAGE;
|
||||
|
||||
/**
|
||||
@ -143,7 +143,7 @@ public class MessageFragment extends ListFragment implements OnItemSelected, OnD
|
||||
|
||||
case PROFILE:
|
||||
Intent profile = new Intent(requireContext(), UserProfile.class);
|
||||
profile.putExtra(KEY_PROFILE_ID, message.getSender().getId());
|
||||
profile.putExtra(KEY_PROFILE_DATA, message.getSender());
|
||||
startActivity(profile);
|
||||
break;
|
||||
}
|
||||
|
@ -18,8 +18,7 @@ import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
import java.util.List;
|
||||
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
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.TweetActivity.KEY_TWEET_DATA;
|
||||
|
||||
/**
|
||||
* #Fragment class for a list of tweets
|
||||
@ -131,8 +130,7 @@ public class TweetFragment extends ListFragment implements TweetClickListener {
|
||||
if (tweet.getEmbeddedTweet() != null)
|
||||
tweet = tweet.getEmbeddedTweet();
|
||||
Intent tweetIntent = new Intent(requireContext(), TweetActivity.class);
|
||||
tweetIntent.putExtra(KEY_TWEET_ID, tweet.getId());
|
||||
tweetIntent.putExtra(KEY_TWEET_NAME, tweet.getUser().getScreenname());
|
||||
tweetIntent.putExtra(KEY_TWEET_DATA, tweet);
|
||||
startActivityForResult(tweetIntent, REQUEST_TWEET_CHANGED);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID;
|
||||
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_DATA;
|
||||
import static org.nuclearfog.twidda.backend.ListManager.Action.DEL_USER;
|
||||
import static org.nuclearfog.twidda.backend.UserLoader.NO_CURSOR;
|
||||
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.DEL_USER_LIST;
|
||||
@ -159,11 +159,12 @@ public class UserFragment extends ListFragment implements UserClickListener,
|
||||
public void onUserClick(User user) {
|
||||
if (!isRefreshing()) {
|
||||
Intent intent = new Intent(requireContext(), UserProfile.class);
|
||||
intent.putExtra(KEY_PROFILE_ID, user.getId());
|
||||
intent.putExtra(KEY_PROFILE_DATA, user);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFooterClick(long cursor) {
|
||||
if (userTask != null && userTask.getStatus() != RUNNING) {
|
||||
|
@ -18,8 +18,7 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
import static org.nuclearfog.twidda.activity.ListDetail.KEY_CURRENT_USER_OWNS;
|
||||
import static org.nuclearfog.twidda.activity.ListDetail.KEY_LISTDETAIL_ID;
|
||||
import static org.nuclearfog.twidda.activity.ListDetail.KEY_LIST_DATA;
|
||||
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID;
|
||||
import static org.nuclearfog.twidda.backend.ListLoader.NO_CURSOR;
|
||||
import static org.nuclearfog.twidda.backend.ListLoader.Type.LOAD_MEMBERSHIPS;
|
||||
@ -128,8 +127,7 @@ public class UserListFragment extends ListFragment implements ListClickListener
|
||||
@Override
|
||||
public void onListClick(UserList listItem) {
|
||||
Intent listIntent = new Intent(requireContext(), ListDetail.class);
|
||||
listIntent.putExtra(KEY_LISTDETAIL_ID, listItem.getId());
|
||||
listIntent.putExtra(KEY_CURRENT_USER_OWNS, listItem.isListOwner());
|
||||
listIntent.putExtra(KEY_LIST_DATA, listItem);
|
||||
startActivityForResult(listIntent, REQUEST_OPEN_LIST);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user