store selection in the database
This commit is contained in:
parent
72a8b558e6
commit
a0f9225a9a
@ -8,7 +8,7 @@ import android.provider.BaseColumns;
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
public static final String DATABASE_NAME = "OfflineStorage";
|
||||
public static final String DATABASE_NAME = "OfflineStorage.db";
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
@ -40,7 +40,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
"link TEXT, " +
|
||||
"feed_id INTEGER, " +
|
||||
"tags TEXT, " +
|
||||
"content TEXT" +
|
||||
"content TEXT," +
|
||||
"selected BOOLEAN" +
|
||||
");");
|
||||
|
||||
db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds."+BaseColumns._ID+" AS "+BaseColumns._ID+", " +
|
||||
|
@ -111,22 +111,56 @@ public class OfflineActivity extends FragmentActivity {
|
||||
|
||||
List<PackageInfo> pkgs = getPackageManager().getInstalledPackages(0);
|
||||
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
||||
|
||||
initMainMenu();
|
||||
|
||||
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
||||
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
||||
|
||||
if (m_smallScreenMode) {
|
||||
if (m_selectedArticleId != 0) {
|
||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
||||
} else if (m_activeFeedId != 0) {
|
||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
} else {
|
||||
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
||||
//findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
||||
|
||||
/*if (m_enableCats && m_activeCategory == null) {
|
||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
} */
|
||||
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
if (m_selectedArticleId == 0) {
|
||||
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
||||
|
||||
/* if (!m_enableCats || m_activeCategory != null)
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
else
|
||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE); */
|
||||
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
|
||||
} else {
|
||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_activeFeedId == 0) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
||||
ft.replace(R.id.feeds_fragment, frag);
|
||||
ft.commit();
|
||||
} else {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,7 +396,7 @@ public class OfflineActivity extends FragmentActivity {
|
||||
refreshFeeds();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initMainMenu() {
|
||||
if (m_menu != null) {
|
||||
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
||||
@ -388,7 +422,7 @@ public class OfflineActivity extends FragmentActivity {
|
||||
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||
|
||||
if (hf != null) {
|
||||
int numSelected = hf.getSelectedArticles().size();
|
||||
int numSelected = 0; // hf.getSelectedArticles().size();
|
||||
|
||||
if (numSelected != 0) {
|
||||
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
||||
@ -516,6 +550,8 @@ public class OfflineActivity extends FragmentActivity {
|
||||
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
|
||||
ft.replace(R.id.headlines_fragment, frag);
|
||||
|
@ -47,7 +47,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
private int m_feedId;
|
||||
private int m_activeArticleId;
|
||||
private boolean m_combinedMode = true;
|
||||
private ArrayList<Integer> m_selectedArticles = new ArrayList<Integer>();
|
||||
|
||||
private SharedPreferences m_prefs;
|
||||
|
||||
@ -63,10 +62,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
|
||||
};
|
||||
|
||||
public List<Integer> getSelectedArticles() {
|
||||
return m_selectedArticles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -80,15 +75,15 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
|
||||
getActivity().getMenuInflater().inflate(R.menu.headlines_menu, menu);
|
||||
|
||||
if (m_selectedArticles.size() > 0) {
|
||||
menu.setHeaderTitle(R.string.headline_context_multiple);
|
||||
menu.setGroupVisible(R.id.menu_group_single_article, false);
|
||||
} else {
|
||||
//if (m_selectedArticles.size() > 0) {
|
||||
// menu.setHeaderTitle(R.string.headline_context_multiple);
|
||||
// menu.setGroupVisible(R.id.menu_group_single_article, false);
|
||||
//} else {
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
|
||||
Cursor c = getArticleAtPosition(info.position);
|
||||
menu.setHeaderTitle(c.getString(c.getColumnIndex("title")));
|
||||
menu.setGroupVisible(R.id.menu_group_single_article, true);
|
||||
}
|
||||
//}
|
||||
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
||||
@ -352,23 +347,25 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
CheckBox cb = (CheckBox) v.findViewById(R.id.selected);
|
||||
|
||||
if (cb != null) {
|
||||
cb.setChecked(m_selectedArticles.contains(article));
|
||||
cb.setChecked(article.getInt(article.getColumnIndex("selected")) == 1);
|
||||
cb.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
CheckBox cb = (CheckBox)view;
|
||||
|
||||
SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET selected = ? " +
|
||||
"WHERE " + BaseColumns._ID + " = ?");
|
||||
|
||||
if (cb.isChecked()) {
|
||||
if (!m_selectedArticles.contains(new Integer(articleId)))
|
||||
m_selectedArticles.add(new Integer(articleId));
|
||||
} else {
|
||||
m_selectedArticles.remove(new Integer(articleId));
|
||||
}
|
||||
stmtUpdate.bindLong(1, cb.isChecked() ? 1 : 0);
|
||||
stmtUpdate.bindLong(2, articleId);
|
||||
stmtUpdate.execute();
|
||||
stmtUpdate.close();
|
||||
|
||||
refresh();
|
||||
|
||||
((OfflineActivity)getActivity()).initMainMenu();
|
||||
|
||||
Log.d(TAG, "num selected: " + m_selectedArticles.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -393,20 +390,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
} */
|
||||
}
|
||||
|
||||
public void setSelection(ArticlesSelection select) {
|
||||
m_selectedArticles.clear();
|
||||
|
||||
/* if (select != ArticlesSelection.NONE) {
|
||||
for (Article a : m_articles) {
|
||||
if (select == ArticlesSelection.ALL || select == ArticlesSelection.UNREAD && a.unread) {
|
||||
m_selectedArticles.add(a);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
m_adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public Cursor getArticleAtPosition(int position) {
|
||||
return (Cursor) m_adapter.getItem(position);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user