Skip to content
Snippets Groups Projects
Commit a2c6d7d9 authored by John Carlson's avatar John Carlson
Browse files

Turns out we don't really need to load the branches

parent d9ec9996
No related branches found
No related tags found
No related merge requests found
Pipeline #
package com.commit451.gitlab.activity;
 
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
Loading
Loading
@@ -225,7 +227,7 @@ public class AddIssueActivity extends MorphActivity {
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
onBackPressed();
}
});
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
Loading
Loading
@@ -315,6 +317,26 @@ public class AddIssueActivity extends MorphActivity {
}
}
 
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle(R.string.discard)
.setMessage(R.string.are_you_sure_you_want_to_discard)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
private void save() {
if (!TextUtils.isEmpty(mTitleInput.getText())) {
mTeleprinter.hideKeyboard();
Loading
Loading
Loading
Loading
@@ -24,15 +24,12 @@ import com.commit451.gitlab.animation.HideRunnable;
import com.commit451.gitlab.event.ProjectReloadEvent;
import com.commit451.gitlab.fragment.BaseFragment;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Branch;
import com.commit451.gitlab.model.api.Project;
import com.commit451.gitlab.navigation.Navigator;
import com.commit451.gitlab.util.IntentUtil;
 
import org.parceler.Parcels;
 
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Callback;
Loading
Loading
@@ -74,39 +71,7 @@ public class ProjectActivity extends BaseActivity {
private final Callback<Project> mProjectCallback = new EasyCallback<Project>() {
@Override
public void success(@NonNull Project response) {
mProject = response;
bindProject();
}
@Override
public void failure(Throwable t) {
Timber.e(t, null);
mProgress.animate()
.alpha(0.0f)
.withEndAction(new HideRunnable(mProgress));
Snackbar.make(mRoot, getString(R.string.connection_error), Snackbar.LENGTH_SHORT)
.show();
}
};
private final Callback<List<Branch>> mBranchesCallback = new EasyCallback<List<Branch>>() {
@Override
public void success(@NonNull List<Branch> response) {
mProgress.animate()
.alpha(0.0f)
.withEndAction(new HideRunnable(mProgress));
for (int i = 0; i < response.size(); i++) {
if (response.get(i).getName().equals(mProject.getDefaultBranch())) {
String ref = response.get(i).getName();
mRef = new Ref(Ref.TYPE_BRANCH, ref);
}
}
if (response.isEmpty()) {
broadcastLoad();
}
bindProject(response);
}
 
@Override
Loading
Loading
@@ -160,7 +125,7 @@ public class ProjectActivity extends BaseActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_project);
ButterKnife.bind(this);
mProject = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_PROJECT));
Project project = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_PROJECT));
 
