aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Renard 2016-04-12 16:32:23 -0300
committerLibravatar Renard 2016-04-12 16:32:23 -0300
commitd1112bd475f069424397cc392ccbcb4871565f43 (patch)
tree20cde2471ae9a79e07e498225e13f9731a810687
parent90ee611af8ba4c38e70f27eb0df55e9134ad625c (diff)
downloadBaiApp-d1112bd475f069424397cc392ccbcb4871565f43.tar.gz
BaiApp-d1112bd475f069424397cc392ccbcb4871565f43.tar.xz
BaiApp-d1112bd475f069424397cc392ccbcb4871565f43.zip
Thumbnails changes
-rw-r--r--app/src/main/java/layout/FragmentBoardItemList.java24
1 files changed, 20 insertions, 4 deletions
diff --git a/app/src/main/java/layout/FragmentBoardItemList.java b/app/src/main/java/layout/FragmentBoardItemList.java
index 149def3..6095a86 100644
--- a/app/src/main/java/layout/FragmentBoardItemList.java
+++ b/app/src/main/java/layout/FragmentBoardItemList.java
@@ -49,6 +49,7 @@ import org.json.JSONObject;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
@@ -688,11 +689,15 @@ public class FragmentBoardItemList extends Fragment {
ContextWrapper cw = new ContextWrapper(getActivity().getApplicationContext());
File directory = cw.getDir("thumbs", Context.MODE_PRIVATE);
- File mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.getThumb());
+ if (!directory.exists()){
+ directory.mkdir();
+ }
+ final File mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.getThumb());
if (mypath.exists()){
try {
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(mypath));
- bi.setThumbBitmap(b);
+ bi.setThumbBitmap(Bitmap.createScaledBitmap(b, 128, 128, false));
+ listViewAdapter.notifyDataSetChanged();
Log.i("getThumb", bi.getThumb() + " from cache");
return;
}catch (Exception e){
@@ -714,9 +719,20 @@ public class FragmentBoardItemList extends Fragment {
if (e != null) {
displayError(e.getMessage());
e.printStackTrace();
- } else {
- bi.setThumbBitmap(result);
+ }else{
+ bi.setThumbBitmap(Bitmap.createScaledBitmap(result, 128, 128, false));
listViewAdapter.notifyDataSetChanged();
+ FileOutputStream out;
+ try{
+ out = new FileOutputStream(mypath);
+ result.compress(Bitmap.CompressFormat.PNG, 100, out);
+ if(out != null){
+ out.close();
+ }
+ Log.v("getThumb", bi.getThumb() + " saved.");
+ }catch (Exception e1){
+ e1.printStackTrace();
+ }
}
}
});