1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
package org.fox.ttrss;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed;
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
private final String TAG = this.getClass().getSimpleName();
protected SharedPreferences m_prefs;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
setAppTheme(m_prefs);
super.onCreate(savedInstanceState);
setContentView(R.layout.headlines_articles);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null);
GlobalState.getInstance().load(savedInstanceState);
if (savedInstanceState == null) {
Intent i = getIntent();
if (i.getExtras() != null) {
boolean shortcutMode = i.getBooleanExtra("shortcut_mode", false);
Log.d(TAG, "is_shortcut_mode: " + shortcutMode);
Feed tmpFeed;
if (shortcutMode) {
int feedId = i.getIntExtra("feed_id", 0);
boolean isCat = i.getBooleanExtra("feed_is_cat", false);
String feedTitle = i.getStringExtra("feed_title");
tmpFeed = new Feed(feedId, feedTitle, isCat);
GlobalState.getInstance().m_loadedArticles.clear();
} else {
tmpFeed = i.getParcelableExtra("feed");
}
final Feed feed = tmpFeed;
final Article article = i.getParcelableExtra("article");
final String searchQuery = i.getStringExtra("searchQuery");
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new LoadingFragment(), null);
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
ft.commit();
setTitle(feed.title);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
HeadlinesFragment hf = new HeadlinesFragment();
hf.initialize(feed, article, true);
hf.setSearchQuery(searchQuery);
ArticlePager af = new ArticlePager();
af.initialize(article != null ? hf.getArticleById(article.id) : new Article(), feed);
af.setSearchQuery(searchQuery);
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit();
}
}, 25);
}
}
}
@Override
protected void refresh() {
super.refresh();
}
@Override
protected void loginSuccess(boolean refresh) {
Log.d(TAG, "loginSuccess");
invalidateOptionsMenu();
if (refresh) refresh();
}
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
GlobalState.getInstance().save(out);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
overridePendingTransition(0, R.anim.right_slide_out);
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
protected void initMenu() {
super.initMenu();
if (m_menu != null && getSessionId() != null) {
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
//HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, !isPortrait() && !isSmallScreen());
//m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(!isPortrait() && !isSmallScreen());
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
if (af != null) {
if (af.getSelectedArticle() != null && af.getSelectedArticle().attachments != null && af.getSelectedArticle().attachments.size() > 0) {
/* if (!isCompatMode() && (isSmallScreen() || !isPortrait())) {
m_menu.findItem(R.id.toggle_attachments).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
} */
m_menu.findItem(R.id.toggle_attachments).setVisible(true);
} else {
/* if (!isCompatMode()) {
m_menu.findItem(R.id.toggle_attachments).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
} */
m_menu.findItem(R.id.toggle_attachments).setVisible(false);
}
}
m_menu.findItem(R.id.search).setVisible(false);
}
}
@Override
public void onArticleListSelectionChange(ArticleList m_selectedArticles) {
invalidateOptionsMenu();
}
@Override
public void onArticleSelected(Article article) {
onArticleSelected(article, true);
}
@Override
public void onArticleSelected(Article article, boolean open) {
if (article == null) return;
if (article.unread) {
article.unread = false;
saveArticleUnread(article);
}
if (open) {
final Article fArticle = article;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (af != null) {
af.setActiveArticle(fArticle);
}
}
}, 10);
} else {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
hf.setActiveArticle(article);
}
}
GlobalState.getInstance().m_activeArticle = article;
invalidateOptionsMenu();
}
@Override
public void onHeadlinesLoaded(boolean appended) {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
ArticlePager ap = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (ap != null) {
ap.notifyUpdated();
}
if (hf != null) {
Article article = hf.getActiveArticle();
if (article == null && hf.getAllArticles().size() > 0) {
article = hf.getAllArticles().get(0);
hf.setActiveArticle(article);
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
ft.commitAllowingStateLoss();
final Article fArticle = article;
final Feed fFeed = hf.getFeed();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ArticlePager af = new ArticlePager();
af.initialize(fArticle, fFeed);
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commitAllowingStateLoss();
}
}, 10);
}
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(0, R.anim.right_slide_out);
}
}
|