Skip to content

Commit 6d41551

Browse files
committed
添加自定义rss对话框
1 parent ed66f0f commit 6d41551

File tree

6 files changed

+248
-8
lines changed

6 files changed

+248
-8
lines changed

res/layout/add_dialog.xml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
<LinearLayout
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:orientation="vertical"> <TextView
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:gravity="center"
12+
android:padding="5dp"
13+
android:text="自定义rss源"
14+
android:textSize="20sp"
15+
android:background="@color/light_gray"
16+
android:alpha="0.8" />
17+
<LinearLayout
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:orientation="horizontal"
21+
android:padding="5dp">
22+
<TextView
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:textSize="18sp"
26+
android:text="地址:" />
27+
<EditText
28+
android:id="@+id/add_url_et"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:ems="10" >
32+
</EditText>
33+
</LinearLayout>
34+
<LinearLayout
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content"
37+
android:orientation="horizontal"
38+
android:padding="5dp">
39+
<TextView
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:textSize="18sp"
43+
android:text="分类:" />
44+
<Spinner
45+
android:id="@+id/add_rssSpinner"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content" />
48+
</LinearLayout>
49+
</LinearLayout>
50+
51+
<RelativeLayout
52+
android:id="@+id/add_check_layout"
53+
android:layout_width="100dp"
54+
android:layout_height="wrap_content"
55+
android:background="@color/light_black"
56+
android:layout_centerHorizontal="true"
57+
android:layout_centerVertical="true"
58+
android:padding="5dp"
59+
android:alpha="0.5"
60+
android:visibility="visible"
61+
>
62+
<ProgressBar
63+
style="@android:style/Widget.ProgressBar.Small"
64+
android:layout_alignParentLeft="true"
65+
android:layout_centerVertical="true"
66+
android:layout_width="wrap_content"
67+
android:layout_height="wrap_content"
68+
/>
69+
<TextView
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:layout_alignParentRight="true"
73+
android:layout_centerVertical="true"
74+
android:textColor="@color/white"
75+
android:text="检测中……" />
76+
</RelativeLayout>
77+
</RelativeLayout>

src/com/dreamteam/app/commons/ItemListEntityParser.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class ItemListEntityParser extends DefaultHandler
3232
private boolean isFeedTitle = true;
3333
private boolean isFeedDesc = true;
3434
private boolean isFeedLink = true;
35+
private String feedTitle;
3536

3637

3738
@Override
@@ -72,9 +73,16 @@ public void endElement(String uri, String localName, String qName)
7273
{
7374
feedItem.setLink(content);
7475
}
75-
if(!isFeedTitle && qName.equalsIgnoreCase("title"))
76+
if(qName.equalsIgnoreCase("title"))
7677
{
77-
feedItem.setTitle(content);
78+
if(isFeedTitle)
79+
{
80+
feedTitle = content;
81+
}
82+
else
83+
{
84+
feedItem.setTitle(content);
85+
}
7886
return;
7987
}
8088
if(!isFeedDesc && (qName.equalsIgnoreCase("description") || qName.equalsIgnoreCase("content:encoded")))
@@ -167,5 +175,9 @@ public ItemListEntity parse(String url)
167175
}
168176
}
169177
}
170-
178+
179+
public String getFeedTitle() {
180+
return feedTitle;
181+
}
182+
171183
}

src/com/dreamteam/app/entity/Feed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Feed
1212

1313
private String title;
1414
private String url;
15-
private int selectStatus;//是否已经选中
15+
private int selectStatus;//是否已经选中
1616

