split offline stuff into offline activity
This commit is contained in:
parent
6b6231ded5
commit
d1cb963452
@ -13,6 +13,11 @@
|
|||||||
<activity android:name=".LoginActivity"
|
<activity android:name=".LoginActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".OfflineActivity"
|
||||||
|
android:label="@string/app_name">
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -61,9 +61,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
private int m_articleOffset = 0;
|
private int m_articleOffset = 0;
|
||||||
private boolean m_isOffline = false;
|
private boolean m_isOffline = false;
|
||||||
|
|
||||||
private int m_activeOfflineFeedId = 0;
|
|
||||||
private int m_selectedOfflineArticleId = 0;
|
|
||||||
|
|
||||||
private SQLiteDatabase m_readableDb;
|
private SQLiteDatabase m_readableDb;
|
||||||
private SQLiteDatabase m_writableDb;
|
private SQLiteDatabase m_writableDb;
|
||||||
|
|
||||||
@ -324,9 +321,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
m_activeCategory = savedInstanceState.getParcelable("activeCategory");
|
m_activeCategory = savedInstanceState.getParcelable("activeCategory");
|
||||||
m_apiLevel = savedInstanceState.getInt("apiLevel");
|
m_apiLevel = savedInstanceState.getInt("apiLevel");
|
||||||
m_isLicensed = savedInstanceState.getInt("isLicensed");
|
m_isLicensed = savedInstanceState.getInt("isLicensed");
|
||||||
m_isOffline = savedInstanceState.getBoolean("isOffline");
|
|
||||||
m_activeOfflineFeedId = savedInstanceState.getInt("offlineActiveFeedId");
|
|
||||||
m_selectedOfflineArticleId = savedInstanceState.getInt("offlineArticleId");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_enableCats = m_prefs.getBoolean("enable_cats", false);
|
m_enableCats = m_prefs.getBoolean("enable_cats", false);
|
||||||
@ -354,6 +348,11 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
new TransitionHelper((LinearLayout)findViewById(R.id.main));
|
new TransitionHelper((LinearLayout)findViewById(R.id.main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_isOffline) {
|
||||||
|
Intent refresh = new Intent(this, OfflineActivity.class);
|
||||||
|
startActivity(refresh);
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
List<PackageInfo> pkgs = getPackageManager().getInstalledPackages(0);
|
List<PackageInfo> pkgs = getPackageManager().getInstalledPackages(0);
|
||||||
|
|
||||||
for (PackageInfo p : pkgs) {
|
for (PackageInfo p : pkgs) {
|
||||||
@ -364,12 +363,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_isOffline) {
|
|
||||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
||||||
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
||||||
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (m_smallScreenMode) {
|
if (m_smallScreenMode) {
|
||||||
if (m_selectedArticle != null) {
|
if (m_selectedArticle != null) {
|
||||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||||
@ -404,25 +397,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (m_isOffline) {
|
|
||||||
|
|
||||||
initMainMenu();
|
|
||||||
|
|
||||||
findViewById(R.id.loading_container).setVisibility(View.INVISIBLE);
|
|
||||||
findViewById(R.id.main).setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
if (m_activeOfflineFeedId == 0) {
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
||||||
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
|
||||||
ft.replace(R.id.feeds_fragment, frag);
|
|
||||||
ft.commit();
|
|
||||||
} else {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (m_sessionId != null) {
|
if (m_sessionId != null) {
|
||||||
loginSuccess();
|
loginSuccess();
|
||||||
} else {
|
} else {
|
||||||
@ -561,16 +536,12 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
editor.putBoolean("offline_mode_active", true);
|
editor.putBoolean("offline_mode_active", true);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
|
||||||
Intent refresh = new Intent(this, MainActivity.class);
|
Intent refresh = new Intent(this, OfflineActivity.class);
|
||||||
startActivity(refresh);
|
startActivity(refresh);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getActiveOfflineFeedId() {
|
|
||||||
return m_activeOfflineFeedId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLoadingStatus(int status, boolean showProgress) {
|
public void setLoadingStatus(int status, boolean showProgress) {
|
||||||
TextView tv = (TextView)findViewById(R.id.loading_message);
|
TextView tv = (TextView)findViewById(R.id.loading_message);
|
||||||
|
|
||||||
@ -597,9 +568,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
out.putParcelable("activeCategory", m_activeCategory);
|
out.putParcelable("activeCategory", m_activeCategory);
|
||||||
out.putInt("apiLevel", m_apiLevel);
|
out.putInt("apiLevel", m_apiLevel);
|
||||||
out.putInt("isLicensed", m_isLicensed);
|
out.putInt("isLicensed", m_isLicensed);
|
||||||
out.putBoolean("isOffline", m_isOffline);
|
|
||||||
out.putInt("offlineActiveFeedId", m_activeOfflineFeedId);
|
|
||||||
out.putInt("offlineArticleId", m_selectedOfflineArticleId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -664,7 +632,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
if (m_smallScreenMode) {
|
if (m_smallScreenMode) {
|
||||||
if (m_selectedArticle != null) {
|
if (m_selectedArticle != null) {
|
||||||
closeArticle();
|
closeArticle();
|
||||||
} else if (m_activeFeed != null || m_activeOfflineFeedId != 0) {
|
} else if (m_activeFeed != null) {
|
||||||
if (m_compatMode) {
|
if (m_compatMode) {
|
||||||
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
||||||
}
|
}
|
||||||
@ -681,7 +649,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
refreshFeeds();
|
refreshFeeds();
|
||||||
}
|
}
|
||||||
m_activeFeed = null;
|
m_activeFeed = null;
|
||||||
m_activeOfflineFeedId = 0;
|
|
||||||
initMainMenu();
|
initMainMenu();
|
||||||
|
|
||||||
} else if (m_activeCategory != null) {
|
} else if (m_activeCategory != null) {
|
||||||
@ -1659,60 +1626,4 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void offlineViewFeed(int feedId) {
|
|
||||||
m_activeOfflineFeedId = feedId;
|
|
||||||
|
|
||||||
initMainMenu();
|
|
||||||
|
|
||||||
if (m_smallScreenMode) {
|
|
||||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
||||||
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
||||||
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
|
|
||||||
ft.replace(R.id.headlines_fragment, frag);
|
|
||||||
ft.commit();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openOfflineArticle(int articleId, int compatAnimation) {
|
|
||||||
m_selectedOfflineArticleId = articleId;
|
|
||||||
|
|
||||||
initMainMenu();
|
|
||||||
|
|
||||||
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
|
||||||
|
|
||||||
if (hf != null) {
|
|
||||||
hf.setActiveArticleId(articleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
OfflineArticleFragment frag = new OfflineArticleFragment();
|
|
||||||
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
||||||
ft.replace(R.id.article_fragment, frag);
|
|
||||||
ft.commit();
|
|
||||||
|
|
||||||
if (m_compatMode) {
|
|
||||||
if (compatAnimation == 0)
|
|
||||||
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left));
|
|
||||||
else
|
|
||||||
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, compatAnimation));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_smallScreenMode) {
|
|
||||||
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
||||||
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
|
||||||
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
|
||||||
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSelectedOfflineArticleId() {
|
|
||||||
return m_selectedOfflineArticleId;
|
|
||||||
}
|
|
||||||
}
|
}
|
462
src/org/fox/ttrss/OfflineActivity.java
Normal file
462
src/org/fox/ttrss/OfflineActivity.java
Normal file
@ -0,0 +1,462 @@
|
|||||||
|
package org.fox.ttrss;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteStatement;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.BaseColumns;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
public class OfflineActivity extends FragmentActivity {
|
||||||
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
|
|
||||||
|
private SharedPreferences m_prefs;
|
||||||
|
private String m_themeName = "";
|
||||||
|
private Menu m_menu;
|
||||||
|
private boolean m_smallScreenMode;
|
||||||
|
private boolean m_unreadOnly = true;
|
||||||
|
private boolean m_unreadArticlesOnly = true;
|
||||||
|
private boolean m_compatMode = false;
|
||||||
|
private boolean m_enableCats = false;
|
||||||
|
|
||||||
|
private int m_activeOfflineFeedId = 0;
|
||||||
|
private int m_selectedOfflineArticleId = 0;
|
||||||
|
|
||||||
|
private SQLiteDatabase m_readableDb;
|
||||||
|
private SQLiteDatabase m_writableDb;
|
||||||
|
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
|
||||||
|
public boolean isSmallScreen() {
|
||||||
|
return m_smallScreenMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
|
|
||||||
|
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
|
||||||
|
|
||||||
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
||||||
|
setTheme(R.style.DarkTheme);
|
||||||
|
} else {
|
||||||
|
setTheme(R.style.LightTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
m_themeName = m_prefs.getString("theme", "THEME_DARK");
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
m_unreadOnly = savedInstanceState.getBoolean("unreadOnly");
|
||||||
|
m_unreadArticlesOnly = savedInstanceState.getBoolean("unreadArticlesOnly");
|
||||||
|
m_activeOfflineFeedId = savedInstanceState.getInt("offlineActiveFeedId");
|
||||||
|
m_selectedOfflineArticleId = savedInstanceState.getInt("offlineArticleId");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_enableCats = m_prefs.getBoolean("enable_cats", false);
|
||||||
|
|
||||||
|
Display display = getWindowManager().getDefaultDisplay();
|
||||||
|
|
||||||
|
int width = display.getWidth();
|
||||||
|
int height = display.getHeight();
|
||||||
|
|
||||||
|
if (height > width) { int tmp = height; width = tmp; height = width; }
|
||||||
|
|
||||||
|
m_smallScreenMode = width < 960 || height < 720;
|
||||||
|
|
||||||
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
|
initDatabase();
|
||||||
|
|
||||||
|
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
|
||||||
|
Log.d(TAG, "m_compatMode=" + m_compatMode);
|
||||||
|
|
||||||
|
if (!m_compatMode) {
|
||||||
|
new TransitionHelper((LinearLayout)findViewById(R.id.main));
|
||||||
|
}
|
||||||
|
|
||||||
|
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_activeOfflineFeedId == 0) {
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
OfflineFeedsFragment frag = new OfflineFeedsFragment();
|
||||||
|
ft.replace(R.id.feeds_fragment, frag);
|
||||||
|
ft.commit();
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initDatabase() {
|
||||||
|
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
|
||||||
|
m_writableDb = dh.getWritableDatabase();
|
||||||
|
m_readableDb = dh.getReadableDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized SQLiteDatabase getReadableDb() {
|
||||||
|
return m_readableDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized SQLiteDatabase getWritableDb() {
|
||||||
|
return m_writableDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchOnline() {
|
||||||
|
SharedPreferences.Editor editor = m_prefs.edit();
|
||||||
|
editor.putBoolean("offline_mode_active", false);
|
||||||
|
editor.commit();
|
||||||
|
|
||||||
|
Intent refresh = new Intent(this, MainActivity.class);
|
||||||
|
startActivity(refresh);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActiveOfflineFeedId() {
|
||||||
|
return m_activeOfflineFeedId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoadingStatus(int status, boolean showProgress) {
|
||||||
|
TextView tv = (TextView)findViewById(R.id.loading_message);
|
||||||
|
|
||||||
|
if (tv != null) {
|
||||||
|
tv.setText(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
View pb = findViewById(R.id.loading_progress);
|
||||||
|
|
||||||
|
if (pb != null) {
|
||||||
|
pb.setVisibility(showProgress ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState (Bundle out) {
|
||||||
|
super.onSaveInstanceState(out);
|
||||||
|
|
||||||
|
out.putBoolean("unreadOnly", m_unreadOnly);
|
||||||
|
out.putBoolean("unreadArticlesOnly", m_unreadArticlesOnly);
|
||||||
|
out.putInt("offlineActiveFeedId", m_activeOfflineFeedId);
|
||||||
|
out.putInt("offlineArticleId", m_selectedOfflineArticleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
boolean needRefresh = !m_prefs.getString("theme", "THEME_DARK").equals(m_themeName) ||
|
||||||
|
m_prefs.getBoolean("enable_cats", false) != m_enableCats;
|
||||||
|
|
||||||
|
if (needRefresh) {
|
||||||
|
Intent refresh = new Intent(this, OfflineActivity.class);
|
||||||
|
startActivity(refresh);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.main_menu, menu);
|
||||||
|
|
||||||
|
m_menu = menu;
|
||||||
|
|
||||||
|
initMainMenu();
|
||||||
|
|
||||||
|
MenuItem item = menu.findItem(R.id.show_feeds);
|
||||||
|
|
||||||
|
/* if (getUnreadOnly()) {
|
||||||
|
item.setTitle(R.string.menu_all_feeds);
|
||||||
|
} else {
|
||||||
|
item.setTitle(R.string.menu_unread_feeds);
|
||||||
|
} */
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMenuLabel(int id, int labelId) {
|
||||||
|
MenuItem mi = m_menu.findItem(id);
|
||||||
|
|
||||||
|
if (mi != null) {
|
||||||
|
mi.setTitle(labelId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
|
||||||
|
if (m_smallScreenMode) {
|
||||||
|
if (m_selectedOfflineArticleId != 0) {
|
||||||
|
closeArticle();
|
||||||
|
} else if (m_activeOfflineFeedId != 0) {
|
||||||
|
if (m_compatMode) {
|
||||||
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if (m_activeFeed != null && m_activeFeed.is_cat) {
|
||||||
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
refreshCategories();
|
||||||
|
} else { */
|
||||||
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
|
||||||
|
//}
|
||||||
|
m_activeOfflineFeedId = 0;
|
||||||
|
initMainMenu();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (m_selectedOfflineArticleId != 0) {
|
||||||
|
closeArticle();
|
||||||
|
} else {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.preferences:
|
||||||
|
Intent intent = new Intent(this, PreferencesActivity.class);
|
||||||
|
startActivityForResult(intent, 0);
|
||||||
|
return true;
|
||||||
|
case R.id.go_online:
|
||||||
|
switchOnline();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshFeeds() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeArticle() {
|
||||||
|
if (m_compatMode) {
|
||||||
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_smallScreenMode) {
|
||||||
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
findViewById(R.id.article_fragment).setVisibility(View.GONE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
m_selectedOfflineArticleId = 0;
|
||||||
|
|
||||||
|
initMainMenu();
|
||||||
|
refreshFeeds();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initMainMenu() {
|
||||||
|
if (m_menu != null) {
|
||||||
|
m_menu.setGroupVisible(R.id.menu_group_logged_in, false);
|
||||||
|
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
||||||
|
m_menu.setGroupVisible(R.id.menu_group_headlines, false);
|
||||||
|
m_menu.setGroupVisible(R.id.menu_group_article, false);
|
||||||
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, false);
|
||||||
|
|
||||||
|
m_menu.setGroupVisible(R.id.menu_group_logged_out, false);
|
||||||
|
m_menu.findItem(R.id.go_online).setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
m_readableDb.close();
|
||||||
|
m_writableDb.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
default:
|
||||||
|
Log.d(TAG, "onContextItemSelected, unhandled id=" + item.getItemId());
|
||||||
|
return super.onContextItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @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());
|
||||||
|
|
||||||
|
Article next = base != null ? getRelativeArticle(base, RelativeArticle.AFTER) : hf.getArticleAtPosition(0);
|
||||||
|
|
||||||
|
if (next != null) {
|
||||||
|
hf.setActiveArticleId(next.id);
|
||||||
|
|
||||||
|
boolean combinedMode = m_prefs.getBoolean("combined_mode", false);
|
||||||
|
|
||||||
|
if (combinedMode || m_selectedArticle == null) {
|
||||||
|
next.unread = false;
|
||||||
|
saveArticleUnread(next);
|
||||||
|
} else {
|
||||||
|
openArticle(next, 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());
|
||||||
|
|
||||||
|
Article prev = base != null ? getRelativeArticle(base, RelativeArticle.BEFORE) : hf.getArticleAtPosition(0);
|
||||||
|
|
||||||
|
if (prev != null) {
|
||||||
|
hf.setActiveArticleId(prev.id);
|
||||||
|
|
||||||
|
boolean combinedMode = m_prefs.getBoolean("combined_mode", false);
|
||||||
|
|
||||||
|
if (combinedMode || m_selectedArticle == null) {
|
||||||
|
prev.unread = false;
|
||||||
|
saveArticleUnread(prev);
|
||||||
|
} else {
|
||||||
|
openArticle(prev, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.dispatchKeyEvent(event);
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
|
public void offlineViewFeed(int feedId) {
|
||||||
|
m_activeOfflineFeedId = feedId;
|
||||||
|
|
||||||
|
initMainMenu();
|
||||||
|
|
||||||
|
if (m_smallScreenMode) {
|
||||||
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
|
||||||
|
ft.replace(R.id.headlines_fragment, frag);
|
||||||
|
ft.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openOfflineArticle(int articleId, int compatAnimation) {
|
||||||
|
m_selectedOfflineArticleId = articleId;
|
||||||
|
|
||||||
|
initMainMenu();
|
||||||
|
|
||||||
|
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
|
||||||
|
|
||||||
|
if (hf != null) {
|
||||||
|
hf.setActiveArticleId(articleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
OfflineArticleFragment frag = new OfflineArticleFragment();
|
||||||
|
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
ft.replace(R.id.article_fragment, frag);
|
||||||
|
ft.commit();
|
||||||
|
|
||||||
|
if (m_compatMode) {
|
||||||
|
if (compatAnimation == 0)
|
||||||
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left));
|
||||||
|
else
|
||||||
|
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, compatAnimation));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_smallScreenMode) {
|
||||||
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
findViewById(R.id.feeds_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.article_fragment).setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedOfflineArticleId() {
|
||||||
|
return m_selectedOfflineArticleId;
|
||||||
|
}
|
||||||
|
}
|
@ -60,7 +60,7 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
|||||||
|
|
||||||
|
|
||||||
// TODO change to interface?
|
// TODO change to interface?
|
||||||
MainActivity activity = (MainActivity)getActivity();
|
OfflineActivity activity = (OfflineActivity)getActivity();
|
||||||
|
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation();
|
int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation();
|
||||||
@ -79,7 +79,7 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
|||||||
view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE);
|
view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cursor = ((MainActivity)getActivity()).getReadableDb().query("articles", null, BaseColumns._ID + "=?",
|
m_cursor = ((OfflineActivity)getActivity()).getReadableDb().query("articles", null, BaseColumns._ID + "=?",
|
||||||
new String[] { String.valueOf(m_articleId) }, null, null, null);
|
new String[] { String.valueOf(m_articleId) }, null, null, null);
|
||||||
|
|
||||||
m_cursor.moveToFirst();
|
m_cursor.moveToFirst();
|
||||||
@ -205,7 +205,7 @@ public class OfflineArticleFragment extends Fragment implements OnClickListener
|
|||||||
|
|
||||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||||
|
|
||||||
m_articleId = ((MainActivity)activity).getSelectedOfflineArticleId();
|
m_articleId = ((OfflineActivity)activity).getSelectedOfflineArticleId();
|
||||||
/* m_articleOps = (ArticleOps)activity;
|
/* m_articleOps = (ArticleOps)activity;
|
||||||
m_article = m_articleOps.getSelectedArticle();
|
m_article = m_articleOps.getSelectedArticle();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene
|
|||||||
public Cursor createCursor() {
|
public Cursor createCursor() {
|
||||||
if (m_cursor != null) m_cursor.close();
|
if (m_cursor != null) m_cursor.close();
|
||||||
|
|
||||||
return ((MainActivity)getActivity()).getReadableDb().query("feeds_unread",
|
return ((OfflineActivity)getActivity()).getReadableDb().query("feeds_unread",
|
||||||
null, null, null, null, null, "title");
|
null, null, null, null, null, "title");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene
|
|||||||
int feedId = (int) cursor.getLong(0);
|
int feedId = (int) cursor.getLong(0);
|
||||||
Log.d(TAG, "clicked on feed " + feedId);
|
Log.d(TAG, "clicked on feed " + feedId);
|
||||||
|
|
||||||
((MainActivity)getActivity()).offlineViewFeed(feedId);
|
((OfflineActivity)getActivity()).offlineViewFeed(feedId);
|
||||||
|
|
||||||
m_selectedFeedId = feedId;
|
m_selectedFeedId = feedId;
|
||||||
|
|
||||||
|
@ -131,14 +131,14 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
public Cursor createCursor() {
|
public Cursor createCursor() {
|
||||||
if (m_cursor != null) m_cursor.close();
|
if (m_cursor != null) m_cursor.close();
|
||||||
|
|
||||||
return ((MainActivity)getActivity()).getReadableDb().query("articles",
|
return ((OfflineActivity)getActivity()).getReadableDb().query("articles",
|
||||||
null, "feed_id = ?", new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC");
|
null, "feed_id = ?", new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
m_feedId = ((MainActivity)activity).getActiveOfflineFeedId();
|
m_feedId = ((OfflineActivity)activity).getActiveOfflineFeedId();
|
||||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||||
m_articleOps = (ArticleOps) activity;
|
m_articleOps = (ArticleOps) activity;
|
||||||
m_combinedMode = m_prefs.getBoolean("combined_mode", false);
|
m_combinedMode = m_prefs.getBoolean("combined_mode", false);
|
||||||
@ -156,7 +156,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
m_activeArticleId = cursor.getInt(0);
|
m_activeArticleId = cursor.getInt(0);
|
||||||
|
|
||||||
if (m_combinedMode) {
|
if (m_combinedMode) {
|
||||||
SQLiteStatement stmtUpdate = ((MainActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET unread = 0 " +
|
SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET unread = 0 " +
|
||||||
"WHERE " + BaseColumns._ID + " = ?");
|
"WHERE " + BaseColumns._ID + " = ?");
|
||||||
|
|
||||||
stmtUpdate.bindLong(1, m_activeArticleId);
|
stmtUpdate.bindLong(1, m_activeArticleId);
|
||||||
@ -165,7 +165,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
} else {
|
} else {
|
||||||
((MainActivity)getActivity()).openOfflineArticle(m_activeArticleId, 0);
|
((OfflineActivity)getActivity()).openOfflineArticle(m_activeArticleId, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
SQLiteStatement stmtUpdate = ((MainActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET marked = NOT marked " +
|
SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET marked = NOT marked " +
|
||||||
"WHERE " + BaseColumns._ID + " = ?");
|
"WHERE " + BaseColumns._ID + " = ?");
|
||||||
|
|
||||||
stmtUpdate.bindLong(1, articleId);
|
stmtUpdate.bindLong(1, articleId);
|
||||||
@ -302,7 +302,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
SQLiteStatement stmtUpdate = ((MainActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET published = NOT published " +
|
SQLiteStatement stmtUpdate = ((OfflineActivity)getActivity()).getWritableDb().compileStatement("UPDATE articles SET published = NOT published " +
|
||||||
"WHERE " + BaseColumns._ID + " = ?");
|
"WHERE " + BaseColumns._ID + " = ?");
|
||||||
|
|
||||||
stmtUpdate.bindLong(1, articleId);
|
stmtUpdate.bindLong(1, articleId);
|
||||||
@ -369,7 +369,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
m_selectedArticles.remove(new Integer(articleId));
|
m_selectedArticles.remove(new Integer(articleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
((MainActivity)getActivity()).initMainMenu();
|
((OfflineActivity)getActivity()).initMainMenu();
|
||||||
|
|
||||||
Log.d(TAG, "num selected: " + m_selectedArticles.size());
|
Log.d(TAG, "num selected: " + m_selectedArticles.size());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user