|
13 | 13 | import android.widget.Button;
|
14 | 14 | import android.widget.EditText;
|
15 | 15 | import android.widget.Spinner;
|
| 16 | +import android.widget.Toast; |
16 | 17 |
|
17 | 18 | import ekylibre.database.ZeroContract;
|
18 | 19 | import ekylibre.zero.R;
|
19 | 20 |
|
20 | 21 |
|
21 | 22 | public class ArticleNewActivity extends AppCompatActivity implements View.OnClickListener {
|
22 | 23 |
|
23 |
| - String[] natureList = {"Fertilizer", "Seed", "Chemical"}; |
24 |
| - String[] unityList = {"kg", "L", "t"}; |
25 |
| - |
26 | 24 | @Override
|
27 | 25 | public void onCreate(Bundle savedInstanceState) {
|
28 | 26 | super.onCreate(savedInstanceState);
|
29 | 27 |
|
| 28 | + |
| 29 | + String[] natureList = {getResources().getString(R.string.spinner_selection_nature), getResources().getString(R.string.fertilizer), getResources().getString(R.string.seed), getResources().getString(R.string.chemical)}; |
| 30 | + String[] unityList = {getResources().getString(R.string.spinner_selection_unity), "kg", "L", "t"}; |
| 31 | + |
30 | 32 | setContentView(R.layout.article_new);
|
31 | 33 |
|
32 | 34 | Button btn_save = (Button) findViewById(R.id.buttonSaveArticleId);
|
@@ -55,15 +57,40 @@ public void add_article(Context context) {
|
55 | 57 | mNewValues.put(ZeroContract.Articles.NAME, newArticleName.getText().toString());
|
56 | 58 | mNewValues.put(ZeroContract.Articles.NATURE, SpinnerArticleNature.getSelectedItem().toString());
|
57 | 59 | mNewValues.put(ZeroContract.Articles.UNITY, SpinnerArticleUnity.getSelectedItem().toString());
|
| 60 | + mNewValues.put(ZeroContract.Articles.EK_ID, 1); |
| 61 | + |
58 | 62 | contentResolver.insert(ZeroContract.Articles.CONTENT_URI, mNewValues);
|
59 | 63 | }
|
60 | 64 |
|
61 | 65 | @Override
|
62 | 66 | public void onClick(View _buttonView) {
|
63 |
| - //Récupère ce qu'a tapé l'utilisateur dans la zone de texte et la renvoie à la MainActivtity |
64 | 67 | if (_buttonView.getId() == R.id.buttonSaveArticleId) {
|
65 |
| - add_article(this); |
| 68 | + if (is_complete()) { |
| 69 | + add_article(this); |
| 70 | + Toast toast = Toast.makeText(getApplicationContext(), R.string.article_saved, Toast.LENGTH_SHORT); |
| 71 | + toast.show(); |
| 72 | + } |
| 73 | + else{ |
| 74 | + Toast toast = Toast.makeText(getApplicationContext(), R.string.article_cannot_save, Toast.LENGTH_SHORT); |
| 75 | + toast.show(); |
66 | 76 |
|
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private boolean is_complete() { |
| 84 | + EditText newArticleName = (EditText) findViewById(R.id.editArticleNameId); |
| 85 | + |
| 86 | + Spinner SpinnerArticleNature = (Spinner) findViewById(R.id.spinnerNatureArticleId); |
| 87 | + Spinner SpinnerArticleUnity = (Spinner) findViewById(R.id.spinnerUnityArticleId); |
| 88 | + |
| 89 | + if (SpinnerArticleNature.getSelectedItemPosition() == 0 || SpinnerArticleUnity.getSelectedItemPosition() == 0 || newArticleName.getText().toString().trim().equals("")){ |
| 90 | + return false; |
| 91 | + } |
| 92 | + else { |
| 93 | + return true; |
67 | 94 | }
|
68 | 95 | }
|
69 | 96 | }
|
|
0 commit comments