Added functionality to AddFeedActivity
This commit is contained in:
parent
43de4eaf58
commit
055fda3c91
@ -1,15 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtvFeedurl"
|
||||||
|
android:text="@string/feedurl_label"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical" >
|
/>
|
||||||
<EditText android:id="@+id/etxtFeedurl"
|
<EditText android:id="@+id/etxtFeedurl"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"/>
|
||||||
/>
|
<LinearLayout
|
||||||
<Button android:id="@+id/butConfirm"
|
android:layout_width="match_parent"
|
||||||
android:text="@string/confirm_label"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:orientation="horizontal">
|
||||||
android:layout_height="wrap_content"
|
<Button android:id="@+id/butConfirm"
|
||||||
/>
|
android:text="@string/confirm_label"
|
||||||
|
android:layout_width="0px"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
<Button android:id="@+id/butCancel"
|
||||||
|
android:layout_width="0px"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/cancel_label"/>
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
<string name="confirm_label">Confirm</string>
|
<string name="confirm_label">Confirm</string>
|
||||||
|
<string name="cancel_label">Cancel</string>
|
||||||
|
|
||||||
|
<!-- AddFeed Activity labels -->
|
||||||
|
<string name="feedurl_label">Feed URL</string>
|
||||||
|
|
||||||
<!-- Feeditemview labels-->
|
<!-- Feeditemview labels-->
|
||||||
<string name="download_label">Download</string>
|
<string name="download_label">Download</string>
|
||||||
|
@ -7,6 +7,7 @@ import android.view.View;
|
|||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.feed.Feed;
|
import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.storage.DownloadRequester;
|
import de.podfetcher.storage.DownloadRequester;
|
||||||
|
import de.podfetcher.util.URLChecker;
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
@ -18,6 +19,7 @@ public class AddFeedActivity extends SherlockActivity {
|
|||||||
|
|
||||||
private EditText etxtFeedurl;
|
private EditText etxtFeedurl;
|
||||||
private Button butConfirm;
|
private Button butConfirm;
|
||||||
|
private Button butCancel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -26,25 +28,38 @@ public class AddFeedActivity extends SherlockActivity {
|
|||||||
|
|
||||||
etxtFeedurl = (EditText) findViewById(R.id.etxtFeedurl);
|
etxtFeedurl = (EditText) findViewById(R.id.etxtFeedurl);
|
||||||
butConfirm = (Button) findViewById(R.id.butConfirm);
|
butConfirm = (Button) findViewById(R.id.butConfirm);
|
||||||
|
butCancel = (Button) findViewById(R.id.butCancel);
|
||||||
|
|
||||||
butConfirm.setOnClickListener(new View.OnClickListener() {
|
butConfirm.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
addNewFeed();
|
addNewFeed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
butCancel.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNewFeed() {
|
private void addNewFeed() {
|
||||||
String url = etxtFeedurl.getText().toString();
|
String url = etxtFeedurl.getText().toString();
|
||||||
Feed feed = new Feed(url);
|
url = URLChecker.prepareURL(url);
|
||||||
DownloadRequester req = DownloadRequester.getInstance();
|
|
||||||
req.downloadFeed(this, feed);
|
|
||||||
|
|
||||||
|
|
||||||
|
if(url != null) {
|
||||||
|
Feed feed = new Feed(url);
|
||||||
|
DownloadRequester req = DownloadRequester.getInstance();
|
||||||
|
req.downloadFeed(this, feed);
|
||||||
|
setResult(RESULT_OK);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
29
src/de/podfetcher/util/URLChecker.java
Normal file
29
src/de/podfetcher/util/URLChecker.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package de.podfetcher.util;
|
||||||
|
|
||||||
|
import android.webkit.URLUtil;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/** Provides methods for checking and editing a URL */
|
||||||
|
public class URLChecker {
|
||||||
|
|
||||||
|
private static final String TAG = "URLChecker";
|
||||||
|
private static final String FEEDBURNER_URL = "feeds.feedburner.com";
|
||||||
|
private static final String FEEDBURNER_PREFIX = "?format=xml";
|
||||||
|
|
||||||
|
/** Checks if URL is valid and modifies it if necessary */
|
||||||
|
public static String prepareURL(String url) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
if(!url.startsWith("http")) {
|
||||||
|
builder.append("http://");
|
||||||
|
Log.d(TAG, "Missing http; appending");
|
||||||
|
}
|
||||||
|
builder.append(url);
|
||||||
|
|
||||||
|
if(url.contains(FEEDBURNER_URL)) {
|
||||||
|
Log.d(TAG, "URL seems to be Feedburner URL; appending prefix");
|
||||||
|
builder.append(FEEDBURNER_PREFIX);
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user