Update APIv1 & APIv2 support

This commit is contained in:
david 2013-07-15 14:38:01 +02:00
parent 0efc61e905
commit c2fdb8550e
35 changed files with 4934 additions and 4643 deletions

View file

@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

BIN
libs/gson-2.2.4-javadoc.jar Normal file

Binary file not shown.

BIN
libs/gson-2.2.4-sources.jar Normal file

Binary file not shown.

BIN
libs/gson-2.2.4.jar Normal file

Binary file not shown.

View file

@ -44,7 +44,10 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
*/
public ViewPager mViewPager;
private int currentPosition;
MenuItem menuItem_Starred;
MenuItem menuItem_Read;
IReader _Reader;
ArrayList<Integer> databaseItemIds;
DatabaseConnection dbConn;
@ -199,14 +202,12 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
currentPosition = position;
ResumeVideoPlayersOnCurrentPage();
UpdateActionBarIcons();
//String idFeed = String.valueOf(rssFiles.get(position).getDB_Id());
String idFeed = String.valueOf(databaseItemIds.get(currentPosition));
if(!dbConn.isFeedUnreadStarred(idFeed, true))
{
dbConn.updateIsReadOfFeed(idFeed, true);
markItemAsReadUnread(idFeed, true);
//Cursor cur = dbConn.getArticleByID(idFeed);
//cur.moveToFirst();
@ -228,6 +229,8 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
//dbConn.closeDatabase();
Log.d("PAGE CHANGED", "PAGE: " + position + " - IDFEED: " + idFeed);
}
else //Only in else because the function markItemAsReas updates the ActionBar items as well
UpdateActionBarIcons();
}
private void ResumeVideoPlayersOnCurrentPage()
@ -248,6 +251,7 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
public void UpdateActionBarIcons()
{
boolean isStarred = dbConn.isFeedUnreadStarred(String.valueOf(databaseItemIds.get(currentPosition)), false);
boolean isRead = dbConn.isFeedUnreadStarred(String.valueOf(databaseItemIds.get(currentPosition)), true);
//if(rssFiles.get(currentPosition).getStarred() && menuItem_Starred != null)
if(isStarred && menuItem_Starred != null)
@ -256,6 +260,11 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
else if(menuItem_Starred != null)
menuItem_Starred.setIcon(android.R.drawable.star_off);
//menuItem_Starred.setIcon(R.drawable.btn_rating_star_off_normal_holo_light);
if(isRead && menuItem_Read != null)
menuItem_Read.setChecked(true);
else if(menuItem_Read != null)
menuItem_Read.setChecked(false);
}
@Override
@ -265,6 +274,7 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
getSupportMenuInflater().inflate(R.menu.news_detail, menu);
menuItem_Starred = menu.findItem(R.id.action_starred);
menuItem_Read = menu.findItem(R.id.action_read);
UpdateActionBarIcons();
return true;
@ -373,11 +383,29 @@ public class NewsDetailActivity extends SherlockFragmentActivity {
startActivity(Intent.createChooser(share, "Share Item"));
break;
case R.id.action_read:
if(cursor != null)
{
cursor.moveToFirst();
String id = cursor.getString(0);
markItemAsReadUnread(id, !menuItem_Read.isChecked());
cursor.close();
}
break;
}
return super.onOptionsItemSelected(item);
}
private void markItemAsReadUnread(String item_id, boolean read) {
dbConn.updateIsReadOfFeed(item_id, read);
UpdateActionBarIcons();
}
/*
OnAsyncTaskCompletedListener asyncTaskCompletedPerformTagRead = new OnAsyncTaskCompletedListener() {

View file

@ -122,7 +122,7 @@ public class NewsReaderDetailActivity extends MenuUtilsSherlockFragmentActivity
@TargetApi(Build.VERSION_CODES.FROYO)
public static void UpdateListViewAndScrollToPos(FragmentActivity act, int pos)
{
((NewsReaderDetailFragment) act.getSupportFragmentManager().findFragmentById(R.id.newsreader_detail_container)).lvAdapter.notifyDataSetChanged();
((NewsReaderDetailFragment) act.getSupportFragmentManager().findFragmentById(R.id.newsreader_detail_container)).getLvAdapter().notifyDataSetChanged();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
((NewsReaderDetailFragment) act.getSupportFragmentManager().findFragmentById(R.id.newsreader_detail_container)).getListView().smoothScrollToPosition(pos);
else

View file

@ -3,11 +3,14 @@ package de.luhmer.owncloudnewsreader;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -37,8 +40,18 @@ public class NewsReaderDetailFragment extends SherlockListFragment {
protected static final String TAG = "NewsReaderDetailFragment";
DatabaseConnection dbConn;
NewsListCursorAdapter lvAdapter;
private DatabaseConnection dbConn;
private boolean DialogShowedToMarkLastItemsAsRead = false;
private NewsListCursorAdapter lvAdapter;
/**
* @return the lvAdapter
*/
public NewsListCursorAdapter getLvAdapter() {
return lvAdapter;
}
String idFeed;
/**
* @return the idFeed
@ -132,8 +145,9 @@ public class NewsReaderDetailFragment extends SherlockListFragment {
getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
//Log.d(TAG, "Scroll: " + scrollState);
/*
Log.d(TAG, "LOL" + scrollState);
if(AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL == scrollState)
{
@ -141,16 +155,50 @@ public class NewsReaderDetailFragment extends SherlockListFragment {
}
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, int totalItemCount) {
CheckBox cb = getCheckBoxAtPosition(0, view);
ChangeCheckBoxState(cb, true);
NewsListCursorAdapter.ChangeCheckBoxState(cb, true, getActivity());
if((firstVisibleItem + visibleItemCount) == totalItemCount) {
if(((firstVisibleItem + visibleItemCount) == totalItemCount) && !DialogShowedToMarkLastItemsAsRead ){
DialogShowedToMarkLastItemsAsRead = true;
boolean needQuestion = false;
for (int i = firstVisibleItem + 1; i < firstVisibleItem + visibleItemCount; i++) {
cb = getCheckBoxAtPosition(i - firstVisibleItem, view);
ChangeCheckBoxState(cb, true);
if(!cb.isChecked())
{
needQuestion = true;
break;
}
}
if(needQuestion)
new AlertDialog.Builder(getActivity())
.setTitle("Alle als gelesen markieren ?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = firstVisibleItem + 1; i < firstVisibleItem + visibleItemCount; i++) {
CheckBox cb = getCheckBoxAtPosition(i - firstVisibleItem, view);
NewsListCursorAdapter.ChangeCheckBoxState(cb, true, getActivity());
}
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
})
.create()
.show();
}
}
/*
@ -185,12 +233,7 @@ public class NewsReaderDetailFragment extends SherlockListFragment {
super.onViewCreated(view, savedInstanceState);
}
private void ChangeCheckBoxState(CheckBox cb, boolean state)
{
if(cb != null)
if(cb.isChecked() != state)
cb.setChecked(state);
}
private CheckBox getCheckBoxAtPosition(int pos, AbsListView viewLV)
{

View file

@ -8,6 +8,7 @@ import android.preference.PreferenceManager;
import com.actionbarsherlock.app.SherlockDialogFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.handmark.pulltorefresh.library.BlockingExpandableListView;
import com.handmark.pulltorefresh.library.PullToRefreshExpandableListView;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
@ -105,15 +106,25 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im
}
public void updateAdapter() {
NewsReaderListFragment nlf = ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.newsreader_list));
if(nlf != null)
{
// Block children layout for now
PullToRefreshExpandableListView ptrel = ((PullToRefreshExpandableListView)nlf.eListView);
BlockingExpandableListView bView = ((BlockingExpandableListView) ptrel.getRefreshableView());
bView.setBlockLayoutChildren(true);
nlf.lvAdapter.notifyDataSetChanged();
bView.setBlockLayoutChildren(false);
}
}
@Override
protected void onResume() {
ThemeChooser.chooseTheme(this);
NewsReaderListFragment nlf = ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.newsreader_list));
if(nlf != null)
nlf.lvAdapter.notifyDataSetChanged();
updateAdapter();
super.onResume();
}
@ -320,13 +331,4 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im
SherlockDialogFragment dialog = new LoginDialogFragment();
dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
}
/*
AsyncUpdateFinished updateFinished = new AsyncUpdateFinished() {
@Override
public void FinishedUpdate() {
menuItemUpdater.setActionView(null);
}
};*/
}

