-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlarmDataManager.java
84 lines (67 loc) · 3.71 KB
/
AlarmDataManager.java
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
package com.example.user.standartaalarmclock;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
public class AlarmDataManager {
private Context context;
private AlarmDataHelper alarmDataHelper;
private SQLiteDatabase sqLiteDatabase;
public AlarmDataManager(Context context) {
this.context = context;
alarmDataHelper=new AlarmDataHelper(context);
}
public long addAlarmData(AlarmDataClass alarmDataClass){
open();
ContentValues contentValues=new ContentValues();
contentValues.put(AlarmDataHelper.COLUMN_ALARM_NAME,alarmDataClass.getAlarm_Name());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_HOURE,alarmDataClass.getAlarm_Houre());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_MINUTE,alarmDataClass.getAlarm_Minute());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_FORMATE,alarmDataClass.getTime_Formate());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_DAY,alarmDataClass.getAlarm_Day());
long insertedRow=sqLiteDatabase.insert(AlarmDataHelper.TABLE_ALARM,null,contentValues);
sqLiteDatabase.close();
return insertedRow;
}
public long updateAlarmTime(AlarmDataClass alarmDataClass){
open();
ContentValues contentValues=new ContentValues();
contentValues.put(AlarmDataHelper.COLUMN_ALARM_NAME,alarmDataClass.getAlarm_Name());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_HOURE,alarmDataClass.getAlarm_Houre());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_MINUTE,alarmDataClass.getAlarm_Minute());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_FORMATE,alarmDataClass.getTime_Formate());
contentValues.put(AlarmDataHelper.COLUMN_ALARM_DAY,alarmDataClass.getAlarm_Day());
long insertedRow=sqLiteDatabase.update(AlarmDataHelper.TABLE_ALARM,contentValues,AlarmDataHelper.COLUMN_ALARM_ID+" = "+alarmDataClass.getId(),null);
sqLiteDatabase.close();
return insertedRow;
}
public long deleteAlarm(int id){
open();
long deleted=sqLiteDatabase.delete(AlarmDataHelper.TABLE_ALARM,AlarmDataHelper.COLUMN_ALARM_ID+" = "+id,null);
sqLiteDatabase.close();
return deleted;
}
public ArrayList<AlarmDataClass> getAlarmData(){
ArrayList<AlarmDataClass>alarmDataClasses=new ArrayList<>();
open();
String selectQuery="select * from "+AlarmDataHelper.TABLE_ALARM;
Cursor cursor=sqLiteDatabase.rawQuery(selectQuery,null);
if(cursor.moveToFirst()){
do{
AlarmDataClass alarmDataClass=new AlarmDataClass();
alarmDataClass.setId(cursor.getInt(cursor.getColumnIndex(AlarmDataHelper.COLUMN_ALARM_ID)));
alarmDataClass.setAlarm_Name(cursor.getString(cursor.getColumnIndex(AlarmDataHelper.COLUMN_ALARM_NAME)));
alarmDataClass.setAlarm_Houre(cursor.getInt(cursor.getColumnIndex(AlarmDataHelper.COLUMN_ALARM_HOURE)));
alarmDataClass.setAlarm_Minute(cursor.getInt(cursor.getColumnIndex(AlarmDataHelper.COLUMN_ALARM_MINUTE)));
alarmDataClass.setTime_Formate(cursor.getInt(cursor.getColumnIndex(AlarmDataHelper.COLUMN_ALARM_FORMATE)));
alarmDataClass.setAlarm_Day(cursor.getString(cursor.getColumnIndex(AlarmDataHelper.COLUMN_ALARM_DAY)));
alarmDataClasses.add(alarmDataClass);
}while(cursor.moveToNext());
}
return alarmDataClasses;
}
private void open() {
sqLiteDatabase=alarmDataHelper.getWritableDatabase();
}
}