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 {
|
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private final String TAG = this.getClass().getSimpleName();
|
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 static final int DATABASE_VERSION = 1;
|
||||||
|
|
||||||
public DatabaseHelper(Context context) {
|
public DatabaseHelper(Context context) {
|
||||||
@ -40,7 +40,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
"link TEXT, " +
|
"link TEXT, " +
|
||||||
"feed_id INTEGER, " +
|
"feed_id INTEGER, " +
|
||||||
"tags TEXT, " +
|
"tags TEXT, " +
|
||||||
"content TEXT" +
|
"content TEXT," +
|
||||||
|
"selected BOOLEAN" +
|
||||||
");");
|
");");
|
||||||
|
|
||||||
db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds."+BaseColumns._ID+" AS "+BaseColumns._ID+", " +
|
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);
|
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();
|
initMainMenu();
|
||||||
|
|
||||||
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
||||||
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
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) {
|
if (m_activeFeedId == 0) {
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
||||||
ft.replace(R.id.feeds_fragment, frag);
|
ft.replace(R.id.feeds_fragment, frag);
|
||||||
ft.commit();
|
ft.commit();
|
||||||
} else {
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +396,7 @@ public class OfflineActivity extends FragmentActivity {
|
|||||||
refreshFeeds();
|
refreshFeeds();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initMainMenu() {
|
public void initMainMenu() {
|
||||||
if (m_menu != null) {
|
if (m_menu != null) {
|
||||||
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
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);
|
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||||
|
|
||||||
if (hf != null) {
|
if (hf != null) {
|
||||||
int numSelected = hf.getSelectedArticles().size();
|
int numSelected = 0; // hf.getSelectedArticles().size();
|
||||||
|
|
||||||
if (numSelected != 0) {
|
if (numSelected != 0) {
|
||||||
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
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);
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
|
||||||
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
|
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
|
||||||
ft.replace(R.id.headlines_fragment, frag);
|
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_feedId;
|
||||||
private int m_activeArticleId;
|
private int m_activeArticleId;
|
||||||
private boolean m_combinedMode = true;
|
private boolean m_combinedMode = true;
|
||||||
private ArrayList<Integer> m_selectedArticles = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
private SharedPreferences m_prefs;
|
private SharedPreferences m_prefs;
|
||||||
|
|
||||||
@ -63,10 +62,6 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public List<Integer> getSelectedArticles() {
|
|
||||||
return m_selectedArticles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@ -80,15 +75,15 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
|
|
||||||
getActivity().getMenuInflater().inflate(R.menu.headlines_menu, menu);
|
getActivity().getMenuInflater().inflate(R.menu.headlines_menu, menu);
|
||||||
|
|
||||||
if (m_selectedArticles.size() > 0) {
|
//if (m_selectedArticles.size() > 0) {
|
||||||
menu.setHeaderTitle(R.string.headline_context_multiple);
|
// menu.setHeaderTitle(R.string.headline_context_multiple);
|
||||||
menu.setGroupVisible(R.id.menu_group_single_article, false);
|
// menu.setGroupVisible(R.id.menu_group_single_article, false);
|
||||||
} else {
|
//} else {
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
|
||||||
Cursor c = getArticleAtPosition(info.position);
|
Cursor c = getArticleAtPosition(info.position);
|
||||||
menu.setHeaderTitle(c.getString(c.getColumnIndex("title")));
|
menu.setHeaderTitle(c.getString(c.getColumnIndex("title")));
|
||||||
menu.setGroupVisible(R.id.menu_group_single_article, true);
|
menu.setGroupVisible(R.id.menu_group_single_article, true);
|
||||||
}
|
//}
|
||||||
|
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
|
|
||||||
@ -352,23 +347,25 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
CheckBox cb = (CheckBox) v.findViewById(R.id.selected);
|
CheckBox cb = (CheckBox) v.findViewById(R.id.selected);
|
||||||
|
|
||||||
if (cb != null) {
|
if (cb != null) {
|
||||||
cb.setChecked(m_selectedArticles.contains(article));
|
cb.setChecked(article.getInt(article.getColumnIndex("selected")) == 1);
|
||||||
cb.setOnClickListener(new OnClickListener() {
|
cb.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
CheckBox cb = (CheckBox)view;
|
CheckBox cb = (CheckBox)view;
|
||||||
|
|
||||||
|
SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET selected = ? " +
|
||||||
|
"WHERE " + BaseColumns._ID + " = ?");
|
||||||
|
|
||||||
if (cb.isChecked()) {
|
stmtUpdate.bindLong(1, cb.isChecked() ? 1 : 0);
|
||||||
if (!m_selectedArticles.contains(new Integer(articleId)))
|
stmtUpdate.bindLong(2, articleId);
|
||||||
m_selectedArticles.add(new Integer(articleId));
|
stmtUpdate.execute();
|
||||||
} else {
|
stmtUpdate.close();
|
||||||
m_selectedArticles.remove(new Integer(articleId));
|
|
||||||
}
|
refresh();
|
||||||
|
|
||||||
((OfflineActivity)getActivity()).initMainMenu();
|
((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) {
|
public Cursor getArticleAtPosition(int position) {
|
||||||
return (Cursor) m_adapter.getItem(position);
|
return (Cursor) m_adapter.getItem(position);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user