bug fix, added error message
This commit is contained in:
parent
9ef8c0a741
commit
181985dddc
|
@ -2,6 +2,8 @@ package org.nuclearfog.twidda.backend.async;
|
|||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.database.AppDatabase;
|
||||
import org.nuclearfog.twidda.model.Account;
|
||||
import org.nuclearfog.twidda.ui.fragments.AccountFragment;
|
||||
|
@ -45,27 +47,39 @@ public class AccountLoader extends AsyncTask<Long, Void, List<Account>> {
|
|||
|
||||
@Override
|
||||
protected List<Account> doInBackground(Long... param) {
|
||||
// get all logins
|
||||
if (mode == MODE_LOAD) {
|
||||
return db.getLogins();
|
||||
}
|
||||
// delete login
|
||||
else if (mode == MODE_DELETE) {
|
||||
db.removeLogin(param[0]);
|
||||
deleteId = param[0];
|
||||
try {
|
||||
// get all logins
|
||||
if (mode == MODE_LOAD) {
|
||||
return db.getLogins();
|
||||
}
|
||||
// delete login
|
||||
else if (mode == MODE_DELETE) {
|
||||
db.removeLogin(param[0]);
|
||||
deleteId = param[0];
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Account> accounts) {
|
||||
protected void onPostExecute(@Nullable List<Account> accounts) {
|
||||
AccountFragment fragment = weakRef.get();
|
||||
if (fragment != null) {
|
||||
if (mode == MODE_LOAD) {
|
||||
fragment.onSuccess(accounts);
|
||||
if (accounts != null) {
|
||||
fragment.onSuccess(accounts);
|
||||
} else {
|
||||
fragment.onError();
|
||||
}
|
||||
} else if (mode == MODE_DELETE) {
|
||||
fragment.onDelete(deleteId);
|
||||
if (deleteId > 0) {
|
||||
fragment.onDelete(deleteId);
|
||||
} else {
|
||||
fragment.onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
public class FilterLoader extends AsyncTask<String, Void, Void> {
|
||||
public class FilterLoader extends AsyncTask<String, Void, Boolean> {
|
||||
|
||||
/**
|
||||
* refresh exclude list
|
||||
|
@ -55,34 +55,36 @@ public class FilterLoader extends AsyncTask<String, Void, Void> {
|
|||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... names) {
|
||||
protected Boolean doInBackground(String... names) {
|
||||
try {
|
||||
switch (mode) {
|
||||
case REFRESH:
|
||||
List<Long> ids = connection.getIdBlocklist();
|
||||
db.setFilterlistUserIds(ids);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case MUTE_USER:
|
||||
connection.muteUser(names[0]);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case BLOCK_USER:
|
||||
connection.blockUser(names[0]);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
protected void onPostExecute(Boolean success) {
|
||||
UsersActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (exception == null) {
|
||||
if (success) {
|
||||
activity.onSuccess(mode);
|
||||
} else {
|
||||
activity.onError(exception);
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.nuclearfog.twidda.ui.activities.ImageViewer;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
@ -72,15 +71,15 @@ public class ImageLoader extends AsyncTask<Uri, Void, Uri> {
|
|||
return Uri.fromFile(imageFile);
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Uri localUri) {
|
||||
protected void onPostExecute(@Nullable Uri localUri) {
|
||||
ImageViewer activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (localUri != null) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.os.AsyncTask;
|
|||
|
||||
import org.nuclearfog.twidda.ui.activities.MediaActivity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -43,11 +42,11 @@ public class ImageSaver extends AsyncTask<Void, Void, Boolean> {
|
|||
}
|
||||
mediaStream.close();
|
||||
fileStream.close();
|
||||
} catch (IOException err) {
|
||||
err.printStackTrace();
|
||||
return false;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -156,19 +156,21 @@ public class LinkLoader extends AsyncTask<Uri, Void, LinkLoader.DataHolder> {
|
|||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(DataHolder result) {
|
||||
protected void onPostExecute(@Nullable DataHolder result) {
|
||||
MainActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (exception != null) {
|
||||
activity.onError(exception);
|
||||
} else {
|
||||
if (result != null) {
|
||||
activity.onSuccess(result);
|
||||
} else {
|
||||
activity.onError(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.nuclearfog.twidda.backend.async;
|
|||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.backend.api.Connection;
|
||||
import org.nuclearfog.twidda.backend.api.ConnectionException;
|
||||
import org.nuclearfog.twidda.backend.api.ConnectionManager;
|
||||
|
@ -77,13 +79,15 @@ public class ListAction extends AsyncTask<Void, Void, UserList> {
|
|||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(UserList userList) {
|
||||
protected void onPostExecute(@Nullable UserList userList) {
|
||||
UserlistActivity callback = this.weakRef.get();
|
||||
if (callback != null) {
|
||||
if (userList != null) {
|
||||
|
|
|
@ -71,13 +71,15 @@ public class ListLoader extends AsyncTask<Long, Void, UserLists> {
|
|||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(UserLists result) {
|
||||
protected void onPostExecute(@Nullable UserLists result) {
|
||||
UserListFragment fragment = weakRef.get();
|
||||
if (fragment != null) {
|
||||
if (result != null) {
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.lang.ref.WeakReference;
|
|||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
public class ListManager extends AsyncTask<Void, Void, Void> {
|
||||
public class ListManager extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
/**
|
||||
* add user to list
|
||||
|
@ -57,29 +57,31 @@ public class ListManager extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... v) {
|
||||
protected Boolean doInBackground(Void... v) {
|
||||
try {
|
||||
switch (action) {
|
||||
case ADD_USER:
|
||||
connection.addUserToList(listId, username);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case DEL_USER:
|
||||
connection.removeUserFromList(listId, username);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
protected void onPostExecute(Boolean success) {
|
||||
UserlistActivity callback = weakRef.get();
|
||||
if (callback != null) {
|
||||
if (exception == null) {
|
||||
if (success) {
|
||||
callback.onSuccess(action, username);
|
||||
} else {
|
||||
callback.onFailure(exception);
|
||||
|
|
|
@ -48,13 +48,15 @@ public class ListUpdater extends AsyncTask<Void, Void, UserList> {
|
|||
return connection.createUserlist(update);
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(UserList result) {
|
||||
protected void onPostExecute(@Nullable UserList result) {
|
||||
UserlistEditor activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (result != null) {
|
||||
|
|
|
@ -41,13 +41,15 @@ public class LocationLoader extends AsyncTask<Void, Void, List<Location>> {
|
|||
return connection.getLocations();
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Location> locations) {
|
||||
protected void onPostExecute(@Nullable List<Location> locations) {
|
||||
SettingsActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (locations != null) {
|
||||
|
|
|
@ -94,13 +94,15 @@ public class LoginAction extends AsyncTask<String, Void, String> {
|
|||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
protected void onPostExecute(@Nullable String result) {
|
||||
LoginActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (result != null) {
|
||||
|
|
|
@ -93,6 +93,8 @@ public class MessageLoader extends AsyncTask<Void, Void, Messages> {
|
|||
if (exception.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND) {
|
||||
db.removeMessage(messageId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -102,16 +104,23 @@ public class MessageLoader extends AsyncTask<Void, Void, Messages> {
|
|||
protected void onPostExecute(@Nullable Messages messages) {
|
||||
MessageFragment fragment = weakRef.get();
|
||||
if (fragment != null) {
|
||||
if (exception != null) {
|
||||
fragment.onError(exception, messageId);
|
||||
} else {
|
||||
if (action == DB || action == LOAD) {
|
||||
switch (action) {
|
||||
case DB:
|
||||
case LOAD:
|
||||
if (messages != null) {
|
||||
fragment.setData(messages);
|
||||
} else {
|
||||
fragment.onError(exception, messageId);
|
||||
}
|
||||
} else if (action == DEL) {
|
||||
fragment.removeItem(messageId);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEL:
|
||||
if (exception == null) {
|
||||
fragment.removeItem(messageId);
|
||||
} else {
|
||||
fragment.onError(exception, messageId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,8 @@ public class MessageUpdater extends AsyncTask<Void, Void, Boolean> {
|
|||
return true;
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// close all streams
|
||||
message.close();
|
||||
|
|
|
@ -62,18 +62,21 @@ public class NotificationLoader extends AsyncTask<Long, Void, List<Notification>
|
|||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Notification> notifications) {
|
||||
protected void onPostExecute(@Nullable List<Notification> notifications) {
|
||||
NotificationFragment fragment = callback.get();
|
||||
if (fragment != null) {
|
||||
if (notifications != null) {
|
||||
fragment.onSuccess(notifications, pos);
|
||||
} else {
|
||||
}
|
||||
if (exception != null) {
|
||||
fragment.onError(exception);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.lang.ref.WeakReference;
|
|||
* @author nuclearfog
|
||||
* @see StatusActivity
|
||||
*/
|
||||
public class StatusAction extends AsyncTask<Long, Status, Void> {
|
||||
public class StatusAction extends AsyncTask<Long, Status, Boolean> {
|
||||
|
||||
/**
|
||||
* Load status
|
||||
|
@ -92,7 +92,7 @@ public class StatusAction extends AsyncTask<Long, Status, Void> {
|
|||
* @param ids first value is the status ID. The second value is the repost status ID. Required for delete operations
|
||||
*/
|
||||
@Override
|
||||
protected Void doInBackground(Long... ids) {
|
||||
protected Boolean doInBackground(Long... ids) {
|
||||
org.nuclearfog.twidda.model.Status status;
|
||||
try {
|
||||
switch (action) {
|
||||
|
@ -110,21 +110,21 @@ public class StatusAction extends AsyncTask<Long, Status, Void> {
|
|||
// update status if there is a database entry
|
||||
db.updateStatus(status);
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
|
||||
case DELETE:
|
||||
connection.deleteStatus(ids[0]);
|
||||
db.removeStatus(ids[0]);
|
||||
// removing repost reference to this status
|
||||
db.removeStatus(ids[1]);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case REPOST:
|
||||
status = connection.repostStatus(ids[0]);
|
||||
if (status.getEmbeddedStatus() != null)
|
||||
publishProgress(status.getEmbeddedStatus());
|
||||
db.updateStatus(status);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case REMOVE_REPOST:
|
||||
status = connection.removeRepost(ids[0]);
|
||||
|
@ -133,29 +133,29 @@ public class StatusAction extends AsyncTask<Long, Status, Void> {
|
|||
// removing repost reference to this status
|
||||
if (ids.length == 2)
|
||||
db.removeStatus(ids[1]);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case FAVORITE:
|
||||
status = connection.favoriteStatus(ids[0]);
|
||||
publishProgress(status);
|
||||
db.saveToFavorites(status);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case UNFAVORITE:
|
||||
status = connection.unfavoriteStatus(ids[0]);
|
||||
publishProgress(status);
|
||||
db.removeFavorite(status);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case HIDE:
|
||||
connection.muteConversation(ids[0]);
|
||||
db.hideStatus(ids[0], true);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case UNHIDE:
|
||||
connection.unmuteConversation(ids[0]);
|
||||
db.hideStatus(ids[0], false);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
|
@ -167,8 +167,10 @@ public class StatusAction extends AsyncTask<Long, Status, Void> {
|
|||
db.removeStatus(ids[1]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,10 +184,10 @@ public class StatusAction extends AsyncTask<Long, Status, Void> {
|
|||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
protected void onPostExecute(Boolean success) {
|
||||
StatusActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (exception == null) {
|
||||
if (success) {
|
||||
activity.OnSuccess(action);
|
||||
} else {
|
||||
activity.onError(exception);
|
||||
|
|
|
@ -202,12 +202,13 @@ public class StatusLoader extends AsyncTask<Long, Void, List<Status>> {
|
|||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<org.nuclearfog.twidda.model.Status> statuses) {
|
||||
protected void onPostExecute(@Nullable List<org.nuclearfog.twidda.model.Status> statuses) {
|
||||
StatusFragment fragment = weakRef.get();
|
||||
if (fragment != null) {
|
||||
if (statuses != null) {
|
||||
fragment.setData(statuses, pos);
|
||||
} else {
|
||||
}
|
||||
if (exception != null) {
|
||||
fragment.onError(exception);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.lang.ref.WeakReference;
|
|||
* @author nuclearfog
|
||||
* @see StatusEditor
|
||||
*/
|
||||
public class StatusUpdater extends AsyncTask<StatusUpdate, Void, Void> {
|
||||
public class StatusUpdater extends AsyncTask<StatusUpdate, Void, Boolean> {
|
||||
|
||||
private Connection connection;
|
||||
private ConnectionException exception;
|
||||
|
@ -36,7 +36,7 @@ public class StatusUpdater extends AsyncTask<StatusUpdate, Void, Void> {
|
|||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(StatusUpdate... statusUpdates) {
|
||||
protected Boolean doInBackground(StatusUpdate... statusUpdates) {
|
||||
StatusUpdate statusUpdate = statusUpdates[0];
|
||||
try {
|
||||
// upload media first
|
||||
|
@ -50,21 +50,24 @@ public class StatusUpdater extends AsyncTask<StatusUpdate, Void, Void> {
|
|||
if (!isCancelled()) {
|
||||
connection.uploadStatus(statusUpdate, mediaIds);
|
||||
}
|
||||
return true;
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// close inputstreams
|
||||
statusUpdate.close();
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
protected void onPostExecute(Boolean success) {
|
||||
StatusEditor activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (exception == null) {
|
||||
if (success) {
|
||||
activity.onSuccess();
|
||||
} else {
|
||||
activity.onError(exception);
|
||||
|
|
|
@ -59,18 +59,21 @@ public class TrendLoader extends AsyncTask<Void, Void, List<Trend>> {
|
|||
return trends;
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Trend> trends) {
|
||||
protected void onPostExecute(@Nullable List<Trend> trends) {
|
||||
TrendFragment fragment = weakRef.get();
|
||||
if (fragment != null) {
|
||||
if (trends != null) {
|
||||
fragment.setData(trends);
|
||||
} else {
|
||||
}
|
||||
if (exception != null) {
|
||||
fragment.onError(exception);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.nuclearfog.twidda.backend.async;
|
|||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.backend.api.Connection;
|
||||
import org.nuclearfog.twidda.backend.api.ConnectionException;
|
||||
import org.nuclearfog.twidda.backend.api.ConnectionManager;
|
||||
|
@ -91,9 +93,7 @@ public class UserAction extends AsyncTask<Void, User, Relation> {
|
|||
User user;
|
||||
if (userId > 0) {
|
||||
user = db.getUser(userId);
|
||||
if (user != null) {
|
||||
publishProgress(user);
|
||||
}
|
||||
publishProgress(user);
|
||||
}
|
||||
|
||||
case PROFILE_lOAD:
|
||||
|
@ -151,6 +151,8 @@ public class UserAction extends AsyncTask<Void, User, Relation> {
|
|||
return connection.getUserRelationship(userId);
|
||||
} catch (ConnectionException exception) {
|
||||
this.error = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -159,14 +161,14 @@ public class UserAction extends AsyncTask<Void, User, Relation> {
|
|||
@Override
|
||||
protected void onProgressUpdate(User[] users) {
|
||||
ProfileActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (activity != null && users[0] != null) {
|
||||
activity.setUser(users[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Relation relation) {
|
||||
protected void onPostExecute(@Nullable Relation relation) {
|
||||
ProfileActivity activity = weakRef.get();
|
||||
if (activity != null) {
|
||||
if (relation != null) {
|
||||
|
|
|
@ -143,13 +143,15 @@ public class UserLoader extends AsyncTask<Long, Void, Users> {
|
|||
}
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Users users) {
|
||||
protected void onPostExecute(@Nullable Users users) {
|
||||
UserFragment fragment = weakRef.get();
|
||||
if (fragment != null) {
|
||||
if (users != null) {
|
||||
|
|
|
@ -30,6 +30,7 @@ public class UserUpdater extends AsyncTask<Void, Void, User> {
|
|||
private ConnectionException exception;
|
||||
private ProfileUpdate profile;
|
||||
|
||||
|
||||
public UserUpdater(ProfileEditor activity, ProfileUpdate profile) {
|
||||
super();
|
||||
db = new AppDatabase(activity);
|
||||
|
@ -48,6 +49,8 @@ public class UserUpdater extends AsyncTask<Void, Void, User> {
|
|||
return user;
|
||||
} catch (ConnectionException exception) {
|
||||
this.exception = exception;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// close image streams
|
||||
profile.close();
|
||||
|
|
|
@ -134,7 +134,7 @@ public class ImageViewer extends MediaActivity {
|
|||
*
|
||||
* @param uri Uri of the cached image file
|
||||
*/
|
||||
public void onSuccess(Uri uri) {
|
||||
public void onSuccess(@NonNull Uri uri) {
|
||||
cacheUri = uri;
|
||||
zoomImage.reset();
|
||||
zoomImage.setImageURI(uri);
|
||||
|
@ -144,7 +144,7 @@ public class ImageViewer extends MediaActivity {
|
|||
/**
|
||||
* Called from {@link ImageLoader} when an error occurs
|
||||
*/
|
||||
public void onError(ConnectionException err) {
|
||||
public void onError(@Nullable ConnectionException err) {
|
||||
ErrorHandler.handleFailure(getApplicationContext(), err);
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -329,7 +329,7 @@ public class LoginActivity extends AppCompatActivity implements OnClickListener,
|
|||
/**
|
||||
* Called when the app is registered successfully
|
||||
*/
|
||||
public void onSuccess(int mode, String result) {
|
||||
public void onSuccess(int mode, @NonNull String result) {
|
||||
switch (mode) {
|
||||
case LoginAction.MODE_LOGIN:
|
||||
setResult(RETURN_LOGIN_SUCCESSFUL);
|
||||
|
|
|
@ -283,27 +283,27 @@ public class MainActivity extends AppCompatActivity implements OnTabSelectedList
|
|||
*
|
||||
* @param holder holder with activity information and extras
|
||||
*/
|
||||
public void onSuccess(@Nullable LinkLoader.DataHolder holder) {
|
||||
public void onSuccess(@NonNull LinkLoader.DataHolder holder) {
|
||||
loadingCircle.dismiss();
|
||||
if (holder != null) {
|
||||
if (holder.activity == MainActivity.class) {
|
||||
int page = holder.data.getInt(KEY_TAB_PAGE, 0);
|
||||
pager.setCurrentItem(page);
|
||||
} else {
|
||||
Intent intent = new Intent(this, holder.activity);
|
||||
intent.putExtras(holder.data);
|
||||
startActivity(intent);
|
||||
}
|
||||
if (holder.activity == MainActivity.class) {
|
||||
int page = holder.data.getInt(KEY_TAB_PAGE, 0);
|
||||
pager.setCurrentItem(page);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.error_open_link, Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(this, holder.activity);
|
||||
intent.putExtras(holder.data);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called from {@link LinkLoader} when an error occurs
|
||||
*/
|
||||
public void onError(ConnectionException error) {
|
||||
ErrorHandler.handleFailure(this, error);
|
||||
public void onError(@Nullable ConnectionException error) {
|
||||
if (error != null) {
|
||||
ErrorHandler.handleFailure(this, error);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.error_open_link, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
loadingCircle.dismiss();
|
||||
}
|
||||
}
|
|
@ -689,7 +689,7 @@ public class ProfileActivity extends AppCompatActivity implements OnClickListene
|
|||
*
|
||||
* @param relation relation to an user
|
||||
*/
|
||||
public void onAction(Relation relation) {
|
||||
public void onAction(@NonNull Relation relation) {
|
||||
if (this.relation != null) {
|
||||
// check if block status changed
|
||||
if (relation.isBlocked() != this.relation.isBlocked()) {
|
||||
|
|
|
@ -273,7 +273,7 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, OnP
|
|||
/**
|
||||
* called after user profile was updated successfully
|
||||
*/
|
||||
public void onSuccess(User user) {
|
||||
public void onSuccess(@NonNull User user) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra(KEY_UPDATED_PROFILE, user);
|
||||
Toast.makeText(this, R.string.info_profile_updated, Toast.LENGTH_SHORT).show();
|
||||
|
@ -286,7 +286,7 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, OnP
|
|||
*
|
||||
* @param err Engine Exception
|
||||
*/
|
||||
public void onError(ConnectionException err) {
|
||||
public void onError(@Nullable ConnectionException err) {
|
||||
String message = ErrorHandler.getErrorMessage(this, err);
|
||||
confirmDialog.show(ConfirmDialog.PROFILE_EDITOR_ERROR, message);
|
||||
loadingCircle.dismiss();
|
||||
|
|
|
@ -572,7 +572,7 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
|
|||
*
|
||||
* @param data location data
|
||||
*/
|
||||
public void setLocationData(List<Location> data) {
|
||||
public void setLocationData(@NonNull List<Location> data) {
|
||||
locationAdapter.replaceItems(data);
|
||||
int position = locationAdapter.indexOf(settings.getTrendLocation());
|
||||
if (position > 0)
|
||||
|
@ -585,7 +585,7 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
|
|||
*
|
||||
* @param err exception from twitter
|
||||
*/
|
||||
public void onError(ConnectionException err) {
|
||||
public void onError(@Nullable ConnectionException err) {
|
||||
ErrorHandler.handleFailure(this, err);
|
||||
}
|
||||
|
||||
|
|
|
@ -651,7 +651,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
|
|||
*
|
||||
* @param status Tweet information
|
||||
*/
|
||||
public void setStatus(Status status) {
|
||||
public void setStatus(@NonNull Status status) {
|
||||
this.status = status;
|
||||
if (status.getEmbeddedStatus() != null) {
|
||||
repostName.setVisibility(VISIBLE);
|
||||
|
|
|
@ -395,7 +395,7 @@ public class UserlistActivity extends AppCompatActivity implements OnTabSelected
|
|||
*
|
||||
* @param userList userlist update
|
||||
*/
|
||||
public void onSuccess(UserList userList, int action) {
|
||||
public void onSuccess(@NonNull UserList userList, int action) {
|
||||
this.userList = userList;
|
||||
switch (action) {
|
||||
case ListAction.LOAD:
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
|
@ -164,17 +165,11 @@ public class UserlistEditor extends AppCompatActivity implements OnClickListener
|
|||
/**
|
||||
* called when a list was updated successfully
|
||||
*/
|
||||
public void onSuccess(UserList result) {
|
||||
if (userList != null) {
|
||||
Toast.makeText(this, R.string.info_list_updated, Toast.LENGTH_SHORT).show();
|
||||
Intent data = new Intent();
|
||||
data.putExtra(KEY_UPDATED_USERLIST, result);
|
||||
setResult(RETURN_LIST_CHANGED, data);
|
||||
} else {
|
||||
// it's a new list, if no list is defined
|
||||
Toast.makeText(this, R.string.info_list_created, Toast.LENGTH_SHORT).show();
|
||||
setResult(RETURN_LIST_CREATED);
|
||||
}
|
||||
public void onSuccess(@NonNull UserList result) {
|
||||
Toast.makeText(getApplicationContext(), R.string.info_list_updated, Toast.LENGTH_SHORT).show();
|
||||
Intent data = new Intent();
|
||||
data.putExtra(KEY_UPDATED_USERLIST, result);
|
||||
setResult(RETURN_LIST_CHANGED, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.SearchView.OnQueryTextListener;
|
||||
|
@ -313,7 +314,7 @@ public class UsersActivity extends AppCompatActivity implements OnTabSelectedLis
|
|||
/**
|
||||
* called from {@link FilterLoader} if an error occurs
|
||||
*/
|
||||
public void onError(ConnectionException err) {
|
||||
public void onError(@Nullable ConnectionException err) {
|
||||
ErrorHandler.handleFailure(this, err);
|
||||
}
|
||||
}
|
|
@ -118,7 +118,7 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
|||
*
|
||||
* @param result login information
|
||||
*/
|
||||
public void onSuccess(List<Account> result) {
|
||||
public void onSuccess(@NonNull List<Account> result) {
|
||||
adapter.replaceItems(result);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
@ -131,4 +131,11 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
|||
public void onDelete(long id) {
|
||||
adapter.removeItem(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* called from {@link AccountLoader} when an error occurs
|
||||
*/
|
||||
public void onError() {
|
||||
Toast.makeText(requireContext(), R.string.error_acc_loading, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
|
@ -192,7 +192,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
|||
*
|
||||
* @param data list of direct messages
|
||||
*/
|
||||
public void setData(Messages data) {
|
||||
public void setData(@NonNull Messages data) {
|
||||
adapter.addItems(data);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
@ -212,9 +212,9 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
|||
*
|
||||
* @param messageId ID of the message assosiated with the error
|
||||
*/
|
||||
public void onError(@NonNull ConnectionException error, long messageId) {
|
||||
public void onError(@Nullable ConnectionException error, long messageId) {
|
||||
ErrorHandler.handleFailure(requireContext(), error);
|
||||
if (error.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND) {
|
||||
if (error != null && error.getErrorCode() == ConnectionException.RESOURCE_NOT_FOUND) {
|
||||
adapter.removeItem(messageId);
|
||||
}
|
||||
setRefresh(false);
|
||||
|
|
|
@ -131,7 +131,7 @@ public class NotificationFragment extends ListFragment implements OnNotification
|
|||
* @param notifications new items
|
||||
* @param position index where to insert the new items
|
||||
*/
|
||||
public void onSuccess(List<Notification> notifications, int position) {
|
||||
public void onSuccess(@NonNull List<Notification> notifications, int position) {
|
||||
adapter.addItems(notifications, position);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ public class NotificationFragment extends ListFragment implements OnNotification
|
|||
/**
|
||||
* called from {@link NotificationLoader} if an error occurs
|
||||
*/
|
||||
public void onError(@Nullable ConnectionException exception) {
|
||||
public void onError(ConnectionException exception) {
|
||||
ErrorHandler.handleFailure(requireContext(), exception);
|
||||
adapter.disableLoading();
|
||||
setRefresh(false);
|
||||
|
|
|
@ -207,7 +207,7 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
|||
* @param statuses List of statuses
|
||||
* @param pos position where statuses should be added
|
||||
*/
|
||||
public void setData(List<Status> statuses, int pos) {
|
||||
public void setData(@NonNull List<Status> statuses, int pos) {
|
||||
if (pos == CLEAR_LIST) {
|
||||
adapter.replaceItems(statuses);
|
||||
} else {
|
||||
|
@ -219,7 +219,7 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
|||
/**
|
||||
* called from {@link StatusLoader} if an error occurs
|
||||
*/
|
||||
public void onError(@Nullable ConnectionException error) {
|
||||
public void onError(ConnectionException error) {
|
||||
ErrorHandler.handleFailure(requireContext(), error);
|
||||
adapter.disableLoading();
|
||||
setRefresh(false);
|
||||
|
|
|
@ -84,16 +84,6 @@ public class TrendFragment extends ListFragment implements TrendClickListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set trend data to list
|
||||
*
|
||||
* @param data Trend data
|
||||
*/
|
||||
public void setData(List<Trend> data) {
|
||||
adapter.replaceItems(data);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if list is empty
|
||||
*
|
||||
|
@ -103,10 +93,20 @@ public class TrendFragment extends ListFragment implements TrendClickListener {
|
|||
return adapter.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* set trend data to list
|
||||
*
|
||||
* @param data Trend data
|
||||
*/
|
||||
public void setData(@NonNull List<Trend> data) {
|
||||
adapter.replaceItems(data);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* called from {@link TrendLoader} if an error occurs
|
||||
*/
|
||||
public void onError(@Nullable ConnectionException error) {
|
||||
public void onError(ConnectionException error) {
|
||||
ErrorHandler.handleFailure(requireContext(), error);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ public class UserFragment extends ListFragment implements UserClickListener {
|
|||
*
|
||||
* @param data list of users
|
||||
*/
|
||||
public void setData(Users data) {
|
||||
public void setData(@NonNull Users data) {
|
||||
adapter.addItems(data);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ public class UserFragment extends ListFragment implements UserClickListener {
|
|||
/**
|
||||
* called when an error occurs
|
||||
*/
|
||||
public void onError(ConnectionException exception) {
|
||||
public void onError(@Nullable ConnectionException exception) {
|
||||
ErrorHandler.handleFailure(requireContext(), exception);
|
||||
adapter.disableLoading();
|
||||
setRefresh(false);
|
||||
|
|
|
@ -170,7 +170,7 @@ public class UserListFragment extends ListFragment implements ListClickListener
|
|||
/**
|
||||
* set data to list
|
||||
*/
|
||||
public void setData(UserLists data) {
|
||||
public void setData(@NonNull UserLists data) {
|
||||
adapter.addItems(data);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
<string name="error_cant_reply_to_tweet">You can\'t reply to this status!</string>
|
||||
<string name="error_corrupt_api_key">Error, corrupt API key!</string>
|
||||
<string name="error_acc_update">Account update failed! Please check your input!</string>
|
||||
<string name="error_acc_loading">Error while loading login information!</string>
|
||||
<string name="error_api_access_denied">Error, API access denied! Please check your API Keys.</string>
|
||||
<string name="error_api_access_limited">Error, API access limited by Twitter!</string>
|
||||
<string name="error_api_key_expired">Error, API Keys expired! Please update app!</string>
|
||||
|
|
Loading…
Reference in New Issue