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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
| package com.jifisher.dnevnik;
public class HomeworkActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
public static int step = 2;
public static String[] day;
public static String[] lesson;
public static String[] homework;
public static String[] mark;
public static String[] time;
public static String _day = "day";
public static String _lesson = "lesson";
public static String _homework = "homework";
public static String _mark = "mark";
public static String _time = "time";
ListView lvHomework;
public static Calendar calStep1;
DB db;
SimpleCursorAdapter scAdapter;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homework);
final DB db = new DB(this);
db.open();
final Calendar calendar = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
dayOfWeek--;
if (dayOfWeek == 0) {
dayOfWeek = 7;
}
calendar.add(Calendar.DAY_OF_MONTH, -dayOfWeek + 1);
cal.add(Calendar.DAY_OF_MONTH, -dayOfWeek + 1);
cal.add(Calendar.DAY_OF_MONTH, -7);
calendar.add(Calendar.DAY_OF_MONTH, 14);
selectionDay(cal, calendar);
//selectionThreeWeek();
lvHomework = (ListView) findViewById(R.id.lvHomework);
lvHomework.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Scanner scanner;
switch (step) {
case 1:
break;
case 2:
Log.d(FerialActivity.LOG_TAG,"Начинаем настройку");
scanner = new Scanner(day[(int) id]);
int dayBegin = scanner.nextInt();
String month = scanner.next();
int monthBegin;
int i = 0;
if (month.equals("января")) {
i = 0;
} else {
if (month.equals("февраля")) {
i = 1;
} else {
if (month.equals("марта")) {
i = 2;
} else {
if (month.equals("апреля")) {
i = 3;
} else {
if (month.equals("мая")) {
i = 4;
} else {
if (month.equals("июня")) {
i = 5;
} else {
if (month.equals("июля")) {
i = 6;
} else {
if (month.equals("августа")) {
i = 7;
} else {
if (month.equals("сентября")) {
i = 8;
} else {
if (month.equals("октября")) {
i = 9;
monthBegin = i;
Log.d(FerialActivity.LOG_TAG,"Узнали дату");
int yearBegin = scanner.nextInt();
calStep1=new GregorianCalendar(yearBegin, monthBegin, dayBegin);
selectionLesson(new GregorianCalendar(yearBegin, monthBegin, dayBegin));
break;
case 3:
scanner = new Scanner(day[(int) id]);
step=2;
dayBegin = scanner.nextInt();
month = scanner.next();
i = 0;
monthBegin = i;
yearBegin = scanner.nextInt();
String str = scanner.next();
int dayEnd = scanner.nextInt();
month = scanner.next();
int monthEnd;
i = 0;
monthEnd = i;
int yearEnd = scanner.nextInt();
Calendar cal = new GregorianCalendar(yearBegin, monthBegin, dayBegin);
Calendar calendar = new GregorianCalendar(yearEnd, monthEnd, dayEnd);
selectionDay(cal, calendar);
break;
}
}
});
}
@RequiresApi(api = Build.VERSION_CODES.N)
public void selectionDay(Calendar cal, Calendar calendar) {
int i = 1;
day = new String[23];
Arrays.fill(day, "");
day[0] = getString(R.string.selectionDay);
calendar.add(Calendar.DAY_OF_MONTH, 1);
Log.d(FerialActivity.LOG_TAG, cal.get(Calendar.DAY_OF_MONTH) + "." + cal.get(Calendar.MONTH) + "." + cal.get(Calendar.YEAR));
Log.d(FerialActivity.LOG_TAG, calendar.get(Calendar.DAY_OF_MONTH) + "." + calendar.get(Calendar.MONTH) + "." + calendar.get(Calendar.YEAR));
while (cal.before(calendar)) {
day[i] = cal.get(Calendar.DAY_OF_MONTH) + " ";
day[i] += " " + cal.get(Calendar.YEAR);
Log.d(FerialActivity.LOG_TAG, day[i]);
i++;
cal.add(Calendar.DAY_OF_MONTH, 1);
}
ListView lvHomework = (ListView) findViewById(R.id.lvHomework);
Log.d(FerialActivity.LOG_TAG, "homework заполняем arrayList");
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(
day.length);
Map<String, Object> m;
for (int j = 0; j < day.length; j++) {
m = new HashMap<String, Object>();
m.put(_day, day[j]);
Log.d(FerialActivity.LOG_TAG, day[j]);
data.add(m);
}
Log.d(FerialActivity.LOG_TAG, "заполнили массив");
String[] from = {_day};
int[] to = {R.id.textViewDayMonth};
SimpleAdapter sAdapter = new SimpleAdapter(HomeworkActivity.this, data, R.layout.selection_day_month_list_view, from, to);
lvHomework.setAdapter(sAdapter);
}
@RequiresApi(api = Build.VERSION_CODES.N)
public void selectionThreeWeek() {
day = new String[44];
Calendar calendar = new GregorianCalendar(2016, 8, 1);
Calendar cal = new GregorianCalendar(2016, 8, 1);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
dayOfWeek--;
if (dayOfWeek == 0) {
dayOfWeek = 7;
}
calendar.add(Calendar.DAY_OF_MONTH, -dayOfWeek + 1);
cal.add(Calendar.DAY_OF_MONTH, -dayOfWeek + 1);
calendar.add(Calendar.DAY_OF_MONTH, 20);
int i = 1;
Arrays.fill(day, "");
day[0] = getString(R.string.selectionThreeWeek);
Log.d(FerialActivity.LOG_TAG, cal.get(Calendar.DAY_OF_MONTH) + "." + cal.get(Calendar.MONTH) + "." + cal.get(Calendar.YEAR));
Log.d(FerialActivity.LOG_TAG, calendar.get(Calendar.DAY_OF_MONTH) + "." + calendar.get(Calendar.MONTH) + "." + calendar.get(Calendar.YEAR));
Calendar calEnd = new GregorianCalendar(2017, 6, 3);
while (calendar.before(calEnd)) {
day[i] = cal.get(Calendar.DAY_OF_MONTH) + " ";
switch (cal.get(Calendar.MONTH)) {
case 0:
day[i] += "января ";
break;
case 1:
day[i] += "февраля ";
break;
case 2:
day[i] += "марта ";
break;
case 3:
day[i] += "апреля ";
break;
case 4:
day[i] += "мая ";
break;
case 5:
day[i] += "июня ";
break;
case 6:
day[i] += "июля ";
break;
case 7:
day[i] += "августа ";
break;
case 8:
day[i] += "сентября ";
break;
case 9:
day[i] += "октября ";
break;
case 10:
day[i] += "ноября ";
break;
case 11:
day[i] += "декабря ";
break;
}
day[i] += " " + cal.get(Calendar.YEAR) + " - " + "\n";
day[i] += calendar.get(Calendar.DAY_OF_MONTH) + " ";
switch (calendar.get(Calendar.MONTH)) {
case 0:
day[i] += "января ";
break;
case 1:
day[i] += "февраля ";
break;
case 2:
day[i] += "марта ";
break;
case 3:
day[i] += "апреля ";
break;
case 4:
day[i] += "мая ";
break;
case 5:
day[i] += "июня ";
break;
case 6:
day[i] += "июля ";
break;
case 7:
day[i] += "августа ";
break;
case 8:
day[i] += "сентября ";
break;
case 9:
day[i] += "октября ";
break;
case 10:
day[i] += "ноября ";
break;
case 11:
day[i] += "декабря ";
break;
}
day[i] += " " + calendar.get(Calendar.YEAR);
Log.d(FerialActivity.LOG_TAG, day[i]);
i++;
cal.add(Calendar.DAY_OF_MONTH, 7);
calendar.add(Calendar.DAY_OF_MONTH, 7);
}
ListView lvHomework = (ListView) findViewById(R.id.lvHomework);
Log.d(FerialActivity.LOG_TAG, "homework заполняем arrayList");
homework = new String[22];
Arrays.fill(homework, "");
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(
day.length);
Map<String, Object> m;
for (int j = 0; j < day.length; j++) {
m = new HashMap<String, Object>();
m.put(_day, day[j]);
Log.d(FerialActivity.LOG_TAG, day[j]);
data.add(m);
}
Log.d(FerialActivity.LOG_TAG, "заполнили массив");
String[] from = {_day};
int[] to = {R.id.textViewDayMonth};
SimpleAdapter sAdapter = new SimpleAdapter(HomeworkActivity.this, data, R.layout.selection_day_month_list_view, from, to);
lvHomework.setAdapter(sAdapter);
}
@RequiresApi(api = Build.VERSION_CODES.N)
public void selectionLesson(Calendar calendar) {
String[] from = {DB.COLUMN_LESSONS, DB.COLUMN_HOMEWORK_SHORT, DB.COLUMN_MARK};
int[] to={R.id.textViewNameLesson,R.id.textViewHomeworkShort,R.id.textViewMark};
scAdapter = new SimpleCursorAdapter(HomeworkActivity.this, R.layout.selection_lesson_list_view, null, from, to, 0);
step=1;
lvHomework.setAdapter(scAdapter);
getSupportLoaderManager().initLoader(0, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle bndl) {
return new MyCursorLoader(this, db);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
Log.d(FerialActivity.LOG_TAG, "запрос OnLoadFinisher");
scAdapter.swapCursor(cursor);
Log.d(FerialActivity.LOG_TAG, "OnLoadFinisher выполнен");
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
}
static class MyCursorLoader extends CursorLoader {
DB db;
public MyCursorLoader(Context context, DB db) {
super(context);
this.db = db;
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public Cursor loadInBackground() {
Log.d(FerialActivity.LOG_TAG, "запрос курсора");
Cursor cursor = db.getAllData(new String[]{calStep1.get(Calendar.DAY_OF_MONTH) + "." + calStep1.get(Calendar.MONTH) + "." + calStep1.get(Calendar.YEAR)});
Log.d(FerialActivity.LOG_TAG, "курсор выдан");
return cursor;
}
}
} |