Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation of the Codebase #65

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

18 changes: 10 additions & 8 deletions app/src/main/java/com/vob/scanit/PDFProcessing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ import java.io.*
import java.util.*
import kotlin.collections.ArrayList

/* The following class enables us to generate, compress and save PDF documents*/
public class PDFProcessing(context: Context) {

lateinit var pdfDocument: PdfDocument
val context = context


/*makePDF() is used to create a new PDF document, start a page, write content to it and save the document*/
public fun makePDF(bitmap: Bitmap, filename: String) {
pdfDocument = PdfDocument()

pdfDocument = PdfDocument() //create a new PDF document

val compressedBitmap = compressBitmap(bitmap)
val pageInfo: PdfDocument.PageInfo = PdfDocument.PageInfo.Builder(compressedBitmap.width, compressedBitmap.height, 1).create()
val page: PdfDocument.Page = pdfDocument.startPage(pageInfo)
val page: PdfDocument.Page = pdfDocument.startPage(pageInfo) //start a page
val canvas: Canvas = page.getCanvas()
val paint = Paint()
paint.setColor(Color.parseColor("#FFFFFF"))
canvas.drawBitmap(compressedBitmap, 0.0f, 0.0f, null)
pdfDocument.finishPage(page)
pdfDocument.finishPage(page) //finish the page
//if (fileName.getText().toString().isEmpty()) {
// Toast.makeText(context, "You need to enter file name as follow\nyour_fileName.pdf", Toast.LENGTH_SHORT).show()
//}
Expand All @@ -44,13 +44,14 @@ public class PDFProcessing(context: Context) {
saveFileToScopedStorage(filename)
}

else
else //if filename does not have .pdf extension, we append it with the extension before calling save method
{
//saveFile("$filename.pdf")
saveFileToScopedStorage("$filename.pdf")
}
}

/*The following function compresses the document to a standard size*/
private fun compressBitmap(bitmap: Bitmap): Bitmap {
val originalHeight = bitmap.height
val originalWidth = bitmap.width
Expand All @@ -73,14 +74,13 @@ public class PDFProcessing(context: Context) {
return compressedBitmap
}


/* saveFile() writes the PDF document to the output stream */
fun saveFile(filename: String) {
if (pdfDocument == null) {
return
}
val root = File(Environment.getExternalStorageDirectory().absolutePath, "Scanner")


var isDirectoryCreated: Boolean = root.exists()
if (!isDirectoryCreated) {
isDirectoryCreated = root.mkdir()
Expand All @@ -104,6 +104,8 @@ public class PDFProcessing(context: Context) {
return true
}

/* The following function saves the PDF file. It uses the ContentValues class to store a
* set of values that the ContentResolver can process. The put() method adds a value to the set */
// fun queryScopedStorage() : ArrayList<PdfDocument> {
// val projection = arrayOf(
// MediaStore.MediaColumns.DISPLAY_NAME,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/vob/scanit/ThemeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.content.Context
import android.content.res.Configuration
import androidx.appcompat.app.AppCompatDelegate

/*This kotlin file defines the themes for the app, which allows the user to toggle between system theme,
* light theme and dark theme*/

fun currentSystemTheme(context: Context):Int{
return when(context.resources.configuration.uiMode.and(Configuration.UI_MODE_NIGHT_MASK)){
Configuration.UI_MODE_NIGHT_NO -> 1
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/vob/scanit/adapters/DocumentListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,38 @@ import androidx.recyclerview.widget.RecyclerView
import com.vob.scanit.R
import java.io.File

/* DocumentListAdapter class extends RecyclerView.Adapter, and overrides the methods needed for the
* Adapter to work. */
class DocumentListAdapter(private val documentList: ArrayList<File>):
RecyclerView.Adapter<DocumentListAdapter.DocumentViewHolder>()
{
/* DocumentViewHolder class extends RecyclerView.ViewHolder. It is used to represent the items in
our list and display them. */
class DocumentViewHolder(var view: View): RecyclerView.ViewHolder(view) {}

/* The following method updates the list of documents and informs the listener*/
fun updateDocumentList(newDocumentList: List<File>) {
documentList.clear()
documentList.addAll(newDocumentList)
notifyDataSetChanged()
}

/*The following method is called when the Adapter is created and is used to initialise the ViewHolder.
* LayoutInflater class is used to convert the xml file(adapter_pdf) to a view*/
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DocumentViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.adapter_pdf, parent, false)
return DocumentViewHolder(view)
}

/* The function onBindViewHolder() is called for each ViewHolder and is used to bind it to the Adapter.
* We pass the data to our ViewHolder using this function*/
override fun onBindViewHolder(holder: DocumentViewHolder, position: Int) {
val filename = holder.view.findViewById<TextView>(R.id.filename_TV)
filename.text = documentList.get(position).name
}

/* getItemCount() method returns the number of items in the list that we want to display */
override fun getItemCount(): Int {
return documentList.size
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/vob/scanit/adapters/PDFAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Locale;
import java.util.logging.Handler;

/* PDFAdapter class extends ArrayAdapter, specifying the type of data the adapter must display*/
public class PDFAdapter extends ArrayAdapter<File> {

Context context;
Expand All @@ -40,6 +41,8 @@ public class PDFAdapter extends ArrayAdapter<File> {
private ImageView options_btn;
Activity activity;

/*Defining a constructor that takes in arguments used to initialise the class variables
* This is required for inflating and adding data to our view */
public PDFAdapter(Context context, ArrayList<File> fileList, Activity activity) {
super(context, R.layout.adapter_pdf, fileList);
this.context = context;
Expand All @@ -48,11 +51,13 @@ public PDFAdapter(Context context, ArrayList<File> fileList, Activity activity)
this.searchList.addAll(this.fileList);
}

/*The following method returns the view type of the item at position*/
@Override
public int getItemViewType(int position) {
return position;
}

/*The following method returns the number of different types of views*/
@Override
public int getViewTypeCount() {
if (fileList.size() > 0)
Expand All @@ -61,6 +66,8 @@ public int getViewTypeCount() {
return 1;
}

/* We override the method getView() that is called when the items are created and populated with data
* In this method, the view gets inflated if the view is new (check for null) */
@NonNull
@Override
public View getView(int position, @Nullable View view, @NonNull ViewGroup parent) {
Expand Down Expand Up @@ -90,6 +97,11 @@ public void onClick(View v) {
return view;
}

/* In the following method, we find the file searched for by the user.
We convert the text we receive into the lowercase characters of the language in the region
where the app is being used(using Locale.getDefault()).
Using notifyDataSetChanged(), we can notify the listeners attached to our adapter about the
changes in the underlying data, so that any view reflecting this data can be refreshed accordingly*/
public void filter(String characterText) {
characterText = characterText.toLowerCase(Locale.getDefault());
fileList.clear();
Expand All @@ -110,6 +122,7 @@ public void filter(String characterText) {
notifyDataSetChanged();
}

/* We define a ViewHolder class to be used with our Adapter */
public class ViewHolder
{
TextView filename;
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/vob/scanit/adapters/PdfAdapterRv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ import java.io.File
import java.util.*
import kotlin.collections.ArrayList

/* PdfAdapterRv class extends RecyclerView.Adapter and takes in arguments and a listener,
along with overriding the methods needed for the Adapter to work. */

class PdfAdapterRv(private val context: Context, private val activity: Activity,
private val fileList: ArrayList<File>,private val pdfInterface: PdfAdapterInterface) :
RecyclerView.Adapter<PdfAdapterRv.PdfAdapterViewHolder>(){

private val searchList: ArrayList<File> = ArrayList()

/* PdfAdapterViewHolder contains all the elements that gets displayed in the recycler view */
inner class PdfAdapterViewHolder(itemView: View):RecyclerView.ViewHolder(itemView){

val fileName: TextView = itemView.findViewById(R.id.filename_TV)
val optionsBtn: ImageView = itemView.findViewById(R.id.options_btn)

}

/* Informs the activity when the item gets clicked */
interface PdfAdapterInterface{
fun onItemClicked(position: Int)
fun onItemLongClicked(position: Int)
}

/*onCreateViewHolder() is called when the Adapter is created and returns an instance of the
PdfAdapterViewHolder. In this function, we handle the onClick event by displaying a toast message*/
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PdfAdapterViewHolder {
val viewHolder = PdfAdapterViewHolder(
LayoutInflater.from(context).inflate(R.layout.adapter_pdf, parent, false))
Expand All @@ -44,22 +51,29 @@ class PdfAdapterRv(private val context: Context, private val activity: Activity,
return viewHolder
}

/*onBindViewHolder() is called for each ViewHolder and used to define the actions on it */
override fun onBindViewHolder(holder: PdfAdapterViewHolder, position: Int) {
holder.fileName.text = fileList[position].name

holder.itemView.setOnClickListener{
holder.itemView.setOnClickListener {
pdfInterface.onItemClicked(position)
}
holder.itemView.setOnLongClickListener{
holder.itemView.setOnLongClickListener {
pdfInterface.onItemLongClicked(position)
true
}
}

/* getItemCount() method returns the number of items in the list that we want to display */
override fun getItemCount(): Int {
return fileList.size
}

/* In the following method, we find the file searched for by the user.
We convert the text we receive into the lowercase characters of the language in the region
where the app is being used (using Locale.getDefault()).
Using notifyDataSetChanged(), we can notify the listener attached to our adapter about the
changes in the underlying data, so that any view reflecting this data can be refreshed accordingly */
fun filter(characterText: String) {
var characterText = characterText
characterText = characterText.toLowerCase(Locale.getDefault())
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/vob/scanit/model/Documents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.vob.scanit.model
import android.net.Uri
import java.util.*

/* We define a data class and specify the arguments to be passed into its constructor */
data class Documents(
val id: Long,
val displayName: String,
Expand Down
Loading