reimplement moving between articles using volume buttons,
articlefragment clicks, etc
This commit is contained in:
parent
d4b6e34b98
commit
797860e517
@ -6,6 +6,8 @@ import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.fox.ttrss.ArticleOps.RelativeArticle;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
@ -187,7 +189,7 @@ public class OfflineActivity extends FragmentActivity {
|
||||
finish();
|
||||
}
|
||||
|
||||
public int getActiveOfflineFeedId() {
|
||||
public int getActiveFeedId() {
|
||||
return m_activeFeedId;
|
||||
}
|
||||
|
||||
@ -735,69 +737,108 @@ public class OfflineActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
int action = event.getAction();
|
||||
int keyCode = event.getKeyCode();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||
|
||||
if (hf != null && m_activeFeed != null) {
|
||||
Article base = hf.getArticleById(hf.getActiveArticleId());
|
||||
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||
|
||||
Article next = base != null ? getRelativeArticle(base, RelativeArticle.AFTER) : hf.getArticleAtPosition(0);
|
||||
int nextId = getRelativeArticleId(m_selectedArticleId, m_activeFeedId, RelativeArticle.AFTER);
|
||||
|
||||
if (next != null) {
|
||||
hf.setActiveArticleId(next.id);
|
||||
if (nextId != 0 && ohf != null) {
|
||||
if (m_prefs.getBoolean("combined_mode", false)) {
|
||||
ohf.setActiveArticleId(nextId);
|
||||
|
||||
boolean combinedMode = m_prefs.getBoolean("combined_mode", false);
|
||||
SQLiteStatement stmt = getWritableDb().compileStatement("UPDATE articles SET unread = 0 " +
|
||||
"WHERE " + BaseColumns._ID + " = ?");
|
||||
|
||||
if (combinedMode || m_selectedArticle == null) {
|
||||
next.unread = false;
|
||||
saveArticleUnread(next);
|
||||
} else {
|
||||
openArticle(next, 0);
|
||||
}
|
||||
stmt.bindLong(1, nextId);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
|
||||
} else {
|
||||
openArticle(nextId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (action == KeyEvent.ACTION_UP) {
|
||||
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||
|
||||
if (hf != null && m_activeFeed != null) {
|
||||
Article base = hf.getArticleById(hf.getActiveArticleId());
|
||||
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||
|
||||
Article prev = base != null ? getRelativeArticle(base, RelativeArticle.BEFORE) : hf.getArticleAtPosition(0);
|
||||
int prevId = getRelativeArticleId(m_selectedArticleId, m_activeFeedId, RelativeArticle.BEFORE);
|
||||
|
||||
if (prev != null) {
|
||||
hf.setActiveArticleId(prev.id);
|
||||
if (prevId != 0 && ohf != null) {
|
||||
if (m_prefs.getBoolean("combined_mode", false)) {
|
||||
ohf.setActiveArticleId(prevId);
|
||||
|
||||
boolean combinedMode = m_prefs.getBoolean("combined_mode", false);
|
||||
SQLiteStatement stmt = getWritableDb().compileStatement("UPDATE articles SET unread = 0 " +
|
||||
"WHERE " + BaseColumns._ID + " = ?");
|
||||
|
||||
if (combinedMode || m_selectedArticle == null) {
|
||||
prev.unread = false;
|
||||
saveArticleUnread(prev);
|
||||
} else {
|
||||
openArticle(prev, 0);
|
||||
}
|
||||
stmt.bindLong(1, prevId);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
|
||||
} else {
|
||||
openArticle(prevId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
public void deselectAllArticles() {
|
||||
getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
|
||||
}
|
||||
|
||||
public int getRelativeArticleId(int baseId, int feedId, ArticleOps.RelativeArticle mode) {
|
||||
|
||||
Cursor c;
|
||||
|
||||
/* if (baseId == 0) {
|
||||
c = getReadableDb().query("articles",
|
||||
null, "feed_id = ?",
|
||||
new String[] { String.valueOf(feedId) }, null, null, "updated DESC LIMIT 1");
|
||||
|
||||
if (c.moveToFirst()) {
|
||||
baseId = c.getInt(0);
|
||||
}
|
||||
|
||||
c.close();
|
||||
|
||||
return baseId;
|
||||
} */
|
||||
|
||||
if (mode == RelativeArticle.BEFORE) {
|
||||
c = getReadableDb().query("articles",
|
||||
null, "updated > (SELECT updated FROM articles WHERE "+BaseColumns._ID+" = ?) AND feed_id = ?",
|
||||
new String[] { String.valueOf(baseId), String.valueOf(feedId) }, null, null, "updated LIMIT 1");
|
||||
|
||||
} else {
|
||||
c = getReadableDb().query("articles",
|
||||
null, "updated < (SELECT updated FROM articles WHERE "+BaseColumns._ID+" = ?) AND feed_id = ?",
|
||||
new String[] { String.valueOf(baseId), String.valueOf(feedId) }, null, null, "updated DESC LIMIT 1");
|
||||
}
|
||||
|
||||
int id = 0;
|
||||
|
||||
if (c.moveToFirst()) {
|
||||
id = c.getInt(0);
|
||||
}
|
||||
|
||||
c.close();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public void viewFeed(int feedId) {
|
||||
m_activeFeedId = feedId;
|
||||
|
||||
@ -828,6 +869,13 @@ public class OfflineActivity extends FragmentActivity {
|
||||
hf.setActiveArticleId(articleId);
|
||||
}
|
||||
|
||||
SQLiteStatement stmt = getWritableDb().compileStatement("UPDATE articles SET unread = 0 " +
|
||||
"WHERE " + BaseColumns._ID + " = ?");
|
||||
|
||||
stmt.bindLong(1, articleId);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
|
||||
OfflineArticleFragment frag = new OfflineArticleFragment();
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
|
@ -7,7 +7,6 @@ import org.fox.ttrss.ArticleOps.RelativeArticle;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -26,7 +25,6 @@ import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.ads.AdRequest;
|
||||
import com.google.ads.AdView;
|
||||
|
||||
public class OfflineArticleFragment extends Fragment implements OnClickListener {
|
||||
@ -35,6 +33,8 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
||||
|
||||
private SharedPreferences m_prefs;
|
||||
private int m_articleId;
|
||||
private int m_nextArticleId;
|
||||
private int m_prevArticleId;
|
||||
private GestureDetector m_gestureDetector;
|
||||
private View.OnTouchListener m_gestureListener;
|
||||
private Cursor m_cursor;
|
||||
@ -44,6 +44,8 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
m_articleId = savedInstanceState.getInt("articleId");
|
||||
m_prevArticleId = savedInstanceState.getInt("prevArticleId");
|
||||
m_nextArticleId = savedInstanceState.getInt("nextArticleId");
|
||||
}
|
||||
|
||||
View view = inflater.inflate(R.layout.article_fragment, container, false);
|
||||
@ -163,21 +165,21 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
||||
ImageView next = (ImageView)view.findViewById(R.id.next_article);
|
||||
|
||||
if (next != null) {
|
||||
// if (m_nextArticle != null) {
|
||||
// next.setOnClickListener(this);
|
||||
// } else {
|
||||
if (m_nextArticleId != 0) {
|
||||
next.setOnClickListener(this);
|
||||
} else {
|
||||
next.setImageResource(R.drawable.ic_next_article_disabled);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
ImageView prev = (ImageView)view.findViewById(R.id.prev_article);
|
||||
|
||||
if (prev != null) {
|
||||
// if (m_prevArticle != null) {
|
||||
// prev.setOnClickListener(this);
|
||||
// } else {
|
||||
if (m_prevArticleId != 0) {
|
||||
prev.setOnClickListener(this);
|
||||
} else {
|
||||
prev.setImageResource(R.drawable.ic_prev_article_disabled);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -197,6 +199,9 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
||||
super.onSaveInstanceState(out);
|
||||
|
||||
out.putInt("articleId", m_articleId);
|
||||
out.putInt("prevArticleId", m_prevArticleId);
|
||||
out.putInt("nextArticleId", m_nextArticleId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -205,21 +210,21 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
||||
|
||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||
|
||||
m_articleId = ((OfflineActivity)activity).getSelectedArticleId();
|
||||
/* m_articleOps = (ArticleOps)activity;
|
||||
m_article = m_articleOps.getSelectedArticle();
|
||||
OfflineActivity oa = (OfflineActivity)activity;
|
||||
|
||||
m_prevArticle = m_articleOps.getRelativeArticle(m_article, RelativeArticle.BEFORE);
|
||||
m_nextArticle = m_articleOps.getRelativeArticle(m_article, RelativeArticle.AFTER); */
|
||||
m_articleId = oa.getSelectedArticleId();
|
||||
|
||||
m_prevArticleId = oa.getRelativeArticleId(m_articleId, oa.getActiveFeedId(), RelativeArticle.BEFORE);
|
||||
m_nextArticleId = oa.getRelativeArticleId(m_articleId, oa.getActiveFeedId(), RelativeArticle.AFTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
/* if (v.getId() == R.id.next_article) {
|
||||
m_articleOps.openArticle(m_nextArticle, 0);
|
||||
if (v.getId() == R.id.next_article) {
|
||||
((OfflineActivity)getActivity()).openArticle(m_nextArticleId, 0);
|
||||
} else if (v.getId() == R.id.prev_article) {
|
||||
m_articleOps.openArticle(m_prevArticle, R.anim.slide_right);
|
||||
} */
|
||||
((OfflineActivity)getActivity()).openArticle(m_prevArticleId, R.anim.slide_right);
|
||||
}
|
||||
}
|
||||
|
||||
// http://blog.blackmoonit.com/2010/07/gesture-detection-swipe-detection_4292.html
|
||||
@ -238,14 +243,14 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
||||
if (dX>0) {
|
||||
//Log.d(TAG, "Right swipe");
|
||||
|
||||
//if (m_prevArticle != null)
|
||||
// m_articleOps.openArticle(m_prevArticle, R.anim.slide_right);
|
||||
if (m_prevArticleId != 0)
|
||||
((OfflineActivity)getActivity()).openArticle(m_prevArticleId, 0);
|
||||
|
||||
} else {
|
||||
//Log.d(TAG, "Left swipe");
|
||||
|
||||
//if (m_nextArticle != null)
|
||||
// m_articleOps.openArticle(m_nextArticle, 0);
|
||||
if (m_nextArticleId != 0)
|
||||
((OfflineActivity)getActivity()).openArticle(m_nextArticleId, 0);
|
||||
|
||||
}
|
||||
return true;
|
||||
|
@ -89,7 +89,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene
|
||||
|
||||
list.setAdapter(m_adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
list.setEmptyView(view.findViewById(R.id.no_unread_feeds));
|
||||
list.setEmptyView(view.findViewById(R.id.no_feeds));
|
||||
registerForContextMenu(list);
|
||||
|
||||
view.findViewById(R.id.loading_container).setVisibility(View.GONE);
|
||||
|
@ -131,6 +131,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
|
||||
list.setAdapter(m_adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
list.setEmptyView(view.findViewById(R.id.no_headlines));
|
||||
registerForContextMenu(list);
|
||||
|
||||
view.findViewById(R.id.loading_progress).setVisibility(View.GONE);
|
||||
@ -146,7 +147,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
m_feedId = ((OfflineActivity)activity).getActiveOfflineFeedId();
|
||||
m_feedId = ((OfflineActivity)activity).getActiveFeedId();
|
||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||
m_combinedMode = m_prefs.getBoolean("combined_mode", false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user