Skip to content
Snippets Groups Projects
Commit 0aaf2a88 authored by Jawn's avatar Jawn
Browse files

Adapters now update via events posted on the event bus, instead of holding...

Adapters now update via events posted on the event bus, instead of holding static references to adapters
parent 07d75601
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 36 deletions
Loading
Loading
@@ -63,6 +63,7 @@ public class DiffActivity extends BaseActivity {
}
});
 
//TODO make this use RecyclerViews, cause this is insane
GitLabClient.instance().getCommit(Repository.selectedProject.getId(), Repository.selectedCommit.getId(), commitCallback);
GitLabClient.instance().getCommitDiff(Repository.selectedProject.getId(), Repository.selectedCommit.getId(), diffCallback);
}
Loading
Loading
Loading
Loading
@@ -247,10 +247,7 @@ public class IssueActivity extends BaseActivity {
Repository.selectedIssue.setState(stateSpinner.getSelectedItem().toString());
Repository.selectedIssue.setAssignee((User) assigneeSpinner.getSelectedItem());
Repository.selectedIssue.setMilestone((Milestone) milestoneSpinner.getSelectedItem());
if(Repository.issueAdapter != null) {
Repository.issueAdapter.notifyDataSetChanged();
}
//TODO notify the main activity when a issue changes so it will update in the list
}
@Override
Loading
Loading
Loading
Loading
@@ -38,8 +38,6 @@ public class ProjectsAdapter extends RecyclerView.Adapter<ProjectViewHolder> {
//TODO make the event bus control most of this. NO MORE STATIC UI
Repository.selectedProject = Repository.projects.get(position);
Prefs.setLastProject(v.getContext(), Repository.selectedProject.toString());
Repository.issueAdapter = null;
Repository.userAdapter = null;
notifyDataSetChanged();
}
GitLabApp.bus().post(new CloseDrawerEvent());
Loading
Loading
Loading
Loading
@@ -77,14 +77,11 @@ public class AddIssueDialogFragment extends DialogFragment {
@Override
public void success(Issue issue, Response resp) {
if(pd != null && pd.isShowing())
if(pd != null && pd.isShowing()) {
pd.cancel();
if(Repository.issueAdapter != null) {
Repository.issueAdapter.addIssue(issue);
Repository.issueAdapter.notifyDataSetChanged();
}
//TODO update the parent list when a new issue is created
Repository.selectedIssue = issue;
startActivity(new Intent(getActivity(), IssueActivity.class));
Loading
Loading
@@ -95,8 +92,9 @@ public class AddIssueDialogFragment extends DialogFragment {
public void failure(RetrofitError e) {
RetrofitHelper.printDebugInfo(getActivity(), e);
if(pd != null && pd.isShowing())
if(pd != null && pd.isShowing()) {
pd.cancel();
}
Toast.makeText(getActivity(), getString(R.string.connection_error), Toast.LENGTH_SHORT)
.show();
}
Loading
Loading
Loading
Loading
@@ -82,8 +82,9 @@ public class AddUserDialogFragment extends DialogFragment {
if(pd != null && pd.isShowing())
pd.cancel();
if(user.getId() != 0)
Repository.userAdapter.addUser(user);
if(user.getId() != 0) {
//TODO tell the parent to add the user to the list
}
else {
Toast.makeText(getActivity(), getString(R.string.user_error), Toast.LENGTH_SHORT)
.show();
Loading
Loading
Loading
Loading
@@ -13,12 +13,17 @@ import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.gitlab.FileActivity;
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.api.GitLab;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.events.CloseDrawerEvent;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.TreeItem;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.tools.RetrofitHelper;
import com.commit451.gitlab.viewHolders.FileViewHolder;
import com.squareup.otto.Subscribe;
 
import java.util.ArrayList;
import java.util.List;
Loading
Loading
@@ -28,14 +33,17 @@ import butterknife.ButterKnife;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import timber.log.Timber;
 
public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private ArrayList<String> path;
 
@Bind(R.id.error_text) TextView errorText;
@Bind(R.id.swipe_layout) SwipeRefreshLayout swipeLayout;
@Bind(R.id.list) RecyclerView list;
EventReceiver eventReceiver;
public FilesFragment() {}
Loading
Loading
@@ -47,12 +55,13 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
list.setLayoutManager(new LinearLayoutManager(getActivity()));
 
swipeLayout.setOnRefreshListener(this);
path = new ArrayList<>();
if(Repository.selectedProject != null) {
loadData();
}
eventReceiver = new EventReceiver();
GitLabApp.bus().register(eventReceiver);
return view;
}
Loading
Loading
@@ -61,10 +70,12 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
GitLabApp.bus().unregister(eventReceiver);
}
public void loadData() {
path = new ArrayList<>();
Timber.d("loadData");
path = new ArrayList<>();
loadFiles();
}
Loading
Loading
@@ -96,13 +107,20 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
if(swipeLayout != null && swipeLayout.isRefreshing()) {
swipeLayout.setRefreshing(false);
}
list.setAdapter(new FilesAdapter(files));
if (files != null && !files.isEmpty()) {
list.setVisibility(View.VISIBLE);
list.setAdapter(new FilesAdapter(files));
errorText.setVisibility(View.GONE);
} else {
errorText.setVisibility(View.VISIBLE);
}
}
@Override
public void failure(RetrofitError e) {
if(swipeLayout != null && swipeLayout.isRefreshing())
if(swipeLayout != null && swipeLayout.isRefreshing()) {
swipeLayout.setRefreshing(false);
}
if(e.getResponse() != null && e.getResponse().getStatus() == 404) {
errorText.setVisibility(View.VISIBLE);
Loading
Loading
@@ -133,6 +151,14 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
return false;
}
 
private class EventReceiver {
@Subscribe
public void onProjectChanged(ProjectChangedEvent event) {
loadData();
}
}
public class FilesAdapter extends RecyclerView.Adapter<FileViewHolder> {
 
private List<TreeItem> mValues;
Loading
Loading
Loading
Loading
@@ -12,12 +12,15 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.IssuesAdapter;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.Issue;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.tools.RetrofitHelper;
import com.squareup.otto.Subscribe;
 
import java.util.List;
 
Loading
Loading
@@ -33,7 +36,9 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
@Bind(R.id.add_issue_button) View addIssueButton;
@Bind(R.id.list) RecyclerView listView;
@Bind(R.id.swipe_layout) SwipeRefreshLayout swipeLayout;
EventReceiver eventReceiver;
public IssuesFragment() {}
@Override
Loading
Loading
@@ -44,8 +49,12 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
listView.setLayoutManager(new LinearLayoutManager(getActivity()));
swipeLayout.setOnRefreshListener(this);
 
if(Repository.selectedProject != null)
if(Repository.selectedProject != null) {
loadData();
}
eventReceiver = new EventReceiver();
GitLabApp.bus().register(eventReceiver);
return view;
}
Loading
Loading
@@ -54,6 +63,7 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
GitLabApp.bus().unregister(eventReceiver);
}
 
@Override
Loading
Loading
@@ -76,10 +86,7 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
if(swipeLayout != null && swipeLayout.isRefreshing())
swipeLayout.setRefreshing(false);
 
IssuesAdapter issueAdapter = new IssuesAdapter(issues);
listView.setAdapter(new IssuesAdapter(issues));
Repository.issueAdapter = issueAdapter;
 
addIssueButton.setEnabled(true);
}
Loading
Loading
@@ -106,4 +113,12 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
DialogFragment newFragment = AddIssueDialogFragment.newInstance();
newFragment.show(ft, "dialog");
}
private class EventReceiver {
@Subscribe
public void onProjectChanged(ProjectChangedEvent event) {
loadData();
}
}
}
\ No newline at end of file
Loading
Loading
@@ -13,12 +13,15 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.NewUserAdapter;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.tools.RetrofitHelper;
import com.squareup.otto.Subscribe;
 
