View difference between Paste ID: Y0JNYjEd and Mpm5XTWz
SHOW: | | - or go back to the newest paste.
1
package com.example.naabi.listeserie;
2
3
import android.app.AlertDialog;
4
import android.content.DialogInterface;
5
import android.os.Bundle;
6
import android.support.v7.app.AppCompatActivity;
7
import android.util.Log;
8
import android.view.MotionEvent;
9
import android.view.View;
10
import android.widget.AdapterView;
11
import android.widget.ArrayAdapter;
12
import android.widget.BaseAdapter;
13
import android.widget.Button;
14
import android.widget.EditText;
15
import android.widget.LinearLayout;
16
import android.widget.ListView;
17
import android.widget.TextView;
18
19
import java.util.ArrayList;
20
import java.util.Arrays;
21
22
import com.example.naabi.listeserie.dao.SerialisationSerieDAO;
23
import com.example.naabi.listeserie.modele.Acteur;
24
import com.example.naabi.listeserie.modele.Episode;
25
import com.example.naabi.listeserie.modele.Saison;
26
import com.example.naabi.listeserie.modele.Serie;
27
28
public class descriptionMrRobot extends AppCompatActivity implements AdapterView.OnItemClickListener{
29
    private TextView descSerie;
30
    private TextView nomSerie;
31
    private ListView lView1;
32
    private ListView lView2;
33
    private Button bSend;
34
    private ArrayList listeAct = new ArrayList();
35
    private ArrayList listeEpiSai1 = new ArrayList();
36
    private ArrayList listeEpiSai2 = new ArrayList();
37
    private String[] listeSai = {" 1", " 2"};
38
    private String description = new String();
39
    private String nom = new String();
40
    SerialisationSerieDAO dao = SerialisationSerieDAO.getInstance();
41
42
43
44
45
    //########1ere saison##########
46
    Episode ep1 = new Episode("1", "eps1.0_hellofriend.mov");
47
    Episode ep2 = new Episode("2", "eps1.1_ones-and-zer0es.mpeg");
48
    Episode ep3 = new Episode("3", "eps1.2_d3bug.mkv");
49
    Episode ep4 = new Episode("4", "eps1.3_da3m0ns.mp4");
50
    Episode ep5 = new Episode("5", "eps1.4_3xpl0its.wmv");
51
    Episode ep6 = new Episode("6", "eps1.5_br4ve-trave1er.asf");
52
    Episode ep7 = new Episode("7", "eps1.6_v1ew-s0urce.flv");
53
    Episode ep8 = new Episode("8", "eps1.7_wh1ter0se.m4v");
54
    Episode ep9 = new Episode("9", "eps1.8_m1rr0r1ng.qt");
55
    Episode ep10 = new Episode("10", "eps1.9_zer0-day.avi");
56
    ArrayList<Episode> EpS1= new ArrayList();
57
    //#############################
58
59
    //########acteurs##############
60
    Acteur ac1 = new Acteur("1", "Rami Malek");
61
    Acteur ac2 = new Acteur("2", "Carly Chaikins");
62
    Acteur ac3 = new Acteur("3", "Cristian Slater");
63
    Acteur ac4 = new Acteur("4", "Portia DoubleDay");
64
    ArrayList<Acteur> LAct = new ArrayList();
65
    //#############################
66
67
    //########Série################
68
    ArrayList<Saison> listeSais1 = new ArrayList();
69
    ArrayList<Serie> listeAllSerie = new ArrayList();
70
    //#############################
71
    @Override
72
    protected void onCreate(Bundle savedInstanceState) {
73
        Log.i("Passage","Passage dans le onCreate");
74
        super.onCreate(savedInstanceState);
75
        setContentView(R.layout.activity_description_mr_robot);
76
        description = getResources().getString(R.string.descSerie);
77
        nom = getResources().getString(R.string.nomSerie);
78
        restoreMe(savedInstanceState);
79
        listeAct.addAll(Arrays.asList(getResources().getStringArray(R.array.acteur)));
80
        listeEpiSai1.addAll(Arrays.asList(getResources().getStringArray(R.array.epiSaison1)));
81
        listeEpiSai2.addAll(Arrays.asList(getResources().getStringArray(R.array.epiSaison2)));
82
        for (int i=0; i < listeSai.length; i++) {
83
            listeSai[i]= this.getResources().getString(R.string.saison) + listeSai[i];
84
        }
85
86
87
        EpS1.add(ep1);
88
        EpS1.add(ep2);
89
        EpS1.add(ep3);
90
        EpS1.add(ep4);
91
        EpS1.add(ep5);
92
        EpS1.add(ep6);
93
        EpS1.add(ep7);
94
        EpS1.add(ep8);
95
        EpS1.add(ep9);
96
        EpS1.add(ep10);
97
        LAct.add(ac1);
98
        LAct.add(ac2);
99
        LAct.add(ac3);
100
        LAct.add(ac4);
101
102
        Saison s1 = new Saison("1",EpS1);
103
        listeSais1.add(s1);
104
        Serie ser1 = new Serie(listeSais1, LAct, "1", "mrrobot", "Ceci est une courte description", "Mr Robot");
105
        listeAllSerie.add(ser1);
106
    }
107
108
    @Override
109
    public void onStart() {
110
        Log.i("Passage","Passage dans le onStart");
111
        super.onStart();
112
113
        final ArrayAdapter<String> adapteracteur = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1, listeAct);
114
        final ArrayAdapter<String> adaptersaison = new ArrayAdapter<>(this,android.R.layout.simple_list_item_single_choice, listeSai);
115
116
        //#############FINDBYID################
117
        this.lView1 = (ListView) findViewById(R.id.listeSaison);
118
        this.lView2 = (ListView) findViewById(R.id.acteurSerie);
119
        this.nomSerie = (TextView) findViewById(R.id.nomSerie);
120
        this.descSerie = (TextView) findViewById(R.id.descSerie);
121
        this.bSend = (Button) findViewById(R.id.bEnv);
122
        //#####################################
123
124
        //#######RECUPVARIABLE#################
125
        descSerie.setText(description);
126
        nomSerie.setText(nom);
127
        //#####################################
128
129
130
        lView1.setAdapter(adaptersaison);
131
        lView1.setItemChecked(0, true);
132
        lView1.setOnTouchListener(new View.OnTouchListener() {
133
            @Override
134
            public boolean onTouch(View v, MotionEvent ACTION_UP) {
135
                v.getParent().requestDisallowInterceptTouchEvent(true);
136
                return false;
137
            }
138
        });
139
140
        lView2.setAdapter(adapteracteur);
141
        lView2.setItemChecked(0, true);
142
        lView2.setOnTouchListener(new View.OnTouchListener() {
143
            // Setting on Touch Listener for handling the touch inside ScrollView
144
            @Override
145
            public boolean onTouch(View v, MotionEvent ACTION_UP) {
146
                // Disallow the touch request for parent scroll on touch of child view
147
                v.getParent().requestDisallowInterceptTouchEvent(true);
148
                return false;
149
            }
150
        });
151
152
153
        //#############LISTENER################
154
        lView1.setOnItemClickListener(this);
155
156
        lView2.setOnLongClickListener(new View.OnLongClickListener() {
157
            @Override
158
            public boolean onLongClick(View v) {
159
                final AlertDialog.Builder fenetreConstruct = new AlertDialog.Builder(descriptionMrRobot.this);
160
                fenetreConstruct.setTitle("Editeur");
161
                fenetreConstruct.setMessage("Zone d'édition");
162
                fenetreConstruct.setCancelable(false);
163
                final EditText input = new EditText(descriptionMrRobot.this);
164
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
165
                input.setLayoutParams(lp);
166
                fenetreConstruct.setView(input);
167
168
                fenetreConstruct.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
169
                    public void onClick(DialogInterface dialog, int id) {
170
                        lView2.setTag(input.getText());
171
                        ((BaseAdapter) adapteracteur).notifyDataSetChanged();
172
                    }
173
                });
174
175
                fenetreConstruct.setNegativeButton("Annuler",new DialogInterface.OnClickListener() {
176
                    public void onClick(DialogInterface dialog, int id) {
177
                        //Rien pour le moment
178
                    }
179
                });
180
181
                final AlertDialog fenetre = fenetreConstruct.create();
182
                fenetre.show();
183
                return false;
184
            }  });
