Skip to content

Commit

Permalink
feat: add loading indicator fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
butzist committed Apr 13, 2024
1 parent cbc1449 commit 6981b49
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import de.szalkowski.activitylauncher.ui.DisclaimerDialogFragment
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity() : AppCompatActivity(), ActionBarSearch {
class MainActivity : AppCompatActivity(), ActionBarSearch {

private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
Expand All @@ -43,12 +43,13 @@ class MainActivity() : AppCompatActivity(), ActionBarSearch {
setupActionBarWithNavController(navController, appBarConfiguration)
}


override var onActionBarSearchListener: ((String) -> Unit)? = null
private var actionBarSearchView: SearchView? = null
override var actionBarSearchText: String
get() = actionBarSearchView?.query?.toString().orEmpty()
set(value) { actionBarSearchView?.setQuery(value, false) }
set(value) {
actionBarSearchView?.setQuery(value, false)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.szalkowski.activitylauncher.ui

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import de.szalkowski.activitylauncher.R
import de.szalkowski.activitylauncher.services.PackageListService
import javax.inject.Inject
import javax.inject.Provider
import kotlin.concurrent.thread

@AndroidEntryPoint
class LoadingFragment : Fragment() {
@Inject
internal lateinit var packageListService: Provider<PackageListService>

@SuppressLint("RestrictedApi")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
val context = this.requireActivity()

thread {
// preload package list
packageListService.get()

context.runOnUiThread {
val action = LoadingFragmentDirections.actionLoadingFinished()
findNavController().navigate(action)
}
}

// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_loading, container, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController
import dagger.hilt.android.AndroidEntryPoint
import de.szalkowski.activitylauncher.R
import de.szalkowski.activitylauncher.databinding.FragmentPackageListBinding
import javax.inject.Inject

Expand All @@ -21,6 +25,20 @@ class PackageListFragment : Fragment() {
// onDestroyView.
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// disable back button
val appBarConfiguration = AppBarConfiguration.Builder(
R.id.PackageListFragment
).build()
setupActionBarWithNavController(
this.requireActivity() as AppCompatActivity,
findNavController(),
appBarConfiguration
)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/fragment_loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.LoadingFragment" >

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="@string/dialog_progress_loading"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/progressBar"
app:layout_constraintEnd_toEndOf="@+id/progressBar"
app:layout_constraintStart_toStartOf="@+id/progressBar" />

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
24 changes: 19 additions & 5 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/PackageListFragment">
app:startDestination="@id/LoadingFragment">

<fragment
android:id="@+id/LoadingFragment"
android:name="de.szalkowski.activitylauncher.ui.LoadingFragment"
android:label="@string/app_name"
tools:layout="@layout/fragment_loading">

<action
android:id="@+id/actionLoadingFinished"
app:destination="@id/PackageListFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpTo="@id/LoadingFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/PackageListFragment"
android:name="de.szalkowski.activitylauncher.ui.PackageListFragment"
Expand All @@ -17,8 +33,7 @@
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
/>
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/ActivityListFragment"
Expand All @@ -36,8 +51,7 @@
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
/>
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/ActivityDetailsFragment"
Expand Down

0 comments on commit 6981b49

Please sign in to comment.