Skip to content

Commit

Permalink
Percentage of completion for checklists (closes federicoiosue#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Jul 17, 2020
1 parent a380929 commit 309f0fa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,25 @@ protected void onCreate (Bundle savedInstanceState) {

private void populateViews (Note note) {
StatsSingleNote infos = NotesHelper.getNoteInfos(note);

populateView(category, infos.getCategoryName());
populateView(tags, infos.getTags());
populateView(chars, infos.getChars());
populateView(words, infos.getWords());
populateView(checklistItems, infos.getChecklistItemsNumber());
populateView(checklistCompletedItems, infos.getChecklistCompletedItemsNumber());
populateView(checklistCompletedItems, getChecklistCompletionState(infos));
populateView(images, infos.getImages());
populateView(videos, infos.getVideos());
populateView(audioRecordings, infos.getAudioRecordings());
populateView(sketches, infos.getSketches());
populateView(files, infos.getFiles());
}

static String getChecklistCompletionState (StatsSingleNote infos) {
int percentage = Math.round((float) infos.getChecklistCompletedItemsNumber() / infos.getChecklistItemsNumber() * 100);
return infos.getChecklistCompletedItemsNumber() + " (" + percentage + "%)";
}

private void populateView (TextView textView, int numberValue) {
String stringValue = numberValue > 0 ? String.valueOf(numberValue) : "";
populateView(textView, stringValue);
Expand Down
1 change: 1 addition & 0 deletions omniNotes/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<changelogtext>[i]Improved![/i] New date pickers for reminders</changelogtext>
<changelogtext>[i]Improved![/i] Simplified merging notes: confirmation is no more required</changelogtext>
<changelogtext>[i]Improved![/i] Changed position of sharing action in menu to make it faster to be reached</changelogtext>
<changelogtext>[i]Improved![/i] Percentage of completion for checklists into note informations dialog</changelogtext>
<changelogtext>[i]Improved![/i] Removed legacy option to customize text size</changelogtext>
<changelogtext>[i]Improved![/i] Updated languages</changelogtext>
</changelogversion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2013-2020 Federico Iosue ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package it.feio.android.omninotes;

import static org.junit.Assert.*;

import it.feio.android.omninotes.models.StatsSingleNote;
import org.junit.Test;

public class NoteInfosActivityTest {

@Test
public void getChecklistCompletionState () {
StatsSingleNote infos = new StatsSingleNote();
infos.setChecklistItemsNumber(42);
infos.setChecklistCompletedItemsNumber(12);

String completionState = NoteInfosActivity.getChecklistCompletionState(infos);

assertTrue(completionState.contains(infos.getChecklistCompletedItemsNumber() + ""));
assertTrue(completionState.contains("29%"));
}
}

0 comments on commit 309f0fa

Please sign in to comment.