185
186
        nomSerie.setOnLongClickListener(new View.OnLongClickListener() {
187
            @Override
188
            public boolean onLongClick(View v) {
189
                final AlertDialog.Builder fenetreConstruct = new AlertDialog.Builder(descriptionMrRobot.this);
190
                fenetreConstruct.setTitle("Editeur");
191
                fenetreConstruct.setMessage("Zone d'édition");
192
                fenetreConstruct.setCancelable(false);
193
                final EditText input = new EditText(descriptionMrRobot.this);
194
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
195
                input.setLayoutParams(lp);
196
                fenetreConstruct.setView(input);
197
198
                fenetreConstruct.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
199
                    public void onClick(DialogInterface dialog, int id) {
200
                        nomSerie.setText(input.getText());
201
                    }
202
                });
203
204
                fenetreConstruct.setNegativeButton("Annuler",new DialogInterface.OnClickListener() {
205
                    public void onClick(DialogInterface dialog, int id) {
206
                        //Rien pour le moment
207
                    }
208
                });
209
210
                final AlertDialog fenetre = fenetreConstruct.create();
211
                fenetre.show();
212
                return false;
213
            }  });
214
215
216
        descSerie.setOnLongClickListener(new View.OnLongClickListener() {
217
            @Override
218
            public boolean onLongClick(View v) {
219
                final AlertDialog.Builder fenetreConstruct = new AlertDialog.Builder(descriptionMrRobot.this);
220
                fenetreConstruct.setTitle("Editeur");
221
                fenetreConstruct.setMessage("Zone d'édition");
222
                fenetreConstruct.setCancelable(false);
223
                final EditText input = new EditText(descriptionMrRobot.this);
224
                input.setText(descSerie.getText());
225
                input.setMaxHeight(450);
226
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
227
                input.setLayoutParams(lp);
228
                fenetreConstruct.setView(input);
229
230
                fenetreConstruct.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
231
                    public void onClick(DialogInterface dialog, int id) {
232
                        descSerie.setText(input.getText());
233
                    }
234
                });
235
236
                fenetreConstruct.setNegativeButton("Annuler",new DialogInterface.OnClickListener() {
237
                    public void onClick(DialogInterface dialog, int id) {
238
239
                    }
240
                });
241
242
                final AlertDialog fenetre = fenetreConstruct.create();
243
                fenetre.show();
244
                return false;
245
            }  });
