-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added calculation of the project progress on projects list initializa… #1167
Conversation
@@ -199,6 +199,7 @@ private void initializeViews() { | |||
|
|||
hideProjectsIfEmpty(mNumProjects); | |||
if (mNumProjects > 0) { | |||
calculateProjectsProgress(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to put this here; there's already too much work going on to start up this activity that we need to make sure that things that won't change very often don't happen all the time.
progress is only "wrong" when the filesystem and database were out of sync, correct?
Then let's add a resultcode to the resync to return whether or not anything changed, and only on change do we calculate all the project progress.
String projectIdString = String.valueOf(projectId); | ||
SQLiteDatabase db = getReadableDatabase(); | ||
final String query = String.format("SELECT %s FROM %s WHERE %s=?", | ||
ProjectContract.ProjectEntry.PROJECT_PROGRESS, ProjectContract.ProjectEntry.TABLE_PROJECT, ProjectContract.ProjectEntry._ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you have to split arguments onto another line because of length (and this still has line length issues), each parameter goes on its own line like so:
final String query = String.format(
"SELECT %s FROM %s WHERE %s=?",
ProjectContract.ProjectEntry.PROJECT_PROGRESS,
ProjectContract.ProjectEntry.TABLE_PROJECT,
ProjectContract.ProjectEntry._ID
);
SQLiteDatabase db = getReadableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(ProjectContract.ProjectEntry.PROJECT_PROGRESS, progress); | ||
db.update(ProjectContract.ProjectEntry.TABLE_PROJECT, contentValues, whereClause, new String[]{projectIdString}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
@@ -192,13 +195,20 @@ private void prepareUnitCardData() { | |||
List<Chunk> chunks = chunkPlugin.getChapter(mChapterNum).getChunks(); | |||
for (Chunk unit : chunks) { | |||
String title = Utils.capitalizeFirstLetter(mProject.getModeName()) + " " + unit.getLabel(); | |||
mUnitCardList.add(new UnitCard(mAdapter, mProject, title, mChapterNum, unit.getStartVerse(), unit.getEndVerse())); | |||
mUnitCardList.add(new UnitCard(mAdapter, mProject, title, mChapterNum, unit.getStartVerse(), unit.getEndVerse(), this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarabiaj Updated
|
||
public int calculateProjectProgress() { | ||
try { | ||
ChunkPlugin chunks = project.getChunkPlugin(new ChunkPluginLoader(context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not do this in the constructor, and move it to the top as a member variable since most every method here uses it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarabiaj That's a good idea. Updated!
} | ||
} | ||
|
||
public Chapter getChapter(int chapterNumber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this really shouldn't be a public API for a progress use case object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarabiaj Updated!
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.OutputStream; | ||
import java.io.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't import .*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarabiaj yeah, I know... It's just my ide does that, and I didn't pay attention
|
||
// Constructors | ||
public UnitCard(DatabaseAccessor db, Project project, String title, int chapter, int firstVerse, int endVerse) { | ||
public UnitCard(DatabaseAccessor db, Project project, String title, int chapter, int firstVerse, int endVerse, OnTakeDeleteListener listener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
return Math.round(((float) current / total) * 100); | ||
} | ||
|
||
public void destroy() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual resource cleanup is difficult and should probably be considered an antipattern in a garbage collected language especially.
nulling out these objects isn't necessary either, they will get garbage collected when ProjectProgress gets garbage collected when the Activity is flagged for GC.
Fortunately, because of what we discussed about injecting the database, you wouldn't need to worry about closing (or opening) the database in this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarabiaj Yep, I've just removed this method
@@ -34,15 +40,16 @@ | |||
|
|||
Context mCtx; | |||
FragmentManager mFragmentManager; | |||
ProjectDatabaseHelper mDb; | |||
|
|||
public ProjectListResyncTask(int taskId, Context ctx, FragmentManager fm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets Inject the database here too
} | ||
} | ||
|
||
@Override | ||
public void onTakeDeleted() { | ||
ProjectProgress pp = new ProjectProgress(mProject, db, chunkPlugin.getChapters()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be moved to the top; I'd name it projectProgress over pp though since its use will be further from the declaration. (you're in the unit list, so everything is in the same project, this will cut down on a lot of work being done repeatedly)
|
||
public ProjectListResyncTask(int taskId, Context ctx, FragmentManager fm) { | ||
public ProjectListResyncTask(int taskId, Context ctx, FragmentManager fm, ProjectDatabaseHelper db) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you inject the chunkpluginloader, you won't need the context object dependency here
Map<Project, File> directoriesOnFs = getProjectDirectoriesOnFileSystem(); | ||
//if the number of projects doesn't match up between the filesystem and the db, OR, | ||
//the projects themselves don't match an id in the db, then resync everything (only resyncing | ||
// projects missing won't remove dangling take references in the db) | ||
//NOTE: removing a project only removes dangling takes, not the project itself from the db | ||
if (directoriesOnFs.size() != db.getNumProjects() || db.projectsNeedingResync(directoriesOnFs.keySet()).size() > 0) { | ||
fullResync(db, directoriesOnFs); | ||
if (directoriesOnFs.size() != mDb.getNumProjects() || mDb.projectsNeedingResync(directoriesOnFs.keySet()).size() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
if(chunkPlugin != null) { | ||
ProjectProgress pp = new ProjectProgress(mProject, db, chunkPlugin.getChapters()); | ||
pp.updateProjectProgress(); | ||
} | ||
db.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not good to close this if we're going to have one instance for the whole activity
@@ -145,7 +162,11 @@ private void refreshAudioPlayer() { | |||
ap.loadFile(getTakeList().get(mTakeIndex)); | |||
} | |||
} | |||
ap.refreshView(mViewHolder.elapsed, mViewHolder.duration, mViewHolder.takePlayPauseBtn, mViewHolder.seekBar); | |||
ap.refreshView(mViewHolder.elapsed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first parameter goes on a new line like you did on line 135
List<Chunk> chunks = chunkPlugin.getChapter(mChapterNum).getChunks(); | ||
for (Chunk unit : chunks) { | ||
String title = Utils.capitalizeFirstLetter(mProject.getModeName()) + " " + unit.getLabel(); | ||
mUnitCardList.add(new UnitCard(mAdapter, mProject, title, mChapterNum, unit.getStartVerse(), unit.getEndVerse())); | ||
mUnitCardList.add(new UnitCard( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code formatting
|
||
String jarName = "biblechunk.jar"; | ||
String className = "org.wycliffeassociates.translationrecorder.biblechunk.BibleChunkPlugin"; | ||
Anthology anthology = new Anthology("ot", "Old Testament", "bible", regex, groups, mask, jarName, className); | ||
Anthology anthology = new Anthology("ot", "Old Testament", "bible", sort, regex, groups, mask, jarName, className); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
@@ -54,7 +54,8 @@ protected void handleUserInput() { | |||
@Override | |||
public void run() { | |||
Context ctx = mCtx.getActivity().getApplicationContext(); | |||
uploadBinary(ctx, outputFile()); | |||
ProjectDatabaseHelper db = ((TranslationRecorderApp)mCtx.getActivity().getApplication()).getDatabase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't do this; provide it as a dependency
@@ -287,6 +284,8 @@ private void initApp() { | |||
brd.show(fm, "Bug Report Dialog"); | |||
} | |||
|
|||
db = ((TranslationRecorderApp)getApplication()).getDatabase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not related to initializing views; maybe move it to onCreate
@@ -96,6 +96,15 @@ | |||
<service android:name="org.wycliffeassociates.translationrecorder.Recording.WavRecorder" /> | |||
<service android:name="org.wycliffeassociates.translationrecorder.Recording.WavFileWriter" /> | |||
|
|||
<provider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this needed for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarabiaj Since Android api 24, in order for the app to give an access to it's content to other apps, this FileProvider is needed. You can try to share a project on devices with Android 7 and up, it will crash.
https://developer.android.com/training/secure-file-sharing/setup-sharing
AppCompatActivity context, | ||
Project project, | ||
List<ChapterCard> chapterCardList, | ||
ProjectDatabaseHelper db) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put the ) { on a new line
@@ -71,12 +68,12 @@ public View getView(final int position, View convertView, final ViewGroup parent | |||
holder = (ViewHolder) convertView.getTag(); | |||
} | |||
|
|||
initializeProjectCard(mCtx, mProjectList.get(position), mDb, holder.mLanguage, holder.mBook, holder.mInfo, holder.mRecord, holder.mTextLayout, holder.mProgressPie); | |||
initializeProjectCard(mCtx, mProjectList.get(position), db, holder.mLanguage, holder.mBook, holder.mInfo, holder.mRecord, holder.mTextLayout, holder.mProgressPie); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
|
||
return convertView; | ||
} | ||
|
||
public static void initializeProjectCard(final Activity ctx, final Project project, ProjectDatabaseHelper dB, TextView languageView, TextView bookView, | ||
public static void initializeProjectCard(final Activity ctx, final Project project, final ProjectDatabaseHelper dB, TextView languageView, TextView bookView, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
Project project, | ||
int chapter, | ||
List<UnitCard> unitCardList, | ||
ProjectDatabaseHelper db) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline for ) {
@@ -23,13 +22,13 @@ | |||
* Created by sarabiaj on 9/27/2016. | |||
*/ | |||
public class DatabaseResyncTask extends Task implements ProjectDatabaseHelper.OnLanguageNotFound, ProjectDatabaseHelper.OnCorruptFile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
mode = db.getMode(db.getModeId( | ||
wav.getMetadata().getModeSlug(), | ||
wav.getMetadata().getAnthology() | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code formatting
fullResync(db, directoriesOnFs); | ||
if (directoriesOnFs.size() != db.getNumProjects() || db.projectsNeedingResync( | ||
directoriesOnFs.keySet() | ||
).size() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you're meaning to break apart the method call in projects needing resync, but you want to make sure that it lines up vertically when you do that, especially with its beginning and the close parenthesis
if (
directoriesOnFs.size() != db.getNumProjects()
|| db.projectsNeedingResync(directoriesOnFs.keySet()).size() > 0
) {
is probably what you would do here? but realistically, you'd rather assign variables
boolean projectCountDiffers = directoriesOnFs.size != db.getNumProjects;
boolean projectsNeedResync = db.projectsNeedingResync(directoriesOnFs.keySet()).size > 0
if(projectCountDiffers || projectsNeedResync) {
added benefit here is the if statement is more readable as to its intent
books.toArray(new Book[books.size()]), | ||
versions.toArray(new Version[versions.size()]), | ||
modes.toArray(new Mode[modes.size()]), | ||
db); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); on new line
…tion