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

Create authenticator for that rare time when someone would invalidate their private token

parent ee490860
No related branches found
No related tags found
No related merge requests found
Showing
with 115 additions and 61 deletions
Loading
Loading
@@ -38,7 +38,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:robolectric:3.1'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
 
Loading
Loading
@@ -55,8 +55,8 @@ dependencies {
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2'
compile 'com.squareup:otto:1.3.8'
Loading
Loading
@@ -67,16 +67,16 @@ dependencies {
compile 'com.jakewharton.timber:timber:4.1.2'
apt 'com.bluelinelabs:logansquare-compiler:1.3.7'
compile 'com.bluelinelabs:logansquare:1.3.7'
compile 'net.danlew:android.joda:2.9.3'
compile 'org.parceler:parceler-api:1.0.4'
apt 'org.parceler:parceler:1.0.4'
compile 'net.danlew:android.joda:2.9.3.1'
compile 'org.parceler:parceler-api:1.1.5'
apt 'org.parceler:parceler:1.1.5'
compile 'com.commit451:bypasses:1.0.1'
compile 'com.commit451:easel:0.0.5'
compile 'com.commit451:foregroundviews:1.0.0'
compile 'com.commit451:elasticdragdismisslayout:1.0.2'
compile 'com.commit451:adapterlayout:1.0.1'
compile 'com.github.Commit451:Gimbal:1.0.0'
compile 'com.github.Commit451:Teleprinter:1.0.1'
compile 'com.github.Commit451:Teleprinter:1.0.2'
compile 'com.github.Commit451:BypassPicassoImageGetter:1.0.0'
compile 'com.github.Commit451:Jounce:1.0.1'
compile 'com.github.Commit451:EasyCallback:1.0.0'
Loading
Loading
Loading
Loading
@@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
 
<application
android:name=".LabCoatApp"
android:name=".App"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
Loading
Loading
Loading
Loading
@@ -24,7 +24,7 @@ import timber.log.Timber;
/**
* App for one time init things and to house singletons
*/
public class LabCoatApp extends Application {
public class App extends Application {
 
/**
* Register our type converters on our singleton LoganSquare create
Loading
Loading
@@ -41,8 +41,8 @@ public class LabCoatApp extends Application {
return sBus;
}
 
private static LabCoatApp sInstance;
public static LabCoatApp instance() {
private static App sInstance;
public static App instance() {
return sInstance;
}
 
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.Toolbar;
import android.view.View;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.event.CloseDrawerEvent;
Loading
Loading
@@ -44,7 +44,7 @@ public class ActivityActivity extends BaseActivity {
ButterKnife.bind(this);
 
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
 
mToolbar.setTitle(R.string.nav_activity);
mToolbar.setNavigationIcon(R.drawable.ic_menu_24dp);
Loading
Loading
@@ -75,7 +75,7 @@ public class ActivityActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
private class EventReceiver {
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ import android.widget.FrameLayout;
import android.widget.Spinner;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.AddIssueLabelAdapter;
import com.commit451.gitlab.adapter.AssigneeSpinnerAdapter;
Loading
Loading
@@ -185,9 +185,9 @@ public class AddIssueActivity extends MorphActivity {
@Override
public void success(@NonNull Issue response) {
if (mIssue == null) {
LabCoatApp.bus().post(new IssueCreatedEvent(response));
App.bus().post(new IssueCreatedEvent(response));
} else {
LabCoatApp.bus().post(new IssueChangedEvent(response));
App.bus().post(new IssueChangedEvent(response));
}
dismiss();
}
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ import android.widget.EditText;
import android.widget.FrameLayout;
 
import com.commit451.easel.Easel;
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.easycallback.EasyCallback;
import com.commit451.gitlab.api.GitLabClient;
Loading
Loading
@@ -114,9 +114,9 @@ public class AddMilestoneActivity extends MorphActivity {
public void success(@NonNull Milestone response) {
mProgress.setVisibility(View.GONE);
if (mMilestone == null) {
LabCoatApp.bus().post(new MilestoneCreatedEvent(response));
App.bus().post(new MilestoneCreatedEvent(response));
} else {
LabCoatApp.bus().post(new MilestoneChangedEvent(response));
App.bus().post(new MilestoneChangedEvent(response));
}
finish();
}
Loading
Loading
Loading
Loading
@@ -19,7 +19,7 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.UsersAdapter;
import com.commit451.gitlab.animation.HideRunnable;
Loading
Loading
@@ -224,7 +224,7 @@ public class AddUserActivity extends MorphActivity {
.show();
mAccessDialog.dismiss();
dismiss();
LabCoatApp.bus().post(new MemberAddedEvent(response));
App.bus().post(new MemberAddedEvent(response));
}
 
@Override
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.BuildSectionsPagerAdapter;
import com.commit451.easycallback.EasyCallback;
Loading
Loading
@@ -62,7 +62,7 @@ public class BuildActivity extends BaseActivity {
mProgress.setVisibility(View.GONE);
Snackbar.make(mRoot, R.string.build_started, Snackbar.LENGTH_LONG)
.show();
LabCoatApp.bus().post(new BuildChangedEvent(response));
App.bus().post(new BuildChangedEvent(response));
}
 
@Override
Loading
Loading
@@ -80,7 +80,7 @@ public class BuildActivity extends BaseActivity {
mProgress.setVisibility(View.GONE);
Snackbar.make(mRoot, R.string.build_erased, Snackbar.LENGTH_LONG)
.show();
LabCoatApp.bus().post(new BuildChangedEvent(response));
App.bus().post(new BuildChangedEvent(response));
}
 
@Override
Loading
Loading
@@ -98,7 +98,7 @@ public class BuildActivity extends BaseActivity {
mProgress.setVisibility(View.GONE);
Snackbar.make(mRoot, R.string.build_canceled, Snackbar.LENGTH_LONG)
.show();
LabCoatApp.bus().post(new BuildChangedEvent(response));
App.bus().post(new BuildChangedEvent(response));
}
 
@Override
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.GroupAdapter;
import com.commit451.easycallback.EasyCallback;
Loading
Loading
@@ -123,7 +123,7 @@ public class GroupsActivity extends BaseActivity {
setContentView(R.layout.activity_groups);
ButterKnife.bind(this);
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
 
mToolbar.setTitle(R.string.nav_groups);
mToolbar.setNavigationIcon(R.drawable.ic_menu_24dp);
Loading
Loading
@@ -156,7 +156,7 @@ public class GroupsActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
private void load() {
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.IssueDetailsAdapter;
import com.commit451.easycallback.EasyCallback;
Loading
Loading
@@ -224,8 +224,8 @@ public class IssueActivity extends BaseActivity {
public void success(@NonNull Issue response) {
mProgress.setVisibility(View.GONE);
mIssue = response;
LabCoatApp.bus().post(new IssueChangedEvent(mIssue));
LabCoatApp.bus().post(new IssueReloadEvent());
App.bus().post(new IssueChangedEvent(mIssue));
App.bus().post(new IssueReloadEvent());
setOpenCloseMenuStatus();
loadNotes();
}
Loading
Loading
@@ -280,7 +280,7 @@ public class IssueActivity extends BaseActivity {
ButterKnife.bind(this);
mTeleprinter = new Teleprinter(this);
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
 
mToolbar.setNavigationIcon(R.drawable.ic_back_24dp);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
Loading
Loading
@@ -370,7 +370,7 @@ public class IssueActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
private void bindProject() {
Loading
Loading
Loading
Loading
@@ -26,7 +26,7 @@ import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.api.GitLabClient;
import com.commit451.gitlab.data.Prefs;
Loading
Loading
@@ -291,9 +291,9 @@ public class LoginActivity extends BaseActivity {
mAccount.setLastUsed(new Date());
Prefs.addAccount(LoginActivity.this, mAccount);
GitLabClient.setAccount(mAccount);
LabCoatApp.bus().post(new LoginEvent(mAccount));
App.bus().post(new LoginEvent(mAccount));
//This is mostly for if projects already exists, then we will reload the data
LabCoatApp.bus().post(new ReloadDataEvent());
App.bus().post(new ReloadDataEvent());
NavigationManager.navigateToStartingActivity(LoginActivity.this);
finish();
}
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.MergeRequestSectionsPagerAdapter;
import com.commit451.easycallback.EasyCallback;
Loading
Loading
@@ -62,7 +62,7 @@ public class MergeRequestActivity extends BaseActivity {
mProgress.setVisibility(View.GONE);
Snackbar.make(mRoot, R.string.merge_request_accepted, Snackbar.LENGTH_LONG)
.show();
LabCoatApp.bus().post(new MergeRequestChangedEvent(response));
App.bus().post(new MergeRequestChangedEvent(response));
}
 
@Override
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.DividerItemDecoration;
import com.commit451.gitlab.adapter.MilestoneIssuesAdapter;
Loading
Loading
@@ -134,7 +134,7 @@ public class MilestoneActivity extends BaseActivity {
public void success(@NonNull Milestone response) {
mProgress.setVisibility(View.GONE);
mMilestone = response;
LabCoatApp.bus().post(new MilestoneChangedEvent(mMilestone));
App.bus().post(new MilestoneChangedEvent(mMilestone));
setOpenCloseMenuStatus();
}
 
Loading
Loading
@@ -166,7 +166,7 @@ public class MilestoneActivity extends BaseActivity {
setContentView(R.layout.activity_milestone);
ButterKnife.bind(this);
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
 
mProject = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_PROJECT));
mMilestone = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_MILESTONE));
Loading
Loading
@@ -217,7 +217,7 @@ public class MilestoneActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
private void bind(Milestone milestone) {
Loading
Loading
Loading
Loading
@@ -20,7 +20,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.SectionsPagerAdapter;
import com.commit451.gitlab.animation.HideRunnable;
Loading
Loading
@@ -221,7 +221,7 @@ public class ProjectActivity extends BaseActivity {
}
 
private void broadcastLoad() {
LabCoatApp.bus().post(new ProjectReloadEvent(mProject, mBranchName));
App.bus().post(new ProjectReloadEvent(mProject, mBranchName));
}
 
@Override
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.ProjectsPagerAdapter;
import com.commit451.gitlab.event.CloseDrawerEvent;
Loading
Loading
@@ -58,7 +58,7 @@ public class ProjectsActivity extends BaseActivity {
setContentView(R.layout.activity_projects);
ButterKnife.bind(this);
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
 
mToolbar.setTitle(R.string.projects);
mToolbar.setNavigationIcon(R.drawable.ic_menu_24dp);
Loading
Loading
@@ -77,7 +77,7 @@ public class ProjectsActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
private class EventReceiver {
Loading
Loading
package com.commit451.gitlab.api;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.model.Account;
import com.commit451.gitlab.provider.OkHttpClientProvider;
import com.commit451.gitlab.provider.SimpleXmlProvider;
Loading
Loading
@@ -79,7 +79,7 @@ public final class GitLabClient {
 
public static Picasso getPicasso(Account account) {
OkHttpClient client = OkHttpClientProvider.getInstance(account);
return new Picasso.Builder(LabCoatApp.instance())
return new Picasso.Builder(App.instance())
.downloader(new OkHttp3Downloader(client))
.build();
}
Loading
Loading
@@ -95,7 +95,7 @@ public final class GitLabClient {
 
private static void checkAccountSet() {
if (sAccount == null) {
List<Account> accounts = Account.getAccounts(LabCoatApp.instance());
List<Account> accounts = Account.getAccounts(App.instance());
if (accounts.isEmpty()) {
throw new IllegalStateException("No accounts found");
}
Loading
Loading
package com.commit451.gitlab.api;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.activity.LoginActivity;
import com.commit451.gitlab.data.Prefs;
import com.commit451.gitlab.model.Account;
import java.io.IOException;
import okhttp3.Authenticator;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
/**
* If it detects a 401, redirect the user to the login screen, clearing the stack.
* Kinda a weird global way of forcing the user to the login screen if their auth has expired
*/
public class OpenSignInAuthenticator implements Authenticator {
private Account mAccount;
public OpenSignInAuthenticator(Account account) {
mAccount = account;
}
@Override
public Request authenticate(Route route, Response response) throws IOException {
//Special case for if someone just put in their username or password wrong
if (!"session".equals(response.request().url().pathSegments().get(response.request().url().pathSegments().size()-1))) {
//Off the background thread
Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
//Remove the account, so that the user can sign in again
Prefs.removeAccount(App.instance(), mAccount);
Toast.makeText(App.instance(), R.string.error_401, Toast.LENGTH_LONG)
.show();
Intent intent = LoginActivity.newIntent(App.instance());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
App.instance().startActivity(intent);
}
});
}
return null;
}
}
Loading
Loading
@@ -5,7 +5,7 @@ import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.event.ReloadDataEvent;
import com.squareup.otto.Subscribe;
 
Loading
Loading
@@ -18,13 +18,13 @@ public class BaseFragment extends Fragment{
super.onViewCreated(view, savedInstanceState);
 
mBaseEventReceiever = new EventReceiver();
LabCoatApp.bus().register(mBaseEventReceiever);
App.bus().register(mBaseEventReceiever);
}
 
@Override
public void onDestroyView() {
super.onDestroyView();
LabCoatApp.bus().unregister(mBaseEventReceiever);
App.bus().unregister(mBaseEventReceiever);
}
 
protected void loadData() {
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.BuildArtifactsAdapter;
import com.commit451.gitlab.adapter.DividerItemDecoration;
Loading
Loading
@@ -141,13 +141,13 @@ public class BuildArtifactsFragment extends ButterKnifeFragment {
});
loadData();
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
}
 
@Override
public void onDestroyView() {
super.onDestroyView();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
@Override
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.gitlab.LabCoatApp;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.easycallback.EasyCallback;
import com.commit451.gitlab.api.GitLabClient;
Loading
Loading
@@ -77,7 +77,7 @@ public class BuildDescriptionFragment extends ButterKnifeFragment {
mSwipeRefreshLayout.setRefreshing(false);
mBuild = response;
bindBuild(response);
LabCoatApp.bus().post(new BuildChangedEvent(response));
App.bus().post(new BuildChangedEvent(response));
}
 
@Override
Loading
Loading
@@ -115,7 +115,7 @@ public class BuildDescriptionFragment extends ButterKnifeFragment {
});
bindBuild(mBuild);
mEventReceiver = new EventReceiver();
LabCoatApp.bus().register(mEventReceiver);
App.bus().register(mEventReceiver);
}
 
private void load() {
Loading
Loading
@@ -158,7 +158,7 @@ public class BuildDescriptionFragment extends ButterKnifeFragment {
@Override
public void onDestroyView() {
super.onDestroyView();
LabCoatApp.bus().unregister(mEventReceiver);
App.bus().unregister(mEventReceiver);
}
 
private class EventReceiver {
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