Update SpotBugs
This commit is contained in:
parent
6f582e4c52
commit
c2ccc28b95
|
@ -290,7 +290,7 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (drawerLayout != null) {
|
if (drawerLayout != null && drawerToggle != null) {
|
||||||
drawerLayout.removeDrawerListener(drawerToggle);
|
drawerLayout.removeDrawerListener(drawerToggle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,8 +139,8 @@ public class TimeRangeDialog extends MaterialAlertDialogBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Point radToPoint(float angle, float radius) {
|
protected Point radToPoint(float angle, float radius) {
|
||||||
return new Point((int) (getWidth() / 2 + radius * Math.sin(-angle * Math.PI / 180 + Math.PI)),
|
return new Point((int) (getWidth() / 2.0 + radius * Math.sin(-angle * Math.PI / 180.0 + Math.PI)),
|
||||||
(int) (getHeight() / 2 + radius * Math.cos(-angle * Math.PI / 180 + Math.PI)));
|
(int) (getHeight() / 2.0 + radius * Math.cos(-angle * Math.PI / 180.0 + Math.PI)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -86,9 +86,9 @@ public class DownloadLogFragment extends BottomSheetDialogFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
Object item = adapter.getItem(position);
|
final DownloadResult item = adapter.getItem(position);
|
||||||
if (item instanceof DownloadResult) {
|
if (item != null) {
|
||||||
new DownloadLogDetailsDialog(getContext(), (DownloadResult) item).show();
|
new DownloadLogDetailsDialog(getContext(), item).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ buildscript {
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application' version "$agpVersion" apply false
|
id 'com.android.application' version "$agpVersion" apply false
|
||||||
id 'com.android.library' version "$agpVersion" apply false
|
id 'com.android.library' version "$agpVersion" apply false
|
||||||
id 'com.github.spotbugs' version '4.7.0' apply false
|
id 'com.github.spotbugs' version '4.8.0' apply false
|
||||||
id 'checkstyle'
|
id 'checkstyle'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ gradle.projectsEvaluated {
|
||||||
apply plugin: 'com.github.spotbugs'
|
apply plugin: 'com.github.spotbugs'
|
||||||
|
|
||||||
spotbugs {
|
spotbugs {
|
||||||
|
toolVersion = '4.2.3'
|
||||||
effort = 'max'
|
effort = 'max'
|
||||||
reportLevel = 'medium'
|
reportLevel = 'medium'
|
||||||
excludeFilter = rootProject.file('config/spotbugs/exclude.xml')
|
excludeFilter = rootProject.file('config/spotbugs/exclude.xml')
|
||||||
|
@ -86,23 +87,33 @@ gradle.taskGraph.whenReady { taskGraph ->
|
||||||
taskGraph.allTasks.each { task ->
|
taskGraph.allTasks.each { task ->
|
||||||
if (task.name.toLowerCase().contains('spotbugs')) {
|
if (task.name.toLowerCase().contains('spotbugs')) {
|
||||||
task.doLast {
|
task.doLast {
|
||||||
def reportFile = task.project.file("build/reports/spotbugs/playDebug.xml")
|
def reportFile = task.project.file("build/reports/spotbugs/debug.xml")
|
||||||
if (!reportFile.exists()) return
|
def reportFilePlay = task.project.file("build/reports/spotbugs/playDebug.xml")
|
||||||
def slurped = new groovy.xml.XmlSlurper().parse(reportFile)
|
|
||||||
|
|
||||||
def foundErrors = false
|
if (reportFile.exists()) {
|
||||||
slurped['BugInstance'].each { bug ->
|
parseSpotBugsXml(task, reportFile)
|
||||||
logger.error "[SpotBugs] ${bug['LongMessage']} [${bug.@'type'}]"
|
|
||||||
bug['SourceLine'].each { line ->
|
|
||||||
logger.error "[SpotBugs] ${line['Message']}"
|
|
||||||
foundErrors = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (foundErrors) {
|
if (reportFilePlay.exists()) {
|
||||||
throw new TaskExecutionException(task,
|
parseSpotBugsXml(task, reportFilePlay)
|
||||||
new Exception("SpotBugs violations were found. See output above for details."))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def parseSpotBugsXml(task, xmlFile) {
|
||||||
|
def slurped = new groovy.xml.XmlSlurper().parse(xmlFile)
|
||||||
|
|
||||||
|
def foundErrors = false
|
||||||
|
slurped['BugInstance'].each { bug ->
|
||||||
|
logger.error "[SpotBugs] ${bug['LongMessage']} [${bug.@'type'}]"
|
||||||
|
bug['SourceLine'].each { line ->
|
||||||
|
logger.error "[SpotBugs] ${line['Message']}"
|
||||||
|
foundErrors = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (foundErrors) {
|
||||||
|
throw new TaskExecutionException(task,
|
||||||
|
new Exception("SpotBugs violations were found. See output above for details."))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,14 +8,30 @@
|
||||||
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE"/>
|
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE"/>
|
||||||
<Class name="de.danoeh.antennapod.net.ssl.NoV1SslSocketFactory"/>
|
<Class name="de.danoeh.antennapod.net.ssl.NoV1SslSocketFactory"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="DLS_DEAD_LOCAL_STORE"/>
|
||||||
|
<Class name="de.danoeh.antennapod.ui.statistics.StatisticsFragment"/>
|
||||||
|
</Match>
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="DM_DEFAULT_ENCODING"/>
|
<Bug pattern="DM_DEFAULT_ENCODING"/>
|
||||||
<Class name="de.danoeh.antennapod.parser.media.vorbis.VorbisCommentReader"/>
|
<Class name="de.danoeh.antennapod.parser.media.vorbis.VorbisCommentReader"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS"/>
|
||||||
|
<Class name="de.danoeh.antennapod.model.feed.FeedMedia"/>
|
||||||
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS"/>
|
||||||
|
<Class name="de.danoeh.antennapod.model.playback.RemoteMedia"/>
|
||||||
|
</Match>
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="HSC_HUGE_SHARED_STRING_CONSTANT"/>
|
<Bug pattern="HSC_HUGE_SHARED_STRING_CONSTANT"/>
|
||||||
<Class name="de.danoeh.antennapod.net.ssl.BackportCaCerts"/>
|
<Class name="de.danoeh.antennapod.net.ssl.BackportCaCerts"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="ICAST_IDIV_CAST_TO_DOUBLE"/>
|
||||||
|
<Class name="de.danoeh.antennapod.ui.echo.screens.RotatingSquaresScreen"/>
|
||||||
|
</Match>
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="MS_CANNOT_BE_FINAL"/>
|
<Bug pattern="MS_CANNOT_BE_FINAL"/>
|
||||||
<Class name="de.danoeh.antennapod.core.service.playback.PlaybackService"/>
|
<Class name="de.danoeh.antennapod.core.service.playback.PlaybackService"/>
|
||||||
|
@ -44,6 +60,10 @@
|
||||||
<Bug pattern="NP_NULL_PARAM_DEREF"/>
|
<Bug pattern="NP_NULL_PARAM_DEREF"/>
|
||||||
<Class name="de.danoeh.antennapod.model.feed.FeedMedia"/>
|
<Class name="de.danoeh.antennapod.model.feed.FeedMedia"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
|
||||||
|
<Class name="de.danoeh.antennapod.core.service.download.DownloadRequestCreator"/>
|
||||||
|
</Match>
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
|
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
|
||||||
<Class name="de.danoeh.antennapod.preferences.PreferenceUpgrader"/>
|
<Class name="de.danoeh.antennapod.preferences.PreferenceUpgrader"/>
|
||||||
|
@ -64,6 +84,22 @@
|
||||||
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
|
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
|
||||||
<Class name="de.danoeh.antennapod.core.service.playback.PlaybackService"/>
|
<Class name="de.danoeh.antennapod.core.service.playback.PlaybackService"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
|
||||||
|
<Class name="de.danoeh.antennapod.ui.home.sections.EpisodesSurpriseSection"/>
|
||||||
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="URF_UNREAD_FIELD"/>
|
||||||
|
<Class name="de.danoeh.antennapod.ui.common.TriangleLabelView$PaintHolder"/>
|
||||||
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"/>
|
||||||
|
<Class name="de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer"/>
|
||||||
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"/>
|
||||||
|
<Class name="de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer$PSMPInfo"/>
|
||||||
|
</Match>
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"/>
|
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"/>
|
||||||
<Class name="de.danoeh.antennapod.core.storage.NavDrawerData$TagDrawerItem"/>
|
<Class name="de.danoeh.antennapod.core.storage.NavDrawerData$TagDrawerItem"/>
|
||||||
|
@ -77,10 +113,16 @@
|
||||||
|
|
||||||
<Match><Package name="de.danoeh.antennapod.core.glide"/></Match>
|
<Match><Package name="de.danoeh.antennapod.core.glide"/></Match>
|
||||||
<Match><Package name="de.danoeh.antennapod.databinding"/></Match>
|
<Match><Package name="de.danoeh.antennapod.databinding"/></Match>
|
||||||
|
<Match><Package name="de.danoeh.antennapod.core.databinding"/></Match>
|
||||||
|
<Match><Package name="de.danoeh.antennapod.ui.common.databinding"/></Match>
|
||||||
|
<Match><Package name="de.danoeh.antennapod.ui.echo.databinding"/></Match>
|
||||||
|
<Match><Package name="de.danoeh.antennapod.ui.statistics.databinding"/></Match>
|
||||||
|
|
||||||
|
<Match><Bug pattern="DMI_RANDOM_USED_ONLY_ONCE"/></Match>
|
||||||
<Match><Bug pattern="EI_EXPOSE_REP"/></Match>
|
<Match><Bug pattern="EI_EXPOSE_REP"/></Match>
|
||||||
<Match><Bug pattern="EI_EXPOSE_REP2"/></Match>
|
<Match><Bug pattern="EI_EXPOSE_REP2"/></Match>
|
||||||
<Match><Bug pattern="HE_EQUALS_NO_HASHCODE"/></Match>
|
<Match><Bug pattern="HE_EQUALS_NO_HASHCODE"/></Match>
|
||||||
|
<Match><Bug pattern="HE_EQUALS_USE_HASHCODE"/></Match>
|
||||||
<Match><Bug pattern="ICAST_INTEGER_MULTIPLY_CAST_TO_LONG"/></Match>
|
<Match><Bug pattern="ICAST_INTEGER_MULTIPLY_CAST_TO_LONG"/></Match>
|
||||||
<Match><Bug pattern="IS2_INCONSISTENT_SYNC"/></Match>
|
<Match><Bug pattern="IS2_INCONSISTENT_SYNC"/></Match>
|
||||||
<Match><Bug pattern="NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION"/></Match>
|
<Match><Bug pattern="NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION"/></Match>
|
||||||
|
@ -96,6 +138,8 @@
|
||||||
<Match><Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED"/></Match>
|
<Match><Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED"/></Match>
|
||||||
<Match><Bug pattern="SF_SWITCH_NO_DEFAULT"/></Match>
|
<Match><Bug pattern="SF_SWITCH_NO_DEFAULT"/></Match>
|
||||||
<Match><Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON"/></Match>
|
<Match><Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON"/></Match>
|
||||||
|
<Match><Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/></Match>
|
||||||
<Match><Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/></Match>
|
<Match><Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/></Match>
|
||||||
|
<Match><Bug pattern="VA_FORMAT_STRING_USES_NEWLINE"/></Match>
|
||||||
<Match><Bug pattern="WMI_WRONG_MAP_ITERATOR"/></Match>
|
<Match><Bug pattern="WMI_WRONG_MAP_ITERATOR"/></Match>
|
||||||
</FindBugsFilter>
|
</FindBugsFilter>
|
||||||
|
|
|
@ -90,17 +90,18 @@ public class OpmlBackupAgent extends BackupAgentHelper {
|
||||||
|
|
||||||
// Get the old checksum
|
// Get the old checksum
|
||||||
if (oldState != null) {
|
if (oldState != null) {
|
||||||
FileInputStream inState = new FileInputStream(oldState.getFileDescriptor());
|
try (final FileInputStream inState = new FileInputStream(oldState.getFileDescriptor())) {
|
||||||
int len = inState.read();
|
int len = inState.read();
|
||||||
|
|
||||||
if (len != -1) {
|
if (len != -1) {
|
||||||
byte[] oldChecksum = new byte[len];
|
byte[] oldChecksum = new byte[len];
|
||||||
IOUtils.read(inState, oldChecksum, 0, len);
|
IOUtils.read(inState, oldChecksum, 0, len);
|
||||||
Log.d(TAG, "Old checksum: " + new BigInteger(1, oldChecksum).toString(16));
|
Log.d(TAG, "Old checksum: " + new BigInteger(1, oldChecksum).toString(16));
|
||||||
|
|
||||||
if (Arrays.equals(oldChecksum, newChecksum)) {
|
if (Arrays.equals(oldChecksum, newChecksum)) {
|
||||||
Log.d(TAG, "Checksums are the same; won't backup");
|
Log.d(TAG, "Checksums are the same; won't backup");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -736,9 +736,33 @@ public final class DBReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MonthlyStatisticsItem {
|
public static class MonthlyStatisticsItem {
|
||||||
public int year = 0;
|
private int year = 0;
|
||||||
public int month = 0;
|
private int month = 0;
|
||||||
public long timePlayed = 0;
|
private long timePlayed = 0;
|
||||||
|
|
||||||
|
public int getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(final int year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMonth() {
|
||||||
|
return month;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMonth(final int month) {
|
||||||
|
this.month = month;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimePlayed() {
|
||||||
|
return timePlayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimePlayed(final long timePlayed) {
|
||||||
|
this.timePlayed = timePlayed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -752,9 +776,9 @@ public final class DBReader {
|
||||||
int indexTotalDuration = cursor.getColumnIndexOrThrow("total_duration");
|
int indexTotalDuration = cursor.getColumnIndexOrThrow("total_duration");
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
MonthlyStatisticsItem item = new MonthlyStatisticsItem();
|
MonthlyStatisticsItem item = new MonthlyStatisticsItem();
|
||||||
item.month = Integer.parseInt(cursor.getString(indexMonth));
|
item.setMonth(Integer.parseInt(cursor.getString(indexMonth)));
|
||||||
item.year = Integer.parseInt(cursor.getString(indexYear));
|
item.setYear(Integer.parseInt(cursor.getString(indexYear)));
|
||||||
item.timePlayed = cursor.getLong(indexTotalDuration);
|
item.setTimePlayed(cursor.getLong(indexTotalDuration));
|
||||||
months.add(item);
|
months.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class EchoActivity extends AppCompatActivity {
|
||||||
long secondsPerDay = queueSecondsLeft / daysUntilNextYear;
|
long secondsPerDay = queueSecondsLeft / daysUntilNextYear;
|
||||||
String timePerDay = Converter.getDurationStringLocalized(
|
String timePerDay = Converter.getDurationStringLocalized(
|
||||||
getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000, true);
|
getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000, true);
|
||||||
double hoursPerDay = (double) (secondsPerDay / 3600);
|
double hoursPerDay = secondsPerDay / 3600.0;
|
||||||
int nextYear = RELEASE_YEAR + 1;
|
int nextYear = RELEASE_YEAR + 1;
|
||||||
if (hoursPerDay < 1.5) {
|
if (hoursPerDay < 1.5) {
|
||||||
viewBinding.aboveLabel.setText(R.string.echo_queue_title_clean);
|
viewBinding.aboveLabel.setText(R.string.echo_queue_title_clean);
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class BarChartView extends AppCompatImageView {
|
||||||
drawable.data = data;
|
drawable.data = data;
|
||||||
drawable.maxValue = 1;
|
drawable.maxValue = 1;
|
||||||
for (DBReader.MonthlyStatisticsItem item : data) {
|
for (DBReader.MonthlyStatisticsItem item : data) {
|
||||||
drawable.maxValue = Math.max(drawable.maxValue, item.timePlayed);
|
drawable.maxValue = Math.max(drawable.maxValue, item.getTimePlayed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,21 +89,21 @@ public class BarChartView extends AppCompatImageView {
|
||||||
paintBars.setStrokeWidth(height * 0.015f);
|
paintBars.setStrokeWidth(height * 0.015f);
|
||||||
paintBars.setColor(colors[0]);
|
paintBars.setColor(colors[0]);
|
||||||
int colorIndex = 0;
|
int colorIndex = 0;
|
||||||
int lastYear = data.size() > 0 ? data.get(0).year : 0;
|
int lastYear = data.size() > 0 ? data.get(0).getYear() : 0;
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
float x = textPadding + (i + 1) * stepSize;
|
float x = textPadding + (i + 1) * stepSize;
|
||||||
if (lastYear != data.get(i).year) {
|
if (lastYear != data.get(i).getYear()) {
|
||||||
lastYear = data.get(i).year;
|
lastYear = data.get(i).getYear();
|
||||||
colorIndex++;
|
colorIndex++;
|
||||||
paintBars.setColor(colors[colorIndex % 2]);
|
paintBars.setColor(colors[colorIndex % 2]);
|
||||||
if (i < data.size() - 2) {
|
if (i < data.size() - 2) {
|
||||||
canvas.drawText(String.valueOf(data.get(i).year), x + stepSize,
|
canvas.drawText(String.valueOf(data.get(i).getYear()), x + stepSize,
|
||||||
barHeight + (height - barHeight + textSize) / 2, paintGridText);
|
barHeight + (height - barHeight + textSize) / 2, paintGridText);
|
||||||
}
|
}
|
||||||
canvas.drawLine(x, height, x, barHeight, paintGridText);
|
canvas.drawLine(x, height, x, barHeight, paintGridText);
|
||||||
}
|
}
|
||||||
|
|
||||||
float valuePercentage = (float) Math.max(0.005, (float) data.get(i).timePlayed / maxValue);
|
float valuePercentage = (float) Math.max(0.005, (float) data.get(i).getTimePlayed() / maxValue);
|
||||||
float y = (1 - valuePercentage) * barHeight;
|
float y = (1 - valuePercentage) * barHeight;
|
||||||
canvas.drawRect(x, y, x + stepSize * 0.95f, barHeight, paintBars);
|
canvas.drawRect(x, y, x + stepSize * 0.95f, barHeight, paintBars);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,41 +57,41 @@ public class YearStatisticsListAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
} else {
|
} else {
|
||||||
StatisticsHolder holder = (StatisticsHolder) h;
|
StatisticsHolder holder = (StatisticsHolder) h;
|
||||||
DBReader.MonthlyStatisticsItem statsItem = yearlyAggregate.get(position - 1);
|
DBReader.MonthlyStatisticsItem statsItem = yearlyAggregate.get(position - 1);
|
||||||
holder.year.setText(String.format(Locale.getDefault(), "%d ", statsItem.year));
|
holder.year.setText(String.format(Locale.getDefault(), "%d ", statsItem.getYear()));
|
||||||
holder.hours.setText(String.format(Locale.getDefault(), "%.1f ", statsItem.timePlayed / 3600000.0f)
|
holder.hours.setText(String.format(Locale.getDefault(), "%.1f ", statsItem.getTimePlayed() / 3600000.0f)
|
||||||
+ context.getString(R.string.time_hours));
|
+ context.getString(R.string.time_hours));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(List<DBReader.MonthlyStatisticsItem> statistics) {
|
public void update(List<DBReader.MonthlyStatisticsItem> statistics) {
|
||||||
int lastYear = statistics.size() > 0 ? statistics.get(0).year : 0;
|
int lastYear = statistics.size() > 0 ? statistics.get(0).getYear() : 0;
|
||||||
int lastDataPoint = statistics.size() > 0 ? (statistics.get(0).month - 1) + lastYear * 12 : 0;
|
int lastDataPoint = statistics.size() > 0 ? (statistics.get(0).getMonth() - 1) + lastYear * 12 : 0;
|
||||||
long yearSum = 0;
|
long yearSum = 0;
|
||||||
yearlyAggregate.clear();
|
yearlyAggregate.clear();
|
||||||
statisticsData.clear();
|
statisticsData.clear();
|
||||||
for (DBReader.MonthlyStatisticsItem statistic : statistics) {
|
for (DBReader.MonthlyStatisticsItem statistic : statistics) {
|
||||||
if (statistic.year != lastYear) {
|
if (statistic.getYear() != lastYear) {
|
||||||
DBReader.MonthlyStatisticsItem yearAggregate = new DBReader.MonthlyStatisticsItem();
|
DBReader.MonthlyStatisticsItem yearAggregate = new DBReader.MonthlyStatisticsItem();
|
||||||
yearAggregate.year = lastYear;
|
yearAggregate.setYear(lastYear);
|
||||||
yearAggregate.timePlayed = yearSum;
|
yearAggregate.setTimePlayed(yearSum);
|
||||||
yearlyAggregate.add(yearAggregate);
|
yearlyAggregate.add(yearAggregate);
|
||||||
yearSum = 0;
|
yearSum = 0;
|
||||||
lastYear = statistic.year;
|
lastYear = statistic.getYear();
|
||||||
}
|
}
|
||||||
yearSum += statistic.timePlayed;
|
yearSum += statistic.getTimePlayed();
|
||||||
while (lastDataPoint + 1 < (statistic.month - 1) + statistic.year * 12) {
|
while (lastDataPoint + 1 < (statistic.getMonth() - 1) + statistic.getYear() * 12) {
|
||||||
lastDataPoint++;
|
lastDataPoint++;
|
||||||
DBReader.MonthlyStatisticsItem item = new DBReader.MonthlyStatisticsItem();
|
DBReader.MonthlyStatisticsItem item = new DBReader.MonthlyStatisticsItem();
|
||||||
item.year = lastDataPoint / 12;
|
item.setYear(lastDataPoint / 12);
|
||||||
item.month = lastDataPoint % 12 + 1;
|
item.setMonth(lastDataPoint % 12 + 1);
|
||||||
statisticsData.add(item); // Compensate for months without playback
|
statisticsData.add(item); // Compensate for months without playback
|
||||||
}
|
}
|
||||||
statisticsData.add(statistic);
|
statisticsData.add(statistic);
|
||||||
lastDataPoint = (statistic.month - 1) + statistic.year * 12;
|
lastDataPoint = (statistic.getMonth() - 1) + statistic.getYear() * 12;
|
||||||
}
|
}
|
||||||
DBReader.MonthlyStatisticsItem yearAggregate = new DBReader.MonthlyStatisticsItem();
|
DBReader.MonthlyStatisticsItem yearAggregate = new DBReader.MonthlyStatisticsItem();
|
||||||
yearAggregate.year = lastYear;
|
yearAggregate.setYear(lastYear);
|
||||||
yearAggregate.timePlayed = yearSum;
|
yearAggregate.setTimePlayed(yearSum);
|
||||||
yearlyAggregate.add(yearAggregate);
|
yearlyAggregate.add(yearAggregate);
|
||||||
Collections.reverse(yearlyAggregate);
|
Collections.reverse(yearlyAggregate);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
Loading…
Reference in New Issue