Skip to content

Commit

Permalink
Added FAB to update reports (#292)
Browse files Browse the repository at this point in the history
* Add floating action button that hides on scrolling down to update reports

* Add floating action button that shrinks on scrolling down to update reports

* Remove FAB text, add content description and expected scroll behaviour
  • Loading branch information
sivasubramaniamv authored May 25, 2023
1 parent 17161b5 commit 0acb338
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.eu.exodus_privacy.exodusprivacy.fragments.apps

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.PopupMenu
import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.transition.MaterialFadeThrough
import dagger.hilt.android.AndroidEntryPoint
import org.eu.exodus_privacy.exodusprivacy.ExodusUpdateService
Expand Down Expand Up @@ -38,6 +41,8 @@ class AppsFragment : Fragment(R.layout.fragment_apps) {
reenterTransition = MaterialFadeThrough()
returnTransition = MaterialFadeThrough()

val updateReportsFab = binding.updateReportsFAB

// Setup menu actions
val toolbar = binding.toolbarApps
toolbar.menu.clear()
Expand All @@ -63,6 +68,18 @@ class AppsFragment : Fragment(R.layout.fragment_apps) {
binding.appListRV.apply {
adapter = appsRVAdapter
layoutManager = LinearLayoutManager(view.context)
addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (dy > 0 && updateReportsFab.isVisible) {
updateReportsFab.hide()
} else if (dy < 0 && !updateReportsFab.isVisible) {
updateReportsFab.show()
}
}
}
)
}

// Setup Shimmer Layout
Expand All @@ -85,13 +102,11 @@ class AppsFragment : Fragment(R.layout.fragment_apps) {

binding.swipeRefreshLayout.setOnRefreshListener {
binding.swipeRefreshLayout.isRefreshing = false
if (!ExodusUpdateService.IS_SERVICE_RUNNING) {
val intent = Intent(view.context, ExodusUpdateService::class.java)
intent.apply {
action = ExodusUpdateService.START_SERVICE
activity?.startService(this)
}
}
updateReports(view.context)
}

updateReportsFab.setOnClickListener {
updateReports(view.context)
}
}

Expand All @@ -110,4 +125,14 @@ class AppsFragment : Fragment(R.layout.fragment_apps) {
binding.toolbarApps.setOnMenuItemClickListener(null)
_binding = null
}

private fun updateReports(context: Context) {
if (!ExodusUpdateService.IS_SERVICE_RUNNING) {
val intent = Intent(context, ExodusUpdateService::class.java)
intent.apply {
action = ExodusUpdateService.START_SERVICE
activity?.startService(this)
}
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_apps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,15 @@
android:scrollbars="vertical" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/updateReportsFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:contentDescription="@string/refresh"
android:src="@drawable/ic_update"
app:backgroundTint="@color/chipColor" />

</RelativeLayout>

0 comments on commit 0acb338

Please sign in to comment.