add DB stuff for offline category sync
This commit is contained in:
parent
f02d851533
commit
3063d86667
@ -11,6 +11,7 @@ import org.fox.ttrss.R.drawable;
|
||||
import org.fox.ttrss.R.string;
|
||||
import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.Feed;
|
||||
import org.fox.ttrss.types.FeedCategory;
|
||||
import org.fox.ttrss.util.DatabaseHelper;
|
||||
import org.fox.ttrss.util.ImageCacheService;
|
||||
import org.jsoup.Jsoup;
|
||||
@ -262,6 +263,69 @@ public class OfflineDownloadService extends Service {
|
||||
|
||||
req.execute(map);
|
||||
}
|
||||
|
||||
private void downloadCategories() {
|
||||
|
||||
updateNotification(R.string.notify_downloading_feeds);
|
||||
|
||||
getWritableDb().execSQL("DELETE FROM categories;");
|
||||
|
||||
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
||||
@Override
|
||||
protected void onPostExecute(JsonElement content) {
|
||||
if (content != null) {
|
||||
|
||||
try {
|
||||
Type listType = new TypeToken<List<FeedCategory>>() {}.getType();
|
||||
List<FeedCategory> cats = new Gson().fromJson(content, listType);
|
||||
|
||||
SQLiteStatement stmtInsert = getWritableDb().compileStatement("INSERT INTO categories " +
|
||||
"("+BaseColumns._ID+", title) " +
|
||||
"VALUES (?, ?);");
|
||||
|
||||
for (FeedCategory cat : cats) {
|
||||
stmtInsert.bindLong(1, cat.id);
|
||||
stmtInsert.bindString(2, cat.title);
|
||||
|
||||
stmtInsert.execute();
|
||||
}
|
||||
|
||||
stmtInsert.close();
|
||||
|
||||
Log.d(TAG, "offline: done downloading categories");
|
||||
|
||||
if (m_canProceed) {
|
||||
downloadFeeds();
|
||||
} else {
|
||||
downloadFailed();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
updateNotification(R.string.offline_switch_error);
|
||||
downloadFailed();
|
||||
}
|
||||
|
||||
} else {
|
||||
updateNotification(getErrorMessage());
|
||||
downloadFailed();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
HashMap<String,String> map = new HashMap<String,String>() {
|
||||
{
|
||||
put("op", "getFeeds");
|
||||
put("sid", m_sessionId);
|
||||
put("cat_id", "-3");
|
||||
put("unread_only", "true");
|
||||
}
|
||||
};
|
||||
|
||||
req.execute(map);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
@ -151,6 +151,9 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
list.setEmptyView(view.findViewById(R.id.no_headlines));
|
||||
registerForContextMenu(list);
|
||||
|
||||
if (m_offlineServices.isSmallScreen())
|
||||
view.findViewById(R.id.headlines_fragment).setPadding(0, 0, 0, 0);
|
||||
|
||||
getActivity().setProgressBarIndeterminateVisibility(false);
|
||||
|
||||
return view;
|
||||
|
@ -10,7 +10,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
@SuppressWarnings("unused")
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
public static final String DATABASE_NAME = "OfflineStorage.db";
|
||||
public static final int DATABASE_VERSION = 2;
|
||||
public static final int DATABASE_VERSION = 3;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
@ -18,6 +18,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("DROP TABLE IF EXISTS categories;");
|
||||
db.execSQL("DROP TABLE IF EXISTS feeds;");
|
||||
db.execSQL("DROP TABLE IF EXISTS articles;");
|
||||
db.execSQL("DROP VIEW IF EXISTS feeds_unread;");
|
||||
@ -31,6 +32,11 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
"cat_id INTEGER" +
|
||||
");");
|
||||
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS categories (" +
|
||||
BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"title TEXT" +
|
||||
");");
|
||||
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS articles (" +
|
||||
BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"unread BOOLEAN, " +
|
||||
|
Loading…
Reference in New Issue
Block a user