performance improvements

This commit is contained in:
nuclearfog 2020-12-22 22:35:19 +01:00
parent c95fca519a
commit 6a3c7bd2a2
No known key found for this signature in database
GPG Key ID: D5490E4A81F97B14
10 changed files with 109 additions and 57 deletions

View File

@ -37,7 +37,6 @@ import java.util.regex.Pattern;
import static android.os.AsyncTask.Status.RUNNING; 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_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_TITLE;
import static org.nuclearfog.twidda.activity.ListPopup.KEY_LIST_VISIB; import static org.nuclearfog.twidda.activity.ListPopup.KEY_LIST_VISIB;
import static org.nuclearfog.twidda.backend.ListAction.Action.DELETE; 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 * 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 * 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 * Request code for list editing
@ -113,20 +117,28 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
Bundle param = getIntent().getExtras(); Bundle param = getIntent().getExtras();
if (param != null) { if (param != null) {
listId = param.getLong(KEY_LISTDETAIL_ID); boolean currentUserOwnsList;
boolean currentUserOwnsList = param.getBoolean(KEY_CURRENT_USER_OWNS, false); if (param.containsKey(KEY_LIST_DATA)) {
adapter.setupListContentPage(listId, currentUserOwnsList); userList = (UserList) param.getSerializable(KEY_LIST_DATA);
Tab tweetTab = tablayout.getTabAt(0); currentUserOwnsList = userList.isListOwner();
Tab userTab = tablayout.getTabAt(1); listId = userList.getId();
Tab subscrTab = tablayout.getTabAt(2); } else {
if (tweetTab != null && userTab != null && subscrTab != null) { currentUserOwnsList = param.getBoolean(KEY_LIST_OWNER, false);
tweetTab.setIcon(R.drawable.list); listId = param.getLong(KEY_LIST_ID);
userTab.setIcon(R.drawable.user);
subscrTab.setIcon(R.drawable.subscriber);
} }
toolbar.setTitle(""); adapter.setupListContentPage(listId, currentUserOwnsList);
setSupportActionBar(toolbar);
} }
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); FontTool.setViewFontAndColor(settings, root);
} }
@ -135,6 +147,11 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
if (listLoaderTask == null && userList == null) { if (listLoaderTask == null && userList == null) {
if (userList != null) {
toolbar.setTitle(userList.getTitle());
toolbar.setSubtitle(userList.getDescription());
invalidateOptionsMenu();
}
loadList(); loadList();
} }
} }
@ -190,7 +207,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
int itemId = item.getItemId(); int itemId = item.getItemId();
if (itemId == R.id.menu_list_edit) { if (itemId == R.id.menu_list_edit) {
Intent editList = new Intent(this, ListPopup.class); 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_TITLE, userList.getTitle());
editList.putExtra(KEY_LIST_DESCR, userList.getDescription()); editList.putExtra(KEY_LIST_DESCR, userList.getDescription());
editList.putExtra(KEY_LIST_VISIB, !userList.isPrivate()); editList.putExtra(KEY_LIST_VISIB, !userList.isPrivate());
@ -351,11 +368,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
* load list information * load list information
*/ */
private void loadList() { private void loadList() {
Bundle param = getIntent().getExtras(); listLoaderTask = new ListAction(this, LOAD);
if (param != null) { listLoaderTask.execute(listId);
long listId = param.getLong(KEY_LISTDETAIL_ID);
listLoaderTask = new ListAction(this, LOAD);
listLoaderTask.execute(listId);
}
} }
} }

View File

