Skip to content

Commit

Permalink
minor UI feedback on transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytamsf committed May 14, 2024
1 parent d8feec8 commit c8be6fb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onBindViewHolder(@NonNull TranscriptViewholder holder, int position)
}

TranscriptSegment seg = media.getTranscript().getSegmentAt(position);
holder.itemView.setOnClickListener(v -> {
holder.viewContent.setOnClickListener(v -> {
if (segmentClickListener != null) {
segmentClickListener.onTranscriptClicked(position, seg);
}
Expand Down Expand Up @@ -88,10 +88,19 @@ public void onBindViewHolder(@NonNull TranscriptViewholder holder, int position)
holder.viewContent.setBackgroundColor(SurfaceColors.getColorForElevation(context, 32 * density));
holder.viewContent.setAlpha(1.0f);
holder.viewTimecode.setAlpha(1.0f);
holder.viewContent.setAlpha(1.0f);
holder.spaceLeft.setBackgroundColor(SurfaceColors.getColorForElevation(context, 32 * density));
holder.spaceLeft.setAlpha(1.0f);
holder.spaceRight.setBackgroundColor(SurfaceColors.getColorForElevation(context, 32 * density));
holder.spaceRight.setAlpha(1.0f);
} else {
holder.viewContent.setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
holder.viewContent.setAlpha(0.5f);
holder.viewTimecode.setAlpha(0.5f);
holder.spaceLeft.setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
holder.spaceRight.setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
holder.spaceLeft.setAlpha(0.5f);
holder.spaceRight.setAlpha(0.5f);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.databinding.TranscriptDialogBinding;
Expand Down Expand Up @@ -75,16 +77,16 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
.create();
// Replace the neutral button with a checkbox for following audio
dialog.setOnShowListener(dialogInterface -> {
Button buttonNeutral = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
Button buttonNeutral = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
ViewGroup viewGroup = (ViewGroup) buttonNeutral.getParent();
Space space = new Space(getContext());
viewGroup.removeAllViews();
viewGroup.addView(followAudioCheckbox);
viewGroup.addView(space);
space.setLayoutParams(new LinearLayout.LayoutParams(100, LinearLayout.LayoutParams.MATCH_PARENT));

Button buttonPositive = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
Button buttonNegative = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
Button buttonPositive = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button buttonNegative = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
viewGroup.addView(buttonNegative);
viewGroup.addView(buttonPositive);
});
Expand All @@ -109,6 +111,16 @@ public View onCreateView(LayoutInflater inflater) {
transcriptClicked(pos, segment);
});
viewBinding.transcriptList.setAdapter(adapter);
viewBinding.transcriptList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
followAudioCheckbox.setChecked(false);
}
}
});


return viewBinding.getRoot();
}
Expand All @@ -121,11 +133,8 @@ private void transcriptClicked(int pos, TranscriptSegment segment) {
if (! (controller.getPosition() >= startTime
&& controller.getPosition() <= endTime)) {
controller.seekTo((int) startTime);

if (controller.getStatus() == PlayerStatus.PAUSED
|| controller.getStatus() == PlayerStatus.STOPPED) {
controller.playPause();
}
// TODO TT
Toast.makeText(getContext(), "Seeking to " + startTime, Toast.LENGTH_SHORT).show();
} else {
controller.playPause();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.danoeh.antennapod.ui.transcript;

import android.widget.Space;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -9,11 +10,15 @@
public class TranscriptViewholder extends RecyclerView.ViewHolder {
public final TextView viewTimecode;
public final TextView viewContent;
public final TextView spaceLeft;
public final TextView spaceRight;

public TranscriptViewholder(TranscriptItemBinding binding) {
super(binding.getRoot());
viewTimecode = binding.speaker;
viewContent = binding.content;
spaceLeft = binding.spacerLeft;
spaceRight = binding.spacerRight;
}

@Override
Expand Down
34 changes: 25 additions & 9 deletions app/src/main/res/layout/transcript_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,35 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clickable="false"
android:defaultFocusHighlightEnabled="false"
android:longClickable="false"
android:textStyle="bold"
android:textColor="?android:attr/textColorPrimary" />

<TextView
android:id="@+id/content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="1"
android:maxLines="100"
android:nestedScrollingEnabled="false"
android:selectAllOnFocus="false"
android:singleLine="false"
android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="false" />
android:orientation="horizontal">
<TextView
android:id="@+id/spacerLeft"
android:layout_width="8dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="1"
android:maxLines="100"
android:nestedScrollingEnabled="false"
android:selectAllOnFocus="false"
android:singleLine="false"
android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="false" />
<TextView
android:id="@+id/spacerRight"
android:layout_width="8dp"
android:layout_height="match_parent" />
</LinearLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import de.danoeh.antennapod.model.feed.Transcript;

public class TranscriptParser {
static final long MIN_SPAN = 50000L; // merge short segments together to form a span of 5 seconds
static final long MAX_SPAN = 80000L; // Do go beyond 8 seconds when merging
static final long MIN_SPAN = 50000L; // Merge short segments together to form a span of 50 seconds
static final long MAX_SPAN = 80000L; // Don't go beyond 80 seconds when merging

public static Transcript parse(String str, String type) {
if (str == null || StringUtils.isBlank(str)) {
Expand All @@ -23,12 +23,4 @@ public static Transcript parse(String str, String type) {
}
return null;
}

public static String secondsToTime(long msecs) {
int duration = Math.toIntExact(msecs / 1000L);
return String.format(Locale.getDefault(), "%d:%02d:%02d",
duration / 3600,
(duration % 3600) / 60,
(duration % 60));
}
}

0 comments on commit c8be6fb

Please sign in to comment.