Skip to content

Commit

Permalink
chore: added fab layout in home to pick documents (api >= 29)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmjr committed Jun 22, 2024
1 parent 8048359 commit 647b6e9
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

8 changes: 8 additions & 0 deletions .idea/misc.xml

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

41 changes: 40 additions & 1 deletion app/src/main/java/com/mjrt/app/allebooks/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mjrt.app.allebooks.ui.home

import android.annotation.SuppressLint
import android.os.Build
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.mjrt.app.allebooks.MainActivity
import com.mjrt.app.allebooks.R
Expand All @@ -20,7 +23,10 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
}

override fun initializeAttributes() {
loadDocuments()
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P)
loadDocuments()
else
setupPickDocumentFAB()
}

private fun loadDocuments() {
Expand All @@ -45,6 +51,39 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
}
}

private fun setupPickDocumentFAB() {
showFab()
setFabOpenClickListener()
setFabOpenDocClickListener()
}

private fun showFab() {
binding.fabsParentLayout.visibility = View.VISIBLE
}

private fun setFabOpenClickListener() {
binding.fabOpen.setOnClickListener {
revertFabVisibility()
}
}

private fun setFabOpenDocClickListener() {
binding.fabOpenDoc.setOnClickListener {
revertFabVisibility()
Toast.makeText(requireContext(), "Pick document", Toast.LENGTH_SHORT).show()
}
}

private fun revertFabVisibility() {
if (binding.fabOpenDoc.isVisible) {
binding.fabOpenDoc.visibility = View.INVISIBLE
binding.openDocFabLabel.visibility = View.INVISIBLE
} else {
binding.fabOpenDoc.visibility = View.VISIBLE
binding.openDocFabLabel.visibility = View.VISIBLE
}
}

companion object {
var documents: ArrayList<PdfDocument>? = null
@SuppressLint("StaticFieldLeak")
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,57 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/fabs_parent_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias=".95"
app:layout_constraintHorizontal_bias="1">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_open_doc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/open_new_document_button"
android:visibility="invisible"
app:fabSize="auto"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/fab_open"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias=".8"
android:layout_margin="8dp" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/open_doc_fab_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open_a_document"
android:textSize="18sp"
android:visibility="invisible"
app:layout_constraintTop_toTopOf="@id/fab_open_doc"
app:layout_constraintBottom_toBottomOf="@id/fab_open_doc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/fab_open_doc"
android:layout_margin="8dp"/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/open_new_button"
app:fabSize="auto"
app:layout_constraintTop_toBottomOf="@+id/fab_open_doc"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/fab_open_doc"
app:layout_constraintEnd_toEndOf="@id/fab_open_doc"
android:layout_margin="8dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<string name="menu_home">Home</string>
<string name="menu_reading">Reading</string>
<string name="menu_read">Read</string>
<string name="open_new_document_button">Open new document button</string>
<string name="open_new_button">Open new button</string>
<string name="open_a_document">Open a document</string>
</resources>
1 change: 1 addition & 0 deletions reader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions reader/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsKotlinAndroid)
}

android {
namespace 'com.mjrt.app.allebook.reader'
compileSdk 34

defaultConfig {
minSdk 21

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation libs.androidx.core.ktx
implementation libs.androidx.appcompat
implementation libs.material
testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
}
Empty file added reader/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions reader/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
4 changes: 4 additions & 0 deletions reader/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ include ':thumbnail_manager'
include ':utils'
include ':ui'
include ':core'
include ':reader'

0 comments on commit 647b6e9

Please sign in to comment.