Skip to content

Commit

Permalink
Merge pull request #141 from trufla-technology/fix_attached_more_than…
Browse files Browse the repository at this point in the history
…_imges_and_titiles

fix attached more than images
  • Loading branch information
islamwt authored Sep 5, 2021
2 parents aa93ed8 + 48811de commit 0349b4c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

setContentView(R.layout.pdfviewer);
pdfView = findViewById(R.id.doc_pdf_viewer);
String base64 = SharedData.getInstance().getBase64_pdf();
String key = getIntent().getStringExtra("bitmap");

String base64 = SharedData.getInstance().getBase64().get(key);
storage = new Storage(this);
loadPDF(base64);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_viewer);

Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("bitmap");

//String base64 = SharedData.getInstance().getBase64_image();
String key = getIntent().getStringExtra("bitmap");
String base64 = SharedData.getInstance().getBase64().get(key);
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
// Bitmap bitmap = BitmapUtils.decodeBase64ToBitmap(base64);
Bitmap bitmap = BitmapUtils.decodeBase64ToBitmap(base64);
photoView.setImageBitmap(bitmap);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.trufla.androidtruforms.utils.TruUtils;

import java.util.HashMap;

/**
* Created by Mohamed Salah on 10,March,2020
* Trufla Technology,
Expand All @@ -18,13 +20,26 @@ public class SharedData
private String base64_pdf ;
private String base64_image ;


public HashMap<String, String> getBase64() {
return base64;
}

public void setBase64(HashMap<String, String> base64) {
this.base64 = base64;
}

private HashMap<String,String> base64 ;

// Restrict the constructor from being instantiated
private SharedData() {
base64 = new HashMap<>();
}

public static synchronized SharedData getInstance() {
if (instance == null) {
instance = new SharedData();

}
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -30,9 +31,13 @@
import com.trufla.androidtruforms.utils.ColorFactory;
import com.trufla.androidtruforms.utils.PDFUtil;

import java.util.HashMap;


public class TruPhotoPickerView extends TruStringView {
String base64Image = "";
Object constItem;
String key = "";

public TruPhotoPickerView(Context context, StringInstance instance) {
super(context, instance);
Expand Down Expand Up @@ -94,8 +99,11 @@ private TruConsumer<ImageModel> getImagePickedListener() {
}

private void setImageToView(Bitmap bitmap) {

mView.findViewById(R.id.photo_thumb_container).setVisibility(View.GONE);
((ImageView) mView.findViewById(R.id.photo)).setImageBitmap(bitmap);
ImageView imageView = ((ImageView) mView.findViewById(R.id.photo));
imageView.setImageBitmap(bitmap);
imageView.setTag(key);
mView.findViewById(R.id.photo_container).setVisibility(View.VISIBLE);
}

Expand Down Expand Up @@ -124,26 +132,40 @@ public LinearLayout.LayoutParams getLayoutParams() {

@Override
protected void setNonEditableValues(Object constItem) {
this.constItem = constItem;
sharedData = SharedData.getInstance();
if (instance!= null && instance.getPresentationTitle() != null)
((TextView) mView.findViewById(R.id.title)).setText(instance.getPresentationTitle());
if (constItem instanceof String && !TextUtils.isEmpty(constItem.toString())) {
mView.findViewById(R.id.title).setVisibility(View.GONE);
if (sharedData.getBase64().containsKey(instance.getPresentationTitle())){
key = instance.getPresentationTitle()+sharedData.getBase64().size();
}else{
key = instance.getPresentationTitle();
}

try {
if(constItem.toString().startsWith(FileCompressTask.PDF_CONST)){
String[] str = constItem.toString().split(",");
Uri uri = Uri.parse(PDFUtil.savePDF(str[1],mContext)) ;
Bitmap bmp = PDFUtil.generateImageFromPdf(uri,mContext);
// Bitmap bmp = BitmapUtils.getBitmapFromDrawable(mContext,R.drawable.ic_pdf_file_icon);

setImageToView(bmp);
mView.setEnabled(true);
sharedData = SharedData.getInstance();
//sharedData = SharedData.getInstance();
sharedData.setBase64_pdf(str[1]);
sharedData.getBase64().put(key,str[1]);

mView.findViewById(R.id.photo_container).setOnClickListener(view -> startPDFViewer(mContext));

}else {
Bitmap img = BitmapUtils.decodeBase64ToBitmap(constItem.toString());
sharedData.getBase64().put(key,constItem.toString());
setImageToView(img);
mView.setEnabled(true);
sharedData = SharedData.getInstance();
//sharedData = SharedData.getInstance();
sharedData.setBase64_image(constItem.toString());

mView.findViewById(R.id.photo_container).setOnClickListener(view -> startPhotoViewer(mContext));
}
} catch (Exception e) {
Expand All @@ -157,17 +179,19 @@ protected void setNonEditableValues(Object constItem) {

private void startPhotoViewer( Context context) {


ImageView image = ((ImageView) mView.findViewById(R.id.photo));
image.buildDrawingCache();
Bitmap bitmap = image.getDrawingCache();
Log.e("TAG",image.getTag().toString());
Intent intent = new Intent(context, PhotoViewerActivity.class);
intent.putExtra("bitmap",bitmap);
intent.putExtra("bitmap",image.getTag().toString());
context.startActivity(intent);
}

private void startPDFViewer( Context context) {

ImageView image = ((ImageView) mView.findViewById(R.id.photo));
Log.e("TAG",image.getTag().toString());
Intent intent = new Intent(context, PDFViewerActivity.class);
intent.putExtra("bitmap",image.getTag().toString());
context.startActivity(intent);

}
Expand Down

0 comments on commit 0349b4c

Please sign in to comment.