Commit 379d6b7f by Thomas Krex

-added separators in the List of the feed items

- added date string to FeedItem object
-added helper Method to transform String to Date
parent 99575cea
......@@ -40,7 +40,7 @@
<intent-filter>
<data android:scheme="http" />
<data android:host="ttt.in.tum.de" />
<data android:pathPattern="\\/lectures\\/.*"/>
<data android:pathPattern="\\/lectures\\/rss\\.php.*"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="5" >
android:layout_height="60dp">
<LinearLayout
android:id="@+id/headerLayout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
<TextView
android:id="@+id/listHeader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="@android:color/darker_gray"
android:text="TEST"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<TextView
android:id="@+id/itemTitle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/statusIcon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:src="@drawable/ic_action_download" >
</ImageView>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -198,8 +198,11 @@ public class FeedActivity extends SherlockActivity implements
// delete all whitespaces from url before inserting into the
// database
url.replaceAll("\\s+", "");
String beginDate = "&begindate="+datePicker.getYear()+"_"+"0"+(datePicker.getMonth()+1)+"_"+"0"+datePicker.getDayOfMonth();
int month= datePicker.getMonth()+1;
int day= datePicker.getDayOfMonth();
String beginDate = "&begindate="+datePicker.getYear()+"_"+(month <10 ? "0" :"")+month+"_"+(day<10 ? "0" :"" )+day;
url=url +beginDate;
Log.d("FEED URL", url);
......
......@@ -2,7 +2,9 @@ package tttclient.activities;
import java.io.File;
import java.io.IOException;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Date;
import org.apache.commons.io.FileUtils;
......@@ -11,6 +13,7 @@ import tttclient.models.FeedItem;
import tttclient.models.FeedItemDbManager;
import tttclient.services.DownloadService;
import tttclient.services.ParseService;
import tttclient.utils.Utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
......@@ -27,12 +30,15 @@ import android.os.Handler;
import android.os.ResultReceiver;
import android.os.Vibrator;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
......@@ -144,7 +150,7 @@ public class FeedDetailActivity extends SherlockActivity implements
setContentView(R.layout.feed_details_activity);
// haptic feedback for longclick
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
// init progress dialog for showing downloading/unzipping progress
progressDialog = new ProgressDialog(FeedDetailActivity.this);
progressDialog.setIndeterminate(true);
......@@ -164,19 +170,48 @@ public class FeedDetailActivity extends SherlockActivity implements
feedItemLv.setEmptyView(findViewById(R.id.empty));
// displaying items in listview
manager = new FeedItemDbManager(this);
Cursor cursor = manager.getAllFromDB(feed.getId());
adapter = new SimpleCursorAdapter(this, R.layout.list_feeditems,
cursor, new String[] { FeedItemDbManager.COLUMN_TITLE,
FeedItemDbManager.COLUMN_STATUS }, new int[] {
R.id.itemTitle, R.id.statusIcon });
FeedItemDbManager.COLUMN_STATUS ,FeedItemDbManager.COLUMN_DATE}, new int[] {
R.id.itemTitle, R.id.statusIcon,R.id.listHeader });
// set Binder to change icon depending on download status
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor,
int columnIndex) {
boolean state=false;
// Log.d("FeedItems", "Month: " +currDate.getMonth());
if(view.getId()==R.id.listHeader){
Log.d("VIew Binder", "found header view");
TextView tx = (TextView) view;
Date currDate= Utils.stringToDate(cursor.getString(cursor.getColumnIndex(FeedItemDbManager.COLUMN_DATE)));
Date prevDate= null;
Log.d("ListView"," currDate: "+ currDate.toString());
if (cursor.getPosition() > 0 && cursor.moveToPrevious()) {
prevDate = Utils.stringToDate(cursor.getString(cursor.getColumnIndex(FeedItemDbManager.COLUMN_DATE)));
Log.d("ListView"," prevDate: "+ prevDate.toString());
cursor.moveToNext();
}
if(prevDate==null||prevDate.getMonth()!=currDate.getMonth()){
tx.setText(new DateFormatSymbols().getMonths()[currDate.getMonth()]);
tx.setVisibility(View.VISIBLE);
}
else{
tx.setVisibility(View.GONE);
}
state=true;
}
if (view.getId() == R.id.statusIcon) {
ImageView icon = (ImageView) view;
int status = cursor.getInt(cursor
......@@ -191,12 +226,11 @@ public class FeedDetailActivity extends SherlockActivity implements
(R.drawable.ic_action_download)));
}
return true;
state=true;
}
return false;
return state;
}
});
feedItemLv.setAdapter(adapter);
......
......@@ -116,6 +116,7 @@ public class PlayerActivity extends SherlockActivity implements
@Override
public void onClick(View v) {
recording.previous();
audioController.show(5000);
}
};
......@@ -124,6 +125,7 @@ public class PlayerActivity extends SherlockActivity implements
@Override
public void onClick(View v) {
recording.next();
audioController.show(5000);
}
};
......@@ -132,6 +134,7 @@ public class PlayerActivity extends SherlockActivity implements
prevListener);
audioController.setAnchorView(imgV);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -145,7 +148,7 @@ public class PlayerActivity extends SherlockActivity implements
// close dialog
dialog.dismiss();
// show control bar
audioController.show(5000);
audioController.show(8000);
}
};
......@@ -163,7 +166,7 @@ public class PlayerActivity extends SherlockActivity implements
@Override
public boolean onTouchEvent(MotionEvent event) {
if (audioController != null)
audioController.show();
audioController.show(8000);
return true;
}
......@@ -327,10 +330,10 @@ public class PlayerActivity extends SherlockActivity implements
}
}
void switchLayout(int index) {
void switchLayout(int mode) {
// switch to fullscreen
if (index == LAYOUT_MODE_FULL) {
if (mode == LAYOUT_MODE_FULL) {
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().updateView(true);
......@@ -338,12 +341,13 @@ public class PlayerActivity extends SherlockActivity implements
}
// switch to extended View
if (index == LAYOUT_MODE_EXTENDED) {
if (mode == LAYOUT_MODE_EXTENDED) {
imgV = (ImageView) findViewById(R.id.playerView_extended);
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().updateView(true);
switcher.setDisplayedChild(LAYOUT_MODE_EXTENDED);
scrollView.scrollTo(0, recording.getIndex().scrollPos);
}
......
......@@ -39,6 +39,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
......@@ -72,7 +73,7 @@ public class Index {
private final Context context;
private final ScrollView indexViewer;
private final Handler scrollHandler;
public int scrollPos;
int getWidth() {
return recording.getProtocolPreferences().framebufferWidth;
}
......@@ -95,9 +96,9 @@ public class Index {
IndexEntry entry = get(indexNumber - 1);
entry.setBackgroundColor(color);
LinearLayout parent = (LinearLayout) entry.getParent();
indexViewer.scrollTo(0, parent.getTop() - parent.getHeight()
/ 2);
scrollPos=parent.getTop() - parent.getHeight()
/ 2;
indexViewer.scrollTo(0, scrollPos);
}
};
......@@ -326,7 +327,7 @@ public class Index {
static final public int PAINT_NO_ANNOTATIONS = 1;
static final public int PAINT_NO_HIGHLIGHT_ANNOTATIONS = 2;
// disabled because not working yet
int annotationsPaintMode = PAINT_NO_ANNOTATIONS;
int annotationsPaintMode = PAINT_ALL_ANNOTATIONS;
public int getAnnotationsPaintMode() {
return annotationsPaintMode;
......@@ -361,6 +362,8 @@ public class Index {
// read message
Message message = recording.getMessages().get(message_nr);
int start = message.getTimestamp();
// delete flag
boolean marked_to_be_deleted = false;
......@@ -407,6 +410,7 @@ public class Index {
// set collected annotations
recording.getIndex().get(i).setAnnotations(annotations);
Log.d("Index annotations", "index "+i+" start "+start+" end" +end+" annotations " +annotations.size());
// clear buffer if index ended with a delete event, which was not
// performed yet
......@@ -612,7 +616,6 @@ public class Index {
// ///////////////////////////////////////////////////////////////////////////////////
private int lastIndexFired = -1;
public int getLastIndexFired() {
return lastIndexFired;
}
......@@ -626,7 +629,7 @@ public class Index {
*/
public void fireIndexChangedEvent(int indexNumber) {
if (lastIndexFired != indexNumber) {
Log.d("Index Update","index number: "+indexNumber);
// highlighting of index entry and scrolling has to be done in ui
// thread
if (lastIndexFired > 0) {
......
......@@ -79,4 +79,5 @@ public class FeedDbManager {
db.execSQL("DELETE FROM feeds WHERE id = ?",
new String[] { String.valueOf(id) });
}
}
package tttclient.models;
import java.util.Date;
import android.os.Parcel;
import android.os.Parcelable;
......@@ -15,7 +17,7 @@ public class FeedItem implements Parcelable {
private String title;
private String link;
private String description;
private String pubDate;
private String date;
private String length;
// private String[] enclosure;
......@@ -44,13 +46,7 @@ public class FeedItem implements Parcelable {
this.description = description;
}
public String getPupDate() {
return pubDate;
}
public void setPupDate(String pupDate) {
this.pubDate = pupDate;
}
public String getLength() {
return length;
......@@ -60,10 +56,19 @@ public class FeedItem implements Parcelable {
this.length = length;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public String toString() {
return "FeedItem [title=" + title + ", link=" + link + ", description="
+ description + ", pupDate=" + pubDate + ", length=" + length
+ description + ", date=" + date + ", length=" + length
+ "]";
}
......@@ -72,7 +77,7 @@ public class FeedItem implements Parcelable {
copy.title = title;
copy.link = link;
copy.description = description;
copy.pubDate = pubDate;
copy.date = date;
copy.length = length;
return copy;
......@@ -91,7 +96,7 @@ public class FeedItem implements Parcelable {
title = in.readString();
link = in.readString();
description = in.readString();
pubDate = in.readString();
date = in.readString();
length = in.readString();
}
......@@ -100,7 +105,7 @@ public class FeedItem implements Parcelable {
dest.writeString(title);
dest.writeString(link);
dest.writeString(description);
dest.writeString(pubDate);
dest.writeString(date.toString());
dest.writeString(length);
}
......
......@@ -25,7 +25,7 @@ public class FeedItemDbManager {
public static final String COLUMN_TITLE = "title";
public static final String COLUMN_LINK = "link";
public static final String COLUMN_DESCRIPTION = "description";
public static final String COLUMN_PUBDATE = "pubDate";
public static final String COLUMN_DATE = "date";
public static final String COLUMN_PATH = "path";
public static final String COLUMN_STATUS = "status";
......@@ -33,7 +33,7 @@ public class FeedItemDbManager {
+ TABLE_FEEDITEMS + " ( " + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_FEEDID
+ " INTEGER, " + COLUMN_TITLE + " VARCHAR, " + COLUMN_LINK
+ " VARCHAR, " + COLUMN_DESCRIPTION + " VARCHAR, " + COLUMN_PUBDATE
+ " VARCHAR, " + COLUMN_DESCRIPTION + " VARCHAR, " + COLUMN_DATE
+ " VARCHAR, " + COLUMN_PATH + " VARCHAR, " + COLUMN_STATUS
+ " INTEGER );";
private final SQLiteDatabase db;
......@@ -52,7 +52,7 @@ public class FeedItemDbManager {
public Cursor getAllFromDB(int feedid) {
return db
.rawQuery(
"SELECT title, id as _id , feedId, link, description, pubDate, path, status FROM feedItems WHERE feedId = ? ORDER BY title DESC",
"SELECT title, id as _id , feedId, link, description, date, path, status FROM feedItems WHERE feedId = ? ORDER BY title ASC",
new String[] { String.valueOf(feedid) });
}
......@@ -107,11 +107,11 @@ public class FeedItemDbManager {
"INSERT INTO " + TABLE_FEEDITEMS + " (" + COLUMN_TITLE
+ ", " + COLUMN_FEEDID + ", " + COLUMN_LINK
+ ", " + COLUMN_DESCRIPTION + ", "
+ COLUMN_PUBDATE + ", " + COLUMN_STATUS
+ COLUMN_DATE + ", " + COLUMN_STATUS
+ ") VALUES ( ? , ? , ? , ? , ?," + 0 + " )",
new String[] { item.getTitle(), String.valueOf(feedId),
item.getLink(), item.getDescription(),
item.getPupDate() });
item.getDate() });
}
......@@ -151,5 +151,7 @@ public class FeedItemDbManager {
db.execSQL("DELETE FROM feedItems WHERE feedId = ?",
new String[] { String.valueOf(feedId) });
}
public void deleteTable(){
db.execSQL("DROP TABLE "+TABLE_FEEDITEMS);
}
}
......@@ -4,6 +4,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.xml.sax.Attributes;
......@@ -32,7 +34,6 @@ public class ParseService extends IntentService {
static final String CHANNEL = "channel";
static final String ITEM = "item";
static final String LANGUAGE = "language";
static final String PUB_DATE = "pubDate";
static final String DESCRIPTION = "description";
static final String LINK = "link";
static final String TITLE = "title";
......@@ -88,8 +89,14 @@ public class ParseService extends IntentService {
@Override
public void end(String body) {
feedItem.setTitle(body);
Pattern pattern =Pattern.compile( ".*(\\d{4}_\\d{2}_\\d{2}).*");
Matcher m = pattern.matcher(body);
if(m.matches())
feedItem.setDate(m.group(1));
}
});
item.getChild(LINK).setEndTextElementListener(
new EndTextElementListener() {
@Override
......@@ -104,13 +111,7 @@ public class ParseService extends IntentService {
feedItem.setDescription(body);
}
});
item.getChild(PUB_DATE).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setPupDate(body);
}
});
Element enclosure = item.getChild(ENCLOSURE);
enclosure.setStartElementListener(new StartElementListener() {
......
package tttclient.utils;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.util.Log;
public class Utils {
public static Date stringToDate(String string){
int year=0;
int month=0;
int day=0;
Pattern pattern = Pattern.compile("(\\d{4})_(\\d{2})_(\\d{2})");
Matcher m = pattern.matcher(string);
if(m.matches()){
year = Integer.parseInt(m.group(1));
month= Integer.parseInt(m.group(2)) -1;
day= Integer.parseInt(m.group(3));
}
Date date = new Date(year, month, day);
return date;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment