blob: cd7b853778dda62a94902b0809f8fcc5ead8facd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
package ryuslash.org.dvdroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
public class AddDVDActivity extends Activity
{
private DVDDataSource datasource;
private long id;
public void saveDVD()
{
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);
if (id > 0) {
datasource.updateDVD(id, name_entry.getText().toString(),
watched_entry.isChecked() ? 1 : 0,
wishlist_entry.isChecked() ? 1 : 0);
} else {
datasource.createDVD(name_entry.getText().toString(),
watched_entry.isChecked() ? 1 : 0,
wishlist_entry.isChecked() ? 1 : 0);
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
datasource = new DVDDataSource(this);
datasource.open();
Intent intent = getIntent();
id = intent.getLongExtra(SQLiteHelper.COLUMN_ID, 0l);
if (id > 0) {
DVD dvd = datasource.getById(id);
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);
name_entry.setText(dvd.getTitle());
watched_entry.setChecked(dvd.getWatched() == 1);
wishlist_entry.setChecked(dvd.getWishlist() == 1);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.add_activity, menu);
return true;
}
@Override
protected void onDestroy()
{
datasource.close();
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case R.id.add_menu_save:
saveDVD();
finish();
return true;
}
return false;
}
@Override
protected void onPause()
{
datasource.close();
super.onPause();
}
@Override
protected void onResume()
{
datasource.open();
super.onResume();
}
}
|