Fix crashes

This commit is contained in:
tom79 2019-07-27 15:05:29 +02:00
parent 4dcb2cc3d9
commit 8ae5566054
3 changed files with 83 additions and 67 deletions

View File

@ -150,7 +150,7 @@ public class Status implements Parcelable{
private int warningFetched = -1;
private List<String> imageURL;
private boolean statusAnimated = false;
@Override
public void writeToParcel(Parcel dest, int flags) {
@ -1603,12 +1603,4 @@ public class Status implements Parcelable{
public void setImageURL(List<String> imageURL) {
this.imageURL = imageURL;
}
public boolean isStatusAnimated() {
return statusAnimated;
}
public void setStatusAnimated(boolean statusAnimated) {
this.statusAnimated = statusAnimated;
}
}

View File

@ -104,6 +104,7 @@ import app.fedilab.android.interfaces.OnPostNotificationsActionInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
import static android.content.Context.MODE_PRIVATE;
import static app.fedilab.android.activities.BaseMainActivity.social;
@ -123,7 +124,32 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
private boolean isOnWifi;
private NotificationsListAdapter.ViewHolder holder;
private int style;
private Timer timer;
private List<NotificationsListAdapter.ViewHolder> lstHolders;
private Runnable updateAnimatedEmoji = new Runnable() {
@Override
public void run() {
synchronized (lstHolders) {
for (NotificationsListAdapter.ViewHolder holder : lstHolders) {
holder.updateAnimatedEmoji();
}
}
}
};
private Handler mHandler = new Handler();
private void startUpdateTimer() {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
if( !disableAnimatedEmoji ){
Timer tmr = new Timer();
tmr.schedule(new TimerTask() {
@Override
public void run() {
mHandler.post(updateAnimatedEmoji);
}
}, 0, 130);
}
}
public NotificationsListAdapter(Context context, boolean isOnWifi, int behaviorWithAttachments, List<Notification> notifications){
this.context = context;
@ -132,6 +158,8 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
notificationsListAdapter = this;
this.isOnWifi = isOnWifi;
this.behaviorWithAttachments = behaviorWithAttachments;
lstHolders = new ArrayList<>();
startUpdateTimer();
}
@ -146,6 +174,11 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
holder = (NotificationsListAdapter.ViewHolder) viewHolder;
synchronized (lstHolders) {
lstHolders.add(holder);
}
final Notification notification = notifications.get(position);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -377,34 +410,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
holder.status_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.VISIBLE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
if( !disableAnimatedEmoji && !notification.isNotificationAnimated() && (status.getEmojis().size() > 0 || status.getAccount().getEmojis().size() > 0) ) {
notification.setNotificationAnimated(true);
/*try{
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
holder.notification_status_content.invalidate();
}
}, 0, 130, TimeUnit.MILLISECONDS);
}catch (Exception ignored){}*/
if( timer == null) {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
holder.notification_account_username.invalidate();
holder.notification_status_content.invalidate();
}
});
}
}, 0, 130);
}
}
if( !status.isClickable())
Status.transform(context, status);
if( !status.isEmojiFound())
@ -1485,6 +1491,12 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
submit_vote = itemView.findViewById(R.id.submit_vote);
refresh_poll = itemView.findViewById(R.id.refresh_poll);
}
void updateAnimatedEmoji() {
holder.notification_account_username.invalidate();
holder.notification_status_content.invalidate();
}
}
}

View File

@ -216,7 +216,34 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private TextView warning_message;
private Status tootReply;
private long currentToId = -1;
private Timer timer;
private List<ViewHolder> lstHolders;
private Runnable updateAnimatedEmoji = new Runnable() {
@Override
public void run() {
synchronized (lstHolders) {
for (ViewHolder holder : lstHolders) {
holder.updateAnimatedEmoji();
}
}
}
};
private Handler mHandler = new Handler();
private void startUpdateTimer() {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
if( !disableAnimatedEmoji ){
Timer tmr = new Timer();
tmr.schedule(new TimerTask() {
@Override
public void run() {
mHandler.post(updateAnimatedEmoji);
}
}, 0, 130);
}
}
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, List<Status> statuses){
super();
this.context = context;
@ -227,6 +254,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
this.type = type;
this.targetedId = targetedId;
redraft = false;
lstHolders = new ArrayList<>();
startUpdateTimer();
}
public StatusListAdapter(Context context, TagTimeline tagTimeline, String targetedId, boolean isOnWifi, List<Status> statuses){
@ -240,6 +269,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
this.targetedId = targetedId;
redraft = false;
this.tagTimeline = tagTimeline;
lstHolders = new ArrayList<>();
startUpdateTimer();
}
public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, List<Status> statuses){
@ -252,6 +283,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
this.conversationPosition = position;
this.targetedId = targetedId;
redraft = false;
lstHolders = new ArrayList<>();
startUpdateTimer();
}
@ -776,7 +809,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
quick_reply_privacy = itemView.findViewById(R.id.quick_reply_privacy);
warning_message = itemView.findViewById(R.id.warning_message);
}
void updateAnimatedEmoji() {
status_account_displayname.invalidate();
status_content.invalidate();
}
}
@ -831,7 +868,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if( viewHolder.getItemViewType() != HIDDEN_STATUS ) {
final ViewHolder holder = (ViewHolder) viewHolder;
synchronized (lstHolders) {
lstHolders.add(holder);
}
final Status status = statuses.get(i);
if( status == null)
return;
@ -1172,35 +1213,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
if( !disableAnimatedEmoji && !status.isStatusAnimated() && (status.getEmojis().size() > 0 || status.getAccount().getEmojis().size() > 0) ) {
status.setStatusAnimated(true);
/*try{
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
holder.status_content.invalidate();
}
}, 0, 130, TimeUnit.MILLISECONDS);
}catch (Exception ignored){}*/
if( timer == null) {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
holder.status_account_displayname.invalidate();
holder.status_content.invalidate();
}
});
}
}, 0, 130);
}
}
holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100);
switch (translator) {