Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NewsReaderListActivity.java « owncloudnewsreader « luhmer « de « java « main « src « News-Android-App - github.com/nextcloud/news-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d5398893d4251d81142012a0469e00e43de65df (plain)
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/**
* 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.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.Settings;
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.view.View;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.LoginDialogFragment.LoginSuccessfullListener;
import de.luhmer.owncloudnewsreader.authentication.AccountGeneral;
import de.luhmer.owncloudnewsreader.cursor.NewsListCursorAdapter;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.DatabaseUtils;
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
import de.luhmer.owncloudnewsreader.helper.MenuUtilsSherlockFragmentActivity;
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
import de.luhmer.owncloudnewsreader.services.DownloadImagesService;
import de.luhmer.owncloudnewsreader.services.IOwnCloudSyncService;
import de.luhmer.owncloudnewsreader.view.PodcastSlidingUpPanelLayout;
import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout;

/**
 * An activity representing a list of NewsReader. This activity has different
 * presentations for handset and tablet-size devices.
 * The activity makes heavy use of fragments. The list of items is a
 * {@link NewsReaderListFragment} and the item details (if present) is a
 * {@link NewsReaderDetailFragment}.
 * <p>
 * This activity also implements the required
 * {@link NewsReaderListFragment.Callbacks} interface to listen for item
 * selections.
 */
