Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,33 @@

package io.scalaproject.vault.fragment.send;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.pdf.PdfDocument;
import android.graphics.pdf.PdfDocument.Page;
import android.graphics.pdf.PdfDocument.PageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import io.scalaproject.vault.R;
import io.scalaproject.vault.data.PendingTx;
import io.scalaproject.vault.data.TxData;
Expand Down Expand Up @@ -70,14 +89,15 @@ interface Listener {
private TextView tvTxPaymentId;
private TextView tvTxAmount;
private TextView tvTxFee;
private Button btnReceipt;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

Timber.d("onCreateView() %s", (String.valueOf(savedInstanceState)));

View view = inflater.inflate(
final View view = inflater.inflate(
R.layout.fragment_send_success, container, false);

bCopyTxId = view.findViewById(R.id.bCopyTxId);
Expand All @@ -94,6 +114,73 @@ public void onClick(View v) {
tvTxPaymentId = view.findViewById(R.id.tvTxPaymentId);
tvTxAmount = view.findViewById(R.id.tvTxAmount);
tvTxFee = view.findViewById(R.id.tvTxFee);
btnReceipt = view.findViewById(R.id.btnReceipt);

btnReceipt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnReceipt.setVisibility(View.GONE);

// create a new document
PdfDocument document = new PdfDocument();
FileOutputStream fOut = null;
Log.d("XLA", "Download Clicked");
try {

// create a page description
PageInfo pageInfo = new PageInfo.Builder(view.getWidth(), view.getHeight(), 1).create();

// start a page
Page page = document.startPage(pageInfo);
view.draw(page.getCanvas());

// finish the page
document.finishPage(page);
// add more pages
// write the document content
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/txs";

File dir = new File(path);

if (!dir.exists())
dir.mkdirs();

File file = new File(dir, "receipt.pdf");

fOut = new FileOutputStream(file);

document.writeTo(fOut);
fOut.flush();
fOut.close();

Intent intentShareFile = new Intent(Intent.ACTION_SEND);

if(file.exists()) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

intentShareFile.setType("application/pdf");
intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, "Sharing File...");
intentShareFile.putExtra(Intent.EXTRA_TEXT, file.getName());
intentShareFile.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intentShareFile, "Share File"));
}


} catch (FileNotFoundException de) {
Log.e("XLA", "DocumentException:" + de);
} catch (IOException e) {
Log.e("XLA", "ioException:" + e);
}
finally {
document.close();
}

btnReceipt.setVisibility(View.VISIBLE);

}
});

return view;
}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/fragment_send_success.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
android:layout_height="wrap_content"
android:layout_weight="2"
android:textAlignment="textEnd"
tools:text="143.008000 XLA" />
tools:text="14300.08 XLA" />

<TextView
android:id="@+id/tvTxFee"
Expand Down Expand Up @@ -117,5 +117,11 @@
android:textAlignment="textStart"
tools:text="4AdkPJoxn7JCvAby9szgnt93MSEwdnxdhaASxbTBm6x5dCwmsDep2UYN4FhStDn5i11nsJbpU7oj59ahg8gXb1Mg3viqCuk" />

<Button
android:id="@+id/btnReceipt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/download" />

</LinearLayout>
</ScrollView>