Code Cleanup

main
Prathamesh More 2021-10-11 11:47:55 +05:30
parent 6ff3eb2e2a
commit 520b6b74ca
22 changed files with 155 additions and 139 deletions

View File

@ -40,7 +40,7 @@ public class CategoryInfoAdapter extends RecyclerView.Adapter<CategoryInfoAdapte
implements SwipeAndDragHelper.ActionCompletionContract {
private List<CategoryInfo> categoryInfos;
private ItemTouchHelper touchHelper;
private final ItemTouchHelper touchHelper;
public CategoryInfoAdapter() {
SwipeAndDragHelper swipeAndDragHelper = new SwipeAndDragHelper(this);
@ -128,15 +128,15 @@ public class CategoryInfoAdapter extends RecyclerView.Adapter<CategoryInfoAdapte
}
static class ViewHolder extends RecyclerView.ViewHolder {
private MaterialCheckBox checkBox;
private View dragView;
private TextView title;
private final MaterialCheckBox checkBox;
private final View dragView;
private final TextView title;
ViewHolder(View view) {
super(view);
checkBox = view.findViewById(R.id.checkbox);
checkBox.setButtonTintList(
ColorStateList.valueOf(ThemeStore.Companion.accentColor(checkBox.getContext())));
ColorStateList.valueOf(ThemeStore.Companion.accentColor(checkBox.getContext())));
title = view.findViewById(R.id.title);
dragView = view.findViewById(R.id.drag_view);
}

View File

@ -130,7 +130,7 @@ open class AlbumAdapter(
}
override fun getName(album: Album): String {
return album.title!!
return album.title
}
override fun onMultipleItemAction(

View File

@ -54,7 +54,7 @@ class AlbumDetailsViewModel(
fun getAlbumInfo(album: Album): LiveData<Result<LastFmAlbum>> = liveData {
emit(Result.Loading)
emit(repository.albumInfo(album.artistName ?: "-", album.title ?: "-"))
emit(repository.albumInfo(album.artistName, album.title))
}
fun getMoreAlbums(artist: Artist): LiveData<List<Album>> = liveData(IO) {

View File

@ -19,13 +19,15 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
/** 一行歌词实体 */
/**
*
*/
class LrcEntry implements Comparable<LrcEntry> {
public static final int GRAVITY_CENTER = 0;
public static final int GRAVITY_LEFT = 1;
public static final int GRAVITY_RIGHT = 2;
private long time;
private String text;
private final long time;
private final String text;
private String secondText;
private StaticLayout staticLayout;
/** 歌词距离视图顶部的距离 */

View File

@ -43,15 +43,17 @@ import java.util.List;
import code.name.monkey.retromusic.BuildConfig;
import code.name.monkey.retromusic.R;
/** 歌词 Created by wcy on 2015/11/9. */
/**
* Created by wcy on 2015/11/9.
*/
@SuppressLint("StaticFieldLeak")
public class LrcView extends View {
private static final long ADJUST_DURATION = 100;
private static final long TIMELINE_KEEP_TIME = 4 * DateUtils.SECOND_IN_MILLIS;
private List<LrcEntry> mLrcEntryList = new ArrayList<>();
private TextPaint mLrcPaint = new TextPaint();
private TextPaint mTimePaint = new TextPaint();
private final List<LrcEntry> mLrcEntryList = new ArrayList<>();
private final TextPaint mLrcPaint = new TextPaint();
private final TextPaint mTimePaint = new TextPaint();
private Paint.FontMetrics mTimeFontMetrics;
private Drawable mPlayDrawable;
private float mDividerHeight;
@ -78,28 +80,30 @@ public class LrcView extends View {
private boolean isTouching;
private boolean isFling;
private int mTextGravity; // 歌词显示位置,靠左/居中/靠右
private Runnable hideTimelineRunnable =
new Runnable() {
@Override
public void run() {
if (hasLrc() && isShowTimeline) {
isShowTimeline = false;
smoothScrollTo(mCurrentLine);
}
}
};
/** 手势监听器 */
private GestureDetector.SimpleOnGestureListener mSimpleOnGestureListener =
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
if (hasLrc() && mOnPlayClickListener != null) {
mScroller.forceFinished(true);
removeCallbacks(hideTimelineRunnable);
isTouching = true;
isShowTimeline = true;
invalidate();
return true;
private final Runnable hideTimelineRunnable =
new Runnable() {
@Override
public void run() {
if (hasLrc() && isShowTimeline) {
isShowTimeline = false;
smoothScrollTo(mCurrentLine);
}
}
};
/**
*
*/
private final GestureDetector.SimpleOnGestureListener mSimpleOnGestureListener =
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
if (hasLrc() && mOnPlayClickListener != null) {
mScroller.forceFinished(true);
removeCallbacks(hideTimelineRunnable);
isTouching = true;
isShowTimeline = true;
invalidate();
return true;
}
return super.onDown(e);
}

View File

@ -78,15 +78,17 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
private final FragmentManager mFragmentManager;
private FragmentTransaction mCurTransaction = null;
private ArrayList<Fragment.SavedState> mSavedState = new ArrayList<Fragment.SavedState>();
private ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
private final ArrayList<Fragment.SavedState> mSavedState = new ArrayList<Fragment.SavedState>();
private final ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
private Fragment mCurrentPrimaryItem = null;
public CustomFragmentStatePagerAdapter(FragmentManager fm) {
mFragmentManager = fm;
}
/** Return the Fragment associated with a specified position. */
/**
* Return the Fragment associated with a specified position.
*/
public abstract Fragment getItem(int position);
@Override

View File

@ -38,7 +38,7 @@ public class UpdateToastMediaScannerCompletionListener
private final List<String> toBeScanned;
private int failed = 0;
private int scanned = 0;
private Toast toast;
private final Toast toast;
@SuppressLint("ShowToast")
public UpdateToastMediaScannerCompletionListener(Activity activity, List<String> toBeScanned) {

View File

@ -30,9 +30,6 @@ data class Artist(
}
var name: String = ""
set(value) {
field = value
}
get() {
val name = if (isAlbumArtist) getAlbumArtistName()
else getArtistName()

View File

@ -112,7 +112,8 @@ public class LastFmAlbum {
public class Tags {
@Expose private List<Tag> tag = null;
@Expose
private final List<Tag> tag = null;
public List<Tag> getTag() {
return tag;

View File

@ -84,7 +84,8 @@ public class LastFmTrack {
}
public static class Toptags {
@Expose private List<Tag> tag = null;
@Expose
private final List<Tag> tag = null;
public List<Tag> getTag() {
return tag;

View File

@ -36,7 +36,7 @@ public class BlacklistStore extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "blacklist.db";
private static final int VERSION = 2;
private static BlacklistStore sInstance = null;
private Context context;
private final Context context;
public BlacklistStore(final Context context) {
super(context, DATABASE_NAME, null, VERSION);

View File

@ -34,24 +34,27 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
private static final int VERSION = 3;
// how many weeks worth of playback to track
private static final int NUM_WEEKS = 52;
@Nullable private static SongPlayCountStore sInstance = null;
@Nullable
private static SongPlayCountStore sInstance = null;
// interpolator curve applied for measuring the curve
@NonNull private static Interpolator sInterpolator = new AccelerateInterpolator(1.5f);
@NonNull
private static final Interpolator sInterpolator = new AccelerateInterpolator(1.5f);
// how high to multiply the interpolation curve
@SuppressWarnings("FieldCanBeLocal")
private static int INTERPOLATOR_HEIGHT = 50;
private static final int INTERPOLATOR_HEIGHT = 50;
// how high the base value is. The ratio of the Height to Base is what really matters
@SuppressWarnings("FieldCanBeLocal")
private static int INTERPOLATOR_BASE = 25;
private static final int INTERPOLATOR_BASE = 25;
@SuppressWarnings("FieldCanBeLocal")
private static int ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7;
private static final int ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7;
@NonNull private static String WHERE_ID_EQUALS = SongPlayCountColumns.ID + "=?";
@NonNull
private static final String WHERE_ID_EQUALS = SongPlayCountColumns.ID + "=?";
// number of weeks since epoch time
private int mNumberOfWeeksSinceEpoch;
private final int mNumberOfWeeksSinceEpoch;
// used to track if we've walked through the db and updated all the rows
private boolean mDatabaseUpdated;

View File

@ -34,7 +34,7 @@ public class SortedCursor extends AbstractCursor {
// the map of external indices to internal indices
private ArrayList<Integer> mOrderedPositions;
// this contains the ids that weren't found in the underlying cursor
private ArrayList<String> mMissingValues;
private final ArrayList<String> mMissingValues;
// this contains the mapped cursor positions and afterwards the extra ids that weren't found
private HashMap<String, Integer> mMapCursorPositions;

View File

@ -34,7 +34,7 @@ public class SortedLongCursor extends AbstractCursor {
// the map of external indices to internal indices
private ArrayList<Integer> mOrderedPositions;
// this contains the ids that weren't found in the underlying cursor
private ArrayList<Long> mMissingIds;
private final ArrayList<Long> mMissingIds;
// this contains the mapped cursor positions and afterwards the extra ids that weren't found
private HashMap<Long, Integer> mMapCursorPositions;

View File

@ -39,8 +39,9 @@ public class MultiPlayer
private MediaPlayer mCurrentMediaPlayer = new MediaPlayer();
private MediaPlayer mNextMediaPlayer;
private Context context;
@Nullable private Playback.PlaybackCallbacks callbacks;
private final Context context;
@Nullable
private Playback.PlaybackCallbacks callbacks;
private boolean mIsInitialized = false;

View File

@ -187,15 +187,15 @@ public class MusicService extends MediaBrowserServiceCompat
public int position = -1;
private AppWidgetBig appWidgetBig = AppWidgetBig.Companion.getInstance();
private final AppWidgetBig appWidgetBig = AppWidgetBig.Companion.getInstance();
private AppWidgetCard appWidgetCard = AppWidgetCard.Companion.getInstance();
private final AppWidgetCard appWidgetCard = AppWidgetCard.Companion.getInstance();
private AppWidgetClassic appWidgetClassic = AppWidgetClassic.Companion.getInstance();
private final AppWidgetClassic appWidgetClassic = AppWidgetClassic.Companion.getInstance();
private AppWidgetSmall appWidgetSmall = AppWidgetSmall.Companion.getInstance();
private final AppWidgetSmall appWidgetSmall = AppWidgetSmall.Companion.getInstance();
private AppWidgetText appWidgetText = AppWidgetText.Companion.getInstance();
private final AppWidgetText appWidgetText = AppWidgetText.Companion.getInstance();
private final BroadcastReceiver widgetIntentReceiver =
new BroadcastReceiver() {
@ -229,15 +229,15 @@ public class MusicService extends MediaBrowserServiceCompat
}
}
};
private AudioManager audioManager;
private IntentFilter becomingNoisyReceiverIntentFilter =
new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
private boolean becomingNoisyReceiverRegistered;
private IntentFilter bluetoothConnectedIntentFilter =
new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
private boolean bluetoothConnectedRegistered = false;
private IntentFilter headsetReceiverIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
private boolean headsetReceiverRegistered = false;
private AudioManager audioManager;
private final IntentFilter becomingNoisyReceiverIntentFilter =
new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
private boolean becomingNoisyReceiverRegistered;
private final IntentFilter bluetoothConnectedIntentFilter =
new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
private boolean bluetoothConnectedRegistered = false;
private final IntentFilter headsetReceiverIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
private boolean headsetReceiverRegistered = false;
private MediaSessionCompat mediaSession;
private ContentObserver mediaStoreObserver;
private HandlerThread musicPlayerHandlerThread;
@ -291,59 +291,59 @@ public class MusicService extends MediaBrowserServiceCompat
private HandlerThread queueSaveHandlerThread;
private boolean queuesRestored;
private int repeatMode;
private int shuffleMode;
private SongPlayCountHelper songPlayCountHelper = new SongPlayCountHelper();
private final BroadcastReceiver bluetoothReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
String action = intent.getAction();
if (action != null) {
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)
&& PreferenceUtil.INSTANCE.isBluetoothSpeaker()) {
if (VERSION.SDK_INT >= VERSION_CODES.M) {
if (getAudioManager().getDevices(AudioManager.GET_DEVICES_OUTPUTS).length > 0) {
private int shuffleMode;
private final SongPlayCountHelper songPlayCountHelper = new SongPlayCountHelper();
private final BroadcastReceiver bluetoothReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
String action = intent.getAction();
if (action != null) {
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)
&& PreferenceUtil.INSTANCE.isBluetoothSpeaker()) {
if (VERSION.SDK_INT >= VERSION_CODES.M) {
if (getAudioManager().getDevices(AudioManager.GET_DEVICES_OUTPUTS).length > 0) {
play();
}
} else {
if (getAudioManager().isBluetoothA2dpOn()) {
play();
}
}
}
}
}
};
private PhoneStateListener phoneStateListener =
new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// Not in call: Play music
play();
break;
case TelephonyManager.CALL_STATE_RINGING:
case TelephonyManager.CALL_STATE_OFFHOOK:
// A call is dialing, active or on hold
pause();
break;
default:
} else {
if (getAudioManager().isBluetoothA2dpOn()) {
play();
}
super.onCallStateChanged(state, incomingNumber);
}
}
};
private BroadcastReceiver headsetReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if (Intent.ACTION_HEADSET_PLUG.equals(action)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
pause();
}
}
};
private final PhoneStateListener phoneStateListener =
new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// Not in call: Play music
play();
break;
case TelephonyManager.CALL_STATE_RINGING:
case TelephonyManager.CALL_STATE_OFFHOOK:
// A call is dialing, active or on hold
pause();
break;
default:
}
super.onCallStateChanged(state, incomingNumber);
}
};
private final BroadcastReceiver headsetReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if (Intent.ACTION_HEADSET_PLUG.equals(action)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
pause();
break;
case 1:
play();

View File

@ -146,7 +146,7 @@ public class AutoGeneratedPlaylistBitmap {
try {
return Glide.with(context)
.asBitmap()
.load(MusicUtil.INSTANCE.getMediaStoreAlbumCoverUri(id))
.load(MusicUtil.getMediaStoreAlbumCoverUri(id))
.submit(200, 200)
.get();
} catch (Exception e) {

View File

@ -22,7 +22,7 @@ public class CalendarUtil {
private static final long MS_PER_MINUTE = 60 * 1000;
private static final long MS_PER_DAY = 24 * 60 * MS_PER_MINUTE;
private Calendar calendar;
private final Calendar calendar;
public CalendarUtil() {
this.calendar = Calendar.getInstance();

View File

@ -34,6 +34,8 @@ import org.xmlpull.v1.XmlPullParserException
import java.io.IOException
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.util.*
import kotlin.collections.LinkedHashMap
/**
* Validates that the calling package is authorized to browse a [MediaBrowserServiceCompat].
@ -274,7 +276,8 @@ class PackageValidator(
var eventType = parser.next()
while (eventType != XmlResourceParser.END_TAG) {
val isRelease = parser.getAttributeBooleanValue(null, "release", false)
val signature = parser.nextText().replace(WHITESPACE_REGEX, "").toLowerCase()
val signature = parser.nextText().replace(WHITESPACE_REGEX, "")
.lowercase(Locale.getDefault())
callerSignatures += KnownSignature(signature, isRelease)
eventType = parser.next()
@ -319,14 +322,14 @@ class PackageValidator(
}
private data class KnownCallerInfo(
internal val name: String,
internal val packageName: String,
internal val signatures: MutableSet<KnownSignature>
val name: String,
val packageName: String,
val signatures: MutableSet<KnownSignature>
)
private data class KnownSignature(
internal val signature: String,
internal val release: Boolean
val signature: String,
val release: Boolean
)
/**
@ -334,11 +337,11 @@ class PackageValidator(
* to see if it's a known caller.
*/
private data class CallerPackageInfo(
internal val name: String,
internal val packageName: String,
internal val uid: Int,
internal val signature: String?,
internal val permissions: Set<String>
val name: String,
val packageName: String,
val uid: Int,
val signature: String?,
val permissions: Set<String>
)
}

View File

@ -22,7 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
public class SwipeAndDragHelper extends ItemTouchHelper.Callback {
private ActionCompletionContract contract;
private final ActionCompletionContract contract;
public SwipeAndDragHelper(@NonNull ActionCompletionContract contract) {
this.contract = contract;

View File

@ -77,7 +77,7 @@ public class MediaNotificationProcessor {
private static final String TAG = "ColorPicking";
private float[] mFilteredBackgroundHsl = null;
private Palette.Filter mBlackWhiteFilter =
private final Palette.Filter mBlackWhiteFilter =
(rgb, hsl) -> !isWhiteOrBlack(hsl);
private boolean mIsLowPriority;
private int backgroundColor;
@ -85,7 +85,7 @@ public class MediaNotificationProcessor {
private int primaryTextColor;
private int actionBarColor;
private Drawable drawable;
private Context context;
private final Context context;
public MediaNotificationProcessor(Context context, Drawable drawable) {
this.context = context;

View File

@ -38,14 +38,16 @@ import code.name.monkey.retromusic.R;
public class SeekArc extends View {
private static final String TAG = SeekArc.class.getSimpleName();
private static int INVALID_PROGRESS_VALUE = -1;
private static final int INVALID_PROGRESS_VALUE = -1;
// The initial rotational offset -90 means we start at 12 o'clock
private final int mAngleOffset = -90;
private Paint mArcPaint;
// Internal variables
private int mArcRadius = 0;
private RectF mArcRect = new RectF();
/** The Width of the background arc for the SeekArc */
private final RectF mArcRect = new RectF();
/**
* The Width of the background arc for the SeekArc
*/
private int mArcWidth = 2;
/** Will the progress increase clockwise or anti-clockwise */
private boolean mClockwise = true;