Commits

Tobias Duehr  committed 6bb7fe2

It is now possible to submit comments on issues

  • Participants
  • Parent commits af15ddb

Comments (0)

Files changed (9)

File AndroidManifest.xml

    		</activity>
 		<activity android:name="NewIssueActivity"></activity>
 		<activity android:name="IssueActivity"></activity>
+		<activity android:name="NewIssueCommentActivity"></activity>
     </application>
 </manifest>

File project.properties

 #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
 
 # Project target.
-target=android-15
+target=android-16
 android.library.reference.1=../../Apps/JakeWharton-ActionBarSherlock-2eabf25/library

File res/layout/issue.xml

 
 </ListView>
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical" >
-
-        <EditText
-            android:id="@+id/issue_new_comment"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:ems="10"
-            android:hint="@string/new_comment_hint"
-            android:inputType="textMultiLine" >
-
-        </EditText>
-
-    </LinearLayout>
-
 </LinearLayout>

File res/layout/new_issue_comment.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
+  <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content">
+      <LinearLayout android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content">
+          <TextView android:text="@string/content" android:autoLink="all" android:layout_margin="5dip" android:layout_height="wrap_content" android:id="@+id/TextView02" android:layout_width="match_parent" android:linksClickable="true"></TextView>
+
+          <EditText
+              android:id="@+id/new_issue_comment_content"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:inputType="textMultiLine"
+              android:lines="3" >
+</EditText>
+      </LinearLayout>
+  </ScrollView>
+  
+</LinearLayout>

File res/menu/menu_issues.xml

-<?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
-    <item android:id="@+id/menu_add" android:title="@string/new_issue" android:showAsAction="always|withText" android:icon="@drawable/plus_alt_32x32"></item>
-    
-
-</menu>

File src/com/saibotd/bitbeaker/IssueActivity.java

 import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.EditText;
 import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.TextView;
 	private int id;
 	private ListView listView;//issue's content and comments
 	ActionMode mMode;
+	static final int NEW_ISSUE_COMMENT = 0;
 
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		id = b.getInt("id");
 		listView = (ListView) findViewById(R.id.issue_comments_list);
 
-		AsyncLoader asyncLoader = new AsyncLoader();
-		asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id);
 		ActionBar actionBar = getSupportActionBar();
 		setTitle(slug);
         actionBar.setSubtitle("Issue: " + title);
         
-        ((EditText)findViewById(R.id.issue_new_comment)).setOnFocusChangeListener(new View.OnFocusChangeListener() {
-
-			@Override
-			public void onFocusChange(View v, boolean hasFocus) {
-				Log.d("EDIT", v.toString());
-        		if(hasFocus){
-        			mMode = startActionMode(new NewCommentActionMode());
-        		} else {
-        			if (mMode != null) mMode.finish();
-        		}
-        	}
-		});
+        AsyncLoader asyncLoader = new AsyncLoader();
+		asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id);
+        
+        loadComments();
+	}
+	
+	private void loadComments(){
+		bitbeaker.delKV("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
+		AsyncCommentsLoader asyncCommentsLoader = new AsyncCommentsLoader();
+		asyncCommentsLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
 	}
 	
 	public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getSupportMenuInflater();
-        inflater.inflate(R.menu.menu_issues, menu);
+        inflater.inflate(R.menu.menu_simple_add, menu);
         return true;
     }
     
     @Override
    	public boolean onOptionsItemSelected(MenuItem item) {
-       	Bundle b = new Bundle();
-   		b.putString("slug", slug);
-   		b.putString("owner", owner);
    	    switch (item.getItemId()) {
    		    case R.id.menu_add:
-   		    	Intent intent = new Intent(this, NewIssueActivity.class);
-   				intent.putExtras(b);
-   				startActivity(intent);
+   		    	Intent intent = new Intent(this, NewIssueCommentActivity.class);
+   				intent.putExtras(getIntent().getExtras()); // Just passing the current bundle instead of creating a new one!
+   				startActivityForResult(intent, NEW_ISSUE_COMMENT);
    		        return true;
    		    default:
    		        return super.onOptionsItemSelected(item);
    	    }
    	}
     
-    private final class NewCommentActionMode implements ActionMode.Callback {
-        @Override
-        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
-            return true;
-        }
-
-        @Override
-        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
-            return false;
-        }
-
-        @Override
-        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
-            Log.d("ITEM", item.toString());
-            mode.finish();
-            return true;
-        }
-
-        @Override
-        public void onDestroyActionMode(ActionMode mode) {
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (requestCode == NEW_ISSUE_COMMENT) {
+        	loadComments();
         }
     }
 
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-
-		AsyncCommentsLoader asyncCommentsLoader = new AsyncCommentsLoader();
-		setSupportProgressBarIndeterminateVisibility(true);
-		asyncCommentsLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
 	}
 
 	protected class AsyncCommentsLoader extends AsyncLoader {

File src/com/saibotd/bitbeaker/IssuesActivity.java

     
     public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getSupportMenuInflater();
-        inflater.inflate(R.menu.menu_issues, menu);
+        inflater.inflate(R.menu.menu_simple_add, menu);
         return true;
     }
     

File src/com/saibotd/bitbeaker/NewIssueActivity.java

         Bundle b = getIntent().getExtras();
         slug = b.getString("slug");
         owner = b.getString("owner");
-        bitbeaker.delKV("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/");
         setContentView(R.layout.new_issue);
         setTitle(slug);
         getSupportActionBar().setSubtitle("Report new issue");

File src/com/saibotd/bitbeaker/NewIssueCommentActivity.java

+package com.saibotd.bitbeaker;
+
+import java.net.URLEncoder;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+
+public class NewIssueCommentActivity extends MyActivity {
+	
+	private String slug;
+	private String owner;
+	private String title;
+	private int id;
+	
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setSupportProgressBarIndeterminateVisibility(false);
+        Bundle b = getIntent().getExtras();
+        slug = b.getString("slug");
+		owner = b.getString("owner");
+		title = b.getString("title");
+		id = b.getInt("id");
+        setContentView(R.layout.new_issue_comment);
+        setTitle(title);
+        getSupportActionBar().setSubtitle(slug + " - Add a comment");
+    }
+    
+    public boolean onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getSupportMenuInflater();
+        inflater.inflate(R.menu.menu_simple_submit, menu);
+        return true;
+    }
+    
+    @Override
+  	public boolean onOptionsItemSelected(MenuItem item) {
+  	    switch (item.getItemId()) {
+  		    case R.id.menu_submit:
+  				String content = ((EditText) findViewById(R.id.new_issue_comment_content)).getText().toString();
+  		        AsyncLoader asyncLoader = new AsyncLoader();
+  		        bitbeaker.delKV("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
+  		        asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/", "content=" + URLEncoder.encode(content));
+  		    default:
+  		        return super.onOptionsItemSelected(item);
+  	    }
+  	}
+    
+    private void done(){
+    	Toast.makeText(this, "New comment submitted!", Toast.LENGTH_LONG).show();
+    	setResult(Activity.RESULT_OK, getIntent());
+    	finish();
+    }
+	
+    protected void AsyncLoaderDone(String result) {
+    	super.AsyncLoaderDone(result);
+    	if(result != null && result != "") done();
+	}
+	
+    
+}