Added functionality to AddFeedActivity
This commit is contained in:
parent
43de4eaf58
commit
055fda3c91
|
@ -1,15 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<EditText android:id="@+id/etxtFeedurl"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<Button android:id="@+id/butConfirm"
|
||||
android:text="@string/confirm_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<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>
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
<!-- -->
|
||||
<string name="confirm_label">Confirm</string>
|
||||
<string name="cancel_label">Cancel</string>
|
||||
|
||||
<!-- AddFeed Activity labels -->
|
||||
<string name="feedurl_label">Feed URL</string>
|
||||
|
||||
<!-- Feeditemview labels-->
|
||||
<string name="download_label">Download</string>
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.view.View;
|
|||
import de.podfetcher.R;
|
||||
import de.podfetcher.feed.Feed;
|
||||
import de.podfetcher.storage.DownloadRequester;
|
||||
import de.podfetcher.util.URLChecker;
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
|
@ -18,6 +19,7 @@ public class AddFeedActivity extends SherlockActivity {
|
|||
|
||||
private EditText etxtFeedurl;
|
||||
private Button butConfirm;
|
||||
private Button butCancel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -26,25 +28,38 @@ public class AddFeedActivity extends SherlockActivity {
|
|||
|
||||
etxtFeedurl = (EditText) findViewById(R.id.etxtFeedurl);
|
||||
butConfirm = (Button) findViewById(R.id.butConfirm);
|
||||
butCancel = (Button) findViewById(R.id.butCancel);
|
||||
|
||||
butConfirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
addNewFeed();
|
||||
}
|
||||
});
|
||||
|
||||
butCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void addNewFeed() {
|
||||
String url = etxtFeedurl.getText().toString();
|
||||
Feed feed = new Feed(url);
|
||||
DownloadRequester req = DownloadRequester.getInstance();
|
||||
req.downloadFeed(this, feed);
|
||||
|
||||
url = URLChecker.prepareURL(url);
|
||||
|
||||
if(url != null) {
|
||||
Feed feed = new Feed(url);
|
||||
DownloadRequester req = DownloadRequester.getInstance();
|
||||
req.downloadFeed(this, feed);
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue