Skip to content

Commit

Permalink
Reformat code / automated code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Nov 12, 2024
1 parent e3d84b9 commit 65f47dc
Show file tree
Hide file tree
Showing 57 changed files with 6,093 additions and 5,544 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public class CustomSmoothScroller extends RecyclerView.SmoothScroller {
// view is not laid out until interim target position is reached, we can detect the case before
// scrolling slows down and reschedule another interim target scroll
private static final float TARGET_SEEK_EXTRA_SCROLL_RATIO = 1.2f;
private final DisplayMetrics mDisplayMetrics;
protected final LinearInterpolator mLinearInterpolator = new LinearInterpolator();
protected final TimeInterpolator mDecelerateInterpolator =
new PathInterpolator(0.4f, 0.2f, 0f, 1f);
new PathInterpolator(0.4f, 0.2f, 0f, 1f);
private final DisplayMetrics mDisplayMetrics;
@SuppressLint("UnknownNullness") // b/240775049: Cannot annotate properly
protected PointF mTargetVector;
// Temporary variables to keep track of the interim scroll target. These values do not
Expand All @@ -102,6 +102,7 @@ protected void onStart() {

/**
* {@inheritDoc}
*
* @noinspection NullableProblems
*/
@Override
Expand All @@ -125,6 +126,7 @@ protected void afterTargetFound() {

/**
* {@inheritDoc}
*
* @noinspection NullableProblems
*/
@Override
Expand All @@ -138,7 +140,7 @@ protected void onSeekTargetStep(int dx, int dy, RecyclerView.State state, Action
return;
}
if (DEBUG && mTargetVector != null
&& (mTargetVector.x * dx < 0 || mTargetVector.y * dy < 0)) {
&& (mTargetVector.x * dx < 0 || mTargetVector.y * dy < 0)) {
throw new IllegalStateException("Scroll happened in the opposite direction"
+ " of the target. Some calculations are wrong");
}
Expand Down Expand Up @@ -225,7 +227,7 @@ protected int calculateTimeForScrolling(int dx) {
*/
protected int getHorizontalSnapPreference() {
return mTargetVector == null || mTargetVector.x == 0 ? SNAP_TO_ANY :
mTargetVector.x > 0 ? SNAP_TO_END : SNAP_TO_START;
mTargetVector.x > 0 ? SNAP_TO_END : SNAP_TO_START;
}

/**
Expand All @@ -239,7 +241,7 @@ protected int getHorizontalSnapPreference() {
*/
protected int getVerticalSnapPreference() {
return mTargetVector == null || mTargetVector.y == 0 ? SNAP_TO_ANY :
mTargetVector.y > 0 ? SNAP_TO_END : SNAP_TO_START;
mTargetVector.y > 0 ? SNAP_TO_END : SNAP_TO_START;
}

/**
Expand Down Expand Up @@ -268,8 +270,8 @@ protected void updateActionForInterimTarget(Action action) {
// interim target. Since we track the distance travelled in onSeekTargetStep callback, it
// won't actually scroll more than what we need.
action.update((int) (mInterimTargetDx * TARGET_SEEK_EXTRA_SCROLL_RATIO),
(int) (mInterimTargetDy * TARGET_SEEK_EXTRA_SCROLL_RATIO),
(int) (time * TARGET_SEEK_EXTRA_SCROLL_RATIO), mLinearInterpolator);
(int) (mInterimTargetDy * TARGET_SEEK_EXTRA_SCROLL_RATIO),
(int) (time * TARGET_SEEK_EXTRA_SCROLL_RATIO), mLinearInterpolator);
}

private int clampApplyScroll(int tmpDt, int dt) {
Expand All @@ -289,22 +291,22 @@ public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd
snapPreference) {
switch (snapPreference) {
case SNAP_TO_START:
return boxStart - viewStart;
return boxStart - viewStart;
case SNAP_TO_END:
return boxEnd - viewEnd;
return boxEnd - viewEnd;
case SNAP_TO_ANY:
final int dtStart = boxStart - viewStart;
if (dtStart > 0) {
return dtStart;
}
final int dtEnd = boxEnd - viewEnd;
if (dtEnd < 0) {
return dtEnd;
}
break;
final int dtStart = boxStart - viewStart;
if (dtStart > 0) {
return dtStart;
}
final int dtEnd = boxEnd - viewEnd;
if (dtEnd < 0) {
return dtEnd;
}
break;
default:
throw new IllegalArgumentException("snap preference should be one of the"
+ " constants defined in SmoothScroller, starting with SNAP_");
throw new IllegalArgumentException("snap preference should be one of the"
+ " constants defined in SmoothScroller, starting with SNAP_");
}
return 0;
}
Expand All @@ -327,7 +329,7 @@ public int calculateDyToMakeVisible(View view, int snapPreference) {
return 0;
}
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
view.getLayoutParams();
view.getLayoutParams();
final int top = layoutManager.getDecoratedTop(view) - params.topMargin;
final int bottom = layoutManager.getDecoratedBottom(view) + params.bottomMargin;
final int start = layoutManager.getPaddingTop();
Expand All @@ -353,7 +355,7 @@ public int calculateDxToMakeVisible(View view, int snapPreference) {
return 0;
}
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
view.getLayoutParams();
view.getLayoutParams();
final int left = layoutManager.getDecoratedLeft(view) - params.leftMargin;
final int right = layoutManager.getDecoratedRight(view) + params.rightMargin;
final int start = layoutManager.getPaddingLeft();
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/kotlin/androidx/media3/session/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import android.os.Looper
// see MeiZuLyricsMediaNotificationProvider

var isManualNotificationUpdate = false
private set
private set

// onUpdateNotificationInternal is package-private
fun MediaSessionService.doUpdateNotification(session: MediaSession) {
if (Looper.myLooper() != session.player.applicationLooper)
throw UnsupportedOperationException("wrong looper for doUpdateNotification")
isManualNotificationUpdate = true
onUpdateNotificationInternal(session, false)
isManualNotificationUpdate = false
if (Looper.myLooper() != session.player.applicationLooper)
throw UnsupportedOperationException("wrong looper for doUpdateNotification")
isManualNotificationUpdate = true
onUpdateNotificationInternal(session, false)
isManualNotificationUpdate = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import coil3.fetch.ImageFetchResult
import coil3.request.NullRequestDataException
import coil3.size.pxOrElse
import coil3.util.Logger
import org.akanework.gramophone.BuildConfig
import org.akanework.gramophone.logic.ui.BugHandlerActivity
import org.akanework.gramophone.ui.LyricWidgetProvider
import java.io.File
import java.io.IOException
import kotlin.system.exitProcess
import org.akanework.gramophone.BuildConfig
import org.akanework.gramophone.logic.ui.BugHandlerActivity
import org.akanework.gramophone.ui.LyricWidgetProvider

/**
* GramophoneApplication
Expand All @@ -71,12 +71,17 @@ class GramophoneApplication : Application(), SingletonImageLoader.Factory,
// Use StrictMode to find anti-pattern issues
StrictMode.setThreadPolicy(
ThreadPolicy.Builder()
.detectAll().permitDiskReads() // permit disk reads due to media3 setMetadata() TODO extra player thread
.penaltyLog().penaltyDialog().build())
.detectAll()
.permitDiskReads() // permit disk reads due to media3 setMetadata() TODO extra player thread
.penaltyLog()
.penaltyDialog()
.build()
)
StrictMode.setVmPolicy(
VmPolicy.Builder()
.detectAll()
.penaltyLog().penaltyDeath().build())
.penaltyLog().penaltyDeath().build()
)
}
// This is a separate thread to avoid disk read on main thread and improve startup time
Thread {
Expand Down Expand Up @@ -119,36 +124,38 @@ class GramophoneApplication : Application(), SingletonImageLoader.Factory,
return@Factory Fetcher {
ImageFetchResult(
ThumbnailUtils.createAudioThumbnail(file, options.size.let {
Size(it.width.pxOrElse { size?.width ?: 10000 },
it.height.pxOrElse { size?.height ?: 10000 })
}, null).asImage(), true, DataSource.DISK)
Size(it.width.pxOrElse { size?.width ?: 10000 },
it.height.pxOrElse { size?.height ?: 10000 })
}, null).asImage(), true, DataSource.DISK
)
}
})
}
}
.run {
if (!BuildConfig.DEBUG) this else
logger(object : Logger {
override var minLevel = Logger.Level.Verbose
override fun log(
tag: String,
level: Logger.Level,
message: String?,
throwable: Throwable?
) {
if (level < minLevel) return
val priority = level.ordinal + 2 // obviously the best way to do it
if (message != null) {
Log.println(priority, tag, message)
logger(object : Logger {
override var minLevel = Logger.Level.Verbose
override fun log(
tag: String,
level: Logger.Level,
message: String?,
throwable: Throwable?
) {
if (level < minLevel) return
val priority = level.ordinal + 2 // obviously the best way to do it
if (message != null) {
Log.println(priority, tag, message)
}
// Let's keep the log readable and ignore normal events' stack traces.
if (throwable != null && throwable !is NullRequestDataException
&& (throwable !is IOException
|| throwable.message != "No album art found")
) {
Log.println(priority, tag, Log.getStackTraceString(throwable))
}
}
// Let's keep the log readable and ignore normal events' stack traces.
if (throwable != null && throwable !is NullRequestDataException
&& (throwable !is IOException
|| throwable.message != "No album art found")) {
Log.println(priority, tag, Log.getStackTraceString(throwable))
}
}
})
})
}
.build()
}
Expand Down
Loading

0 comments on commit 65f47dc

Please sign in to comment.