Skip to content
Snippets Groups Projects
Commit a317c0fe authored by Jawnnypoo's avatar Jawnnypoo
Browse files

Move static seleted items into App so that we do not store them statically.

parent 96e895a5
No related branches found
No related tags found
No related merge requests found
Showing
with 83 additions and 63 deletions
Loading
Loading
@@ -12,7 +12,6 @@ import android.widget.LinearLayout;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.model.Diff;
import com.commit451.gitlab.model.DiffLine;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.views.DiffView;
import com.commit451.gitlab.views.MessageView;
 
Loading
Loading
@@ -79,8 +78,8 @@ public class DiffActivity extends BaseActivity {
});
 
//TODO make this use RecyclerViews, cause this is insane
GitLabClient.instance().getCommit(Repository.selectedProject.getId(), commit.getId(), commitCallback);
GitLabClient.instance().getCommitDiff(Repository.selectedProject.getId(), commit.getId(), diffCallback);
GitLabClient.instance().getCommit(GitLabApp.instance().getSelectedProject().getId(), commit.getId(), commitCallback);
GitLabClient.instance().getCommitDiff(GitLabApp.instance().getSelectedProject().getId(), commit.getId(), diffCallback);
}
 
private Callback<DiffLine> commitCallback = new Callback<DiffLine>() {
Loading
Loading
Loading
Loading
@@ -16,7 +16,6 @@ import android.webkit.WebView;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.model.DiffLine;
import com.commit451.gitlab.model.TreeItem;
import com.commit451.gitlab.tools.Repository;
 
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
Loading
Loading
@@ -66,7 +65,7 @@ public class FileActivity extends BaseActivity {
if(file != null) {
setupUI();
GitLabClient.instance().getBlob(
Repository.selectedProject.getId(),
GitLabApp.instance().getSelectedProject().getId(),
commit.getId(),
path + file.getName(),
blobCallback);
Loading
Loading
Loading
Loading
@@ -2,6 +2,9 @@ package com.commit451.gitlab;
 
import android.app.Application;
 
import com.commit451.gitlab.model.Branch;
import com.commit451.gitlab.model.Project;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
import com.squareup.otto.Bus;
 
Loading
Loading
@@ -15,6 +18,34 @@ import timber.log.Timber;
*/
public class GitLabApp extends Application {
 
public Project selectedProject;
public Branch selectedBranch;
public User selectedUser;
public Project getSelectedProject() {
return selectedProject;
}
public void setSelectedProject(Project project) {
selectedProject = project;
}
public Branch getSelectedBranch() {
return selectedBranch;
}
public void setSelectedBranch(Branch branch) {
selectedBranch = branch;
}
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
this.selectedUser = selectedUser;
}
private static Bus bus;
public static Bus bus() {
if (bus == null) {
Loading
Loading
@@ -35,7 +66,7 @@ public class GitLabApp extends Application {
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
Repository.init(this);
Repository.init();
JodaTimeAndroid.init(this);
}
}
Loading
Loading
@@ -18,7 +18,6 @@ import com.commit451.gitlab.model.Issue;
import com.commit451.gitlab.model.Milestone;
import com.commit451.gitlab.model.Note;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
 
import org.parceler.Parcels;
 
Loading
Loading
@@ -89,9 +88,9 @@ public class IssueActivity extends BaseActivity {
private void load() {
swipeRefreshLayout.setRefreshing(true);
//TODO chain these
GitLabClient.instance().getIssueNotes(Repository.selectedProject.getId(), issue.getId(), notesCallback);
GitLabClient.instance().getMilestones(Repository.selectedProject.getId(), milestonesCallback);
GitLabClient.instance().getUsersFallback(Repository.selectedProject.getId(), usersCallback);
GitLabClient.instance().getIssueNotes(GitLabApp.instance().getSelectedProject().getId(), issue.getId(), notesCallback);
GitLabClient.instance().getMilestones(GitLabApp.instance().getSelectedProject().getId(), milestonesCallback);
GitLabClient.instance().getUsersFallback(GitLabApp.instance().getSelectedProject().getId(), usersCallback);
}
 
private void changeStatus() {
Loading
Loading
@@ -145,7 +144,7 @@ public class IssueActivity extends BaseActivity {
imm.hideSoftInputFromWindow(newNoteEdit.getWindowToken(), 0);
newNoteEdit.setText("");
 
GitLabClient.instance().postIssueNote(Repository.selectedProject.getId(), issue.getId(), body, "", noteCallback);
GitLabClient.instance().postIssueNote(GitLabApp.instance().getSelectedProject().getId(), issue.getId(), body, "", noteCallback);
}
private Callback<Note> noteCallback = new Callback<Note>() {
Loading
Loading
Loading
Loading
@@ -60,8 +60,9 @@ public class MainActivity extends BaseActivity {
private final AdapterView.OnItemSelectedListener spinnerItemSelectedListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Repository.selectedBranch = Repository.branches.get(position);
Prefs.setLastBranch(MainActivity.this, Repository.selectedBranch.getName());
Branch selectedBranch = Repository.branches.get(position);
GitLabApp.instance().setSelectedBranch(selectedBranch);
Prefs.setLastBranch(MainActivity.this, selectedBranch.getName());
loadData();
}
 
Loading
Loading
@@ -171,8 +172,9 @@ public class MainActivity extends BaseActivity {
}
private void loadData() {
if(Repository.selectedProject == null)
if(GitLabApp.instance().getSelectedProject() == null) {
return;
}
CommitsFragment commitsFragment = (CommitsFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0");
commitsFragment.loadData();
Loading
Loading
@@ -295,22 +297,25 @@ public class MainActivity extends BaseActivity {
 
if(Repository.projects.size() != 0) {
if(Prefs.getLastProject(MainActivity.this).length() == 0)
Repository.selectedProject = Repository.projects.get(0);
GitLabApp.instance().setSelectedProject(Repository.projects.get(0));
else if(Repository.projects.size() > 0) {
String lastProject = Prefs.getLastProject(MainActivity.this);
 
for(Project p : Repository.projects) {
if(p.toString().equals(lastProject))
Repository.selectedProject = p;
if(p.toString().equals(lastProject)) {
GitLabApp.instance().setSelectedProject(p);
}
}
 
if(Repository.selectedProject == null)
Repository.selectedProject = Repository.projects.get(0);
if(GitLabApp.instance().getSelectedProject() == null) {
GitLabApp.instance().setSelectedProject(Repository.projects.get(0));
}
}
}
if(Repository.selectedProject != null)
GitLabClient.instance().getBranches(Repository.selectedProject.getId(), branchesCallback);
if(GitLabApp.instance().getSelectedProject() != null) {
GitLabClient.instance().getBranches(GitLabApp.instance().getSelectedProject().getId(), branchesCallback);
}
else {
progress.setVisibility(View.GONE);
}
Loading
Loading
@@ -342,7 +347,7 @@ public class MainActivity extends BaseActivity {
 
if(Prefs.getLastBranch(MainActivity.this).equals(spinnerData[i].getName()))
selectedBranchIndex = i;
else if(selectedBranchIndex == -1 && Repository.selectedProject != null && spinnerData[i].getName().equals(Repository.selectedProject.getDefaultBranch()))
else if(selectedBranchIndex == -1 && GitLabApp.instance().getSelectedProject() != null && spinnerData[i].getName().equals(GitLabApp.instance().getSelectedProject().getDefaultBranch()))
selectedBranchIndex = i;
}
 
Loading
Loading
@@ -354,7 +359,7 @@ public class MainActivity extends BaseActivity {
branchSpinner.setOnItemSelectedListener(spinnerItemSelectedListener);
if(Repository.branches.size() == 0) {
Repository.selectedBranch = null;
GitLabApp.instance().setSelectedBranch(null);
loadData();
}
}
Loading
Loading
@@ -364,7 +369,7 @@ public class MainActivity extends BaseActivity {
progress.setVisibility(View.GONE);
 
if(e.getResponse() != null && e.getResponse().getStatus() == 500) {
Repository.selectedBranch = null;
GitLabApp.instance().setSelectedBranch(null);
loadData();
return;
}
Loading
Loading
@@ -384,7 +389,7 @@ public class MainActivity extends BaseActivity {
 
@Subscribe
public void onProjectChanged(ProjectChangedEvent event) {
GitLabClient.instance().getBranches(Repository.selectedProject.getId(), branchesCallback);
GitLabClient.instance().getBranches(GitLabApp.instance().getSelectedProject().getId(), branchesCallback);
}
}
}
Loading
Loading
@@ -34,10 +34,10 @@ public class ProjectsAdapter extends RecyclerView.Adapter<ProjectViewHolder> {
@Override
public void onClick(View v) {
int position = (int) v.getTag(R.id.list_position);
if(Repository.selectedProject == null || !Repository.selectedProject.equals(Repository.projects.get(position))) {
if(GitLabApp.instance().getSelectedProject() == null || !GitLabApp.instance().getSelectedProject().equals(Repository.projects.get(position))) {
//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());
GitLabApp.instance().setSelectedProject(Repository.projects.get(position));
Prefs.setLastProject(v.getContext(), GitLabApp.instance().getSelectedProject().toString());
notifyDataSetChanged();
}
GitLabApp.bus().post(new CloseDrawerEvent());
Loading
Loading
Loading
Loading
@@ -8,11 +8,11 @@ import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
 
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.IssueActivity;
import com.commit451.gitlab.R;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.model.Issue;
import com.commit451.gitlab.tools.Repository;
 
import butterknife.Bind;
import butterknife.ButterKnife;
Loading
Loading
@@ -46,7 +46,7 @@ public class NewIssueDialog extends AppCompatDialog {
progress.setVisibility(View.VISIBLE);
progress.setAlpha(0.0f);
progress.animate().alpha(1.0f);
GitLabClient.instance().postIssue(Repository.selectedProject.getId(), titleInput.getText().toString().trim(), descriptionInput.getText().toString().trim(), "", issueCallback);
GitLabClient.instance().postIssue(GitLabApp.instance().getSelectedProject().getId(), titleInput.getText().toString().trim(), descriptionInput.getText().toString().trim(), "", issueCallback);
}
else {
titleInputLayout.setError(getContext().getString(R.string.required_field));
Loading
Loading
Loading
Loading
@@ -7,6 +7,7 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
 
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.UserAdapter;
import com.commit451.gitlab.api.GitLabClient;
Loading
Loading
@@ -47,7 +48,7 @@ public class NewUserDialog extends AppCompatDialog {
 
@OnClick(R.id.add_button)
public void onAddClick() {
if(Repository.selectedProject.getGroup() == null) {
if(GitLabApp.instance().getSelectedProject().getGroup() == null) {
return;
}
 
Loading
Loading
@@ -58,7 +59,7 @@ public class NewUserDialog extends AppCompatDialog {
long userId = ((User) userSpinner.getSelectedItem()).getId();
String accessLevel = getContext().getResources().getStringArray(R.array.role_values)[roleSpinner.getSelectedItemPosition()];
 
GitLabClient.instance().addGroupMember(Repository.selectedProject.getGroup().getId(), userId, accessLevel, "", userCallback);
GitLabClient.instance().addGroupMember(GitLabApp.instance().getSelectedProject().getGroup().getId(), userId, accessLevel, "", userCallback);
}
 
private Callback<User> userCallback = new Callback<User>() {
Loading
Loading
Loading
Loading
@@ -10,11 +10,11 @@ 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.CommitsAdapter;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.model.DiffLine;
import com.commit451.gitlab.tools.Repository;
 
import java.util.List;
 
Loading
Loading
@@ -39,7 +39,7 @@ public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRe
listView.setLayoutManager(new LinearLayoutManager(getActivity()));
swipeLayout.setOnRefreshListener(this);
 
if(Repository.selectedProject != null) {
if(GitLabApp.instance().getSelectedProject() != null) {
loadData();
}
Loading
Loading
@@ -58,11 +58,11 @@ public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
public void loadData() {
if(Repository.selectedProject == null) {
if(GitLabApp.instance().getSelectedProject() == null) {
return;
}
 
if(Repository.selectedBranch == null) {
if(GitLabApp.instance().getSelectedBranch() == null) {
if(swipeLayout != null && swipeLayout.isRefreshing()) {
swipeLayout.setRefreshing(false);
}
Loading
Loading
@@ -75,7 +75,7 @@ public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRe
swipeLayout.setRefreshing(true);
}
 
GitLabClient.instance().getCommits(Repository.selectedProject.getId(), Repository.selectedBranch.getName(), commitsCallback);
GitLabClient.instance().getCommits(GitLabApp.instance().getSelectedProject().getId(), GitLabApp.instance().getSelectedBranch().getName(), commitsCallback);
}
 
public boolean onBackPressed() {
Loading
Loading
Loading
Loading
@@ -17,7 +17,6 @@ import com.commit451.gitlab.R;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.TreeItem;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.viewHolders.FileViewHolder;
import com.squareup.otto.Subscribe;
 
Loading
Loading
@@ -52,7 +51,7 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
 
swipeLayout.setOnRefreshListener(this);
if(Repository.selectedProject != null) {
if(GitLabApp.instance().getSelectedProject() != null) {
loadData();
}
 
Loading
Loading
@@ -82,8 +81,8 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
private void loadFiles() {
String branch = "master";
if(Repository.selectedBranch != null)
branch = Repository.selectedBranch.getName();
if(GitLabApp.instance().getSelectedBranch() != null)
branch = GitLabApp.instance().getSelectedBranch().getName();
if(swipeLayout != null && !swipeLayout.isRefreshing())
swipeLayout.setRefreshing(true);
Loading
Loading
@@ -93,7 +92,7 @@ public class FilesFragment extends Fragment implements SwipeRefreshLayout.OnRefr
currentPath += p;
}
 
GitLabClient.instance().getTree(Repository.selectedProject.getId(), branch, currentPath, filesCallback);
GitLabClient.instance().getTree(GitLabApp.instance().getSelectedProject().getId(), branch, currentPath, filesCallback);
}
private Callback<List<TreeItem>> filesCallback = new Callback<List<TreeItem>>() {
Loading
Loading
Loading
Loading
@@ -17,7 +17,6 @@ import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.dialogs.NewIssueDialog;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.Issue;
import com.commit451.gitlab.tools.Repository;
import com.squareup.otto.Subscribe;
 
import java.util.List;
Loading
Loading
@@ -48,7 +47,7 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
listView.setLayoutManager(new LinearLayoutManager(getActivity()));
swipeLayout.setOnRefreshListener(this);
 
if(Repository.selectedProject != null) {
if(GitLabApp.instance().getSelectedProject() != null) {
loadData();
}
 
Loading
Loading
@@ -75,7 +74,7 @@ public class IssuesFragment extends Fragment implements SwipeRefreshLayout.OnRef
swipeLayout.setRefreshing(true);
}
 
GitLabClient.instance().getIssues(Repository.selectedProject.getId(), issuesCallback);
GitLabClient.instance().getIssues(GitLabApp.instance().getSelectedProject().getId(), issuesCallback);
}
private Callback<List<Issue>> issuesCallback = new Callback<List<Issue>>() {
Loading
Loading
Loading
Loading
@@ -18,7 +18,6 @@ import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.dialogs.NewUserDialog;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
import com.squareup.otto.Subscribe;
 
import java.util.List;
Loading
Loading
@@ -50,7 +49,7 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
listView.setLayoutManager(new LinearLayoutManager(getActivity()));
swipeLayout.setOnRefreshListener(this);
 
if(Repository.selectedProject != null) {
if(GitLabApp.instance().getSelectedProject() != null) {
loadData();
}
 
Loading
Loading
@@ -77,7 +76,7 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
swipeLayout.setRefreshing(true);
}
if(Repository.selectedProject.getGroup() == null) {
if(GitLabApp.instance().getSelectedProject().getGroup() == null) {
errorText.setVisibility(View.VISIBLE);
errorText.setText(R.string.not_in_group);
listView.setVisibility(View.GONE);
Loading
Loading
@@ -88,7 +87,7 @@ public class UsersFragment extends Fragment implements SwipeRefreshLayout.OnRefr
return;
}
 
GitLabClient.instance().getGroupMembers(Repository.selectedProject.getGroup().getId(), usersCallback);
GitLabClient.instance().getGroupMembers(GitLabApp.instance().getSelectedProject().getGroup().getId(), usersCallback);
}
public Callback<List<User>> usersCallback = new Callback<List<User>>() {
Loading
Loading
package com.commit451.gitlab.tools;
 
import android.content.Context;
import com.commit451.gitlab.model.Branch;
import com.commit451.gitlab.model.Group;
import com.commit451.gitlab.model.Project;
Loading
Loading
@@ -16,19 +14,10 @@ public class Repository {
public static ArrayList<Group> groups;
public static ArrayList<User> users;
public static Project selectedProject;
public static Branch selectedBranch;
public static User selectedUser;
public static void init(Context context) {
public static void init() {
projects = null;
branches = null;
groups = null;
users = null;
selectedProject = null;
selectedBranch = null;
selectedUser = null;
}
}
Loading
Loading
@@ -8,9 +8,9 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.Project;
import com.commit451.gitlab.tools.Repository;
import com.squareup.picasso.Picasso;
 
import butterknife.Bind;
Loading
Loading
@@ -39,7 +39,7 @@ public class ProjectViewHolder extends RecyclerView.ViewHolder {
 
public void bind(Project project) {
title.setText(project.getName());
if (project.equals(Repository.selectedProject)) {
if (project.equals(GitLabApp.instance().getSelectedProject())) {
itemView.setPressed(true);
itemView.setSelected(true);
title.setTextColor(itemView.getResources().getColor(R.color.orange));
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