public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity implements
		 NewsReaderListFragment.Callbacks {

	private SlidingPaneLayout mSlidingLayout;
    public PodcastSlidingUpPanelLayout sliding_layout;

	//static final String TAG = "NewsReaderListActivity";
	//ActionBarDrawerToggle drawerToggle;
	//DrawerLayout drawerLayout;

	public static final String FOLDER_ID = "FOLDER_ID";
	public static final String SUBSCRIPTION_ID = "SUBSCRIPTION_ID";
	public static final String ITEM_ID = "ITEM_ID";
	public static final String TITEL = "TITEL";

    PodcastFragment podcastFragment;
    //boolean isSlideUpPanelExpanded = false;

	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		ThemeChooser.chooseTheme(this);

		//setTheme(R.style.Theme_Sherlock);

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_newsreader);


		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)) {
                //mAccountManager.removeAccount(accounts[index], null, null);
                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());
	    	//ContentResolver.setSyncAutomatically(account, getString(R.string.authorities), true);
			//ContentResolver.setIsSyncable(account, getString(R.string.authorities), 1);
	    }

		//Init config --> if nothing is configured start the login dialog.
        SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        if(mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null) == null)
        	StartLoginFragment(NewsReaderListActivity.this);


        // Insert the fragment by replacing any existing fragment
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
        				.replace(R.id.left_drawer, new NewsReaderListFragment())
                   		.commit();






        sliding_layout = (PodcastSlidingUpPanelLayout) findViewById(R.id.sliding_layout);
        UpdatePodcastView();



        mSlidingLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane);

        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) {
				updateAdapter();

                getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                getSupportActionBar().setHomeButtonEnabled(false);

                getMenuItemUpdater().setVisible(false);
			}

			@Override
			public void onPanelClosed(View arg0) {
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setHomeButtonEnabled(true);

                getMenuItemUpdater().setVisible(true);

				StartDetailFragmentNow();
			}
		});
        mSlidingLayout.openPane();











        /*
		// Get a reference of the DrawerLayout
		drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
		*/

		// Set a listener to be notified of drawer events.
		//drawerLayout.setDrawerListener(drawerToggle);


        //if(mPrefs.getBoolean(SettingsActivity.CB_SYNCONSTARTUP_STRING, false))
		//	startSync();

        /*
		if(!shouldDrawerStayOpen()) {
			getSupportActionBar().setDisplayHomeAsUpEnabled(true);
			getSupportActionBar().setHomeButtonEnabled(true);
		}*/

        if(savedInstanceState == null)//When the app starts (no orientation change)
        {
        	startDetailFHolder = new StartDetailFragmentHolder(SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS.getValueString(), true, null, true);
        	StartDetailFragmentNow();
        }


        ImageHandler.createNoMediaFile(this);
        //AppRater.app_launched(this);
        //AppRater.rateNow(this);

        //onTopItemClicked(SubscriptionExpandableListAdapter.ALL_UNREAD_ITEMS, true, null);
    }


	private static final String FIRST_VISIBLE_DETAIL_ITEM_STRING = "FIRST_VISIBLE_DETAIL_ITEM_STRING";
	private static final String FIRST_VISIBLE_DETAIL_ITEM_MARGIN_TOP_STRING = "FIRST_VISIBLE_DETAIL_ITEM_MARGIN_TOP_STRING";
	private static final String ID_FEED_STRING = "ID_FEED_STRING";
	private static final String IS_FOLDER_BOOLEAN = "IS_FOLDER_BOOLEAN";
	private static final String OPTIONAL_FOLDER_ID ="OPTIONAL_FOLDER_ID";


    public void UpdatePodcastView() {

        if(podcastFragment != null) {
            getSupportFragmentManager().beginTransaction().remove(podcastFragment).commitAllowingStateLoss();
        }


        SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        if(mPrefs.getBoolean(SettingsActivity.CB_ENABLE_PODCASTS_STRING, false)) {
            podcastFragment = PodcastFragment.newInstance(null, null);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.podcast_frame, podcastFragment)
                    .commitAllowingStateLoss();
        } else {
            sliding_layout.getChildAt(1).setVisibility(View.GONE);
            podcastFragment = null;
        }
    }

	/* (non-Javadoc)
	 * @see com.actionbarsherlock.app.SherlockFragmentActivity#onSaveInstanceState(android.os.Bundle)
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {

		NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame));
		if(ndf != null) {
			View v = ndf.getListView().getChildAt(0);
			int top = (v == null) ? 0 : v.getTop();

			outState.putInt(FIRST_VISIBLE_DETAIL_ITEM_STRING, ndf.getListView().getFirstVisiblePosition());
			outState.putInt(FIRST_VISIBLE_DETAIL_ITEM_MARGIN_TOP_STRING, top);
			outState.putString(OPTIONAL_FOLDER_ID, ndf.getIdFeed() == null ? ndf.getIdFolder() : ndf.getIdFeed());
			outState.putBoolean(IS_FOLDER_BOOLEAN, ndf.getIdFeed() == null);
			outState.putString(ID_FEED_STRING, ndf.getIdFeed() != null ? ndf.getIdFolder() : ndf.getIdFeed());
		}

        //outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
		super.onSaveInstanceState(outState);
	}

	/* (non-Javadoc)
	 * @see com.actionbarsherlock.app.SherlockFragmentActivity#onRestoreInstanceState(android.os.Bundle)
	 */
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		if(savedInstanceState != null) {
			if(savedInstanceState.containsKey(FIRST_VISIBLE_DETAIL_ITEM_STRING) &&
					savedInstanceState.containsKey(ID_FEED_STRING) &&
					savedInstanceState.containsKey(IS_FOLDER_BOOLEAN) &&
					savedInstanceState.containsKey(OPTIONAL_FOLDER_ID)) {


				startDetailFHolder = new StartDetailFragmentHolder(savedInstanceState.getString(OPTIONAL_FOLDER_ID),
																	savedInstanceState.getBoolean(IS_FOLDER_BOOLEAN),
																	savedInstanceState.getString(ID_FEED_STRING),
                                                                    false);

	        	NewsReaderDetailFragment ndf = StartDetailFragmentNow();
	        	if(ndf != null) {
	        		ndf.setActivatedPosition(savedInstanceState.getInt(FIRST_VISIBLE_DETAIL_ITEM_STRING));
	        		ndf.setMarginFromTop(savedInstanceState.getInt(FIRST_VISIBLE_DETAIL_ITEM_MARGIN_TOP_STRING));
	        	}
			}
		}
		super.onRestoreInstanceState(savedInstanceState);
	}


    public boolean isSlidingPaneOpen() {
        return mSlidingLayout.isOpen();
    }

	private NewsReaderDetailFragment StartDetailFragmentNow() {
		NewsReaderDetailFragment nrdf = null;
		if(startDetailFHolder != null) {
			nrdf = startDetailFHolder.StartDetailFragment();
			startDetailFHolder = null;
		}
		return nrdf;
	}

	public void updateAdapter() {
        NewsReaderListFragment nlf = ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer));
        if(nlf != null) {
            nlf.ListViewNotifyDataSetChanged();
        }
    }



	@Override
	protected void onResume() {
		ThemeChooser.chooseTheme(this);

		updateAdapter();

		super.onResume();
	}

	public boolean shouldDrawerStayOpen() {
        return getResources().getBoolean(R.bool.two_pane);
    }

	private StartDetailFragmentHolder startDetailFHolder = null;

	private class StartDetailFragmentHolder {
		String idSubscription;
		boolean isFolder;
		String optional_folder_id;
        boolean updateListView;

		public StartDetailFragmentHolder(String idSubscription, boolean isFolder, String optional_folder_id, boolean updateListView) {
			this.idSubscription = idSubscription;
			this.isFolder = isFolder;
			this.optional_folder_id = optional_folder_id;
            this.updateListView = updateListView;
		}

		public NewsReaderDetailFragment StartDetailFragment() {
			return NewsReaderListActivity.this.StartDetailFragment(idSubscription, isFolder, optional_folder_id, updateListView);
		}
	}

	/**
	 * Callback method from {@link NewsReaderListFragment.Callbacks} indicating
	 * that the item with the given ID was selected.
	 */
	@Override
	public void onTopItemClicked(String idSubscription, boolean isFolder, String optional_folder_id) {
		if(!shouldDrawerStayOpen())
			mSlidingLayout.closePane();

		startDetailFHolder = new StartDetailFragmentHolder(idSubscription, isFolder, optional_folder_id, true);

		if(shouldDrawerStayOpen())
			StartDetailFragmentNow();
	}

	@Override
	public void onChildItemClicked(String idSubscription, String optional_folder_id) {
		if(!shouldDrawerStayOpen())
			mSlidingLayout.closePane();

		//StartDetailFragment(idSubscription, false, optional_folder_id);
		startDetailFHolder = new StartDetailFragmentHolder(idSubscription, false, optional_folder_id, true);
		if(shouldDrawerStayOpen())
			StartDetailFragmentNow();
	}

	private NewsReaderDetailFragment StartDetailFragment(String id, Boolean folder, String optional_folder_id, boolean UpdateListView)
	{
		if(super.getMenuItemDownloadMoreItems() != null)
			super.getMenuItemDownloadMoreItems().setEnabled(true);

		DatabaseConnection dbConn = new DatabaseConnection(getApplicationContext());


		Intent intent = new Intent();

		if(!folder)
		{
			intent.putExtra(SUBSCRIPTION_ID, id);
			intent.putExtra(FOLDER_ID, optional_folder_id);
			intent.putExtra(TITEL, dbConn.getTitleOfSubscriptionByRowID(id));
		}
		else
		{
			intent.putExtra(FOLDER_ID, id);
			int idFolder = Integer.valueOf(id);
			if(idFolder >= 0)
				intent.putExtra(TITEL, dbConn.getTitleOfFolderByID(id));
			else if(idFolder == -10)
				intent.putExtra(TITEL, getString(R.string.allUnreadFeeds));
			else if(idFolder == -11)
				intent.putExtra(TITEL, getString(R.string.starredFeeds));
		}

		Bundle arguments = intent.getExtras();

		NewsReaderDetailFragment fragment = new NewsReaderDetailFragment();
        fragment.setUpdateListViewOnStartUp(UpdateListView);

		fragment.setArguments(arguments);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, fragment)
				.commit();

		dbConn.closeDatabase();

		return fragment;
	}


    public void UpdateItemList()
    {
        NewsReaderDetailFragment nrD = (NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);
        if(nrD != null)
            ((NewsListCursorAdapter)nrD.getListAdapter()).notifyDataSetChanged();
            //nrD.UpdateCursor();
    }


    void startSync()
    {
		//menuItemUpdater.setActionView(R.layout.inderterminate_progress);
		((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)).StartSync();
    }

	public void UpdateButtonSyncLayout()
    {
        if(super.getMenuItemUpdater() != null)
        {
            //IReader _Reader = ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer))._Reader;


            try {
                NewsReaderListFragment ndf = (NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer);
            	IOwnCloudSyncService _Reader = ndf._ownCloudSyncService;
                PullToRefreshLayout pullToRefreshView = ndf.mPullToRefreshLayout;

                if(_Reader != null) {
					if(_Reader.isSyncRunning())
					{
						super.getMenuItemUpdater().setActionView(R.layout.inderterminate_progress);
					    if(pullToRefreshView != null && !pullToRefreshView.isRefreshing()) {
					    	pullToRefreshView.setRefreshing(true);
                        }
					}
					else
					{
						super.getMenuItemUpdater().setActionView(null);
					    if(pullToRefreshView != null)
					    	pullToRefreshView.setRefreshComplete();
					}
                }
			} catch (RemoteException e) {
				e.printStackTrace();
			}
        }
    }


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		//getMenuInflater().inflate(R.menu.news_reader, menu);
		//getSupportMenuInflater().inflate(R.menu.news_reader, menu);


		super.onCreateOptionsMenu(menu, getSupportMenuInflater(), this);

        UpdateButtonSyncLayout();

		return true;
	}

	@Override
	public void onBackPressed() {
        if(podcastFragment != null && sliding_layout.isPanelExpanded()) {
            if (!podcastFragment.onBackPressed())
                sliding_layout.collapsePanel();
        } else if(mSlidingLayout.isOpen())
			super.onBackPressed();
		else
			mSlidingLayout.openPane();
	}

	private static final int RESULT_SETTINGS = 15642;
    private static final int RESULT_ADD_NEW_FEED = 15643;

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		boolean handled = super.onOptionsItemSelected(item, this);

		if(!handled)
		{
			switch (item.getItemId()) {

				case android.R.id.home:
                    if(podcastFragment != null && sliding_layout.isPanelExpanded()) {
                        if (!podcastFragment.onBackPressed())
                            sliding_layout.collapsePanel();
                    }
					else if(!mSlidingLayout.isOpen())
						mSlidingLayout.openPane();
					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.action_sync_settings:
                    String[] authorities = { "de.luhmer.owncloudnewsreader" };
                    Intent intentSyncSettings = new Intent(Settings.ACTION_SYNC_SETTINGS);
                    intentSyncSettings.putExtra(Settings.EXTRA_AUTHORITIES, authorities);
                    startActivity(intentSyncSettings);
                    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_add_new_feed:
                    Intent newFeedIntent = new Intent(this, NewFeedActivity.class);
                    startActivityForResult(newFeedIntent, RESULT_ADD_NEW_FEED);
                    break;

				case R.id.menu_StartImageCaching:
					DatabaseConnection dbConn = new DatabaseConnection(this);
			    	try {
			    		long highestItemId = dbConn.getLowestItemIdUnread();
			    		Intent service = new Intent(this, DownloadImagesService.class);
			        	service.putExtra(DownloadImagesService.LAST_ITEM_ID, highestItemId);
                        //service.putExtra(DownloadImagesService.DOWNLOAD_FAVICONS_EXCLUSIVE, true);
			    		startService(service);
			    	} finally {
			    		dbConn.closeDatabase();
			    	}
					break;

                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;
			}
		}
		return super.onOptionsItemSelected(item);
	}


    @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);

            ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)).ListViewNotifyDataSetChanged();
        }

        if(requestCode == RESULT_SETTINGS)
        {
        	((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)).ReloadAdapter();
        	((NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame)).UpdateCursor();

            UpdatePodcastView();
        } else if(requestCode == RESULT_ADD_NEW_FEED) {
            if(data != null) {
                boolean val = data.getBooleanExtra(NewFeedActivity.ADD_NEW_SUCCESS, false);
                if (val)
                    startSync();
            }
        }
    }


    public static void StartLoginFragment(final SherlockFragmentActivity activity)
    {
	   	LoginDialogFragment dialog = LoginDialogFragment.getInstance();
	   	dialog.setActivity(activity);
	   	dialog.setListener(new LoginSuccessfullListener() {

            @Override
            public void LoginSucceeded() {
                ((NewsReaderListActivity) activity).startSync();
            }
        });
	    dialog.show(activity.getSupportFragmentManager(), "NoticeDialogFragment");
    }

    /*
    @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);
			}
			if (resultCode == RESULT_CANCELED) {
				//Write your code on no result return
			}
		//}
	}*/


    //@TargetApi(Build.VERSION_CODES.FROYO)
	public static void UpdateListViewAndScrollToPos(FragmentActivity act, int pos)
    {
        ((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);
    }
}