mToolbar.setNavigationIcon(R.drawable.ic_back_24dp);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
Loading
Loading
@@ -172,11 +137,11 @@ public class ProjectActivity extends BaseActivity {
mToolbar.inflateMenu(R.menu.menu_project);
mToolbar.setOnMenuItemClickListener(mOnMenuItemClickListener);
 
if (mProject == null) {
if (project == null) {
String projectId = getIntent().getStringExtra(EXTRA_PROJECT_ID);
loadProject(projectId);
} else {
bindProject();
bindProject(project);
}
}
 
Loading
Loading
@@ -200,13 +165,6 @@ public class ProjectActivity extends BaseActivity {
App.instance().getGitLab().getProject(projectId).enqueue(mProjectCallback);
}
 
private void loadBranches() {
mProgress.setAlpha(0.0f);
mProgress.setVisibility(View.VISIBLE);
mProgress.animate().alpha(1.0f);
App.instance().getGitLab().getBranches(mProject.getId()).enqueue(mBranchesCallback);
}
private void broadcastLoad() {
App.bus().post(new ProjectReloadEvent(mProject, mRef.getRef()));
}
Loading
Loading
@@ -234,16 +192,16 @@ public class ProjectActivity extends BaseActivity {
return mProject;
}
 
private void bindProject() {
private void bindProject(Project project) {
mProject = project;
mRef = new Ref(Ref.TYPE_BRANCH, mProject.getDefaultBranch());
mToolbar.setTitle(mProject.getName());
mToolbar.setSubtitle(mProject.getNamespace().getName());
setupTabs();
loadBranches();
}
 
private void setupTabs() {
ProjectSectionsPagerAdapter projectSectionsPagerAdapter = new ProjectSectionsPagerAdapter(this, getSupportFragmentManager());
mViewPager.setAdapter(projectSectionsPagerAdapter);
mTabLayout.setupWithViewPager(mViewPager);
}
Loading
Loading
Loading
Loading
@@ -48,6 +48,8 @@ public class PickBranchFragment extends ButterKnifeFragment {
RecyclerView mProjectsListView;
@BindView(R.id.message_text)
TextView mMessageView;
@BindView(R.id.progress)
View mProgress;
 
BranchesAdapter mBranchesAdapter;
 
Loading
Loading
@@ -90,6 +92,7 @@ public class PickBranchFragment extends ButterKnifeFragment {
if (getView() == null) {
return;
}
mProgress.setVisibility(View.VISIBLE);
mMessageView.setVisibility(View.GONE);
 
App.instance().getGitLab().getBranches(mProjectId).enqueue(new EasyCallback<List<Branch>>() {
Loading
Loading
@@ -98,6 +101,7 @@ public class PickBranchFragment extends ButterKnifeFragment {
if (getView() == null) {
return;
}
mProgress.setVisibility(View.GONE);
mBranchesAdapter.setEntries(response);
}
 
Loading
Loading
@@ -107,6 +111,7 @@ public class PickBranchFragment extends ButterKnifeFragment {
if (getView() == null) {
return;
}
mProgress.setVisibility(View.GONE);
mMessageView.setVisibility(View.VISIBLE);
}
});
Loading
Loading
Loading
Loading
@@ -48,6 +48,8 @@ public class PickTagFragment extends ButterKnifeFragment {
RecyclerView mProjectsListView;
@BindView(R.id.message_text)
TextView mMessageView;
@BindView(R.id.progress)
View mProgress;
 
TagsAdapter mTagsAdapter;
 
Loading
Loading
@@ -91,6 +93,7 @@ public class PickTagFragment extends ButterKnifeFragment {
if (getView() == null) {
return;
}
mProgress.setVisibility(View.VISIBLE);
mMessageView.setVisibility(View.GONE);
 
App.instance().getGitLab().getTags(mProjectId).enqueue(new EasyCallback<List<Tag>>() {
Loading
Loading
@@ -99,6 +102,7 @@ public class PickTagFragment extends ButterKnifeFragment {
if (getView() == null) {
return;
}
mProgress.setVisibility(View.GONE);
mTagsAdapter.setEntries(response);
}
 
Loading
Loading
@@ -108,6 +112,7 @@ public class PickTagFragment extends ButterKnifeFragment {
if (getView() == null) {
return;
}
mProgress.setVisibility(View.GONE);
mMessageView.setVisibility(View.VISIBLE);
}
});
Loading
Loading
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
 
<com.commit451.gitlab.view.LabCoatSwipeRefreshLayout
android:id="@+id/swipe_layout"
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent" />
 
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.commit451.gitlab.view.LabCoatSwipeRefreshLayout>
 
<TextView
android:id="@+id/message_text"
Loading
Loading
@@ -24,6 +17,8 @@
android:layout_margin="16dp"
android:gravity="center"
android:text="@string/no_branches"
android:visibility="gone"/>
android:visibility="gone" />
<include layout="@layout/progress"/>
 
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
 
<com.commit451.gitlab.view.LabCoatSwipeRefreshLayout
android:id="@+id/swipe_layout"
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.commit451.gitlab.view.LabCoatSwipeRefreshLayout>
android:layout_height="match_parent" />
 
<TextView
android:id="@+id/message_text"
Loading
Loading
@@ -24,6 +16,8 @@
android:layout_margin="16dp"
android:gravity="center"
android:text="@string/no_tags"
android:visibility="gone"/>
android:visibility="gone" />
<include layout="@layout/progress"/>
 
</FrameLayout>
\ No newline at end of file
Loading
Loading
@@ -140,6 +140,7 @@
<string name="required_field">Required Field</string>
<string name="wait_for_project_to_load">Wait for the project to load!</string>
<string name="error_401">Account credentials no longer valid. Please sign in again</string>
<!-- General -->
<string name="projects">Projects</string>
<string name="no_projects">No projects.</string>
Loading
Loading
@@ -154,6 +155,8 @@
<string name="failed_to_load">Failed to load</string>
<string name="just_now">just now</string>
<string name="failed_to_create_issue">Failed to create or modify issue</string>
<string name="discard">Discard</string>
<string name="are_you_sure_you_want_to_discard">Are you sure you want to discard?</string>
 
<!-- Project -->
<string name="no_readme_found">No README found for project</string>
Loading
Loading
Loading
Loading
@@ -11,6 +11,7 @@
<item name="android:windowContentTransitions" tools:ignore="NewApi">true</item>
<item name="android:windowBackground">@color/window_background</item>
<item name="dialogTheme">@style/AppDialogTheme</item>
<item name="alertDialogTheme">@style/AppDialogTheme</item>
</style>
 
<style name="Activity" parent="AppTheme"/>
Loading
Loading
package com.commit451.gitlab;
 
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
 
import com.bluelinelabs.logansquare.LoganSquare;
import com.commit451.gitlab.api.GitLab;
import com.commit451.gitlab.model.api.FileUploadResponse;
import com.commit451.gitlab.model.api.Group;
import com.commit451.gitlab.model.api.Issue;
import com.commit451.gitlab.model.api.MergeRequest;
Loading
Loading
@@ -20,8 +23,11 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
 
import java.io.ByteArrayOutputStream;
import java.util.List;
 
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Response;
 
import static org.junit.Assert.assertNotNull;
Loading
Loading
@@ -125,4 +131,18 @@ public class ApiTests {
assertNotNull(userFullResponse.body());
}
 
//@Test
public void uploadFile() throws Exception {
Bitmap bitmap = BitmapFactory.decodeResource(RuntimeEnvironment.application.getResources(), R.drawable.ic_fork);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), stream.toByteArray());
Response<FileUploadResponse> userFullResponse = gitLab
.uploadFile(sFakeProject.getId(), requestBody)
.execute();
assertTrue(userFullResponse.isSuccessful());
assertNotNull(userFullResponse.body());
}
}
\ No newline at end of file
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