summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/activity/AddFeedActivity.java
blob: 54eff51c54ee8bb155284cf2d9f5dc3f7f1abc54 (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
package de.danoeh.antennapod.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.gpoddernet.GpodnetMainActivity;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.util.StorageUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * Activity for adding a Feed
 */
public class AddFeedActivity extends ActionBarActivity {
    private static final String TAG = "AddFeedActivity";

    private EditText etxtFeedurl;
    private Button butBrowseMiroGuide;
    private Button butBrowserGpoddernet;
    private Button butOpmlImport;
    private Button butConfirm;

    private ProgressDialog progDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Was started with Intent " + getIntent().getAction()
                    + " and Data " + getIntent().getDataString());
        setTheme(UserPreferences.getTheme());
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        StorageUtils.checkStorageAvailability(this);
        setContentView(R.layout.addfeed);

        progDialog = new ProgressDialog(this);

        etxtFeedurl = (EditText) findViewById(R.id.etxtFeedurl);
        if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
            etxtFeedurl.setText(getIntent().getDataString());
        }

        butBrowserGpoddernet = (Button) findViewById(R.id.butBrowseGpoddernet);
        butOpmlImport = (Button) findViewById(R.id.butOpmlImport);
        butConfirm = (Button) findViewById(R.id.butConfirm);

        butBrowseMiroGuide.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent(AddFeedActivity.this,
                        MiroGuideMainActivity.class));
            }
        });
        butBrowserGpoddernet.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(AddFeedActivity.this,
                        GpodnetMainActivity.class));
            }
        });

        butOpmlImport.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent(AddFeedActivity.this,
                        OpmlImportFromPathActivity.class));
            }
        });

        butConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AddFeedActivity.this, DefaultOnlineFeedViewActivity.class);
                intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, etxtFeedurl.getText().toString());
                intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, getSupportActionBar().getTitle());
                startActivity(intent);
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        StorageUtils.checkStorageAvailability(this);
        Intent intent = getIntent();
        if (intent.getAction() != null
                && intent.getAction().equals(Intent.ACTION_SEND)) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Resuming with ACTION_SEND intent");
            String text = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (text != null) {
                etxtFeedurl.setText(text);
            } else {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "No text was sent");
            }
        }

    }

    @Override
    protected void onStop() {
        super.onStop();
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Stopping Activity");
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            default:
                return false;
        }
    }

}