Pretty print SyncAdapter java code for better readability / removed
authorLennart Rosam <lennart@familie-rosam.de>
Sat, 14 Apr 2012 09:23:12 +0000 (11:23 +0200)
committerLennart Rosam <lennart@familie-rosam.de>
Sat, 14 Apr 2012 09:23:12 +0000 (11:23 +0200)
superflues if statement

src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java
src/eu/alefzero/owncloud/ui/activity/LandingActivity.java

index 60520ed..b849a1c 100644 (file)
@@ -15,9 +15,9 @@
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
  *\r
  */\r
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
  *\r
  */\r
-
-package eu.alefzero.owncloud.syncadapter;
-
+\r
+package eu.alefzero.owncloud.syncadapter;\r
+\r
 import java.io.IOException;\r
 import java.net.UnknownHostException;\r
 import java.util.Date;\r
 import java.io.IOException;\r
 import java.net.UnknownHostException;\r
 import java.util.Date;\r
@@ -50,175 +50,197 @@ import eu.alefzero.webdav.TreeNode;
 import eu.alefzero.webdav.TreeNode.NodeProperty;\r
 import eu.alefzero.webdav.WebdavClient;\r
 import eu.alefzero.webdav.WebdavUtils;\r
 import eu.alefzero.webdav.TreeNode.NodeProperty;\r
 import eu.alefzero.webdav.WebdavClient;\r
 import eu.alefzero.webdav.WebdavUtils;\r
-
-/**
- * Base SyncAdapter for OwnCloud
- * Designed to be subclassed for the concrete SyncAdapter, like ConcatsSync, CalendarSync, FileSync etc..
- * 
- * @author sassman
- *
- */
-public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAdapter {
-
-       private AccountManager accountManager;
-       private Account account;
-       private ContentProviderClient contentProvider;
-       private Date lastUpdated;
-       
-       private HttpHost mHost;
-       private WebdavClient mClient = null;
+\r
+/**\r
+ * Base SyncAdapter for OwnCloud Designed to be subclassed for the concrete\r
+ * SyncAdapter, like ConcatsSync, CalendarSync, FileSync etc..\r
+ * \r
+ * @author sassman\r
+ * \r
+ */\r
+public abstract class AbstractOwnCloudSyncAdapter extends\r
+               AbstractThreadedSyncAdapter {\r
+\r
+       private AccountManager accountManager;\r
+       private Account account;\r
+       private ContentProviderClient contentProvider;\r
+       private Date lastUpdated;\r
+\r
+       private HttpHost mHost;\r
+       private WebdavClient mClient = null;\r
        private static String TAG = "AbstractOwnCloudSyncAdapter";\r
        private static String TAG = "AbstractOwnCloudSyncAdapter";\r
-       
-       public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize) {
-               super(context, autoInitialize);
-               this.setAccountManager(AccountManager.get(context));
-       }
-
-       public AccountManager getAccountManager() {
-               return accountManager;
-       }
-
-       public void setAccountManager(AccountManager accountManager) {
-               this.accountManager = accountManager;
-       }
-
-       public Account getAccount() {
-               return account;
-       }
-
-       public void setAccount(Account account) {
-               this.account = account;
-       }
-
-       public ContentProviderClient getContentProvider() {
-               return contentProvider;
-       }
-
-       public void setContentProvider(ContentProviderClient contentProvider) {
-               this.contentProvider = contentProvider;
-       }
-
-       public Date getLastUpdated() {
-               return lastUpdated;
-       }
-
-       public void setLastUpdated(Date lastUpdated) {
-               this.lastUpdated = lastUpdated;
-       }
-       
-       protected ConnectionKeepAliveStrategy getKeepAliveStrategy() {
-               return new ConnectionKeepAliveStrategy() {
-                       public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
-                               // Change keep alive straategy basing on response: ie forbidden/not found/etc
-                               // should have keep alive 0
+\r
+       public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize) {\r
+               super(context, autoInitialize);\r
+               this.setAccountManager(AccountManager.get(context));\r
+       }\r
+\r
+       public AccountManager getAccountManager() {\r
+               return accountManager;\r
+       }\r
+\r
+       public void setAccountManager(AccountManager accountManager) {\r
+               this.accountManager = accountManager;\r
+       }\r
+\r
+       public Account getAccount() {\r
+               return account;\r
+       }\r
+\r
+       public void setAccount(Account account) {\r
+               this.account = account;\r
+       }\r
+\r
+       public ContentProviderClient getContentProvider() {\r
+               return contentProvider;\r
+       }\r
+\r
+       public void setContentProvider(ContentProviderClient contentProvider) {\r
+               this.contentProvider = contentProvider;\r
+       }\r
+\r
+       public Date getLastUpdated() {\r
+               return lastUpdated;\r
+       }\r
+\r
+       public void setLastUpdated(Date lastUpdated) {\r
+               this.lastUpdated = lastUpdated;\r
+       }\r
+\r
+       protected ConnectionKeepAliveStrategy getKeepAliveStrategy() {\r
+               return new ConnectionKeepAliveStrategy() {\r
+                       public long getKeepAliveDuration(HttpResponse response,\r
+                                       HttpContext context) {\r
+                               // Change keep alive straategy basing on response: ie\r
+                               // forbidden/not found/etc\r
+                               // should have keep alive 0\r
                                // default return: 5s\r
                                int statusCode = response.getStatusLine().getStatusCode();\r
                                // default return: 5s\r
                                int statusCode = response.getStatusLine().getStatusCode();\r
-                               \r
-                               // HTTP 400, 500 Errors as well as HTTP 118 - Connection timed out\r
-                               if((statusCode >= 400 && statusCode <= 418) || \r
-                                               (statusCode >= 421 && statusCode <= 426) ||\r
-                                               (statusCode >= 500 && statusCode <= 510 ) ||\r
-                                               statusCode == 118) {\r
+\r
+                               // HTTP 400, 500 Errors as well as HTTP 118 - Connection timed\r
+                               // out\r
+                               if ((statusCode >= 400 && statusCode <= 418)\r
+                                               || (statusCode >= 421 && statusCode <= 426)\r
+                                               || (statusCode >= 500 && statusCode <= 510)\r
+                                               || statusCode == 118) {\r
                                        return 0;\r
                                }\r
                                        return 0;\r
                                }\r
-                               
-                               return 5 * 1000;
-                       }
-               };
-       }
-       
-       protected HttpPropFind getPropFindQuery() throws OperationCanceledException, AuthenticatorException, IOException {
-               HttpPropFind query = new HttpPropFind(getUri().toString());
-               query.setHeader("Content-type", "text/xml");
-               query.setHeader("User-Agent", "Android-ownCloud");
-               return query;
-       }
-       
-       protected HttpResponse fireRawRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException {
-           BasicHttpContext httpContext = new BasicHttpContext();
-        BasicScheme basicAuth = new BasicScheme();
-        httpContext.setAttribute("preemptive-auth", basicAuth);
-        
-        HttpResponse response = getClient().execute(mHost, query, httpContext);
-        return response;
-       }
-       
-       protected TreeNode fireRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException {
-               HttpResponse response = fireRawRequest(query);
-               
-               TreeNode root = new TreeNode();
-               root.setProperty(TreeNode.NodeProperty.NAME, "");
-               this.parseResponse(response, getUri(), getClient(), mHost, root.getChildList(), false, 0);
-               return root;
-       }
-       
-       protected Uri getUri() {
-               return Uri.parse(this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL));
-       }
-       
-       private DefaultHttpClient getClient() throws OperationCanceledException, AuthenticatorException, IOException {
-               if(mClient == null) {
-                       String username = getAccount().name.split("@")[0];
-                       String password = this.getAccountManager().blockingGetAuthToken(getAccount(), AccountAuthenticator.AUTH_TOKEN_TYPE, true);
-                       if (this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL) == null) {
-                               throw new UnknownHostException();
-                       }
-                       Uri uri = getUri();
-       
-                       mClient = new WebdavClient(uri);
-                       mClient.setCredentials(username, password);
-                       mClient.allowUnsignedCertificates();
-                       mHost = mClient.getTargetHost();
-               }
-               
-               return mClient.getHttpClient();
-       }
-       
-       private void parseResponse(HttpResponse resp, Uri uri, DefaultHttpClient client, HttpHost targetHost, LinkedList<TreeNode> insertList, boolean sf, long parent_id) throws IOException, OperationCanceledException, AuthenticatorException {
-               boolean skipFirst = sf, override_parent = !sf;
-               for (TreeNode n :WebdavUtils.parseResponseToNodes(resp.getEntity().getContent())) {\r
-                 if (skipFirst) {\r
-        skipFirst = false;\r
-        continue;\r
-      }
+\r
+                               return 5 * 1000;\r
+                       }\r
+               };\r
+       }\r
+\r
+       protected HttpPropFind getPropFindQuery()\r
+                       throws OperationCanceledException, AuthenticatorException,\r
+                       IOException {\r
+               HttpPropFind query = new HttpPropFind(getUri().toString());\r
+               query.setHeader("Content-type", "text/xml");\r
+               query.setHeader("User-Agent", "Android-ownCloud");\r
+               return query;\r
+       }\r
+\r
+       protected HttpResponse fireRawRequest(HttpRequest query)\r
+                       throws ClientProtocolException, OperationCanceledException,\r
+                       AuthenticatorException, IOException {\r
+               BasicHttpContext httpContext = new BasicHttpContext();\r
+               BasicScheme basicAuth = new BasicScheme();\r
+               httpContext.setAttribute("preemptive-auth", basicAuth);\r
+\r
+               HttpResponse response = getClient().execute(mHost, query, httpContext);\r
+               return response;\r
+       }\r
+\r
+       protected TreeNode fireRequest(HttpRequest query)\r
+                       throws ClientProtocolException, OperationCanceledException,\r
+                       AuthenticatorException, IOException {\r
+               HttpResponse response = fireRawRequest(query);\r
+\r
+               TreeNode root = new TreeNode();\r
+               root.setProperty(TreeNode.NodeProperty.NAME, "");\r
+               this.parseResponse(response, getUri(), getClient(), mHost,\r
+                               root.getChildList(), false, 0);\r
+               return root;\r
+       }\r
+\r
+       protected Uri getUri() {\r
+               return Uri.parse(this.getAccountManager().getUserData(getAccount(),\r
+                               AccountAuthenticator.KEY_OC_URL));\r
+       }\r
+\r
+       private DefaultHttpClient getClient() throws OperationCanceledException,\r
+                       AuthenticatorException, IOException {\r
+               if (mClient == null) {\r
+                       String username = getAccount().name.split("@")[0];\r
+                       String password = this.getAccountManager().blockingGetAuthToken(\r
+                                       getAccount(), AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
+                       if (this.getAccountManager().getUserData(getAccount(),\r
+                                       AccountAuthenticator.KEY_OC_URL) == null) {\r
+                               throw new UnknownHostException();\r
+                       }\r
+                       Uri uri = getUri();\r
+\r
+                       mClient = new WebdavClient(uri);\r
+                       mClient.setCredentials(username, password);\r
+                       mClient.allowUnsignedCertificates();\r
+                       mHost = mClient.getTargetHost();\r
+               }\r
+\r
+               return mClient.getHttpClient();\r
+       }\r
+\r
+       private void parseResponse(HttpResponse resp, Uri uri,\r
+                       DefaultHttpClient client, HttpHost targetHost,\r
+                       LinkedList<TreeNode> insertList, boolean sf, long parent_id)\r
+                       throws IOException, OperationCanceledException,\r
+                       AuthenticatorException {\r
+               boolean skipFirst = sf, override_parent = !sf;\r
+               for (TreeNode n : WebdavUtils.parseResponseToNodes(resp.getEntity()\r
+                               .getContent())) {\r
+                       if (skipFirst) {\r
+                               skipFirst = false;\r
+                               continue;\r
+                       }\r
                        String path = n.stripPathFromFilename(uri.getPath());\r
                        String path = n.stripPathFromFilename(uri.getPath());\r
-                       \r
-                       long mod = n.getProperty(NodeProperty.LAST_MODIFIED_DATE) == null ?\r
-                                  0 :\r
-                                  Long.parseLong(n.getProperty(NodeProperty.LAST_MODIFIED_DATE));\r
-           OCFile file = new OCFile(getContentProvider(), getAccount(), n.getProperty(NodeProperty.PATH));\r
-           if (file.fileExtist() && file.getModificationTimestamp() >= mod) {\r
-             Log.d(TAG, "No update for file/dir " + file.getFileName() + " is needed");\r
-           } else {\r
-             Log.d(TAG, "File " + n.getProperty(NodeProperty.PATH) + " will be " + (file.fileExtist() ? "updated" : "created"));\r
-           long len = n.getProperty(NodeProperty.CONTENT_LENGTH) == null ?\r
-                   0 :\r
-                   Long.parseLong(n.getProperty(NodeProperty.CONTENT_LENGTH));\r
-           long create = n.getProperty(NodeProperty.CREATE_DATE) == null ?\r
-                      0 :\r
-                      Long.parseLong(n.getProperty(NodeProperty.CREATE_DATE));\r
-                       file = OCFile.createNewFile(getContentProvider(),\r
-            getAccount(),\r
-            n.getProperty(NodeProperty.PATH),\r
-            len,\r
-            create,\r
-            mod,\r
-            n.getProperty(NodeProperty.RESOURCE_TYPE),\r
-            parent_id);\r
-                       file.save();\r
-                       if (override_parent) {\r
-                         parent_id = file.getFileId();\r
-                         override_parent = false;\r
-                       }\r
-           }
-
-                       if (!TextUtils.isEmpty(n.getProperty(NodeProperty.NAME)) &&
-                                       n.getProperty(NodeProperty.RESOURCE_TYPE).equals("DIR")) {
-                           
-                           HttpPropFind method = new HttpPropFind(uri.getPath() + path + n.getProperty(NodeProperty.NAME).replace(" ", "%20") + "/");
-                               HttpResponse response = fireRawRequest(method);
-                               parseResponse(response, uri, client, targetHost, n.getChildList(), true, file.getFileId());
-                       }
-               }
-       }
+\r
+                       long mod = n.getProperty(NodeProperty.LAST_MODIFIED_DATE) == null ? 0\r
+                                       : Long.parseLong(n\r
+                                                       .getProperty(NodeProperty.LAST_MODIFIED_DATE));\r
+                       OCFile file = new OCFile(getContentProvider(), getAccount(),\r
+                                       n.getProperty(NodeProperty.PATH));\r
+                       if (file.fileExtist() && file.getModificationTimestamp() >= mod) {\r
+                               Log.d(TAG, "No update for file/dir " + file.getFileName()\r
+                                               + " is needed");\r
+                       } else {\r
+                               Log.d(TAG, "File " + n.getProperty(NodeProperty.PATH)\r
+                                               + " will be "\r
+                                               + (file.fileExtist() ? "updated" : "created"));\r
+                               long len = n.getProperty(NodeProperty.CONTENT_LENGTH) == null ? 0\r
+                                               : Long.parseLong(n\r
+                                                               .getProperty(NodeProperty.CONTENT_LENGTH));\r
+                               long create = n.getProperty(NodeProperty.CREATE_DATE) == null ? 0\r
+                                               : Long.parseLong(n\r
+                                                               .getProperty(NodeProperty.CREATE_DATE));\r
+                               file = OCFile.createNewFile(getContentProvider(), getAccount(),\r
+                                               n.getProperty(NodeProperty.PATH), len, create, mod,\r
+                                               n.getProperty(NodeProperty.RESOURCE_TYPE), parent_id);\r
+                               file.save();\r
+                               if (override_parent) {\r
+                                       parent_id = file.getFileId();\r
+                                       override_parent = false;\r
+                               }\r
+                       }\r
+\r
+                       if (!TextUtils.isEmpty(n.getProperty(NodeProperty.NAME))\r
+                                       && n.getProperty(NodeProperty.RESOURCE_TYPE).equals("DIR")) {\r
+\r
+                               HttpPropFind method = new HttpPropFind(uri.getPath() + path\r
+                                               + n.getProperty(NodeProperty.NAME).replace(" ", "%20")\r
+                                               + "/");\r
+                               HttpResponse response = fireRawRequest(method);\r
+                               parseResponse(response, uri, client, targetHost,\r
+                                               n.getChildList(), true, file.getFileId());\r
+                       }\r
+               }\r
+       }\r
 }
