Skip to content

Commit

Permalink
Update Spacing and styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Long Do committed Jun 2, 2022
1 parent 549ca2a commit 085e8ae
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/lee/module/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {
}

getPdf = registerForActivityResult(ActivityResultContracts.GetContent()) {
startPdfActivity(it)
it?.let { startPdfActivity(it) }
}

findViewById<View>(R.id.btnOpenLocalFile).setOnClickListener {
Expand Down Expand Up @@ -80,7 +80,8 @@ class MainActivity : AppCompatActivity() {
private fun startPdfActivity(uri: Uri) {
Intent(Intent.ACTION_VIEW).apply {
val fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri.toString())
val type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension.toLowerCase())
val type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(fileExtension.toLowerCase())
setDataAndType(uri, type)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:windowBackground">@android:color/transparent</item>
<!-- Customize your theme here. -->
</style>
</resources>
6 changes: 0 additions & 6 deletions pdfview/src/main/java/lee/module/pdfview/pdf/PdfView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ import android.graphics.pdf.PdfRenderer
import android.net.Uri
import android.util.AttributeSet
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
import lee.module.pdfview.R

class PdfView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr) {

init {
layoutManager = PreloadLayoutManager(context)
addItemDecoration(DividerItemDecoration(context, VERTICAL).apply {
setDrawable(ContextCompat.getDrawable(context, R.drawable.pv_divider_vertical_16)!!)
})
}

fun setPdfRenderer(renderer: PdfRenderer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import android.graphics.Bitmap
import android.graphics.pdf.PdfRenderer
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView
import lee.module.pdfview.R
import lee.module.pdfview.databinding.PvPdfItemBinding

class PdfViewAdapter(
Expand Down Expand Up @@ -55,10 +53,6 @@ class PdfViewAdapter(
RecyclerView.ViewHolder(binding.root) {

fun bind(bitmap: Bitmap) {
binding.root.updateLayoutParams {
height =
getScreenHeight() - itemView.resources.getDimensionPixelSize(R.dimen.pv_bottom_spacing)
}
binding.ivContent.setImageBitmap(bitmap)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import androidx.recyclerview.widget.RecyclerView
class PreloadLayoutManager(context: Context) : LinearLayoutManager(context) {

override fun getExtraLayoutSpace(state: RecyclerView.State?): Int {
return 3 * getScreenHeight()
return 5 * getScreenHeight()
}
}
5 changes: 0 additions & 5 deletions pdfview/src/main/res/drawable/pv_divider_vertical_16.xml

This file was deleted.

6 changes: 5 additions & 1 deletion pdfview/src/main/res/layout/activity_pv_pdf_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
<lee.module.pdfview.pdf.PdfView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:clipToPadding="false"
android:paddingTop="8dp"
android:paddingBottom="8dp" />
24 changes: 18 additions & 6 deletions pdfview/src/main/res/layout/pv_pdf_item.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<lee.module.pdfview.pdf.photoview.PhotoView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ivContent"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:background="@android:color/white"
android:minHeight="100dp" />
android:layout_height="match_parent">

<lee.module.pdfview.pdf.photoview.PhotoView
android:id="@+id/ivContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/white"
android:minHeight="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 085e8ae

Please sign in to comment.