Skip to content

Commit

Permalink
- version bump v1.4
Browse files Browse the repository at this point in the history
- use enqueueUniqueWork for Workers making DB transactions to prevent duplicate row entries
- display progress indicator when syncing libraries/projects
  • Loading branch information
lmj0011 committed Mar 15, 2021
1 parent 6720184 commit 0fdaa35
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
minSdkVersion(19)
targetSdkVersion(30)
versionCode(getCommitCount().toInt())
versionName = "1.3"
versionName = "1.4"

vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -137,7 +137,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.appcompat:appcompat:1.2.0")

implementation("com.google.android.material:material:1.2.1")
implementation("com.google.android.material:material:1.3.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.1")
implementation("androidx.vectordrawable:vectordrawable:1.1.0")
implementation("androidx.navigation:navigation-fragment:${findProperty("fragment.version")}")
Expand Down
2 changes: 1 addition & 1 deletion app/deps.list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.4.10
org.jetbrains.kotlin:kotlin-stdlib:1.4.10
androidx.core:core-ktx:1.3.2
androidx.appcompat:appcompat:1.2.0
com.google.android.material:material:1.2.1
com.google.android.material:material:1.3.0
androidx.constraintlayout:constraintlayout:2.0.1
androidx.vectordrawable:vectordrawable:1.1.0
androidx.navigation:navigation-fragment:2.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.fragment_libraries.*
import kotlinx.coroutines.*
import name.lmj0011.jetpackreleasetracker.MainActivity
import name.lmj0011.jetpackreleasetracker.R
Expand Down Expand Up @@ -59,6 +61,10 @@ class LibrariesFragment : Fragment(R.layout.fragment_libraries), SearchableRecyc
binding = FragmentLibrariesBinding.bind(view)
binding.lifecycleOwner = this
binding.homeViewModel = librariesViewModel
binding.fetchLibrariesButton.setOnClickListener {
enqueueNewLibraryRefreshWorkerRequest()
(requireActivity() as MainActivity).showToastMessage(requireContext().getString(R.string.toast_message_fetching_libraries))
}
}

private fun setupAdapter() {
Expand Down Expand Up @@ -137,7 +143,12 @@ class LibrariesFragment : Fragment(R.layout.fragment_libraries), SearchableRecyc

// if it's always empty, there's a problem with the network
if (it.isEmpty()) {
binding.swipeRefresh.visibility = View.GONE
binding.emptyListContainer.visibility = View.VISIBLE
enqueueNewLibraryRefreshWorkerRequest()
} else {
binding.swipeRefresh.visibility = View.VISIBLE
binding.emptyListContainer.visibility = View.GONE
}

listAdapter.submitLibArtifacts(it.toList())
Expand All @@ -164,20 +175,32 @@ class LibrariesFragment : Fragment(R.layout.fragment_libraries), SearchableRecyc
.addTag(requireContext().getString(R.string.update_one_time_worker_tag))
.build()

progress_indicator.visibility = View.VISIBLE

WorkManager.getInstance(requireContext())
.getWorkInfoByIdLiveData(libraryRefreshWorkerRequest.id)
.observe(viewLifecycleOwner, Observer { workInfo ->
if (workInfo != null) {
val progress = workInfo.progress
val value = progress.getInt(ProjectSyncAllWorker.Progress, 0)
progress_indicator.progress = value

/**
* start in indeterminate mode until ~20% complete,
* to give an immediate visual que of work being done
*/
if (value >= 20) progress_indicator.isIndeterminate = false

if (value >= 100) {
librariesViewModel.refreshLibraries()
progress_indicator.visibility = View.GONE
progress_indicator.isIndeterminate = true
}
}
})

WorkManager.getInstance(requireContext()).enqueue(libraryRefreshWorkerRequest)
WorkManager.getInstance(requireContext())
.enqueueUniqueWork(getString(R.string.unique_work_name_fetch_libraries), ExistingWorkPolicy.KEEP, libraryRefreshWorkerRequest)
}

