mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Now showing progress bar while calculating passes
This commit is contained in:
1 parent
8b1901fd48
commit
e9424ad997
4 files changed
+23
-30
No files matched your search
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.rtbishop.look4sat.ui.fragments
|
package com.rtbishop.look4sat.ui.fragments
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@@ -35,7 +34,6 @@ import com.rtbishop.look4sat.ui.adapters.PassesAdapter
|
|||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.utility.PrefsManager
|
||||||
import com.rtbishop.look4sat.utility.RecyclerDivider
|
import com.rtbishop.look4sat.utility.RecyclerDivider
|
||||||
import com.rtbishop.look4sat.utility.Utilities
|
import com.rtbishop.look4sat.utility.Utilities
|
||||||
import com.rtbishop.look4sat.utility.Utilities.getRotationAnimator
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -47,7 +45,6 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
|||||||
lateinit var prefsManager: PrefsManager
|
lateinit var prefsManager: PrefsManager
|
||||||
|
|
||||||
private lateinit var binding: FragmentPassesBinding
|
private lateinit var binding: FragmentPassesBinding
|
||||||
private lateinit var animator: ObjectAnimator
|
|
||||||
private lateinit var passesAdapter: PassesAdapter
|
private lateinit var passesAdapter: PassesAdapter
|
||||||
private val viewModel: SharedViewModel by activityViewModels()
|
private val viewModel: SharedViewModel by activityViewModels()
|
||||||
private var passes = mutableListOf<SatPass>()
|
private var passes = mutableListOf<SatPass>()
|
||||||
@@ -62,10 +59,14 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
|||||||
private fun setupObservers() {
|
private fun setupObservers() {
|
||||||
viewModel.getPasses().observe(viewLifecycleOwner, { result ->
|
viewModel.getPasses().observe(viewLifecycleOwner, { result ->
|
||||||
if (result is Result.Success) {
|
if (result is Result.Success) {
|
||||||
animator.cancel()
|
binding.passesProgress.visibility = View.INVISIBLE
|
||||||
|
binding.passesRecycler.visibility = View.VISIBLE
|
||||||
passes = result.data
|
passes = result.data
|
||||||
passesAdapter.setList(passes)
|
passesAdapter.setList(passes)
|
||||||
} else if (result is Result.InProgress) animator.start()
|
} else if (result is Result.InProgress) {
|
||||||
|
binding.passesRecycler.visibility = View.INVISIBLE
|
||||||
|
binding.passesProgress.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
})
|
})
|
||||||
viewModel.getCurrentTimeMillis().observe(viewLifecycleOwner, { currentTime ->
|
viewModel.getCurrentTimeMillis().observe(viewLifecycleOwner, { currentTime ->
|
||||||
tickMainTimer(currentTime)
|
tickMainTimer(currentTime)
|
||||||
@@ -84,14 +85,7 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
|||||||
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
||||||
addItemDecoration(RecyclerDivider(R.drawable.rec_divider_dark))
|
addItemDecoration(RecyclerDivider(R.drawable.rec_divider_dark))
|
||||||
}
|
}
|
||||||
animator = passesFab.getRotationAnimator()
|
passesFab.setOnClickListener { viewModel.calculatePasses() }
|
||||||
passesFab.setOnClickListener {
|
|
||||||
if (animator.isRunning) {
|
|
||||||
animator.cancel()
|
|
||||||
} else {
|
|
||||||
viewModel.calculatePasses()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
viewModel.triggerCalculation()
|
viewModel.triggerCalculation()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package com.rtbishop.look4sat.utility
|
package com.rtbishop.look4sat.utility
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.animation.LinearInterpolator
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
@@ -28,15 +26,6 @@ object Utilities {
|
|||||||
return round(this * multiplier) / multiplier
|
return round(this * multiplier) / multiplier
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.getRotationAnimator(): ObjectAnimator {
|
|
||||||
return ObjectAnimator.ofFloat(this, "rotation", 0f, 360f).apply {
|
|
||||||
duration = 333
|
|
||||||
repeatCount = ObjectAnimator.INFINITE
|
|
||||||
repeatMode = ObjectAnimator.RESTART
|
|
||||||
interpolator = LinearInterpolator()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun SharedPreferences.Editor.putDouble(key: String, double: Double) {
|
fun SharedPreferences.Editor.putDouble(key: String, double: Double) {
|
||||||
putLong(key, double.toRawBits())
|
putLong(key, double.toRawBits())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:keepScreenOn="true">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -49,7 +48,7 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/stub_left"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="4dp"
|
android:elevation="4dp"
|
||||||
@@ -63,7 +62,7 @@
|
|||||||
app:layout_constraintTop_toTopOf="@+id/passes_timer" />
|
app:layout_constraintTop_toTopOf="@+id/passes_timer" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/textView2"
|
android:id="@+id/stub_right"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="4dp"
|
android:elevation="4dp"
|
||||||
@@ -88,6 +87,17 @@
|
|||||||
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/passes_progress"
|
||||||
|
style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Large"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/passes_recycler"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/passes_bar" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/stub_left"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="4dp"
|
android:elevation="4dp"
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
app:layout_constraintTop_toTopOf="@+id/polar_timer" />
|
app:layout_constraintTop_toTopOf="@+id/polar_timer" />
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/textView2"
|
android:id="@+id/stub_right"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="4dp"
|
android:elevation="4dp"
|
||||||
|
|||||||
Reference in new issue
Block a user