Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Include stop button on experiment feed during recording
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 280708631
  • Loading branch information
Ashley Marie authored and lizlooney committed Nov 15, 2019
1 parent f51f517 commit f00c420
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,40 @@ public void attachRecordButton(ImageButton recordButton, FragmentManager fragmen
});
}

public void attachStopButton(CardView recordButton, FragmentManager fragmentManager) {
Observable<RecordingStatus> recordingStatus =
AppSingleton.getInstance(recordButton.getContext())
.getRecorderController(appAccount)
.watchRecordingStatus();

Resources resources = recordButton.getResources();
((TextView) recordButton.findViewById(R.id.record_button_text))
.setText(R.string.btn_stop_label);
recordButton.setContentDescription(resources.getString(R.string.btn_stop_description));
((ImageView) recordButton.findViewById(R.id.record_button_icon))
.setImageDrawable(resources.getDrawable(R.drawable.ic_recording_stop_42dp));

RxView.clicks(recordButton)
.flatMapMaybe(click -> recordingStatus.firstElement())
.subscribe(
status -> {
if (status.isRecording()) {
tryStopRecording(recordButton, fragmentManager);
}
});

recordingStatus
.takeUntil(RxView.detaches(recordButton))
.subscribe(
status -> {
if (status.state.shouldShowStopButton()) {
recordButton.setVisibility(View.VISIBLE);
} else {
recordButton.setVisibility(View.INVISIBLE);
}
});
}

/**
* Updates the recording button, action area, title bar, and sensor card view for {@link
* SensorFragment} when a recording starts/stops.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.google.android.apps.forscience.whistlepunk.AppSingleton;
import com.google.android.apps.forscience.whistlepunk.Appearances;
import com.google.android.apps.forscience.whistlepunk.ColorUtils;
import com.google.android.apps.forscience.whistlepunk.ControlBarController;
import com.google.android.apps.forscience.whistlepunk.DataController;
import com.google.android.apps.forscience.whistlepunk.DeletedLabel;
import com.google.android.apps.forscience.whistlepunk.DevOptionsFragment;
Expand All @@ -73,6 +74,7 @@
import com.google.android.apps.forscience.whistlepunk.RxDataController;
import com.google.android.apps.forscience.whistlepunk.RxEvent;
import com.google.android.apps.forscience.whistlepunk.SensorAppearance;
import com.google.android.apps.forscience.whistlepunk.SnackbarManager;
import com.google.android.apps.forscience.whistlepunk.StatsAccumulator;
import com.google.android.apps.forscience.whistlepunk.StatsList;
import com.google.android.apps.forscience.whistlepunk.WhistlePunkApplication;
Expand Down Expand Up @@ -172,6 +174,7 @@ public interface ListenerProvider {
private RxEvent destroyed = new RxEvent();
private LocalSyncManager localSyncManager;
private ExperimentLibraryManager experimentLibraryManager;
private ControlBarController controlBarController;

/**
* Creates a new instance of this fragment.
Expand Down Expand Up @@ -223,6 +226,8 @@ public void onCreate(Bundle savedInstanceState) {
experimentId = getArguments().getString(ARG_EXPERIMENT_ID);
claimExperimentsMode = getArguments().getBoolean(ARG_CLAIM_EXPERIMENTS_MODE);
setHasOptionsMenu(true);
controlBarController =
new ControlBarController(appAccount, getExperimentId(), new SnackbarManager());
if (claimExperimentsMode) {
WhistlePunkApplication.getUsageTracker(getActivity())
.trackEvent(
Expand Down Expand Up @@ -394,10 +399,14 @@ public View onCreateView(
graphOptionsController.loadIntoScalarDisplayOptions(scalarDisplayOptions, view);

ActionAreaView actionArea = view.findViewById(R.id.action_area);
CardView recordButton = view.findViewById(R.id.record);

ExperimentActivity experimentActivity = (ExperimentActivity) getActivity();
if (experimentActivity.isTwoPane()) {
recordButton.setVisibility(View.GONE);
actionArea.setVisibility(View.GONE);
} else {
controlBarController.attachStopButton(recordButton, getChildFragmentManager());
actionArea.addItems(
getContext(), experimentActivity.getActionAreaItems(), experimentActivity);
actionArea.setUpScrollListener(details);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include layout="@layout/experiment_details" />

<include layout="@layout/record_button" />

<com.google.android.apps.forscience.whistlepunk.actionarea.ActionAreaView
android:id="@+id/action_area"
style="@style/DefaultActionArea" />
style="@style/DefaultActionArea"
android:layout_alignParentBottom="true" />

</FrameLayout>
</RelativeLayout>

0 comments on commit f00c420

Please sign in to comment.