@ -73,12 +73,17 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
/** /**
* ID of the tweet to open. required * 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 * 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 * regex pattern of a tweet URL
@ -96,6 +101,7 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
private TweetAction statusAsync; private TweetAction statusAsync;
@Nullable @Nullable
private Tweet tweet; private Tweet tweet;
private long tweetId;
@Override @Override
@ -127,8 +133,15 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
Bundle param = getIntent().getExtras(); Bundle param = getIntent().getExtras();
FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager()); FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
if (param != null) { if (param != null) {
long tweetId = param.getLong(KEY_TWEET_ID); String username;
String username = param.getString(KEY_TWEET_NAME, ""); 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); adapter.setupTweetPage(tweetId, username);
} }
@ -156,12 +169,14 @@ public class TweetActivity extends AppCompatActivity implements OnClickListener,
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
Bundle param = getIntent().getExtras(); if (statusAsync == null) {
if (statusAsync == null && param != null) { if (tweet == null) {
if (param.containsKey(KEY_TWEET_ID)) {
long tweetId = param.getLong(KEY_TWEET_ID);
statusAsync = new TweetAction(this, tweetId); statusAsync = new TweetAction(this, tweetId);
statusAsync.execute(Action.LD_DB);
} else {
statusAsync = new TweetAction(this, tweet.getId());
statusAsync.execute(Action.LOAD); 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) { else if (v.getId() == R.id.profileimage_detail) {
if (tweet != null) { if (tweet != null) {
Intent profile = new Intent(getApplicationContext(), UserProfile.class); 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); startActivity(profile);
} }
} }

View File

@ -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_UNBLOCK;
import static org.nuclearfog.twidda.backend.UserAction.Action.ACTION_UNFOLLOW; 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.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_BLOCK;
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.PROFILE_MUTE; import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.PROFILE_MUTE;
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.PROFILE_UNFOLLOW; 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"; 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} * request code for {@link ProfileEditor}
*/ */
@ -126,6 +132,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
private UserAction profileAsync; private UserAction profileAsync;
private Relation relation; private Relation relation;
private User user; private User user;
private String username;
private long userId;
@Override @Override
@ -189,8 +197,14 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
Bundle param = getIntent().getExtras(); Bundle param = getIntent().getExtras();
if (param != null) { if (param != null) {
long userId = param.getLong(KEY_PROFILE_ID, -1); if (param.containsKey(KEY_PROFILE_DATA)) {
String username = param.getString(KEY_PROFILE_NAME, ""); 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); adapter.setupProfilePage(userId, username);
} }
Tab tweetTab = tabLayout.getTabAt(0); Tab tweetTab = tabLayout.getTabAt(0);
@ -212,12 +226,14 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, O
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
Bundle param = getIntent().getExtras(); if (profileAsync == null) {
if (profileAsync == null && param != null) {
long userId = param.getLong(KEY_PROFILE_ID, -1);
String username = param.getString(KEY_PROFILE_NAME, "");
profileAsync = new UserAction(this, userId, username); profileAsync = new UserAction(this, userId, username);
profileAsync.execute(LDR_PROFILE); if (user == null) {
profileAsync.execute(PROFILE_DB);
} else {
profileAsync.execute(PROFILE_lOAD);
setUser(user);
}
} }
} }

View File

