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

SubscriptionExpandableListAdapter.java « ListView « 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: 960247cd9d0579d26e39a6f1106b2c770425620a (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
/*
* 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.ListView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.Feed;
import de.luhmer.owncloudnewsreader.database.model.Folder;
import de.luhmer.owncloudnewsreader.databinding.SubscriptionListItemBinding;
import de.luhmer.owncloudnewsreader.databinding.SubscriptionListSubItemBinding;
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
import de.luhmer.owncloudnewsreader.helper.StopWatch;
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
import de.luhmer.owncloudnewsreader.interfaces.ExpListTextClicked;
import de.luhmer.owncloudnewsreader.model.AbstractItem;
import de.luhmer.owncloudnewsreader.model.ConcreteFeedItem;
import de.luhmer.owncloudnewsreader.model.FolderSubscribtionItem;
import de.luhmer.owncloudnewsreader.model.Tuple;

import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_STARRED_ITEMS;
import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS;
import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ITEMS_WITHOUT_FOLDER;

public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter {
    private final String TAG = getClass().getCanonicalName();

    private final Context mContext;
    private final DatabaseConnectionOrm dbConn;

    private final ListView listView;

    private ExpListTextClicked eListTextClickHandler;

    private final FavIconHandler favIconHandler;

    private ArrayList<AbstractItem> mCategoriesArrayList;
    private SparseArray<ArrayList<ConcreteFeedItem>> mItemsArrayList;
    private boolean showOnlyUnread = false;
    private Integer btn_rating_star_off_normal_holo_light;

    private SparseArray<String> starredCountFeeds;
    private SparseArray<String> unreadCountFolders;
    private SparseArray<String> unreadCountFeeds;

    private final SharedPreferences mPrefs;

    public enum SPECIAL_FOLDERS  {
        ALL_UNREAD_ITEMS(-10), ALL_STARRED_ITEMS(-11), ALL_ITEMS(-12), ITEMS_WITHOUT_FOLDER(-22);

        private final int id;
        SPECIAL_FOLDERS(int id) {
            this.id = id;
        }

        public int getValue() {
            return id;
        }


        public String getValueString() {
            return String.valueOf(id);
        }

        @Override
        public String toString() {
            return getValueString();
        }
    }

    public SubscriptionExpandableListAdapter(Context mContext, DatabaseConnectionOrm dbConn, ListView listView, SharedPreferences prefs) {
        this.favIconHandler = new FavIconHandler(mContext);
        this.mPrefs = prefs;

    	this.mContext = mContext;
    	this.dbConn = dbConn;

        unreadCountFeeds = new SparseArray<>();
        unreadCountFolders = new SparseArray<>();
        starredCountFeeds = new SparseArray<>();

        mCategoriesArrayList = new ArrayList<>();
        mItemsArrayList = new SparseArray<>();

        this.listView = listView;
    }

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		int parent_id = (int)getGroupId(groupPosition);
        return mItemsArrayList.get(parent_id).get(childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return ((ConcreteFeedItem)(getChild(groupPosition, childPosition))).id_database;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		final ConcreteFeedItem item = (ConcreteFeedItem)getChild(groupPosition, childPosition);
        final ChildHolder viewHolder;

        if (convertView != null) {
            viewHolder = (ChildHolder) convertView.getTag();
        } else {
            LinearLayout view = new LinearLayout(mContext);
            SubscriptionListSubItemBinding binding = SubscriptionListSubItemBinding.inflate(LayoutInflater.from(mContext), view, true);
            convertView = binding.getRoot();
            viewHolder = new ChildHolder(binding);
            convertView.setTag(viewHolder);
        }


        if(item != null)
        {
	        String headerText = (item.header != null) ? item.header : "";
	        viewHolder.binding.summary.setText(headerText);


            String unreadCount;
            if(item.idFolder == ALL_STARRED_ITEMS.getValue()) {
                unreadCount = starredCountFeeds.get((int) item.id_database);
            } else {
                unreadCount = unreadCountFeeds.get((int) item.id_database);
            }

            if(unreadCount != null)
                viewHolder.binding.tvUnreadCount.setText(unreadCount);
            else
                viewHolder.binding.tvUnreadCount.setText("");

            favIconHandler.loadFavIconForFeed(item.favIcon, viewHolder.binding.iVFavicon);
        }
        else
        {
	        viewHolder.binding.summary.setText(mContext.getString(R.string.login_dialog_text_something_went_wrong));
	        viewHolder.binding.tvUnreadCount.setText("");
	        viewHolder.binding.iVFavicon.setImageDrawable(null);
        }

        return convertView;
	}

	static class ChildHolder {
        @NonNull final SubscriptionListSubItemBinding binding;

        public ChildHolder(@NonNull SubscriptionListSubItemBinding binding) {
            this.binding = binding;
        }
	  }

	@Override
	public int getChildrenCount(int groupPosition) {
        int parent_id = (int)getGroupId(groupPosition);
        return (mItemsArrayList.get(parent_id) != null) ? mItemsArrayList.get(parent_id).size() : 0;
	}

	@Override
	public Object getGroup(int groupPosition) {
		return mCategoriesArrayList.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		return mCategoriesArrayList.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		return ((AbstractItem)getGroup(groupPosition)).id_database;
	}

    private enum GroupViewType { FOLDER, FEED }

    @Override
    public int getGroupType(int groupPosition) {
        AbstractItem ai = mCategoriesArrayList.get(groupPosition);

        if(ai instanceof FolderSubscribtionItem)
            return GroupViewType.FOLDER.ordinal();
        else
            return GroupViewType.FEED.ordinal();
    }

    @Override
    public int getGroupTypeCount() {
        return GroupViewType.values().length;
    }

	@Override
	public View getGroupView(final int groupPosition, final boolean isExpanded, View convertView, ViewGroup parent) {

        GroupHolder viewHolder;
        final AbstractItem group = (AbstractItem) getGroup(groupPosition);

        if (convertView == null) {
            SubscriptionListItemBinding binding = SubscriptionListItemBinding.inflate(LayoutInflater.from(mContext), new LinearLayout(mContext), true);
            viewHolder = new GroupHolder(binding);
            convertView = binding.getRoot();
            binding.getRoot().setTag(viewHolder);
        } else {
        	viewHolder = (GroupHolder) convertView.getTag();
        }

        viewHolder.binding.summary.setText(group.header);
        viewHolder.binding.listItemLayout.setOnClickListener(v -> {

            long idFeed = group.id_database;
            boolean skipFireEvent = false;

            if (group instanceof ConcreteFeedItem) {
                fireListTextClicked(idFeed, false, (long) ITEMS_WITHOUT_FOLDER.getValue());
                skipFireEvent = true;
            }

            if (!skipFireEvent)
                fireListTextClicked(idFeed, true, ((FolderSubscribtionItem) group).idFolder);
        });

        viewHolder.binding.listItemLayout.setOnLongClickListener(v -> {

            long idFeed = group.id_database;

            if (group instanceof ConcreteFeedItem) {
                fireListTextLongClicked(idFeed, false, (long) ITEMS_WITHOUT_FOLDER.getValue());
            } else {
                fireListTextLongClicked(idFeed, true, ((FolderSubscribtionItem) group).idFolder);
            }
            return true; //consume event
        });


        viewHolder.binding.tVFeedsCount.setText("");
        boolean skipGetUnread = false;
        if(group.idFolder != null && group.idFolder == ITEMS_WITHOUT_FOLDER.getValue()) {
            String unreadCount = unreadCountFeeds.get((int) group.id_database);
            if(unreadCount != null) {
                viewHolder.binding.tVFeedsCount.setText(unreadCount);
            }

            skipGetUnread = true;
        }

        if(!skipGetUnread) {
            String unreadCount = unreadCountFolders.get((int) group.id_database);
            if(unreadCount != null)
                viewHolder.binding.tVFeedsCount.setText(unreadCount);
        }


        int rotation = 0;
        int contentDescriptionId = R.string.content_desc_none;


        if(group.idFolder != null)
        {
            viewHolder.binding.imgViewExpandableIndicator.setVisibility(View.GONE);
	        if(group.idFolder == ITEMS_WITHOUT_FOLDER.getValue())
	        {
                ConcreteFeedItem concreteFeedItem = ((ConcreteFeedItem) group);
                favIconHandler.loadFavIconForFeed(concreteFeedItem.favIcon, viewHolder.binding.imgViewFavicon);
	        }
        } else {
        	if(group.id_database == ALL_STARRED_ITEMS.getValue()) {
                viewHolder.binding.imgViewExpandableIndicator.setVisibility(View.GONE);
        		viewHolder.binding.imgViewFavicon.setVisibility(View.VISIBLE);
                rotation = 0;
                viewHolder.binding.imgViewFavicon.setImageResource(getBtn_rating_star_off_normal_holo_light());
        	} else if (getChildrenCount( groupPosition ) == 0 ) {
	        	viewHolder.binding.imgViewExpandableIndicator.setVisibility(View.GONE);
                viewHolder.binding.imgViewFavicon.setVisibility(View.INVISIBLE);
	        } else {
	        	viewHolder.binding.imgViewExpandableIndicator.setVisibility(View.VISIBLE);
                viewHolder.binding.imgViewFavicon.setVisibility(View.INVISIBLE);
                viewHolder.binding.imgViewExpandableIndicator.setImageResource(R.drawable.ic_action_expand_less);

	        	if(isExpanded) {
                    rotation = 180;
                    contentDescriptionId = R.string.content_desc_collapse;
	        	} else {
                    if (ViewCompat.getLayoutDirection(listView) == ViewCompat.LAYOUT_DIRECTION_RTL) {
                        rotation = -90; // mirror for rtl layout
                    } else {
                        rotation = 90;
                    }
                    contentDescriptionId = R.string.content_desc_expand;
                }
        
                viewHolder.binding.imgViewExpandableIndicator.setOnClickListener(v -> {
                    if(isExpanded)
                        ((ExpandableListView)listView).collapseGroup(groupPosition);
                    else
                        ((ExpandableListView)listView).expandGroup(groupPosition);
                });
            }
        }

        viewHolder.binding.imgViewExpandableIndicator.setRotation(rotation);
        viewHolder.binding.imgViewExpandableIndicator.setContentDescription(viewHolder.binding.imgViewExpandableIndicator.getContext().getString(contentDescriptionId));

        return convertView;
    }


    private int getBtn_rating_star_off_normal_holo_light() {
        if(btn_rating_star_off_normal_holo_light == null) {
            if(ThemeChooser.getSelectedTheme().equals(ThemeChooser.THEME.LIGHT)) {
                btn_rating_star_off_normal_holo_light = R.drawable.ic_action_star_border_light;
            } else {
                btn_rating_star_off_normal_holo_light = R.drawable.ic_action_star_border_dark;
            }
        }
        return btn_rating_star_off_normal_holo_light;
    }

    static class GroupHolder {
        @NonNull final SubscriptionListItemBinding binding;

        public GroupHolder(@NonNull SubscriptionListItemBinding binding) {
            this.binding = binding;
        }
    }


    @Override
    public boolean hasStableIds() {
		return false;
	}

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}

    public void NotifyDataSetChangedAsync() {
        new NotifyDataSetChangedAsyncTask().execute((Void) null);
    }


    private class NotifyDataSetChangedAsyncTask extends AsyncTask<Void, Void, Void> {
        SparseArray<String> starredCountFeedsTemp;
        SparseArray<String> unreadCountFoldersTemp;
        SparseArray<String> unreadCountFeedsTemp;
        SparseArray<String> urlsToFavIconsTemp;

        @Override
        protected Void doInBackground(Void... voids) {
            StopWatch stopwatch = new StopWatch();
            stopwatch.start();

            SparseArray<String>[] temp = dbConn.getUnreadItemCountFeedFolder();

            unreadCountFoldersTemp = temp[0];// dbConn.getUnreadItemCountForFolder();
            unreadCountFeedsTemp = temp[1]; // dbConn.getUnreadItemCountForFeed();

            starredCountFeedsTemp = dbConn.getStarredItemCount();
            urlsToFavIconsTemp = dbConn.getUrlsToFavIcons();

            stopwatch.stop();
            Log.v(TAG, "Fetched folder/feed counts in " + stopwatch.toString());
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            if(showOnlyUnread) {
                for (int i = 0; i < mCategoriesArrayList.size(); i++) {
                    AbstractItem item = mCategoriesArrayList.get(i);

                    if(item instanceof FolderSubscribtionItem &&
                            unreadCountFoldersTemp.get(((Long) item.id_database).intValue()) == null) {
                        Log.v(TAG, "Remove folder item!!!");
                        mCategoriesArrayList.remove(i);
                        i--;
                    } else if(item instanceof ConcreteFeedItem &&
                            unreadCountFeedsTemp.get(((Long) item.id_database).intValue()) == null) {
                        Log.v(TAG, "Remove feed item!!!");
                        mCategoriesArrayList.remove(i);
                        i--;
                    } /* else {
                        Log.v(TAG, "Keep.. " + unreadCountFoldersTemp.get(((Long) item.id_database).intValue()));
                    } */
                }

                for (int i = 0; i < mItemsArrayList.size(); i++) {
                    ArrayList<ConcreteFeedItem> item = mItemsArrayList.valueAt(i);
                    for (int x = 0; x < item.size(); x++) {
                        if (unreadCountFeedsTemp.get((int) item.get(x).id_database) == null) {
                            item.remove(x);
                            x--;
                            Log.v(TAG, "Remove sub feed!!");
                        }
                    }
                }
            }

            notifyCountDataSetChanged(unreadCountFoldersTemp, unreadCountFeedsTemp, starredCountFeedsTemp);
            super.onPostExecute(aVoid);
        }
    }

    public void ReloadAdapterAsync() {
        new ReloadAdapterAsyncTask().execute((Void) null);
    }

    private class ReloadAdapterAsyncTask extends AsyncTask<Void, Void, Tuple<ArrayList<AbstractItem>, SparseArray<ArrayList<ConcreteFeedItem>>>> {

        public ReloadAdapterAsyncTask() {

        }

        @Override
        protected Tuple<ArrayList<AbstractItem>, SparseArray<ArrayList<ConcreteFeedItem>>> doInBackground(Void... voids) {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            Tuple<ArrayList<AbstractItem>, SparseArray<ArrayList<ConcreteFeedItem>>> ad = ReloadAdapter();
            //return reloadAdapter();

            stopWatch.stop();
            Log.v(TAG, "Reload Adapter - time taken: " + stopWatch.toString());

            return ad;
        }

        @Override
        protected void onPostExecute(Tuple<ArrayList<AbstractItem>, SparseArray<ArrayList<ConcreteFeedItem>>> arrayListSparseArrayTuple) {
            mCategoriesArrayList = arrayListSparseArrayTuple.key;
            mItemsArrayList = arrayListSparseArrayTuple.value;

            notifyDataSetChanged();

            NotifyDataSetChangedAsync();

            super.onPostExecute(arrayListSparseArrayTuple);
        }

    }

    public Tuple<ArrayList<AbstractItem>, SparseArray<ArrayList<ConcreteFeedItem>>> ReloadAdapter()
    {
        showOnlyUnread = mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false);

        ArrayList<AbstractItem> mCategoriesArrayListAsync = new ArrayList<>();
        mCategoriesArrayListAsync.add(new FolderSubscribtionItem(mContext.getString(R.string.allUnreadFeeds), null, ALL_UNREAD_ITEMS.getValue()));
        mCategoriesArrayListAsync.add(new FolderSubscribtionItem(mContext.getString(R.string.starredFeeds), null, ALL_STARRED_ITEMS.getValue()));


        StopWatch sw = new StopWatch();
        sw.start();

        List<Folder> folderList;
        //if(showOnlyUnread) {
        //    folderList = dbConn.getListOfFoldersWithUnreadItems();
        //} else {
            folderList = dbConn.getListOfFolders();
        //}

        sw.stop();
        Log.v(TAG, "Time needed (fetch folder list): " + sw.toString());


        for(Folder folder : folderList) {
            mCategoriesArrayListAsync.add(new FolderSubscribtionItem(folder.getLabel(), null, folder.getId()));
        }

        for(Feed feed : dbConn.getListOfFeedsWithoutFolders(showOnlyUnread)) {
            mCategoriesArrayListAsync.add(new ConcreteFeedItem(feed.getFeedTitle(), (long) ITEMS_WITHOUT_FOLDER.getValue(), feed.getId(), feed.getFaviconUrl(), feed.getId()));
        }

        SparseArray<ArrayList<ConcreteFeedItem>> mItemsArrayListAsync = new SparseArray<>();

        for(int groupPosition = 0; groupPosition < mCategoriesArrayListAsync.size(); groupPosition++) {
            //int parent_id = (int)getGroupId(groupPosition);
            int parent_id = (int) mCategoriesArrayListAsync.get(groupPosition).id_database;
            mItemsArrayListAsync.append(parent_id, new ArrayList<>());

            List<Feed> feedItemList = null;

            if(parent_id == ALL_UNREAD_ITEMS.getValue()) {
                feedItemList = dbConn.getAllFeedsWithUnreadRssItems();
            } else if(parent_id == ALL_STARRED_ITEMS.getValue()) {
                feedItemList = dbConn.getAllFeedsWithStarredRssItems();
            } else {
                for(Folder folder : folderList) {//Find the current selected folder
                    if (folder.getId() == parent_id) {//Current item
                        feedItemList = dbConn.getAllFeedsWithUnreadRssItemsForFolder(folder.getId());
                        break;
                    }
                }
            }

            if(feedItemList != null) {
                for (Feed feed : feedItemList) {
                    ConcreteFeedItem newItem = new ConcreteFeedItem(feed.getFeedTitle(), (long) parent_id, feed.getId(), feed.getFaviconUrl(), feed.getId());
                    mItemsArrayListAsync.get(parent_id).add(newItem);
                }
            }
        }

        return new Tuple<>(mCategoriesArrayListAsync, mItemsArrayListAsync);
    }


    @SuppressLint("NewApi") // wrongly reports setSelectionFromTop is only available in lollipop
    public void notifyCountDataSetChanged(SparseArray<String> unreadCountFolders, SparseArray<String> unreadCountFeeds, SparseArray<String> starredCountFeeds) {
        this.unreadCountFolders = unreadCountFolders;
        this.unreadCountFeeds = unreadCountFeeds;
        this.starredCountFeeds = starredCountFeeds;

        BlockingExpandableListView bView = (BlockingExpandableListView) listView;

        int firstVisPos = bView.getFirstVisiblePosition();
        View firstVisView = bView.getChildAt(0);
        int top = firstVisView != null ? firstVisView.getTop() : 0;

        // Number of items added before the first visible item
        int itemsAddedBeforeFirstVisible = 0;

        bView.setBlockLayoutChildren(true);
        notifyDataSetChanged();
        bView.setBlockLayoutChildren(false);

        // Call setSelectionFromTop to change the ListView position
        if(bView.getCount() >= firstVisPos + itemsAddedBeforeFirstVisible)
            bView.setSelectionFromTop(firstVisPos + itemsAddedBeforeFirstVisible, top);
    }


    public void setHandlerListener(ExpListTextClicked listener)
	{
		eListTextClickHandler = listener;
	}
	protected void fireListTextClicked(long idFeed, boolean isFolder, Long optional_folder_id)
	{
        if(eListTextClickHandler != null)
			eListTextClickHandler.onTextClicked(idFeed, isFolder, optional_folder_id);
	}
    protected void fireListTextLongClicked(long idFeed, boolean isFolder, Long optional_folder_id)
    {
        if(eListTextClickHandler != null)
            eListTextClickHandler.onTextLongClicked(idFeed, isFolder, optional_folder_id);
    }
}