Android Open Source - Gazetti_Newspaper_Reader Bookmark List Fragment






From Project

Back to project page Gazetti_Newspaper_Reader.

License

The source code is released under:

MIT License

If you think the Android project Gazetti_Newspaper_Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package in.sahildave.gazetti.bookmarks;
//from ww w.  j  a  v  a  2 s. co m
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.nhaarman.listviewanimations.appearance.simple.ScaleInAnimationAdapter;
import com.nhaarman.listviewanimations.appearance.simple.SwingBottomInAnimationAdapter;
import in.sahildave.gazetti.R;
import in.sahildave.gazetti.bookmarks.sqlite.BookmarkDataSource;
import in.sahildave.gazetti.bookmarks.sqlite.BookmarkModel;

import java.util.List;

public class BookmarkListFragment extends ListFragment {

    // Tags
    private static final String TAG = BookmarkListFragment.class.getName();
    private BookmarkSelectedListeners mBookmarkSelectedListeners = sDummyBookmarkSelectedListeners;
    private static final String STATE_ACTIVATED_POSITION = "activated_position";

    // Retained objects
    private static int mActivatedPosition = 1;

    private ListView mListView;

    // From Bundle
    private boolean mTwoPane;

    // Booleans
    private boolean firstRun = false;
    private BookmarkDataSource dataSource;

    public interface BookmarkSelectedListeners {
        public void onItemSelected(String headlineText);
    }

    private static BookmarkSelectedListeners sDummyBookmarkSelectedListeners = new BookmarkSelectedListeners() {
        @Override
        public void onItemSelected(String headlineText) {
        }
    };

    public BookmarkListFragment() {
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (!(activity instanceof BookmarkSelectedListeners)) {
            throw new IllegalStateException("Activity must implement fragment's callbacks.");
        }

        mTwoPane = getArguments().getBoolean("mTwoPane");
        mBookmarkSelectedListeners = (BookmarkSelectedListeners) activity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        firstRun = true;
        setRetainInstance(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_bookmark_list, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mListView = getListView();
        mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //Log.d(TAG, "ListFragment in onActivityCreated ");

        if (mTwoPane && !firstRun) {
            setActivatedPosition(mActivatedPosition);
        }
        dataSource = new BookmarkDataSource(getActivity());
        dataSource.open();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        //Log.d(TAG, "Fragment in onDetach");
        mBookmarkSelectedListeners = sDummyBookmarkSelectedListeners;
    }

    @Override
    public void onDestroy() {
        dataSource.close();
        super.onDestroy();
        //Log.d(TAG, "Fragment in onDestroy");
        mActivatedPosition = 1;
    }

    @Override
    public void onResume() {
        dataSource.open();
        List<BookmarkModel> values = dataSource.getAllBookmarkModels();
        BookmarkAdapter bookmarkAdapter = new BookmarkAdapter(getActivity(), values);
        SwingBottomInAnimationAdapter animAdapter = new SwingBottomInAnimationAdapter(bookmarkAdapter);
        ScaleInAnimationAdapter animAdapterMultiple = new ScaleInAnimationAdapter(animAdapter);
        animAdapterMultiple.setAbsListView(mListView);

        mListView.setAdapter(animAdapterMultiple);
        super.onResume();
    }

    @Override
    public void onListItemClick(ListView listView, View view, int position, long id) {
        super.onListItemClick(listView, view, position, id);
        TextView headlineTextView = null;
        String headlineText = null;
        try {
            headlineTextView = (TextView) view.findViewById(R.id.headline);
            if(headlineTextView!=null){
                headlineText = (String) headlineTextView.getText();
                setActivatedPosition(position);
                mBookmarkSelectedListeners.onItemSelected(headlineText);
            }

        } catch (Exception e) {
            //Log.d(TAG, "Exception in onListItemClick ",e);
            Crashlytics.log("Is headlineTextView null - "+(null==headlineTextView));
            Crashlytics.log("Is headlineText null - "+(null==headlineText));
            Crashlytics.log("Clicked on - "+headlineTextView.getText().toString());
            Crashlytics.logException(e);
        }
    }

    private void setActivatedPosition(int position) {
        if (position == ListView.INVALID_POSITION) {
            mListView.setItemChecked(mActivatedPosition, false);
        } else {
            mListView.setItemChecked(position, true);
        }
        mActivatedPosition = position;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {

        if (mActivatedPosition != ListView.INVALID_POSITION) {
            outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
        }
        super.onSaveInstanceState(outState);
    }
}




Java Source Code List

in.sahildave.gazetti.StarterApplication.java
in.sahildave.gazetti.bookmarks.BookmarkAdapter.java
in.sahildave.gazetti.bookmarks.BookmarkDetailActivity.java
in.sahildave.gazetti.bookmarks.BookmarkDetailFragment.java
in.sahildave.gazetti.bookmarks.BookmarkListActivity.java
in.sahildave.gazetti.bookmarks.BookmarkListFragment.java
in.sahildave.gazetti.bookmarks.BookmarkLoadingCallback.java
in.sahildave.gazetti.bookmarks.sqlite.BookmarkDataSource.java
in.sahildave.gazetti.bookmarks.sqlite.BookmarkModel.java
in.sahildave.gazetti.bookmarks.sqlite.SQLiteHelper.java
in.sahildave.gazetti.homescreen.HomeScreenActivity.java
in.sahildave.gazetti.homescreen.HomeScreenFragment.java
in.sahildave.gazetti.homescreen.adapter.AddCellDialogFragment.java
in.sahildave.gazetti.homescreen.adapter.CellModel.java
in.sahildave.gazetti.homescreen.adapter.EditCellDialogFragment.java
in.sahildave.gazetti.homescreen.adapter.GridAdapter.java
in.sahildave.gazetti.homescreen.adapter.NewsCatModel.java
in.sahildave.gazetti.homescreen.newcontent.DialogNewContentExpListAdaper.java
in.sahildave.gazetti.homescreen.newcontent.DialogNewContent.java
in.sahildave.gazetti.news_activities.ArticleLoadingCallback.java
in.sahildave.gazetti.news_activities.WebViewFragment.java
in.sahildave.gazetti.news_activities.WebsiteDetailActivity.java
in.sahildave.gazetti.news_activities.WebsiteDetailFragment.java
in.sahildave.gazetti.news_activities.WebsiteListActivity.java
in.sahildave.gazetti.news_activities.WebsiteListFragment.java
in.sahildave.gazetti.news_activities.adapter.NavDrawerListAdapter.java
in.sahildave.gazetti.news_activities.adapter.NewsAdapter.java
in.sahildave.gazetti.news_activities.adapter.RobotoLight.java
in.sahildave.gazetti.news_activities.fetch.firstPost.java
in.sahildave.gazetti.news_activities.fetch.hindu.java
in.sahildave.gazetti.news_activities.fetch.indianExpressBusiness.java
in.sahildave.gazetti.news_activities.fetch.indianExpress.java
in.sahildave.gazetti.news_activities.fetch.toi.java
in.sahildave.gazetti.preference.FeedSelectFragment.java
in.sahildave.gazetti.preference.FeedSelectSettingsActivity.java
in.sahildave.gazetti.preference.LicensesActivity.java
in.sahildave.gazetti.preference.PreferenceExpListAdapter.java
in.sahildave.gazetti.preference.SettingsActivity.java
in.sahildave.gazetti.util.BitmapTransform.java
in.sahildave.gazetti.util.ConfigService.java
in.sahildave.gazetti.util.Constants.java
in.sahildave.gazetti.util.GazettiEnums.java
in.sahildave.gazetti.util.JsonHelper.java
in.sahildave.gazetti.util.NewsCatFileUtil.java
in.sahildave.gazetti.util.ShareButtonListener.java
in.sahildave.gazetti.util.UserPrefUtil.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenExpListAdapter.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenFragmentExpList.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenFragmentFirst.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenViewPagerActivity.java