View file

@ -33,7 +33,10 @@ import de.luhmer.owncloudnewsreader.interfaces.ExpListTextClicked;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.IReader;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
/**
* A list fragment representing a list of NewsReader. This fragment also
@ -125,34 +128,6 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
{
dbConn = new DatabaseConnection(getActivity());
/*
//Update Database Stuff first
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
if(mPrefs.getInt("LAST_APP_VERSION", 0) < pInfo.versionCode)
{
dbConn.resetDatabase();
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt("LAST_APP_VERSION", pInfo.versionCode);
editor.commit();
}
} catch (Exception e) {
e.printStackTrace();
}
*/
/*
String val = String.valueOf(dbConn.getLongValueBySQL("SELECT COUNT(*) FROM " +
DatabaseConnection.RSS_ITEM_TABLE +
" WHERE " + DatabaseConnection.RSS_ITEM_STARRED_TEMP + " != " + DatabaseConnection.RSS_ITEM_STARRED
));
Toast.makeText(getActivity(), val, Toast.LENGTH_LONG).show();
*/
//dbConn.resetDatabase();
//dbConn.clearDatabaseOverSize();
@ -167,18 +142,6 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
if(_Reader == null)
_Reader = new OwnCloud_Reader();
//((NewsReaderListActivity) getActivity()).startSync();
//_Reader.Start_AsyncTask_GetFeeds(2, getActivity(), null);
/*
new AsyncTask_GetGReaderTags(1, getActivity(), onAsyncTask_GetTopReaderTags).execute(username, password);
new AsyncTask_GetSubReaderTags(1, getActivity(), onAsyncTask_GetSubReaderTags).execute(username, password);*/
}
catch(Exception ex)
{
@ -199,6 +162,39 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
} else {
if (!_Reader.isSyncRunning())
{
OwnCloud_Reader ocReader = (OwnCloud_Reader) _Reader;
ocReader.Start_AsyncTask_GetVersion(-10, getActivity(), onAsyncTask_GetVersionFinished, username, password);
}
else
_Reader.attachToRunningTask(-10, getActivity(), onAsyncTask_GetVersionFinished);
}
UpdateSyncButtonLayout();
}
OnAsyncTaskCompletedListener onAsyncTask_GetVersionFinished = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(int task_id, Object task_result) {
if(!(task_result instanceof Exception))
{
API api = null;
String appVersion = task_result.toString();
int versionCode = 0;
if(appVersion != null)
{
appVersion = appVersion.replace(".", "");
versionCode = Integer.parseInt(appVersion);
}
if (versionCode >= 1101) {
api = new APIv2(getActivity());
} else {
api = new APIv1(getActivity());
}
((OwnCloud_Reader) _Reader).setApi(api);
DatabaseConnection dbConn = new DatabaseConnection(getActivity());
try {
//Mark as READ
@ -224,14 +220,11 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
eListView.getLoadingLayoutProxy().setLastUpdatedLabel(getString(R.string.pull_to_refresh_updateTags));
//_Reader.Start_AsyncTask_GetFolder(0, getActivity(), onAsyncTask_GetTopReaderTags);
}
else
//_Reader.attachToRunningTask(0, getActivity(), onAsyncTask_GetTopReaderTags);
_Reader.attachToRunningTask(-1, getActivity(), onAsyncTask_PerformTagExecute);
}
UpdateSyncButtonLayout();
}
};
//Sync state of items e.g. read/unread/starred/unstarred
OnAsyncTaskCompletedListener onAsyncTask_PerformTagExecute = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(int task_id, Object task_result) {
@ -243,7 +236,7 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
if(task_id == -1)
{
_Reader.Start_AsyncTask_GetFolder(1, getActivity(), onAsyncTask_GetTopReaderTags);
_Reader.Start_AsyncTask_GetFolder(1, getActivity(), onAsyncTask_GetFolder);
if(eListView != null)
eListView.getLoadingLayoutProxy().setLastUpdatedLabel(getString(R.string.pull_to_refresh_updateFolder));
}
@ -258,7 +251,8 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
}
};
OnAsyncTaskCompletedListener onAsyncTask_GetTopReaderTags = new OnAsyncTaskCompletedListener() {
OnAsyncTaskCompletedListener onAsyncTask_GetFolder = new OnAsyncTaskCompletedListener() {
@Override
@ -284,7 +278,7 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
}
else
{
_Reader.Start_AsyncTask_GetFeeds(1, getActivity(), onAsyncTask_GetSubReaderTags);
_Reader.Start_AsyncTask_GetFeeds(1, getActivity(), onAsyncTask_GetFeed);
if(eListView != null)
eListView.getLoadingLayoutProxy().setLastUpdatedLabel(getString(R.string.pull_to_refresh_updateFeeds));
}
@ -299,7 +293,7 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
}
OnAsyncTaskCompletedListener onAsyncTask_GetSubReaderTags = new OnAsyncTaskCompletedListener() {
OnAsyncTaskCompletedListener onAsyncTask_GetFeed = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(int task_id, Object task_result) {
@ -315,7 +309,7 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
{
//dbConn.resetRssItemsDatabase();
_Reader.Start_AsyncTask_GetItems(2, getActivity(), onAsyncTask_GetFeeds, TAGS.ALL);//Recieve all unread Items
_Reader.Start_AsyncTask_GetItems(2, getActivity(), onAsyncTask_GetItems, TAGS.ALL);//Recieve all unread Items
//_Reader.Start_AsyncTask_GetFeeds(3, getActivity(), onAsyncTask_GetFeeds, TAGS.ALL_STARRED);//Recieve all starred Items
if(eListView != null)
@ -333,7 +327,7 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
}
};
OnAsyncTaskCompletedListener onAsyncTask_GetFeeds = new OnAsyncTaskCompletedListener() {
OnAsyncTaskCompletedListener onAsyncTask_GetItems = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(int task_id, Object task_result) {
@ -379,9 +373,9 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
//eListView.demo();
eListView.setShowIndicator(false);
eListView.setOnRefreshListener(new OnRefreshListener<ExpandableListView>() {
eListView.setOnRefreshListener(new OnRefreshListener<BlockingExpandableListView>() {
@Override
public void onRefresh(PullToRefreshBase<ExpandableListView> refreshView) {
public void onRefresh(PullToRefreshBase<BlockingExpandableListView> refreshView) {
StartSync();
}
});
@ -535,6 +529,13 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
((NewsReaderListActivity) getActivity()).UpdateButtonSyncLayout();
}
/**
* @return the eListView
*/
public PullToRefreshExpandableListView geteListView() {
return eListView;
}
/*
public void setUpdateFinishedListener(AsyncUpdateFinished listener)
{

View file

@ -24,7 +24,11 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import de.luhmer.owncloudnewsreader.NewsDetailFragment;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
@ -88,6 +92,7 @@ public class NewsListCursorAdapter extends CursorAdapter {
else
cb.setButtonDrawable(R.drawable.btn_rating_star_off_normal_holo_light);
*/
cb.setClickable(true);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@ -131,7 +136,7 @@ public class NewsListCursorAdapter extends CursorAdapter {
//GoogleReaderMethods.MarkItemAsRead(isChecked, getCursorForCurrentRow(buttonView), dbConn, context, asyncTaskCompletedPerformTagStarred);
dbConn.updateIsReadOfFeed(idItemDb, isChecked);
UpdateListCursor(mContext);
/*
//TODO THIS IS IMPORTANT CODE !
List<String> idItems = new ArrayList<String>();
@ -230,9 +235,33 @@ public class NewsListCursorAdapter extends CursorAdapter {
LinearLayout lLayout = (LinearLayout) view.getParent();
Boolean isChecked = dbConn.isFeedUnreadStarred(idItemDb, true);
CheckBox cbRead = (CheckBox) lLayout.findViewById(R.id.cb_lv_item_read);
//ChangeCheckBoxState(cbRead, isChecked, mContext);
cbRead.setChecked(isChecked);
}
public static void ChangeCheckBoxState(CheckBox cb, boolean state, Context context)
{
if(cb != null)
{
if(cb.isChecked() != state)
{
cb.setChecked(state);
UpdateListCursor(context);
}
}
}
public static void UpdateListCursor(Context context)//TODO make this better
{
SherlockFragmentActivity sfa = (SherlockFragmentActivity) context;
//if tablet view is enabled --> update the listview
if(sfa instanceof NewsReaderListActivity)
((NewsReaderListActivity) sfa).updateAdapter();
}
private String getBodyText(String body)
{
//if(body.length() > LengthBody)

View file

@ -1,6 +1,6 @@
package de.luhmer.owncloudnewsreader.data;
public class ConcreteSubscribtionItem {
public class ConcreteFeedItem {
public String folder_id;
public String subscription_id;
@ -8,7 +8,7 @@ public class ConcreteSubscribtionItem {
public String header;
public long id_database;
public ConcreteSubscribtionItem(String header, String folder_id, String subscription_id, String favIcon, long id_database/*, String parent_title*/) {
public ConcreteFeedItem(String header, String folder_id, String subscription_id, String favIcon, long id_database/*, String parent_title*/) {
this.header = header;
this.folder_id = folder_id;

View file

@ -9,6 +9,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import de.luhmer.owncloudnewsreader.Constants;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
public class DatabaseConnection {
@ -68,7 +69,7 @@ public class DatabaseConnection {
//DELETE FROM table ORDER BY dateRegistered ASC LIMIT 5
int max = 1000;
int max = Constants.maxItemsCount;
int total = (int) getLongValueBySQL("SELECT COUNT(*) FROM rss_item");
int unread = (int) getLongValueBySQL("SELECT COUNT(*) FROM rss_item WHERE read_temp != 1");
int read = total - unread;

View file

@ -1,5 +1,9 @@
package de.luhmer.owncloudnewsreader.helper;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.Toast;
@ -10,17 +14,23 @@ import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import de.luhmer.owncloudnewsreader.Constants;
import de.luhmer.owncloudnewsreader.NewsReaderDetailActivity;
import de.luhmer.owncloudnewsreader.NewsReaderDetailFragment;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.VersionInfoDialogFragment;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.IReader;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
public class MenuUtilsSherlockFragmentActivity extends SherlockFragmentActivity {
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onResume()
*/
protected static final String TAG = "MenuUtils";
static FragmentActivity activity;
@ -56,6 +66,14 @@ public class MenuUtilsSherlockFragmentActivity extends SherlockFragmentActivity
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onResume() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
invalidateOptionsMenu();
}
super.onResume();
}
public static void onCreateOptionsMenu(Menu menu, MenuInflater inflater, boolean mTwoPane, FragmentActivity act) {
@ -126,6 +144,10 @@ public class MenuUtilsSherlockFragmentActivity extends SherlockFragmentActivity
}
ndf.UpdateCursor();
//If tablet view is enabled update the listview as well
if(activity instanceof NewsReaderListActivity)
((NewsReaderListActivity) activity).updateAdapter();
}
return true;
@ -139,11 +161,32 @@ public class MenuUtilsSherlockFragmentActivity extends SherlockFragmentActivity
private static void DownloadMoreItems()
{
NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) activity.getSupportFragmentManager().findFragmentById(R.id.newsreader_detail_container));
DatabaseConnection dbConn = new DatabaseConnection(activity);
int count = dbConn.getCountFeedsForFolder(SubscriptionExpandableListAdapter.ALL_UNREAD_ITEMS, true);
if(count > Constants.maxItemsCount)
{
String text = activity.getString(R.string.max_items_count_reached);
text = text.replace("XX", "" + Constants.maxItemsCount);
new AlertDialog.Builder(activity)
.setTitle(activity.getString(R.string.empty_view_header))
.setMessage(text)
.setPositiveButton(activity.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
}
})
.create()
.show();
//Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
}
else
{
IReader _Reader = new OwnCloud_Reader();
_Reader.Start_AsyncTask_GetOldItems(0, activity, onAsyncTaskComplete, ndf.getIdFeed(), ndf.getIdFolder());
Toast.makeText(activity, activity.getString(R.string.toast_GettingMoreItems), Toast.LENGTH_SHORT).show();
}
}
static OnAsyncTaskCompletedListener onAsyncTaskComplete = new OnAsyncTaskCompletedListener() {
@Override

View file

@ -1,7 +1,45 @@
package de.luhmer.owncloudnewsreader.reader;
import android.app.Activity;
import android.os.AsyncTask;
public interface AsyncTask_Reader {
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener);
public abstract class AsyncTask_Reader extends AsyncTask<Object, Void, Object> {
protected Activity context;
protected int task_id;
protected OnAsyncTaskCompletedListener[] listener;
public AsyncTask_Reader(final int task_id, final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.task_id = task_id;
this.listener = listener;
}
//public abstract void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener);
//Activity meldet sich zurueck nach OrientationChange
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.listener = listener;
}
//Activity meldet sich ab
public void detach() {
if (context != null) {
context = null;
}
if (listener != null) {
listener = null;
}
}
@Override
protected void onPostExecute(Object ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(task_id, ex);
}
detach();
}
}

View file

@ -1,5 +1,7 @@
package de.luhmer.owncloudnewsreader.reader;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
@ -25,28 +27,65 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.helper.SSLHttpClient;
import de.luhmer.owncloudnewsreader.util.Base64;
public class HttpJsonRequest {
//private static final String TAG = "HttpJsonRequest";
@SuppressLint("DefaultLocale")
public static JSONObject PerformJsonRequest(String urlString, List<NameValuePair> nameValuePairs, String username, String password, Context context) throws Exception
public static InputStream PerformJsonRequest(String urlString, List<NameValuePair> nameValuePairs, final String username, final String password, Context context) throws Exception
{
if(nameValuePairs != null)
{
urlString += "&" + URLEncodedUtils.format(nameValuePairs, "utf-8");
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
/*
JSONObject jObj = new JSONObject();
if(sp.getBoolean(SettingsActivity.CB_ALLOWALLSSLCERTIFICATES_STRING, false) && url.getProtocol().toLowerCase().equals("https"))
httpClient = new SSLHttpClient(context);
else
httpClient = new DefaultHttpClient();
*/
for (NameValuePair nameValuePair : nameValuePairs) {
jObj.put(nameValuePair.getName(), nameValuePair.getValue());
}*/
//urlConnection.setDefaultSSLSocketFactory(new MySSLSocketFactory()); getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username,password));
//request.setEntity(new ByteArrayEntity(jObj.toString().getBytes("UTF8")));
if(username != null && password != null)
urlConnection.setRequestProperty("Authorization", "Basic " + Base64.encode((username + ":" + password).getBytes()));
/*
Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}});*/
//httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
urlConnection.setDoOutput(false);
urlConnection.setDoInput(true);
urlConnection.setRequestMethod("GET");
//urlConnection.setFollowRedirects(true);
urlConnection.setUseCaches(false);
urlConnection.setConnectTimeout(10000);
urlConnection.setReadTimeout(120000);//2min
urlConnection.setRequestProperty("Content-Type","application/json");
//urlConnection.setRequestProperty("Host", "de.luhmer.ownCloudNewsReader");
urlConnection.connect();
int HttpResult = urlConnection.getResponseCode();
if(HttpResult == HttpURLConnection.HTTP_OK) {
return urlConnection.getInputStream();
} else {
throw new Exception(urlConnection.getResponseMessage());
}
}
@SuppressLint("DefaultLocale")
public static JSONObject PerformJsonRequest_old(String urlString, List<NameValuePair> nameValuePairs, String username, String password, Context context) throws Exception
{
if(nameValuePairs != null)
urlString += "&" + URLEncodedUtils.format(nameValuePairs, "utf-8");
URL url = new URL(urlString);
@ -85,54 +124,8 @@ public class HttpJsonRequest {
//return null;
// Log.i(getClass().getSimpleName(), "send task - end");
/*
URLConnection conn = null;
InputStream inputStream = null;
URL urlInstance = new URL(url);
conn = urlInstance.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
return new JSONObject(total.toString());
}
else
Log.d(TAG, "Response Code: " + httpConn.getResponseCode());
*/
}
/*
public static int performTagChangeRequest(String url)
{
try
{
URLConnection conn = null;
//InputStream inputStream = null;
URL urlInstance = new URL(url);
conn = urlInstance.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
return httpConn.getResponseCode();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return -1;
}
*/
@SuppressLint("DefaultLocale")

View file

@ -3,7 +3,6 @@ package de.luhmer.owncloudnewsreader.reader;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.util.SparseArray;
public interface IReader {
@ -18,7 +17,7 @@ public interface IReader {
public void Start_AsyncTask_GetFolder(final int task_id, final Activity context, final OnAsyncTaskCompletedListener listener);
public void Start_AsyncTask_GetFeeds(final int task_id, final Activity context, final OnAsyncTaskCompletedListener listener);
public void Start_AsyncTask_PerformTagAction(final int task_id, final Context context, final OnAsyncTaskCompletedListener listener, List<String> itemIds, FeedItemTags.TAGS tag);
public void Start_AsyncTask_PerformTagAction(final int task_id, final Activity context, final OnAsyncTaskCompletedListener listener, List<String> itemIds, FeedItemTags.TAGS tag);
public void Start_AsyncTask_Authenticate(final int task_id, final Activity context, final OnAsyncTaskCompletedListener listener);
public abstract void onAsyncTaskCompleted(final int task_id, final Object task_result);

View file

@ -5,7 +5,7 @@ import java.util.List;
import android.app.Activity;
import android.util.Log;
import de.luhmer.owncloudnewsreader.data.ConcreteSubscribtionItem;
import de.luhmer.owncloudnewsreader.data.ConcreteFeedItem;
import de.luhmer.owncloudnewsreader.data.RssFile;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
@ -15,10 +15,9 @@ import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
public class InsertIntoDatabase {
private static final String TAG = "InsertIntoDatabase";
public static void InsertFoldersIntoDatabase(List<String[]> tags, Activity activity)
public static void InsertFoldersIntoDatabase(List<String[]> tags, DatabaseConnection dbConn)
{
DatabaseConnection dbConn = new DatabaseConnection(activity);
//DatabaseConnection dbConn = new DatabaseConnection(activity);
//List<String[]> tags = (List<String[]>) task_result;
List<String> tagsAvailable = dbConn.convertCursorToStringArray(dbConn.getAllTopSubscriptions(false), 1);
@ -66,12 +65,12 @@ public class InsertIntoDatabase {
}
dbConn.closeDatabase();
//dbConn.closeDatabase();
}
public static void InsertSubscriptionsIntoDatabase(ArrayList<ConcreteSubscribtionItem> tags, Activity activity)
public static void InsertSubscriptionsIntoDatabase(ArrayList<ConcreteFeedItem> tags, DatabaseConnection dbConn)
{
DatabaseConnection dbConn = new DatabaseConnection(activity);
//DatabaseConnection dbConn = new DatabaseConnection(activity);
List<String> tagsAvailable = dbConn.convertCursorToStringArray(dbConn.getAllSubSubscriptions(), 1);
@ -80,7 +79,7 @@ public class InsertIntoDatabase {
{
if(tags != null)
{
for(ConcreteSubscribtionItem tag : tags)
for(ConcreteFeedItem tag : tags)
{
if(!tagsAvailable.contains(tag.header))
{
@ -121,7 +120,7 @@ public class InsertIntoDatabase {
} finally {
//dbConn.getDatabase().endTransaction();
}
dbConn.closeDatabase();
//dbConn.closeDatabase();
}

View file

@ -0,0 +1,58 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
public abstract class API {
protected SharedPreferences mPrefs;
public API(Activity act) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(act);
}
protected abstract String getItemUrl();
protected abstract String getItemUpdatedUrl();
protected abstract String getFeedUrl();
protected abstract String getFolderUrl();
protected abstract String getTagBaseUrl();
//public abstract void markSingleItemAsReadApiv1();
public String getUsername() {
return mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
}
public String getPassword() {
return mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
}
public int GetFeeds(Activity act, API api) throws Exception {
return OwnCloudReaderMethods.GetFeeds(act, api);
}
public int GetFolderTags(Activity act, API api) throws Exception {
return OwnCloudReaderMethods.GetFolderTags(act, api);
}
public int GetItems(TAGS tag, Activity act, String offset, boolean getRead, String id, String type, API api) throws Exception {
return OwnCloudReaderMethods.GetItems(tag, act, offset, getRead, id, type, api);
}
public int GetUpdatedItems(TAGS tag, Activity act, long lastSync, API api) throws Exception {
return OwnCloudReaderMethods.GetUpdatedItems(tag, act, lastSync, api);
}
public abstract boolean PerformTagExecution(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api);
/*
public boolean PerformTagExecution(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api) {
return OwnCloudReaderMethods.PerformTagExecution(itemIds, tag, context, api);
}*/
}

View file

@ -0,0 +1,33 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
public class AsyncTask_GetApiVersion extends AsyncTask_Reader {
private String username;
private String password;
public AsyncTask_GetApiVersion(final int task_id, final Activity context, String username, String password, final OnAsyncTaskCompletedListener[] listener) {
super(task_id, context, listener);
this.username = username;
this.password = password;
}
@Override
protected Object doInBackground(Object... params) {
try {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
return OwnCloudReaderMethods.GetVersionNumber(context, username, password, oc_root_path);
} catch (Exception ex) {
return ex;
}
}
}

View file

@ -1,60 +1,26 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import android.app.Activity;
import android.os.AsyncTask;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
public class AsyncTask_GetFeeds extends AsyncTask<Object, Void, Exception> implements AsyncTask_Reader {
private Activity context;
private int task_id;
private OnAsyncTaskCompletedListener[] listener;
public class AsyncTask_GetFeeds extends AsyncTask_Reader {
public AsyncTask_GetFeeds(final int task_id, final Activity context, final OnAsyncTaskCompletedListener[] listener) {
super();
this.context = context;
this.task_id = task_id;
this.listener = listener;
super(task_id, context, listener);
}
//Activity meldet sich zurueck nach OrientationChange
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.listener = listener;
}
//Activity meldet sich ab
public void detach() {
if (context != null) {
context = null;
}
if (listener != null) {
listener = null;
}
}
@Override
protected Exception doInBackground(Object... params) {
API api = new APIv2(context);
try {
InsertIntoDatabase.InsertSubscriptionsIntoDatabase(OwnCloudReaderMethods.GetSubscriptionTags(context), context);
api.GetFeeds(context, api);
//OwnCloudReaderMethods.GetFeeds(context, api);
} catch (Exception ex) {
return ex;
}
return null;
}
@Override
protected void onPostExecute(Exception ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(task_id, ex);
}
detach();
}
}

View file

@ -1,65 +1,26 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import android.app.Activity;
import android.os.AsyncTask;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
public class AsyncTask_GetFolderTags extends AsyncTask<Object, Void, Exception> implements AsyncTask_Reader {
private Activity context;
private int task_id;
private OnAsyncTaskCompletedListener[] listener;
public class AsyncTask_GetFolderTags extends AsyncTask_Reader {
public AsyncTask_GetFolderTags(final int task_id, final Activity context, final OnAsyncTaskCompletedListener[] listener) {
super();
this.context = context;
this.task_id = task_id;
this.listener = listener;
super(task_id, context, listener);
}
//Activity meldet sich zurueck nach OrientationChange
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.listener = listener;
}
//Activity meldet sich ab
public void detach() {
if (context != null) {
context = null;
}
if (listener != null) {
listener = null;
}
}
@Override
protected Exception doInBackground(Object... params) {
/*
String username = (String) params[0];
String password = (String) params[1];
*/
API api = new APIv2(context);
try {
InsertIntoDatabase.InsertFoldersIntoDatabase(OwnCloudReaderMethods.GetFolderTags(context), context);
//OwnCloudReaderMethods.GetFolderTags(context, api);
api.GetFolderTags(context, api);
} catch(Exception ex) {
return ex;
}
return null;
}
@Override
protected void onPostExecute(Exception ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(task_id, ex);
}
detach();
}
}

View file

@ -5,8 +5,8 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import de.luhmer.owncloudnewsreader.Constants;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
@ -14,49 +14,18 @@ import de.luhmer.owncloudnewsreader.helper.NetworkConnection;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
import de.luhmer.owncloudnewsreader.services.DownloadImagesService;
public class AsyncTask_GetItems extends AsyncTask<Object, Void, Exception> implements AsyncTask_Reader {
private Activity context;
private int task_id;
private OnAsyncTaskCompletedListener[] listener;
public class AsyncTask_GetItems extends AsyncTask_Reader {
private long highestItemIdBeforeSync;
public AsyncTask_GetItems(final int task_id, final Activity context, final OnAsyncTaskCompletedListener[] listener) {
super();
this.context = context;
this.task_id = task_id;
this.listener = listener;
}
//Activity meldet sich zurueck nach OrientationChange
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.listener = listener;
}
//Activity meldet sich ab
public void detach() {
if (context != null) {
context = null;
}
if (listener != null) {
listener = null;
}
super(task_id, context, listener);
}
@Override
protected Exception doInBackground(Object... params) {
//FeedItemTags.TAGS tag = (TAGS) params[0];
/*
String username = (String) params[0];
String password = (String) params[1];
String _TAG_LABEL = (String) params[2];
*/
DatabaseConnection dbConn = new DatabaseConnection(context);
try {
//String authKey = AuthenticationManager.getGoogleAuthKey(username, password);
@ -67,72 +36,38 @@ public class AsyncTask_GetItems extends AsyncTask<Object, Void, Exception> imple
//List<RssFile> files;
long offset = dbConn.getLowestItemId(false);
//int totalCount = 0;
int totalCount = 0;
int requestCount = 0;
int maxSyncSize = Integer.parseInt(OwnCloudReaderMethods.maxSizePerSync);
int maxItemsInDatabase = Constants.maxItemsCount;
highestItemIdBeforeSync = dbConn.getHighestItemId();
API api = new APIv2(context);
if(lastModified == 0)
{
//init startup
do {
requestCount = OwnCloudReaderMethods.GetItems(TAGS.ALL, context, String.valueOf(offset), false, "0", "3");
requestCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), false, "0", "3", api);
if(requestCount > 0)
offset = dbConn.getLowestItemId(false);
//totalCount += requestCount;
totalCount += requestCount;
} while(requestCount == maxSyncSize /* && totalCount < maxItemsInDatabase */);
do {
offset = dbConn.getLowestItemId(true);
requestCount = OwnCloudReaderMethods.GetItems(TAGS.ALL_STARRED, context, String.valueOf(offset), true, "0", "2");
requestCount = api.GetItems(TAGS.ALL_STARRED, context, String.valueOf(offset), true, "0", "2", api);
if(requestCount > 0)
offset = dbConn.getLowestItemId(true);
} while(requestCount == maxSyncSize);
totalCount += requestCount;
} while(requestCount == maxSyncSize && totalCount < maxItemsInDatabase);
}
else
{
//OwnCloudReaderMethods.GetUpdatedItems(tag, context, lastModified, true);
OwnCloudReaderMethods.GetUpdatedItems(TAGS.ALL, context, lastModified);
//OwnCloudReaderMethods.GetUpdatedItems(TAGS.ALL_STARRED, context, lastModified);
api.GetUpdatedItems(TAGS.ALL, context, lastModified, api);
//OwnCloudReaderMethods.GetUpdatedItems(TAGS.ALL, context, lastModified, api);
}
/*
//Get all unread items which are older then the latest item id in db
do {
requestCount = OwnCloudReaderMethods.GetItems(tag, context, String.valueOf(offset), false);
//InsertIntoDatabase.InsertFeedItemsIntoDatabase(files, context);
if(requestCount > 0)
offset = dbConn.getLowestItemId();
totalCount += requestCount;
} while(requestCount == maxSyncSize && totalCount < maxItemsInDatabase);
if(lastModified == 0 && totalCount < maxItemsInDatabase)//If the app should sync all the items in past.
{
do {
requestCount = OwnCloudReaderMethods.GetItems(tag, context, String.valueOf(offset), true);
//InsertIntoDatabase.InsertFeedItemsIntoDatabase(files, context);
if(requestCount > 0)
offset = dbConn.getLowestItemId();
totalCount += requestCount;
} while(requestCount == maxSyncSize && totalCount < maxItemsInDatabase);
}
else if(lastModified != 0)
{
OwnCloudReaderMethods.GetUpdatedItems(tag, context, lastModified, true);
//InsertIntoDatabase.InsertFeedItemsIntoDatabase(files, context);
}
if(dbConn.getCountOfAllItems(true) > maxItemsInDatabase && !tag.equals(FeedItemTags.TAGS.ALL_STARRED))//Remove all old items which are over the limit of maxItemsInDatabase
{
String id_db = String.valueOf(dbConn.getItemDbIdAtPosition(maxItemsInDatabase));
dbConn.removeAllItemsWithIdLowerThan(id_db);
}*/
} catch (Exception ex) {
return ex;
} finally {
@ -142,17 +77,11 @@ public class AsyncTask_GetItems extends AsyncTask<Object, Void, Exception> imple
}
@Override
protected void onPostExecute(Exception ex) {
protected void onPostExecute(Object ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(task_id, ex);
}
/*
if(task_id == 3)//All Starred Item request was performed
{
Intent service = new Intent(context, DownloadImagesService.class);
context.startService(service);
}*/
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if(mPrefs.getBoolean(SettingsActivity.CB_CACHE_IMAGES_OFFLINE_STRING, false))

View file

@ -1,7 +1,6 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import android.app.Activity;
import android.os.AsyncTask;
import android.widget.Toast;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
@ -9,43 +8,21 @@ import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
public class AsyncTask_GetOldItems extends AsyncTask<Object, Void, Exception> implements AsyncTask_Reader {
public class AsyncTask_GetOldItems extends AsyncTask_Reader {
private Activity context;
private int task_id;
private OnAsyncTaskCompletedListener[] listener;
public String feed_id;
public String folder_id;
private int downloadedItemsCount = 0;
public AsyncTask_GetOldItems(final int task_id, final Activity context, final OnAsyncTaskCompletedListener[] listener, String feed_id, String folder_id) {
super();
super(task_id, context, listener);
this.context = context;
this.task_id = task_id;
this.listener = listener;
this.feed_id = feed_id;
this.folder_id = folder_id;
}
//Activity meldet sich zurueck nach OrientationChange
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.listener = listener;
}
//Activity meldet sich ab
public void detach() {
if (context != null) {
context = null;
}
if (listener != null) {
listener = null;
}
}
@Override
protected Exception doInBackground(Object... params) {
DatabaseConnection dbConn = new DatabaseConnection(context);
@ -76,8 +53,9 @@ public class AsyncTask_GetOldItems extends AsyncTask<Object, Void, Exception> im
}
}
downloadedItemsCount = OwnCloudReaderMethods.GetItems(TAGS.ALL, context, String.valueOf(offset), true, id, type);
API api = new APIv2(context);
downloadedItemsCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), true, id, type, api);
//downloadedItemsCount = OwnCloudReaderMethods.GetItems(TAGS.ALL, context, String.valueOf(offset), true, id, type, api);
//do {
@ -95,7 +73,7 @@ public class AsyncTask_GetOldItems extends AsyncTask<Object, Void, Exception> im
}
@Override
protected void onPostExecute(Exception ex) {
protected void onPostExecute(Object ex) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(task_id, ex);

View file

@ -3,44 +3,18 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
public class AsyncTask_PerformTagAction extends AsyncTask<Object, Void, Boolean> implements AsyncTask_Reader {
public class AsyncTask_PerformTagAction extends AsyncTask_Reader {
private Context context;
private int task_id;
private OnAsyncTaskCompletedListener[] listener;
public AsyncTask_PerformTagAction(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener) {
super();
this.context = context;
this.task_id = task_id;
this.listener = listener;
public AsyncTask_PerformTagAction(final int task_id, final Activity context, final OnAsyncTaskCompletedListener[] listener) {
super(task_id, context, listener);
}
//Activity meldet sich zurueck nach OrientationChange
public void attach(final Activity context, final OnAsyncTaskCompletedListener[] listener) {
this.context = context;
this.listener = listener;
}
//Activity meldet sich ab
public void detach() {
if (context != null) {
context = null;
}
if (listener != null) {
listener = null;
}
}
@SuppressWarnings("unchecked")
@Override
protected Boolean doInBackground(Object... params) {
@ -49,8 +23,10 @@ public class AsyncTask_PerformTagAction extends AsyncTask<Object, Void, Boolean>
try {
//String authKey = AuthenticationManager.getGoogleAuthKey(username, password);
API api = new APIv2(context);
if(itemIds.size() > 0)
return OwnCloudReaderMethods.PerformTagExecution(itemIds, tag, context);
return api.PerformTagExecution(itemIds, tag, context, api);
else
return true;
} catch (Exception e) {
@ -60,7 +36,7 @@ public class AsyncTask_PerformTagAction extends AsyncTask<Object, Void, Boolean>
}
@Override
protected void onPostExecute(Boolean values) {
protected void onPostExecute(Object values) {
for (OnAsyncTaskCompletedListener listenerInstance : listener) {
if(listenerInstance != null)
listenerInstance.onAsyncTaskCompleted(task_id, values);

View file

@ -0,0 +1,21 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import org.json.JSONObject;
public class GetVersion implements IHandleJsonObject{
String version;
@Override
public void performAction(JSONObject jObj) {
this.version = jObj.optString("version");
}
/**
* @return the version
*/
public String getVersion() {
return version;
}
}

View file

@ -0,0 +1,7 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import org.json.JSONObject;
public interface IHandleJsonObject {
public void performAction(JSONObject jObj);
}

View file

@ -0,0 +1,39 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.util.ArrayList;
import org.json.JSONObject;
import de.luhmer.owncloudnewsreader.data.ConcreteFeedItem;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
public class InsertFeedIntoDatabase implements IHandleJsonObject{
DatabaseConnection dbConn;
ArrayList<ConcreteFeedItem> feeds = new ArrayList<ConcreteFeedItem>();
public InsertFeedIntoDatabase(DatabaseConnection dbConn) {
this.dbConn = dbConn;
}
private static ConcreteFeedItem parseFeed(JSONObject e)
{
String faviconLink = e.optString("faviconLink");
if(faviconLink != null)
if(faviconLink.equals("null") || faviconLink.trim().equals(""))
faviconLink = null;
return new ConcreteFeedItem(e.optString("title"), e.optString("folderId"), e.optString("id"), faviconLink, -1);
}
@Override
public void performAction(JSONObject jObj) {
ConcreteFeedItem rssFeed = parseFeed(jObj);
feeds.add(rssFeed);
}
public void WriteAllToDatabaseNow() {
InsertIntoDatabase.InsertSubscriptionsIntoDatabase(feeds, dbConn);
}
}

View file

@ -0,0 +1,32 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.util.ArrayList;
import org.json.JSONObject;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
public class InsertFolderIntoDatabase implements IHandleJsonObject{
DatabaseConnection dbConn;
ArrayList<String[]> folders = new ArrayList<String[]>();
public InsertFolderIntoDatabase(DatabaseConnection dbConn) {
this.dbConn = dbConn;
}
private static String[] parseFolder(JSONObject e)
{
return new String[] { e.optString("name"), e.optString("id") };
}
@Override
public void performAction(JSONObject jObj) {
folders.add(parseFolder(jObj));
}
public void WriteAllToDatabaseNow() {
InsertIntoDatabase.InsertFoldersIntoDatabase(folders, dbConn);
}
}

View file

@ -0,0 +1,44 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.util.Date;
import org.json.JSONObject;
import de.luhmer.owncloudnewsreader.data.RssFile;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
public class InsertItemIntoDatabase implements IHandleJsonObject {
DatabaseConnection dbConn;
public InsertItemIntoDatabase(DatabaseConnection dbConn) {
this.dbConn = dbConn;
}
private static RssFile parseItem(JSONObject e)
{
Date date = new Date(e.optLong("pubDate") * 1000);
String content = e.optString("body");
content = content.replaceAll("<img[^>]*feedsportal.com.*>", "");
content = content.replaceAll("<img[^>]*statisches.auslieferung.commindo-media-ressourcen.de.*>", "");
content = content.replaceAll("<img[^>]*auslieferung.commindo-media-ressourcen.de.*>", "");
content = content.replaceAll("<img[^>]*rss.buysellads.com.*>", "");
return new RssFile(0, e.optString("id"),
e.optString("title"),
e.optString("url"), content,
!e.optBoolean("unread"), null,
e.optString("feedId"), null,
date, e.optBoolean("starred"),
e.optString("guid"), e.optString("guidHash"),
e.optString("lastModified"));
}
@Override
public void performAction(JSONObject jObj) {
RssFile rssFile = parseItem(jObj);
InsertIntoDatabase.InsertSingleFeedItemIntoDatabase(rssFile, dbConn);
}
}

View file

@ -1,7 +1,9 @@
package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -9,32 +11,27 @@ import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.data.ConcreteSubscribtionItem;
import de.luhmer.owncloudnewsreader.data.RssFile;
import com.google.gson.stream.JsonReader;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
public class OwnCloudReaderMethods {
public static String maxSizePerSync = "200";
public static int GetUpdatedItems(TAGS tag, Activity act, long lastSync) throws Exception
public static int GetUpdatedItems(TAGS tag, Activity act, long lastSync, API api) throws Exception
{
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(act);
//ArrayList<RssFile> rssFiles = new ArrayList<RssFile>();
List<NameValuePair> nVPairs = new ArrayList<NameValuePair>();
nVPairs.add(new BasicNameValuePair("batchSize", maxSizePerSync));
//nVPairs.add(new BasicNameValuePair("batchSize", maxSizePerSync));
if(tag.equals(TAGS.ALL_STARRED))
{
nVPairs.add(new BasicNameValuePair("type", "2"));
@ -47,31 +44,22 @@ public class OwnCloudReaderMethods {
}
nVPairs.add(new BasicNameValuePair("lastModified", String.valueOf(lastSync)));
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
String requestURL = oc_root_path + OwnCloudConstants.FEED_PATH_UPDATED_ITEMS + OwnCloudConstants.JSON_FORMAT;
JSONObject jsonObj = HttpJsonRequest.PerformJsonRequest(requestURL, nVPairs, username, password, act);
InputStream is = HttpJsonRequest.PerformJsonRequest(api.getItemUpdatedUrl(), nVPairs, api.getUsername(), api.getPassword(), act);
DatabaseConnection dbConn = new DatabaseConnection(act);
try
{
return parseItems(jsonObj, dbConn, act);
return readJsonStream(is, new InsertItemIntoDatabase(dbConn));
} finally {
dbConn.closeDatabase();
is.close();
}
//return rssFiles;
}
//"type": 1, // the type of the query (Feed: 0, Folder: 1, Starred: 2, All: 3)
public static int GetItems(TAGS tag, Activity act, String offset, boolean getRead, String id, String type) throws Exception
public static int GetItems(TAGS tag, Activity act, String offset, boolean getRead, String id, String type, API api) throws Exception
{
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(act);
//ArrayList<RssFile> rssFiles = new ArrayList<RssFile>();
List<NameValuePair> nVPairs = new ArrayList<NameValuePair>();
nVPairs.add(new BasicNameValuePair("batchSize", maxSizePerSync));
if(tag.equals(TAGS.ALL_STARRED))
@ -91,162 +79,142 @@ public class OwnCloudReaderMethods {
nVPairs.add(new BasicNameValuePair("getRead", "false"));
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
String requestURL = oc_root_path + OwnCloudConstants.FEED_PATH + OwnCloudConstants.JSON_FORMAT;
JSONObject jsonObj = HttpJsonRequest.PerformJsonRequest(requestURL, nVPairs, username, password, act);
InputStream is = HttpJsonRequest.PerformJsonRequest(api.getItemUrl(), nVPairs, api.getUsername(), api.getPassword(), act);
DatabaseConnection dbConn = new DatabaseConnection(act);
try
{
return parseItems(jsonObj, dbConn, act);
return readJsonStream(is, new InsertItemIntoDatabase(dbConn));
} finally {
dbConn.closeDatabase();
is.close();
}
//return rssFiles;
}
private static int parseItems(JSONObject jsonObj, DatabaseConnection dbConn, Context context)
public static int GetFolderTags(Activity act, API api) throws Exception
{
//ArrayList<RssFile> rssFiles = new ArrayList<RssFile>();
InputStream is = HttpJsonRequest.PerformJsonRequest(api.getFolderUrl(), null, api.getUsername(), api.getPassword(), act);
DatabaseConnection dbConn = new DatabaseConnection(act);
int result = 0;
try
{
InsertFolderIntoDatabase ifid = new InsertFolderIntoDatabase(dbConn);
result = readJsonStream(is, ifid);
ifid.WriteAllToDatabaseNow();
} finally {
dbConn.closeDatabase();
is.close();
}
return result;
}
public static int GetFeeds(Activity act, API api) throws Exception
{
InputStream inputStream = HttpJsonRequest.PerformJsonRequest(api.getFeedUrl() , null, api.getUsername(), api.getPassword(), act);
DatabaseConnection dbConn = new DatabaseConnection(act);
int result = 0;
try {
InsertFeedIntoDatabase ifid = new InsertFeedIntoDatabase(dbConn);
result = readJsonStream(inputStream, ifid);
ifid.WriteAllToDatabaseNow();
} finally {
dbConn.closeDatabase();
inputStream.close();
}
return result;
}
/**
* can parse json like {"items":[{"id":6782}]}
* @param in
* @param iJoBj
* @return
* @throws IOException
* @throws JSONException
*/
public static int readJsonStream(InputStream in, IHandleJsonObject iJoBj) throws IOException, JSONException {
int count = 0;
JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
reader.beginObject();
reader.nextName();
reader.beginArray();
while (reader.hasNext()) {
reader.beginObject();
//jsonObj = jsonObj.optJSONObject("ocs");
//jsonObj = jsonObj.optJSONObject("data");
JSONArray jsonArr = jsonObj.optJSONArray("items");
JSONObject e = getJSONObjectFromReader(reader);
if(jsonArr != null)
{
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject e = jsonArr.optJSONObject(i);
//rssFiles.add(parseItem(e));
RssFile rssFile = parseItem(e);
InsertIntoDatabase.InsertSingleFeedItemIntoDatabase(rssFile, dbConn);
//new AsyncTask_DownloadImages(rssFile.getDescription(), context).execute();
iJoBj.performAction(e);
reader.endObject();
count++;
}
}
reader.endArray();
reader.close();
return count;
//return rssFiles;
}
private static RssFile parseItem(JSONObject e)
/**
* can read json like {"version":"1.101"}
* @param in
* @param iJoBj
* @return
* @throws IOException
* @throws JSONException
*/
private static int readJsonStreamSimple(InputStream in, IHandleJsonObject iJoBj) throws IOException, JSONException {
int count = 0;
JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
reader.beginObject();
JSONObject e = getJSONObjectFromReader(reader);
iJoBj.performAction(e);
reader.endObject();
reader.close();
return count;
}
private static JSONObject getJSONObjectFromReader(JsonReader jsonReader) {
JSONObject jObj = new JSONObject();
try {
while(jsonReader.hasNext()) {
try {
jObj.put(jsonReader.nextName(), jsonReader.nextString());
} catch(Exception ex) {
//ex.printStackTrace();
jsonReader.skipValue();
}
}
return jObj;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static boolean PerformTagExecutionAPIv2(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api)
{
Date date = new Date(e.optLong("pubDate") * 1000);
String content = e.optString("body");
content = content.replaceAll("<img[^>]*feedsportal.com.*>", "");
content = content.replaceAll("<img[^>]*statisches.auslieferung.commindo-media-ressourcen.de.*>", "");
content = content.replaceAll("<img[^>]*auslieferung.commindo-media-ressourcen.de.*>", "");
content = content.replaceAll("<img[^>]*rss.buysellads.com.*>", "");
return new RssFile(0, e.optString("id"),
e.optString("title"),
e.optString("url"), content,
!e.optBoolean("unread"), null,
e.optString("feedId"), null,
date, e.optBoolean("starred"),
e.optString("guid"), e.optString("guidHash"),
e.optString("lastModified"));
}
public static ArrayList<String[]> GetFolderTags(Activity act) throws Exception
{
ArrayList<String[]> folderTags = null;
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(act);
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
if(oc_root_path.endsWith("/"))
oc_root_path = oc_root_path.substring(0, oc_root_path.length() - 1);
String requestUrl = oc_root_path + OwnCloudConstants.FOLDER_PATH + OwnCloudConstants.JSON_FORMAT;
JSONObject jsonObj = HttpJsonRequest.PerformJsonRequest(requestUrl, null, username, password, act);
//jsonObj = jsonObj.optJSONObject("ocs");
//jsonObj = jsonObj.optJSONObject("data");
JSONArray jsonArr = jsonObj.optJSONArray("folders");
folderTags = new ArrayList<String[]>();
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject e = jsonArr.optJSONObject(i);
folderTags.add(new String[] { e.optString("name"), e.optString("id") });
}
return folderTags;
}
public static ArrayList<ConcreteSubscribtionItem> GetSubscriptionTags(Activity act) throws Exception
{
ArrayList<ConcreteSubscribtionItem> subscriptionTags = new ArrayList<ConcreteSubscribtionItem>();
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(act);
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
JSONObject jsonObj = HttpJsonRequest.PerformJsonRequest(oc_root_path + OwnCloudConstants.SUBSCRIPTION_PATH + OwnCloudConstants.JSON_FORMAT, null, username, password, act);
//jsonObj = jsonObj.optJSONObject("ocs");
//jsonObj = jsonObj.optJSONObject("data");
JSONArray jsonArr = jsonObj.optJSONArray("feeds");
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject e = jsonArr.optJSONObject(i);
String faviconLink = e.optString("faviconLink");
if(faviconLink != null)
if(faviconLink.equals("null") || faviconLink.trim().equals(""))
faviconLink = null;
subscriptionTags.add(new ConcreteSubscribtionItem(e.optString("title"), e.optString("folderId"), e.optString("id"), faviconLink, -1));
}
return subscriptionTags;
}
public static boolean PerformTagExecution(List<String> itemIds, FeedItemTags.TAGS tag, Context context)
{
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
//List<NameValuePair> nameValuePairs = null;
String jsonIds = null;
String url = oc_root_path + OwnCloudConstants.FEED_PATH + "/";
String url = api.getTagBaseUrl();
if(tag.equals(TAGS.MARK_ITEM_AS_READ) || tag.equals(TAGS.MARK_ITEM_AS_UNREAD))
{
jsonIds = buildIdsToJSONArray(itemIds);
/*
if(jsonIds != null)
{
nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("itemIds", jsonIds));
}*/
//url += itemIds.get(0) + "/read";
if(tag.equals(TAGS.MARK_ITEM_AS_READ))
url += "read/multiple";
else
url += "unread/multiple";
}
//else if(tag.equals(TAGS.MARK_ITEM_AS_UNREAD))
// url += itemIds.get(0) + "/unread";//TODO HERE...
else
{
} else {
DatabaseConnection dbConn = new DatabaseConnection(context);
HashMap<String, String> items = new HashMap<String, String>();
@ -294,7 +262,7 @@ public class OwnCloudReaderMethods {
}
try
{
int result = HttpJsonRequest.performTagChangeRequest(url, username, password, context, jsonIds);
int result = HttpJsonRequest.performTagChangeRequest(url, api.getUsername(), api.getPassword(), context, jsonIds);
//if(result != -1 || result != 405)
if(result == 200)
return true;
@ -308,17 +276,81 @@ public class OwnCloudReaderMethods {
}
}
public static boolean PerformTagExecutionAPIv1(String itemId, FeedItemTags.TAGS tag, Context context, API api)
{
String url = api.getTagBaseUrl();
if(tag.equals(TAGS.MARK_ITEM_AS_READ) || tag.equals(TAGS.MARK_ITEM_AS_UNREAD))
{
if(tag.equals(TAGS.MARK_ITEM_AS_READ))
url += itemId + "/read";
else
url += itemId + "/unread";
} else {
DatabaseConnection dbConn = new DatabaseConnection(context);
Cursor cursor = dbConn.getArticleByID(dbConn.getRowIdOfFeedByItemID(itemId));
cursor.moveToFirst();
String idSubscription = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID));
String guidHash = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_GUIDHASH));
cursor.close();
String subscription_id = dbConn.getSubscriptionIdByRowID(idSubscription);
url += subscription_id;
dbConn.closeDatabase();
url += "/" + guidHash;
if(tag.equals(TAGS.MARK_ITEM_AS_STARRED))
url += "/star";
else if(tag.equals(TAGS.MARK_ITEM_AS_UNSTARRED))
url += "/unstar";
}
try
{
int result = HttpJsonRequest.performTagChangeRequest(url, api.getUsername(), api.getPassword(), context, null);
if(result == 200)
return true;
else
return false;
}
catch (Exception ex)
{
ex.printStackTrace();
return false;
}
}
public static String GetVersionNumber(Activity act, String username, String password, String oc_root_path) throws Exception
{
if(oc_root_path.endsWith("/"))
oc_root_path = oc_root_path.substring(0, oc_root_path.length() - 1);
String requestUrl = oc_root_path + OwnCloudConstants.VERSION_PATH;
JSONObject jsonObj = HttpJsonRequest.PerformJsonRequest(requestUrl, null, username, password, act);
return jsonObj.optString("version");
//Try APIv2
try {
String requestUrl = oc_root_path + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.VERSION_PATH;
InputStream is = HttpJsonRequest.PerformJsonRequest(requestUrl, null, username, password, act);
try {
GetVersion gv = new GetVersion();
readJsonStreamSimple(is, gv);
return gv.getVersion();
} finally {
is.close();
}
} catch(Exception ex) { //TODO GET HERE THE RIGHT EXCEPTION
String requestUrl = oc_root_path + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.VERSION_PATH;
InputStream is = HttpJsonRequest.PerformJsonRequest(requestUrl, null, username, password, act);
try {
GetVersion gv = new GetVersion();
readJsonStreamSimple(is, gv);
return gv.getVersion();
} finally {
is.close();
}
}
}
private static String buildIdsToJSONArray(List<String> ids)
@ -355,7 +387,6 @@ public class OwnCloudReaderMethods {
jArr.put(jOb);
}
JSONObject jObj = new JSONObject();
jObj.put("items", jArr);

View file

@ -3,7 +3,6 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.util.SparseArray;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
@ -12,6 +11,7 @@ import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
public class OwnCloud_Reader implements IReader {
boolean isSyncRunning = false;
private API api = null;
SparseArray<AsyncTask_Reader> AsyncTasksRunning;
@ -49,12 +49,19 @@ public class OwnCloud_Reader implements IReader {
@Override
public void Start_AsyncTask_PerformTagAction(int task_id,
Context context, OnAsyncTaskCompletedListener listener,
Activity context, OnAsyncTaskCompletedListener listener,
List<String> itemIds, FeedItemTags.TAGS tag) {
setSyncRunning(true);
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_PerformTagAction(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener } ).execute(itemIds, tag));
}
public void Start_AsyncTask_GetVersion(int task_id,
Activity context, OnAsyncTaskCompletedListener listener, String username, String password) {
setSyncRunning(true);
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_GetApiVersion(task_id, context, username, password, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener } ).execute());
}
@Override
public void Start_AsyncTask_Authenticate(int task_id, Activity context,
OnAsyncTaskCompletedListener listener) {
@ -62,9 +69,9 @@ public class OwnCloud_Reader implements IReader {
}
@Override
public void onAsyncTaskCompleted(int task_id, Object task_result) {
// TODO Auto-generated method stub
}
@ -98,5 +105,11 @@ public class OwnCloud_Reader implements IReader {
AsyncTasksRunning.get(task_id).attach(activity, new OnAsyncTaskCompletedListener[] { listener, AsyncTask_finished });
}
public API getApi() {
return api;
}
public void setApi(API api) {
this.api = api;
}
}

View file

@ -1,9 +1,15 @@
package de.luhmer.owncloudnewsreader.reader.owncloud.apiv1;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
public class APIv1 extends API {
@ -46,7 +52,17 @@ public class APIv1 extends API {
}
@Override
public void markSingleItemAsReadApiv1() {
public boolean PerformTagExecution(List<String> itemIds, TAGS tag,
Context context, API api) {
List<Boolean> succeeded = new ArrayList<Boolean>();
for(String item : itemIds) {
succeeded.add(OwnCloudReaderMethods.PerformTagExecutionAPIv1(item, tag, context, api));
}
if(succeeded.contains(false))
return false;
else
return true;
}
}

View file

@ -1,9 +1,14 @@
package de.luhmer.owncloudnewsreader.reader.owncloud.apiv2;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
public class APIv2 extends API {
@ -46,6 +51,8 @@ public class APIv2 extends API {
}
@Override
public void markSingleItemAsReadApiv1() {
public boolean PerformTagExecution(List<String> itemIds, TAGS tag,
Context context, API api) {
return OwnCloudReaderMethods.PerformTagExecutionAPIv2(itemIds, tag, context, api);
}
}