Commit da8e0041 authored by Thomas Krex's avatar Thomas Krex

New Fragments for Feeds and FeedDetails

parent efccfef6
......@@ -21,7 +21,7 @@
android:icon="@drawable/ttt24"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/Theme.Customactionbar" >
android:theme="@style/MyTheme" >
<activity
android:name="tttclient.activities.MainActivity"
android:label="@string/app_name" >
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/actionbar_blue"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5" >
<fragment
android:id="@+id/feedFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="2"
class="tttclient.fragments.FeedFragment" />
<fragment
android:id="@+id/itemFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
class="tttclient.fragments.FeedDetailsFragment" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/detailFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="tttclient.fragments.FeedDetailsFragment" />
</LinearLayout>
\ No newline at end of file
......@@ -3,17 +3,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
<fragment
android:id="@+id/feedFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"/>
<fragment
android:id="@+id/itemFragment"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"/>
class="tttclient.fragments.FeedFragment" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<ListView
android:id="@+id/feedDetailsLv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
<ListView
android:id="@+id/feedDetailsLv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
<ViewStub
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout="@layout/empty_feed_items" >
</ViewStub>
<ViewStub
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout="@layout/empty_feed_items" >
</ViewStub>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<ListView
android:id="@+id/feed_list"
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TTTClient</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="wait">Please Wait. Reading File</string>
<string name="confirm_download">Do you want to download this Lecture?\nThis could take some time and can\'t be canceled</string>
<string name="yes">Yes</string>
<string name="cancel">Cancel</string>
<string name="inet_needed">Internet Connection needed</string>
<string name="not_found">File was not found</string>
<string name="deleted">File was deleted</string>
<string name="delete_feed">Do you want to delete this feed? All corresponding Lectures on this devices will be deleted!</string>
<string name="delete_lecture"> Do you want to delete this lecture from your devices?</string>
<string name="delete">Delete</string>
<string name="add_feed">Add a new Feed</string>
<string name="parse_fail_title">Connection Failed!!!</string>
<string name="parse_fail_message">Please make sure that the URL is correct and reachable</string>
<string name="save">Save</string>
<string name="paste_url">Paste URL</string>
<string name="toast_clipboard_no_url">no URL in clipboard</string>
<string name="toast_insert_name">Please insert a name for this feed</string>
<string name="toast_insert_url">Please insert a valid Url</string>
<string name="toast_internet_needed">Internet Connection needed</string>
<string name="no_lectures">No Lectures Available</string>
<string name="no_feeds">No Feeds found!!! \n\n Add a feed by clicking on \n + \nin the Actionbar</string>
<string name="watch">Watch Lectures</string>
<color name="light_gray">#66bfbdbd</color>
<color name="trans_blue">#660063d2</color>
<color name="trans_black">#d1212427</color>
<string name="drawer_open">Open Index Navigation</string>
<string name="drawer_close">Close Index Navigation</string>
<string name="app_name">TTTClient</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="wait">Please Wait. Reading File</string>
<string name="confirm_download">Do you want to download this Lecture?\nThis could take some time and can\'t be canceled</string>
<string name="yes">Yes</string>
<string name="cancel">Cancel</string>
<string name="inet_needed">Internet Connection needed</string>
<string name="not_found">File was not found</string>
<string name="deleted">File was deleted</string>
<string name="delete_feed">Do you want to delete this feed? All corresponding Lectures on this devices will be deleted!</string>
<string name="delete_lecture"> Do you want to delete this lecture from your devices?</string>
<string name="delete">Delete</string>
<string name="add_feed">Add a new Feed</string>
<string name="parse_fail_title">Connection Failed!!!</string>
<string name="parse_fail_message">Please make sure that the URL is correct and reachable</string>
<string name="save">Save</string>
<string name="paste_url">Paste URL</string>
<string name="toast_clipboard_no_url">no URL in clipboard</string>
<string name="toast_insert_name">Please insert a name for this feed</string>
<string name="toast_insert_url">Please insert a valid Url</string>
<string name="toast_internet_needed">Internet Connection needed</string>
<string name="no_lectures">No Lectures Available</string>
<string name="no_feeds">No Feeds found!!! \n\n Add a feed by clicking on \n + \nin the Actionbar</string>
<string name="watch">Watch Lectures</string>
<color name="light_gray">#66bfbdbd</color>
<color name="trans_blue">#660063d2</color>
<color name="trans_black">#d1212427</color>
<string name="drawer_open">Open Index Navigation</string>
<string name="drawer_close">Close Index Navigation</string>
<color name="actionbar_blue">#6fbcfc</color>
</resources>
\ No newline at end of file
<resources>
<!--
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
-->
<style name="android:Theme.MusicPlayer">
</style>
<style name="android:Theme.MusicPlayer">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="MyTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.Sherlock.ActionBar">
<item name="android:background">@color/actionbar_blue</item>
</style>
</resources>
\ No newline at end of file
package tttclient.activities;
import tttclient.fragments.FeedDetailsFragment;
import tttclient.fragments.FeedFragment.OnFeedSelectedListener;
import tttclient.models.Feed;
import tttclient.models.FeedDbManager;
import tttclient.models.FeedItemDbManager;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import de.tum.in.tttclient.R;
/**
*
* @author Thomas Krex
*
* Activity for adding and Displaying Feeds. This class uses the
* FeedDbManger to store feeds and a Listview to display them.
*
* @see FeedDbManager, Feed
*
*
*/
public class FeedActivity extends SherlockActivity implements
OnItemClickListener, OnItemLongClickListener {
public class FeedActivity extends SherlockFragmentActivity implements
OnFeedSelectedListener {
private SimpleCursorAdapter adapter;
private String feedUrl;
private String feedName;
private int feedId;
private Vibrator myVib;
private ListView feedLv;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_feeds);
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
feedLv = (ListView) findViewById(R.id.feed_list);
FeedDbManager fManager = new FeedDbManager(this);
Cursor cursor = fManager.getAllFromDB();
adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, cursor,
new String[] { FeedDbManager.COLUMN_NAME,
FeedDbManager.COLUMN_FEEDURL }, new int[] {
android.R.id.text1, android.R.id.text2 });
feedLv.setAdapter(adapter);
// set view for empty list
View empty = findViewById(R.id.empty);
feedLv.setEmptyView(empty);
feedLv.setOnItemClickListener(this);
feedLv.setOnItemLongClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.feed_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.add) {
// addDialog.show();
Intent intent = new Intent(this, FeedWizardActivity.class);
startActivityForResult(intent, 0);
setContentView(R.layout.activity_feeds);
}
return true;
}
@Override
public void onItemClick(AdapterView<?> av, View v, int position, long id) {
// click on feed in list
if (position != -1) {
Cursor c = (Cursor) av.getAdapter().getItem(position);
feedUrl = c.getString(c
.getColumnIndex(FeedDbManager.COLUMN_FEEDURL));
feedName = c.getString(c.getColumnIndex(FeedDbManager.COLUMN_NAME));
feedId = c.getInt(c.getColumnIndex("_id"));
Feed feed = new Feed(feedId, feedName, feedUrl);
public void onFeedSelected(Feed feed) {
FeedDetailsFragment detailsFragment = (FeedDetailsFragment) getSupportFragmentManager()
.findFragmentById(R.id.itemFragment);
if (detailsFragment == null) {
// send Feed to FeedDetailsActivity for displaying items
Intent intent = new Intent(this, FeedDetailActivity.class);
Intent intent = new Intent(this, FeedDetailActivity_old.class);
intent.putExtra("feed", feed);
startActivity(intent);
}
}
@Override
public boolean onItemLongClick(final AdapterView<?> av, View v,
final int position, long id) {
if (id == -1) {
return false;
}
// haptic feedback for longclick
myVib.vibrate(50);
// v.performHapticFeedback(HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
} else {
detailsFragment.updateList(feed);
// confirm delete
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// delete feed from list, refresh feed list
Cursor c = (Cursor) av.getAdapter().getItem(position);
feedId = c.getInt(c.getColumnIndex("_id"));
FeedDbManager fm = new FeedDbManager(av.getContext());
FeedItemDbManager fim = new FeedItemDbManager(av.getContext());
// delete all childs and their folders
fim.deleteFromDb(feedId);
fm.deleteFromDb(feedId);
adapter.changeCursor(fm.getAllFromDB());
}
};
// show alert dialog to get confirmed delete process
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.delete_feed);
builder.setPositiveButton(R.string.delete, listener);
builder.setNegativeButton(R.string.cancel, null);
builder.show();
return true;
}
}
@Override
protected void onResume() {
super.onResume();
adapter.changeCursor(new FeedDbManager(this).getAllFromDB());
}
}
package tttclient.activities;
import tttclient.models.Feed;
import tttclient.models.FeedDbManager;
import tttclient.models.FeedItemDbManager;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import de.tum.in.tttclient.R;
/**
*
* @author Thomas Krex
*
* Activity for adding and Displaying Feeds. This class uses the
* FeedDbManger to store feeds and a ListView to display them. For
* adding a feed, the FeedWizardActivity is opened.
*
* @see FeedDbManager, Feed, FeedWizardActivity
*
*
*/
public class FeedActivity_old extends SherlockActivity implements
OnItemClickListener, OnItemLongClickListener {
private SimpleCursorAdapter adapter;
private String feedUrl;
private String feedName;
private int feedId;
private Vibrator myVib;
private ListView feedLv;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_feeds);
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
feedLv = (ListView) findViewById(R.id.feed_list);
FeedDbManager fManager = new FeedDbManager(this);
Cursor cursor = fManager.getAllFromDB();
adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, cursor,
new String[] { FeedDbManager.COLUMN_NAME,
FeedDbManager.COLUMN_FEEDURL }, new int[] {
android.R.id.text1, android.R.id.text2 });
feedLv.setAdapter(adapter);
// set view for empty list
View empty = findViewById(R.id.empty);
feedLv.setEmptyView(empty);
feedLv.setOnItemClickListener(this);
feedLv.setOnItemLongClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.feed_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.add) {
// addDialog.show();
Intent intent = new Intent(this, FeedWizardActivity.class);
startActivityForResult(intent, 0);
}
return true;
}
@Override
public void onItemClick(AdapterView<?> av, View v, int position, long id) {
// click on feed in list
if (position != -1) {
Cursor c = (Cursor) av.getAdapter().getItem(position);
feedUrl = c.getString(c
.getColumnIndex(FeedDbManager.COLUMN_FEEDURL));
feedName = c.getString(c.getColumnIndex(FeedDbManager.COLUMN_NAME));
feedId = c.getInt(c.getColumnIndex("_id"));
Feed feed = new Feed(feedId, feedName, feedUrl);
// send Feed to FeedDetailsActivity for displaying items
Intent intent = new Intent(this, FeedDetailActivity_old.class);
intent.putExtra("feed", feed);
startActivity(intent);
}
}
@Override
public boolean onItemLongClick(final AdapterView<?> av, View v,
final int position, long id) {
if (id == -1) {
return false;
}
// haptic feedback for longclick
myVib.vibrate(50);
// v.performHapticFeedback(HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
// confirm delete
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// delete feed from list, refresh feed list
Cursor c = (Cursor) av.getAdapter().getItem(position);
feedId = c.getInt(c.getColumnIndex("_id"));
FeedDbManager fm = new FeedDbManager(av.getContext());
FeedItemDbManager fim = new FeedItemDbManager(av.getContext());
// delete all childs and their folders
fim.deleteFromDb(feedId);
fm.deleteFromDb(feedId);
adapter.changeCursor(fm.getAllFromDB());
}
};
// show alert dialog to get confirmed delete process
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.delete_feed);
builder.setPositiveButton(R.string.delete, listener);
builder.setNegativeButton(R.string.cancel, null);
builder.show();
return true;
}
@Override
protected void onResume() {
super.onResume();
adapter.changeCursor(new FeedDbManager(this).getAllFromDB());
}
}
This diff is collapsed.
package tttclient.activities;
import com.actionbarsherlock.app.SherlockListFragment;
public class FeedDetailsFragment extends SherlockListFragment {
}
package tttclient.activities;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import com.actionbarsherlock.app.SherlockListFragment;
import de.tum.in.tttclient.R;
public class FeedFragment extends SherlockListFragment {
private SimpleCursorAdapter adapter;
private String feedUrl;
private String feedName;
private int feedId;
private Dialog addDialog;
private EditText urlTxt;
private EditText nameTxt;
private DatePicker datePicker;
private Button pasteButton;
private Button saveButton;
private Vibrator myVib;
private ListView feedLv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_feeds, container, false);
return view;
}
}
......@@ -16,6 +16,13 @@ import com.actionbarsherlock.view.MenuItem;
import de.tum.in.tttclient.R;
/**
* @author thomas
*
* Activity for Adding new Feeds. This Activity uses two fragments, each
* for one step of the adding process.
*
*/
public class FeedWizardActivity extends SherlockFragmentActivity {
FrameLayout container;
......
This diff is collapsed.
package tttclient.fragments;
import tttclient.models.Feed;
import tttclient.models.FeedDbManager;
import tttclient.models.FeedItemDbManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import com.actionbarsherlock.app.SherlockFragment;
import de.tum.in.tttclient.R;
public class FeedFragment extends SherlockFragment implements
OnItemClickListener, OnItemLongClickListener {
private OnFeedSelectedListener listener;
private SimpleCursorAdapter adapter;
private String feedUrl;
private String feedName;
private int feedId;
private Dialog addDialog;
private EditText urlTxt;
private EditText nameTxt;
private DatePicker datePicker;
private Button pasteButton;
private Button saveButton;
private Vibrator myVib;
private ListView feedLv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_feeds, container, false);
myVib = (Vibrator) getSherlockActivity().getSystemService(
Context.VIBRATOR_SERVICE);
feedLv = (ListView) view.findViewById(R.id.feed_list);
FeedDbManager fManager = new FeedDbManager(getSherlockActivity());
Cursor cursor = fManager.getAllFromDB();
adapter = new SimpleCursorAdapter(getSherlockActivity(),
android.R.layout.simple_list_item_2, cursor,
new String[] { FeedDbManager.COLUMN_NAME,
FeedDbManager.COLUMN_FEEDURL }, new int[] {
android.R.id.text1, android.R.id.text2 });
feedLv.setAdapter(adapter);
// set view for empty list
View empty = view.findViewById(R.id.empty);
feedLv.setEmptyView(empty);
feedLv.setOnItemClickListener(this);
feedLv.setOnItemLongClickListener(this);
return view;