mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-16 03:20:37 +01:00
bug fix
This commit is contained in:
parent
43109bfcac
commit
1ddba16c1a
@ -18,11 +18,14 @@ import java.util.List;
|
|||||||
|
|
||||||
import twitter4j.TwitterException;
|
import twitter4j.TwitterException;
|
||||||
|
|
||||||
public class MessageLoader extends AsyncTask<Long, Void, Long> {
|
public class MessageLoader extends AsyncTask<Long, Void, Void> {
|
||||||
|
|
||||||
public static final long LOAD = 0;
|
public enum Mode {
|
||||||
public static final long DELETE = 1;
|
LOAD,
|
||||||
private static final long FAIL = -1;
|
DELETE
|
||||||
|
}
|
||||||
|
private final Mode mode;
|
||||||
|
private boolean failure = false;
|
||||||
|
|
||||||
private WeakReference<DirectMessage> ui;
|
private WeakReference<DirectMessage> ui;
|
||||||
private MessageAdapter mAdapter;
|
private MessageAdapter mAdapter;
|
||||||
@ -32,13 +35,14 @@ public class MessageLoader extends AsyncTask<Long, Void, Long> {
|
|||||||
private List<Message> message;
|
private List<Message> message;
|
||||||
|
|
||||||
|
|
||||||
public MessageLoader(@NonNull DirectMessage context) {
|
public MessageLoader(@NonNull DirectMessage context, Mode mode) {
|
||||||
ui = new WeakReference<>(context);
|
ui = new WeakReference<>(context);
|
||||||
RecyclerView dm_list = context.findViewById(R.id.messagelist);
|
RecyclerView dm_list = context.findViewById(R.id.messagelist);
|
||||||
mAdapter = (MessageAdapter) dm_list.getAdapter();
|
mAdapter = (MessageAdapter) dm_list.getAdapter();
|
||||||
twitter = TwitterEngine.getInstance(context);
|
twitter = TwitterEngine.getInstance(context);
|
||||||
message = new ArrayList<>();
|
|
||||||
mData = new DatabaseAdapter(context);
|
mData = new DatabaseAdapter(context);
|
||||||
|
message = new ArrayList<>();
|
||||||
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,45 +56,49 @@ public class MessageLoader extends AsyncTask<Long, Void, Long> {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Long doInBackground(Long... param) {
|
protected Void doInBackground(Long... param) {
|
||||||
final long MODE = param[0];
|
|
||||||
try {
|
try {
|
||||||
if (MODE == LOAD) {
|
switch(mode) {
|
||||||
if (mAdapter.getItemCount() > 0) {
|
case LOAD:
|
||||||
message = twitter.getMessages();
|
if (mAdapter.getItemCount() > 0) {
|
||||||
mData.storeMessage(message);
|
|
||||||
message = mData.getMessages();
|
|
||||||
} else {
|
|
||||||
message = mData.getMessages();
|
|
||||||
if (message.isEmpty()) {
|
|
||||||
message = twitter.getMessages();
|
message = twitter.getMessages();
|
||||||
mData.storeMessage(message);
|
mData.storeMessage(message);
|
||||||
|
message = mData.getMessages();
|
||||||
|
} else {
|
||||||
|
message = mData.getMessages();
|
||||||
|
if (message.isEmpty()) {
|
||||||
|
message = twitter.getMessages();
|
||||||
|
mData.storeMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} else if (MODE == DELETE) {
|
|
||||||
mData.deleteDm(param[1]);
|
case DELETE:
|
||||||
message = mData.getMessages();
|
long messageId = param[0];
|
||||||
twitter.deleteMessage(param[1]);
|
twitter.deleteMessage(messageId);
|
||||||
|
mData.deleteDm(messageId);
|
||||||
|
message = mData.getMessages();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (TwitterException err) {
|
} catch (TwitterException err) {
|
||||||
this.err = err;
|
this.err = err;
|
||||||
return FAIL;
|
failure = true;
|
||||||
} catch (Exception err) {
|
} catch (Exception err) {
|
||||||
Log.e("Direct Message", err.getMessage());
|
Log.e("Direct Message", err.getMessage());
|
||||||
return FAIL;
|
failure = true;
|
||||||
}
|
}
|
||||||
return MODE;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Long mode) {
|
protected void onPostExecute(Void mode) {
|
||||||
if (ui.get() == null) return;
|
if (ui.get() == null) return;
|
||||||
|
|
||||||
SwipeRefreshLayout mRefresh = ui.get().findViewById(R.id.dm_reload);
|
SwipeRefreshLayout mRefresh = ui.get().findViewById(R.id.dm_reload);
|
||||||
mRefresh.setRefreshing(false);
|
mRefresh.setRefreshing(false);
|
||||||
|
|
||||||
if (mode != FAIL) {
|
if (!failure) {
|
||||||
mAdapter.setData(message);
|
mAdapter.setData(message);
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,6 +22,8 @@ import org.nuclearfog.twidda.backend.items.Message;
|
|||||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||||
|
|
||||||
import static android.os.AsyncTask.Status.RUNNING;
|
import static android.os.AsyncTask.Status.RUNNING;
|
||||||
|
import static org.nuclearfog.twidda.backend.MessageLoader.Mode.DELETE;
|
||||||
|
import static org.nuclearfog.twidda.backend.MessageLoader.Mode.LOAD;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct Message page
|
* Direct Message page
|
||||||
@ -67,8 +69,8 @@ public class DirectMessage extends AppCompatActivity implements OnRefreshListene
|
|||||||
mAdapter.setColor(settings.getFontColor(), settings.getHighlightColor());
|
mAdapter.setColor(settings.getFontColor(), settings.getHighlightColor());
|
||||||
mAdapter.setImageLoad(settings.getImageLoad());
|
mAdapter.setImageLoad(settings.getImageLoad());
|
||||||
dmList.setAdapter(mAdapter);
|
dmList.setAdapter(mAdapter);
|
||||||
mLoader = new MessageLoader(this);
|
mLoader = new MessageLoader(this, LOAD);
|
||||||
mLoader.execute(MessageLoader.LOAD);
|
mLoader.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +126,8 @@ public class DirectMessage extends AppCompatActivity implements OnRefreshListene
|
|||||||
.setPositiveButton(R.string.yes_confirm, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.yes_confirm, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
mLoader = new MessageLoader(DirectMessage.this);
|
mLoader = new MessageLoader(DirectMessage.this, DELETE);
|
||||||
mLoader.execute(MessageLoader.DELETE, messageId);
|
mLoader.execute(messageId);
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
@ -156,7 +158,7 @@ public class DirectMessage extends AppCompatActivity implements OnRefreshListene
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
mLoader = new MessageLoader(this);
|
mLoader = new MessageLoader(this, LOAD);
|
||||||
mLoader.execute(MessageLoader.LOAD);
|
mLoader.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user