mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-31 19:34:55 +01:00
fixed memory leaks
This commit is contained in:
parent
8a9b503484
commit
e6b4379b5f
@ -8,15 +8,18 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
||||
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageHolder> {
|
||||
|
||||
private OnImageClickListener l;
|
||||
private WeakReference<OnImageClickListener> itemClickListener;
|
||||
private Bitmap images[];
|
||||
|
||||
|
||||
public ImageAdapter(OnImageClickListener l) {
|
||||
itemClickListener = new WeakReference<>(l);
|
||||
images = new Bitmap[0];
|
||||
this.l = l;
|
||||
}
|
||||
|
||||
|
||||
@ -52,18 +55,31 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageHolder>
|
||||
vh.item.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
l.onImageClick(image);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onImageClick(image);
|
||||
}
|
||||
});
|
||||
vh.item.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return l.onImageTouch(image);
|
||||
if (itemClickListener.get() != null)
|
||||
return itemClickListener.get().onImageTouch(image);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class ImageHolder extends ViewHolder {
|
||||
final ImageView item;
|
||||
|
||||
ImageHolder(ImageView item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface OnImageClickListener {
|
||||
/**
|
||||
* simple click on image
|
||||
@ -80,13 +96,4 @@ public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageHolder>
|
||||
*/
|
||||
boolean onImageTouch(Bitmap image);
|
||||
}
|
||||
|
||||
class ImageHolder extends ViewHolder {
|
||||
final ImageView item;
|
||||
|
||||
ImageHolder(ImageView item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import org.nuclearfog.tag.Tagger.OnTagClickListener;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.backend.items.Message;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@ -25,18 +26,18 @@ import java.util.List;
|
||||
|
||||
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageHolder> {
|
||||
|
||||
private WeakReference<OnItemSelected> itemClickListener;
|
||||
private Message messages[];
|
||||
private OnItemSelected mListener;
|
||||
|
||||
|
||||
private boolean loadImage = true;
|
||||
private int highlight;
|
||||
private int fontColor = 0xFFFFFFFF;
|
||||
private int fontColor;
|
||||
private boolean loadImage;
|
||||
|
||||
|
||||
public MessageAdapter(OnItemSelected listener) {
|
||||
public MessageAdapter(OnItemSelected l) {
|
||||
itemClickListener = new WeakReference<>(l);
|
||||
messages = new Message[0];
|
||||
this.mListener = listener;
|
||||
fontColor = 0xFFFFFFFF;
|
||||
loadImage = true;
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +84,8 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
|
||||
public void onClick(View v) {
|
||||
RecyclerView rv = (RecyclerView) parent;
|
||||
int position = rv.getChildLayoutPosition(view);
|
||||
mListener.onAnswer(position);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onAnswer(position);
|
||||
}
|
||||
});
|
||||
view.findViewById(R.id.dm_delete).setOnClickListener(new View.OnClickListener() {
|
||||
@ -91,7 +93,8 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
|
||||
public void onClick(View v) {
|
||||
RecyclerView rv = (RecyclerView) parent;
|
||||
int position = rv.getChildLayoutPosition(view);
|
||||
mListener.onDelete(position);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onDelete(position);
|
||||
}
|
||||
});
|
||||
view.findViewById(R.id.dm_profileImg).setOnClickListener(new View.OnClickListener() {
|
||||
@ -99,7 +102,8 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
|
||||
public void onClick(View v) {
|
||||
RecyclerView rv = (RecyclerView) parent;
|
||||
int position = rv.getChildLayoutPosition(view);
|
||||
mListener.onProfileClick(position);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onProfileClick(position);
|
||||
}
|
||||
});
|
||||
return new MessageHolder(view);
|
||||
@ -108,11 +112,16 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageH
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MessageHolder vh, int index) {
|
||||
Spanned text;
|
||||
Message message = messages[index];
|
||||
Spanned text = Tagger.makeText(message.getText(), highlight, mListener);
|
||||
if (itemClickListener.get() != null)
|
||||
text = Tagger.makeText(message.getText(), highlight, itemClickListener.get());
|
||||
else
|
||||
text = Tagger.makeText(message.getText(), highlight);
|
||||
|
||||
vh.message.setText(text);
|
||||
vh.message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
vh.message.setLinkTextColor(highlight);
|
||||
vh.message.setText(text);
|
||||
vh.username.setText(message.getSender().getUsername());
|
||||
vh.screenname.setText(message.getSender().getScreenname());
|
||||
vh.createdAt.setText(stringTime(message.getTime()));
|
||||
|
@ -18,6 +18,7 @@ import org.nuclearfog.tag.Tagger;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.backend.items.Tweet;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
@ -27,18 +28,21 @@ import java.util.List;
|
||||
|
||||
public class TimelineAdapter extends Adapter<TimelineAdapter.ItemHolder> {
|
||||
|
||||
private OnItemClickListener mListener;
|
||||
private WeakReference<OnItemClickListener> itemClickListener;
|
||||
private Tweet tweets[];
|
||||
|
||||
private NumberFormat formatter;
|
||||
private int highlight = 0xFFFFFFFF;
|
||||
private int font_color = 0xFFFFFFFF;
|
||||
private int highlight;
|
||||
private int font_color;
|
||||
private boolean img_ldr = true;
|
||||
|
||||
|
||||
public TimelineAdapter(OnItemClickListener mListener) {
|
||||
tweets = new Tweet[0];
|
||||
public TimelineAdapter(OnItemClickListener l) {
|
||||
itemClickListener = new WeakReference<>(l);
|
||||
formatter = NumberFormat.getIntegerInstance();
|
||||
this.mListener = mListener;
|
||||
tweets = new Tweet[0];
|
||||
highlight = 0xFFFFFFFF;
|
||||
font_color = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +93,8 @@ public class TimelineAdapter extends Adapter<TimelineAdapter.ItemHolder> {
|
||||
public void onClick(View v) {
|
||||
RecyclerView rv = (RecyclerView) parent;
|
||||
int position = rv.getChildLayoutPosition(v);
|
||||
mListener.onItemClick(rv, position);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onItemClick(rv, position);
|
||||
}
|
||||
});
|
||||
return new ItemHolder(v);
|
||||
|
@ -13,18 +13,21 @@ import android.widget.TextView;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.backend.items.Trend;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class TrendAdapter extends Adapter<TrendAdapter.ItemHolder> {
|
||||
|
||||
|
||||
private WeakReference<OnItemClickListener> itemClickListener;
|
||||
private Trend trends[];
|
||||
private OnItemClickListener mListener;
|
||||
private int font_color = 0xFFFFFFFF;
|
||||
private int font_color;
|
||||
|
||||
|
||||
public TrendAdapter(OnItemClickListener mListener) {
|
||||
public TrendAdapter(OnItemClickListener l) {
|
||||
itemClickListener = new WeakReference<>(l);
|
||||
trends = new Trend[0];
|
||||
this.mListener = mListener;
|
||||
font_color = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +61,8 @@ public class TrendAdapter extends Adapter<TrendAdapter.ItemHolder> {
|
||||
public void onClick(View v) {
|
||||
RecyclerView rv = (RecyclerView) parent;
|
||||
int position = rv.getChildLayoutPosition(v);
|
||||
mListener.onItemClick(rv, position);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onItemClick(rv, position);
|
||||
}
|
||||
});
|
||||
return new ItemHolder(v);
|
||||
|
@ -16,19 +16,22 @@ import com.squareup.picasso.Picasso;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class UserAdapter extends Adapter<UserAdapter.ItemHolder> {
|
||||
|
||||
private WeakReference<OnItemClickListener> itemClickListener;
|
||||
private TwitterUser mUser[];
|
||||
private OnItemClickListener mListener;
|
||||
private int font_color = 0xFFFFFFFF;
|
||||
private boolean loadImage = true;
|
||||
private int font_color;
|
||||
private boolean loadImage;
|
||||
|
||||
|
||||
public UserAdapter(OnItemClickListener mListener) {
|
||||
public UserAdapter(OnItemClickListener l) {
|
||||
itemClickListener = new WeakReference<>(l);
|
||||
mUser = new TwitterUser[0];
|
||||
this.mListener = mListener;
|
||||
font_color = 0xFFFFFFFF;
|
||||
loadImage = true;
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +76,8 @@ public class UserAdapter extends Adapter<UserAdapter.ItemHolder> {
|
||||
public void onClick(View v) {
|
||||
RecyclerView rv = (RecyclerView) parent;
|
||||
int position = rv.getChildLayoutPosition(v);
|
||||
mListener.onItemClick(rv, position);
|
||||
if (itemClickListener.get() != null)
|
||||
itemClickListener.get().onItemClick(rv, position);
|
||||
}
|
||||
});
|
||||
return new ItemHolder(v);
|
||||
|
Loading…
x
Reference in New Issue
Block a user