Commit ca859d19 authored by Thomas Krex's avatar Thomas Krex

eintrag in datenbank ob file gedownloadad wurde /status

icon ändert sich dementsrpechend via viewbinder
parent bb8e546c
......@@ -5,5 +5,6 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="lib" path="libs/commons-io-2.4.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
......@@ -21,28 +21,32 @@ public final class R {
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
public static final int my_border=0x7f020001;
public static final int selected_index_border=0x7f020002;
public static final int checked_icon=0x7f020000;
public static final int ic_launcher=0x7f020001;
public static final int my_border=0x7f020002;
public static final int selected_index_border=0x7f020003;
public static final int unchecked_icon=0x7f020004;
}
public static final class id {
public static final int action_settings=0x7f080013;
public static final int add=0x7f080012;
public static final int action_settings=0x7f080015;
public static final int add=0x7f080014;
public static final int button_save=0x7f08000e;
public static final int checkBox1=0x7f08000b;
public static final int connect_btn=0x7f08000a;
public static final int extend=0x7f080015;
public static final int extend=0x7f080017;
public static final int feedDetailsLv=0x7f080010;
public static final int feed_list=0x7f08000f;
public static final int indexScrollView=0x7f080003;
public static final int itemTitle=0x7f080012;
public static final int liveChannel_button=0x7f080002;
public static final int playerView_extended=0x7f080004;
public static final int playerView_fullscreen=0x7f080006;
public static final int port_tx=0x7f080009;
public static final int progressBar=0x7f080011;
public static final int scrollView1=0x7f080005;
public static final int search=0x7f080014;
public static final int search=0x7f080016;
public static final int server_tx=0x7f080008;
public static final int statusIcon=0x7f080013;
public static final int test_button=0x7f080000;
public static final int tx_name=0x7f08000d;
public static final int tx_url=0x7f08000c;
......@@ -58,6 +62,7 @@ public final class R {
public static final int dialog_feeds=0x7f030005;
public static final int feed_activity=0x7f030006;
public static final int feed_details_activity=0x7f030007;
public static final int list_feeditems=0x7f030008;
}
public static final class menu {
public static final int feed_menu=0x7f070000;
......
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache Commons IO
Copyright 2002-2012 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
\ No newline at end of file
......@@ -12,3 +12,4 @@
# Project target.
target=android-19
android.library=false
......@@ -4,7 +4,7 @@
<stroke
android:width="10dip"
android:color="@android:color/darker_gray" >
android:color="@android:color/background_dark" >
</stroke>
</shape>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="5" >
<TextView
android:id="@+id/itemTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/statusIcon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="?android:attr/textCheckMark" />
</LinearLayout>
\ No newline at end of file
package tttclient.activities;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.io.FileUtils;
import tttclient.models.FeedItem;
import tttclient.models.FeedItemDbManager;
import tttclient.services.DownloadService;
......@@ -25,8 +28,11 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import com.example.test.R;
......@@ -46,6 +52,7 @@ public class FeedDetailActivity extends Activity implements
FeedItemDbManager manager;
SimpleCursorAdapter adapter;
ProgressDialog progressDialog;
ListView lv;
private final BroadcastReceiver receiver = new BroadcastReceiver() {
......@@ -63,12 +70,13 @@ public class FeedDetailActivity extends Activity implements
if (result == RESULT_OK) {
Log.d("Download", "complete " + path);
manager.updatePath(title, path);
manager.updatePath(title, path, true);
adapter.changeCursor(manager.getAllFromDB());
startPlayer();
}
lv.setClickable(true);
} else if (action.equals(ParseService.BROADCAST_NAME)) {
itemList = bundle.getParcelableArrayList("result");
......@@ -95,25 +103,58 @@ public class FeedDetailActivity extends Activity implements
setContentView(R.layout.feed_details_activity);
progressDialog = new ProgressDialog(FeedDetailActivity.this);
progressDialog.setIndeterminate(false);
progressDialog.setIndeterminate(true);
progressDialog.setTitle("Downloading File");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// progressDialog.setCancelable(true);
progressDialog.setMessage("0% downloaded");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
feedId = getIntent().getStringExtra("id");
feedName = getIntent().getStringExtra("name");
feedUrl = getIntent().getStringExtra("feedUrl");
this.setTitle(feedName);
ListView lv = (ListView) findViewById(R.id.feedDetailsLv);
lv = (ListView) findViewById(R.id.feedDetailsLv);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
manager = new FeedItemDbManager(this);
Cursor cursor = manager.getAllFromDB();
adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, cursor,
new String[] { FeedItemDbManager.COLUMN_TITLE },
new int[] { android.R.id.text1 });
adapter = new SimpleCursorAdapter(this, R.layout.list_feeditems,
cursor, new String[] { FeedItemDbManager.COLUMN_TITLE,
FeedItemDbManager.COLUMN_STATUS }, new int[] {
R.id.itemTitle, R.id.statusIcon });
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor,
int columnIndex) {
if (view.getId() == R.id.statusIcon) {
ImageView icon = (ImageView) view;
int status = cursor.getInt(cursor
.getColumnIndex(FeedItemDbManager.COLUMN_STATUS));
if (status == 1) {
icon.setImageDrawable(getResources().getDrawable(
(R.drawable.checked_icon)));
} else if (status == 0) {
icon.setImageDrawable(getResources().getDrawable(
(R.drawable.unchecked_icon)));
}
return true;
}
return false;
}
});
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
lv.setOnItemLongClickListener(this);
Intent intent = new Intent(this, ParseService.class);
intent.putExtra(Consts.SERVICE_ID, Consts.PARSE_SERVICE_ID);
......@@ -151,12 +192,18 @@ public class FeedDetailActivity extends Activity implements
link = c.getString(c.getColumnIndex(FeedItemDbManager.COLUMN_LINK));
title = c.getString(c
.getColumnIndex(FeedItemDbManager.COLUMN_TITLE));
int status = c.getInt(c
.getColumnIndex(FeedItemDbManager.COLUMN_STATUS));
Log.d("FeedItem", "status: " + status);
if (path != null) {
if (checkPath(path)) {
startPlayer();
} else {
manager.updatePath(title, "");
manager.updatePath(title, "", false);
Toast.makeText(FeedDetailActivity.this,
"invalide path, start downloading",
Toast.LENGTH_LONG).show();
startDownloadService();
}
}
......@@ -193,6 +240,19 @@ public class FeedDetailActivity extends Activity implements
}
public void isDownloaded() {
int count = lv.getChildCount();
for (int i = 0; i < count; i++) {
CheckedTextView child = (CheckedTextView) lv.getChildAt(i);
String title = child.getText().toString();
Log.d("isDownloaded", "title: " + title);
String path = manager.getPath(title);
child.setChecked(checkPath(path));
}
}
public boolean checkPath(String path) {
Log.d("FILE", "checking path " + path);
......@@ -217,15 +277,33 @@ public class FeedDetailActivity extends Activity implements
// delete feed from list, refresh feed list
Cursor c = (Cursor) av.getAdapter().getItem(position);
int _id = c.getInt(c
.getColumnIndex(FeedItemDbManager.COLUMN_ID));
// int _id = c.getInt(c
// .getColumnIndex(FeedItemDbManager.COLUMN_ID));
String path = c.getString(c
.getColumnIndex(FeedItemDbManager.COLUMN_PATH));
String title = c.getString(c
.getColumnIndex(FeedItemDbManager.COLUMN_TITLE));
File dir = new File(path);
try {
FileUtils.deleteDirectory(dir);
Toast.makeText(FeedDetailActivity.this, "File was deleted",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(FeedDetailActivity.this, "File not found",
Toast.LENGTH_LONG).show();
}
FeedItemDbManager fm = new FeedItemDbManager(av.getContext());
fm.deleteFromDb(_id);
// fm.deleteFromDb(_id);
fm.updatePath(title, path, false);
adapter.changeCursor(fm.getAllFromDB());
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog.Builder builder = new AlertDialog.Builder(
FeedDetailActivity.this);
builder.setMessage("delete?");
builder.setPositiveButton("delete", listener);
builder.setNegativeButton("cancel", null);
......@@ -245,11 +323,8 @@ public class FeedDetailActivity extends Activity implements
if (resultCode == DownloadService.PROGRESS_UPDATE) {
int progress = resultData.getInt("progress");
Log.d("ResultReceiver", "progress: " + progress);
progressDialog.setProgress(progress);
progressDialog.setMessage(String.valueOf(progress)
+ "% downloaded sucessfully.");
progressDialog.setMessage(progress + "% donwloaded");
if (progress == 100) {
progressDialog.dismiss();
......
......@@ -17,13 +17,15 @@ public class FeedItemDbManager {
public static final String COLUMN_DESCRIPTION = "description";
public static final String COLUMN_PUBDATE = "pubDate";
public static final String COLUMN_PATH = "path";
public static final String COLUMN_STATUS = "status";
private static final String TABLE_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TABLE_FEEDITEMS + " ( " + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_FEEDID
+ " INTEGER, " + COLUMN_TITLE + " VARCHAR, " + COLUMN_LINK
+ " VARCHAR, " + COLUMN_DESCRIPTION + " VARCHAR, " + COLUMN_PUBDATE
+ " VARCHAR, " + COLUMN_PATH + " VARCHAR );";
+ " VARCHAR, " + COLUMN_PATH + " VARCHAR, " + COLUMN_STATUS
+ " INTEGER );";
private final SQLiteDatabase db;
public FeedItemDbManager(Context context) {
......@@ -41,17 +43,22 @@ public class FeedItemDbManager {
// + " FROM " + TABLE_FEEDITEMS + " ORDER BY " + COLUMN_PUBDATE);
return db
.rawQuery(
"SELECT title, id as _id , feedId, link, description, pubDate, path FROM feedItems ORDER BY pubDate",
"SELECT title, id as _id , feedId, link, description, pubDate, path, status FROM feedItems ORDER BY pubDate",
null);
}