-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #823 from freedom0/master
- Loading branch information
Showing
2 changed files
with
449 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903220/RSS_listManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903220; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
import java.util.Calendar; | ||
|
||
|
||
public class RSS_listManager { | ||
|
||
private static final String DATABASE_NAME = "RSSDB"; | ||
private static final int DATABASE_VERSION = 1; | ||
private static final String TABLE_NAME = "RSSLIST"; | ||
|
||
private Context _context; | ||
private RSSHelper rHelper; | ||
private SQLiteDatabase sDatabase; | ||
|
||
public RSS_listManager(Context ct) { | ||
this._context = ct; | ||
} | ||
|
||
public class RSSHelper extends SQLiteOpenHelper { | ||
|
||
public RSSHelper(Context context) { | ||
super(context, DATABASE_NAME, null, DATABASE_VERSION); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL("create table " + TABLE_NAME + " (" + RSS_mlist._ID | ||
+ " integer primary key autoincrement," + RSS_mlist.title | ||
+ " text not null," + RSS_mlist.link + " text not null," | ||
+ RSS_mlist.date + " text not null);"); | ||
|
||
ContentValues cValues = new ContentValues(); | ||
cValues.put(RSS_mlist.title, RSS_mlist.TITLE); | ||
cValues.put(RSS_mlist.link, RSS_mlist.LINK); | ||
Calendar calendar = Calendar.getInstance(); | ||
String date = calendar.get(Calendar.YEAR) + "Äê" | ||
+ calendar.get(Calendar.MONTH) + "ÔÂ" | ||
|
||
+ calendar.get(Calendar.HOUR_OF_DAY) | ||
+ calendar.get(Calendar.MINUTE); | ||
cValues.put(RSS_mlist.date, date); | ||
|
||
db.insert(TABLE_NAME, null, cValues); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
public boolean Open() { | ||
rHelper = new RSSHelper(this._context); | ||
|
||
return true; | ||
} | ||
|
||
|
||
public void Close() { | ||
if (rHelper != null) { | ||
rHelper.close(); | ||
} | ||
} | ||
|
||
|
||
public boolean insertDate(String title, String link) { | ||
ContentValues cValues = new ContentValues(); | ||
cValues.put(RSS_mlist.title, title); | ||
cValues.put(RSS_mlist.link, link); | ||
|
||
Calendar calendar = Calendar.getInstance(); | ||
String date = calendar.get(Calendar.YEAR) + "Äê" | ||
+ calendar.get(Calendar.MONTH) + "ÔÂ" | ||
|
||
+ calendar.get(Calendar.HOUR_OF_DAY) | ||
+ calendar.get(Calendar.MINUTE); | ||
cValues.put(RSS_mlist.date, date); | ||
|
||
sDatabase = rHelper.getWritableDatabase(); | ||
return sDatabase.insert(TABLE_NAME, null, cValues) > 0; | ||
|
||
} | ||
|
||
|
||
public boolean deleteDate(long id) { | ||
sDatabase = rHelper.getWritableDatabase(); | ||
return sDatabase.delete(TABLE_NAME, RSS_mlist._ID + "=" + id, null) > 0; | ||
} | ||
|
||
|
||
public boolean updateDate(long id, String title, String link) { | ||
System.out.println("YES"); | ||
sDatabase = rHelper.getWritableDatabase(); | ||
ContentValues cValues = new ContentValues(); | ||
cValues.put(RSS_mlist.title, title); | ||
cValues.put(RSS_mlist.link, link); | ||
System.out.println("NO"); | ||
return sDatabase.update(TABLE_NAME, cValues, RSS_mlist._ID + "=" + id, | ||
null) > 0; | ||
} | ||
|
||
|
||
public Cursor selectDate() { | ||
sDatabase = rHelper.getReadableDatabase(); | ||
return sDatabase.query(TABLE_NAME, new String[] { RSS_mlist._ID, | ||
RSS_mlist.title, RSS_mlist.link, RSS_mlist.date }, null, null, | ||
null, null, null); | ||
} | ||
|
||
|
||
public Cursor selectDate(long id) { | ||
sDatabase = rHelper.getReadableDatabase(); | ||
Cursor cursor = sDatabase.query(TABLE_NAME, | ||
new String[] { RSS_mlist._ID, RSS_mlist.title, RSS_mlist.link, | ||
RSS_mlist.date }, RSS_mlist._ID + "=" + id, null, null, | ||
null, null); | ||
if (cursor != null) { | ||
cursor.moveToFirst(); | ||
} | ||
return cursor; | ||
} | ||
|
||
|
||
public Cursor selectDateDesc() { | ||
sDatabase = rHelper.getReadableDatabase(); | ||
Cursor cursor = sDatabase.query(TABLE_NAME, | ||
new String[] { RSS_mlist._ID, RSS_mlist.title, RSS_mlist.link, | ||
RSS_mlist.date }, null, null, null, | ||
null, RSS_mlist._ID+" desc"); | ||
if (cursor != null) { | ||
cursor.moveToFirst(); | ||
} | ||
return cursor; | ||
} | ||
|
||
} |
Oops, something went wrong.