\ No newline at end of file
 }
\ No newline at end of file
index a12a31c..7e2a8c0 100644 (file)
@@ -50,12 +50,10 @@ public class LandingActivity extends SherlockFragmentActivity implements OnClick
                super.onCreate(savedInstanceState);\r
                setContentView(R.layout.main);\r
                \r
                super.onCreate(savedInstanceState);\r
                setContentView(R.layout.main);\r
                \r
-               // Fill the grid view that is only available in portrait mode\r
+               // Fill the grid view of the landing screen with icons\r
                GridView landingScreenItems = (GridView) findViewById(R.id.homeScreenGrid);\r
                GridView landingScreenItems = (GridView) findViewById(R.id.homeScreenGrid);\r
-               if(landingScreenItems != null){\r
-                       landingScreenItems.setAdapter(new LandingScreenAdapter(this));\r
-                       landingScreenItems.setOnItemClickListener(this);\r
-               }\r
+               landingScreenItems.setAdapter(new LandingScreenAdapter(this));\r
+               landingScreenItems.setOnItemClickListener(this);\r
                \r
                // Check, if there are ownCloud accounts\r
                if(!accountsAreSetup()){\r
                \r
                // Check, if there are ownCloud accounts\r
                if(!accountsAreSetup()){\r
@@ -129,6 +127,7 @@ public class LandingActivity extends SherlockFragmentActivity implements OnClick
                if(intent != null ){\r
                        startActivity(intent);\r
                } else {\r
                if(intent != null ){\r
                        startActivity(intent);\r
                } else {\r
+                       // TODO: Implement all of this and make this text go away ;-)\r
                        Toast toast = Toast.makeText(this, "Not yet implemented!", Toast.LENGTH_SHORT);\r
                        toast.show();\r
                } \r
                        Toast toast = Toast.makeText(this, "Not yet implemented!", Toast.LENGTH_SHORT);\r
                        toast.show();\r
                } \r