1717
public String getTitle()
1818
{
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package com.dreamteam.app.ui;
2+
3+
import java.io.File;
4+
5+
import android.app.AlertDialog;
6+
import android.app.Dialog;
7+
import android.content.DialogInterface;
8+
import android.content.DialogInterface.OnClickListener;
9+
import android.content.Intent;
10+
import android.database.sqlite.SQLiteDatabase;
11+
import android.os.AsyncTask;
12+
import android.os.Bundle;
13+
import android.support.v4.app.DialogFragment;
14+
import android.util.Log;
15+
import android.view.LayoutInflater;
16+
import android.view.View;
17+
import android.widget.AdapterView;
18+
import android.widget.AdapterView.OnItemSelectedListener;
19+
import android.widget.ArrayAdapter;
20+
import android.widget.EditText;
21+
import android.widget.ProgressBar;
22+
import android.widget.RelativeLayout;
23+
import android.widget.Spinner;
24+
import android.widget.Toast;
25+
26+
import com.dreamteam.app.commons.ItemListEntityParser;
27+
import com.dreamteam.app.commons.SectionHelper;
28+
import com.dreamteam.app.commons.SeriaHelper;
29+
import com.dreamteam.app.db.DbManager;
30+
import com.dreamteam.app.entity.ItemListEntity;
31+
import com.dreamteam.app.utils.CategoryNameExchange;
32+
import com.dreateam.app.ui.R;
33+
34+
public class AddDialog extends DialogFragment implements OnItemSelectedListener
35+
{
36+
private static final String tag = "AddDialog";
37+
private Spinner mSpinner;
38+
private EditText urlEt;
39+
private RelativeLayout checkLayout;
40+
private String tableName_en;
41+
42+
43+
@Override
44+
public Dialog onCreateDialog(Bundle savedInstanceState)
45+
{
46+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
47+
LayoutInflater inflater = getActivity().getLayoutInflater();
48+
View view = inflater.inflate(R.layout.add_dialog, null);
49+
50+
urlEt = (EditText) view.findViewById(R.id.add_url_et);
51+
checkLayout = (RelativeLayout) view.findViewById(R.id.add_check_layout);
52+
53+
mSpinner = (Spinner) view.findViewById(R.id.add_rssSpinner);
54+
ArrayAdapter<CharSequence> cateAdapter = ArrayAdapter.createFromResource(getActivity()
55+
, R.array.feed_category, android.R.layout.simple_spinner_item);
56+
cateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
57+
mSpinner.setAdapter(cateAdapter);
58+
mSpinner.setOnItemSelectedListener(this);
59+
60+
builder.setView(view)
61+
.setNegativeButton("取消", new OnClickListener() {
62+
@Override
63+
public void onClick(DialogInterface dialog, int which) {
64+
}
65+
})
66+
.setPositiveButton("确定", new OnClickListener() {
67+
@Override
68+
public void onClick(DialogInterface dialog, int which) {
69+
// checkRss();
70+
}
71+
});
72+
return builder.create();
73+
}
74+
75+
76+
@Override
77+
public void onItemSelected(AdapterView<?> parent, View view, int pos,
78+
long id) {
79+
String tableName = parent.getItemAtPosition(pos).toString();
80+
Log.d(tag, tableName);
81+
tableName_en = new CategoryNameExchange(getActivity()).zh2en(tableName);
82+
}
83+
84+
85+
@Override
86+
public void onNothingSelected(AdapterView<?> arg0) {
87+
88+
}
89+
90+
private void checkRss()
91+
{
92+
final String url = urlEt.getText().toString();
93+
94+
new AsyncTask<String, Integer, String>() {
95+
96+
@Override
97+
protected void onPostExecute(String result)
98+
{
99+
checkLayout.setVisibility(View.GONE);
100+
101+
if(result == null)
102+
{
103+
// Toast.makeText(AddDialog.this.getActivity(), "抱歉,暂不支持该rss", Toast.LENGTH_SHORT).show();
104+
Log.e(tag, "抱歉,暂不支持该rss");
105+
return;
106+
}
107+
Log.e(tag, "添加成功");
108+
// Toast.makeText(AddDialog.this.getActivity(), "添加成功", Toast.LENGTH_SHORT).show();
109+
//加入section表
110+
DbManager mgr = new DbManager(AddDialog.this.getActivity(), DbManager.DB_NAME, null, 1);
111+
SQLiteDatabase db = mgr.getWritableDatabase();
112+
SectionHelper.insert(db, tableName_en, result, url);
113+
db.close();
114+
115+
Intent intent = new Intent();
116+
intent.setAction(Main.ACTION_ADD_SECTION);
117+
getActivity().sendBroadcast(intent);
118+
}
119+
120+
@Override
121+
protected void onPreExecute()
122+
{
123+
checkLayout.setVisibility(View.VISIBLE);
124+
}
125+
126+
@Override
127+
protected String doInBackground(String... params) {
128+
String title = null;
129+
130+
ItemListEntityParser parser = new ItemListEntityParser();
131+
ItemListEntity entity = parser.parse(params[0]);
132+
if(entity != null)
133+
{
134+
SeriaHelper helper = SeriaHelper.newInstance();
135+
File cache = SectionHelper.newSdCache(params[0]);
136+
helper.saveObject(entity, cache);
137+
title = parser.getFeedTitle();
138+
}
139+
return title;
140+
}
141+
142+
}.execute(url);
143+
}
144+
145+
}

src/com/dreamteam/app/ui/FeedCategory.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.content.Intent;
55
import android.os.Bundle;
6+
import android.support.v4.app.FragmentActivity;
67
import android.view.View;
78
import android.view.View.OnClickListener;
89
import android.widget.AdapterView;
@@ -12,9 +13,10 @@
1213
import android.widget.Toast;
1314

1415
import com.dreamteam.app.adapter.FeedCategoryAdapter;
16+
import com.dreamteam.app.commons.AppContext;
1517
import com.dreateam.app.ui.R;
1618

17-
public class FeedCategory extends Activity
19+
public class FeedCategory extends FragmentActivity
1820
{
1921

2022
private ListView categoryList;
@@ -42,8 +44,12 @@ private void initView()
4244
@Override
4345
public void onClick(View v)
4446
{
45-
Toast.makeText(FeedCategory.this, "开发中功能", Toast.LENGTH_SHORT)
46-
.show();
47+
// if(!AppContext.isNetworkAvailable(FeedCategory.this))
48+
// {
49+
// Toast.makeText(FeedCategory.this, "请检查网络设置", Toast.LENGTH_SHORT).show();
50+
// return;
51+
// }
52+
new AddDialog().show(getSupportFragmentManager(), "添加Feed");
4753
}
4854
});
4955
findViewById(R.id.feed_category_btn_back).setOnClickListener(new OnClickListener()

src/com/dreamteam/app/ui/ItemList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected void onCreate(Bundle savedInstanceState)
7676
initView();
7777
initData();
7878
initTts();
79-
initBroadeCast();
79+
// initBroadeCast();
8080
}
8181

8282
private void initBroadeCast()

0 commit comments

Comments
 (0)