Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Issue 918 #923

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
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.ArrayList;
import java.util.List;

public class LastAddedLoader {

@NonNull
public static List<Song> getLastAddedSongs(@NonNull Context context) {
return SongLoader.getSongs(makeLastAddedCursor(context));
List<Song> songs = SongLoader.getSongs(makeLastAddedCursor(context));

if (PreferenceUtil.getInstance(context).isLastAddedItemShowLimitEnable()) {
int limit = PreferenceUtil.getInstance(context).getLastAddedItemShowLimit();
return songs.subList(0, Math.min(songs.size(), limit));
} else {
return songs;
}
}

public static Cursor makeLastAddedCursor(@NonNull final Context context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.kabouzeid.gramophone.preferences;

import android.content.Context;
import android.util.AttributeSet;

import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEDialogPreference;

public class LastAddedLimitPreference extends ATEDialogPreference {

public LastAddedLimitPreference(Context context) {
super(context);
}

public LastAddedLimitPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}

public LastAddedLimitPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public LastAddedLimitPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.kabouzeid.gramophone.preferences;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;

import com.afollestad.materialdialogs.MaterialDialog;
import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.material.textfield.TextInputEditText;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.util.PreferenceUtil;

public class LastAddedLimitPreferenceDialog extends DialogFragment {

public static LastAddedLimitPreferenceDialog newInstance() {
return new LastAddedLimitPreferenceDialog();
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = requireActivity().getLayoutInflater()
.inflate(R.layout.preference_dailog_last_added_limit ,null);

PreferenceUtil preferenceUtil = PreferenceUtil.getInstance(requireContext());

SwitchMaterial enableLimit = view.findViewById(R.id.last_added_limit_switch);
TextInputEditText limitText = view.findViewById(R.id.last_added_limit_text);

enableLimit.setChecked(preferenceUtil.isLastAddedItemShowLimitEnable());
limitText.setEnabled(enableLimit.isChecked());

enableLimit.setOnCheckedChangeListener((compoundButton, b) -> limitText.setEnabled(b));

limitText.setText(String.valueOf(preferenceUtil.getLastAddedItemShowLimit()));

return new MaterialDialog.Builder(requireContext())
.title(getResources().getString(R.string.last_added_items_show_limit))
.autoDismiss(false)
.customView(view, false)
.positiveText(android.R.string.ok)
.negativeText(android.R.string.cancel)
.onPositive((dialog, which) -> {
if (enableLimit.isChecked() && limitText.getText().toString().equals("")) {
Toast.makeText(requireContext(), R.string.invalid_last_added_limit,
Toast.LENGTH_SHORT).show();
} else {
PreferenceUtil.getInstance(requireContext()).setLastAddedItemShowLimitEnable
(enableLimit.isChecked());
PreferenceUtil.getInstance(requireContext()).setLastAddedItemShowLimit(
toIntOrDefault(limitText.getText().toString(), 100));
dismiss();
}
})
.onNegative((dialog, which) -> dismiss())
.build();
}

public int toIntOrDefault(String s, int d) {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
return d;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.kabouzeid.gramophone.misc.NonProAllowedColors;
import com.kabouzeid.gramophone.preferences.BlacklistPreference;
import com.kabouzeid.gramophone.preferences.BlacklistPreferenceDialog;
import com.kabouzeid.gramophone.preferences.LastAddedLimitPreference;
import com.kabouzeid.gramophone.preferences.LastAddedLimitPreferenceDialog;
import com.kabouzeid.gramophone.preferences.LibraryPreference;
import com.kabouzeid.gramophone.preferences.LibraryPreferenceDialog;
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreference;
Expand Down Expand Up @@ -170,6 +172,8 @@ public DialogFragment onCreatePreferenceDialog(Preference preference) {
return BlacklistPreferenceDialog.newInstance();
} else if (preference instanceof LibraryPreference) {
return LibraryPreferenceDialog.newInstance();
} else if (preference instanceof LastAddedLimitPreference) {
return LastAddedLimitPreferenceDialog.newInstance();
}
return super.onCreatePreferenceDialog(preference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public final class PreferenceUtil {

public static final String LIBRARY_CATEGORIES = "library_categories";

public static final String LAST_ADDED_ITEMS_LIMIT = "last_added_show_limit";
public static final String LAST_ADDED_ITEMS_LIMIT_ENABLE = "last_added_show_limit_enable";

private static final String REMEMBER_SHUFFLE = "remember_shuffle";

private static PreferenceUtil sInstance;
Expand Down Expand Up @@ -535,4 +538,20 @@ public List<CategoryInfo> getDefaultLibraryCategoryInfos() {
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.PLAYLISTS, true));
return defaultCategoryInfos;
}

public boolean isLastAddedItemShowLimitEnable() {
return mPreferences.getBoolean(LAST_ADDED_ITEMS_LIMIT_ENABLE, false);
}

public void setLastAddedItemShowLimitEnable(boolean enable) {
mPreferences.edit().putBoolean(LAST_ADDED_ITEMS_LIMIT_ENABLE, enable).apply();
}

public int getLastAddedItemShowLimit() {
return mPreferences.getInt(LAST_ADDED_ITEMS_LIMIT, 100);
}

public void setLastAddedItemShowLimit(int limit) {
mPreferences.edit().putInt(LAST_ADDED_ITEMS_LIMIT, limit).apply();
}
}
39 changes: 39 additions & 0 deletions app/src/main/res/layout/preference_dailog_last_added_limit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="24dp"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="12dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/enable" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/last_added_limit_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/last_added_limit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:paddingVertical="12dp"
android:enabled="false" />
</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">إكمال آخر أغنية</string>
<string name="dialog_ringtone_title">تعيين كنغمة الرنين</string>
<string name="dialog_ringtone_message">السماح لـphonograph بتعديل إعدادات الصوت</string>
<string name="last_added_items_show_limit">الحد لعرض العناصر المضافة الأخيرة</string>
<string name="enable">ممكن</string>
<string name="last_added_items_show_limit_summery">واضاف التشغيل آخر تظهر الأغاني تقتصر فقط</string>
<string name="invalid_last_added_limit">الرجاء إدخال رقم</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,8 @@
<string name="app_shortcut_top_tracks_short">Най - често слушани</string>
<string name="app_shortcut_last_added_short">Последно_добавени</string>
<string name="playlist_is_empty">Плейлистът е празен</string>
<string name="last_added_items_show_limit">Ограничение за показване на последно добавени елементи</string>
<string name="enable">активиране</string>
<string name="last_added_items_show_limit_summery">Последно добавени плейлист ще показва само ограничени песни</string>
<string name="invalid_last_added_limit">Моля въведете номер</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">Dokončit poslední skladbu</string>
<string name="dialog_ringtone_title">Nastavit vyzváněcí tón</string>
<string name="dialog_ringtone_message">Povolit aplikaci Phonograph měnit nastavení zvuku</string>
<string name="last_added_items_show_limit">Limit pro zobrazení naposledy přidaných položek</string>
<string name="enable">umožnit</string>
<string name="last_added_items_show_limit_summery">Poslední přidané playlist se zobrazí pouze omezené písně</string>
<string name="invalid_last_added_limit">Zadejte číslo</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">Letzten Song beenden</string>
<string name="dialog_ringtone_title">Klingelton einstellen</string>
<string name="dialog_ringtone_message">Phonograph erlauben, die Audioeinstellungen zu verändern</string>
<string name="last_added_items_show_limit">Limit für die Anzeige der zuletzt hinzugefügten Elemente</string>
<string name="enable">aktivieren</string>
<string name="last_added_items_show_limit_summery">Zuletzt hinzugekommen Playlist zeigt nur begrenzt Songs</string>
<string name="invalid_last_added_limit">Bitte gebe eine Nummer ein</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,8 @@
<string name="app_shortcut_top_tracks_short">Κορυφαία Κομμάτια</string>
<string name="app_shortcut_last_added_short">@string/last_added</string>
<string name="playlist_is_empty">Η Λίστα αναπαραγωγής είναι κενή</string>
<string name="last_added_items_show_limit">Όριο για την εμφάνιση των στοιχείων που προστέθηκαν τελευταία</string>
<string name="enable">επιτρέπω</string>
<string name="last_added_items_show_limit_summery">Πρόσφατες playlist θα δείξει μόνο περιορισμένη τραγούδια</string>
<string name="invalid_last_added_limit">Παρακαλώ εισάγετε έναν αριθμό</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-en-rCA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,8 @@
<string name="pref_summary_blacklist">The content of blacklisted folders is hidden from your library</string>
<string name="reset_artist_image">Reset artist image</string>
<string name="set_artist_image">Set artist image</string>
<string name="last_added_items_show_limit">Limit for showing last added items</string>
<string name="enable">Enable</string>
<string name="last_added_items_show_limit_summery">Last Added playlist will show only limited songs</string>
<string name="invalid_last_added_limit">Please enter a number</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-en-rGB/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">Finish last song</string>
<string name="dialog_ringtone_title">Set ringtone</string>
<string name="dialog_ringtone_message">Allow phonograph to modify audio settings</string>
<string name="last_added_items_show_limit">Limit for showing last added items</string>
<string name="enable">Enable</string>
<string name="last_added_items_show_limit_summery">Last Added playlist will show only limited songs</string>
<string name="invalid_last_added_limit">Please enter a number</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,8 @@ El contenido de las carpetas de la lista negra está oculto en tu biblioteca"</s
<string name="sort_order_album">Álbum</string>
<string name="sort_order_year">Año</string>
<string name="finish_current_music_sleep_timer">Terminar la última canción</string>
<string name="last_added_items_show_limit">Límite para mostrar los últimos elementos agregados</string>
<string name="enable">permitir</string>
<string name="last_added_items_show_limit_summery">Última Agregado lista de reproducción mostrará canciones limitados</string>
<string name="invalid_last_added_limit">Por favor, introduzca un número</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-es-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,8 @@
<string name="sort_order_artist">Artista</string>
<string name="sort_order_album">Álbum</string>
<string name="sort_order_year">Año</string>
<string name="last_added_items_show_limit">Límite para mostrar los últimos elementos agregados</string>
<string name="enable">permitir</string>
<string name="last_added_items_show_limit_summery">Última Agregado lista de reproducción mostrará canciones limitados</string>
<string name="invalid_last_added_limit">Por favor, introduzca un número</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,8 @@
<string name="sort_order_album">Albumi</string>
<string name="sort_order_year">Vuosi</string>
<string name="finish_current_music_sleep_timer">Lopeta viimeinen kappale</string>
<string name="last_added_items_show_limit">Rajoitus viimeksi lisättyjen tuotteiden näyttämiselle</string>
<string name="enable">activer</string>
<string name="last_added_items_show_limit_summery">Viimeksi lisätyt soittolista näkyy vain vähän kappaleita</string>
<string name="invalid_last_added_limit">Anna numero</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">Terminer le dernier titre</string>
<string name="dialog_ringtone_title">Définir la sonnerie</string>
<string name="dialog_ringtone_message">Autoriser Phonograph à modifier les paramètres audio</string>
<string name="last_added_items_show_limit">Limite d\'affichage des derniers éléments ajoutés</string>
<string name="enable">activer</string>
<string name="last_added_items_show_limit_summery">playlist Dernières ajoutées affichera des chansons seulement limitées</string>
<string name="invalid_last_added_limit">S\'il vous plaît entrer un numéro</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-he/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,8 @@
<string name="sort_order_album">אלבום</string>
<string name="sort_order_year">שנה</string>
<string name="finish_current_music_sleep_timer">סיים את השיר האחרון</string>
<string name="last_added_items_show_limit">מגבלה להצגת פריטים שנוספו לאחרונה</string>
<string name="enable">לְאַפשֵׁר</string>
<string name="last_added_items_show_limit_summery">רשימת השמעה הוסף לאחרונה נראתה רק שירים מוגבלים</string>
<string name="invalid_last_added_limit">בבקשה הכנס מספר</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,8 @@
<string name="sort_order_album">Album</string>
<string name="sort_order_year">Godina</string>
<string name="finish_current_music_sleep_timer">Završi zadnju pjesmu</string>
<string name="last_added_items_show_limit">Ograničenje za prikaz posljednjih dodanih stavki</string>
<string name="enable">omogućiti</string>
<string name="last_added_items_show_limit_summery">Zadnje dodano popis će se prikazati samo ograničene pjesme</string>
<string name="invalid_last_added_limit">Unesite broj</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,8 @@
<string name="sort_order_artist">Előadó</string>
<string name="sort_order_album">Album</string>
<string name="sort_order_year">Év</string>
<string name="last_added_items_show_limit">Korlát a legutóbb hozzáadott elemek megjelenítésére</string>
<string name="enable">engedélyezze</string>
<string name="last_added_items_show_limit_summery">Utoljára feltöltött lejátszási lista megmutatja csak korlátozott dalok</string>
<string name="invalid_last_added_limit">Kérjük, adjon meg egy számot</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-id/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">Selesaikan lagu terakhir</string>
<string name="dialog_ringtone_title">Setel sebagai nada dering</string>
<string name="dialog_ringtone_message">Izinkan phonograph mengubah pengaturan audio</string>
<string name="last_added_items_show_limit">Batas untuk menampilkan item terakhir ditambahkan</string>
<string name="enable">memungkinkan</string>
<string name="last_added_items_show_limit_summery">Terakhir Ditambahkan playlist akan menunjukkan lagu hanya terbatas</string>
<string name="invalid_last_added_limit">Masukkan nomor</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,8 @@
<string name="finish_current_music_sleep_timer">Selesaikan lagu terakhir</string>
<string name="dialog_ringtone_title">Setel sebagai nada dering</string>
<string name="dialog_ringtone_message">Izinkan phonograph mengubah pengaturan audio</string>
<string name="last_added_items_show_limit">Batas untuk menampilkan item terakhir ditambahkan</string>
<string name="enable">memungkinkan</string>
<string name="last_added_items_show_limit_summery">Terakhir Ditambahkan playlist akan menunjukkan lagu hanya terbatas</string>
<string name="invalid_last_added_limit">Masukkan nomor</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,8 @@
<string name="finish_current_music_sleep_timer">Termina l\'ultimo brano</string>
<string name="dialog_ringtone_title">Imposta suoneria</string>
<string name="dialog_ringtone_message">Consenti a Phonograph di modificare le impostazioni audio</string>
<string name="last_added_items_show_limit">Limite per la visualizzazione degli ultimi elementi aggiunti</string>
<string name="enable">abilitare</string>
<string name="last_added_items_show_limit_summery">Ultime aggiunte playlist mostrerà canzoni limitate</string>
<string name="invalid_last_added_limit">Per favore inserisci un numero</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,8 @@
<string name="sort_order_album">אלבום</string>
<string name="sort_order_year">שנה</string>
<string name="finish_current_music_sleep_timer">סיים את השיר האחרון</string>
<string name="last_added_items_show_limit">מגבלה להצגת פריטים שנוספו לאחרונה</string>
<string name="enable">לְאַפשֵׁר</string>
<string name="last_added_items_show_limit_summery">רשימת השמעה הוסף לאחרונה נראתה רק שירים מוגבלים</string>
<string name="invalid_last_added_limit">בבקשה הכנס מספר</string>
</resources>
Loading