@ -28,6 +28,10 @@ public class TweetAction extends AsyncTask<TweetAction.Action, Tweet, TweetActio
* Load tweet * Load tweet
*/ */
LOAD, LOAD,
/**
* load tweet from database first
*/
LD_DB,
/** /**
* retweet tweet * retweet tweet
*/ */
@ -82,14 +86,16 @@ public class TweetAction extends AsyncTask<TweetAction.Action, Tweet, TweetActio
@Override @Override
protected Action doInBackground(Action[] action) { protected Action doInBackground(Action[] action) {
try { try {
boolean updateStatus = false;
switch (action[0]) { switch (action[0]) {
case LOAD: case LD_DB:
boolean updateStatus = false;
Tweet tweet = db.getStatus(tweetId); Tweet tweet = db.getStatus(tweetId);
if (tweet != null) { if (tweet != null) {
publishProgress(tweet); publishProgress(tweet);
updateStatus = true; updateStatus = true;
} }
case LOAD:
tweet = mTwitter.getStatus(tweetId); tweet = mTwitter.getStatus(tweetId);
publishProgress(tweet); publishProgress(tweet);
if (updateStatus) { if (updateStatus) {

View File

@ -25,7 +25,11 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
/** /**
* Load profile information * Load profile information
*/ */
LDR_PROFILE, PROFILE_lOAD,
/**
* load profile from database first
*/
PROFILE_DB,
/** /**
* follow user * follow user
*/ */
@ -86,7 +90,7 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
protected Relation doInBackground(Action[] action) { protected Relation doInBackground(Action[] action) {
try { try {
switch (action[0]) { switch (action[0]) {
case LDR_PROFILE: case PROFILE_DB:
// load user information from database // load user information from database
User user; User user;
if (userId > 0) { if (userId > 0) {
@ -95,6 +99,8 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
publishProgress(user); publishProgress(user);
} }
} }
case PROFILE_lOAD:
// load user information from twitter // load user information from twitter
user = mTwitter.getUser(userId, screenName); user = mTwitter.getUser(userId, screenName);
publishProgress(user); publishProgress(user);

View File

@ -2,7 +2,6 @@ package org.nuclearfog.twidda.backend.engine;
import twitter4j.TwitterException; 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.RESOURCE_NOT_FOUND;
import static org.nuclearfog.twidda.backend.engine.EngineException.ErrorType.USER_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 * @return true if resource not found or access denied
*/ */
public boolean resourceNotFound() { public boolean resourceNotFound() {
return errorType == RESOURCE_NOT_FOUND || errorType == NOT_AUTHORIZED || errorType == USER_NOT_FOUND; return errorType == RESOURCE_NOT_FOUND || errorType == USER_NOT_FOUND;
} }

View File

@ -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_ID;
import static org.nuclearfog.twidda.activity.TweetActivity.KEY_TWEET_NAME; 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.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; 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: case PROFILE:
Intent profile = new Intent(requireContext(), UserProfile.class); Intent profile = new Intent(requireContext(), UserProfile.class);
profile.putExtra(KEY_PROFILE_ID, message.getSender().getId()); profile.putExtra(KEY_PROFILE_DATA, message.getSender());
startActivity(profile); startActivity(profile);
break; break;
} }

View File

@ -18,8 +18,7 @@ import org.nuclearfog.twidda.database.GlobalSettings;
import java.util.List; import java.util.List;
import static android.os.AsyncTask.Status.RUNNING; 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_DATA;
import static org.nuclearfog.twidda.activity.TweetActivity.KEY_TWEET_NAME;
/** /**
* #Fragment class for a list of tweets * #Fragment class for a list of tweets
@ -131,8 +130,7 @@ public class TweetFragment extends ListFragment implements TweetClickListener {
if (tweet.getEmbeddedTweet() != null) if (tweet.getEmbeddedTweet() != null)
tweet = tweet.getEmbeddedTweet(); tweet = tweet.getEmbeddedTweet();
Intent tweetIntent = new Intent(requireContext(), TweetActivity.class); Intent tweetIntent = new Intent(requireContext(), TweetActivity.class);
tweetIntent.putExtra(KEY_TWEET_ID, tweet.getId()); tweetIntent.putExtra(KEY_TWEET_DATA, tweet);
tweetIntent.putExtra(KEY_TWEET_NAME, tweet.getUser().getScreenname());
startActivityForResult(tweetIntent, REQUEST_TWEET_CHANGED); startActivityForResult(tweetIntent, REQUEST_TWEET_CHANGED);
} }
} }

View File

@ -22,7 +22,7 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.database.GlobalSettings; import org.nuclearfog.twidda.database.GlobalSettings;
import static android.os.AsyncTask.Status.RUNNING; 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.ListManager.Action.DEL_USER;
import static org.nuclearfog.twidda.backend.UserLoader.NO_CURSOR; import static org.nuclearfog.twidda.backend.UserLoader.NO_CURSOR;
import static org.nuclearfog.twidda.backend.utils.DialogBuilder.DialogType.DEL_USER_LIST; 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) { public void onUserClick(User user) {
if (!isRefreshing()) { if (!isRefreshing()) {
Intent intent = new Intent(requireContext(), UserProfile.class); Intent intent = new Intent(requireContext(), UserProfile.class);
intent.putExtra(KEY_PROFILE_ID, user.getId()); intent.putExtra(KEY_PROFILE_DATA, user);
startActivity(intent); startActivity(intent);
} }
} }
@Override @Override
public void onFooterClick(long cursor) { public void onFooterClick(long cursor) {
if (userTask != null && userTask.getStatus() != RUNNING) { if (userTask != null && userTask.getStatus() != RUNNING) {

View File

@ -18,8 +18,7 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.database.GlobalSettings; import org.nuclearfog.twidda.database.GlobalSettings;
import static android.os.AsyncTask.Status.RUNNING; 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_LIST_DATA;
import static org.nuclearfog.twidda.activity.ListDetail.KEY_LISTDETAIL_ID;
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID; 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.NO_CURSOR;
import static org.nuclearfog.twidda.backend.ListLoader.Type.LOAD_MEMBERSHIPS; import static org.nuclearfog.twidda.backend.ListLoader.Type.LOAD_MEMBERSHIPS;
@ -128,8 +127,7 @@ public class UserListFragment extends ListFragment implements ListClickListener
@Override @Override
public void onListClick(UserList listItem) { public void onListClick(UserList listItem) {
Intent listIntent = new Intent(requireContext(), ListDetail.class); Intent listIntent = new Intent(requireContext(), ListDetail.class);
listIntent.putExtra(KEY_LISTDETAIL_ID, listItem.getId()); listIntent.putExtra(KEY_LIST_DATA, listItem);
listIntent.putExtra(KEY_CURRENT_USER_OWNS, listItem.isListOwner());
startActivityForResult(listIntent, REQUEST_OPEN_LIST); startActivityForResult(listIntent, REQUEST_OPEN_LIST);
} }