Skip to content

Commit fa5eb04

Browse files
committed
listview added, deletion works too
1 parent ef17104 commit fa5eb04

File tree

5 files changed

+112
-24
lines changed

5 files changed

+112
-24
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/sam/alarmclock/DBHandler.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.content.Context;
77
import android.content.ContentValues;
88

9+
import java.util.ArrayList;
10+
911
public class DBHandler extends SQLiteOpenHelper{
1012

1113
private static final int DATABASE_VERSION = 1;
@@ -47,7 +49,12 @@ public void addVideoOption(VideoOption videoOption){
4749
//Delete a videoOption from database
4850
public void deleteVideoOption(String url){
4951
SQLiteDatabase db = getWritableDatabase();
50-
db.execSQL("DELETE FROM( " + TABLE_VIDEOOPTIONS + " WHERE " + COLUMN_VIDEOURL + "=\"" + url + "\";");
52+
db.execSQL("DELETE * FROM " + TABLE_VIDEOOPTIONS + " WHERE " + COLUMN_VIDEOURL + "=\"" + url + "\";");
53+
}
54+
55+
public void clearTable(){
56+
SQLiteDatabase db = getWritableDatabase();
57+
db.execSQL("DELETE FROM " + TABLE_VIDEOOPTIONS + ";");
5158
}
5259

5360
public String databaseToString() {
@@ -73,4 +80,31 @@ public String databaseToString() {
7380
return dbString;
7481
}
7582

83+
public ArrayList<String> databaseToStringList(){
84+
ArrayList<String> urlList = new ArrayList<String>();
85+
SQLiteDatabase db = getWritableDatabase();
86+
String query = "SELECT * FROM " + TABLE_VIDEOOPTIONS + " WHERE 1";
87+
88+
//Cursor points to a location in your results
89+
Cursor recordSet = db.rawQuery(query, null);
90+
//Move to the first row in your results
91+
recordSet.moveToFirst();
92+
93+
//Position after the last row means the end of the results
94+
while (!recordSet.isAfterLast()) {
95+
// null could happen if we used our empty constructor
96+
// if (recordSet.getString(recordSet.getColumnIndex("videourl")) != null && recordSet.getString(recordSet.getColumnIndex("videoname")) != null) {
97+
//// urlList.add("Title: " + recordSet.getString(recordSet.getColumnIndex("videoname")) + "\n"
98+
//// + "URL: " + recordSet.getString(recordSet.getColumnIndex("videourl")));
99+
// urlList.add("URL: " + recordSet.getString(recordSet.getColumnIndex("videourl")));
100+
// } else
101+
if (recordSet.getString(recordSet.getColumnIndex("videourl")) != null) {
102+
urlList.add("URL: " + recordSet.getString(recordSet.getColumnIndex("videourl")));
103+
}
104+
recordSet.moveToNext();
105+
}
106+
db.close();
107+
return urlList;
108+
}
109+
76110
}

app/src/main/java/sam/alarmclock/OptionAdapter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import android.widget.ImageView;
99
import android.widget.TextView;
1010

11+
import java.util.ArrayList;
12+
1113

1214
public class OptionAdapter extends ArrayAdapter<String>{
13-
public OptionAdapter(Context context, String[] foods) {
14-
super(context, R.layout.option_row ,foods);
15+
public OptionAdapter(Context context, ArrayList<String> urlList) {
16+
super(context, R.layout.option_row ,urlList);
1517
}
1618

1719
@Override

app/src/main/java/sam/alarmclock/VideoListActivity.java

+53-13
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
import android.app.TaskStackBuilder;
55
import android.content.Intent;
66
import android.os.Bundle;
7+
import android.provider.MediaStore;
78
import android.support.design.widget.FloatingActionButton;
89
import android.support.design.widget.Snackbar;
910
import android.support.v4.app.NavUtils;
1011
import android.support.v7.app.AppCompatActivity;
1112
import android.support.v7.app.NotificationCompat;
1213
import android.support.v7.widget.Toolbar;
1314
import android.view.View;
15+
import android.widget.AdapterView;
16+
import android.widget.ListAdapter;
17+
import android.widget.ListView;
1418
import android.widget.TextView;
19+
import android.widget.Toast;
20+
21+
import java.util.ArrayList;
1522

1623

1724
public class VideoListActivity extends AppCompatActivity {
@@ -20,6 +27,8 @@ public class VideoListActivity extends AppCompatActivity {
2027
TextView textViewIntent;
2128
DBHandler dbHandler;
2229
String selectedURL;
30+
String currentURL;
31+
ArrayList<String> urlList;
2332

2433
@Override
2534
protected void onCreate(Bundle savedInstanceState) {
@@ -42,20 +51,25 @@ protected void onCreate(Bundle savedInstanceState) {
4251
}
4352
}
4453

45-
Intent currentIntent = NavUtils.getParentActivityIntent(this);
46-
47-
PendingIntent pendingIntent =
48-
TaskStackBuilder.create(this)
49-
// add all of DetailsActivity's parents to the stack,
50-
// followed by DetailsActivity itself
51-
.addNextIntentWithParentStack(currentIntent)
52-
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
54+
// Intent currentIntent = NavUtils.getParentActivityIntent(this);
55+
//
56+
// PendingIntent pendingIntent =
57+
// TaskStackBuilder.create(this)
58+
// // add all of DetailsActivity's parents to the stack,
59+
// // followed by DetailsActivity itself
60+
// .addNextIntentWithParentStack(currentIntent)
61+
// .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
62+
//
63+
// NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
64+
// builder.setContentIntent(pendingIntent);
65+
//
66+
// System.out.println("here");
5367

54-
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
55-
builder.setContentIntent(pendingIntent);
68+
//urlList = new ArrayList<String>();
5669

57-
System.out.println("here");
70+
// urlList = dbHandler.databaseToStringList();
5871

72+
setUpListView();
5973

6074

6175
printDatabase();
@@ -84,6 +98,7 @@ public void handleYoutubeURL(Intent intent){
8498
String url = intent.getStringExtra(Intent.EXTRA_TEXT);
8599
if (url != null){
86100
selectedURL = url;
101+
currentURL = url;
87102
textViewIntent.setText(url);
88103
}
89104
}
@@ -94,9 +109,34 @@ public void printDatabase() {
94109
testTextView.setText(dbString);
95110
}
96111
public void testButtonClicked(View view){
97-
System.out.println("hi0");
98-
VideoOption videoOption = new VideoOption("zdEhHLjtxDA");
112+
//VideoOption videoOption = new VideoOption("zdEhHLjtxDA");
113+
VideoOption videoOption = new VideoOption(currentURL);
99114
dbHandler.addVideoOption(videoOption);
100115
printDatabase();
116+
setUpListView();
117+
}
118+
public void clearTable(View view){
119+
dbHandler.clearTable();
120+
printDatabase();
121+
}
122+
123+
public void setUpListView(){
124+
urlList = dbHandler.databaseToStringList();
125+
126+
ListAdapter customListAdapter = new OptionAdapter(this,urlList);//
127+
ListView customListView = (ListView) findViewById(R.id.VideoListView);
128+
customListView.setAdapter(customListAdapter);
129+
130+
customListView.setOnItemClickListener(
131+
new AdapterView.OnItemClickListener() {
132+
@Override
133+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
134+
String food = String.valueOf(parent.getItemAtPosition(position));
135+
Toast.makeText(VideoListActivity.this, food, Toast.LENGTH_LONG).show();
136+
}
137+
}
138+
);
139+
140+
101141
}
102142
}

app/src/main/res/layout/content_video_list.xml

+19-7
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,40 @@
5252
</TableLayout>
5353

5454
<Button
55-
android:text="Button"
55+
android:text="Add Entry"
5656
android:layout_height="wrap_content"
57-
android:id="@+id/button"
57+
android:id="@+id/addButton"
5858
android:onClick="testButtonClicked"
5959
android:layout_width="wrap_content"
6060
android:layout_below="@id/theTable"
6161
/>
6262

63+
<Button
64+
android:text="Clear List"
65+
android:layout_height="wrap_content"
66+
android:id="@+id/clearButton"
67+
android:onClick="clearTable"
68+
android:layout_width="wrap_content"
69+
android:layout_below="@id/theTable"
70+
android:layout_toRightOf="@id/addButton"
71+
/>
72+
6373

6474
<TextView
6575
android:text="TextView"
6676
android:layout_width="match_parent"
6777
android:layout_height="wrap_content"
6878
android:id="@+id/textViewTest"
6979
android:layout_marginTop="120dp"
70-
android:layout_below="@+id/button"
80+
android:layout_below="@+id/addButton"
7181
android:layout_alignParentEnd="true"
7282
android:layout_marginEnd="12dp" />
7383

74-
<!--<ListView-->
75-
<!--android:layout_width="wrap_content"-->
76-
<!--android:layout_height="wrap_content"-->
77-
<!--android:id="@+id/VideoListView"></ListView>-->
84+
85+
<ListView
86+
android:layout_width="wrap_content"
87+
android:layout_height="wrap_content"
88+
android:id="@+id/VideoListView"
89+
android:layout_below="@id/textViewTest"></ListView>
7890

7991
</RelativeLayout>

0 commit comments

Comments
 (0)