Commits

Dariusz Kordonski committed 65a6c3d

cleanup + progress bar while refreshing inbox

  • Participants
  • Parent commits 7ea9d84

Comments (0)

Files changed (7)

jiraconnect-android-main/res/values/jconnect_droid_strings.xml

     <string name="jconnect.droid.sending_feedback">Sending feedback for \'%s\'</string>
     <string name="jconnect.droid.feedback_sent">Feedback has been sent</string>
     <string name="jconnect.droid.feedback_sending_failed">Failed to send feedback</string>
+    <string name="jconnect.droid.reply_sent">Reply sent</string>
+    <string name="jconnect.droid.reply_sending_failed">Failed to send reply</string>
+    <string name="jconnect.droid.feedback_retrieving_failed">Error while retrieving feedback items</string>
 
     <string name="jconnect.droid.no_response">No response</string>
     <string name="jconnect.droid.send">Send</string>

jiraconnect-android-main/src/com/atlassian/jconnect/droid/activity/FeedbackInboxActivity.java

 import android.text.format.DateFormat;
 import android.view.LayoutInflater;
 import android.view.Menu;
-import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.Window;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;
 import com.atlassian.jconnect.droid.Api;
 import com.atlassian.jconnect.droid.R;
-import com.atlassian.jconnect.droid.config.BaseConfig;
 import com.atlassian.jconnect.droid.jira.Issue;
 import com.atlassian.jconnect.droid.jira.IssuesWithComments;
 import com.atlassian.jconnect.droid.persistence.IssuePersister;
+import com.atlassian.jconnect.droid.service.AbstractWrappingServiceCallback;
+import com.atlassian.jconnect.droid.service.RemoteFeedbackServiceBinder;
 import com.atlassian.jconnect.droid.task.GetFeedbackItemsTask;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
     private static final String LOG_TAG = "FeedbackInboxActivity";
 
 
-    private BaseConfig baseConfig;
     private IssuePersister issuePersister;
     private IssuesWithComments currentIssues;
     private ProgressDialog spinner;
+    private RemoteFeedbackServiceBinder serviceBinder;
 
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
         setContentView(R.layout.jconnect_droid_feedback_inbox);
-        baseConfig = new BaseConfig(this);
+        initServiceBinder();
         issuePersister = new IssuePersister(this);
         addCreateFeedbackListener();
         initSpinner();
         setListAdapter(new ViewAdapter(this, Lists.<Issue>newArrayList()));
     }
 
+
     @Override
     protected void onResume() {
         super.onResume();
         initLocalIssues();
-        refreshIssuesFromServer();
+        getListView().post(new Runnable() {
+            @Override
+            public void run()
+            {
+                refreshIssuesFromServer();
+            }
+        });
+    }
+
+    @Override
+    protected void onDestroy()
+    {
+        super.onDestroy();
+        serviceBinder.destroy();
+    }
+
+    private void initServiceBinder() {
+        serviceBinder = new RemoteFeedbackServiceBinder(this);
+        serviceBinder.init();
     }
 
     private void initLocalIssues() {
         }
     }
 
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         getMenuInflater().inflate(R.menu.jconnect_feedback_inbox_menu, menu);
 
     private void addCreateFeedbackListener() {
         final View createFeedbackView = findViewById(R.id.jconnect_droid_feedbackinbox_create_feedback);
-        createFeedbackView.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View view) {
+        createFeedbackView.setOnClickListener(new View.OnClickListener()
+        {
+            public void onClick(View view)
+            {
                 startActivity(Api.createFeedbackIntent());
             }
         });
     }
 
     public void refreshIssuesFromServer() {
-        GetFeedbackItemsTask task = new GetFeedbackItemsTask(this);
-        task.execute(new GetFeedbackItemsTask.RequestParams(baseConfig, issuePersister.getLastServerCheck()));
+        setProgressBarIndeterminateVisibility(true);
+        serviceBinder.getService().retrieveFeedbackItems(new IssuesRetrievedCallback(this));
     }
 
     public void onRemoteIssuesRetrieved(GetFeedbackItemsTask.FeedbackItemsResult result) {
         showIssues(result.issues);
-        issuePersister.storeIssuesJson(result.json);
-    }
-
-    public void onServerCheck(GetFeedbackItemsTask.FeedbackItemsResult result) {
-        issuePersister.setLastServerCheck(result.issues.lastUpdated());
     }
 
     private void showIssues(IssuesWithComments issues) {
         }
     }
 
