more offline functionality stuff

This commit is contained in:
Andrew Dolgov 2012-09-17 16:57:02 +04:00
parent 4eac5b73bb
commit 3fd63d640a
5 changed files with 281 additions and 29 deletions

View File

@ -43,11 +43,11 @@
android:icon="@drawable/ic_menu_database"
android:showAsAction="ifRoom"
android:title="@string/headlines_select"/>
<item
<!-- <item
android:id="@+id/close_feed"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction=""
android:title="@string/close_feed"/>
android:title="@string/close_feed"/> -->
</group>
<group android:id="@+id/menu_group_headlines_selection" >
<item
@ -97,11 +97,11 @@
android:id="@+id/catchup_above"
android:icon="@drawable/ic_menu_tick"
android:title="@string/article_mark_read_above"/>
<item
<!-- <item
android:id="@+id/close_article"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction=""
android:title="@string/close_article"/>
android:title="@string/close_article"/> -->
</group>
<item

View File

@ -1,12 +1,20 @@
package org.fox.ttrss.offline;
import javax.crypto.spec.OAEPParameterSpec;
import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
@ -15,6 +23,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
public class OfflineActivity extends CommonActivity {
private final String TAG = this.getClass().getSimpleName();
@ -68,11 +77,226 @@ public class OfflineActivity extends CommonActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item) {
final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_HEADLINES);
final OfflineFeedsFragment off = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_FEEDS);
final OfflineFeedCategoriesFragment ocf = (OfflineFeedCategoriesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_CATS);
final OfflineArticlePager oap = (OfflineArticlePager) getSupportFragmentManager()
.findFragmentByTag(FRAG_ARTICLE);
switch (item.getItemId()) {
case R.id.go_online:
switchOnline();
return true;
return true;
case R.id.search:
if (ohf != null && isCompatMode()) {
Dialog dialog = new Dialog(this);
final EditText edit = new EditText(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.search)
.setPositiveButton(getString(R.string.search),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
String query = edit.getText().toString().trim();
ohf.setSearchQuery(query);
}
})
.setNegativeButton(getString(R.string.cancel),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
//
}
}).setView(edit);
dialog = builder.create();
dialog.show();
}
return true;
case R.id.preferences:
Intent intent = new Intent(this, PreferencesActivity.class);
startActivityForResult(intent, 0);
return true;
case R.id.headlines_select:
if (ohf != null) {
Dialog dialog = new Dialog(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.headlines_select_dialog);
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() {
@Override
public void onClick(DialogInterface dialog,
int which) {
switch (which) {
case 0:
SQLiteStatement stmtSelectAll = getWritableDb()
.compileStatement(
"UPDATE articles SET selected = 1 WHERE feed_id = ?");
stmtSelectAll.bindLong(1, ohf.getFeedId());
stmtSelectAll.execute();
stmtSelectAll.close();
break;
case 1:
SQLiteStatement stmtSelectUnread = getWritableDb()
.compileStatement(
"UPDATE articles SET selected = 1 WHERE feed_id = ? AND unread = 1");
stmtSelectUnread
.bindLong(1, ohf.getFeedId());
stmtSelectUnread.execute();
stmtSelectUnread.close();
break;
case 2:
deselectAllArticles();
break;
}
initMenu();
refresh();
dialog.cancel();
}
});
dialog = builder.create();
dialog.show();
}
return true;
case R.id.headlines_mark_as_read:
if (ohf != null) {
int feedId = ohf.getFeedId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE feed_id = ?");
stmt.bindLong(1, feedId);
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.share_article:
if (oap != null && android.os.Build.VERSION.SDK_INT < 14) {
int articleId = oap.getSelectedArticleId();
shareArticle(articleId);
}
return true;
case R.id.toggle_marked:
if (oap != null) {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET marked = NOT marked WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.selection_select_none:
deselectAllArticles();
return true;
case R.id.selection_toggle_unread:
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = getWritableDb()
.compileStatement(
"UPDATE articles SET unread = NOT unread WHERE selected = 1");
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.selection_toggle_marked:
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = getWritableDb()
.compileStatement(
"UPDATE articles SET marked = NOT marked WHERE selected = 1");
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.selection_toggle_published:
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = getWritableDb()
.compileStatement(
"UPDATE articles SET published = NOT published WHERE selected = 1");
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.toggle_published:
if (oap != null) {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET published = NOT published WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.catchup_above:
if (oap != null) {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE updated >= "
+ "(SELECT updated FROM articles WHERE "
+ BaseColumns._ID + " = ?)");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
refresh();
}
return true;
case R.id.set_unread:
if (oap != null) {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 1 WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
refresh();
}
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
@ -189,4 +413,32 @@ public class OfflineActivity extends CommonActivity {
return selected;
}
protected void deselectAllArticles() {
getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
refresh();
}
protected void refresh() {
OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_FEEDS);
if (ff != null) {
ff.refresh();
}
OfflineFeedCategoriesFragment cf = (OfflineFeedCategoriesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_CATS);
if (cf != null) {
cf.refresh();
}
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_HEADLINES);
if (ohf != null) {
ohf.refresh();
}
}
}

View File

@ -95,6 +95,12 @@ public class OfflineArticlePager extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.article_pager, container, false);
if (savedInstanceState != null) {
m_articleId = savedInstanceState.getInt("articleId", 0);
m_feedId = savedInstanceState.getInt("feedId", 0);
m_isCat = savedInstanceState.getBoolean("isCat", false);
}
m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager());
m_cursor.moveToFirst();
@ -130,6 +136,8 @@ public class OfflineArticlePager extends Fragment {
m_listener.onArticleSelected(articleId, false);
m_articleId = articleId;
}
}
});
@ -147,4 +155,17 @@ public class OfflineArticlePager extends Fragment {
}
public int getSelectedArticleId() {
return m_articleId;
}
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putInt("articleId", m_articleId);
out.putInt("feedId", m_feedId);
out.putBoolean("isCat", m_isCat);
}
}

View File

@ -81,29 +81,6 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
initMenu();
}
protected void refresh() {
OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_FEEDS);
if (ff != null) {
ff.refresh();
}
OfflineFeedCategoriesFragment cf = (OfflineFeedCategoriesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_CATS);
if (cf != null) {
cf.refresh();
}
/* OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAG_HEADLINES);
if (ohf != null) {
ohf.refresh();
} */
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

View File

@ -188,6 +188,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
m_combinedMode = savedInstanceState.getBoolean("combinedMode");
m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery");
m_feedIsCat = savedInstanceState.getBoolean("feedIsCat");
} else {
m_listener.getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
}
View view = inflater.inflate(R.layout.headlines_fragment, container, false);