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

Commit

Permalink
feat(YouTube - SponsorBlock): Make new segment window draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
anddea committed Sep 17, 2024
1 parent 37eff81 commit 335d929
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import static app.revanced.integrations.shared.utils.ResourceUtils.getIdentifier;
import static app.revanced.integrations.shared.utils.ResourceUtils.getLayoutIdentifier;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import android.widget.ImageView;
import app.revanced.integrations.shared.utils.Logger;
import app.revanced.integrations.shared.utils.ResourceUtils;
import app.revanced.integrations.youtube.settings.Settings;
Expand All @@ -25,6 +28,10 @@ public final class NewSegmentLayout extends FrameLayout {
);
private final int rippleEffectId;

private float dX, dY;
private boolean isDragging = false;
private ImageView dragHandle;

public NewSegmentLayout(final Context context) {
this(context, null);
}
Expand Down Expand Up @@ -91,6 +98,37 @@ public NewSegmentLayout(final Context context, final AttributeSet attributeSet,
);
}

@Override
protected void onFinishInflate() {
super.onFinishInflate();
dragHandle = findViewById(getIdentifier("revanced_sb_new_segment_drag_handle", ResourceUtils.ResourceType.ID, getContext()));
setupDragHandle();
}

@SuppressLint("ClickableViewAccessibility")
private void setupDragHandle() {
dragHandle.setOnTouchListener((v, event) -> {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
dX = getX() - event.getRawX();
dY = getY() - event.getRawY();
isDragging = true;
break;
case MotionEvent.ACTION_MOVE:
if (isDragging) {
setY(event.getRawY() + dY);
setX(event.getRawX() + dX);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
isDragging = false;
break;
}
return true;
});
}

/**
* Initializes a segment button with the given resource identifier name with the given handler and a ripple effect.
*
Expand Down

0 comments on commit 335d929

Please sign in to comment.