Refactoring
This commit is contained in:
parent
6acf06c94d
commit
66a855e36e
5 changed files with 245 additions and 345 deletions
|
@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -39,6 +40,8 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -416,11 +419,17 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
StopWatch stopwatch = new StopWatch();
|
||||
stopwatch.start();
|
||||
|
||||
unreadCountFoldersTemp = dbConn.getUnreadItemCountForFolder();
|
||||
unreadCountFeedsTemp = dbConn.getUnreadItemCountForFeed();
|
||||
starredCountFeedsTemp = dbConn.getStarredItemCountForFeed();
|
||||
|
||||
urlsToFavIconsTemp = dbConn.getUrlsToFavIcons();
|
||||
|
||||
stopwatch.stop();
|
||||
Log.v(TAG, "Fetched folder/feed counts in " + stopwatch.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -451,7 +460,16 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
|
|||
|
||||
@Override
|
||||
protected Tuple<ArrayList<AbstractItem>, SparseArray<SparseArray<ConcreteFeedItem>>> doInBackground(Void... voids) {
|
||||
return ReloadAdapter();
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
Tuple<ArrayList<AbstractItem>, SparseArray<SparseArray<ConcreteFeedItem>>> ad = ReloadAdapter();
|
||||
//return ReloadAdapter();
|
||||
|
||||
stopWatch.stop();
|
||||
Log.v(TAG, "Reload Adapter - time taken: " + stopWatch.toString());
|
||||
|
||||
return ad;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,182 +0,0 @@
|
|||
/**
|
||||
* Android ownCloud News
|
||||
*
|
||||
* @author David Luhmer
|
||||
* @copyright 2013 David Luhmer david-dev@live.de
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package de.luhmer.owncloudnewsreader;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.database.model.RssItem;
|
||||
import de.luhmer.owncloudnewsreader.reader.IReader;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
|
||||
|
||||
public class MenuUtilsFragmentActivity extends PodcastFragmentActivity {
|
||||
|
||||
protected static final String TAG = "MenuUtils";
|
||||
|
||||
static FragmentActivity activity;
|
||||
|
||||
static MenuItem menuItemSettings;
|
||||
static MenuItem menuItemLogin;
|
||||
static MenuItem menuItemStartImageCaching;
|
||||
|
||||
|
||||
private static MenuItem menuItemUpdater;
|
||||
private static MenuItem menuItemDownloadMoreItems;
|
||||
|
||||
static IReader _Reader;
|
||||
|
||||
/**
|
||||
* @return the menuItemUpdater
|
||||
*/
|
||||
public static MenuItem getMenuItemUpdater() {
|
||||
return menuItemUpdater;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the menuItemDownloadMoreItems
|
||||
*/
|
||||
public static MenuItem getMenuItemDownloadMoreItems() {
|
||||
return menuItemDownloadMoreItems;
|
||||
}
|
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
protected void onResume() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
public static void onCreateOptionsMenu(Menu menu, MenuInflater inflater, FragmentActivity act) {
|
||||
inflater.inflate(R.menu.news_reader, menu);
|
||||
activity = act;
|
||||
|
||||
menuItemSettings = menu.findItem(R.id.action_settings);
|
||||
menuItemLogin = menu.findItem(R.id.action_login);
|
||||
menuItemStartImageCaching = menu.findItem(R.id.menu_StartImageCaching);
|
||||
|
||||
menuItemUpdater = menu.findItem(R.id.menu_update);
|
||||
//menuItemMarkAllAsRead = menu.findItem(R.id.menu_markAllAsRead);
|
||||
menuItemDownloadMoreItems = menu.findItem(R.id.menu_downloadMoreItems);
|
||||
|
||||
|
||||
//menuItemMarkAllAsRead.setEnabled(false);
|
||||
menuItemDownloadMoreItems.setEnabled(false);
|
||||
|
||||
NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) activity.getSupportFragmentManager().findFragmentById(R.id.content_frame));
|
||||
if(ndf != null)
|
||||
ndf.UpdateMenuItemsState();
|
||||
}
|
||||
|
||||
public static boolean onOptionsItemSelected(MenuItem item, FragmentActivity activity) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_About_Changelog:
|
||||
DialogFragment dialog = new VersionInfoDialogFragment();
|
||||
dialog.show(activity.getSupportFragmentManager(), "VersionChangelogDialogFragment");
|
||||
return true;
|
||||
|
||||
case R.id.menu_markAllAsRead:
|
||||
NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) activity.getSupportFragmentManager().findFragmentById(R.id.content_frame));
|
||||
if(ndf != null)
|
||||
{
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(activity);
|
||||
dbConn.markAllItemsAsReadForCurrentView();
|
||||
|
||||
/*
|
||||
for(int i = 0; i < ndf.getListAdapter().getCount(); i++) {
|
||||
RssItem rssItem = (RssItem) ndf.getListAdapter().getItem(i);
|
||||
rssItem.setRead_temp(true);
|
||||
dbConn.updateRssItem(rssItem);
|
||||
}
|
||||
|
||||
ndf.notifyDataSetChangedOnAdapter();
|
||||
*/
|
||||
|
||||
//If tablet view is enabled update the listview as well
|
||||
if(activity instanceof NewsReaderListActivity)
|
||||
((NewsReaderListActivity) activity).updateAdapter();
|
||||
|
||||
ndf.UpdateCurrentRssView(activity, false);
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.menu_downloadMoreItems:
|
||||
DownloadMoreItems();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void DownloadMoreItems()
|
||||
{
|
||||
String username = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()).getString("edt_username", "");
|
||||
String password = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()).getString("edt_password", "");
|
||||
|
||||
if(username != null) {
|
||||
_Reader = new OwnCloud_Reader();
|
||||
((OwnCloud_Reader)_Reader).Start_AsyncTask_GetVersion(Constants.TaskID_GetVersion, activity, onAsyncTaskGetVersionFinished, username, password);
|
||||
|
||||
Toast.makeText(activity, activity.getString(R.string.toast_GettingMoreItems), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
static OnAsyncTaskCompletedListener onAsyncTaskGetVersionFinished = new OnAsyncTaskCompletedListener() {
|
||||
|
||||
@Override
|
||||
public void onAsyncTaskCompleted(int task_id, Object task_result) {
|
||||
if(_Reader != null) {
|
||||
String appVersion = task_result.toString();
|
||||
API api = API.GetRightApiForVersion(appVersion, activity);
|
||||
((OwnCloud_Reader) _Reader).setApi(api);
|
||||
|
||||
NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) activity.getSupportFragmentManager().findFragmentById(R.id.content_frame));
|
||||
_Reader.Start_AsyncTask_GetOldItems(Constants.TaskID_GetItems, activity, onAsyncTaskComplete, ndf.getIdFeed(), ndf.getIdFolder());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static OnAsyncTaskCompletedListener onAsyncTaskComplete = new OnAsyncTaskCompletedListener() {
|
||||
@Override
|
||||
public void onAsyncTaskCompleted(int task_id, Object task_result) {
|
||||
NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) activity.getSupportFragmentManager().findFragmentById(R.id.content_frame));
|
||||
if(ndf != null)
|
||||
ndf.UpdateCurrentRssView(activity, true);
|
||||
|
||||
Log.d(TAG, "Finished Download extra items..");
|
||||
}
|
||||
};
|
||||
}
|
|
@ -41,6 +41,8 @@ import android.widget.ListView;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -141,10 +143,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//setRetainInstance(true);
|
||||
|
||||
//dbConn = new DatabaseConnection(getActivity());
|
||||
|
||||
if(getArguments() != null) {
|
||||
if (getArguments().containsKey(NewsReaderListActivity.FEED_ID)) {
|
||||
idFeed = getArguments().getLong(NewsReaderListActivity.FEED_ID);
|
||||
|
@ -155,14 +153,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
if (getArguments().containsKey(NewsReaderListActivity.FOLDER_ID)) {
|
||||
idFolder = getArguments().getLong(NewsReaderListActivity.FOLDER_ID);
|
||||
}
|
||||
|
||||
//UpdateMenuItemsState();//Is called on Tablets and Smartphones but on Smartphones the menuItemDownloadMoreItems is null. So it will be ignored
|
||||
|
||||
//getListView().setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
|
||||
//lvAdapter = null;
|
||||
|
||||
//getActivity().getSupportLoaderManager().destroyLoader(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +180,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
}
|
||||
|
||||
private AbsListView.OnScrollListener ListScrollListener = new AbsListView.OnScrollListener() {
|
||||
//CheckBox lastViewedArticleCheckbox = null;
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
@ -200,11 +189,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
@Override
|
||||
public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, int totalItemCount) {
|
||||
|
||||
/*
|
||||
if(lastViewedArticleCheckbox == null)
|
||||
lastViewedArticleCheckbox = getCheckBoxAtPosition(0, view);
|
||||
*/
|
||||
|
||||
//When there are no items in the list
|
||||
if(totalItemCount <= 0) {
|
||||
return;
|
||||
|
@ -230,7 +214,7 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
Long rssItemId = (Long)cb.getTag();
|
||||
|
||||
if(!cb.isChecked() && !stayUnreadRssItems.contains(rssItemId)) {
|
||||
NewsListArrayAdapter.ChangeCheckBoxState(cb, true, getActivity());
|
||||
NewsListArrayAdapter.ChangeCheckBoxState(cb, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -238,12 +222,13 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
|
||||
public void UpdateMenuItemsState()
|
||||
{
|
||||
if(MenuUtilsFragmentActivity.getMenuItemDownloadMoreItems() != null)
|
||||
NewsReaderListActivity nla = (NewsReaderListActivity)getActivity();
|
||||
if(nla.getMenuItemDownloadMoreItems() != null)
|
||||
{
|
||||
if(idFolder != null && idFolder == SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS.getValue()) {
|
||||
MenuUtilsFragmentActivity.getMenuItemDownloadMoreItems().setEnabled(false);
|
||||
nla.getMenuItemDownloadMoreItems().setEnabled(false);
|
||||
} else {
|
||||
MenuUtilsFragmentActivity.getMenuItemDownloadMoreItems().setEnabled(true);
|
||||
nla.getMenuItemDownloadMoreItems().setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -260,9 +245,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private CheckBox getCheckBoxAtPosition(int pos, AbsListView viewLV)
|
||||
{
|
||||
ListView lv = (ListView) viewLV;
|
||||
|
@ -275,12 +257,6 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
//if(lvAdapter != null)
|
||||
// lvAdapter.CloseDatabaseConnection();
|
||||
//if(lvAdapter != null)
|
||||
// lvAdapter.CloseDatabaseConnection();
|
||||
//if(dbConn != null)
|
||||
// dbConn.closeDatabase();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -342,6 +318,9 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
|
||||
@Override
|
||||
protected LazyList<RssItem> doInBackground(Void... urls) {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
|
||||
|
||||
if(refreshCurrentRssView) {
|
||||
|
@ -367,7 +346,12 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr
|
|||
|
||||
setUpdateListViewOnStartUp(false);//Always reset this variable here. Otherwise the list will be cleared when the activity is restarted
|
||||
|
||||
return dbConn.getCurrentRssItemView(sortDirection);
|
||||
LazyList<RssItem> list = dbConn.getCurrentRssItemView(sortDirection);
|
||||
|
||||
stopWatch.stop();
|
||||
Log.v(TAG, "Reloaded CurrentRssView - time taken: " + stopWatch.toString());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,16 +31,19 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.widget.SlidingPaneLayout;
|
||||
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.amlcurran.showcaseview.OnShowcaseEventListener;
|
||||
import com.github.amlcurran.showcaseview.ShowcaseView;
|
||||
|
@ -59,6 +62,10 @@ import de.luhmer.owncloudnewsreader.helper.DatabaseUtils;
|
|||
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
|
||||
import de.luhmer.owncloudnewsreader.helper.ShowcaseDimHelper;
|
||||
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
|
||||
import de.luhmer.owncloudnewsreader.reader.IReader;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
|
||||
import de.luhmer.owncloudnewsreader.services.DownloadImagesService;
|
||||
import de.luhmer.owncloudnewsreader.services.IOwnCloudSyncService;
|
||||
|
||||
|
@ -73,21 +80,21 @@ import de.luhmer.owncloudnewsreader.services.IOwnCloudSyncService;
|
|||
* {@link NewsReaderListFragment.Callbacks} interface to listen for item
|
||||
* selections.
|
||||
*/
|
||||
public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
||||
public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
||||
NewsReaderListFragment.Callbacks {
|
||||
|
||||
@InjectView(R.id.sliding_pane) SlidingPaneLayout mSlidingLayout;
|
||||
|
||||
|
||||
//static final String TAG = "NewsReaderListActivity";
|
||||
//ActionBarDrawerToggle drawerToggle;
|
||||
//DrawerLayout drawerLayout;
|
||||
private static final String TAG = NewsReaderListActivity.class.getCanonicalName();
|
||||
|
||||
public static final String FOLDER_ID = "FOLDER_ID";
|
||||
public static final String FEED_ID = "FEED_ID";
|
||||
public static final String ITEM_ID = "ITEM_ID";
|
||||
public static final String TITEL = "TITEL";
|
||||
private static MenuItem menuItemUpdater;
|
||||
private static MenuItem menuItemDownloadMoreItems;
|
||||
private static IReader _Reader;
|
||||
|
||||
@InjectView(R.id.toolbar) Toolbar toolbar;
|
||||
@InjectView(R.id.sliding_pane) SlidingPaneLayout mSlidingLayout;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
|
@ -102,24 +109,7 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
AccountManager mAccountManager = AccountManager.get(this);
|
||||
|
||||
boolean isAccountThere = false;
|
||||
//Remove all accounts first
|
||||
Account[] accounts = mAccountManager.getAccounts();
|
||||
for (Account account : accounts) {
|
||||
if (account.type.intern().equals(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
isAccountThere = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isAccountThere) {
|
||||
//Then add the new account
|
||||
Account account = new Account(getString(R.string.app_name), AccountGeneral.ACCOUNT_TYPE);
|
||||
mAccountManager.addAccountExplicitly(account, "", new Bundle());
|
||||
|
||||
SyncIntervalSelectorActivity.SetAccountSyncInterval(this);
|
||||
}
|
||||
initAccountManager();
|
||||
|
||||
//Init config --> if nothing is configured start the login dialog.
|
||||
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
@ -135,40 +125,7 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
|
||||
mSlidingLayout.setParallaxDistance(280);
|
||||
mSlidingLayout.setSliderFadeColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
mSlidingLayout.setPanelSlideListener(new PanelSlideListener() {
|
||||
|
||||
@Override
|
||||
public void onPanelSlide(View arg0, float arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPanelOpened(View arg0) {
|
||||
togglePodcastVideoViewAnimation();
|
||||
|
||||
updateAdapter();
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
getSupportActionBar().setHomeButtonEnabled(false);
|
||||
|
||||
getMenuItemUpdater().setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPanelClosed(View arg0) {
|
||||
togglePodcastVideoViewAnimation();
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
|
||||
getMenuItemUpdater().setVisible(true);
|
||||
|
||||
StartDetailFragmentNow();
|
||||
|
||||
EventBus.getDefault().post(new FeedPanelSlideEvent(false));
|
||||
}
|
||||
});
|
||||
|
||||
mSlidingLayout.setPanelSlideListener(panelSlideListener);
|
||||
mSlidingLayout.openPane();
|
||||
|
||||
if(savedInstanceState == null)//When the app starts (no orientation change)
|
||||
|
@ -243,6 +200,64 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
|
||||
|
||||
|
||||
private PanelSlideListener panelSlideListener = new PanelSlideListener() {
|
||||
@Override
|
||||
public void onPanelSlide(View arg0, float arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPanelOpened(View arg0) {
|
||||
togglePodcastVideoViewAnimation();
|
||||
|
||||
reloadCountNumbersOfSlidingPaneAdapter();
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
getSupportActionBar().setHomeButtonEnabled(false);
|
||||
|
||||
menuItemUpdater.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPanelClosed(View arg0) {
|
||||
togglePodcastVideoViewAnimation();
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
|
||||
menuItemUpdater.setVisible(true);
|
||||
|
||||
StartDetailFragmentNow();
|
||||
|
||||
EventBus.getDefault().post(new FeedPanelSlideEvent(false));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check if the account is in the Android Account Manager. If not it will be added automatically
|
||||
*/
|
||||
private void initAccountManager() {
|
||||
AccountManager mAccountManager = AccountManager.get(this);
|
||||
|
||||
boolean isAccountThere = false;
|
||||
Account[] accounts = mAccountManager.getAccounts();
|
||||
for (Account account : accounts) {
|
||||
if (account.type.intern().equals(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
isAccountThere = true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the account is not in the Android Account Manager
|
||||
if(!isAccountThere) {
|
||||
//Then add the new account
|
||||
Account account = new Account(getString(R.string.app_name), AccountGeneral.ACCOUNT_TYPE);
|
||||
mAccountManager.addAccountExplicitly(account, "", new Bundle());
|
||||
|
||||
SyncIntervalSelectorActivity.SetAccountSyncInterval(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void safeInstanceState(Bundle outState) {
|
||||
outState.putBoolean(SLIDING_PANE_OPEN_BOOLEAN, mSlidingLayout.isOpen());
|
||||
|
||||
|
@ -309,8 +324,8 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
return nrdf;
|
||||
}
|
||||
|
||||
public void updateAdapter() {
|
||||
NewsReaderListFragment nlf = ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer));
|
||||
public void reloadCountNumbersOfSlidingPaneAdapter() {
|
||||
NewsReaderListFragment nlf = getSlidingListFragment();
|
||||
if(nlf != null) {
|
||||
nlf.ListViewNotifyDataSetChanged();
|
||||
}
|
||||
|
@ -322,7 +337,11 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
protected void onResume() {
|
||||
ThemeChooser.chooseTheme(this);
|
||||
|
||||
updateAdapter();
|
||||
reloadCountNumbersOfSlidingPaneAdapter();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
@ -379,8 +398,9 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
|
||||
private NewsReaderDetailFragment StartDetailFragment(long id, Boolean folder, Long optional_folder_id, boolean updateListView)
|
||||
{
|
||||
if(super.getMenuItemDownloadMoreItems() != null)
|
||||
super.getMenuItemDownloadMoreItems().setEnabled(true);
|
||||
if(menuItemDownloadMoreItems != null) {
|
||||
menuItemDownloadMoreItems.setEnabled(true);
|
||||
}
|
||||
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(getApplicationContext());
|
||||
|
||||
|
@ -422,10 +442,9 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
public void UpdateItemList()
|
||||
{
|
||||
try {
|
||||
NewsReaderDetailFragment nrD = (NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);
|
||||
NewsReaderDetailFragment nrD = getDetailFragment();
|
||||
if (nrD != null)
|
||||
((NewsListArrayAdapter) nrD.getListAdapter()).notifyDataSetChanged();
|
||||
//nrD.UpdateCursor();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -434,16 +453,15 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
|
||||
void startSync()
|
||||
{
|
||||
//menuItemUpdater.setActionView(R.layout.inderterminate_progress);
|
||||
((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)).StartSync();
|
||||
getSlidingListFragment().StartSync();
|
||||
}
|
||||
|
||||
public void UpdateButtonLayout()
|
||||
{
|
||||
if(super.getMenuItemUpdater() != null)
|
||||
if(menuItemUpdater != null)
|
||||
{
|
||||
try {
|
||||
NewsReaderListFragment ndf = (NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer);
|
||||
NewsReaderListFragment ndf = getSlidingListFragment();
|
||||
SwipeRefreshLayout pullToRefreshView = ndf.mPullToRefreshLayout;
|
||||
|
||||
if(ndf._ownCloudSyncService != null) {
|
||||
|
@ -452,7 +470,7 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
if(_Reader.isSyncRunning())
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
super.getMenuItemUpdater().setActionView(R.layout.inderterminate_progress);
|
||||
menuItemUpdater.setActionView(R.layout.inderterminate_progress);
|
||||
|
||||
if(pullToRefreshView != null && !pullToRefreshView.isRefreshing()) {
|
||||
pullToRefreshView.setRefreshing(true);
|
||||
|
@ -462,7 +480,7 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
else
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
super.getMenuItemUpdater().setActionView(null);
|
||||
menuItemUpdater.setActionView(null);
|
||||
|
||||
if(pullToRefreshView != null) {
|
||||
pullToRefreshView.setRefreshing(false);
|
||||
|
@ -480,13 +498,26 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
super.onCreateOptionsMenu(menu, getMenuInflater(), this);
|
||||
getMenuInflater().inflate(R.menu.news_reader, menu);
|
||||
|
||||
menuItemUpdater = menu.findItem(R.id.menu_update);
|
||||
menuItemDownloadMoreItems = menu.findItem(R.id.menu_downloadMoreItems);
|
||||
|
||||
menuItemDownloadMoreItems.setEnabled(false);
|
||||
|
||||
NewsReaderDetailFragment ndf = getDetailFragment();
|
||||
if(ndf != null)
|
||||
ndf.UpdateMenuItemsState();
|
||||
|
||||
UpdateButtonLayout();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public MenuItem getMenuItemDownloadMoreItems() {
|
||||
return menuItemDownloadMoreItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if(handlePodcastBackPressed());
|
||||
|
@ -501,80 +532,129 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean handled = super.onOptionsItemSelected(item, this);
|
||||
switch (item.getItemId()) {
|
||||
|
||||
if(!handled)
|
||||
{
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if(handlePodcastBackPressed());
|
||||
else if(!mSlidingLayout.isOpen())
|
||||
mSlidingLayout.openPane();
|
||||
return true;
|
||||
|
||||
case android.R.id.home:
|
||||
if(handlePodcastBackPressed());
|
||||
else if(!mSlidingLayout.isOpen())
|
||||
mSlidingLayout.openPane();
|
||||
return true;
|
||||
case R.id.action_settings:
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivityForResult(intent, RESULT_SETTINGS);
|
||||
return true;
|
||||
|
||||
case R.id.action_settings:
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
//intent.putExtra(EXTRA_MESSAGE, message);
|
||||
startActivityForResult(intent, RESULT_SETTINGS);
|
||||
return true;
|
||||
case R.id.menu_update:
|
||||
startSync();
|
||||
break;
|
||||
|
||||
case R.id.menu_update:
|
||||
//menuItemUpdater = item.setActionView(R.layout.inderterminate_progress);
|
||||
startSync();
|
||||
break;
|
||||
case R.id.action_login:
|
||||
StartLoginFragment(NewsReaderListActivity.this);
|
||||
break;
|
||||
|
||||
case R.id.action_login:
|
||||
StartLoginFragment(NewsReaderListActivity.this);
|
||||
break;
|
||||
case R.id.action_add_new_feed:
|
||||
Intent newFeedIntent = new Intent(this, NewFeedActivity.class);
|
||||
startActivityForResult(newFeedIntent, RESULT_ADD_NEW_FEED);
|
||||
break;
|
||||
|
||||
case R.id.action_add_new_feed:
|
||||
Intent newFeedIntent = new Intent(this, NewFeedActivity.class);
|
||||
startActivityForResult(newFeedIntent, RESULT_ADD_NEW_FEED);
|
||||
break;
|
||||
case R.id.menu_StartImageCaching:
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);
|
||||
|
||||
case R.id.menu_StartImageCaching:
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);
|
||||
long highestItemId = dbConn.getLowestRssItemIdUnread();
|
||||
Intent service = new Intent(this, DownloadImagesService.class);
|
||||
service.putExtra(DownloadImagesService.LAST_ITEM_ID, highestItemId);
|
||||
startService(service);
|
||||
|
||||
long highestItemId = dbConn.getLowestRssItemIdUnread();
|
||||
Intent service = new Intent(this, DownloadImagesService.class);
|
||||
service.putExtra(DownloadImagesService.LAST_ITEM_ID, highestItemId);
|
||||
startService(service);
|
||||
break;
|
||||
|
||||
break;
|
||||
case R.id.menu_CreateDatabaseDump:
|
||||
DatabaseUtils.CopyDatabaseToSdCard(this);
|
||||
|
||||
case R.id.menu_CreateDatabaseDump:
|
||||
DatabaseUtils.CopyDatabaseToSdCard(this);
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage("Created dump at: " + DatabaseUtils.GetPath(this))
|
||||
.setNeutralButton(getString(android.R.string.ok), null)
|
||||
.show();
|
||||
break;
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage("Created dump at: " + DatabaseUtils.GetPath(this))
|
||||
.setNeutralButton(getString(android.R.string.ok), null)
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
case R.id.menu_About_Changelog:
|
||||
DialogFragment dialog = new VersionInfoDialogFragment();
|
||||
dialog.show(getSupportFragmentManager(), "VersionChangelogDialogFragment");
|
||||
return true;
|
||||
|
||||
case R.id.menu_markAllAsRead:
|
||||
NewsReaderDetailFragment ndf = getDetailFragment();
|
||||
if(ndf != null)
|
||||
{
|
||||
DatabaseConnectionOrm dbConn2 = new DatabaseConnectionOrm(this);
|
||||
dbConn2.markAllItemsAsReadForCurrentView();
|
||||
|
||||
reloadCountNumbersOfSlidingPaneAdapter();
|
||||
ndf.UpdateCurrentRssView(this, false);
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.menu_downloadMoreItems:
|
||||
DownloadMoreItems();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
private void DownloadMoreItems()
|
||||
{
|
||||
String username = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("edt_username", "");
|
||||
String password = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("edt_password", "");
|
||||
|
||||
if(username != null) {
|
||||
_Reader = new OwnCloud_Reader();
|
||||
((OwnCloud_Reader)_Reader).Start_AsyncTask_GetVersion(Constants.TaskID_GetVersion, this, onAsyncTaskGetVersionFinished, username, password);
|
||||
|
||||
Toast.makeText(this, getString(R.string.toast_GettingMoreItems), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
OnAsyncTaskCompletedListener onAsyncTaskGetVersionFinished = new OnAsyncTaskCompletedListener() {
|
||||
|
||||
@Override
|
||||
public void onAsyncTaskCompleted(int task_id, Object task_result) {
|
||||
if(_Reader != null) {
|
||||
String appVersion = task_result.toString();
|
||||
API api = API.GetRightApiForVersion(appVersion, NewsReaderListActivity.this);
|
||||
((OwnCloud_Reader) _Reader).setApi(api);
|
||||
|
||||
NewsReaderDetailFragment ndf = getDetailFragment();
|
||||
_Reader.Start_AsyncTask_GetOldItems(Constants.TaskID_GetItems, NewsReaderListActivity.this, onAsyncTaskComplete, ndf.getIdFeed(), ndf.getIdFolder());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
OnAsyncTaskCompletedListener onAsyncTaskComplete = new OnAsyncTaskCompletedListener() {
|
||||
@Override
|
||||
public void onAsyncTaskCompleted(int task_id, Object task_result) {
|
||||
NewsReaderDetailFragment ndf = getDetailFragment();
|
||||
if(ndf != null)
|
||||
ndf.UpdateCurrentRssView(NewsReaderListActivity.this, true);
|
||||
|
||||
Log.v(TAG, "Finished Download extra items..");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
//if (requestCode == 1) {
|
||||
if(resultCode == RESULT_OK){
|
||||
int pos = data.getIntExtra("POS", 0);
|
||||
UpdateListViewAndScrollToPos(this, pos);
|
||||
UpdateListView(this);
|
||||
|
||||
((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)).ListViewNotifyDataSetChanged();
|
||||
getSlidingListFragment().ListViewNotifyDataSetChanged();
|
||||
}
|
||||
|
||||
if(requestCode == RESULT_SETTINGS)
|
||||
{
|
||||
((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)).ReloadAdapter();
|
||||
//((NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame)).UpdateCurrentRssView(this, false);
|
||||
getSlidingListFragment().ReloadAdapter();
|
||||
|
||||
if(ThemeChooser.ThemeRequiresRestartOfUI(this)) {
|
||||
finish();
|
||||
finish();
|
||||
startActivity(getIntent());
|
||||
}
|
||||
} else if(requestCode == RESULT_ADD_NEW_FEED) {
|
||||
|
@ -586,6 +666,13 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
private NewsReaderListFragment getSlidingListFragment() {
|
||||
return ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer));
|
||||
}
|
||||
|
||||
private NewsReaderDetailFragment getDetailFragment() {
|
||||
return (NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);
|
||||
}
|
||||
|
||||
public static void StartLoginFragment(final FragmentActivity activity)
|
||||
{
|
||||
|
@ -602,15 +689,8 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
|
|||
}
|
||||
|
||||
|
||||
//@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
public static void UpdateListViewAndScrollToPos(FragmentActivity act, int pos)
|
||||
public static void UpdateListView(FragmentActivity act)
|
||||
{
|
||||
((NewsReaderDetailFragment) act.getSupportFragmentManager().findFragmentById(R.id.content_frame)).notifyDataSetChangedOnAdapter();
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
|
||||
//((NewsReaderDetailFragment) act.getSupportFragmentManager().findFragmentById(R.id.newsreader_detail_container)).getListView().smoothScrollToPosition(pos);
|
||||
//else
|
||||
|
||||
//Is not used any longer
|
||||
//((NewsReaderDetailFragment) act.getSupportFragmentManager().findFragmentById(R.id.content_frame)).getListView().setSelection(pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -408,7 +408,7 @@ public class NewsListArrayAdapter extends GreenDaoListAdapter<RssItem> {
|
|||
cbRead.setChecked(read);
|
||||
}
|
||||
|
||||
public static void ChangeCheckBoxState(CheckBox cb, boolean state, Context context)
|
||||
public static void ChangeCheckBoxState(CheckBox cb, boolean state)
|
||||
{
|
||||
if(cb != null && cb.isChecked() != state)
|
||||
cb.setChecked(state);
|
||||
|
@ -419,7 +419,7 @@ public class NewsListArrayAdapter extends GreenDaoListAdapter<RssItem> {
|
|||
FragmentActivity sfa = (FragmentActivity) context;
|
||||
|
||||
if(sfa instanceof NewsReaderListActivity && ((NewsReaderListActivity) sfa).isSlidingPaneOpen())
|
||||
((NewsReaderListActivity) sfa).updateAdapter();
|
||||
((NewsReaderListActivity) sfa).reloadCountNumbersOfSlidingPaneAdapter();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue