Commits

Ville Saalo committed f6f6f33

Turning all "AsyncLoader asyncLoader = getAsyncLoader(); asyncLoader.execute(...)" commands into a new and simple "executeAsyncLoader(...)" command.

  • Participants
  • Parent commits 8adacb0

Comments (0)

Files changed (15)

src/com/saibotd/bitbeaker/DiffActivity.java

 		changeset_id = b.getString("changeset");
 		file = b.getString("file");
 
-		AsyncLoader asyncLoader = getAsyncLoader();
 		/*
 		 * Currently we get raw diff for whole changeset at same time. First file
 		 * will be displayed slowly but the rest are fast due to cache
 		 */
-		asyncLoader.execute("https://bitbucket.org/"+ owner +"/"+slug+"/changeset/"+changeset_id+"/raw/");
+		executeAsyncLoader("https://bitbucket.org/"+ owner +"/"+slug+"/changeset/"+changeset_id+"/raw/");
 		setTitle(slug + ": " + changeset_id);
 		getSupportActionBar().setSubtitle(file);
 
 			imageinfo.setText(String.format(this.getString(R.string.toggle_diff_image), file));
 			imageinfo.setOnClickListener(new View.OnClickListener() {
 				public void onClick(View v) {
-					if (diff_image.getDrawable()==null)
-						getAsyncImageLoader(diff_image).execute("https://bitbucket.org/"+owner+"/"+slug+"/raw/"+changeset_id+"/"+Helper.encode(file));
+					if (diff_image.getDrawable() == null) {
+						executeAsyncImageLoader(diff_image, "https://bitbucket.org/"+owner+"/"+slug+"/raw/"+changeset_id+"/"+Helper.encode(file));
+					}
 					showImage = !showImage;
 					if (showImage) {
 						webView.setVisibility(View.GONE);

src/com/saibotd/bitbeaker/IssueActivity.java

 	}
 	
 	private void loadIssue(){
-		AsyncLoader asyncLoader = getAsyncLoader();
-		asyncLoader.execute(getIssueURL());
+		executeAsyncLoader(getIssueURL());
 	}
 	
 	private void loadComments(){

src/com/saibotd/bitbeaker/IssuesActivity.java

 			url += "?" + filter;
 		}
 		bitbeaker.delKV(url);
-		AsyncLoader asyncLoader = getAsyncLoader();
-		asyncLoader.execute(url);
-
+		executeAsyncLoader(url);
 	}
 
 	@Override

src/com/saibotd/bitbeaker/LauncherActivity.java

 		super.onCreate(savedInstanceState);
 		Uri data = getIntent().getData();
 		if (data != null) {
-			mode = Mode.OTHER;
-			List<String> segments = data.getPathSegments();
-			b = new Bundle();
-			if (segments.size() >= 2) {
-				b.putString("owner", segments.get(0));
-				b.putString("slug", segments.get(1));
-			}
-			
-			// single issue
-			if (segments.size() > 3 && segments.get(2).equalsIgnoreCase("issue")) {
-				b.putInt("id", Integer.parseInt(segments.get(3)));
-
-				// get issue's title
-				mode = Mode.ISSUE;
-				String api_query = API_BASE_URL + "/repositories/" + segments.get(0) +"/"+ segments.get(1) +"/issues/"+segments.get(3);
-				getAsyncLoader().execute(api_query, null, this.getString(R.string.AsyncErrorMSG));
-			}
-
-			// issues
-			else if (segments.size() == 3 && segments.get(2).equalsIgnoreCase("issues")) {
-				b.putStringArray("statusFilter", data.getQueryParameters("status").toArray(new String[0]));
-				Intent intent = new Intent(this, IssuesActivity.class);
-				intent.putExtras(b);
-				this.startActivity(intent);
-			}
-
-			// changesets
-			else if (segments.size() > 3 && segments.get(2).equalsIgnoreCase("changeset")) {
-				// get node data from API
-				mode = Mode.CHANGESETS;
-				String api_query = API_BASE_URL + "/repositories/" + segments.get(0) +"/"+ segments.get(1) +"/changesets/"+segments.get(3);
-				getAsyncLoader().execute(api_query, null, this.getString(R.string.AsyncErrorMSG));
-			}
-
-			// source code browser
-			else if (segments.size() == 3 && segments.get(2).equalsIgnoreCase("src")) {
-				b.putString("subdir", "/");
-
-				// get branches for SourceBrowserActivity
-				mode = Mode.MAIN_PAGE;
-				String api_query = API_BASE_URL + "/repositories/" + segments.get(0) + "/" + segments.get(1) + "/branches";
-				getAsyncLoader().execute(api_query, null, this.getString(R.string.no_branches));
-			}
-
-			// probably repository's main page
-			else if (segments.size() == 2) {
-				Intent intent = new Intent(this, RepositoryActivity.class);
-				intent.putExtras(b);
-				this.startActivity(intent);
-			}
-
-			// user profile
-			else if (segments.size() == 1) {
-				b.putString("user", segments.get(0));
-				Intent intent = new Intent(this, UserProfileActivity.class);
-				intent.putExtras(b);
-				this.startActivity(intent);
-			}
-			
-			else {
-				makeToast(R.string.link_not_supported);
-			}
-
+			handleUriData(data);
 		}
 		this.finish();
 	}
+	
+	private void handleUriData(Uri data) {
+		mode = Mode.OTHER;
+		List<String> segments = data.getPathSegments();
+		b = new Bundle();
+		if (segments.size() >= 2) {
+			b.putString("owner", segments.get(0));
+			b.putString("slug", segments.get(1));
+		}
+		
+		// single issue
+		if (segments.size() > 3 && segments.get(2).equalsIgnoreCase("issue")) {
+			b.putInt("id", Integer.parseInt(segments.get(3)));
+
+			// get issue's title
+			mode = Mode.ISSUE;
+			String api_query = API_BASE_URL + "/repositories/" + segments.get(0) +"/"+ segments.get(1) +"/issues/"+segments.get(3);
+			executeAsyncLoader(api_query, null, this.getString(R.string.AsyncErrorMSG));
+		}
+
+		// issues
+		else if (segments.size() == 3 && segments.get(2).equalsIgnoreCase("issues")) {
+			b.putStringArray("statusFilter", data.getQueryParameters("status").toArray(new String[0]));
+			Intent intent = new Intent(this, IssuesActivity.class);
+			intent.putExtras(b);
+			this.startActivity(intent);
+		}
+
+		// changesets
+		else if (segments.size() > 3 && segments.get(2).equalsIgnoreCase("changeset")) {
+			// get node data from API
+			mode = Mode.CHANGESETS;
+			String api_query = API_BASE_URL + "/repositories/" + segments.get(0) +"/"+ segments.get(1) +"/changesets/"+segments.get(3);
+			executeAsyncLoader(api_query, null, this.getString(R.string.AsyncErrorMSG));
+		}
+
+		// source code browser
+		else if (segments.size() == 3 && segments.get(2).equalsIgnoreCase("src")) {
+			b.putString("subdir", "/");
+
+			// get branches for SourceBrowserActivity
+			mode = Mode.MAIN_PAGE;
+			String api_query = API_BASE_URL + "/repositories/" + segments.get(0) + "/" + segments.get(1) + "/branches";
+			executeAsyncLoader(api_query, null, this.getString(R.string.no_branches));
+		}
+
+		// probably repository's main page
+		else if (segments.size() == 2) {
+			Intent intent = new Intent(this, RepositoryActivity.class);
+			intent.putExtras(b);
+			this.startActivity(intent);
+		}
+
+		// user profile
+		else if (segments.size() == 1) {
+			b.putString("user", segments.get(0));
+			Intent intent = new Intent(this, UserProfileActivity.class);
+			intent.putExtras(b);
+			this.startActivity(intent);
+		}
+		
+		else {
+			makeToast(R.string.link_not_supported);
+		}
+	}
 
 	@Override
 	protected void asyncLoaderDone(String result) {
 				}
 				break;
 
+			default:
+				// Unknown: ignore.
+				break;
 		}
 	}
 

src/com/saibotd/bitbeaker/MyActivity.java

 
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
+import android.graphics.Bitmap;
+import android.os.AsyncTask;
 import android.os.Bundle;
 import android.util.Log;
 import android.widget.ImageView;
 		this.alertDialog = alertDialog;
 	}
 
-	protected AsyncLoader getAsyncLoader() {
-		return new AsyncLoader(this, bitbeaker.getUsername(), bitbeaker.getPassword());
+	protected AsyncTask<String, Integer, String> executeAsyncLoader(String... params) {
+		return new AsyncLoader(this, bitbeaker.getUsername(), bitbeaker.getPassword()).execute(params);
 	}
 	
-	protected AsyncImageLoader getAsyncImageLoader(ImageView image) {
-		return new AsyncImageLoader(this, bitbeaker.getUsername(), bitbeaker.getPassword(), image);
+	protected AsyncTask<String, Integer, Bitmap> executeAsyncImageLoader(ImageView image, String... params) {
+		return new AsyncImageLoader(this, bitbeaker.getUsername(), bitbeaker.getPassword(), image).execute(params);
 	}
 }

src/com/saibotd/bitbeaker/NewIssueActivity.java

 					status = "new";
 			}
 
-			AsyncLoader asyncLoader = getAsyncLoader();
-			asyncLoader.execute(API_BASE_URL + "/repositories/" 
+			executeAsyncLoader(API_BASE_URL + "/repositories/" 
 					+ owner + "/" + slug
 					+ "/issues/", 
 					"title=" 

src/com/saibotd/bitbeaker/NewIssueCommentActivity.java

   	    switch (item.getItemId()) {
   		    case R.id.menu_submit:
   				String content = ((EditText) findViewById(R.id.new_issue_comment_content)).getText().toString();
-  		        AsyncLoader asyncLoader = getAsyncLoader();
-  		        bitbeaker.delKV(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
-  		        asyncLoader.execute(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/", "content=" +  Helper.encode(content));
+  				bitbeaker.delKV(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
+	        	executeAsyncLoader(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/", "content=" +  Helper.encode(content));
   		    default:
-  		        return super.onOptionsItemSelected(item);
+  		    	return super.onOptionsItemSelected(item);
   	    }
   	}
     

src/com/saibotd/bitbeaker/RepositoriesActivity.java

     }
     
 	private void loadRepos(){
-		AsyncLoader asyncLoader = getAsyncLoader();
-		asyncLoader.execute(API_BASE_URL + "/user/repositories/");
+		executeAsyncLoader(API_BASE_URL + "/user/repositories/");
 	}
 	
 	@Override

src/com/saibotd/bitbeaker/RepositoryActivity.java

         firstCall = true;
         setTitle(slug);
         getSupportActionBar().setSubtitle(owner);
-        AsyncLoader asyncLoader = getAsyncLoader();
-        asyncLoader.execute(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/");
+        executeAsyncLoader(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/");
         listBranches();
     }
     
 				if(!Helper.isEmpty(jsonObject.getString("website")) && !jsonObject.getString("website").trim().equals("null")) desc += "<br><a href='"+ jsonObject.getString("website") +"'>" + jsonObject.getString("website") + "</a>";
 				description.setText(Html.fromHtml(desc));
 				if(jsonObject.getString("logo") != "null"){
-					AsyncImageLoader imgLoader = getAsyncImageLoader(icon);
-					imgLoader.execute(jsonObject.getString("logo"));
+					executeAsyncImageLoader(icon, jsonObject.getString("logo"));
 				}
 			} catch (JSONException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();
 			}
-			AsyncLoader asyncLoader2 = getAsyncLoader();
-			asyncLoader2.execute(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/changesets/", null, this.getString(R.string.no_changesets_error));
+			executeAsyncLoader(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/changesets/", null, this.getString(R.string.no_changesets_error));
 		} else {
 			findViewById(R.id.changeset_loading).setVisibility(View.GONE);
 			ListView listView = (ListView) findViewById(R.id.repository_changesets);

src/com/saibotd/bitbeaker/SearchableActivity.java

         if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
           String query = intent.getStringExtra(SearchManager.QUERY);
           if(query.length() >= 3){
-	          AsyncLoader asyncLoader = getAsyncLoader();
-	          asyncLoader.execute(API_BASE_URL + "/repositories/?name=" + Helper.encode(query));
+        	  executeAsyncLoader(API_BASE_URL + "/repositories/?name=" + Helper.encode(query));
 	          setTitle("Results for \"" + query + "\"");
           } else {
         	  makeToast(R.string.please_enter_more_text);

src/com/saibotd/bitbeaker/SourceActivity.java

 		if (Helper.isImage(file)) {
 			ImageView imageView = (ImageView) findViewById(R.id.source_image);
 			imageView.setVisibility(View.VISIBLE);
-			getAsyncImageLoader(imageView).execute("https://bitbucket.org/" + owner + "/" + slug + "/raw/" + branch + Helper.encode(file));
+			executeAsyncImageLoader(imageView, "https://bitbucket.org/" + owner + "/" + slug + "/raw/" + branch + Helper.encode(file));
 		}
-		else getAsyncLoader().execute(API_BASE_URL + "/repositories/" + owner + "/" + slug + "/raw/" + branch + Helper.encode(file));
+		else {
+			executeAsyncLoader(API_BASE_URL + "/repositories/" + owner + "/" + slug + "/raw/" + branch + Helper.encode(file));
+		}
 	}
 
 	@Override

src/com/saibotd/bitbeaker/SourceBrowserActivity.java

 
 	private void getData() {
 		String error_msg = String.format(this.getString(R.string.file_not_found), subdir, branch);
-		getAsyncLoader().execute(API_BASE_URL + "/repositories/" + owner + "/" + slug + "/src/" + branch + Helper.encode(subdir),
+		executeAsyncLoader(API_BASE_URL + "/repositories/" + owner + "/" + slug + "/src/" + branch + Helper.encode(subdir),
 				null,
 				error_msg
 		);

src/com/saibotd/bitbeaker/UpdateIssueActivity.java

 			}
 			
 			bitbeaker.delKV(updateURI);
-			AsyncLoader asyncLoader = getAsyncLoader();
-			asyncLoader.execute(updateURI, postParams, null, "PUT");
+			executeAsyncLoader(updateURI, postParams, null, "PUT");
 			return true;
 
 		}

src/com/saibotd/bitbeaker/UserProfileActivity.java

         user = b.getString("user");
         setTitle(user);
         //getSupportActionBar().setSubtitle(owner);
-        AsyncLoader asyncLoader = getAsyncLoader();
-        asyncLoader.execute(API_BASE_URL + "/users/"+ user +"/");
+        executeAsyncLoader(API_BASE_URL + "/users/"+ user +"/");
     }
     
 	@Override
 			JSONArray repositories = jsonObject.getJSONArray("repositories");
 			real_name.setText(user.getString("first_name") + " " + user.getString("last_name"));
 			if(user.getString("avatar") != "null"){
-				AsyncImageLoader imgLoader = getAsyncImageLoader(avatar);
-				imgLoader.execute(user.getString("avatar"));
+				executeAsyncImageLoader(avatar, user.getString("avatar"));
 			}
 			listView.setAdapter(new RepositoriesAdapter(this, repositories));
 		} catch (JSONException e) {

src/com/saibotd/bitbeaker/WikiActivity.java

         slug = b.getString("slug");
         owner = b.getString("owner");
         setTitle(slug + " wiki");
-        AsyncLoader asyncLoader = getAsyncLoader();
-        asyncLoader.execute(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/wiki/");
+        executeAsyncLoader(API_BASE_URL + "/repositories/"+ owner +"/"+ slug +"/wiki/");
 
 		webView = (WebView) findViewById(R.id.wiki_webview);
 		webView.getSettings().setBuiltInZoomControls(true);
 			data = new JSONObject(result).getString("data");
 
 			// add prefix to local URLs (not starting with "http")
-			data = data.replaceAll("\\[\\[((?!.*http).*)\\|(.*)\\]\\]", "[[https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/wiki/$1|$2]]");
-			data = data.replaceAll("\\[\\[((?!.*http).*)\\]\\]",        "[[https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/wiki/$1|$1]]");
+			data = data.replaceAll("\\[\\[((?!.*http).*)\\|(.*)\\]\\]", "[["+API_BASE_URL+"/repositories/"+ owner +"/"+ slug +"/wiki/$1|$2]]");
+			data = data.replaceAll("\\[\\[((?!.*http).*)\\]\\]",        "[["+API_BASE_URL+"/repositories/"+ owner +"/"+ slug +"/wiki/$1|$1]]");
 
 		} catch (JSONException e) {
 			// TODO Auto-generated catch block
 
 		@SuppressWarnings("unused")
 		public void openWikiLink(final String url) {
-			AsyncLoader asyncLoader = getAsyncLoader();
-			asyncLoader.execute(url);
+			executeAsyncLoader(url);
 		}
 	}
 }