From 850912bc8dedcf754da22ccc6a92bde41a753686 Mon Sep 17 00:00:00 2001 From: dkanada Date: Wed, 29 Apr 2020 13:11:00 +0900 Subject: [PATCH] remove unused loader classes --- .../gramophone/loader/FrequentLoader.java | 102 ----------- .../gramophone/loader/LatestLoader.java | 29 --- .../gramophone/loader/RecentLoader.java | 103 ----------- .../gramophone/loader/SortedLongCursor.java | 170 ------------------ 4 files changed, 404 deletions(-) delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/loader/FrequentLoader.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/loader/LatestLoader.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/loader/RecentLoader.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/loader/SortedLongCursor.java diff --git a/app/src/main/java/com/kabouzeid/gramophone/loader/FrequentLoader.java b/app/src/main/java/com/kabouzeid/gramophone/loader/FrequentLoader.java deleted file mode 100644 index 638a8b13..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/loader/FrequentLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -/* -* Copyright (C) 2014 The CyanogenMod Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package com.kabouzeid.gramophone.loader; - -import android.content.Context; -import android.database.Cursor; -import android.provider.BaseColumns; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.kabouzeid.gramophone.model.Song; -import com.kabouzeid.gramophone.provider.SongPlayCountStore; - -import java.util.List; - -public class FrequentLoader { - @NonNull - public static List getFrequent(@NonNull Context context) { - return SongLoader.getSongs(makeFrequentCursorAndClearUpDatabase(context)); - } - - @Nullable - public static Cursor makeFrequentCursorAndClearUpDatabase(@NonNull final Context context) { - SortedLongCursor retCursor = makeFrequentCursorImpl(context); - - // clean up the databases with any ids not found - if (retCursor != null) { - List missingIds = retCursor.getMissingIds(); - if (missingIds != null && missingIds.size() > 0) { - for (long id : missingIds) { - SongPlayCountStore.getInstance(context).removeItem(id); - } - } - } - return retCursor; - } - - @Nullable - private static SortedLongCursor makeFrequentCursorImpl(@NonNull final Context context) { - // first get the top results ids from the internal database - Cursor songs = SongPlayCountStore.getInstance(context).getTopPlayedResults(100); - - try { - return makeSortedCursor(context, songs, - songs.getColumnIndex(SongPlayCountStore.SongPlayCountColumns.ID)); - } finally { - if (songs != null) { - songs.close(); - } - } - } - - @Nullable - private static SortedLongCursor makeSortedCursor(@NonNull final Context context, @Nullable final Cursor cursor, final int idColumn) { - if (cursor != null && cursor.moveToFirst()) { - // create the list of ids to select against - StringBuilder selection = new StringBuilder(); - selection.append(BaseColumns._ID); - selection.append(" IN ("); - - // this tracks the order of the ids - long[] order = new long[cursor.getCount()]; - - long id = cursor.getLong(idColumn); - selection.append(id); - order[cursor.getPosition()] = id; - - while (cursor.moveToNext()) { - selection.append(","); - - id = cursor.getLong(idColumn); - order[cursor.getPosition()] = id; - selection.append(String.valueOf(id)); - } - - selection.append(")"); - - // get a list of songs with the data given the selection statement - Cursor songCursor = SongLoader.makeSongCursor(context, selection.toString(), null); - if (songCursor != null) { - // now return the wrapped TopTracksCursor to handle sorting given order - return new SortedLongCursor(songCursor, order, BaseColumns._ID); - } - } - - return null; - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/loader/LatestLoader.java b/app/src/main/java/com/kabouzeid/gramophone/loader/LatestLoader.java deleted file mode 100644 index 092fe28f..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/loader/LatestLoader.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.kabouzeid.gramophone.loader; - -import android.content.Context; -import android.database.Cursor; -import android.provider.MediaStore; -import androidx.annotation.NonNull; - -import com.kabouzeid.gramophone.model.Song; -import com.kabouzeid.gramophone.util.PreferenceUtil; - -import java.util.List; - -public class LatestLoader { - - @NonNull - public static List getLatest(@NonNull Context context) { - return SongLoader.getSongs(makeLatestCursor(context)); - } - - public static Cursor makeLatestCursor(@NonNull final Context context) { - long cutoff = PreferenceUtil.getInstance(context).getLastAddedCutoff(); - - return SongLoader.makeSongCursor( - context, - MediaStore.Audio.Media.DATE_ADDED + ">?", - new String[]{String.valueOf(cutoff)}, - MediaStore.Audio.Media.DATE_ADDED + " DESC"); - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/loader/RecentLoader.java b/app/src/main/java/com/kabouzeid/gramophone/loader/RecentLoader.java deleted file mode 100644 index a5a5b8bb..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/loader/RecentLoader.java +++ /dev/null @@ -1,103 +0,0 @@ -/* -* Copyright (C) 2014 The CyanogenMod Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package com.kabouzeid.gramophone.loader; - -import android.content.Context; -import android.database.Cursor; -import android.provider.BaseColumns; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.kabouzeid.gramophone.model.Song; -import com.kabouzeid.gramophone.provider.HistoryStore; - -import java.util.List; - -public class RecentLoader { - @NonNull - public static List getRecent(@NonNull Context context) { - return SongLoader.getSongs(makeRecentCursorAndClearUpDatabase(context)); - } - - @Nullable - public static Cursor makeRecentCursorAndClearUpDatabase(@NonNull final Context context) { - SortedLongCursor retCursor = makeRecentCursorImpl(context); - - // clean up the databases with any ids not found - if (retCursor != null) { - List missingIds = retCursor.getMissingIds(); - if (missingIds != null && missingIds.size() > 0) { - for (long id : missingIds) { - HistoryStore.getInstance(context).removeSongId(id); - } - } - } - return retCursor; - } - - @Nullable - private static SortedLongCursor makeRecentCursorImpl(@NonNull final Context context) { - // first get the top results ids from the internal database - Cursor songs = HistoryStore.getInstance(context).queryRecentIds(); - - try { - return makeSortedCursor(context, songs, - songs.getColumnIndex(HistoryStore.RecentStoreColumns.ID)); - } finally { - if (songs != null) { - songs.close(); - } - } - } - - @Nullable - private static SortedLongCursor makeSortedCursor(@NonNull final Context context, @Nullable final Cursor cursor, final int idColumn) { - if (cursor != null && cursor.moveToFirst()) { - // create the list of ids to select against - StringBuilder selection = new StringBuilder(); - selection.append(BaseColumns._ID); - selection.append(" IN ("); - - // this tracks the order of the ids - long[] order = new long[cursor.getCount()]; - - long id = cursor.getLong(idColumn); - selection.append(id); - order[cursor.getPosition()] = id; - - while (cursor.moveToNext()) { - selection.append(","); - - id = cursor.getLong(idColumn); - order[cursor.getPosition()] = id; - selection.append(String.valueOf(id)); - } - - selection.append(")"); - - // get a list of songs with the data given the selection statement - Cursor songCursor = SongLoader.makeSongCursor(context, selection.toString(), null); - if (songCursor != null) { - // now return the wrapped TopTracksCursor to handle sorting given order - return new SortedLongCursor(songCursor, order, BaseColumns._ID); - } - } - - return null; - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/loader/SortedLongCursor.java b/app/src/main/java/com/kabouzeid/gramophone/loader/SortedLongCursor.java deleted file mode 100644 index 929b1982..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/loader/SortedLongCursor.java +++ /dev/null @@ -1,170 +0,0 @@ -/* -* Copyright (C) 2014 The CyanogenMod Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package com.kabouzeid.gramophone.loader; - -import android.database.AbstractCursor; -import android.database.Cursor; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -/** - * This cursor basically wraps a song cursor and is given a list of the order of the ids of the - * contents of the cursor. It wraps the Cursor and simulates the internal cursor being sorted - * by moving the point to the appropriate spot - */ -public class SortedLongCursor extends AbstractCursor { - // cursor to wrap - private final Cursor mCursor; - // the map of external indices to internal indices - private List mOrderedPositions; - // this contains the ids that weren't found in the underlying cursor - private List mMissingIds; - // this contains the mapped cursor positions and afterwards the extra ids that weren't found - private HashMap mMapCursorPositions; - - /** - * @param cursor to wrap - * @param order the list of unique ids in sorted order to display - * @param columnName the column name of the id to look up in the internal cursor - */ - public SortedLongCursor(final Cursor cursor, final long[] order, final String columnName) { - - mCursor = cursor; - mMissingIds = buildCursorPositionMapping(order, columnName); - } - - /** - * This function populates mOrderedPositions with the cursor positions in the order based - * on the order passed in - * - * @param order the target order of the internal cursor - * @return returns the ids that aren't found in the underlying cursor - */ - @NonNull - private List buildCursorPositionMapping(@Nullable final long[] order, final String columnName) { - List missingIds = new ArrayList<>(); - - mOrderedPositions = new ArrayList<>(mCursor.getCount()); - - mMapCursorPositions = new HashMap<>(mCursor.getCount()); - final int idPosition = mCursor.getColumnIndex(columnName); - - if (mCursor.moveToFirst()) { - // first figure out where each of the ids are in the cursor - do { - mMapCursorPositions.put(mCursor.getLong(idPosition), mCursor.getPosition()); - } while (mCursor.moveToNext()); - - // now create the ordered positions to map to the internal cursor given the - // external sort order - for (int i = 0; order != null && i < order.length; i++) { - final long id = order[i]; - if (mMapCursorPositions.containsKey(id)) { - mOrderedPositions.add(mMapCursorPositions.get(id)); - mMapCursorPositions.remove(id); - } else { - missingIds.add(id); - } - } - - mCursor.moveToFirst(); - } - - return missingIds; - } - - /** - * @return the list of ids that weren't found in the underlying cursor - */ - public List getMissingIds() { - return mMissingIds; - } - - /** - * @return the list of ids that were in the underlying cursor but not part of the ordered list - */ - @NonNull - public Collection getExtraIds() { - return mMapCursorPositions.keySet(); - } - - @Override - public void close() { - mCursor.close(); - - super.close(); - } - - @Override - public int getCount() { - return mOrderedPositions.size(); - } - - @Override - public String[] getColumnNames() { - return mCursor.getColumnNames(); - } - - @Override - public String getString(int column) { - return mCursor.getString(column); - } - - @Override - public short getShort(int column) { - return mCursor.getShort(column); - } - - @Override - public int getInt(int column) { - return mCursor.getInt(column); - } - - @Override - public long getLong(int column) { - return mCursor.getLong(column); - } - - @Override - public float getFloat(int column) { - return mCursor.getFloat(column); - } - - @Override - public double getDouble(int column) { - return mCursor.getDouble(column); - } - - @Override - public boolean isNull(int column) { - return mCursor.isNull(column); - } - - @Override - public boolean onMove(int oldPosition, int newPosition) { - if (newPosition >= 0 && newPosition < getCount()) { - mCursor.moveToPosition(mOrderedPositions.get(newPosition)); - return true; - } - - return false; - } -}