bug fix, improved error handling, excluded exception printstacktrace for release builds

This commit is contained in:
nuclearfog 2023-05-24 22:03:00 +02:00
parent 432b277c6e
commit 2624d992c3
No known key found for this signature in database
GPG Key ID: 03488A185C476379
68 changed files with 403 additions and 252 deletions

View File

@ -12,7 +12,7 @@ public abstract class ConnectionException extends Exception {
/**
* indicates a task interrupt
*/
protected static final int INTERRUPTED = -1;
public static final int INTERRUPTED = -1;
/**
* defines an error which is not listed here
@ -124,6 +124,8 @@ public abstract class ConnectionException extends Exception {
*/
public static final int NETWORK_CONNECTION = 21;
/**
* error parsing json format
*/

View File

@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
@ -1670,8 +1671,10 @@ public class Mastodon implements Connection {
String max_id_str = headerStr.substring(m.start() + 7, m.end());
cursors[1] = Long.parseLong(max_id_str);
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (NumberFormatException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return cursors;

View File

@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import java.io.IOException;
@ -40,11 +41,6 @@ public class MastodonException extends ConnectionException {
*/
private static final int ERROR_JSON = -3;
/**
* caused by interrupt
*/
private static final int ERROR_INTERRUPTED = -4;
private int httpCode = 0;
private int errorCode = UNKNOWN_ERROR;
@ -63,7 +59,7 @@ public class MastodonException extends ConnectionException {
} else if (e instanceof ConnectException) {
errorCode = NO_CONNECTION;
} else if (getCause() instanceof InterruptedException) {
errorCode = ERROR_INTERRUPTED;
errorCode = INTERRUPTED;
}
}
@ -84,8 +80,10 @@ public class MastodonException extends ConnectionException {
errorMessage = title;
else
errorMessage = title + ": " + descr;
} catch (JSONException | IOException e) {
e.printStackTrace();
} catch (JSONException | IOException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
}

View File

@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.twitter.TwitterException;
@ -982,8 +983,10 @@ public class TwitterV1 implements Connection {
message.addSender(user);
}
result.add(message);
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return result;
@ -1250,8 +1253,10 @@ public class TwitterV1 implements Connection {
try {
JSONObject tweetJson = array.getJSONObject(i);
statuses.add(new TweetV1(tweetJson, host, homeId));
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return statuses;
@ -1384,8 +1389,10 @@ public class TwitterV1 implements Connection {
for (int i = 0; i < array.length(); i++) {
try {
users.add(new UserV1(array.getJSONObject(i), homeId));
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return users;
@ -1480,8 +1487,10 @@ public class TwitterV1 implements Connection {
for (int pos = 0; pos < array.length(); pos++) {
try {
result.add(new UserListV1(array.getJSONObject(pos), currentId));
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return result;

View File

@ -6,6 +6,7 @@ import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.LocationV2Map;
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.MediaV2Map;
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.PollV2Map;
@ -199,8 +200,10 @@ public class TweetV2 implements Status {
} else if (referenceType.equals("retweeted")) {
retweetId = Long.parseLong(tweetReference.optString("id"));
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (NumberFormatException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
}

View File

@ -38,9 +38,9 @@ public class AccountLoader extends AsyncExecutor<AccountLoader.AccountParameter,
return new AccountResult(AccountResult.DELETE, request.id, null);
}
} catch (Exception e) {
e.printStackTrace();
return new AccountResult(AccountResult.ERROR, 0L, null);
}
return new AccountResult(AccountResult.ERROR, 0L, null);
return null;
}
/**

View File

@ -89,7 +89,7 @@ public abstract class AsyncExecutor<Parameter, Result> {
*
* @param result result of the background task
*/
private synchronized void onPostExecute(final Result result, WeakReference<AsyncCallback<Result>> callbackReference) {
private synchronized void onPostExecute(@Nullable final Result result, WeakReference<AsyncCallback<Result>> callbackReference) {
uiHandler.post(new Runnable() {
@Override
public void run() {

View File

@ -39,9 +39,9 @@ public class DatabaseAction extends AsyncExecutor<DatabaseAction.DatabaseParam,
return new DatabaseResult(DatabaseResult.LOGOUT);
}
} catch (Exception exception) {
exception.printStackTrace();
return new DatabaseResult(DatabaseResult.ERROR);
}
return new DatabaseResult(DatabaseResult.ERROR);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -46,9 +47,11 @@ public class DomainAction extends AsyncExecutor<DomainAction.DomainParam, Domain
} catch (ConnectionException exception) {
return new DomainResult(DomainResult.ERROR, param.index, null, param.domain, exception);
} catch (Exception exception) {
exception.printStackTrace();
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new DomainResult(DomainResult.ERROR, param.index, null, param.domain, null);
return null;
}
/**

View File

@ -4,6 +4,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
import org.nuclearfog.twidda.database.AppDatabase;
@ -37,10 +38,12 @@ public class EmojiLoader extends AsyncExecutor<Void, List<Emoji>> {
// get online emojis
result = connection.getEmojis();
db.saveEmojis(result);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
// get offline emojis
result = db.getEmojis();
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return result;
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -60,10 +61,12 @@ public class FilterLoader extends AsyncExecutor<FilterLoader.FilterParam, Filter
}
} catch (ConnectionException exception) {
return new FilterResult(FilterResult.ERROR, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new FilterResult(FilterResult.ERROR, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -46,9 +47,11 @@ public class HashtagAction extends AsyncExecutor<HashtagAction.HashtagParam, Has
} catch (ConnectionException exception) {
return new HashtagResult(HashtagResult.ERROR, null, exception);
} catch (Exception exception) {
exception.printStackTrace();
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new HashtagResult(HashtagResult.ERROR, null, null);
return null;
}
/**

View File

@ -6,6 +6,7 @@ import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -65,10 +66,12 @@ public class ImageLoader extends AsyncExecutor<ImageLoader.ImageParameter, Image
return new ImageResult(Uri.fromFile(imageFile), null);
} catch (ConnectionException exception) {
return new ImageResult(null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new ImageResult(null, null);
return null;
}
/**

View File

@ -2,6 +2,7 @@ package org.nuclearfog.twidda.backend.async;
import androidx.annotation.NonNull;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.ui.activities.MediaActivity;
import java.io.InputStream;
@ -27,8 +28,10 @@ public class ImageSaver extends AsyncExecutor<ImageSaver.ImageParam, Boolean> {
param.inputStream.close();
param.outputStream.close();
return true;
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return false;
}

View File

@ -4,6 +4,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
import org.nuclearfog.twidda.database.AppDatabase;
@ -44,7 +45,9 @@ public class InstanceLoader extends AsyncExecutor<Void, Instance> {
db.saveInstance(instance);
}
} catch (Exception exception) {
exception.printStackTrace();
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return instance;
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -38,10 +39,12 @@ public class LocationLoader extends AsyncExecutor<Void, LocationLoader.LocationL
return new LocationLoaderResult(locations, null);
} catch (ConnectionException exception) {
return new LocationLoaderResult(null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new LocationLoaderResult(null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -81,10 +82,12 @@ public class LoginAction extends AsyncExecutor<LoginAction.LoginParam, LoginActi
}
} catch (ConnectionException exception) {
return new LoginResult(LoginResult.MODE_ERROR, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new LoginResult(LoginResult.MODE_ERROR, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -60,10 +61,12 @@ public class MessageLoader extends AsyncExecutor<MessageLoader.MessageLoaderPara
if (exception.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND)
db.removeMessage(param.id);
return new MessageLoaderResult(MessageLoaderResult.ERROR, param.index, param.id, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new MessageLoaderResult(MessageLoaderResult.ERROR, param.index, param.id, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -44,12 +45,14 @@ public class MessageUpdater extends AsyncExecutor<MessageUpdate, MessageUpdater.
return new MessageUpdateResult(true, null);
} catch (ConnectionException exception) {
return new MessageUpdateResult(false, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
} finally {
update.close();
}
return new MessageUpdateResult(false, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -55,9 +56,11 @@ public class NotificationAction extends AsyncExecutor<NotificationAction.Notific
}
return new NotificationActionResult(NotificationActionResult.ERROR, param.id, null, exception);
} catch (Exception exception) {
exception.printStackTrace();
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new NotificationActionResult(NotificationActionResult.ERROR, param.id, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -33,8 +34,8 @@ public class NotificationLoader extends AsyncExecutor<NotificationLoader.Notific
@Override
protected NotificationLoaderResult doInBackground(@NonNull NotificationLoaderParam params) {
Notifications result = null;
try {
Notifications result;
if (params.minId == 0L && params.maxId == 0L) {
result = db.getNotifications();
if (result.isEmpty()) {
@ -47,12 +48,15 @@ public class NotificationLoader extends AsyncExecutor<NotificationLoader.Notific
db.saveNotifications(result);
}
}
return new NotificationLoaderResult(result, params.position, null);
} catch (ConnectionException exception) {
return new NotificationLoaderResult(null, params.position, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new NotificationLoaderResult(result, params.position, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -43,10 +44,12 @@ public class PollAction extends AsyncExecutor<PollAction.PollActionParam, PollAc
}
} catch (ConnectionException exception) {
return new PollActionResult(PollActionResult.ERROR, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new PollActionResult(PollActionResult.ERROR, null, null);
return null;
}
/**

View File

@ -4,6 +4,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -34,7 +35,12 @@ public class PushUpdater extends AsyncExecutor <PushUpdate, PushUpdater.PushUpda
return new PushUpdateResult(webpush, null);
} catch (ConnectionException e) {
return new PushUpdateResult(null, e);
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -79,10 +80,12 @@ public class RelationLoader extends AsyncExecutor<RelationLoader.RelationParam,
}
} catch (ConnectionException exception) {
return new RelationResult(RelationResult.ERROR, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new RelationResult(RelationResult.ERROR, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -104,10 +105,12 @@ public class StatusAction extends AsyncExecutor<StatusAction.StatusParam, Status
db.removeStatus(param.id);
}
return new StatusResult(StatusResult.ERROR, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new StatusResult(StatusResult.ERROR, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -35,9 +36,8 @@ public class StatusLoader extends AsyncExecutor<StatusLoader.StatusParameter, St
@Override
protected StatusResult doInBackground(@NonNull StatusParameter param) {
Statuses statuses = null;
int position = param.pos;
try {
Statuses statuses;
switch (param.type) {
case StatusParameter.HOME:
if (param.minId == StatusParameter.NO_ID && param.maxId == StatusParameter.NO_ID) {
@ -52,7 +52,7 @@ public class StatusLoader extends AsyncExecutor<StatusLoader.StatusParameter, St
db.saveHomeTimeline(statuses);
}
}
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.USER:
if (param.minId == StatusParameter.NO_ID && param.maxId == StatusParameter.NO_ID) {
@ -67,7 +67,7 @@ public class StatusLoader extends AsyncExecutor<StatusLoader.StatusParameter, St
db.saveUserTimeline(statuses);
}
}
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.FAVORIT:
if (param.minId == StatusParameter.NO_ID && param.maxId == StatusParameter.NO_ID) {
@ -80,10 +80,10 @@ public class StatusLoader extends AsyncExecutor<StatusLoader.StatusParameter, St
statuses = connection.getUserFavorits(param.id, 0L, param.maxId);
if (param.maxId == StatusParameter.NO_ID) {
db.saveFavoriteTimeline(statuses, param.id);
position = StatusResult.CLEAR;
return new StatusResult(statuses, StatusResult.CLEAR, null);
}
}
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.BOOKMARKS:
if (param.minId == StatusParameter.NO_ID && param.maxId == StatusParameter.NO_ID) {
@ -96,14 +96,14 @@ public class StatusLoader extends AsyncExecutor<StatusLoader.StatusParameter, St
statuses = connection.getUserBookmarks(0L, param.maxId);
if (param.maxId == StatusParameter.NO_ID) {
db.saveBookmarkTimeline(statuses, param.id);
position = StatusResult.CLEAR;
return new StatusResult(statuses, StatusResult.CLEAR, null);
}
}
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.REPLIES_LOCAL:
statuses = db.getReplies(param.id);
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.REPLIES:
if (param.minId == StatusParameter.NO_ID && param.maxId == StatusParameter.NO_ID) {
@ -120,26 +120,28 @@ public class StatusLoader extends AsyncExecutor<StatusLoader.StatusParameter, St
db.saveReplyTimeline(statuses);
}
}
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.SEARCH:
statuses = connection.searchStatuses(param.search, param.minId, param.maxId);
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.USERLIST:
statuses = connection.getUserlistStatuses(param.id, param.minId, param.maxId);
break;
return new StatusResult(statuses, param.pos, null);
case StatusParameter.PUBLIC:
statuses = connection.getPublicTimeline(param.minId, param.maxId);
break;
return new StatusResult(statuses, param.pos, null);
}
} catch (ConnectionException exception) {
return new StatusResult(null, position, exception);
} catch (Exception e) {
e.printStackTrace();
return new StatusResult(null, param.pos, exception);
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new StatusResult(statuses, position, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -50,12 +51,14 @@ public class StatusUpdater extends AsyncExecutor<StatusUpdate, StatusUpdater.Sta
return new StatusUpdateResult(status, null);
} catch (ConnectionException exception) {
return new StatusUpdateResult(null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
} finally {
update.close();
}
return new StatusUpdateResult(null, null);
return null;
}
/**

View File

@ -8,6 +8,7 @@ import android.text.Spannable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
import org.nuclearfog.twidda.backend.helper.MediaStatus;
@ -59,8 +60,11 @@ public class TextEmojiLoader extends AsyncExecutor<TextEmojiLoader.EmojiParam, T
cache.trimCache();
return new EmojiResult(param.id, param.spannable, result);
} catch (Exception exception) {
return new EmojiResult(param.id, param.spannable, null);
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new EmojiResult(param.id, param.spannable, null);
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -33,7 +34,12 @@ public class TranslationLoader extends AsyncExecutor<Long, TranslationLoader.Tra
return new TranslationResult(connection.getStatusTranslation(param), null);
} catch (ConnectionException exception) {
return new TranslationResult(null, exception);
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -58,10 +59,12 @@ public class TrendLoader extends AsyncExecutor<TrendLoader.TrendParameter, Trend
}
} catch (ConnectionException exception) {
return new TrendResult(TrendResult.ERROR, null, param.index, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new TrendResult(TrendResult.ERROR, null, param.index, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -48,10 +49,12 @@ public class UserLoader extends AsyncExecutor<UserLoader.UserParam, UserLoader.U
}
} catch (ConnectionException exception) {
return new UserResult(UserResult.ERROR, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new UserResult(UserResult.ERROR, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -41,12 +42,14 @@ public class UserUpdater extends AsyncExecutor<ProfileUpdate, UserUpdater.UserUp
return new UserUpdateResult(user, null);
} catch (ConnectionException exception) {
return new UserUpdateResult(null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
} finally {
param.close();
}
return new UserUpdateResult(null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -49,10 +50,12 @@ public class UserlistAction extends AsyncExecutor<UserlistAction.ListActionParam
}
} catch (ConnectionException exception) {
return new ListActionResult(ListActionResult.ERROR, param.id, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new ListActionResult(ListActionResult.ERROR, param.id, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -43,10 +44,12 @@ public class UserlistLoader extends AsyncExecutor<UserlistLoader.UserlistParam,
}
} catch (ConnectionException exception) {
return new UserlistResult(UserlistResult.ERROR, param.index, null, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new UserlistResult(UserlistResult.ERROR, param.index, null, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -41,10 +42,12 @@ public class UserlistManager extends AsyncExecutor<UserlistManager.ListManagerPa
}
} catch (ConnectionException exception) {
return new ListManagerResult(ListManagerResult.ERROR, param.username, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new ListManagerResult(ListManagerResult.ERROR, param.username, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -42,10 +43,12 @@ public class UserlistUpdater extends AsyncExecutor<UserListUpdate, UserlistUpdat
}
} catch (ConnectionException exception) {
return new ListUpdateResult(null, false, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new ListUpdateResult(null, false, null);
return null;
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager;
@ -31,59 +32,60 @@ public class UsersLoader extends AsyncExecutor<UsersLoader.UserParam, UsersLoade
@Override
protected UserResult doInBackground(@NonNull UserParam param) {
Users users = null;
try {
switch (param.type) {
case UserParam.FOLLOWS:
users = connection.getFollower(param.id, param.cursor);
break;
Users users = connection.getFollower(param.id, param.cursor);
return new UserResult(users, param.index, null);
case UserParam.FRIENDS:
users = connection.getFollowing(param.id, param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.REPOST:
users = connection.getRepostingUsers(param.id, param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.FAVORIT:
users = connection.getFavoritingUsers(param.id, param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.SEARCH:
users = connection.searchUsers(param.search, param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.SUBSCRIBER:
users = connection.getListSubscriber(param.id, param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.LISTMEMBER:
users = connection.getListMember(param.id, param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.BLOCK:
users = connection.getBlockedUsers(param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.MUTE:
users = connection.getMutedUsers(param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.REQUEST_IN:
users = connection.getIncomingFollowRequests(param.cursor);
break;
return new UserResult(users, param.index, null);
case UserParam.REQUEST_OUT:
users = connection.getOutgoingFollowRequests(param.cursor);
break;
return new UserResult(users, param.index, null);
}
} catch (ConnectionException exception) {
return new UserResult(null, param.index, exception);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
return new UserResult(users, param.index, null);
return null;
}
/**

View File

@ -6,6 +6,8 @@ import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@ -79,8 +81,10 @@ public class MediaStatus implements Serializable, Closeable {
mimeType = resolver.getType(uri);
// check if stream is valid
return inputStream != null && mimeType != null && inputStream.available() > 0;
} catch (IOException e) {
e.printStackTrace();
} catch (IOException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return false;

View File

@ -9,6 +9,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.documentfile.provider.DocumentFile;
import org.nuclearfog.twidda.BuildConfig;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@ -162,8 +164,10 @@ public class ProfileUpdate implements Closeable {
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (IOException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
return false;
}
return true;

View File

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.documentfile.provider.DocumentFile;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.backend.helper.MediaStatus;
import org.nuclearfog.twidda.model.Instance;
import org.nuclearfog.twidda.model.Media;
@ -471,8 +472,10 @@ public class StatusUpdate implements Serializable, Closeable {
}
}
} catch (Exception e) {
e.printStackTrace();
} catch (Exception exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
return false;
}
return true;

View File

@ -7,6 +7,8 @@ import android.util.LruCache;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.BuildConfig;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -69,8 +71,10 @@ public class ImageCache {
}
}
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (SecurityException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
@ -114,10 +118,10 @@ public class ImageCache {
output.close();
files.put(key, file);
}
} catch (
IOException |
SecurityException e) {
e.printStackTrace();
} catch (IOException | SecurityException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
}
@ -142,9 +146,10 @@ public class ImageCache {
cache.put(key, result);
}
}
} catch (
SecurityException e) {
e.printStackTrace();
} catch (SecurityException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
return result;

View File

@ -38,6 +38,7 @@ import androidx.viewpager2.widget.ViewPager2;
import com.kyleduo.switchbutton.SwitchButton;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.config.GlobalSettings;
@ -271,10 +272,11 @@ public class AppStyles {
image = blur.transform(crop.transform(image));
toolbarBackground.setImageBitmap(image);
}
} catch (Exception e) {
} catch (Exception exception) {
// exception may occur when there is not enough free memory
// reset toolbar background
e.printStackTrace();
if (BuildConfig.DEBUG)
exception.printStackTrace();
toolbarBackground.setImageResource(0);
}
}

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.utils;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.Nullable;
@ -9,32 +10,46 @@ import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.config.GlobalSettings;
/**
* This class handles {@link ConnectionException}
* and prints Toast messages to current activity
* This class provides methods to handle {@link ConnectionException}
*
* @author nuclearfog
*/
public class ErrorHandler {
public class ErrorUtils {
private ErrorHandler() {
private ErrorUtils() {
}
/**
* show toast notification with detailed error message
*
* @param exception connection exception
*/
public static void showErrorMessage(Context context, @Nullable ConnectionException exception) {
if (context != null) {
String errorMessage = getErrorMessage(context, exception);
if (errorMessage != null) {
Toast.makeText(context.getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
}
}
}
/**
* get error message string
*
* @param context application context
* @param error Twitter error
* @param exception connection exception
* @return message string
*/
public static String getErrorMessage(Context context, @Nullable ConnectionException error) {
if (error != null) {
switch (error.getErrorCode()) {
@Nullable
public static String getErrorMessage(Context context, @Nullable ConnectionException exception) {
if (exception != null) {
switch (exception.getErrorCode()) {
case ConnectionException.RATE_LIMIT_EX:
if (error.getTimeToWait() > 0) {
if (exception.getTimeToWait() > 0) {
String errMsg = context.getString(R.string.error_limit_exceeded);
if (error.getTimeToWait() >= 60)
errMsg += " " + error.getTimeToWait() / 60 + "m";
errMsg += " " + error.getTimeToWait() % 60 + "s";
if (exception.getTimeToWait() >= 60)
errMsg += " " + exception.getTimeToWait() / 60 + "m";
errMsg += " " + exception.getTimeToWait() % 60 + "s";
return errMsg;
}
return context.getString(R.string.error_rate_limit);
@ -55,6 +70,9 @@ public class ErrorHandler {
case ConnectionException.STATUS_LENGTH:
return context.getString(R.string.error_status_length);
case ConnectionException.INTERRUPTED:
return null; // ignore exceptions caused by task termination
case ConnectionException.DUPLICATE_STATUS:
return context.getString(R.string.error_duplicate_status);
@ -104,12 +122,15 @@ public class ErrorHandler {
return context.getString(R.string.error_json_format);
case ConnectionException.ERROR_NOT_DEFINED:
if (error.getMessage() != null && !error.getMessage().isEmpty()) {
return error.getMessage();
if (exception.getMessage() != null && !exception.getMessage().isEmpty()) {
return exception.getMessage();
}
break;
default:
return context.getString(R.string.error_not_defined);
}
}
return context.getString(R.string.error_not_defined);
return null;
}
}

View File

@ -3,6 +3,7 @@ package org.nuclearfog.twidda.backend.utils;
import android.content.res.Resources;
import android.util.Base64;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.R;
import java.io.IOException;
@ -213,8 +214,9 @@ public class StringUtils {
return result.getTime() + TIME_ZONE.getOffset(System.currentTimeMillis());
break;
}
} catch (ParseException e) {
e.printStackTrace();
} catch (ParseException exception) {
if (BuildConfig.DEBUG)
exception.printStackTrace();
}
return DEFAULT_TIME;
}

View File

@ -6,6 +6,8 @@ import android.database.sqlite.SQLiteException;
import androidx.annotation.NonNull;
import org.nuclearfog.twidda.BuildConfig;
import java.io.File;
/**
@ -430,9 +432,10 @@ public class DatabaseAdapter {
if (instance == null) {
try {
instance = new DatabaseAdapter(context.getApplicationContext());
} catch (SQLiteException e) {
} catch (SQLiteException exception) {
// if database is corrupted, clear and create a new one
e.printStackTrace();
if (BuildConfig.DEBUG)
exception.printStackTrace();
SQLiteDatabase.deleteDatabase(instance.databasePath);
instance = new DatabaseAdapter(context.getApplicationContext());
}

View File

@ -8,19 +8,19 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import org.nuclearfog.twidda.BuildConfig;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback;
import org.nuclearfog.twidda.backend.async.ImageLoader;
import org.nuclearfog.twidda.backend.async.ImageLoader.ImageParameter;
import org.nuclearfog.twidda.backend.async.ImageLoader.ImageResult;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.ui.views.AnimatedImageView;
import org.nuclearfog.twidda.ui.views.DescriptionView;
@ -203,8 +203,7 @@ public class ImageViewer extends MediaActivity implements AsyncCallback<ImageRes
break;
}
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
finish();
}
}
@ -220,8 +219,10 @@ public class ImageViewer extends MediaActivity implements AsyncCallback<ImageRes
file.delete();
}
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (SecurityException exception) {
if (BuildConfig.DEBUG) {
exception.printStackTrace();
}
}
}
}

View File

@ -35,7 +35,7 @@ import org.nuclearfog.twidda.backend.async.LoginAction.LoginParam;
import org.nuclearfog.twidda.backend.async.LoginAction.LoginResult;
import org.nuclearfog.twidda.backend.helper.ConnectionConfig;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.Configuration;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.ui.adapter.NetworkAdapter;
@ -302,8 +302,7 @@ public class LoginActivity extends AppCompatActivity implements ActivityResultCa
break;
case LoginResult.MODE_ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
break;
}
}

View File

@ -23,7 +23,7 @@ import org.nuclearfog.twidda.backend.async.MessageUpdater;
import org.nuclearfog.twidda.backend.async.MessageUpdater.MessageUpdateResult;
import org.nuclearfog.twidda.backend.helper.update.MessageUpdate;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.Instance;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
@ -236,7 +236,7 @@ public class MessageEditor extends MediaActivity implements OnClickListener, OnC
Toast.makeText(getApplicationContext(), R.string.info_dm_send, Toast.LENGTH_SHORT).show();
finish();
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
confirmDialog.show(ConfirmDialog.MESSAGE_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -57,7 +57,7 @@ import org.nuclearfog.twidda.backend.async.UserLoader.UserResult;
import org.nuclearfog.twidda.backend.image.PicassoBuilder;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.EmojiUtils;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.backend.utils.LinkUtils;
import org.nuclearfog.twidda.backend.utils.StringUtils;
import org.nuclearfog.twidda.config.Configuration;
@ -677,8 +677,7 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
break;
case UserResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
if (user == null || (result.exception != null
&& (result.exception.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND
|| result.exception.getErrorCode() == ConnectionException.USER_NOT_FOUND))) {
@ -720,8 +719,7 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
break;
case RelationResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
break;
}
if (result.relation != null) {
@ -737,7 +735,7 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
if (result.mode == DomainResult.MODE_BLOCK) {
Toast.makeText(getApplicationContext(), R.string.info_domain_blocked, Toast.LENGTH_SHORT).show();
} else if (result.mode == DomainResult.ERROR) {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}

View File

@ -34,7 +34,7 @@ import org.nuclearfog.twidda.backend.async.UserUpdater.UserUpdateResult;
import org.nuclearfog.twidda.backend.helper.update.ProfileUpdate;
import org.nuclearfog.twidda.backend.image.PicassoBuilder;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.Configuration;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.User;
@ -249,7 +249,7 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, Asy
setResult(RETURN_PROFILE_CHANGED, data);
finish();
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
confirmDialog.show(ConfirmDialog.PROFILE_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -23,7 +23,7 @@ import org.nuclearfog.twidda.backend.async.HashtagAction;
import org.nuclearfog.twidda.backend.async.HashtagAction.HashtagParam;
import org.nuclearfog.twidda.backend.async.HashtagAction.HashtagResult;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.Configuration;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.Trend;
@ -256,7 +256,7 @@ public class SearchActivity extends AppCompatActivity implements OnTabSelectedLi
break;
case HashtagResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
break;
}

View File

@ -43,7 +43,7 @@ import org.nuclearfog.twidda.backend.async.DatabaseAction.DatabaseResult;
import org.nuclearfog.twidda.backend.async.LocationLoader;
import org.nuclearfog.twidda.backend.async.LocationLoader.LocationLoaderResult;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.Configuration;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.notification.PushSubscription;
@ -635,7 +635,7 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
location_dropdown.setSelection(position, false);
location_dropdown.setOnItemSelectedListener(this);
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}

View File

@ -63,7 +63,7 @@ import org.nuclearfog.twidda.backend.async.TranslationLoader.TranslationResult;
import org.nuclearfog.twidda.backend.image.PicassoBuilder;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.EmojiUtils;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.backend.utils.LinkUtils;
import org.nuclearfog.twidda.backend.utils.StringUtils;
import org.nuclearfog.twidda.config.Configuration;
@ -997,20 +997,23 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
break;
case StatusResult.DELETE:
if (status != null) {
if (notification != null) {
Toast.makeText(getApplicationContext(), R.string.info_status_removed, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
if (status.getEmbeddedStatus() != null)
intent.putExtra(KEY_STATUS_ID, status.getEmbeddedStatus().getId());
else
intent.putExtra(KEY_STATUS_ID, status.getId());
intent.putExtra(KEY_NOTIFICATION_ID, notification.getId());
setResult(RETURN_NOTIFICATION_REMOVED, intent);
finish();
} else if (status != null) {
Toast.makeText(getApplicationContext(), R.string.info_status_removed, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra(KEY_STATUS_ID, status.getId());
setResult(RETURN_STATUS_REMOVED, intent);
finish();
}
break;
case StatusResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
if (status == null) {
finish();
@ -1057,7 +1060,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
break;
case NotificationActionResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
if (notification == null) {
finish();
@ -1092,7 +1095,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
break;
case PollActionResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
break;
}
@ -1118,7 +1121,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
translate_text.append(result.translation.getOriginalLanguage());
translate_text.setOnClickListener(null); // disable link to translation
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}

View File

@ -27,7 +27,7 @@ import org.nuclearfog.twidda.backend.async.StatusUpdater.StatusUpdateResult;
import org.nuclearfog.twidda.backend.helper.update.PollUpdate;
import org.nuclearfog.twidda.backend.helper.update.StatusUpdate;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.Emoji;
import org.nuclearfog.twidda.model.Instance;
@ -456,7 +456,7 @@ public class StatusEditor extends MediaActivity implements OnClickListener, OnPr
Toast.makeText(getApplicationContext(), R.string.info_status_sent, Toast.LENGTH_LONG).show();
finish();
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
confirmDialog.show(ConfirmDialog.STATUS_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -31,7 +31,7 @@ import org.nuclearfog.twidda.backend.async.UserlistManager;
import org.nuclearfog.twidda.backend.async.UserlistManager.ListManagerParam;
import org.nuclearfog.twidda.backend.async.UserlistManager.ListManagerResult;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.UserList;
import org.nuclearfog.twidda.ui.adapter.FragmentAdapter;
@ -327,8 +327,7 @@ public class UserlistActivity extends AppCompatActivity implements ActivityResul
break;
case ListManagerResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
break;
}
}
@ -365,8 +364,7 @@ public class UserlistActivity extends AppCompatActivity implements ActivityResul
break;
case ListActionResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
if (result.exception != null && result.exception.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND) {
// List does not exist
intent = new Intent();

View File

@ -23,7 +23,7 @@ import org.nuclearfog.twidda.backend.async.UserlistUpdater;
import org.nuclearfog.twidda.backend.async.UserlistUpdater.ListUpdateResult;
import org.nuclearfog.twidda.backend.helper.update.UserListUpdate;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.UserList;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
@ -209,7 +209,7 @@ public class UserlistEditor extends AppCompatActivity implements OnClickListener
setResult(RETURN_LIST_CHANGED, intent);
finish();
} else {
String message = ErrorHandler.getErrorMessage(this, result.exception);
String message = ErrorUtils.getErrorMessage(this, result.exception);
confirmDialog.show(ConfirmDialog.LIST_EDITOR_ERROR, message);
loadingCircle.dismiss();
}

View File

@ -24,7 +24,7 @@ import org.nuclearfog.twidda.backend.async.FilterLoader;
import org.nuclearfog.twidda.backend.async.FilterLoader.FilterParam;
import org.nuclearfog.twidda.backend.async.FilterLoader.FilterResult;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.config.Configuration;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.ui.adapter.FragmentAdapter;
@ -330,8 +330,7 @@ public class UsersActivity extends AppCompatActivity implements OnTabSelectedLis
default:
case FilterResult.ERROR:
String message = ErrorHandler.getErrorMessage(this, result.exception);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getApplicationContext(), result.exception);
break;
}
}

View File

@ -8,7 +8,6 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.R;
@ -166,7 +165,7 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
* @param type Type of dialog to show
*/
public void show(int type) {
show(type, "");
show(type, null);
}
/**
@ -175,7 +174,7 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
* @param type Type of dialog to show
* @param messageTxt override default message text
*/
public void show(int type, @NonNull String messageTxt) {
public void show(int type, @Nullable String messageTxt) {
if (isShowing()) {
return;
}
@ -287,10 +286,10 @@ public class ConfirmDialog extends Dialog implements OnClickListener {
confirm.setText(confirmRes);
confirm.setCompoundDrawablesWithIntrinsicBounds(confirmIconRes, 0, 0, 0);
// setup message
if (messageTxt.isEmpty()) {
message.setText(messageRes);
} else {
if (messageTxt != null && !messageTxt.isEmpty()) {
message.setText(messageTxt);
} else {
message.setText(messageRes);
}
AppStyles.setTheme(root);
super.show();

View File

@ -12,7 +12,7 @@ import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback;
import org.nuclearfog.twidda.backend.async.DomainAction;
import org.nuclearfog.twidda.backend.async.DomainAction.DomainParam;
import org.nuclearfog.twidda.backend.async.DomainAction.DomainResult;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.lists.Domains;
import org.nuclearfog.twidda.ui.adapter.DomainAdapter;
import org.nuclearfog.twidda.ui.adapter.DomainAdapter.OnDomainClickListener;
@ -116,8 +116,9 @@ public class DomainFragment extends ListFragment implements OnDomainClickListene
Toast.makeText(requireContext(), R.string.info_domain_removed, Toast.LENGTH_SHORT).show();
}
} else if (result.mode == DomainResult.ERROR) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
adapter.disableLoading();
}
}

View File

@ -16,7 +16,7 @@ import org.nuclearfog.twidda.backend.async.MessageLoader;
import org.nuclearfog.twidda.backend.async.MessageLoader.MessageLoaderParam;
import org.nuclearfog.twidda.backend.async.MessageLoader.MessageLoaderResult;
import org.nuclearfog.twidda.model.lists.Messages;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.backend.utils.LinkUtils;
import org.nuclearfog.twidda.model.Message;
import org.nuclearfog.twidda.ui.activities.ImageViewer;
@ -192,8 +192,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
case MessageLoaderResult.ERROR:
if (getContext() != null) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
if (result.exception != null && result.exception.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND) {
adapter.removeItem(result.id);

View File

@ -3,7 +3,6 @@ package org.nuclearfog.twidda.ui.fragments;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
@ -20,7 +19,7 @@ import org.nuclearfog.twidda.backend.async.NotificationAction.NotificationAction
import org.nuclearfog.twidda.backend.async.NotificationLoader;
import org.nuclearfog.twidda.backend.async.NotificationLoader.NotificationLoaderParam;
import org.nuclearfog.twidda.backend.async.NotificationLoader.NotificationLoaderResult;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.lists.Notifications;
import org.nuclearfog.twidda.model.Notification;
import org.nuclearfog.twidda.model.User;
@ -185,9 +184,10 @@ public class NotificationFragment extends ListFragment implements OnNotification
private void onResult(@NonNull NotificationLoaderResult result) {
if (result.notifications != null) {
adapter.addItems(result.notifications, result.position);
} else if (getContext() != null) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
} else {
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
adapter.disableLoading();
}
setRefresh(false);
@ -200,8 +200,9 @@ public class NotificationFragment extends ListFragment implements OnNotification
if (result.mode == NotificationActionResult.DISMISS) {
adapter.removeItem(result.id);
} else if (result.mode == NotificationActionResult.ERROR) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
if (result.exception != null && result.exception.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND) {
adapter.removeItem(result.id);
}

View File

@ -3,7 +3,6 @@ package org.nuclearfog.twidda.ui.fragments;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
@ -17,7 +16,7 @@ import org.nuclearfog.twidda.backend.async.StatusLoader;
import org.nuclearfog.twidda.backend.async.StatusLoader.StatusParameter;
import org.nuclearfog.twidda.backend.async.StatusLoader.StatusResult;
import org.nuclearfog.twidda.model.lists.Statuses;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.Status;
import org.nuclearfog.twidda.ui.activities.StatusActivity;
import org.nuclearfog.twidda.ui.adapter.StatusAdapter;
@ -227,9 +226,10 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
} else {
adapter.addItems(result.statuses, result.position);
}
} else if (getContext() != null) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
} else {
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
adapter.disableLoading();
}
setRefresh(false);

View File

@ -3,7 +3,6 @@ package org.nuclearfog.twidda.ui.fragments;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
@ -16,7 +15,7 @@ import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback;
import org.nuclearfog.twidda.backend.async.TrendLoader;
import org.nuclearfog.twidda.backend.async.TrendLoader.TrendParameter;
import org.nuclearfog.twidda.backend.async.TrendLoader.TrendResult;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.lists.Trends;
import org.nuclearfog.twidda.model.Trend;
import org.nuclearfog.twidda.ui.activities.SearchActivity;
@ -173,8 +172,9 @@ public class TrendFragment extends ListFragment implements TrendClickListener, A
@Override
public void onResult(@NonNull TrendResult result) {
if (result.mode == TrendResult.ERROR) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
adapter.disableLoading();
} else {
adapter.addItems(result.trends, result.index);

View File

@ -20,7 +20,7 @@ import org.nuclearfog.twidda.backend.async.UsersLoader;
import org.nuclearfog.twidda.backend.async.UsersLoader.UserParam;
import org.nuclearfog.twidda.backend.async.UsersLoader.UserResult;
import org.nuclearfog.twidda.model.lists.Users;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.ui.activities.ProfileActivity;
import org.nuclearfog.twidda.ui.adapter.UserAdapter;
@ -266,9 +266,10 @@ public class UserFragment extends ListFragment implements UserClickListener, OnC
public void onResult(@NonNull UserResult result) {
if (result.users != null) {
adapter.addItems(result.users, result.index);
} else if (getContext() != null) {
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
} else {
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
adapter.disableLoading();
}
setRefresh(false);

View File

@ -3,7 +3,6 @@ package org.nuclearfog.twidda.ui.fragments;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
@ -17,7 +16,7 @@ import org.nuclearfog.twidda.backend.async.UserlistLoader;
import org.nuclearfog.twidda.backend.async.UserlistLoader.UserlistParam;
import org.nuclearfog.twidda.backend.async.UserlistLoader.UserlistResult;
import org.nuclearfog.twidda.model.lists.UserLists;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.model.UserList;
import org.nuclearfog.twidda.ui.activities.ProfileActivity;
@ -186,8 +185,9 @@ public class UserListFragment extends ListFragment implements ListClickListener,
break;
case UserlistResult.ERROR:
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
if (getContext() != null) {
ErrorUtils.showErrorMessage(getContext(), result.exception);
}
adapter.disableLoading();
break;
}

View File

@ -15,10 +15,10 @@
</string-array>
<string-array name="push_policy">
<item>Alles</item>
<item>Following</item>
<item>Follower</item>
<item>Deaktivieren</item>
<item>Alles anzeigen</item>
<item>nur Following</item>
<item>nur Follower</item>
<item>deaktivieren</item>
</string-array>
</resources>

View File

@ -182,7 +182,7 @@
<string name="settings_icon_color">Symbolfarbe</string>
<string name="settings_key1_hint">Consumer Key</string>
<string name="settings_key2_hint">Consumer Secret</string>
<string name="error_acc_loading">Fehler während des Abruf</string>
<string name="error_acc_loading">Fehler beim Abrufen!</string>
<string name="error_api_access_denied">Fehler, API Zugang wurde abgelehnt! Bitte API Schlüssel überprüfen!</string>
<string name="error_api_key_expired">Fehler, API Schlüssel veraltet, bitte App aktualisieren!</string>
<string name="info_location_pending">Ortung läuft, bitte warten.</string>

View File

@ -72,10 +72,10 @@
</string-array>
<string-array name="push_policy">
<item>All</item>
<item>Following</item>
<item>Follower</item>
<item>Disable</item>
<item>show all</item>
<item>Following only</item>
<item>Followers only</item>
<item>disabled</item>
</string-array>
<string-array name="visibility">