private fun refreshListAdapter(query: String? = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import android.os.Bundle
import android.view.*
import androidx.appcompat.widget.SearchView
import androidx.core.os.bundleOf
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import kotlinx.android.synthetic.main.fragment_libraries.*
import kotlinx.coroutines.*
import name.lmj0011.jetpackreleasetracker.MainActivity
import name.lmj0011.jetpackreleasetracker.R
Expand Down Expand Up @@ -137,21 +137,32 @@ class ProjectSyncsFragment : Fragment(R.layout.fragment_project_syncs), Searchab
.addTag(requireContext().getString(R.string.project_sync_all_one_time_worker_tag))
.build()

progress_indicator.visibility = View.VISIBLE

WorkManager.getInstance(requireActivity().application)
.getWorkInfoByIdLiveData(projectSyncAllWorkRequest.id)
.observe(viewLifecycleOwner, Observer { workInfo ->
if (workInfo != null) {
val progress = workInfo.progress
val value = progress.getInt(Progress, 0)
progress_indicator.progress = value

/**
* start in indeterminate mode until ~20% complete,
* to give an immediate visual que of work being done
*/
if (value >= 20) progress_indicator.isIndeterminate = false

if (value >= 100) {
projectSyncsViewModel.refreshProjectSyncs()
progress_indicator.visibility = View.GONE
progress_indicator.isIndeterminate = true
}
}
})

WorkManager.getInstance(requireActivity().application)
.enqueue(projectSyncAllWorkRequest)
WorkManager.getInstance(requireContext())
.enqueueUniqueWork(getString(R.string.unique_work_name_sync_projects), ExistingWorkPolicy.KEEP, projectSyncAllWorkRequest)

binding.swipeRefresh.isRefreshing = false
(requireActivity() as MainActivity).showToastMessage(requireContext().getString(R.string.toast_message_syncing_projects))
Expand Down
48 changes: 48 additions & 0 deletions app/src/main/res/layout/fragment_libraries.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,54 @@
android:layout_height="match_parent"
tools:context=".ui.libraries.LibrariesFragment">

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress_indicator"
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="gone"
app:indicatorColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/emptyListContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/default_list_item_padding"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">

<TextView
android:id="@+id/emptyListTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/empty_libraries_text"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />

<Button
android:id="@+id/fetchLibrariesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty_libraries_fetch_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emptyListTextView" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.appcompat.widget.SearchView
android:id="@+id/librariesSearchView"
android:layout_width="match_parent"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/fragment_project_syncs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
android:layout_height="match_parent"
tools:context=".ui.projectsyncs.ProjectSyncsFragment">

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress_indicator"
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="gone"
app:indicatorColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/emptyListContainer"
android:layout_width="wrap_content"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<string name="list_header_artifact">Artifact</string>
<string name="list_header_latest_stable">Stable</string>
<string name="list_header_latest_release">Latest</string>
<string name="empty_libraries_text">AndroidX Libraries will show up here</string>
<string name="empty_libraries_fetch_btn">Fetch Libraries</string>
<string name="no_updates_text">New AndroidX releases will show up here</string>
<string name="empty_project_syncs_text">Monitor your project\'s Androidx dependencies</string>
<string name="empty_project_syncs_learn_more_btn">Learn More</string>
Expand All @@ -23,6 +25,7 @@
<string name="project_sync_no_dependencies">No androidx dependencies found</string>

<string name="toast_message_updating_libraries">Updating Libraries</string>
<string name="toast_message_fetching_libraries">Fetching Libraries</string>
<string name="toast_message_syncing_projects">Syncing Projects</string>

<string name="notification_text_fetching_artifacts">fetching Artifacts...</string>
Expand Down Expand Up @@ -56,4 +59,6 @@
</string>

<string name="key_project_sync_id_bundle_property">projectSyncId</string>
<string name="unique_work_name_fetch_libraries">FETCH_LIBRARIES</string>
<string name="unique_work_name_sync_projects">SYNC_PROJECTS</string>
</resources>

0 comments on commit 0fdaa35

Please sign in to comment.