This commit is contained in:
nuclearfog 2020-06-05 15:19:02 +02:00
parent 53bce045d3
commit 945c6d3e19
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
11 changed files with 46 additions and 37 deletions

View File

@ -58,8 +58,6 @@ import static org.nuclearfog.twidda.activity.TweetPopup.KEY_TWEETPOPUP_REPLYID;
import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_ID;
import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_MODE;
import static org.nuclearfog.twidda.activity.UserDetail.USERLIST_RETWEETS;
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.fragment.TweetFragment.INTENT_TWEET_REMOVED_ID;
import static org.nuclearfog.twidda.fragment.TweetFragment.RETURN_TWEET_CHANGED;
@ -450,15 +448,16 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
*/
public void onError(EngineException error) {
ErrorHandler.handleFailure(this, error);
EngineException.ErrorType errorType = error.getErrorType();
if (tweet != null) {
if (errorType == RESOURCE_NOT_FOUND || errorType == NOT_AUTHORIZED) {
if (error.resourceNotFound()) {
Bundle param = getIntent().getExtras();
if (param != null) {
Intent returnData = new Intent();
returnData.putExtra(INTENT_TWEET_REMOVED_ID, tweet.getId());
long tweetID = param.getLong(KEY_TWEET_ID);
returnData.putExtra(INTENT_TWEET_REMOVED_ID, tweetID);
setResult(RETURN_TWEET_CHANGED, returnData);
finish();
}
} else {
finish();
} else if (tweet == null) {
finish();
}
}

View File

@ -164,7 +164,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
adapter.setupProfilePage(userId);
profileAsync.execute(userId);
} else {
String username = param.getString(KEY_PROFILE_NAME);
String username = param.getString(KEY_PROFILE_NAME, "");
adapter.setupProfilePage(username);
profileAsync.execute(username);
}

View File

@ -13,8 +13,6 @@ import org.nuclearfog.twidda.fragment.MessageFragment;
import java.lang.ref.WeakReference;
import java.util.List;
import static org.nuclearfog.twidda.backend.engine.EngineException.ErrorType.RESOURCE_NOT_FOUND;
/**
* task to download a direct message list from twitter and handle message actions
@ -81,7 +79,7 @@ public class MessageListLoader extends AsyncTask<Long, Void, List<Message>> {
}
} catch (EngineException twException) {
this.twException = twException;
if (twException.getErrorType() == RESOURCE_NOT_FOUND)
if (twException.resourceNotFound())
db.deleteMessage(messageId);
} catch (Exception exception) {
exception.printStackTrace();
@ -97,7 +95,7 @@ public class MessageListLoader extends AsyncTask<Long, Void, List<Message>> {
callback.get().setData(messages);
} else if (twException != null) {
callback.get().onError(twException);
if (twException.getErrorType() == RESOURCE_NOT_FOUND) {
if (twException.resourceNotFound()) {
callback.get().removeItem(id);
}
} else if (action == Action.DEL) {

View File

@ -57,13 +57,13 @@ public class ProfileLoader extends AsyncTask<Object, TwitterUser, UserProperties
try {
switch (action) {
case LDR_PROFILE:
if (userId > 0) {
if (userId > 0) { // search user by ID
user = db.getUser(userId);
if (user != null) {
publishProgress(user);
}
user = mTwitter.getUser(userId);
} else {
} else { // Search user by name
user = mTwitter.getUser(username);
}
publishProgress(user);

View File

@ -99,7 +99,7 @@ public class TweetListLoader extends AsyncTask<Object, Void, List<Tweet>> {
case USR_TWEETS:
page = (int) param[1];
if (param[0] instanceof Long) {
if (param[0] instanceof Long) { // search by user ID
id = (long) param[0];
if (sinceId == LIST_EMPTY) {
tweets = db.getUserTweets(id);
@ -111,16 +111,15 @@ public class TweetListLoader extends AsyncTask<Object, Void, List<Tweet>> {
tweets = mTwitter.getUserTweets(id, sinceId, page);
db.storeUserTweets(tweets);
}
} else if (param[0] instanceof String) {
} else if (param[0] instanceof String) { // search by username
search = (String) param[0];
tweets = mTwitter.getUserTweets(search, sinceId, page);
db.storeUserTweets(tweets);
}
break;
case USR_FAVORS:
page = (int) param[1];
if (param[0] instanceof Long) {
if (param[0] instanceof Long) { // search by user ID
id = (long) param[0];
if (sinceId == LIST_EMPTY) {
tweets = db.getUserFavs(id);
@ -132,7 +131,7 @@ public class TweetListLoader extends AsyncTask<Object, Void, List<Tweet>> {
tweets = mTwitter.getUserFavs(id, page);
db.storeUserFavs(tweets, id);
}
} else if (param[0] instanceof String) {
} else if (param[0] instanceof String) { // search by username
search = (String) param[0];
tweets = mTwitter.getUserFavs(search, page);
}

View File

@ -12,8 +12,6 @@ import org.nuclearfog.twidda.database.AppDatabase;
import java.lang.ref.WeakReference;
import static org.nuclearfog.twidda.backend.engine.EngineException.ErrorType.RESOURCE_NOT_FOUND;
/**
* Background task to download tweet informations and to take actions
@ -89,7 +87,7 @@ public class TweetLoader extends AsyncTask<Long, Tweet, Tweet> {
}
} catch (EngineException twException) {
this.twException = twException;
if (twException.getErrorType() == RESOURCE_NOT_FOUND) {
if (twException.resourceNotFound()) {
db.removeStatus(tweetId);
}
} catch (Exception exception) {

View File

@ -2,6 +2,9 @@ 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;
public class EngineException extends Exception {
@ -122,15 +125,26 @@ public class EngineException extends Exception {
/**
* get type of error defined by twitter API
*
* @return type of error {@link ErrorType}
*/
public ErrorType getErrorType() {
return errorType;
}
/**
* check if a resource was not found or current user is not authorized
*
* @return true if resource not found or access denied
*/
public boolean resourceNotFound() {
return errorType == RESOURCE_NOT_FOUND || errorType == NOT_AUTHORIZED;
}
/**
* return time to wait after unlock access in seconds
*
* @return time in seconds
*/
public int getTimeToWait() {

View File

@ -105,7 +105,7 @@ public class MessageFragment extends Fragment implements OnRefreshListener, OnIt
@Override
public void onLinkClick(String link) {
if (getContext() != null && reload != null && !reload.isRefreshing()) {
if (getContext() != null && !reload.isRefreshing()) {
if (TweetDetail.linkPattern.matcher(link).matches()) {
Intent intent = new Intent(getContext(), TweetDetail.class);
intent.setData(Uri.parse(link));
@ -124,7 +124,7 @@ public class MessageFragment extends Fragment implements OnRefreshListener, OnIt
@Override
public void onClick(final Message message, Action action) {
if (getContext() != null && reload != null && !reload.isRefreshing()) {
if (getContext() != null && !reload.isRefreshing()) {
switch (action) {
case ANSWER:
Intent sendDm = new Intent(getContext(), MessagePopup.class);

View File

@ -79,8 +79,9 @@ public class TrendFragment extends Fragment implements OnRefreshListener, TrendC
@Override
public void onRefresh() {
if (trendTask != null && trendTask.getStatus() != RUNNING)
if (trendTask != null && trendTask.getStatus() != RUNNING) {
load();
}
}
@ -96,7 +97,7 @@ public class TrendFragment extends Fragment implements OnRefreshListener, TrendC
@Override
public void onReset() {
if (getView() != null) {
if (reload != null && list != null && adapter != null) {
reload.setProgressBackgroundColorSchemeColor(settings.getHighlightColor());
list.setAdapter(adapter); // force redrawing list
adapter.clear();
@ -107,7 +108,7 @@ public class TrendFragment extends Fragment implements OnRefreshListener, TrendC
@Override
public void onTabChange() {
if (getView() != null) {
if (list != null) {
list.smoothScrollToPosition(0);
}
}
@ -127,7 +128,7 @@ public class TrendFragment extends Fragment implements OnRefreshListener, TrendC
* @return true if list is empty
*/
public boolean isEmpty() {
return adapter == null || adapter.isEmpty();
return adapter.isEmpty();
}

View File

@ -128,7 +128,7 @@ public class TweetFragment extends Fragment implements OnRefreshListener, TweetC
@Override
public void onReset() {
if (getView() != null) {
if (reload != null && list != null && adapter != null) {
reload.setProgressBackgroundColorSchemeColor(settings.getHighlightColor());
list.setAdapter(adapter); // force redrawing list
adapter.clear();
@ -139,7 +139,7 @@ public class TweetFragment extends Fragment implements OnRefreshListener, TweetC
@Override
public void onTabChange() {
if (getView() != null) {
if (list != null) {
list.smoothScrollToPosition(0);
}
}
@ -222,17 +222,17 @@ public class TweetFragment extends Fragment implements OnRefreshListener, TweetC
case TWEET_FRAG_TWEETS:
tweetTask = new TweetListLoader(this, Action.USR_TWEETS);
if (param.containsKey(KEY_FRAG_TWEET_ID))
if (param.containsKey(KEY_FRAG_TWEET_ID)) // Search with User ID
tweetTask.execute(id, 1);
else if (param.containsKey(KEY_FRAG_TWEET_SEARCH))
else if (param.containsKey(KEY_FRAG_TWEET_SEARCH)) // With user screen name
tweetTask.execute(search, 1);
break;
case TWEET_FRAG_FAVORS:
tweetTask = new TweetListLoader(this, Action.USR_FAVORS);
if (param.containsKey(KEY_FRAG_TWEET_ID))
if (param.containsKey(KEY_FRAG_TWEET_ID)) // Search with User ID
tweetTask.execute(id, 1);
else if (param.containsKey(KEY_FRAG_TWEET_SEARCH))
else if (param.containsKey(KEY_FRAG_TWEET_SEARCH)) // With user screen name
tweetTask.execute(search, 1);
break;

View File

@ -97,7 +97,7 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
@Override
public void onUserClick(TwitterUser user) {
if (getContext() != null && reload != null && !reload.isRefreshing()) {
if (getContext() != null && !reload.isRefreshing()) {
Intent intent = new Intent(getContext(), UserProfile.class);
intent.putExtra(KEY_PROFILE_ID, user.getId());
startActivity(intent);
@ -107,7 +107,7 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
@Override
public void onTabChange() {
if (getView() != null) {
if (list != null) {
list.smoothScrollToPosition(0);
}
}