Archived
Added basic category functionality.
This commit is contained in:
1 parent
6171c2cbcc
commit
8874f389b0
4 files changed
+89
-11
No files matched your search
@@ -1,10 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView android:text="Choose category"
|
||||
<ListView android:id="@+id/choose_category_list"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content">
|
||||
</ListView>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="3px"
|
||||
android:paddingBottom="3px">
|
||||
|
||||
<TextView android:id="@+id/choose_category_list_row_text"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" />
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.studentersamfundet.app.ui;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import com.studentersamfundet.app.Event;
|
||||
import com.studentersamfundet.app.R;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
|
||||
public class ChooseCategoryDialog extends Dialog {
|
||||
private final Callback callback;
|
||||
private String chosenCategory = Event.ALL;
|
||||
|
||||
public interface Callback {
|
||||
public void run(String ... message);
|
||||
}
|
||||
|
||||
private class OnDismiss implements OnDismissListener {
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
callback.run(chosenCategory);
|
||||
}
|
||||
}
|
||||
|
||||
public ChooseCategoryDialog(Context context, Callback callback) {
|
||||
super(context);
|
||||
|
||||
if (callback == null)
|
||||
throw new InvalidParameterException("callback is not supposed to be null!");
|
||||
|
||||
this.callback = callback;
|
||||
|
||||
setContentView(R.layout.choose_category_dialog);
|
||||
setTitle("Choose category");
|
||||
setOnDismissListener(new OnDismiss());
|
||||
populateList(context);
|
||||
}
|
||||
|
||||
private void populateList(Context context) {
|
||||
final String[] categories = new String[] {
|
||||
Event.ALL,
|
||||
"film"
|
||||
};
|
||||
|
||||
ListView list = (ListView)findViewById(R.id.choose_category_list);
|
||||
list.setAdapter(new ArrayAdapter<String>(context, R.layout.choose_category_list_row, R.id.choose_category_list_row_text, categories));
|
||||
list.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
ChooseCategoryDialog.this.chosenCategory = categories[position];
|
||||
ChooseCategoryDialog.this.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.studentersamfundet.app.Event;
|
||||
import com.studentersamfundet.app.FeedFetcher;
|
||||
import com.studentersamfundet.app.R;
|
||||
import com.studentersamfundet.app.XmlParser;
|
||||
import com.studentersamfundet.app.ui.ChooseCategoryDialog.Callback;
|
||||
|
||||
public class ProgramListActivity extends BaseDnsActivity {
|
||||
public static final String feedURL = "http://studentersamfundet.no/rss/lars_program_feed.php";
|
||||
@@ -61,8 +62,7 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
return true;
|
||||
|
||||
case R.id.menu_categories:
|
||||
String category = chooseCategory();
|
||||
this.createList(category, false);
|
||||
createCategoryDialog();
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -142,12 +142,16 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
|
||||
}
|
||||
|
||||
protected String chooseCategory() {
|
||||
Dialog dialog = new Dialog(this);
|
||||
dialog.setContentView(R.layout.choose_category_dialog);
|
||||
protected void createCategoryDialog() {
|
||||
Dialog dialog = new ChooseCategoryDialog(this, new Callback() {
|
||||
public void run(String... message) {
|
||||
if (message.length < 1)
|
||||
message = new String[] { Event.ALL };
|
||||
|
||||
ProgramListActivity.this.createList(message[0], false);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setTitle("Choose category");
|
||||
dialog.show();
|
||||
return Event.ALL;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user