-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDF and Image
- Loading branch information
Showing
8 changed files
with
192 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 37 additions & 2 deletions
39
app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/AbdmPdfViewer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,48 @@ | ||
package org.commcare.dalvik.abha.ui.main.fragment | ||
|
||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import org.commcare.dalvik.abha.databinding.PdfBinding | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.DialogFragment | ||
import org.commcare.dalvik.abha.R | ||
import org.commcare.dalvik.abha.databinding.ImgPdfBinding | ||
import org.commcare.dalvik.abha.ui.main.adapters.FileData | ||
import org.commcare.dalvik.abha.ui.main.adapters.FileType | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.util.Base64 | ||
|
||
class AbdmPdfViewer: BaseFragment<PdfBinding>(PdfBinding::inflate) { | ||
class AbdmImgAndPdfViewer(private val fileData: FileData) : DialogFragment() { | ||
|
||
lateinit var binding: ImgPdfBinding | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
isCancelable = false | ||
binding = ImgPdfBinding.inflate(inflater, container, false) | ||
binding.model = fileData | ||
return binding.root | ||
} | ||
|
||
override fun getTheme(): Int { | ||
return R.style.DialogTheme | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
if (fileData.fileType == FileType.PDF) { | ||
val decoded = Base64.getDecoder().decode(fileData.fileData) | ||
binding.pdfView.fromBytes(decoded).load() | ||
|
||
} | ||
|
||
binding.closeDialog.setOnClickListener { | ||
dismiss() | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<data class="ImgPdfBinding"> | ||
|
||
<variable | ||
name="model" | ||
type="org.commcare.dalvik.abha.ui.main.adapters.FileData" /> | ||
|
||
<import type="org.commcare.dalvik.abha.ui.main.adapters.FileType" /> | ||
|
||
<import type="android.view.View" /> | ||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<ImageView | ||
android:id="@+id/closeDialog" | ||
android:layout_width="@dimen/_32dp" | ||
android:layout_height="@dimen/_32dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
android:elevation="@dimen/_10dp" | ||
app:tint="@color/blue" | ||
app:srcCompat="@drawable/ic_baseline_close_24" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/reportImage" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:loadImage="@{model.fileData}" | ||
android:visibility="@{model.fileType == FileType.IMAGE ? View.VISIBLE : View.GONE}" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.5" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.5" | ||
tools:srcCompat="@tools:sample/avatars" /> | ||
|
||
<com.github.barteksc.pdfviewer.PDFView | ||
android:id="@+id/pdfView" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:visibility="@{model.fileType == FileType.PDF ? View.VISIBLE : View.GONE}" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.5" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.5"> | ||
|
||
</com.github.barteksc.pdfviewer.PDFView> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters