Skip to content

Commit

Permalink
[CHORE]: Added first page as preview in pdf lister
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmjr committed May 21, 2024
1 parent ce0c4e1 commit 099fbe0
Show file tree
Hide file tree
Showing 29 changed files with 528 additions and 194 deletions.
5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ dependencies {
implementation libs.androidx.lifecycle.viewmodel.ktx
implementation libs.androidx.navigation.fragment.ktx
implementation libs.androidx.navigation.ui.ktx
implementation libs.cardview
implementation libs.androidx.activity
implementation libs.fragmentKtx
implementation libs.splashScreen
implementation libs.recyclerView
compileOnly libs.lombok
implementation libs.pdf.viewer
implementation libs.pdfium
testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
Expand Down
22 changes: 1 addition & 21 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.shockwave.*
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<application
Expand All @@ -14,8 +15,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AllEBooks"
tools:targetApi="31"
android:requestLegacyExternalStorage="true">
tools:targetApi="31">
<activity
android:name=".activities.PdfViewerActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
73 changes: 46 additions & 27 deletions app/src/main/java/com/mjrt/app/allebooks/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,66 @@ import android.view.Menu
import androidx.core.content.ContextCompat
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.mjrt.app.allebooks.activities.BaseActivity
import com.mjrt.app.allebooks.adapters.PdfDocumentsAdapter
import com.mjrt.app.allebooks.databinding.ActivityMainBinding
import com.mjrt.app.allebooks.document_manager.DocumentManager.READ_STORAGE_PERMISSION_CODE
import com.mjrt.app.allebooks.document_manager.DocumentManager
import com.mjrt.app.allebooks.document_manager.DocumentManager.Companion.READ_STORAGE_PERMISSION_CODE

class MainActivity : BaseActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var navHostFragment: NavHostFragment
private lateinit var navController: NavController
private lateinit var binding: ActivityMainBinding
lateinit var documentManager: DocumentManager
lateinit var pdfDocumentsAdapter: PdfDocumentsAdapter

override fun initializeActivity(): Boolean {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
return true
}

private fun setNavigation() {
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_reading, R.id.nav_read
), binding.drawerLayout
)
navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_content_main) as NavHostFragment
navController = navHostFragment.navController
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_reading, R.id.nav_read
), binding.drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
binding.navView.setupWithNavController(navController)
}

private fun checkForReadPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
if (ContextCompat.checkSelfPermission(
applicationContext, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
READ_STORAGE_PERMISSION_CODE
)
} else
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
if (ContextCompat.checkSelfPermission(
applicationContext, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
) {
requestPermissions(
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
READ_STORAGE_PERMISSION_CODE
)
} else {
onPermissionsLegalizer()
}
} else {
onPermissionsLegalizer()
}
}
}

override fun onRequestPermissionsResult(
Expand All @@ -50,25 +80,14 @@ class MainActivity : BaseActivity() {
onPermissionsLegalizer()
}

override fun initializeAttributes() {
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_reading, R.id.nav_read
), binding.drawerLayout
)
navController = findNavController(R.id.nav_host_fragment_content_main)
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_reading, R.id.nav_read
), binding.drawerLayout
)
setNavigation()
checkForReadPermission()
private fun onPermissionsLegalizer() {
documentManager = DocumentManager.getInstance(applicationContext)!!
pdfDocumentsAdapter = PdfDocumentsAdapter(applicationContext, documentManager.pdfDocuments)
}

private fun setNavigation() {
setupActionBarWithNavController(navController, appBarConfiguration)
binding.navView.setupWithNavController(navController)
override fun initializeAttributes() {
checkForReadPermission()
setNavigation()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.mjrt.app.allebooks.R
import com.mjrt.app.allebooks.document_manager.DocumentManager

abstract class BaseActivity: AppCompatActivity() {
private lateinit var handler: Handler
Expand All @@ -23,10 +22,6 @@ abstract class BaseActivity: AppCompatActivity() {

protected abstract fun initializeActivity(): Boolean

protected fun onPermissionsLegalizer() {
DocumentManager.getInstance(applicationContext).loadAllDocuments()
}

private fun setDefaultToolbar() {
setToolbar(R.id.toolbar)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mjrt.app.allebooks.activities

import com.mjrt.app.allebooks.databinding.ActivityPdfViewerBinding

class PdfViewerActivity : BaseActivity() {
private lateinit var binding: ActivityPdfViewerBinding

override fun initializeActivity(): Boolean {
binding = ActivityPdfViewerBinding.inflate(layoutInflater)
setContentView(binding.root)
return true
}

override fun initializeAttributes() {
TODO("Not yet implemented")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.mjrt.app.allebooks.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mjrt.app.allebooks.R
import com.mjrt.app.allebooks.models.PdfDocument

class PdfDocumentsAdapter(
private val context: Context,
var pdfDocuments: ArrayList<PdfDocument>
) : RecyclerView.Adapter<PdfDocumentsAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
LayoutInflater.from(
context
).inflate(R.layout.cardview_document, parent, false)
)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
pdfDocuments[position].apply {
holder.also {
it.docName.text = title
it.docSize.text = size.toString()
it.thumbnail.setImageBitmap(thumbnail)
}
}
}
override fun getItemCount(): Int {
return pdfDocuments.size
}

inner class ViewHolder(view: View?) : RecyclerView.ViewHolder(view!!) {
val docName: TextView
val docSize: TextView
val thumbnail: ImageView

init {
docName = view!!.findViewById(R.id.doc_name)
docSize = view.findViewById(R.id.doc_size)
thumbnail = view.findViewById(R.id.thumbnail)
}
}
}

This file was deleted.

Loading

0 comments on commit 099fbe0

Please sign in to comment.