Skip to content

Commit

Permalink
Implement #280
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandaka committed Sep 17, 2018
1 parent b2e7865 commit b49ec42
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/erakk/lnreader/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,5 @@ public class Constants {
public static final String EXTRA_INITIAL_FRAGMENT = "initialFragment";
public static final String PREF_RESET_ZOOM = "reset_zoom";
public static final int URL_LENGTH_LIMIT = 500;
public static final String PREF_LOAD_COVER = "load_cover";
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/erakk/lnreader/UIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ public static boolean isAlphabeticalOrder(Context ctx) {
return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean(Constants.PREF_ALPH_ORDER, false);
}

public static boolean isLoadCover(Context ctx) {
return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean(Constants.PREF_LOAD_COVER, true);
}

public static String getBackgroundColor(Context ctx) {
return PreferenceManager.getDefaultSharedPreferences(ctx).getString(Constants.PREF_CSS_BACKGROUND, "#000000");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,31 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
});
}

holder.ivNovelCover.setImageResource(R.drawable.dummy_1);
holder.txtStatusVol.setText("N/A");
// Set volume and status
String txtVolume = novel.getVolumes() + " Volume" + (novel.getVolumes() > 1 ? "s" : "");
String txtCategories = "";
for (String category : novel.getCategories()) {
if (category.contains("Project")) {
txtCategories = " | " + category.substring(0, category.indexOf("Project")).replace("Category:", "");
break;
}
}
holder.txtStatusVol.setText(txtVolume + txtCategories);

// cover related
holder.ivNovelCover.setImageResource(R.drawable.dummy_1);
holder.ivNovelCover.setVisibility(View.GONE);
holder.imgprogressBar.setVisibility(View.VISIBLE);

holder.position = position;

if(false) {
if(UIHelper.isLoadCover(getContext())) {
if (novels.get(novel.getTitle()) == null) {
new NovelLoader(position, holder).execute(novel);
} else {
populate(novels.get(novel.getTitle()), holder);
}
}
else {
String txtVolume = novel.getVolumes() + " Volume" + (novel.getVolumes() > 1 ? "s" : "");
String txtCategories = "";
for (String category : novel.getCategories()) {
if (category.contains("Project")) {
txtCategories = " | " + category.substring(0, category.indexOf("Project")).replace("Category:", "");
break;
}
}
holder.txtStatusVol.setText(txtVolume + txtCategories);
holder.imgprogressBar.setVisibility(View.INVISIBLE);
}

Expand Down Expand Up @@ -203,12 +203,12 @@ public void setResourceId(int id) {
}

private void populate(NovelCollectionModel novelCollectionModel, NovelCollectionHolder holder) {
PageModel novelpage = null;
try {
novelpage = novelCollectionModel.getPageModel();
} catch (Exception e) {
e.printStackTrace();
}
// PageModel novelpage = null;
// try {
// novelpage = novelCollectionModel.getPageModel();
// } catch (Exception e) {
// Log.e(TAG, e.getMessage(), e);
// }
if (holder.ivNovelCover != null) {
holder.ivNovelCover.setVisibility(View.VISIBLE);
holder.imgprogressBar.setVisibility(View.GONE);
Expand All @@ -218,31 +218,31 @@ private void populate(NovelCollectionModel novelCollectionModel, NovelCollection
holder.ivNovelCover.setImageResource(R.drawable.dummy_2);
}
}

if (holder.txtStatusVol != null) {
if (novelpage == null) {
holder.txtStatusVol.setText("N/A");
} else {
String category = getCategory(novelpage);
int volumes = novelCollectionModel.getBookCollections().size();
if (category.isEmpty()) {
holder.txtStatusVol.setText(volumes + " Volume" + (volumes > 1 ? "s" : ""));
} else {
holder.txtStatusVol.setText(category + " | " + volumes + " Volume" + (volumes > 1 ? "s" : ""));
}
}
}
// moved to query
// if (holder.txtStatusVol != null) {
// if (novelpage == null) {
// holder.txtStatusVol.setText("N/A");
// } else {
// String category = getCategory(novelpage);
// int volumes = novelCollectionModel.getBookCollections().size();
// if (category.isEmpty()) {
// holder.txtStatusVol.setText(volumes + " Volume" + (volumes > 1 ? "s" : ""));
// } else {
// holder.txtStatusVol.setText(category + " | " + volumes + " Volume" + (volumes > 1 ? "s" : ""));
// }
// }
// }
}

private String getCategory(PageModel novelpage) {
ArrayList<String> categories = novelpage.getCategories();
for (String category : categories) {
if (category.contains("Project")) {
return category.substring(0, category.indexOf("Project")).replace("Category:", "");
}
}
return "";
}
// private String getCategory(PageModel novelpage) {
// ArrayList<String> categories = novelpage.getCategories();
// for (String category : categories) {
// if (category.contains("Project")) {
// return category.substring(0, category.indexOf("Project")).replace("Category:", "");
// }
// }
// return "";
// }

private class NovelLoader extends AsyncTask<PageModel, Void, NovelCollectionModel> {
int position;
Expand All @@ -260,7 +260,7 @@ protected NovelCollectionModel doInBackground(PageModel... pageModels) {
p = pageModels[0];
return NovelsDao.getInstance().getNovelDetails(p, null, false);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, e.getMessage(), e);
}
return null;
}
Expand All @@ -274,6 +274,4 @@ protected void onPostExecute(NovelCollectionModel novelCollectionModel) {
}
}
}


}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,6 @@
<string name="reset_zoom_title">Reset Zoom Level</string>
<string name="reset_zoom_summary">Reset the zoom level to default value based on screen density.</string>
<string name="css_use_custom_colors_summary">May need to reload the chapter.</string>
<string name="load_cover_summary">Disable for faster loading in the novel list. Might need to reload the activity.</string>
<string name="load_cover_title">Load Cover</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
android:key="invert_colors"
android:summary="@string/invert_color_summary"
android:title="@string/invert_color_title" />
<CheckBoxPreference
android:defaultValue="true"
android:key="load_cover"
android:summary="@string/load_cover_summary"
android:title="@string/load_cover_title" />
<ListPreference
android:defaultValue="0"
android:entries="@array/orientationSelection"
Expand Down

0 comments on commit b49ec42

Please sign in to comment.