Skip to content

Commit

Permalink
Cleanup with default interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantcheese committed Aug 12, 2023
1 parent 540d1df commit 3b38cf6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ public WebResourceResponse shouldInterceptRequestCompat(
) {
return loader.shouldInterceptRequest(Uri.parse(url));
}

@Override
public boolean shouldOverrideUrlCompat(@NonNull WebView view, @NonNull String url) {
return super.shouldOverrideUrlCompat(view, url);
}
});
captchaAutosolve.setWebChromeClient(new WebChromeClient() {
@Override
Expand Down Expand Up @@ -331,21 +326,10 @@ public void onSuccess(ParsedJsonStruct result) {

topText.setText("Move the slider until text is legible.\n Then enter the text below.");
slider.setVisibility(VISIBLE);
slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Matrix centerScaleTranslateMatrix = new Matrix(centerScaleMatrix);
centerScaleTranslateMatrix.postTranslate(-progress * scale, 0);
bg.setImageMatrix(centerScaleTranslateMatrix);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
slider.setOnSeekBarChangeListener((DefaultOnSeekBarChangeListener) (seekBar, progress, fromUser) -> {
Matrix centerScaleTranslateMatrix = new Matrix(centerScaleMatrix);
centerScaleTranslateMatrix.postTranslate(-progress * scale, 0);
bg.setImageMatrix(centerScaleTranslateMatrix);
});

bg.setImageBitmap(currentStruct.origBg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.github.adamantcheese.chan.core.model.orm.Loadable;
import com.github.adamantcheese.chan.core.presenter.ImageReencodingPresenter;
import com.github.adamantcheese.chan.core.settings.ChanSettings;
import com.github.adamantcheese.chan.utils.DefaultOnSeekBarChangeListener;

public class ImageOptionsController
extends BaseFloatingController
Expand Down Expand Up @@ -71,7 +72,7 @@ public class ImageOptionsController
private final Pair<Integer, Integer> dims;
private final CompressFormat imageFormat;

private final SeekBar.OnSeekBarChangeListener listener = new SeekBar.OnSeekBarChangeListener() {
private final SeekBar.OnSeekBarChangeListener listener = new DefaultOnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (seekBar == quality) {
Expand All @@ -91,12 +92,6 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
));
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
};

public ImageOptionsController(Context context, Loadable loadable, ImageOptionsControllerCallback callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.github.adamantcheese.chan.ui.text.spans.BackgroundColorSpanHashed;
import com.github.adamantcheese.chan.ui.view.*;
import com.github.adamantcheese.chan.ui.widget.ColorPickerView;
import com.github.adamantcheese.chan.utils.DefaultOnSeekBarChangeListener;

import java.util.*;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -315,24 +316,15 @@ private void onColorClicked(View v) {
ColorPickerView colorView = colorPickerView.findViewById(R.id.color_picker);
SeekBar alphaBar = colorPickerView.findViewById(R.id.alpha_picker);
TextView percent = colorPickerView.findViewById(R.id.progress);
alphaBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
colorView.setColor(Color.argb(progress,
Color.red(colorView.getColor()),
Color.green(colorView.getColor()),
Color.blue(colorView.getColor())
));
percent.setText(getQuantityString(R.plurals.percent,
(int) (progress * 100 / (float) seekBar.getMax())
));
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
alphaBar.setOnSeekBarChangeListener((DefaultOnSeekBarChangeListener) (seekBar, progress, fromUser) -> {
colorView.setColor(Color.argb(progress,
Color.red(colorView.getColor()),
Color.green(colorView.getColor()),
Color.blue(colorView.getColor())
));
percent.setText(getQuantityString(R.plurals.percent,
(int) (progress * 100 / (float) seekBar.getMax())
));
});
colorView.setColor(filter.color);
alphaBar.setProgress(Color.alpha(filter.color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.github.adamantcheese.chan.core.settings.primitives.Setting;
import com.github.adamantcheese.chan.ui.controller.settings.SettingsController;
import com.github.adamantcheese.chan.ui.settings.limitcallbacks.LimitCallback;
import com.github.adamantcheese.chan.utils.DefaultOnSeekBarChangeListener;

public class SeekbarSettingView
extends SettingView {
Expand Down Expand Up @@ -90,18 +91,8 @@ public void createEditView(View v) {

max.setText(String.valueOf(setting.get()));

rangeSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
max.setText(String.valueOf(convertProgressToRange(progress, seekBar.getMax())));
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
rangeSlider.setOnSeekBarChangeListener((DefaultOnSeekBarChangeListener) (seekBar, progress, fromUser) -> max.setText(
String.valueOf(convertProgressToRange(progress, seekBar.getMax()))));

DialogInterface.OnClickListener clickListener = (d, which) -> {
setting.set(convertProgressToRange(rangeSlider.getProgress(), rangeSlider.getMax()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.adamantcheese.chan.utils;

import android.widget.SeekBar;

public interface DefaultOnSeekBarChangeListener
extends SeekBar.OnSeekBarChangeListener {
@Override
default void onStartTrackingTouch(SeekBar seekBar) {}

@Override
default void onStopTrackingTouch(SeekBar seekBar) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
android:layout_height="match_parent"
android:scaleType="matrix"
tools:src="@drawable/bg"
tools:translationX="-35dp" />
tools:translationX="25dp" />

<ImageView
android:id="@+id/fg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="matrix"
tools:src="@drawable/fg" />
tools:src="@drawable/fg"
tools:translationX="60dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

<SeekBar
Expand Down

0 comments on commit 3b38cf6

Please sign in to comment.