Skip to content

Commit

Permalink
5.9: Date of when episode was marked as seen is shown next to checkmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ltGuillaume authored and ltGuillaume committed Oct 3, 2015
1 parent e620fee commit bf6033b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 21 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="nl.asymmetrics.droidshows"
android:versionCode="58" android:versionName="5.8">
android:versionCode="59" android:versionName="5.9">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="11"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ __Shows Overview__:
__Seasons/Episodes list__:
\+ Showing "[aired] of [season episodes]"
\+ Aired date in episodes list
\+ Date of when episode was marked as seen is shown next to checkmark
\+ Click on episode title for details, on checkmark to change seen state
\* Big performance improvement for entirely rewritten Seasons activity: is now almost instant

Expand All @@ -59,7 +60,6 @@ __Update__:
\* Prevent double episodes

__Other__:
\+ [Clean database] in About to remove double episodes post hoc
\+ Menu (overflow) button should show up in Android 3.0+
\+ Dutch translation
\+ Translucent background
Expand Down
4 changes: 2 additions & 2 deletions res/layout/row_serie_episodes.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:padding="6dp">
<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:paddingTop="6dp" android:paddingBottom="6dp" android:paddingLeft="6dp" android:paddingRight="0dp">
<TextView android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="16sp" android:textStyle="bold" android:ellipsize="marquee" android:maxLines="1" android:singleLine="true"/>
<TextView android:id="@+id/aired" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
<CheckBox android:id="@+id/seen" android:layout_width="wrap_content" android:layout_height="fill_parent" android:focusable="false" android:focusableInTouchMode="false" android:padding="6dp" android:onClick="check"/>
<CheckBox android:id="@+id/seen" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingTop="6dp" android:paddingBottom="6dp" android:paddingLeft="0dp" android:paddingRight="6dp" android:textSize="12sp" android:button="@null" android:drawableRight="?android:attr/listChoiceIndicatorMultiple" android:focusable="false" android:focusableInTouchMode="false" android:onClick="check"/>
</LinearLayout>
30 changes: 25 additions & 5 deletions src/nl/asymmetrics/droidshows/ui/SerieEpisodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import nl.asymmetrics.droidshows.DroidShows;
Expand Down Expand Up @@ -37,6 +38,9 @@ public class SerieEpisodes extends ListActivity {
private List<String> episodes = null;
private ListView listView;
private SwipeDetect swipeDetect = new SwipeDetect();
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private SimpleDateFormat sdfseen = new SimpleDateFormat("yyyyMMdd");
private Format formatter = SimpleDateFormat.getDateInstance();

/* Context Menus */
private static final int VIEWEP_CONTEXT = Menu.FIRST;
Expand Down Expand Up @@ -87,7 +91,7 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
if (swipeDetect.value == 0) {
if (DroidShows.fullLineCheckOption) {
try {
DroidShows.db.updateUnwatchedEpisode(serieId, episodes.get(position));
check(v);
CheckBox c = (CheckBox) v.findViewById(R.id.seen);
c.setChecked(!c.isChecked());
} catch (Exception e) {
Expand Down Expand Up @@ -144,9 +148,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {

String aired = c.getString(airedCol);
if (!aired.equals("") && !aired.equals("null")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Format formatter = SimpleDateFormat.getDateInstance();
aired = formatter.format(sdf.parse(aired));
} catch (ParseException e) {
Log.e(DroidShows.TAG, e.getMessage());
Expand All @@ -164,8 +166,19 @@ public View getView(final int position, View convertView, ViewGroup parent) {
holder.name.setText(tmpName);
holder.aired.setText(tmpAired);
}

holder.seen.setChecked(c.getInt(seenCol) == 1);

int seen = c.getInt(seenCol);
holder.seen.setChecked(seen > 0);
if (seen > 1) {
try {
holder.seen.setTextColor(holder.aired.getTextColors().getDefaultColor());
holder.seen.setText(formatter.format(sdfseen.parse(seen +"")));
} catch (ParseException e) {
Log.e(DroidShows.TAG, e.getMessage());
}
} else {
holder.seen.setText("");
}
}
c.close();
return convertView;
Expand All @@ -182,6 +195,13 @@ public void check(View v) {
int position = getListView().getPositionForView(v);
try {
DroidShows.db.updateUnwatchedEpisode(serieId, episodes.get(position));
CheckBox c = (CheckBox) v.findViewById(R.id.seen);
if (c.isChecked()) {
c.setTextColor(getResources().getColor(android.R.color.white));
c.setText(formatter.format(new Date()));
} else {
c.setText("");
}
} catch (Exception e) {
Log.e(DroidShows.TAG, e.getMessage());
}
Expand Down
46 changes: 34 additions & 12 deletions src/nl/asymmetrics/droidshows/utils/SQLiteStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,23 @@ public List<String> getEpisodes(String serieId, int seasonNumber) {
return episodes;
}

private List<String> getSeen(String serieId, int max_season) {
List<String> episodesSeen = new ArrayList<String>();
Cursor c = Query("SELECT seasonNumber, episodeNumber FROM episodes WHERE serieId='"+ serieId +"'"
private List<EpisodeSeen> getSeen(String serieId, int max_season) {
List<EpisodeSeen> episodesSeen = new ArrayList<EpisodeSeen>();
Cursor c = Query("SELECT seasonNumber, episodeNumber, seen FROM episodes WHERE serieId='"+ serieId +"'"
+ (max_season != -1 ? " AND (seasonNumber="+ max_season +" OR seasonNumber=0)": "")
+" AND seen=1");
+" AND seen>0");
try {
c.moveToFirst();
if (c != null && c.isFirst()) {
do {
episodesSeen.add(c.getInt(0) +"x"+ c.getInt(1));
episodesSeen.add(new EpisodeSeen(c.getInt(0) +"x"+ c.getInt(1), c.getInt(2)));
} while (c.moveToNext());
}
c.close();
} catch (SQLiteException e) {
c.close();
Log.e(DroidShows.TAG, e.getMessage());
}
Log.d(DroidShows.TAG, episodesSeen.toString());
return episodesSeen;
}

Expand Down Expand Up @@ -505,7 +504,9 @@ public int getSeasonEpisodeCount(String serieId, int sNumber) {
public void updateUnwatchedSeason(String serieId, int nseason) {
try {
String today = dateFormat.format(new Date()); // Get today's date
db.execSQL("UPDATE episodes SET seen=1 WHERE serieId='"+ serieId +"' AND seasonNumber="+ nseason
Date date = new Date();
int seen = 10000 * (1900 + date.getYear()) + 100 * (date.getMonth() + 1) + date.getDate();
db.execSQL("UPDATE episodes SET seen="+ seen +" WHERE serieId='"+ serieId +"' AND seasonNumber="+ nseason
+" AND firstAired < '"+ today +"' AND firstAired <> ''");
} catch (SQLiteException e) {
Log.e(DroidShows.TAG, e.getMessage());
Expand Down Expand Up @@ -535,7 +536,12 @@ public String updateUnwatchedEpisode(String serieId, String episodeId) {
int episode = c.getInt(2);
episodeMarked = season +"x"+ (episode < 10 ? "0" : "") + episode;
c.close();
seen ^= 1;
if (seen > 0)
seen = 0;
else {
Date date = new Date();
seen = 10000 * (1900 + date.getYear()) + 100 * (date.getMonth() + 1) + date.getDate();
}
db.execSQL("UPDATE episodes SET seen="+ seen +" WHERE serieId='"+ serieId +"' AND id='"+ episodeId +"'");
}
} catch (SQLiteException e) {
Expand Down Expand Up @@ -658,7 +664,7 @@ public void updateSerie(Serie s, boolean last_season) {
db.execSQL("DELETE FROM writers WHERE serieId='"+ s.getId() +"'");
}

List<String> seen = getSeen(s.getId(), max_season);
List<EpisodeSeen> seenEpisodes = getSeen(s.getId(), max_season);
db.execSQL("DELETE FROM episodes WHERE serieId='"+ s.getId() +"'"
+(max_season != -1 ? " AND (seasonNumber="+ max_season +" OR seasonNumber=0)" : ""));

Expand Down Expand Up @@ -698,9 +704,15 @@ public void updateSerie(Serie s, boolean last_season) {
}
}

int iseen = (seen.contains(s.getEpisodes().get(e).getSeasonNumber()
+"x"+ s.getEpisodes().get(e).getEpisodeNumber()) ? 1 : 0);

int iseen = 0;
String epCode = s.getEpisodes().get(e).getSeasonNumber() +"x"+ s.getEpisodes().get(e).getEpisodeNumber();
for (EpisodeSeen es : seenEpisodes) {
if (epCode.equals(es.episode)) {
iseen = es.seen;
break;
}
}

if (!tmpName.equals("")) {
execQuery("INSERT INTO episodes (serieId, id, combinedEpisodeNumber, combinedSeason, "
+"dvdChapter, dvdDiscId, dvdEpisodeNumber, dvdSeason, epImgFlag, episodeName, "
Expand Down Expand Up @@ -867,4 +879,14 @@ public void updateShowStats(String serieId) {
}
execQuery("UPDATE series SET seasonCount="+ seasonCount +", unwatchedAired="+ unwatchedAired +", unwatched="+ unwatched +", nextEpisode='"+ nextEpisode +"', nextAir='"+ nextAir +"' WHERE id="+ serieId);
}

private class EpisodeSeen {
public String episode;
public int seen;

public EpisodeSeen(String episodeValue, int seenValue) {
episode = episodeValue;
seen = seenValue;
}
}
}

0 comments on commit bf6033b

Please sign in to comment.