-
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.
Extract common component for showing snackbars based on LiveData
- Loading branch information
Showing
3 changed files
with
84 additions
and
47 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
51 changes: 51 additions & 0 deletions
51
...rc/main/java/org/odk/collect/android/instancemanagement/FinalizeAllSnackbarPresenter.java
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,51 @@ | ||
package org.odk.collect.android.instancemanagement; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.odk.collect.android.formmanagement.FinalizeAllResult; | ||
import org.odk.collect.androidshared.ui.SnackbarUtils; | ||
|
||
public class FinalizeAllSnackbarPresenter extends SnackbarUtils.SnackbarPresenterObserver<FinalizeAllResult> { | ||
private final Context context; | ||
|
||
public FinalizeAllSnackbarPresenter(@NonNull View parentView, Context context) { | ||
super(parentView); | ||
this.context = context; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public SnackbarUtils.SnackbarDetails getSnackbarDetails(FinalizeAllResult result) { | ||
if (result.getUnsupportedInstances()) { | ||
return new SnackbarUtils.SnackbarDetails( | ||
context.getString( | ||
org.odk.collect.strings.R.string.bulk_finalize_unsupported, | ||
result.getSuccessCount() | ||
) | ||
); | ||
} else if (result.getFailureCount() == 0) { | ||
return new SnackbarUtils.SnackbarDetails( | ||
context.getResources().getQuantityString( | ||
org.odk.collect.strings.R.plurals.bulk_finalize_success, | ||
result.getSuccessCount(), | ||
result.getSuccessCount() | ||
) | ||
); | ||
} else if (result.getSuccessCount() == 0) { | ||
return new SnackbarUtils.SnackbarDetails( | ||
context.getResources().getQuantityString( | ||
org.odk.collect.strings.R.plurals.bulk_finalize_failure, | ||
result.getFailureCount(), | ||
result.getFailureCount() | ||
) | ||
); | ||
} else { | ||
return new SnackbarUtils.SnackbarDetails( | ||
context.getString(org.odk.collect.strings.R.string.bulk_finalize_partial_success, result.getSuccessCount(), result.getFailureCount()) | ||
); | ||
} | ||
} | ||
} |