246
    }
247
248
249
250
251
252
253
254
    //#####################################
255
256
257
258
    public void onSaveInstanceState(Bundle saveInstanceState){
259
        Log.i("Passage","Passage dans le onSaveInstanceState");
260
        dao.writeAll(listeAllSerie);
261
        super.onSaveInstanceState(saveInstanceState);
262
        saveInstanceState.putStringArrayList("listeEpi1", listeEpiSai1);
263
        saveInstanceState.putStringArrayList("listeEpi2", listeEpiSai2);
264
        saveInstanceState.putStringArrayList("listeAc", listeAct);
265
        saveInstanceState.putString("descri", descSerie.getText().toString());
266
        saveInstanceState.putString("tit", nomSerie.getText().toString());
267
    }
268
269
270
    private void restoreMe(Bundle state) {
271
        Log.i("Passage","Passage dans le restoreMe");
272
        if (state!=null) {
273
            listeAct.addAll(state.getStringArrayList("listeAc"));
274
            listeEpiSai1.addAll(state.getStringArrayList("listeEpi1"));
275
            listeEpiSai2.addAll(state.getStringArrayList("listeEpi2"));
276
            nom = state.getString("tit");
277
            description = state.getString("descri");
278
279
        }
280
    }
281
282
283
    public void onClickSend(View V) {
284
285
        lView1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, listeSai));
286
        lView1.setItemChecked(0, true);
287
        lView1.setOnItemClickListener(this);
288
        bSend.setVisibility(View.GONE);
289
290
    }
291
292
    @Override
293
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
294
        bSend.setVisibility(View.VISIBLE);
295
        if(position == 0){
296
            lView1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listeEpiSai1));
297
            lView1.setOnTouchListener(new View.OnTouchListener() {
298
                // Setting on Touch Listener for handling the touch inside ScrollView
299
                @Override
300
                public boolean onTouch(View v, MotionEvent ACTION_UP) {
301
                    // Disallow the touch request for parent scroll on touch of child view
302
                    v.getParent().requestDisallowInterceptTouchEvent(true);
303
                    return false;
304
                }
305
            });
306
        }
307
308
        if(position == 1){
309
            lView1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listeEpiSai2));
310
            lView1.setOnTouchListener(new View.OnTouchListener() {
311
                // Setting on Touch Listener for handling the touch inside ScrollView
312
                @Override
313
                public boolean onTouch(View v, MotionEvent ACTION_UP) {
314
                    // Disallow the touch request for parent scroll on touch of child view
315
                    v.getParent().requestDisallowInterceptTouchEvent(true);
316
                    return false;
317
                }
318
            });
319
        }
320
321
    }
322
323
324
325
}
326
327
/* A bosser
328
*/