forked from shihaam/thijooree
fix Transfer slip share from the share button #42
This commit is contained in:
@@ -11,17 +11,13 @@ import android.graphics.BitmapFactory
|
|||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.graphics.Rect
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.PixelCopy
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@@ -159,9 +155,6 @@ class TransferReceiptFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
view.findViewById<MaterialButton>(R.id.btnDone).setOnClickListener {
|
|
||||||
parentFragmentManager.popBackStack()
|
|
||||||
}
|
|
||||||
view.findViewById<MaterialButton>(R.id.btnShare).setOnClickListener {
|
view.findViewById<MaterialButton>(R.id.btnShare).setOnClickListener {
|
||||||
shareReceipt()
|
shareReceipt()
|
||||||
}
|
}
|
||||||
@@ -377,21 +370,19 @@ class TransferReceiptFragment : Fragment() {
|
|||||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Captures the receipt card using PixelCopy, which correctly handles
|
* Draws the receipt card to an offscreen bitmap at its natural (unscaled)
|
||||||
* hardware-accelerated views (avoids the black-square problem with view.draw()).
|
* dimensions, so the captured image isn't affected by the on-screen scale
|
||||||
|
* applied to fit small viewports and doesn't pick up overlapping siblings.
|
||||||
*/
|
*/
|
||||||
private fun captureReceiptBitmap(callback: (Bitmap?) -> Unit) {
|
private fun captureReceiptBitmap(callback: (Bitmap?) -> Unit) {
|
||||||
val view = _receiptCard ?: run { callback(null); return }
|
val view = _receiptCard ?: run { callback(null); return }
|
||||||
if (view.width == 0 || view.height == 0) { callback(null); return }
|
if (view.width == 0 || view.height == 0) { callback(null); return }
|
||||||
|
|
||||||
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
|
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
|
||||||
val location = IntArray(2)
|
val canvas = Canvas(bitmap)
|
||||||
view.getLocationInWindow(location)
|
canvas.drawColor(Color.WHITE)
|
||||||
val srcRect = Rect(location[0], location[1], location[0] + view.width, location[1] + view.height)
|
view.draw(canvas)
|
||||||
|
callback(bitmap)
|
||||||
PixelCopy.request(requireActivity().window, srcRect, bitmap, { result ->
|
|
||||||
callback(if (result == PixelCopy.SUCCESS) bitmap else null)
|
|
||||||
}, Handler(Looper.getMainLooper()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatBmlTimestamp(raw: String): String {
|
private fun formatBmlTimestamp(raw: String): String {
|
||||||
|
|||||||
@@ -246,18 +246,10 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_marginHorizontal="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:text="Save"
|
android:text="Save"
|
||||||
app:icon="@drawable/ic_save" />
|
app:icon="@drawable/ic_save" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnDone"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:text="Done" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -376,18 +376,10 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_marginHorizontal="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:text="Save"
|
android:text="Save"
|
||||||
app:icon="@drawable/ic_save" />
|
app:icon="@drawable/ic_save" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnDone"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:text="Done" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -273,18 +273,10 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_marginHorizontal="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:text="Save"
|
android:text="Save"
|
||||||
app:icon="@drawable/ic_save" />
|
app:icon="@drawable/ic_save" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnDone"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:text="Done" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user