Added suggestions & Updated libs.
This commit is contained in:
parent
865e13a536
commit
547e49507e
20 changed files with 568 additions and 186 deletions
|
@ -127,4 +127,16 @@ public class CalendarUtil {
|
|||
final Calendar monthCal = new GregorianCalendar(calendar.get(Calendar.YEAR), month, 1);
|
||||
return monthCal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time elapsed so far last N days in milliseconds.
|
||||
*
|
||||
* @return Time elapsed since N days in milliseconds.
|
||||
*/
|
||||
public long getElapsedDays(int numDays) {
|
||||
long elapsed = getElapsedToday();
|
||||
elapsed += numDays * MS_PER_DAY;
|
||||
|
||||
return elapsed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package code.name.monkey.retromusic.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkInfo
|
||||
|
@ -23,6 +24,7 @@ import com.google.gson.JsonSyntaxException
|
|||
import com.google.gson.reflect.TypeToken
|
||||
import java.io.File
|
||||
|
||||
|
||||
object PreferenceUtil {
|
||||
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.getContext())
|
||||
|
||||
|
@ -537,6 +539,44 @@ object PreferenceUtil {
|
|||
)
|
||||
}
|
||||
|
||||
fun getRecentlyPlayedCutoffTimeMillis(): Long {
|
||||
return getCutoffTimeMillis(RECENTLY_PLAYED_CUTOFF)
|
||||
}
|
||||
|
||||
fun getRecentlyPlayedCutoffText(context: Context): String? {
|
||||
return getCutoffText(RECENTLY_PLAYED_CUTOFF, context)
|
||||
}
|
||||
|
||||
private fun getCutoffText(
|
||||
cutoff: String,
|
||||
context: Context
|
||||
): String? {
|
||||
return when (sharedPreferences.getString(cutoff, "")) {
|
||||
"today" -> context.getString(R.string.today)
|
||||
"this_week" -> context.getString(R.string.this_week)
|
||||
"past_seven_days" -> context.getString(R.string.past_seven_days)
|
||||
"past_three_months" -> context.getString(R.string.past_three_months)
|
||||
"this_year" -> context.getString(R.string.this_year)
|
||||
"this_month" -> context.getString(R.string.this_month)
|
||||
else -> context.getString(R.string.this_month)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCutoffTimeMillis(cutoff: String): Long {
|
||||
val calendarUtil = CalendarUtil()
|
||||
val interval: Long
|
||||
interval = when (sharedPreferences.getString(cutoff, "")) {
|
||||
"today" -> calendarUtil.elapsedToday
|
||||
"this_week" -> calendarUtil.elapsedWeek
|
||||
"past_seven_days" -> calendarUtil.getElapsedDays(7)
|
||||
"past_three_months" -> calendarUtil.getElapsedMonths(3)
|
||||
"this_year" -> calendarUtil.elapsedYear
|
||||
"this_month" -> calendarUtil.elapsedMonth
|
||||
else -> calendarUtil.elapsedMonth
|
||||
}
|
||||
return System.currentTimeMillis() - interval
|
||||
}
|
||||
|
||||
val lastAddedCutoff: Long
|
||||
get() {
|
||||
val calendarUtil = CalendarUtil()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue