Separate adding of DVDs
* AndroidManifest.xml: Add `AddDVDActivity' as an activity. * res/layout/add.xml: Layout for `AddDVDActivity'. * res/layout/main.xml: Remove the nested `LinearLayout' and `EditText' widgets. * res/values/strings.xml: Change the `name_entry' hint text, add captions for `wishlist_entry', `watched_entry' and `save_button'. * src/ryuslash/org/dvdroid/AddDVDActivity.java: New activity. * src/ryuslash/org/dvdroid/DVDDataSource.java (createDVD): Accept WATCHED and WISHLIST parameters and send these to the database instead of `0' and `1'. * src/ryuslash/org/dvdroid/DVDroidActivity.java (addDVD): Call `AddDVDActivity' to add a new DVD to the collection. (onActivityResult): New override.
This commit is contained in:
parent
0f2bd8ae16
commit
9fc77db218
7 changed files with 123 additions and 31 deletions
|
@ -11,5 +11,6 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="AddDVDActivity" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
30
res/layout/add.xml
Normal file
30
res/layout/add.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<EditText
|
||||
android:id="@+id/name_entry"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/name_entry" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/wishlist_entry"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/wishlist_entry" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/watched_entry"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watched_entry" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/save_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save_button"
|
||||
android:onClick="saveDVD" />
|
||||
</LinearLayout>
|
|
@ -3,23 +3,12 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<EditText
|
||||
android:id="@+id/name_entry"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/name_entry" />
|
||||
<Button
|
||||
android:id="@+id/add_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_button"
|
||||
android:onClick="addDVD" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/add_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_button"
|
||||
android:onClick="addDVD" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">DVDroid</string>
|
||||
<string name="name_entry">Enter A DVD title</string>
|
||||
<string name="name_entry">Title...</string>
|
||||
<string name="wishlist_entry">On wishlist</string>
|
||||
<string name="watched_entry">Watched</string>
|
||||
<string name="add_button">Add</string>
|
||||
<string name="save_button">Save</string>
|
||||
</resources>
|
||||
|
|
59
src/ryuslash/org/dvdroid/AddDVDActivity.java
Normal file
59
src/ryuslash/org/dvdroid/AddDVDActivity.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package ryuslash.org.dvdroid;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class AddDVDActivity extends Activity
|
||||
{
|
||||
private DVDDataSource datasource;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.add);
|
||||
|
||||
datasource = new DVDDataSource(this);
|
||||
datasource.open();
|
||||
}
|
||||
|
||||
public void saveDVD(View view)
|
||||
{
|
||||
EditText name_entry = (EditText)findViewById(R.id.name_entry);
|
||||
CheckBox watched_entry =
|
||||
(CheckBox)findViewById(R.id.watched_entry);
|
||||
CheckBox wishlist_entry =
|
||||
(CheckBox)findViewById(R.id.wishlist_entry);
|
||||
|
||||
datasource.createDVD(name_entry.getText().toString(),
|
||||
watched_entry.isChecked() ? 1 : 0,
|
||||
wishlist_entry.isChecked() ? 1 : 0);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
datasource.open();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
datasource.close();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
datasource.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
|
@ -33,13 +33,13 @@ public class DVDDataSource
|
|||
dbHelper.close();
|
||||
}
|
||||
|
||||
public DVD createDVD(String title)
|
||||
public DVD createDVD(String title, int watched, int wishlist)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put(SQLiteHelper.COLUMN_TITLE, title);
|
||||
values.put(SQLiteHelper.COLUMN_WATCHED, 0);
|
||||
values.put(SQLiteHelper.COLUMN_WISHLIST, 1);
|
||||
values.put(SQLiteHelper.COLUMN_WATCHED, watched);
|
||||
values.put(SQLiteHelper.COLUMN_WISHLIST, wishlist);
|
||||
|
||||
long insertId = database.insert(SQLiteHelper.TABLE_DVD, null,
|
||||
values);
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
@ -35,17 +36,10 @@ public class DVDroidActivity extends ListActivity
|
|||
|
||||
public void addDVD(View view)
|
||||
{
|
||||
ArrayAdapter<DVD> adapter = (ArrayAdapter<DVD>)getListAdapter();
|
||||
EditText editText = (EditText)findViewById(R.id.name_entry);
|
||||
DVD dvd = datasource.createDVD(editText.getText().toString());
|
||||
int duration = Toast.LENGTH_SHORT;
|
||||
Toast toast = Toast.makeText(this, "Added " + editText.getText(),
|
||||
duration);
|
||||
Intent intent = new Intent(this, AddDVDActivity.class);
|
||||
|
||||
editText.setText("");
|
||||
adapter.add(dvd);
|
||||
adapter.notifyDataSetChanged();
|
||||
toast.show();
|
||||
datasource.close();
|
||||
startActivityForResult(intent, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,4 +55,20 @@ public class DVDroidActivity extends ListActivity
|
|||
datasource.close();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode,
|
||||
int resultCode,
|
||||
Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
datasource.open();
|
||||
|
||||
ArrayAdapter<DVD> adapter = (ArrayAdapter<DVD>)getListAdapter();
|
||||
List<DVD> dvds = datasource.getWishlist();
|
||||
|
||||
adapter.clear();
|
||||
adapter.addAll(dvds);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue