summaryrefslogtreecommitdiff
path: root/org.fox.ttrss/src/main/java/org/fox/ttrss/BaseFeedlistFragment.java
blob: 1dc880be59c66816dfd3891353e5aa088096caeb (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
package org.fox.ttrss;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SwitchCompat;
import android.util.TypedValue;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.net.MalformedURLException;
import java.net.URL;

public abstract class BaseFeedlistFragment extends Fragment {
    abstract public void refresh(boolean background);

    public void initDrawerHeader(LayoutInflater inflater, View view, ListView list, final CommonActivity activity, final SharedPreferences prefs,
                                 boolean rootView, boolean isOffline) {

        if (true /*m_activity.findViewById(R.id.headlines_drawer) != null*/) {
            try {
                View layout = inflater.inflate(R.layout.drawer_header, list, false);
                list.addHeaderView(layout, null, false);

                TextView login = (TextView) view.findViewById(R.id.drawer_header_login);
                TextView server = (TextView) view.findViewById(R.id.drawer_header_server);

                login.setText(prefs.getString("login", ""));
                try {
                    server.setText(new URL(prefs.getString("ttrss_url", "")).getHost());
                } catch (MalformedURLException e) {
                    server.setText("");
                }

                View account = view.findViewById(R.id.drawer_header_account);

                account.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(prefs.getString("ttrss_url", "")));
                            startActivity(intent);
                        } catch (Exception e) {

                        }
                    }
                });

				/* deal with ~material~ footers */

                // divider
                View footer = inflater.inflate(R.layout.headlines_divider, list, false);
                list.addFooterView(footer);

                // unread only checkbox
                footer = inflater.inflate(R.layout.feeds_row_toggle, list, false);
                list.addFooterView(footer);
                TextView text = (TextView) footer.findViewById(R.id.title);
                text.setText(R.string.unread_only);

                ImageView icon = (ImageView) footer.findViewById(R.id.icon);
                TypedValue tv = new TypedValue();
                getActivity().getTheme().resolveAttribute(R.attr.ic_filter_variant, tv, true);
                icon.setImageResource(tv.resourceId);

                final SwitchCompat rowSwitch = (SwitchCompat) footer.findViewById(R.id.row_switch);
                rowSwitch.setChecked(activity.getUnreadOnly());

                rowSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton button, boolean isChecked) {
                        activity.setUnreadOnly(isChecked);
                        refresh(true);
                    }
                });

                text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        rowSwitch.setChecked(!rowSwitch.isChecked());
                    }
                });

                if (rootView) {
                    // offline
                    footer = inflater.inflate(R.layout.feeds_row, list, false);
                    list.addFooterView(footer);
                    text = (TextView) footer.findViewById(R.id.title);
                    text.setText(isOffline ? R.string.go_online : R.string.go_offline);

                    icon = (ImageView) footer.findViewById(R.id.icon);
                    tv = new TypedValue();
                    getActivity().getTheme().resolveAttribute(isOffline ? R.attr.ic_cloud_upload : R.attr.ic_cloud_download, tv, true);
                    icon.setImageResource(tv.resourceId);

                    TextView counter = (TextView) footer.findViewById(R.id.unread_counter);
                    counter.setText(R.string.blank);
                }

                // settings
                footer = inflater.inflate(R.layout.feeds_row, list, false);
                list.addFooterView(footer);
                text = (TextView) footer.findViewById(R.id.title);
                text.setText(R.string.preferences);

                icon = (ImageView) footer.findViewById(R.id.icon);
                tv = new TypedValue();
                getActivity().getTheme().resolveAttribute(R.attr.ic_settings, tv, true);
                icon.setImageResource(tv.resourceId);

                TextView counter = (TextView) footer.findViewById(R.id.unread_counter);
                counter.setText(R.string.blank);

            } catch (InflateException e) {
                // welp couldn't inflate header i guess
                e.printStackTrace();
            } catch (java.lang.UnsupportedOperationException e) {
                e.printStackTrace();
            }
        }

    }

}