+    private static final class IssuesRetrievedCallback extends AbstractWrappingServiceCallback<FeedbackInboxActivity,IssuesWithComments> {
+
+        public IssuesRetrievedCallback(FeedbackInboxActivity owner) {
+            super(owner);
+        }
+
+        @Override
+        protected void onSuccess(FeedbackInboxActivity owner, IssuesWithComments result) {
+            if (result.hasIssues()) {
+                owner.showIssues(result);
+            }
+            owner.hideSpinner();
+            owner.setProgressBarIndeterminateVisibility(false);
+        }
+
+        @Override
+        protected void onFailure(FeedbackInboxActivity owner, IssuesWithComments result) {
+            owner.hideSpinner();
+            owner.setProgressBarIndeterminateVisibility(false);
+        }
+    }
+
 }

jiraconnect-android-main/src/com/atlassian/jconnect/droid/activity/ViewFeedbackActivity.java

 import android.text.style.StyleSpan;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.*;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
 import com.atlassian.jconnect.droid.Api;
 import com.atlassian.jconnect.droid.R;
 import com.atlassian.jconnect.droid.jira.Comment;
 import com.atlassian.jconnect.droid.jira.Issue;
 import com.atlassian.jconnect.droid.service.AbstractWrappingServiceCallback;
 import com.atlassian.jconnect.droid.service.RemoteFeedbackServiceBinder;
-import com.atlassian.jconnect.droid.ui.UiUtil;
 import com.google.common.base.Strings;
 
 import static com.atlassian.jconnect.droid.ui.UiUtil.findTextView;
         protected void onSuccess(ViewFeedbackActivity owner, Comment result) {
             owner.getAdapter().add(result);
             owner.getAdapter().notifyDataSetChanged();
-            UiUtil.alert(owner, "Reply sent");
-        }
-
-        @Override
-        protected void onFailure(ViewFeedbackActivity owner, Comment result) {
-            UiUtil.alert(owner, "Failed to reply");
         }
     }
 
-
 }
 

jiraconnect-android-main/src/com/atlassian/jconnect/droid/service/AbstractWrappingServiceCallback.java

     }
 
     @Override
-    public void onResult(Status status, R result) {
+    public final void onResult(Status status, R result) {
         final O owner = ownerReference.get();
         if (owner != null) {
             if (status == ServiceCallback.Status.SUCCESS) {

jiraconnect-android-main/src/com/atlassian/jconnect/droid/service/RemoteFeedbackService.java

 import android.content.Intent;
 import android.os.Binder;
 import android.os.IBinder;
+import android.util.Log;
 import com.atlassian.jconnect.droid.R;
 import com.atlassian.jconnect.droid.config.BaseConfig;
 import com.atlassian.jconnect.droid.config.UniqueId;
 import com.atlassian.jconnect.droid.persistence.IssuePersister;
 import com.atlassian.jconnect.droid.task.CreateFeedbackParams;
 import com.atlassian.jconnect.droid.task.CreateFeedbackTask;
+import com.atlassian.jconnect.droid.task.GetFeedbackItemsTask;
 import com.atlassian.jconnect.droid.task.ReplyTask;
 import com.atlassian.jconnect.droid.ui.UiUtil;
 
  */
 public class RemoteFeedbackService extends Service {
 
+    private static final String LOG_TAG = "RemoteFeedbackService";
 
     private Binding binding;
 
         uniqueId = new UniqueId(this);
         baseConfig = new BaseConfig(this);
         issuePersister = new IssuePersister(this);
+        Log.i(LOG_TAG, "created");
     }
 
     @Override
     }
 
 
-    public void retrieveFeedbackItems(ServiceCallback<IssuesWithComments> issues) {
-        // TODO
+    public void retrieveFeedbackItems(final ServiceCallback<IssuesWithComments> callback) {
+        final ServiceCallback<GetFeedbackItemsTask.FeedbackItemsResult> wrappingCallback =
+                new ServiceCallback<GetFeedbackItemsTask.FeedbackItemsResult>() {
+
+            @Override
+            public void onResult(Status status, GetFeedbackItemsTask.FeedbackItemsResult result) {
+                if (status == Status.SUCCESS) {
+                    issuePersister.setLastServerCheck(result.issues.lastUpdated());
+                    if (result.issues.hasIssues()) {
+                        issuePersister.storeIssuesJson(result.json);
+                    }
+                } else {
+                    UiUtil.alert(RemoteFeedbackService.this, R.string.jconnect_droid_feedback_retrieving_failed);
+                }
+                if (callback != null) {
+                    callback.onResult(status, result.issues);
+                }
+            }
+        };
+        new GetFeedbackItemsTask(wrappingCallback).execute(new GetFeedbackItemsTask.RequestParams(baseConfig, issuePersister.getLastServerCheck()));
     }
 
 
             public void onResult(Status status, ReplyTask.Result result) {
                 if (status == Status.SUCCESS) {
                     issuePersister.addCreatedComment(result.issueKey(), result.reply());
+                    UiUtil.alert(RemoteFeedbackService.this, R.string.jconnect_droid_reply_sent);
+                } else {
+                    UiUtil.alert(RemoteFeedbackService.this, R.string.jconnect_droid_reply_sending_failed);
                 }
                 if (callback != null) {
                     callback.onResult(status, result.reply());

jiraconnect-android-main/src/com/atlassian/jconnect/droid/service/RemoteFeedbackServiceBinder.java

 package com.atlassian.jconnect.droid.service;
 
-import android.app.Service;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;

jiraconnect-android-main/src/com/atlassian/jconnect/droid/task/GetFeedbackItemsTask.java

 import android.net.http.AndroidHttpClient;
 import android.os.AsyncTask;
 import android.util.Log;
-import com.atlassian.jconnect.droid.activity.FeedbackInboxActivity;
 import com.atlassian.jconnect.droid.config.BaseConfig;
 import com.atlassian.jconnect.droid.jira.IssueParser;
 import com.atlassian.jconnect.droid.jira.IssuesWithComments;
-import com.atlassian.jconnect.droid.ui.UiUtil;
+import com.atlassian.jconnect.droid.service.ServiceCallback;
 import org.apache.http.HttpResponse;
 import org.apache.http.StatusLine;
 import org.apache.http.client.methods.HttpGet;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
-import java.lang.ref.WeakReference;
 import java.net.URI;
 import java.util.Date;
 
 
     private static final String LOG_TAG = GetFeedbackItemsTask.class.getSimpleName();
 
-    private final WeakReference<FeedbackInboxActivity> activityRef;
+    private final ServiceCallback<FeedbackItemsResult> callback;
 
-    public GetFeedbackItemsTask(FeedbackInboxActivity activity) {
-        this.activityRef = new WeakReference<FeedbackInboxActivity>(activity);
+    public GetFeedbackItemsTask(ServiceCallback<FeedbackItemsResult> callback) {
+        this.callback = callback;
     }
 
     public static final class RequestParams {
     @Override
     protected void onPostExecute(FeedbackItemsResult result) {
         logResult(result);
-        FeedbackInboxActivity activity = activityRef.get();
-        if (activity != null) {
-            if (result == null) {
-                activity.hideSpinner();
-                // TODO i18n
-                UiUtil.alert(activity, "Error while retrieving feedback items.");
-            } else {
-                activity.onServerCheck(result);
-                activity.hideSpinner();
-                if (result.issues.hasIssues()) {
-                    activity.onRemoteIssuesRetrieved(result);
-                }
-            }
+        if (result != null) {
+            callback.onResult(ServiceCallback.Status.SUCCESS, result);
         } else {
-            Log.w(LOG_TAG, "Activity is gone, cannot pass results");
+            callback.onResult(ServiceCallback.Status.FAILURE, result);
         }
     }