Commits

Tobias Duehr committed 30f8bed

- Logout/Login actions
- Wiki links work again, but the solution is not optimal
- Ripped the standard menu from MyActivity, this results in a lot
of duplicated code, but was neccessary for custom actions
- Removed some unneded icons, added some others ;)

  • Participants
  • Parent commits 6bb7fe2

Comments (0)

Files changed (16)

AndroidManifest.xml

     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 
     <application android:label="@string/app_name" android:theme="@style/Theme.Sherlock.Light.DarkActionBar" android:icon="@drawable/icon" android:name="Bitbeaker">
-        <activity android:label="@string/app_name" android:name="LoginActivity" android:noHistory="true">
+        <activity android:label="@string/app_name" android:name="LoginActivity">
         	<meta-data android:name="android.app.default_searchable" android:value=".SearchableActivity" />
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

res/drawable-hdpi/ic_menu_refresh.png

Removed
Old image

res/drawable-hdpi/ic_menu_share.png

Removed
Old image

res/drawable-hdpi/ic_menu_stop.png

Removed
Old image

res/drawable-hdpi/key_stroke_32x32.png

Added
New image

res/drawable-hdpi/lightbulb_20x32.png

Removed
Old image

res/drawable-hdpi/loop_alt2_32x28.png

Added
New image

res/drawable-hdpi/user_24x32.png

Added
New image

res/drawable-mdpi/ic_menu_search_holo_dark.png

Removed
Old image

res/menu/mainmenu.xml

 <?xml version="1.0" encoding="utf-8"?>
 <menu
   xmlns:android="http://schemas.android.com/apk/res/android">
-  <item android:id="@+id/menu_search" android:showAsAction="always" android:icon="@drawable/ic_menu_search_holo_dark"></item><item android:icon="@drawable/ic_menu_refresh" android:id="@+id/menu_refresh" android:title="@string/clear_cache"></item>
-    <item android:title="@string/log_out" android:id="@+id/menu_logout" android:icon="@drawable/ic_menu_stop"></item>
+  <item android:id="@+id/menu_search" android:showAsAction="always" android:icon="@drawable/magnifying_glass_32x32" android:title="@string/search_repo"></item><item android:id="@+id/menu_login" android:title="@string/login" android:showAsAction="ifRoom" android:icon="@drawable/key_stroke_32x32"></item><item android:title="@string/log_out" android:id="@+id/menu_logout" android:icon="@drawable/user_24x32" android:showAsAction="ifRoom|withText"></item><item android:icon="@drawable/loop_alt2_32x28" android:id="@+id/menu_refresh" android:title="@string/clear_cache" android:showAsAction="ifRoom"></item>
+    
+  
     
 </menu>

src/com/saibotd/bitbeaker/Bitbeaker.java

 
 	public void onCreate(){
 		super.onCreate();
-		Log.d("GS", "lol");
 		settings = getSharedPreferences("bitbeaker", 0);
 		kv = new ArrayList<KeyValueCache>();
 	}

src/com/saibotd/bitbeaker/LoginActivity.java

 
 import javax.net.ssl.HttpsURLConnection;
 
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.Intent;
 		findViewById(R.id.login_button).setOnClickListener(clickListener);
 		getSupportActionBar().setDisplayHomeAsUpEnabled(false);
 	}
+	
+    @Override
+	public boolean onCreateOptionsMenu(Menu menu) {
+		MenuInflater inflater = getSupportMenuInflater();
+		inflater.inflate(R.menu.mainmenu, menu);
+		return true;
+	}
+	
+	@Override
+    public boolean onPrepareOptionsMenu (Menu menu) {
+        if (bitbeaker.getUsername() == ""){
+        	menu.getItem(1).setVisible(false);
+        	menu.getItem(2).setVisible(false);
+        }
+        else{
+        	menu.getItem(1).setVisible(false);
+        	menu.getItem(2).setVisible(true);
+        	menu.getItem(2).setTitle(bitbeaker.getUsername());
+        }
+        menu.getItem(3).setVisible(false);
+        return true;
+    }
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item) {
+		// Handle item selection
+		switch (item.getItemId()) {
+		case R.id.menu_logout:
+			logOut(false);
+			return true;
+		case R.id.menu_search:
+			onSearchRequested();
+			return true;
+		case android.R.id.home:
+			return true;
+		default:
+			return super.onOptionsItemSelected(item);
+		}
+	}
 
 	private void logOut(Boolean isError) {
 		if (progressDialog != null)

src/com/saibotd/bitbeaker/MyActivity.java

 import android.app.ProgressDialog;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
-import android.content.Intent;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.util.Base64;
 import android.util.Log;
 
 import com.actionbarsherlock.app.SherlockActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
 import com.actionbarsherlock.view.Window;
 
 public class MyActivity extends SherlockActivity {
 		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 	}
 
-	public void onDestroy() {
-		Log.d("Activity", "Destroy");
-		super.onDestroy();
-	}
-
-	@Override
-	public boolean onCreateOptionsMenu(Menu menu) {
-		MenuInflater inflater = getSupportMenuInflater();
-		inflater.inflate(R.menu.mainmenu, menu);
-		return true;
-	}
-
-	@Override
-	public boolean onOptionsItemSelected(MenuItem item) {
-		// Handle item selection
-		switch (item.getItemId()) {
-		case R.id.menu_refresh:
-			bitbeaker.clearKV();
-			return true;
-		case R.id.menu_logout:
-			Intent intent = new Intent(this, LoginActivity.class);
-			Bundle b = new Bundle();
-			b.putBoolean("logout", true);
-			intent.putExtras(b);
-			startActivity(intent);
-			finish();
-			return true;
-		case R.id.menu_search:
-			onSearchRequested();
-			return true;
-		case android.R.id.home:
-			finish();
-			return true;
-		default:
-			return super.onOptionsItemSelected(item);
-		}
-	}
-
 	protected void AsyncLoaderDone(String result) {
 		Log.d("RESULT", result);
-		setSupportProgressBarIndeterminateVisibility(false);
-		if (progressDialog != null)
-			progressDialog.dismiss();
 		if (ignoreError == false && (result == null || result.length() == 0)) {
 			try {
 				alertDialog = new AlertDialog.Builder(this).create();
 				alertDialog
 						.setMessage("There was a problem retrieving and/or processing data from Bitbucket.org. Checking your data connectivity and trying again might help.");
 				alertDialog.show();
-			} catch (Exception e) {
-			}
+			} catch (Exception e) {}
 		}
 		ignoreError = false;
 	}
 		
 		@Override
 		protected void onPreExecute() {
-			setSupportProgressBarIndeterminateVisibility(true);
+			try{
+				setSupportProgressBarIndeterminateVisibility(true);
+			} catch(Exception e){  }
 		}
 
 		@Override
 		protected void onPostExecute(String result) {
 			AsyncLoaderDone(result);
+			try{
+				setSupportProgressBarIndeterminateVisibility(false);
+			} catch(Exception e){  }
+			if (progressDialog != null)
+				progressDialog.dismiss();
 		}
 
 		public void onCancel(DialogInterface arg0) {

src/com/saibotd/bitbeaker/RepositoriesActivity.java

 import android.widget.TextView;
 
 import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
 
 public class RepositoriesActivity extends MyActivity {
 	
         
         setContentView(R.layout.repositories);
         
-        AsyncLoader asyncLoader = new AsyncLoader();
-        asyncLoader.execute("https://api.bitbucket.org/1.0/user/repositories/");
         getSupportActionBar().setDisplayHomeAsUpEnabled(false);
         ActionBar actionBar = getSupportActionBar();
         actionBar.setSubtitle("Your repositories");
+        
+        loadRepos();
     }
     
+    private void loadRepos(){
+    	AsyncLoader asyncLoader = new AsyncLoader();
+ 		asyncLoader.execute("https://api.bitbucket.org/1.0/user/repositories/");
+    } 
+    
+    @Override
+	public boolean onCreateOptionsMenu(Menu menu) {
+		MenuInflater inflater = getSupportMenuInflater();
+		inflater.inflate(R.menu.mainmenu, menu);
+		return true;
+	}
+	
+	@Override
+    public boolean onPrepareOptionsMenu (Menu menu) {
+        if (bitbeaker.getUsername() == ""){
+        	menu.getItem(1).setVisible(true);
+        	menu.getItem(2).setVisible(false);
+        }
+        else{
+        	menu.getItem(1).setVisible(false);
+        	menu.getItem(2).setVisible(true);
+        	menu.getItem(2).setTitle(bitbeaker.getUsername());
+        }
+        return true;
+    }
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item) {
+		// Handle item selection
+		switch (item.getItemId()) {
+		case R.id.menu_refresh:
+			bitbeaker.clearKV();
+			loadRepos();
+			return true;
+		case R.id.menu_login:
+			startActivity(new Intent(this, LoginActivity.class));
+			return true;
+		case R.id.menu_logout:
+			Intent intent = new Intent(this, LoginActivity.class);
+			Bundle b = new Bundle();
+			b.putBoolean("logout", true);
+			intent.putExtras(b);
+			startActivity(intent);
+			finish();
+			return true;
+		case R.id.menu_search:
+			onSearchRequested();
+			return true;
+		case android.R.id.home:
+			finish();
+			return true;
+		default:
+			return super.onOptionsItemSelected(item);
+		}
+	}
+    
     protected void AsyncLoaderDone(String result){
     	super.AsyncLoaderDone(result);
     	ListView listView = (ListView) findViewById(R.id.repositories_list);

src/com/saibotd/bitbeaker/SearchableActivity.java

 import org.json.JSONException;
 import org.json.JSONObject;
 
-import android.app.ProgressDialog;
 import android.app.SearchManager;
 import android.content.Context;
 import android.content.Intent;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+
 public class SearchableActivity extends MyActivity {
 	
 	private JSONArray lastResult;
           if(query.length() >= 3){
 	          AsyncLoader asyncLoader = new AsyncLoader();
 	          asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/?name=" + query);
-	          progressDialog = ProgressDialog.show(this, "", "Searching ...", true);
 	          setTitle("Results for \"" + query + "\"");
           } else {
         	  Toast.makeText(this, "Please enter at least 3 letters.", Toast.LENGTH_LONG).show();
         }
     }
     
+    @Override
+	public boolean onCreateOptionsMenu(Menu menu) {
+		MenuInflater inflater = getSupportMenuInflater();
+		inflater.inflate(R.menu.mainmenu, menu);
+		return true;
+	}
+	
+	@Override
+    public boolean onPrepareOptionsMenu (Menu menu) {
+        if (bitbeaker.getUsername() == ""){
+        	menu.getItem(1).setVisible(true);
+        	menu.getItem(2).setVisible(false);
+        }
+        else{
+        	menu.getItem(1).setVisible(false);
+        	menu.getItem(2).setVisible(true);
+        	menu.getItem(2).setTitle(bitbeaker.getUsername());
+        }
+        menu.getItem(3).setVisible(false);
+        return true;
+    }
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item) {
+		// Handle item selection
+		switch (item.getItemId()) {
+		case R.id.menu_login:
+			startActivity(new Intent(this, LoginActivity.class));
+			return true;
+		case R.id.menu_logout:
+			Intent intent = new Intent(this, LoginActivity.class);
+			Bundle b = new Bundle();
+			b.putBoolean("logout", true);
+			intent.putExtras(b);
+			startActivity(intent);
+			finish();
+			return true;
+		case R.id.menu_search:
+			onSearchRequested();
+			return true;
+		case android.R.id.home:
+			finish();
+			return true;
+		default:
+			return super.onOptionsItemSelected(item);
+		}
+	}
+    
     protected void AsyncLoaderDone(String result){
     	super.AsyncLoaderDone(result);
     	ListView listView = (ListView) findViewById(R.id.repositories_list);

src/com/saibotd/bitbeaker/WikiActivity.java

 	public boolean onCreateOptionsMenu(Menu menu) {
 		return false;
 	}
+    
+    public void _openWikiLink(String url) {
+		AsyncLoader asyncLoader = new AsyncLoader();
+		asyncLoader.execute(url);
+	}
 
 	public void AsyncLoaderDone(String result) {
 		super.AsyncLoaderDone(result);
 
 		@SuppressWarnings("unused")
 		public void openWikiLink(final String url) {
-			AsyncLoader asyncLoader = new AsyncLoader();
-			asyncLoader.execute(url);
+			_openWikiLink(url); // This maybe changes the context
 		}
 	}
 }