Merge pull request #409 from schaal/sync-optimizations
Sync optimizations
This commit is contained in:
commit
c1313d4762
23 changed files with 386 additions and 448 deletions
|
@ -64,6 +64,7 @@ dependencies {
|
|||
compile 'com.google.code.gson:gson:2.3.1'
|
||||
compile 'com.jakewharton:butterknife:5.1.+'
|
||||
compile 'com.sothree.slidinguppanel:library:3.1.1'
|
||||
compile 'com.squareup.okhttp:okhttp:2.5.0'
|
||||
compile 'de.greenrobot:eventbus:2.2.1'
|
||||
compile 'de.greenrobot:greendao:2.0.0'
|
||||
compile 'de.greenrobot:greendao-generator:2.0.0'
|
||||
|
|
|
@ -55,6 +55,7 @@ import de.luhmer.owncloud.accountimporter.helper.OwnCloudAccount;
|
|||
import de.luhmer.owncloud.accountimporter.interfaces.IAccountImport;
|
||||
import de.luhmer.owncloudnewsreader.authentication.AuthenticatorActivity;
|
||||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
|
||||
|
||||
/**
|
||||
|
@ -316,7 +317,8 @@ public class LoginDialogFragment extends DialogFragment implements IAccountImpor
|
|||
protected Integer doInBackground(Void... params) {
|
||||
|
||||
try {
|
||||
String _version = OwnCloudReaderMethods.GetVersionNumber(getActivity(), username, password, oc_root_path);
|
||||
HttpJsonRequest.getInstance().setCredentials(username, password, oc_root_path);
|
||||
String _version = OwnCloudReaderMethods.GetVersionNumber(getActivity(), oc_root_path);
|
||||
if(_version != null)
|
||||
{
|
||||
_version = _version.replace(".", "");
|
||||
|
|
|
@ -218,10 +218,7 @@ public class NewFeedActivity extends AppCompatActivity {
|
|||
API api = new APIv2(NewFeedActivity.this);
|
||||
|
||||
try {
|
||||
int status = HttpJsonRequest.performCreateFeedRequest(api.getFeedUrl(),
|
||||
api.getUsername(),
|
||||
api.getPassword(),
|
||||
NewFeedActivity.this,
|
||||
int status = HttpJsonRequest.getInstance().performCreateFeedRequest(api.getFeedUrl(),
|
||||
mUrlToFeed, mFolderId);
|
||||
|
||||
if(status == 200) {
|
||||
|
|
|
@ -9,6 +9,9 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
|
||||
import de.luhmer.owncloudnewsreader.reader.OkHttpImageDownloader;
|
||||
|
||||
/**
|
||||
* Created by daniel on 12.07.15.
|
||||
*/
|
||||
|
@ -16,6 +19,7 @@ public class NewsReaderApplication extends Application {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
HttpJsonRequest.init(this);
|
||||
initImageLoader();
|
||||
}
|
||||
|
||||
|
@ -33,6 +37,7 @@ public class NewsReaderApplication extends Application {
|
|||
memoryCacheSize(10 * 1024 * 1024).
|
||||
diskCacheFileNameGenerator(new Md5FileNameGenerator()).
|
||||
defaultDisplayImageOptions(imageOptions).
|
||||
imageDownloader(new OkHttpImageDownloader(this, HttpJsonRequest.getInstance().getImageClient())).
|
||||
build();
|
||||
ImageLoader.getInstance().init(config);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,6 @@ import de.luhmer.owncloudnewsreader.helper.AidlException;
|
|||
import de.luhmer.owncloudnewsreader.helper.DatabaseUtils;
|
||||
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
|
||||
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
|
||||
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;
|
||||
|
@ -111,7 +110,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
|||
|
||||
private static MenuItem menuItemUpdater;
|
||||
private static MenuItem menuItemDownloadMoreItems;
|
||||
private static IReader _Reader;
|
||||
private static OwnCloud_Reader _Reader;
|
||||
|
||||
//private Date mLastSyncDate = new Date(0);
|
||||
private boolean mSyncOnStartupPerformed = false;
|
||||
|
@ -794,7 +793,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
|||
|
||||
if(username != null) {
|
||||
_Reader = new OwnCloud_Reader();
|
||||
((OwnCloud_Reader)_Reader).Start_AsyncTask_GetVersion(Constants.TaskID_GetVersion, this, onAsyncTaskGetVersionFinished, username, password);
|
||||
_Reader.Start_AsyncTask_GetVersion(this, onAsyncTaskGetVersionFinished);
|
||||
|
||||
Toast.makeText(this, getString(R.string.toast_GettingMoreItems), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -807,10 +806,10 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
|||
if(_Reader != null) {
|
||||
String appVersion = task_result.toString();
|
||||
API api = API.GetRightApiForVersion(appVersion, NewsReaderListActivity.this);
|
||||
((OwnCloud_Reader) _Reader).setApi(api);
|
||||
_Reader.setApi(api);
|
||||
|
||||
NewsReaderDetailFragment ndf = getNewsReaderDetailFragment();
|
||||
_Reader.Start_AsyncTask_GetOldItems(Constants.TaskID_GetItems, NewsReaderListActivity.this, onAsyncTaskComplete, ndf.getIdFeed(), ndf.getIdFolder());
|
||||
_Reader.Start_AsyncTask_GetOldItems(NewsReaderListActivity.this, onAsyncTaskComplete, ndf.getIdFeed(), ndf.getIdFolder());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,7 +21,22 @@
|
|||
|
||||
package de.luhmer.owncloudnewsreader.reader;
|
||||
|
||||
public class FeedItemTags {
|
||||
public enum TAGS { MARK_ITEM_AS_READ, MARK_ITEM_AS_UNREAD, MARK_ITEM_AS_STARRED, MARK_ITEM_AS_UNSTARRED, ALL_STARRED, ALL };
|
||||
|
||||
public enum FeedItemTags {
|
||||
MARK_ITEM_AS_READ("read"),
|
||||
MARK_ITEM_AS_UNREAD("unread"),
|
||||
MARK_ITEM_AS_STARRED("star"),
|
||||
MARK_ITEM_AS_UNSTARRED("unstar"),
|
||||
ALL_STARRED("2"),
|
||||
ALL("3");
|
||||
|
||||
private String segment;
|
||||
|
||||
FeedItemTags(String segment) {
|
||||
this.segment = segment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.segment;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,27 +21,29 @@
|
|||
|
||||
package de.luhmer.owncloudnewsreader.reader;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nostra13.universalimageloader.core.download.ImageDownloader;
|
||||
import com.squareup.okhttp.Credentials;
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
|
@ -51,32 +53,104 @@ import de.luhmer.owncloudnewsreader.ssl.MemorizingTrustManager;
|
|||
import de.luhmer.owncloudnewsreader.ssl.TLSSocketFactory;
|
||||
|
||||
public class HttpJsonRequest {
|
||||
//private static final String TAG = "HttpJsonRequest";
|
||||
private static final String TAG = "HttpJsonRequest";
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static InputStream PerformJsonRequest(String urlString, HashMap<String,String> nameValuePairs, final String username, final String password, Context context) throws Exception
|
||||
{
|
||||
if(nameValuePairs != null) {
|
||||
urlString += getUrlEncodedString(nameValuePairs);
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
private static HttpJsonRequest instance;
|
||||
|
||||
public static void init(Context context) {
|
||||
if(instance != null)
|
||||
throw new IllegalStateException("Already initialized");
|
||||
instance = new HttpJsonRequest(context);
|
||||
}
|
||||
|
||||
public static HttpJsonRequest getInstance() {
|
||||
if(instance == null)
|
||||
throw new IllegalStateException("Must be initialized first");
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final OkHttpClient client;
|
||||
private final OkHttpClient imageClient;
|
||||
|
||||
private String credentials;
|
||||
private HttpUrl oc_root_url;
|
||||
|
||||
private HttpJsonRequest(Context context) {
|
||||
client = new OkHttpClient();
|
||||
|
||||
// set location of the keystore
|
||||
MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks");
|
||||
|
||||
// register MemorizingTrustManager for HTTPS
|
||||
try {
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, MemorizingTrustManager.getInstanceList(context),
|
||||
new java.security.SecureRandom());
|
||||
// enables TLSv1.1/1.2 for Jelly Bean Devices
|
||||
TLSSocketFactory tlsSocketFactory = new TLSSocketFactory(sc);
|
||||
client.setSslSocketFactory(tlsSocketFactory);
|
||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
URL url = new URL(API.validateURL(urlString));
|
||||
client.setConnectTimeout(10000, TimeUnit.MILLISECONDS);
|
||||
client.setReadTimeout(120, TimeUnit.SECONDS);
|
||||
|
||||
HttpURLConnection urlConnection = getUrlConnection(url, context, username, password);
|
||||
//HttpsURLConnection urlConnection = null;
|
||||
// disable hostname verification, when preference is set
|
||||
// (this still shows a certification dialog, which requires user interaction!)
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if(sp.getBoolean(SettingsActivity.CB_DISABLE_HOSTNAME_VERIFICATION_STRING, false))
|
||||
client.setHostnameVerifier(new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
imageClient = client.clone();
|
||||
client.interceptors().add(new AuthorizationInterceptor());
|
||||
|
||||
setCredentials(sp.getString(SettingsActivity.EDT_USERNAME_STRING, null), sp.getString(SettingsActivity.EDT_PASSWORD_STRING, null), sp.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null));
|
||||
}
|
||||
|
||||
// Define an array of pins. One of these must be present
|
||||
// in the certificate chain you receive. A pin is a hex-encoded
|
||||
// hash of a X.509 certificate's SubjectPublicKeyInfo. A pin can
|
||||
// be generated using the provided pin.py script:
|
||||
// python ./tools/pin.py certificate_file.pem
|
||||
public void setCredentials(final String username, final String password, final String oc_root_path) {
|
||||
if(username != null)
|
||||
credentials = Credentials.basic(username, password);
|
||||
else
|
||||
credentials = null;
|
||||
|
||||
if(oc_root_path != null)
|
||||
oc_root_url = HttpUrl.parse(oc_root_path);
|
||||
}
|
||||
|
||||
//String[] pins = new String[] {"f30012bbc18c231ac1a44b788e410ce754182513"};
|
||||
//HttpsURLConnection urlConnection = PinningHelper.getPinnedHttpsURLConnection(context, pins, url);
|
||||
private class AuthorizationInterceptor implements Interceptor {
|
||||
public AuthorizationInterceptor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
|
||||
// only add Authorization header for urls on the configured owncloud host
|
||||
if(oc_root_url.host().equals(request.httpUrl().host()))
|
||||
request = request.newBuilder()
|
||||
.addHeader("Authorization",credentials)
|
||||
.build();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
}
|
||||
|
||||
public OkHttpClient getImageClient() {
|
||||
return imageClient;
|
||||
}
|
||||
|
||||
public InputStream PerformJsonRequest(HttpUrl url) throws Exception
|
||||
{
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.build();
|
||||
|
||||
//http://nelenkov.blogspot.de/2011/12/using-custom-certificate-trust-store-on.html
|
||||
//http://stackoverflow.com/questions/5947162/https-and-self-signed-certificate-issue
|
||||
|
@ -84,126 +158,43 @@ public class HttpJsonRequest {
|
|||
//http://stackoverflow.com/questions/859111/how-do-i-accept-a-self-signed-certificate-with-a-java-httpsurlconnection
|
||||
//http://developer.android.com/training/articles/security-ssl.html
|
||||
|
||||
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");
|
||||
|
||||
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
|
||||
// CookieHandler.setDefault(new CookieManager());
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0");
|
||||
//urlConnection.setRequestProperty("Host", "de.luhmer.ownCloudNewsReader");
|
||||
urlConnection.connect();
|
||||
|
||||
int HttpResult = urlConnection.getResponseCode();
|
||||
if(HttpResult == HttpURLConnection.HTTP_OK) {
|
||||
return urlConnection.getInputStream();
|
||||
if(response.isSuccessful()) {
|
||||
return response.body().byteStream();
|
||||
} else {
|
||||
throw new Exception(urlConnection.getResponseMessage());
|
||||
throw new Exception(response.message());
|
||||
}
|
||||
}
|
||||
|
||||
private static String getUrlEncodedString(HashMap<String, String> nameValuePairs) throws UnsupportedEncodingException {
|
||||
String urlString = "";
|
||||
for(Entry<String,String> entry: nameValuePairs.entrySet()) {
|
||||
urlString += String.format("&%s=%s", URLEncoder.encode(entry.getKey(), "UTF-8"), URLEncoder.encode(entry.getValue(), "UTF-8"));
|
||||
}
|
||||
return urlString;
|
||||
public int performCreateFeedRequest(HttpUrl url, String feedUrlString, long folderId) throws Exception {
|
||||
HttpUrl feedUrl = url.newBuilder()
|
||||
.setQueryParameter("url", feedUrlString)
|
||||
.setQueryParameter("folderId", String.valueOf(folderId))
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(feedUrl)
|
||||
.post(RequestBody.create(JSON, ""))
|
||||
.build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
return response.code();
|
||||
}
|
||||
|
||||
|
||||
private static HttpURLConnection getUrlConnection(URL url, Context context, String username, String password) throws IOException, KeyManagementException, NoSuchAlgorithmException {
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
|
||||
// If https is used, use MemorizingTrustManager for certificate verification
|
||||
if (urlConnection instanceof HttpsURLConnection) {
|
||||
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) urlConnection;
|
||||
|
||||
// set location of the keystore
|
||||
MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks");
|
||||
|
||||
// register MemorizingTrustManager for HTTPS
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, MemorizingTrustManager.getInstanceList(context),
|
||||
new java.security.SecureRandom());
|
||||
|
||||
// enables TLSv1.1/1.2 for Jelly Bean Devices
|
||||
TLSSocketFactory tlsSocketFactory = new TLSSocketFactory(sc);
|
||||
|
||||
httpsURLConnection.setSSLSocketFactory(tlsSocketFactory);
|
||||
|
||||
|
||||
// disable redirects to reduce possible confusion
|
||||
//httpsURLConnection.setFollowRedirects(false);
|
||||
|
||||
// disable hostname verification, when preference is set
|
||||
// (this still shows a certification dialog, which requires user interaction!)
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if(sp.getBoolean(SettingsActivity.CB_DISABLE_HOSTNAME_VERIFICATION_STRING, false))
|
||||
httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
else
|
||||
httpsURLConnection.setHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier());
|
||||
}
|
||||
|
||||
if(username != null && password != null) {
|
||||
urlConnection.setRequestProperty("Authorization", "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP));
|
||||
}
|
||||
|
||||
return (HttpURLConnection) urlConnection;
|
||||
}
|
||||
|
||||
public static int performCreateFeedRequest(String urlString, String username, String password, Context context, String feedUrl, long folderId) throws Exception {
|
||||
HashMap<String,String> nameValuePairs = new HashMap<>();
|
||||
nameValuePairs.put("url", feedUrl);
|
||||
nameValuePairs.put("folderId", String.valueOf(folderId));
|
||||
urlString += getUrlEncodedString(nameValuePairs);
|
||||
|
||||
|
||||
URL url = new URL(API.validateURL(urlString));
|
||||
HttpURLConnection urlConnection = getUrlConnection(url, context, username, password);
|
||||
urlConnection.setRequestMethod("POST");
|
||||
urlConnection.setDoOutput(false);
|
||||
urlConnection.setDoInput(true);
|
||||
//urlConnection.setFollowRedirects(true);
|
||||
urlConnection.setUseCaches(false);
|
||||
urlConnection.setConnectTimeout(10000);
|
||||
urlConnection.setReadTimeout(120000);//2min
|
||||
urlConnection.setRequestProperty("Content-Type","application/json");
|
||||
|
||||
|
||||
urlConnection.connect();
|
||||
|
||||
return urlConnection.getResponseCode();
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static int performTagChangeRequest(String urlString, String username, String password, Context context, String content) throws Exception
|
||||
public int performTagChangeRequest(HttpUrl url, String content) throws Exception
|
||||
{
|
||||
URL url = new URL(API.validateURL(urlString));
|
||||
HttpURLConnection urlConnection = getUrlConnection(url, context, username, password);
|
||||
urlConnection.setDoOutput(true);
|
||||
urlConnection.setRequestMethod("PUT");
|
||||
urlConnection.setRequestProperty("Content-Type","application/json");
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.put(RequestBody.create(JSON, content))
|
||||
.build();
|
||||
|
||||
if(content != null) {
|
||||
OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
|
||||
out.write(content);
|
||||
out.close();
|
||||
}
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
return urlConnection.getResponseCode();
|
||||
return response.code();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* Android ownCloud News
|
||||
*
|
||||
* @author David Luhmer
|
||||
* @copyright 2013 David Luhmer david-dev@live.de
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package de.luhmer.owncloudnewsreader.reader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
|
||||
public interface IReader {
|
||||
public boolean isSyncRunning();
|
||||
public void setSyncRunning(boolean status);
|
||||
|
||||
public SparseArray<AsyncTask_Reader> getRunningAsyncTasks();
|
||||
public void attachToRunningTask(int task_id, Activity activity, OnAsyncTaskCompletedListener listener);
|
||||
|
||||
public void Start_AsyncTask_GetItems(final int task_id, final Context context, final OnAsyncTaskCompletedListener listener, FeedItemTags.TAGS tag);
|
||||
public void Start_AsyncTask_GetOldItems(final int task_id, final Context context, final OnAsyncTaskCompletedListener listener, Long feed_id, Long folder_id);
|
||||
|
||||
public void Start_AsyncTask_GetFolder(final int task_id, final Context context, final OnAsyncTaskCompletedListener listener);
|
||||
public void Start_AsyncTask_GetFeeds(final int task_id, final Context context, final OnAsyncTaskCompletedListener listener);
|
||||
public void Start_AsyncTask_PerformItemStateChange(final int task_id, final Context context, final OnAsyncTaskCompletedListener listener);
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package de.luhmer.owncloudnewsreader.reader;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
|
||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.ResponseBody;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Created by daniel on 19.09.15.
|
||||
*/
|
||||
public class OkHttpImageDownloader extends BaseImageDownloader {
|
||||
private static final String TAG = "OkHttpImageDownloader";
|
||||
|
||||
private OkHttpClient imageClient;
|
||||
|
||||
public OkHttpImageDownloader(Context context, OkHttpClient imageClient) {
|
||||
super(context);
|
||||
this.imageClient = imageClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
|
||||
HttpUrl httpUrl = HttpUrl.parse(imageUri);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(httpUrl)
|
||||
.build();
|
||||
|
||||
ResponseBody responseBody = imageClient.newCall(request).execute().body();
|
||||
InputStream inputStream = responseBody.byteStream();
|
||||
|
||||
return new ContentLengthInputStream(inputStream, (int) responseBody.contentLength());
|
||||
}
|
||||
}
|
|
@ -24,21 +24,22 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.SettingsActivity;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
|
||||
|
||||
public abstract class API {
|
||||
protected SharedPreferences mPrefs;
|
||||
//static final Pattern RemoveAllDoubleSlashes = Pattern.compile("[^:](\\/\\/)");
|
||||
static final Pattern RemoveAllDoubleSlashes = Pattern.compile("(?<!:)\\/\\/");
|
||||
|
||||
|
||||
public API(Context cont) {
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(cont);
|
||||
|
@ -83,57 +84,40 @@ public abstract class API {
|
|||
return api;
|
||||
}
|
||||
|
||||
protected abstract String getItemUrl();
|
||||
protected abstract String getItemUpdatedUrl();
|
||||
public abstract String getFeedUrl();
|
||||
protected abstract String getFolderUrl();
|
||||
public abstract HttpUrl getItemUrl();
|
||||
public abstract HttpUrl getItemUpdatedUrl();
|
||||
public abstract HttpUrl getFeedUrl();
|
||||
public abstract HttpUrl getFolderUrl();
|
||||
|
||||
protected abstract String getTagBaseUrl();
|
||||
public abstract HttpUrl getTagBaseUrl();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return http(s)://url_to_server
|
||||
*/
|
||||
protected String getOcRootPath() {
|
||||
protected HttpUrl getAPIUrl(String format, String... urlSegments) {
|
||||
String oc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "");
|
||||
oc_root_path = RemoveAllDoubleSlashes.matcher(oc_root_path).replaceAll("/");
|
||||
HttpUrl basePath = HttpUrl.parse(oc_root_path);
|
||||
|
||||
//if(!oc_root_path.endsWith("/"))
|
||||
// oc_root_path += "/";
|
||||
//while(oc_root_path.endsWith("/"))
|
||||
// oc_root_path += oc_root_path.substring(0, oc_root_path.length() - 2);
|
||||
HttpUrl.Builder apiUrlBuilder = basePath.resolve(StringUtils.join(urlSegments, "/")).newBuilder();
|
||||
|
||||
return oc_root_path;
|
||||
if(format != null)
|
||||
apiUrlBuilder.addQueryParameter("format", format);
|
||||
|
||||
return apiUrlBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
return mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null);
|
||||
public int[] GetFeeds(Context cont) throws Exception {
|
||||
return OwnCloudReaderMethods.GetFeeds(cont, this);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, null);
|
||||
public int GetFolderTags(Context cont) throws Exception {
|
||||
return OwnCloudReaderMethods.GetFolderTags(cont, this);
|
||||
}
|
||||
|
||||
public int[] GetFeeds(Context cont, API api) throws Exception {
|
||||
return OwnCloudReaderMethods.GetFeeds(cont, api);
|
||||
public int GetItems(FeedItemTags tag, Context cont, String offset, boolean getRead, int id, String type) throws Exception {
|
||||
return OwnCloudReaderMethods.GetItems(tag, cont, offset, getRead, String.valueOf(id), type, this);
|
||||
}
|
||||
|
||||
public int GetFolderTags(Context cont, API api) throws Exception {
|
||||
return OwnCloudReaderMethods.GetFolderTags(cont, api);
|
||||
public int[] GetUpdatedItems(FeedItemTags tag, Context cont, long lastSync) throws Exception {
|
||||
return OwnCloudReaderMethods.GetUpdatedItems(tag, cont, lastSync, this);
|
||||
}
|
||||
|
||||
public int GetItems(TAGS tag, Context cont, String offset, boolean getRead, int id, String type, API api) throws Exception {
|
||||
return OwnCloudReaderMethods.GetItems(tag, cont, offset, getRead, String.valueOf(id), type, api);
|
||||
}
|
||||
|
||||
public int[] GetUpdatedItems(TAGS tag, Context cont, long lastSync, API api) throws Exception {
|
||||
return OwnCloudReaderMethods.GetUpdatedItems(tag, cont, lastSync, api);
|
||||
}
|
||||
|
||||
public static String validateURL(String url) {
|
||||
return RemoveAllDoubleSlashes.matcher(url).replaceAll("/");
|
||||
}
|
||||
|
||||
public abstract boolean PerformTagExecution(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api);
|
||||
public abstract boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag, Context context);
|
||||
}
|
|
@ -25,20 +25,14 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
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 Context context, String username, String password, final OnAsyncTaskCompletedListener[] listener) {
|
||||
super(task_id, context, listener);
|
||||
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
public AsyncTask_GetApiVersion(final Context context, final OnAsyncTaskCompletedListener[] listener) {
|
||||
super(Constants.TaskID_GetVersion, context, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +40,7 @@ public class AsyncTask_GetApiVersion extends AsyncTask_Reader {
|
|||
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);
|
||||
return OwnCloudReaderMethods.GetVersionNumber(context, oc_root_path);
|
||||
} catch (Exception ex) {
|
||||
return ex;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
|
||||
|
@ -30,8 +31,8 @@ public class AsyncTask_GetFeeds extends AsyncTask_Reader {
|
|||
|
||||
private API api;
|
||||
|
||||
public AsyncTask_GetFeeds(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(task_id, context, listener);
|
||||
public AsyncTask_GetFeeds(final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(Constants.TaskID_GetFeeds, context, listener);
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,7 @@ public class AsyncTask_GetFeeds extends AsyncTask_Reader {
|
|||
protected Exception doInBackground(Object... params) {
|
||||
|
||||
try {
|
||||
api.GetFeeds(context, api);
|
||||
api.GetFeeds(context);
|
||||
} catch (Exception ex) {
|
||||
return ex;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
|
||||
|
@ -30,8 +31,8 @@ public class AsyncTask_GetFolderTags extends AsyncTask_Reader {
|
|||
|
||||
private API api;
|
||||
|
||||
public AsyncTask_GetFolderTags(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(task_id, context, listener);
|
||||
public AsyncTask_GetFolderTags(final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(Constants.TaskID_GetFolder, context, listener);
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
|
@ -40,7 +41,7 @@ public class AsyncTask_GetFolderTags extends AsyncTask_Reader {
|
|||
|
||||
try {
|
||||
//OwnCloudReaderMethods.GetFolderTags(context, api);
|
||||
api.GetFolderTags(context, api);
|
||||
api.GetFolderTags(context);
|
||||
} catch(Exception ex) {
|
||||
return ex;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import de.luhmer.owncloudnewsreader.SettingsActivity;
|
|||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
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.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
import de.luhmer.owncloudnewsreader.services.DownloadImagesService;
|
||||
|
||||
|
@ -49,8 +49,8 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
|
|||
private API api;
|
||||
int totalCount;
|
||||
|
||||
public AsyncTask_GetItems(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(task_id, context, listener);
|
||||
public AsyncTask_GetItems(final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(Constants.TaskID_GetItems, context, listener);
|
||||
this.api = api;
|
||||
|
||||
totalCount = 0;
|
||||
|
@ -92,7 +92,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
|
|||
int maxItemsInDatabase = Constants.maxItemsCount;
|
||||
|
||||
do {
|
||||
requestCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), false, 0, "3", api);
|
||||
requestCount = api.GetItems(FeedItemTags.ALL, context, String.valueOf(offset), false, 0, "3");
|
||||
if(requestCount > 0)
|
||||
offset = dbConn.getLowestItemId(false);
|
||||
totalCount += requestCount;
|
||||
|
@ -104,7 +104,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
|
|||
|
||||
do {
|
||||
offset = dbConn.getLowestItemId(true);
|
||||
requestCount = api.GetItems(TAGS.ALL_STARRED, context, String.valueOf(offset), true, 0, "2", api);
|
||||
requestCount = api.GetItems(FeedItemTags.ALL_STARRED, context, String.valueOf(offset), true, 0, "2");
|
||||
//if(requestCount > 0)
|
||||
// offset = dbConn.getLowestItemId(true);
|
||||
totalCount += requestCount;
|
||||
|
@ -115,7 +115,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
|
|||
//First reset the count of last updated items
|
||||
mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0).commit();
|
||||
//Get all updated items
|
||||
int[] result = api.GetUpdatedItems(TAGS.ALL, context, lastModified + 1, api);
|
||||
int[] result = api.GetUpdatedItems(FeedItemTags.ALL, context, lastModified + 1);
|
||||
//If no exception occurs, set the number of updated items
|
||||
mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, result[1]).commit();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
|
|||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderDetailFragment;
|
||||
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
|
||||
|
@ -31,7 +32,7 @@ import de.luhmer.owncloudnewsreader.R;
|
|||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.database.model.RssItem;
|
||||
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
|
||||
public class AsyncTask_GetOldItems extends AsyncTask_Reader {
|
||||
|
@ -42,8 +43,8 @@ public class AsyncTask_GetOldItems extends AsyncTask_Reader {
|
|||
private int downloadedItemsCount = 0;
|
||||
private API api;
|
||||
|
||||
public AsyncTask_GetOldItems(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener, Long feed_id, Long folder_id, API api) {
|
||||
super(task_id, context, listener);
|
||||
public AsyncTask_GetOldItems(final Context context, final OnAsyncTaskCompletedListener[] listener, Long feed_id, Long folder_id, API api) {
|
||||
super(Constants.TaskID_GetItems, context, listener);
|
||||
|
||||
this.feed_id = feed_id;
|
||||
this.folder_id = folder_id;
|
||||
|
@ -82,7 +83,7 @@ public class AsyncTask_GetOldItems extends AsyncTask_Reader {
|
|||
}
|
||||
|
||||
|
||||
downloadedItemsCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), true, id.intValue(), type, api);
|
||||
downloadedItemsCount = api.GetItems(FeedItemTags.ALL, context, String.valueOf(offset), true, id.intValue(), type);
|
||||
|
||||
/*
|
||||
int totalCount = dbConn.getCountOfAllItems(false);
|
||||
|
|
|
@ -26,17 +26,18 @@ import android.content.Context;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
|
||||
public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
|
||||
{
|
||||
private API api;
|
||||
|
||||
public AsyncTask_PerformItemStateChange(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(task_id, context, listener);
|
||||
public AsyncTask_PerformItemStateChange(final Context context, final OnAsyncTaskCompletedListener[] listener, API api) {
|
||||
super(Constants.TaskID_PerformStateChange, context, listener);
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
|
@ -49,28 +50,28 @@ public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
|
|||
|
||||
//Mark as READ
|
||||
List<String> itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewReadRssItems());
|
||||
boolean result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_READ, context, api);
|
||||
boolean result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_READ, context);
|
||||
if(result)
|
||||
dbConn.change_readUnreadStateOfItem(itemIds, true);
|
||||
succeeded.add(result);
|
||||
|
||||
//Mark as UNREAD
|
||||
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnreadRssItems());
|
||||
result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_UNREAD, context, api);
|
||||
result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNREAD, context);
|
||||
if(result)
|
||||
dbConn.change_readUnreadStateOfItem(itemIds, false);
|
||||
succeeded.add(result);
|
||||
|
||||
//Mark as STARRED
|
||||
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewStarredRssItems());
|
||||
result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_STARRED, context, api);
|
||||
result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_STARRED, context);
|
||||
if(result)
|
||||
dbConn.change_starrUnstarrStateOfItem(itemIds, true);
|
||||
succeeded.add(result);
|
||||
|
||||
//Mark as UNSTARRED
|
||||
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnstarredRssItems());
|
||||
result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_UNSTARRED, context, api);
|
||||
result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNSTARRED, context);
|
||||
if(result)
|
||||
dbConn.change_starrUnstarrStateOfItem(itemIds, false);
|
||||
succeeded.add(result);
|
||||
|
|
|
@ -24,12 +24,12 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
|
|||
public class OwnCloudConstants {
|
||||
|
||||
//public static final String ROOT_PATH = "/ocs/v1.php/apps/news/";
|
||||
public static final String ROOT_PATH_APIv1 = "/ocs/v1.php/apps/news/";
|
||||
public static final String ROOT_PATH_APIv2 = "/index.php/apps/news/api/v1-2/";
|
||||
public static final String ROOT_PATH_APIv1 = "/ocs/v1.php/apps/news";
|
||||
public static final String ROOT_PATH_APIv2 = "/index.php/apps/news/api/v1-2";
|
||||
public static final String FOLDER_PATH = "folders";
|
||||
public static final String SUBSCRIPTION_PATH = "feeds";
|
||||
public static final String FEED_PATH = "items";
|
||||
public static final String FEED_PATH_UPDATED_ITEMS = "items/updated";
|
||||
public static final String VERSION_PATH = "version";
|
||||
public static final String JSON_FORMAT = "?format=json";
|
||||
public static final String JSON_FORMAT = "json";
|
||||
}
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
package de.luhmer.owncloudnewsreader.reader.owncloud;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -41,33 +43,26 @@ import java.util.Map;
|
|||
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
|
||||
import de.luhmer.owncloudnewsreader.database.model.RssItem;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
|
||||
|
||||
public class OwnCloudReaderMethods {
|
||||
//private static final String TAG = "OwnCloudReaderMethods";
|
||||
private static final String TAG = "OwnCloudReaderMethods";
|
||||
public static String maxSizePerSync = "300";
|
||||
|
||||
public static int[] GetUpdatedItems(TAGS tag, Context cont, long lastSync, API api) throws Exception
|
||||
public static int[] GetUpdatedItems(FeedItemTags tag, Context cont, long lastSync, API api) throws Exception
|
||||
{
|
||||
HashMap<String,String> nVPairs = new HashMap<>();
|
||||
//nVPairs.put("batchSize", maxSizePerSync));
|
||||
if(tag.equals(TAGS.ALL_STARRED))
|
||||
HttpUrl.Builder getItemUpdatedUrlBuilder = api.getItemUpdatedUrl().newBuilder();
|
||||
if(tag.equals(FeedItemTags.ALL_STARRED) || tag.equals(FeedItemTags.ALL))
|
||||
{
|
||||
nVPairs.put("type", "2");
|
||||
nVPairs.put("id", "0");
|
||||
getItemUpdatedUrlBuilder.addQueryParameter("type", tag.toString())
|
||||
.addQueryParameter("id", "0");
|
||||
}
|
||||
else if(tag.equals(TAGS.ALL))
|
||||
{
|
||||
nVPairs.put("type", "3");
|
||||
nVPairs.put("id", "0");
|
||||
}
|
||||
nVPairs.put("lastModified", String.valueOf(lastSync));
|
||||
|
||||
getItemUpdatedUrlBuilder.addQueryParameter("lastModified", String.valueOf(lastSync));
|
||||
|
||||
InputStream is = HttpJsonRequest.PerformJsonRequest(api.getItemUpdatedUrl(), nVPairs, api.getUsername(), api.getPassword(), cont);
|
||||
InputStream is = HttpJsonRequest.getInstance().PerformJsonRequest(getItemUpdatedUrlBuilder.build());
|
||||
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(cont);
|
||||
try
|
||||
|
@ -83,28 +78,21 @@ public class OwnCloudReaderMethods {
|
|||
}
|
||||
|
||||
//"type": 1, // the type of the query (Feed: 0, Folder: 1, Starred: 2, All: 3)
|
||||
public static int GetItems(TAGS tag, Context cont, String offset, boolean getRead, String id, String type, API api) throws Exception
|
||||
public static int GetItems(FeedItemTags tag, Context cont, String offset, boolean getRead, String id, String type, API api) throws Exception
|
||||
{
|
||||
HashMap<String,String> nVPairs = new HashMap<>();
|
||||
nVPairs.put("batchSize", maxSizePerSync);
|
||||
if(tag.equals(TAGS.ALL_STARRED))
|
||||
{
|
||||
nVPairs.put("type", type);
|
||||
nVPairs.put("id", id);
|
||||
}
|
||||
else if(tag.equals(TAGS.ALL))
|
||||
{
|
||||
nVPairs.put("type", type);
|
||||
nVPairs.put("id", id);
|
||||
}
|
||||
nVPairs.put("offset", offset);
|
||||
if(getRead)
|
||||
nVPairs.put("getRead", "true");
|
||||
else
|
||||
nVPairs.put("getRead", "false");
|
||||
HttpUrl.Builder getItemsUrlBuilder = api.getItemUrl().newBuilder();
|
||||
|
||||
getItemsUrlBuilder.addQueryParameter("batchSize", maxSizePerSync)
|
||||
.addQueryParameter("offset", offset)
|
||||
.addQueryParameter("getRead", String.valueOf(getRead));
|
||||
|
||||
InputStream is = HttpJsonRequest.PerformJsonRequest(api.getItemUrl(), nVPairs, api.getUsername(), api.getPassword(), cont);
|
||||
if(tag.equals(FeedItemTags.ALL_STARRED) ||tag.equals(FeedItemTags.ALL))
|
||||
{
|
||||
getItemsUrlBuilder.addQueryParameter("type",type)
|
||||
.addQueryParameter("id", id);
|
||||
}
|
||||
|
||||
InputStream is = HttpJsonRequest.getInstance().PerformJsonRequest(getItemsUrlBuilder.build());
|
||||
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(cont);
|
||||
try
|
||||
|
@ -122,7 +110,7 @@ public class OwnCloudReaderMethods {
|
|||
|
||||
public static int GetFolderTags(Context cont, API api) throws Exception
|
||||
{
|
||||
InputStream is = HttpJsonRequest.PerformJsonRequest(api.getFolderUrl(), null, api.getUsername(), api.getPassword(), cont);
|
||||
InputStream is = HttpJsonRequest.getInstance().PerformJsonRequest(api.getFolderUrl());
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(cont);
|
||||
int[] result = new int[2];
|
||||
try
|
||||
|
@ -144,7 +132,7 @@ public class OwnCloudReaderMethods {
|
|||
|
||||
public static int[] GetFeeds(Context cont, API api) throws Exception
|
||||
{
|
||||
InputStream inputStream = HttpJsonRequest.PerformJsonRequest(api.getFeedUrl() , null, api.getUsername(), api.getPassword(), cont);
|
||||
InputStream inputStream = HttpJsonRequest.getInstance().PerformJsonRequest(api.getFeedUrl());
|
||||
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(cont);
|
||||
int result[] = new int[2];
|
||||
|
@ -337,20 +325,16 @@ public class OwnCloudReaderMethods {
|
|||
|
||||
|
||||
|
||||
public static boolean PerformTagExecutionAPIv2(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api)
|
||||
public static boolean PerformTagExecutionAPIv2(List<String> itemIds, FeedItemTags tag, Context context, API api)
|
||||
{
|
||||
String jsonIds;
|
||||
|
||||
|
||||
String url = api.getTagBaseUrl();
|
||||
if(tag.equals(TAGS.MARK_ITEM_AS_READ) || tag.equals(TAGS.MARK_ITEM_AS_UNREAD))
|
||||
HttpUrl.Builder urlBuilder = api.getTagBaseUrl().newBuilder();
|
||||
if(tag.equals(FeedItemTags.MARK_ITEM_AS_READ) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNREAD))
|
||||
{
|
||||
jsonIds = buildIdsToJSONArray(itemIds);
|
||||
|
||||
if(tag.equals(TAGS.MARK_ITEM_AS_READ))
|
||||
url += "read/multiple";
|
||||
else
|
||||
url += "unread/multiple";
|
||||
urlBuilder.addPathSegment(tag.toString());
|
||||
} else {
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
|
||||
|
||||
|
@ -369,11 +353,8 @@ public class OwnCloudReaderMethods {
|
|||
nameValuePairs.put("itemIds", jsonIds));
|
||||
}*/
|
||||
|
||||
if(tag.equals(TAGS.MARK_ITEM_AS_STARRED))
|
||||
url += "star/multiple";
|
||||
else if(tag.equals(TAGS.MARK_ITEM_AS_UNSTARRED))
|
||||
url += "unstar/multiple";
|
||||
|
||||
if(tag.equals(FeedItemTags.MARK_ITEM_AS_STARRED) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNSTARRED))
|
||||
urlBuilder.addPathSegment(tag.toString());
|
||||
|
||||
/*
|
||||
url += "/" + guidHash;
|
||||
|
@ -385,9 +366,12 @@ public class OwnCloudReaderMethods {
|
|||
*/
|
||||
|
||||
}
|
||||
|
||||
urlBuilder.addPathSegment("multiple");
|
||||
|
||||
try
|
||||
{
|
||||
int result = HttpJsonRequest.performTagChangeRequest(url, api.getUsername(), api.getPassword(), context, jsonIds);
|
||||
int result = HttpJsonRequest.getInstance().performTagChangeRequest(urlBuilder.build(), jsonIds);
|
||||
//if(result != -1 || result != 405)
|
||||
return (result == 200);
|
||||
}
|
||||
|
@ -398,32 +382,28 @@ public class OwnCloudReaderMethods {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean PerformTagExecutionAPIv1(String itemId, FeedItemTags.TAGS tag, Context context, API api)
|
||||
public static boolean PerformTagExecutionAPIv1(String itemId, FeedItemTags 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";
|
||||
HttpUrl.Builder urlBuilder = api.getTagBaseUrl().newBuilder();
|
||||
if(tag.equals(FeedItemTags.MARK_ITEM_AS_READ) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNREAD)) {
|
||||
urlBuilder
|
||||
.addPathSegment(itemId)
|
||||
.addPathSegment(tag.toString());
|
||||
} else {
|
||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
|
||||
|
||||
RssItem rssItem = dbConn.getRssItemById(Long.parseLong(itemId));
|
||||
|
||||
url += rssItem.getFeedId();
|
||||
urlBuilder.addPathSegment(String.valueOf(rssItem.getFeedId()));
|
||||
|
||||
urlBuilder.addPathSegment(rssItem.getGuidHash());
|
||||
|
||||
url += "/" + rssItem.getGuidHash();
|
||||
if(tag.equals(TAGS.MARK_ITEM_AS_STARRED))
|
||||
url += "/star";
|
||||
else if(tag.equals(TAGS.MARK_ITEM_AS_UNSTARRED))
|
||||
url += "/unstar";
|
||||
if(tag.equals(FeedItemTags.MARK_ITEM_AS_STARRED) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNSTARRED))
|
||||
urlBuilder.addPathSegment(tag.toString());
|
||||
}
|
||||
try
|
||||
{
|
||||
int result = HttpJsonRequest.performTagChangeRequest(url, api.getUsername(), api.getPassword(), context, null);
|
||||
int result = HttpJsonRequest.getInstance().performTagChangeRequest(urlBuilder.build(), null);
|
||||
return (result == 200);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -434,13 +414,17 @@ public class OwnCloudReaderMethods {
|
|||
}
|
||||
|
||||
|
||||
public static String GetVersionNumber(Context cont, String username, String password, String oc_root_path) throws Exception
|
||||
public static String GetVersionNumber(Context cont, String oc_root_path) throws Exception
|
||||
{
|
||||
HttpUrl basePath = HttpUrl.parse(oc_root_path);
|
||||
//Try APIv2
|
||||
try {
|
||||
String requestUrl = oc_root_path + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.VERSION_PATH;
|
||||
requestUrl = API.validateURL(requestUrl);
|
||||
InputStream is = HttpJsonRequest.PerformJsonRequest(requestUrl, null, username, password, cont);
|
||||
HttpUrl requestUrl = basePath.resolve(OwnCloudConstants.ROOT_PATH_APIv2).newBuilder()
|
||||
.addPathSegment(OwnCloudConstants.VERSION_PATH)
|
||||
.build();
|
||||
|
||||
InputStream is = HttpJsonRequest.getInstance().PerformJsonRequest(requestUrl);
|
||||
|
||||
try {
|
||||
GetVersion_v2 gv = new GetVersion_v2();
|
||||
readJsonStreamSimple(is, gv);
|
||||
|
@ -449,9 +433,13 @@ public class OwnCloudReaderMethods {
|
|||
is.close();
|
||||
}
|
||||
} catch(Exception ex) {//TODO GET HERE THE RIGHT EXCEPTION
|
||||
String requestUrl = oc_root_path + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.VERSION_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
requestUrl = API.validateURL(requestUrl);
|
||||
InputStream is = HttpJsonRequest.PerformJsonRequest(requestUrl, null, username, password, cont);
|
||||
HttpUrl requestUrl = basePath.resolve(OwnCloudConstants.ROOT_PATH_APIv1).newBuilder()
|
||||
.addPathSegment(OwnCloudConstants.VERSION_PATH)
|
||||
.addQueryParameter("format", "json")
|
||||
.build();
|
||||
|
||||
InputStream is = HttpJsonRequest.getInstance().PerformJsonRequest(requestUrl);
|
||||
|
||||
try {
|
||||
GetVersion_v1 gv = new GetVersion_v1();
|
||||
readJsonStreamSimple(is, gv);
|
||||
|
|
|
@ -27,79 +27,50 @@ import android.util.SparseArray;
|
|||
|
||||
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.IReader;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
|
||||
public class OwnCloud_Reader implements IReader {
|
||||
public class OwnCloud_Reader {
|
||||
boolean isSyncRunning = false;
|
||||
private API api = null;
|
||||
|
||||
SparseArray<AsyncTask_Reader> AsyncTasksRunning;
|
||||
|
||||
|
||||
public OwnCloud_Reader() {
|
||||
AsyncTasksRunning = new SparseArray<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Start_AsyncTask_GetItems(int task_id,
|
||||
Context context, OnAsyncTaskCompletedListener listener, FeedItemTags.TAGS tag) {
|
||||
public void Start_AsyncTask_GetItems(Context context, OnAsyncTaskCompletedListener listener, FeedItemTags tag) {
|
||||
setSyncRunning(true);
|
||||
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_GetItems(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute(tag));
|
||||
new AsyncTask_GetItems(context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Start_AsyncTask_GetOldItems(int task_id,
|
||||
Context context, OnAsyncTaskCompletedListener listener, Long feed_id, Long folder_id) {
|
||||
public void Start_AsyncTask_GetOldItems(Context context, OnAsyncTaskCompletedListener listener, Long feed_id, Long folder_id) {
|
||||
setSyncRunning(true);
|
||||
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_GetOldItems(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, feed_id, folder_id, api).execute());
|
||||
new AsyncTask_GetOldItems(context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, feed_id, folder_id, api).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Start_AsyncTask_GetFolder(int task_id,
|
||||
Context context, OnAsyncTaskCompletedListener listener) {
|
||||
public void Start_AsyncTask_GetFolder(Context context, OnAsyncTaskCompletedListener listener) {
|
||||
setSyncRunning(true);
|
||||
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_GetFolderTags(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute());
|
||||
new AsyncTask_GetFolderTags(context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Start_AsyncTask_GetFeeds(int task_id,
|
||||
Context context, OnAsyncTaskCompletedListener listener) {
|
||||
public void Start_AsyncTask_GetFeeds(Context context, OnAsyncTaskCompletedListener listener) {
|
||||
setSyncRunning(true);
|
||||
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_GetFeeds(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute());
|
||||
new AsyncTask_GetFeeds(context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Start_AsyncTask_PerformItemStateChange(int task_id,
|
||||
Context context, OnAsyncTaskCompletedListener listener) {
|
||||
public void Start_AsyncTask_PerformItemStateChange(Context context, OnAsyncTaskCompletedListener listener) {
|
||||
setSyncRunning(true);
|
||||
AsyncTasksRunning.append(task_id, (AsyncTask_Reader) new AsyncTask_PerformItemStateChange(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute());
|
||||
new AsyncTask_PerformItemStateChange(context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute();
|
||||
}
|
||||
|
||||
|
||||
public void Start_AsyncTask_GetVersion(int task_id,
|
||||
Context context, OnAsyncTaskCompletedListener listener, String username, String password) {
|
||||
public void Start_AsyncTask_GetVersion(Context context, OnAsyncTaskCompletedListener listener) {
|
||||
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) {
|
||||
|
||||
new AsyncTask_GetApiVersion(context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }).execute();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAsyncTaskCompleted(int task_id, Object task_result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSyncRunning() {
|
||||
return isSyncRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSyncRunning(boolean isSyncRunning) {
|
||||
this.isSyncRunning = isSyncRunning;
|
||||
}
|
||||
|
@ -109,21 +80,9 @@ public class OwnCloud_Reader implements IReader {
|
|||
@Override
|
||||
public void onAsyncTaskCompleted(int task_id, Object task_result) {
|
||||
setSyncRunning(false);
|
||||
AsyncTasksRunning.remove(task_id);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public SparseArray<AsyncTask_Reader> getRunningAsyncTasks() {
|
||||
return AsyncTasksRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachToRunningTask(int task_id, Activity activity, OnAsyncTaskCompletedListener listener) {
|
||||
if(AsyncTasksRunning.get(task_id) != null)
|
||||
AsyncTasksRunning.get(task_id).attach(activity, new OnAsyncTaskCompletedListener[] { listener, AsyncTask_finished });
|
||||
}
|
||||
|
||||
public API getApi() {
|
||||
return api;
|
||||
}
|
||||
|
|
|
@ -23,10 +23,12 @@ package de.luhmer.owncloudnewsreader.reader.owncloud.apiv1;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
|
||||
|
@ -38,37 +40,37 @@ public class APIv1 extends API {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getItemUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.FEED_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getItemUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv1, OwnCloudConstants.FEED_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemUpdatedUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.FEED_PATH_UPDATED_ITEMS + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getItemUpdatedUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv1, OwnCloudConstants.FEED_PATH_UPDATED_ITEMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeedUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.SUBSCRIPTION_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getFeedUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv1, OwnCloudConstants.SUBSCRIPTION_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.FOLDER_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getFolderUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv1, OwnCloudConstants.FOLDER_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTagBaseUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv1 + OwnCloudConstants.FEED_PATH + "/";
|
||||
public HttpUrl getTagBaseUrl() {
|
||||
return getAPIUrl(null, OwnCloudConstants.ROOT_PATH_APIv1, OwnCloudConstants.FEED_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean PerformTagExecution(List<String> itemIds, TAGS tag,
|
||||
Context context, API api) {
|
||||
public boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag,
|
||||
Context context) {
|
||||
|
||||
List<Boolean> succeeded = new ArrayList<>();
|
||||
for(String item : itemIds) {
|
||||
succeeded.add(OwnCloudReaderMethods.PerformTagExecutionAPIv1(item, tag, context, api));
|
||||
succeeded.add(OwnCloudReaderMethods.PerformTagExecutionAPIv1(item, tag, context, this));
|
||||
}
|
||||
|
||||
return !succeeded.contains(false);
|
||||
|
|
|
@ -23,9 +23,11 @@ package de.luhmer.owncloudnewsreader.reader.owncloud.apiv2;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
|
||||
|
@ -37,35 +39,35 @@ public class APIv2 extends API {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getItemUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.FEED_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getItemUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv2, OwnCloudConstants.FEED_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemUpdatedUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.FEED_PATH_UPDATED_ITEMS + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getItemUpdatedUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv2, OwnCloudConstants.FEED_PATH_UPDATED_ITEMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeedUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.SUBSCRIPTION_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getFeedUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv2, OwnCloudConstants.SUBSCRIPTION_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.FOLDER_PATH + OwnCloudConstants.JSON_FORMAT;
|
||||
public HttpUrl getFolderUrl() {
|
||||
return getAPIUrl(OwnCloudConstants.JSON_FORMAT, OwnCloudConstants.ROOT_PATH_APIv2, OwnCloudConstants.FOLDER_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTagBaseUrl() {
|
||||
return getOcRootPath() + OwnCloudConstants.ROOT_PATH_APIv2 + OwnCloudConstants.FEED_PATH + "/";
|
||||
public HttpUrl getTagBaseUrl() {
|
||||
return getAPIUrl(null, OwnCloudConstants.ROOT_PATH_APIv2, OwnCloudConstants.FEED_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean PerformTagExecution(List<String> itemIds, TAGS tag,
|
||||
Context context, API api) {
|
||||
public boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag,
|
||||
Context context) {
|
||||
if(itemIds.size() > 0)
|
||||
return OwnCloudReaderMethods.PerformTagExecutionAPIv2(itemIds, tag, context, api);
|
||||
return OwnCloudReaderMethods.PerformTagExecutionAPIv2(itemIds, tag, context, this);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import android.os.RemoteException;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -43,8 +45,7 @@ import de.luhmer.owncloudnewsreader.R;
|
|||
import de.luhmer.owncloudnewsreader.SettingsActivity;
|
||||
import de.luhmer.owncloudnewsreader.helper.AidlException;
|
||||
import de.luhmer.owncloudnewsreader.helper.NotificationManagerNewsReader;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
|
||||
import de.luhmer.owncloudnewsreader.reader.IReader;
|
||||
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
|
||||
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
|
||||
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
|
||||
|
@ -70,12 +71,14 @@ public class OwnCloudSyncService extends Service {
|
|||
@Override
|
||||
public void startSync() throws RemoteException {
|
||||
if(!isSyncRunning()) {
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__GET_API);
|
||||
OwnCloud_Reader ocReader = (OwnCloud_Reader) _Reader;
|
||||
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this);
|
||||
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, "");
|
||||
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, "");
|
||||
ocReader.Start_AsyncTask_GetVersion(Constants.TaskID_GetVersion, OwnCloudSyncService.this, onAsyncTask_GetVersionFinished, username, password);
|
||||
// Only check for API version once
|
||||
if(_Reader.getApi() == null) {
|
||||
_Reader.Start_AsyncTask_GetVersion(OwnCloudSyncService.this, onAsyncTask_GetVersionFinished);
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__GET_API);
|
||||
} else {
|
||||
_Reader.Start_AsyncTask_PerformItemStateChange(OwnCloudSyncService.this, onAsyncTask_PerformTagExecute);
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__ITEM_STATES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,8 +89,8 @@ public class OwnCloudSyncService extends Service {
|
|||
};
|
||||
|
||||
|
||||
static IReader _Reader;
|
||||
|
||||
static OwnCloud_Reader _Reader;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -118,9 +121,9 @@ public class OwnCloudSyncService extends Service {
|
|||
{
|
||||
String appVersion = task_result.toString();
|
||||
API api = API.GetRightApiForVersion(appVersion, OwnCloudSyncService.this);
|
||||
((OwnCloud_Reader) _Reader).setApi(api);
|
||||
_Reader.setApi(api);
|
||||
|
||||
_Reader.Start_AsyncTask_PerformItemStateChange(Constants.TaskID_PerformStateChange, OwnCloudSyncService.this, onAsyncTask_PerformTagExecute);
|
||||
_Reader.Start_AsyncTask_PerformItemStateChange(OwnCloudSyncService.this, onAsyncTask_PerformTagExecute);
|
||||
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__ITEM_STATES);
|
||||
}
|
||||
|
@ -141,7 +144,7 @@ public class OwnCloudSyncService extends Service {
|
|||
if((Boolean) task_result)
|
||||
{
|
||||
if(task_id == Constants.TaskID_PerformStateChange) {
|
||||
_Reader.Start_AsyncTask_GetFolder(Constants.TaskID_GetFolder, OwnCloudSyncService.this, onAsyncTask_GetFolder);
|
||||
_Reader.Start_AsyncTask_GetFolder(OwnCloudSyncService.this, onAsyncTask_GetFolder);
|
||||
|
||||
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__FOLDER);
|
||||
|
@ -163,7 +166,7 @@ public class OwnCloudSyncService extends Service {
|
|||
if(task_result != null)
|
||||
ThrowException((Exception) task_result);
|
||||
else {
|
||||
_Reader.Start_AsyncTask_GetFeeds(Constants.TaskID_GetFeeds, OwnCloudSyncService.this, onAsyncTask_GetFeed);
|
||||
_Reader.Start_AsyncTask_GetFeeds(OwnCloudSyncService.this, onAsyncTask_GetFeed);
|
||||
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__FEEDS);
|
||||
}
|
||||
|
@ -183,7 +186,7 @@ public class OwnCloudSyncService extends Service {
|
|||
if(task_result != null)
|
||||
ThrowException((Exception) task_result);
|
||||
else {
|
||||
_Reader.Start_AsyncTask_GetItems(Constants.TaskID_GetItems, OwnCloudSyncService.this, onAsyncTask_GetItems, TAGS.ALL);//Recieve all unread Items
|
||||
_Reader.Start_AsyncTask_GetItems(OwnCloudSyncService.this, onAsyncTask_GetItems, FeedItemTags.ALL);//Recieve all unread Items
|
||||
|
||||
startedSync(SYNC_TYPES.SYNC_TYPE__ITEMS);
|
||||
}
|
||||
|
|
|
@ -31,14 +31,13 @@ import android.preference.PreferenceManager;
|
|||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.SettingsActivity;
|
||||
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;
|
||||
|
||||
public class SyncItemStateService extends IntentService {
|
||||
|
||||
IReader _Reader = new OwnCloud_Reader();
|
||||
OwnCloud_Reader _Reader = new OwnCloud_Reader();
|
||||
|
||||
public SyncItemStateService() {
|
||||
super(null);
|
||||
|
@ -50,11 +49,7 @@ public class SyncItemStateService extends IntentService {
|
|||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
OwnCloud_Reader ocReader = (OwnCloud_Reader) _Reader;
|
||||
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String username = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, "");
|
||||
String password = mPrefs.getString(SettingsActivity.EDT_PASSWORD_STRING, "");
|
||||
ocReader.Start_AsyncTask_GetVersion(Constants.TaskID_GetVersion, this, onAsyncTask_GetVersionFinished, username, password);
|
||||
_Reader.Start_AsyncTask_GetVersion(this, onAsyncTask_GetVersionFinished);
|
||||
}
|
||||
|
||||
OnAsyncTaskCompletedListener onAsyncTask_GetVersionFinished = new OnAsyncTaskCompletedListener() {
|
||||
|
@ -67,9 +62,9 @@ public class SyncItemStateService extends IntentService {
|
|||
String appVersion = task_result.toString();
|
||||
API api = API.GetRightApiForVersion(appVersion, SyncItemStateService.this);
|
||||
|
||||
((OwnCloud_Reader)_Reader).setApi(api);
|
||||
_Reader.setApi(api);
|
||||
|
||||
_Reader.Start_AsyncTask_PerformItemStateChange(Constants.TaskID_PerformStateChange, SyncItemStateService.this, null);
|
||||
_Reader.Start_AsyncTask_PerformItemStateChange(SyncItemStateService.this, null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue