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

Prevent crash when performing device auth

parent a607727a
No related branches found
No related tags found
No related merge requests found
Pipeline #
Showing
with 154 additions and 143 deletions
Loading
Loading
@@ -16,8 +16,7 @@
 
<activity
android:name=".activity.LaunchActivity"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay">
android:theme="@style/Activity.Launch">
 
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Loading
Loading
Loading
Loading
@@ -18,6 +18,7 @@ import android.widget.TextView;
 
import com.commit451.gimbal.Gimbal;
import com.commit451.gitlab.App;
import com.commit451.gitlab.BuildConfig;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.api.Contributor;
import com.commit451.gitlab.navigation.Navigator;
Loading
Loading
@@ -107,6 +108,7 @@ public class AboutActivity extends BaseActivity {
}
});
toolbar.setTitle(R.string.about);
toolbar.setSubtitle(BuildConfig.VERSION_NAME);
physicsLayout.getPhysics().enableFling();
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
Loading
Loading
Loading
Loading
@@ -11,6 +11,7 @@ import android.view.View;
 
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.data.Prefs;
import com.commit451.gitlab.event.CloseDrawerEvent;
import com.commit451.gitlab.fragment.FeedFragment;
 
Loading
Loading
@@ -40,6 +41,7 @@ public class ActivityActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
App.get().getPrefs().setStartingView(Prefs.STARTING_VIEW_ACTIVITY);
setContentView(R.layout.activity_activity);
ButterKnife.bind(this);
 
Loading
Loading
Loading
Loading
@@ -17,6 +17,7 @@ import com.alexgwyn.recyclerviewsquire.DynamicGridLayoutManager;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.GroupAdapter;
import com.commit451.gitlab.data.Prefs;
import com.commit451.gitlab.event.CloseDrawerEvent;
import com.commit451.gitlab.event.ReloadDataEvent;
import com.commit451.gitlab.model.api.Group;
Loading
Loading
@@ -86,6 +87,7 @@ public class GroupsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
App.get().getPrefs().setStartingView(Prefs.STARTING_VIEW_GROUPS);
setContentView(R.layout.activity_groups);
ButterKnife.bind(this);
App.bus().register(this);
Loading
Loading
package com.commit451.gitlab.activity;
 
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;
 
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
Loading
Loading
@@ -15,40 +15,34 @@ import com.commit451.gitlab.ssl.CustomKeyManager;
 
import java.util.List;
 
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* This activity acts as switching platform for the application directing the user to the appropriate
* activity based on their logged in state
*/
public class LaunchActivity extends Activity {
public class LaunchActivity extends BaseActivity {
 
//Figure out how this works, then reenable
private static final boolean PRIVATE_KEY_ENABLED = false;
 
private static final int REQUEST_DEVICE_AUTH = 123;
 
@BindView(R.id.root)
ViewGroup root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Account> accounts = Account.getAccounts();
if(accounts.isEmpty()) {
Navigator.navigateToLogin(this);
finish();
} else if (App.get().getPrefs().isRequireDeviceAuth()) {
showKeyguard();
} else {
if (PRIVATE_KEY_ENABLED) {
loadPrivateKey(accounts, 0);
} else {
moveAlong();
}
}
setContentView(R.layout.activity_launch);
ButterKnife.bind(this);
figureOutWhatToDo();
}
 
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_DEVICE_AUTH:
if (resultCode == RESULT_OK) {
Loading
Loading
@@ -60,6 +54,22 @@ public class LaunchActivity extends Activity {
}
}
 
private void figureOutWhatToDo() {
List<Account> accounts = Account.getAccounts();
if (accounts.isEmpty()) {
Navigator.navigateToLogin(this);
finish();
} else if (App.get().getPrefs().isRequireDeviceAuth()) {
showKeyguard();
} else {
if (PRIVATE_KEY_ENABLED) {
loadPrivateKey(accounts, 0);
} else {
moveAlong();
}
}
}
@TargetApi(21)
private void showKeyguard() {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Loading
Loading
Loading
Loading
@@ -20,6 +20,7 @@ import com.commit451.alakazam.HideRunnable;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.ProjectSectionsPagerAdapter;
import com.commit451.gitlab.data.Prefs;
import com.commit451.gitlab.event.ProjectReloadEvent;
import com.commit451.gitlab.fragment.BaseFragment;
import com.commit451.gitlab.model.Ref;
Loading
Loading
@@ -120,6 +121,7 @@ public class ProjectActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
App.get().getPrefs().setStartingView(Prefs.STARTING_VIEW_PROJECTS);
setContentView(R.layout.activity_project);
ButterKnife.bind(this);
Project project = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_PROJECT));
Loading
Loading
Loading
Loading
@@ -10,12 +10,9 @@ import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;
 
import com.afollestad.materialdialogs.MaterialDialog;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.data.Prefs;
 
import butterknife.BindView;
import butterknife.ButterKnife;
Loading
Loading
@@ -33,33 +30,11 @@ public class SettingsActivity extends BaseActivity {
 
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.text_launch_activity)
TextView textLaunchActivity;
@BindView(R.id.root_require_device_auth)
ViewGroup rootRequireDeviceAuth;
@BindView(R.id.switch_require_auth)
SwitchCompat switchRequireAuth;
 
@OnClick(R.id.root_launch_activity)
void onLaunchActivityClicked() {
new MaterialDialog.Builder(this)
.title(R.string.setting_starting_view)
.items(R.array.setting_starting_view_choices)
.itemsCallbackSingleChoice(getSelectedIndex(), new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
App.get().getPrefs().setStartingView(which);
bindPrefs();
/**
* If you use alwaysCallSingleChoiceCallback(), which is discussed below,
* returning false here won't allow the newly selected radio button to actually be selected.
**/
return true;
}
})
.show();
}
@OnClick(R.id.root_require_device_auth)
void onRequireDeviceAuthClicked() {
switchRequireAuth.toggle();
Loading
Loading
@@ -93,30 +68,6 @@ public class SettingsActivity extends BaseActivity {
}
 
private void bindPrefs() {
setStartingViewSelection();
switchRequireAuth.setChecked(App.get().getPrefs().isRequireDeviceAuth());
}
private void setStartingViewSelection() {
int startinView = App.get().getPrefs().getStartingView();
switch (startinView) {
case Prefs.STARTING_VIEW_PROJECTS:
textLaunchActivity.setText(R.string.setting_starting_view_projects);
break;
case Prefs.STARTING_VIEW_GROUPS:
textLaunchActivity.setText(R.string.setting_starting_view_groups);
break;
case Prefs.STARTING_VIEW_ACTIVITY:
textLaunchActivity.setText(R.string.setting_starting_view_activity);
break;
case Prefs.STARTING_VIEW_TODOS:
textLaunchActivity.setText(R.string.setting_starting_view_todos);
break;
}
}
private int getSelectedIndex() {
return App.get().getPrefs().getStartingView();
}
}
Loading
Loading
@@ -14,6 +14,7 @@ import android.view.View;
import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.TodoPagerAdapter;
import com.commit451.gitlab.data.Prefs;
import com.commit451.gitlab.event.CloseDrawerEvent;
 
import org.greenrobot.eventbus.Subscribe;
Loading
Loading
@@ -45,6 +46,7 @@ public class TodosActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
App.get().getPrefs().setStartingView(Prefs.STARTING_VIEW_TODOS);
setContentView(R.layout.activity_todos);
ButterKnife.bind(this);
App.bus().register(this);
Loading
Loading
Loading
Loading
@@ -30,52 +30,33 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
private ArrayList<Account> accounts;
private int colorControlHighlight;
 
private View.OnClickListener mOnItemClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = (int) v.getTag(R.id.list_position);
listener.onAccountClicked(getItemAtPosition(position));
}
};
private View.OnClickListener mOnFooterClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onAddAccountClicked();
}
};
public AccountAdapter(Context context, Listener listener) {
this.listener = listener;
accounts = new ArrayList<>();
colorControlHighlight = Easel.getThemeAttrColor(context, R.attr.colorControlHighlight);
}
 
public void setAccounts(Collection<Account> accounts) {
this.accounts.clear();
if (accounts != null) {
this.accounts.addAll(accounts);
}
notifyDataSetChanged();
}
public void addAccount(Account account) {
if (!accounts.contains(account)) {
accounts.add(0, account);
notifyItemInserted(0);
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case TYPE_ACCOUNT:
AccountViewHolder holder = AccountViewHolder.inflate(parent);
holder.itemView.setOnClickListener(mOnItemClickListener);
final AccountViewHolder holder = AccountViewHolder.inflate(parent);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = holder.getAdapterPosition();
listener.onAccountClicked(getItemAtPosition(position));
}
});
return holder;
case TYPE_FOOTER:
AccountFooterViewHolder footerViewHolder = AccountFooterViewHolder.inflate(parent);
footerViewHolder.itemView.setOnClickListener(mOnFooterClickListener);
footerViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onAddAccountClicked();
}
});
return footerViewHolder;
}
throw new IllegalStateException("No known view holder for that type " + viewType);
Loading
Loading
@@ -118,6 +99,21 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
return position == accounts.size() ? TYPE_FOOTER : TYPE_ACCOUNT;
}
 
public void setAccounts(Collection<Account> accounts) {
this.accounts.clear();
if (accounts != null) {
this.accounts.addAll(accounts);
}
notifyDataSetChanged();
}
public void addAccount(Account account) {
if (!accounts.contains(account)) {
accounts.add(0, account);
notifyItemInserted(0);
}
}
private Account getItemAtPosition(int position) {
return accounts.get(position);
}
Loading
Loading
app/src/main/res/drawable-xxxhdpi/logo_commit451.png

13.9 KiB

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="@color/main_blue">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@null"
app:srcCompat="@drawable/ic_logo" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="16dp"
android:contentDescription="@null"
app:srcCompat="@drawable/logo_commit451" />
</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:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
Loading
Loading
@@ -8,12 +7,36 @@
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:padding="16dp"
android:clickable="true"
android:layout_gravity="center">
android:clickable="true">
 
<include layout="@layout/progress"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<com.commit451.gitlab.view.LabCoatProgressView
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:indeterminate="true"
android:visibility="visible" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="@string/fetching_some_details"
android:textSize="16sp" />
</LinearLayout>
 
</android.support.v7.widget.CardView>
 
Loading
Loading
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
Loading
Loading
@@ -12,58 +11,50 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="?attr/actionBarSize">
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
 
<FrameLayout
android:id="@+id/root_launch_activity"
<LinearLayout
android:id="@+id/root_require_device_auth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="horizontal"
android:paddingTop="@dimen/activity_vertical_margin">
 
<TextView
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/setting_starting_view" />
android:orientation="vertical">
 
<TextView
android:id="@+id/text_launch_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
<TextView
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setting_require_device_auth" />
 
</FrameLayout>
<TextView
style="?android:attr/textAppearance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white_60"
android:text="@string/setting_require_device_auth_description" />
</LinearLayout>
 
<FrameLayout
android:id="@+id/root_require_device_auth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/setting_require_device_auth" />
 
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_require_auth"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
android:layout_marginLeft="8dp"
android:layout_height="wrap_content" />
 
</FrameLayout>
</LinearLayout>
 
 
</LinearLayout>
Loading
Loading
@@ -74,6 +65,6 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
android:background="?attr/colorPrimary" />
 
</merge>
\ No newline at end of file
Loading
Loading
@@ -427,6 +427,7 @@
<item>@string/setting_starting_view_todos</item>
</string-array>
<string name="setting_require_device_auth">Require device authentication</string>
<string name="setting_require_device_auth_description">Force device authentication when starting the app for the first time</string>
<string name="device_auth_title">Authenticate</string>
<string name="device_auth_message">Please authenticate to access LabCoat</string>
 
Loading
Loading
@@ -459,4 +460,5 @@
</string-array>
<string name="no_branches">No branches</string>
<string name="no_tags">No tags</string>
<string name="fetching_some_details">Fetching some details</string>
</resources>
\ No newline at end of file
Loading
Loading
@@ -43,6 +43,10 @@
<!--Check v21 for the good bits-->
</style>
 
<style name="Activity.Launch">
<item name="android:windowBackground">?attr/colorPrimary</item>
</style>
<style name="Activity.Translucent">
<!-- using a semi-transparent window background for the drag-back gesture -->
<item name="android:windowBackground">@color/scrim</item>
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