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
|
package org.fox.ttrss.offline;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import org.fox.ttrss.Application;
import org.fox.ttrss.R;
public class OfflineDetailActivity extends OfflineActivity implements OfflineHeadlinesEventListener {
private final String TAG = this.getClass().getSimpleName();
protected SharedPreferences m_prefs;
private ActionBarDrawerToggle m_drawerToggle;
private DrawerLayout m_drawerLayout;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
setAppTheme(m_prefs);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
m_drawerLayout = (DrawerLayout) findViewById(R.id.headlines_drawer);
if (m_drawerLayout != null) {
m_drawerToggle = new ActionBarDrawerToggle(this, m_drawerLayout, R.string.blank, R.string.blank) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().show();
invalidateOptionsMenu();
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
};
m_drawerLayout.setDrawerListener(m_drawerToggle);
m_drawerToggle.setDrawerIndicatorEnabled(true);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null);
if (savedInstanceState == null) {
Intent i = getIntent();
if (i.getExtras() != null) {
int feedId = i.getIntExtra("feed", 0);
boolean isCat = i.getBooleanExtra("isCat", false);
int articleId = i.getIntExtra("article", 0);
String searchQuery = i.getStringExtra("searchQuery");
OfflineHeadlinesFragment hf = new OfflineHeadlinesFragment();
hf.initialize(feedId, isCat, true);
OfflineArticlePager af = new OfflineArticlePager();
af.initialize(articleId, feedId, isCat);
hf.setActiveArticleId(articleId);
hf.setSearchQuery(searchQuery);
af.setSearchQuery(searchQuery);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit();
Cursor c;
if (isCat) {
c = getCatById(feedId);
} else {
c = getFeedById(feedId);
}
if (c != null) {
setTitle(c.getString(c.getColumnIndex("title")));
c.close();
}
}
}
}
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
if (m_drawerToggle != null) m_drawerToggle.syncState();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (m_drawerToggle != null && m_drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
@Override
public void onArticleSelected(int articleId, boolean open) {
if (!open) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 " + "WHERE " + BaseColumns._ID
+ " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
stmt.close();
}
if (open) {
if (m_drawerLayout != null) {
m_drawerLayout.closeDrawers();
}
OfflineArticlePager af = (OfflineArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
af.setArticleId(articleId);
} else {
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
hf.setActiveArticleId(articleId);
}
Application.getInstance().m_selectedArticleId = articleId;
invalidateOptionsMenu();
refresh();
}
@Override
protected void initMenu() {
super.initMenu();
if (m_menu != null) {
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
//OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)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());
Fragment af = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
m_menu.findItem(R.id.search).setVisible(false);
}
}
@Override
public void onArticleSelected(int articleId) {
onArticleSelected(articleId, true);
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
|