import java.util.List;
 
Loading
Loading
@@ -35,7 +38,9 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
@Bind(R.id.list) RecyclerView listView;
@Bind(R.id.error_text) TextView errorText;
@Bind(R.id.swipe_layout) SwipeRefreshLayout swipeLayout;
EventReceiver eventReceiver;
public UsersFragment() {}
@Override
Loading
Loading
@@ -49,7 +54,10 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
if(Repository.selectedProject != null) {
loadData();
}
eventReceiver = new EventReceiver();
GitLabApp.bus().register(eventReceiver);
return view;
}
Loading
Loading
@@ -57,6 +65,7 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
GitLabApp.bus().unregister(eventReceiver);
}
@Override
Loading
Loading
@@ -95,8 +104,7 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
listView.setVisibility(View.VISIBLE);
addUserButton.setVisibility(View.VISIBLE);
 
Repository.userAdapter = new NewUserAdapter(users);
listView.setAdapter(Repository.userAdapter);
listView.setAdapter(new NewUserAdapter(users));
addUserButton.setEnabled(true);
}
Loading
Loading
@@ -124,4 +132,12 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
DialogFragment newFragment = AddUserDialogFragment.newInstance();
newFragment.show(ft, "dialog");
}
private class EventReceiver {
@Subscribe
public void onProjectChanged(ProjectChangedEvent event) {
loadData();
}
}
}
\ No newline at end of file
Loading
Loading
@@ -34,9 +34,6 @@ public class Repository {
public static DiffLine selectedCommit;
public static DiffLine newestCommit;
public static IssuesAdapter issueAdapter;
public static NewUserAdapter userAdapter;
public static float displayWidth;
Loading
Loading
@@ -54,9 +51,6 @@ public class Repository {
selectedUser = null;
newestCommit = null;
issueAdapter = null;
userAdapter = null;
}
 
public static void setListViewSize(ListView listView) {
Loading
Loading
Loading
Loading
@@ -104,6 +104,7 @@ public class DiffView extends LinearLayout {
TextView title = new TextView(getContext());
title.setText(diff.getNewPath());
title.setTypeface(title.getTypeface(), Typeface.BOLD);
title.setTextColor(Color.BLACK);
title.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
title.setPadding(PADDING_HEADER_H, PADDING_HEADER_V, PADDING_HEADER_H, PADDING_HEADER_V);
header.addView(title);
Loading
Loading
@@ -121,6 +122,7 @@ public class DiffView extends LinearLayout {
TextView oldLine = new TextView(getContext());
oldLine.setText(line.oldLine);
oldLine.setTextColor(Color.BLACK);
oldLine.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
oldLine.setEms(2);
oldLine.setGravity(Gravity.CENTER_HORIZONTAL);
Loading
Loading
@@ -128,6 +130,7 @@ public class DiffView extends LinearLayout {
TextView newLine = new TextView(getContext());
newLine.setText(line.newLine);
newLine.setTextColor(Color.BLACK);
newLine.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
newLine.setEms(2);
newLine.setGravity(Gravity.CENTER_HORIZONTAL);
Loading
Loading
@@ -135,6 +138,7 @@ public class DiffView extends LinearLayout {
TextView content = new TextView(getContext());
content.setText(line.lineContent);
content.setTextColor(Color.BLACK);
content.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
content.setPadding(PADDING_CONTENT_H, PADDING_CONTENT_V, PADDING_CONTENT_H, PADDING_CONTENT_V);
row.addView(content);
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment