properly sort feedlist by unread, misc cleanup
This commit is contained in:
parent
581f79b3c1
commit
5178ba7287
@ -4,12 +4,6 @@
|
|||||||
|
|
||||||
<group android:id="@+id/menu_group_feeds" >
|
<group android:id="@+id/menu_group_feeds" >
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/go_offline"
|
|
||||||
android:icon="@drawable/ic_menu_cloud"
|
|
||||||
android:showAsAction="ifRoom|withText"
|
|
||||||
android:title="@string/go_offline"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/back_to_categories"
|
android:id="@+id/back_to_categories"
|
||||||
android:icon="@android:drawable/ic_menu_close_clear_cancel"
|
android:icon="@android:drawable/ic_menu_close_clear_cancel"
|
||||||
@ -25,9 +19,15 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/update_feeds"
|
android:id="@+id/update_feeds"
|
||||||
android:icon="@android:drawable/ic_menu_rotate"
|
android:icon="@android:drawable/ic_menu_rotate"
|
||||||
android:showAsAction=""
|
android:showAsAction="ifRoom|"
|
||||||
android:title="@string/update_feeds"/>
|
android:title="@string/update_feeds"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/go_offline"
|
||||||
|
android:icon="@drawable/ic_menu_cloud"
|
||||||
|
android:showAsAction="ifRoom|withText"
|
||||||
|
android:title="@string/go_offline"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/logout"
|
android:id="@+id/logout"
|
||||||
android:icon="@drawable/ic_menu_exit"
|
android:icon="@drawable/ic_menu_exit"
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</group>
|
</group>
|
||||||
|
|
||||||
<group android:id="@+id/menu_group_headlines" >
|
<group android:id="@+id/menu_group_headlines" >
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/go_offline"
|
android:id="@+id/go_offline"
|
||||||
android:icon="@drawable/ic_menu_cloud"
|
android:icon="@drawable/ic_menu_cloud"
|
||||||
@ -46,6 +46,7 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/headlines_mark_as_read"
|
android:id="@+id/headlines_mark_as_read"
|
||||||
android:icon="@drawable/ic_menu_tick"
|
android:icon="@drawable/ic_menu_tick"
|
||||||
|
android:showAsAction=""
|
||||||
android:title="@string/headlines_mark_as_read"/>
|
android:title="@string/headlines_mark_as_read"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
|
@ -20,12 +20,6 @@
|
|||||||
android:icon="@android:drawable/ic_menu_agenda"
|
android:icon="@android:drawable/ic_menu_agenda"
|
||||||
android:showAsAction=""
|
android:showAsAction=""
|
||||||
android:title="@string/menu_all_feeds"/>
|
android:title="@string/menu_all_feeds"/>
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/logout"
|
|
||||||
android:icon="@drawable/ic_menu_exit"
|
|
||||||
android:showAsAction=""
|
|
||||||
android:title="@string/logout"/>
|
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<group android:id="@+id/menu_group_headlines" >
|
<group android:id="@+id/menu_group_headlines" >
|
||||||
|
@ -101,4 +101,5 @@
|
|||||||
<string name="dialog_offline_go">Go offline</string>
|
<string name="dialog_offline_go">Go offline</string>
|
||||||
<string name="dialog_cancel">Cancel</string>
|
<string name="dialog_cancel">Cancel</string>
|
||||||
<string name="syncing_offline_data">Synchronizing offline data...</string>
|
<string name="syncing_offline_data">Synchronizing offline data...</string>
|
||||||
|
<string name="dialog_offline_switch_prompt">Download unread articles and go offline?</string>
|
||||||
</resources>
|
</resources>
|
@ -42,6 +42,9 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
|
|
||||||
public class MainActivity extends FragmentActivity implements FeedsFragment.OnFeedSelectedListener, ArticleOps, FeedCategoriesFragment.OnCatSelectedListener {
|
public class MainActivity extends FragmentActivity implements FeedsFragment.OnFeedSelectedListener, ArticleOps, FeedCategoriesFragment.OnCatSelectedListener {
|
||||||
private final String TAG = this.getClass().getSimpleName();
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
|
|
||||||
|
private final int OFFLINE_SYNC_SEQ = 60;
|
||||||
|
private final int OFFLINE_SYNC_MAX = 500;
|
||||||
|
|
||||||
private SharedPreferences m_prefs;
|
private SharedPreferences m_prefs;
|
||||||
private String m_themeName = "";
|
private String m_themeName = "";
|
||||||
@ -466,7 +469,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
put("view_mode", "unread");
|
put("view_mode", "unread");
|
||||||
put("show_content", "true");
|
put("show_content", "true");
|
||||||
put("skip", String.valueOf(m_articleOffset));
|
put("skip", String.valueOf(m_articleOffset));
|
||||||
put("limit", "30");
|
put("limit", String.valueOf(OFFLINE_SYNC_SEQ));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -475,76 +478,93 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void switchOffline() {
|
public void switchOffline() {
|
||||||
Log.d(TAG, "offline: starting");
|
|
||||||
|
|
||||||
if (m_sessionId != null) {
|
AlertDialog.Builder builder = new AlertDialog.Builder(this).
|
||||||
|
setMessage(R.string.dialog_offline_switch_prompt).
|
||||||
findViewById(R.id.loading_container).setVisibility(View.VISIBLE);
|
setPositiveButton(R.string.dialog_offline_go, new Dialog.OnClickListener() {
|
||||||
findViewById(R.id.main).setVisibility(View.INVISIBLE);
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
|
||||||
setLoadingStatus(R.string.offline_downloading, true);
|
|
||||||
|
|
||||||
// Download feeds
|
|
||||||
|
|
||||||
getWritableDb().execSQL("DELETE FROM feeds;");
|
|
||||||
|
|
||||||
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(JsonElement content) {
|
|
||||||
if (content != null) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Type listType = new TypeToken<List<Feed>>() {}.getType();
|
|
||||||
List<Feed> feeds = new Gson().fromJson(content, listType);
|
|
||||||
|
|
||||||
SQLiteStatement stmtInsert = getWritableDb().compileStatement("INSERT INTO feeds " +
|
|
||||||
"("+BaseColumns._ID+", title, feed_url, has_icon, cat_id) " +
|
|
||||||
"VALUES (?, ?, ?, ?, ?);");
|
|
||||||
|
|
||||||
for (Feed feed : feeds) {
|
|
||||||
stmtInsert.bindLong(1, feed.id);
|
|
||||||
stmtInsert.bindString(2, feed.title);
|
|
||||||
stmtInsert.bindString(3, feed.feed_url);
|
|
||||||
stmtInsert.bindLong(4, feed.has_icon ? 1 : 0);
|
|
||||||
stmtInsert.bindLong(5, feed.cat_id);
|
|
||||||
|
|
||||||
stmtInsert.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
stmtInsert.close();
|
|
||||||
|
|
||||||
Log.d(TAG, "offline: done downloading feeds");
|
|
||||||
|
|
||||||
m_articleOffset = 0;
|
|
||||||
|
|
||||||
getWritableDb().execSQL("DELETE FROM articles;");
|
|
||||||
|
|
||||||
offlineGetArticles();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
setLoadingStatus(R.string.offline_switch_error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Log.d(TAG, "offline: starting");
|
||||||
|
|
||||||
|
if (m_sessionId != null) {
|
||||||
|
|
||||||
|
findViewById(R.id.loading_container).setVisibility(View.VISIBLE);
|
||||||
|
findViewById(R.id.main).setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
setLoadingStatus(R.string.offline_downloading, true);
|
||||||
|
|
||||||
|
// Download feeds
|
||||||
|
|
||||||
|
getWritableDb().execSQL("DELETE FROM feeds;");
|
||||||
|
|
||||||
|
ApiRequest req = new ApiRequest(getApplicationContext()) {
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(JsonElement content) {
|
||||||
|
if (content != null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Type listType = new TypeToken<List<Feed>>() {}.getType();
|
||||||
|
List<Feed> feeds = new Gson().fromJson(content, listType);
|
||||||
|
|
||||||
|
SQLiteStatement stmtInsert = getWritableDb().compileStatement("INSERT INTO feeds " +
|
||||||
|
"("+BaseColumns._ID+", title, feed_url, has_icon, cat_id) " +
|
||||||
|
"VALUES (?, ?, ?, ?, ?);");
|
||||||
|
|
||||||
|
for (Feed feed : feeds) {
|
||||||
|
stmtInsert.bindLong(1, feed.id);
|
||||||
|
stmtInsert.bindString(2, feed.title);
|
||||||
|
stmtInsert.bindString(3, feed.feed_url);
|
||||||
|
stmtInsert.bindLong(4, feed.has_icon ? 1 : 0);
|
||||||
|
stmtInsert.bindLong(5, feed.cat_id);
|
||||||
|
|
||||||
|
stmtInsert.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
stmtInsert.close();
|
||||||
|
|
||||||
|
Log.d(TAG, "offline: done downloading feeds");
|
||||||
|
|
||||||
|
m_articleOffset = 0;
|
||||||
|
|
||||||
|
getWritableDb().execSQL("DELETE FROM articles;");
|
||||||
|
|
||||||
|
offlineGetArticles();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
setLoadingStatus(R.string.offline_switch_error, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setLoadingStatus(getErrorMessage(), false);
|
||||||
|
// TODO error, could not download feeds, properly report API error (toast)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
} else {
|
} else {
|
||||||
setLoadingStatus(getErrorMessage(), false);
|
switchOfflineSuccess();
|
||||||
// TODO error, could not download feeds, properly report API error (toast)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}).
|
||||||
|
setNegativeButton(R.string.dialog_cancel, new Dialog.OnClickListener() {
|
||||||
HashMap<String,String> map = new HashMap<String,String>() {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
{
|
//
|
||||||
put("op", "getFeeds");
|
}
|
||||||
put("sid", m_sessionId);
|
});
|
||||||
put("cat_id", "-3");
|
|
||||||
put("unread_only", "true");
|
AlertDialog dlg = builder.create();
|
||||||
}
|
dlg.show();
|
||||||
};
|
|
||||||
|
|
||||||
req.execute(map);
|
|
||||||
} else {
|
|
||||||
switchOfflineSuccess();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchOfflineSuccess() {
|
public void switchOfflineSuccess() {
|
||||||
@ -746,10 +766,9 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
case R.id.headlines_select:
|
case R.id.headlines_select:
|
||||||
if (hf != null) {
|
if (hf != null) {
|
||||||
Dialog dialog = new Dialog(this);
|
Dialog dialog = new Dialog(this);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
builder.setTitle(R.string.headlines_select_dialog);
|
.setTitle(R.string.headlines_select_dialog)
|
||||||
|
.setSingleChoiceItems(new String[] { getString(R.string.headlines_select_all),
|
||||||
builder.setSingleChoiceItems(new String[] { getString(R.string.headlines_select_all),
|
|
||||||
getString(R.string.headlines_select_unread), getString(R.string.headlines_select_none) }, 0, new DialogInterface.OnClickListener() {
|
getString(R.string.headlines_select_unread), getString(R.string.headlines_select_none) }, 0, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
@ -1796,7 +1815,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
|
|
||||||
Log.d(TAG, "offline: received " + articles.size() + " articles");
|
Log.d(TAG, "offline: received " + articles.size() + " articles");
|
||||||
|
|
||||||
if (articles.size() == 30 && m_articleOffset < 500) {
|
if (articles.size() == OFFLINE_SYNC_SEQ && m_articleOffset < OFFLINE_SYNC_MAX) {
|
||||||
offlineGetArticles();
|
offlineGetArticles();
|
||||||
} else {
|
} else {
|
||||||
switchOfflineSuccess();
|
switchOfflineSuccess();
|
||||||
|
@ -56,8 +56,10 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene
|
|||||||
public Cursor createCursor() {
|
public Cursor createCursor() {
|
||||||
String unreadOnly = ((OfflineActivity)getActivity()).getUnreadOnly() ? "unread > 0" : null;
|
String unreadOnly = ((OfflineActivity)getActivity()).getUnreadOnly() ? "unread > 0" : null;
|
||||||
|
|
||||||
|
String order = m_prefs.getBoolean("sort_feeds_by_unread", false) ? "unread DESC, title" : "title";
|
||||||
|
|
||||||
return ((OfflineActivity)getActivity()).getReadableDb().query("feeds_unread",
|
return ((OfflineActivity)getActivity()).getReadableDb().query("feeds_unread",
|
||||||
null, unreadOnly, null, null, null, "title");
|
null, unreadOnly, null, null, null, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
Loading…
Reference in New Issue
Block a user