-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5693 from grzesiek2010/COLLECT-5605
Making the "Ready to Send" screen more actionable
- Loading branch information
Showing
22 changed files
with
524 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ct_app/src/main/java/org/odk/collect/android/instancemanagement/send/ReadyToSendBanner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.odk.collect.android.instancemanagement.send | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import org.odk.collect.android.databinding.ReadyToSendBannerBinding | ||
import org.odk.collect.shared.TimeInMs | ||
import org.odk.collect.strings.R | ||
|
||
class ReadyToSendBanner(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs) { | ||
constructor(context: Context) : this(context, null) | ||
|
||
private val binding = ReadyToSendBannerBinding.inflate(LayoutInflater.from(context), this, true) | ||
|
||
fun setData(data: ReadyToSendViewModel.Data) { | ||
if (data.numberOfSentInstances > 0 && data.numberOfInstancesReadyToSend > 0) { | ||
if (data.lastInstanceSentTimeMillis >= TimeInMs.ONE_DAY) { | ||
val days: Int = (data.lastInstanceSentTimeMillis / TimeInMs.ONE_DAY).toInt() | ||
binding.title.text = context.resources.getQuantityString(R.plurals.last_form_sent_days_ago, days, days) | ||
} else if (data.lastInstanceSentTimeMillis >= TimeInMs.ONE_HOUR) { | ||
val hours: Int = (data.lastInstanceSentTimeMillis / TimeInMs.ONE_HOUR).toInt() | ||
binding.title.text = context.resources.getQuantityString(R.plurals.last_form_sent_hours_ago, hours, hours) | ||
} else if (data.lastInstanceSentTimeMillis >= TimeInMs.ONE_MINUTE) { | ||
val minutes: Int = (data.lastInstanceSentTimeMillis / TimeInMs.ONE_MINUTE).toInt() | ||
binding.title.text = context.resources.getQuantityString(R.plurals.last_form_sent_minutes_ago, minutes, minutes) | ||
} else { | ||
val seconds: Int = (data.lastInstanceSentTimeMillis / TimeInMs.ONE_SECOND).toInt() | ||
binding.title.text = context.resources.getQuantityString(R.plurals.last_form_sent_seconds_ago, seconds, seconds) | ||
} | ||
|
||
binding.subtext.text = context.resources.getQuantityString(R.plurals.forms_ready_to_send, data.numberOfInstancesReadyToSend, data.numberOfInstancesReadyToSend) | ||
binding.banner.visibility = VISIBLE | ||
} else { | ||
binding.banner.visibility = GONE | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...app/src/main/java/org/odk/collect/android/instancemanagement/send/ReadyToSendViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.odk.collect.android.instancemanagement.send | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import org.odk.collect.async.Scheduler | ||
import org.odk.collect.forms.instances.Instance | ||
import org.odk.collect.forms.instances.InstancesRepository | ||
import java.util.function.Supplier | ||
|
||
class ReadyToSendViewModel( | ||
private val instancesRepository: InstancesRepository, | ||
private val scheduler: Scheduler, | ||
private val clock: Supplier<Long> | ||
) : ViewModel() { | ||
private val _data = MutableLiveData<Data>() | ||
val data: LiveData<Data> = _data | ||
|
||
fun update() { | ||
scheduler.immediate( | ||
background = { | ||
val sentInstances = instancesRepository.getAllByStatus(Instance.STATUS_SUBMITTED) | ||
val numberOfSentInstances = sentInstances.size | ||
val numberOfInstancesReadyToSend = instancesRepository.getCountByStatus( | ||
Instance.STATUS_COMPLETE, | ||
Instance.STATUS_SUBMISSION_FAILED | ||
) | ||
val lastInstanceSentTimeMillis = if (sentInstances.isNotEmpty()) { | ||
val lastSentInstance = sentInstances.maxBy { instance -> instance.lastStatusChangeDate } | ||
clock.get() - lastSentInstance.lastStatusChangeDate | ||
} else { | ||
0 | ||
} | ||
Data(numberOfInstancesReadyToSend, numberOfSentInstances, lastInstanceSentTimeMillis) | ||
}, | ||
foreground = { | ||
_data.value = it | ||
} | ||
) | ||
} | ||
|
||
open class Factory( | ||
private val instancesRepository: InstancesRepository, | ||
private val scheduler: Scheduler, | ||
private val clock: Supplier<Long> | ||
) : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return ReadyToSendViewModel(instancesRepository, scheduler, clock) as T | ||
} | ||
} | ||
|
||
data class Data( | ||
val numberOfInstancesReadyToSend: Int, | ||
val numberOfSentInstances: Int, | ||
val lastInstanceSentTimeMillis: Long | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/banner" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="?colorSurfaceContainerLow" | ||
android:paddingVertical="@dimen/margin_standard" | ||
android:visibility="gone" | ||
tools:visibility="visible"> | ||
|
||
<ImageView | ||
android:id="@+id/icon" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="@dimen/margin_large" | ||
app:srcCompat="@drawable/ic_send_24" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:tint="?colorPrimary"/> | ||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/title" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="@dimen/margin_large" | ||
android:layout_marginEnd="@dimen/margin_standard" | ||
android:textAppearance="?textAppearanceTitleMedium" | ||
android:textColor="?colorPrimary" | ||
app:layout_constraintStart_toEndOf="@id/icon" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="@id/icon" | ||
tools:text="Last sent: 2 days ago"/> | ||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/subtext" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:textAppearance="?textAppearanceBodyMedium" | ||
app:layout_constraintStart_toStartOf="@id/title" | ||
app:layout_constraintEnd_toEndOf="@id/title" | ||
app:layout_constraintTop_toBottomOf="@id/title" | ||
tools:text="4 forms ready to send"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Oops, something went wrong.