Browse Source

Decrease memory usage

Fixes #22
tags/release-v2.6
Schoumi 3 years ago
parent
commit
726aad0e1d
2 changed files with 18 additions and 12 deletions
  1. +14
    -7
      app/src/main/java/fr/mobdev/goblim/activity/HistoryActivity.java
  2. +4
    -5
      app/src/main/java/fr/mobdev/goblim/objects/Img.java

+ 14
- 7
app/src/main/java/fr/mobdev/goblim/activity/HistoryActivity.java View File

@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -50,7 +51,7 @@ import fr.mobdev.goblim.R;
*/
public class HistoryActivity extends AppCompatActivity {

private List<Img> images;
private List<Long> imagesIdx;

@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -78,9 +79,9 @@ public class HistoryActivity extends AppCompatActivity {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent linkIntent = new Intent(HistoryActivity.this,LinkActivity.class);
if(position < images.size()) {
Img image = images.get(position);
linkIntent.putExtra("imageId", image.getId());
if(position < imagesIdx.size()) {
Long img = imagesIdx.get(position);
linkIntent.putExtra("imageId", img);
startActivity(linkIntent);
}
}
@@ -99,7 +100,12 @@ public class HistoryActivity extends AppCompatActivity {
{
ListView historyList = (ListView) findViewById(R.id.history_list);

images = Database.getInstance(getApplicationContext()).getHistory();
List<Img> images = Database.getInstance(getApplicationContext()).getHistory();
if(imagesIdx == null)
imagesIdx = new ArrayList<>();
imagesIdx.clear();
for(Img img : images)
imagesIdx.add(img.getId());
HistoryAdapter adapter = new HistoryAdapter(this,R.layout.history_item,R.id.url_history_item,images);
historyList.setAdapter(adapter);
}
@@ -112,15 +118,16 @@ public class HistoryActivity extends AppCompatActivity {
private LayoutInflater mInflater;
int resource;

public HistoryAdapter(Context context, int resource, int textViewResourceId, List<Img> objects) {
HistoryAdapter(Context context, int resource, int textViewResourceId, List<Img> objects) {
super(context, resource, textViewResourceId, objects);
images = new ArrayList<>(objects);
this.resource = resource;
mInflater = LayoutInflater.from(context);
}

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent)
public View getView(int position, View convertView, @NonNull ViewGroup parent)
{
Img image = images.get(position);
//reuse view or create a new one?

+ 4
- 5
app/src/main/java/fr/mobdev/goblim/objects/Img.java View File

@@ -31,7 +31,6 @@ public class Img {
private Calendar date;
private int storageDuration;
private byte[] thumb;
private Bitmap image;
private String shortHash;
private String realShortHash;
private String token;
@@ -46,9 +45,6 @@ public class Img {
this.storageDuration = storageDuration;
this.token = token;
thumb = thumbData;
if(thumb != null) {
image = BitmapFactory.decodeByteArray(thumb, 0, thumb.length);
}
}

public Long getId()
@@ -68,6 +64,10 @@ public class Img {

public Bitmap getThumb()
{
Bitmap image = null;
if(thumb != null) {
image = BitmapFactory.decodeByteArray(thumb, 0, thumb.length);
}
return image;
}

@@ -99,5 +99,4 @@ public class Img {
return token;
}


}

Loading…
Cancel
Save