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

Add ability to require device auth on starting the app

parent 53e592d6
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -96,21 +96,12 @@ public class AddIssueActivity extends MorphActivity {
@BindView(R.id.list_labels)
AdapterFlowLayout mListLabels;
 
private Project mProject;
private Issue mIssue;
private HashSet<Member> mMembers;
private AddIssueLabelAdapter mLabelsAdapter;
private Teleprinter mTeleprinter;
@OnClick(R.id.root_add_labels)
void onAddLabelsClick() {
Navigator.navigateToAddLabels(AddIssueActivity.this, mProject, REQUEST_LABEL);
}
AddIssueLabelAdapter mLabelsAdapter;
Teleprinter mTeleprinter;
 
@OnClick(R.id.list_labels)
void onLabelsClicked() {
Navigator.navigateToAddLabels(AddIssueActivity.this, mProject, REQUEST_LABEL);
}
Project mProject;
Issue mIssue;
HashSet<Member> mMembers;
 
private final Callback<List<Milestone>> mMilestonesCallback = new EasyCallback<List<Milestone>>() {
@Override
Loading
Loading
@@ -209,6 +200,11 @@ public class AddIssueActivity extends MorphActivity {
}
};
 
@OnClick(R.id.text_add_labels)
void onAddLabelClicked() {
Navigator.navigateToAddLabels(this, mProject, REQUEST_LABEL);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Loading
Loading
@@ -220,7 +216,27 @@ public class AddIssueActivity extends MorphActivity {
mProject = Parcels.unwrap(getIntent().getParcelableExtra(KEY_PROJECT));
mIssue = Parcels.unwrap(getIntent().getParcelableExtra(KEY_ISSUE));
mMembers = new HashSet<>();
mLabelsAdapter = new AddIssueLabelAdapter();
mLabelsAdapter = new AddIssueLabelAdapter(new AddIssueLabelAdapter.Listener() {
@Override
public void onLabelLongClicked(final Label label) {
new AlertDialog.Builder(AddIssueActivity.this)
.setTitle(R.string.remove)
.setMessage(R.string.are_you_sure_you_want_to_remove)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mLabelsAdapter.removeLabel(label);
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
});
mListLabels.setAdapter(mLabelsAdapter);
 
mToolbar.setNavigationIcon(R.drawable.ic_back_24dp);
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 com.commit451.gitlab.App;
import com.commit451.gitlab.BuildConfig;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.Account;
import com.commit451.gitlab.navigation.Navigator;
import com.commit451.gitlab.ssl.CustomKeyManager;
Loading
Loading
@@ -22,6 +27,8 @@ public class LaunchActivity extends Activity {
//Figure out how this works, then reenable
private static final boolean PRIVATE_KEY_ENABLED = false;
 
private static final int REQUEST_DEVICE_AUTH = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Loading
Loading
@@ -36,16 +43,48 @@ public class LaunchActivity extends Activity {
if(accounts.isEmpty()) {
Navigator.navigateToLogin(this);
finish();
} else if (App.instance().getPrefs().isRequireDeviceAuth()) {
showKeyguard();
} else {
if (PRIVATE_KEY_ENABLED) {
loadPrivateKey(accounts, 0);
} else {
Navigator.navigateToStartingActivity(LaunchActivity.this);
finish();
moveAlong();
}
}
}
 
@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) {
moveAlong();
} else {
finish();
}
break;
}
}
@TargetApi(21)
private void showKeyguard() {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.device_auth_title), getString(R.string.device_auth_message));
if (intent == null) {
moveAlong();
} else {
startActivityForResult(intent, REQUEST_DEVICE_AUTH);
}
}
private void moveAlong() {
Navigator.navigateToStartingActivity(this);
finish();
}
private void loadPrivateKey(final List<Account> accounts, final int i) {
if (i >= accounts.size()) {
runOnUiThread(new Runnable() {
Loading
Loading
Loading
Loading
@@ -2,10 +2,14 @@ package com.commit451.gitlab.activity;
 
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.SwitchCompat;
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;
Loading
Loading
@@ -29,9 +33,12 @@ public class SettingsActivity extends BaseActivity {
 
@BindView(R.id.toolbar)
Toolbar mToolbar;
@BindView(R.id.text_launch_activity)
TextView mTextLaunchActivity;
@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() {
Loading
Loading
@@ -53,6 +60,11 @@ public class SettingsActivity extends BaseActivity {
.show();
}
 
@OnClick(R.id.root_require_device_auth)
void onRequireDeviceAuthClicked() {
switchRequireAuth.toggle();
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Loading
Loading
@@ -66,11 +78,23 @@ public class SettingsActivity extends BaseActivity {
onBackPressed();
}
});
if (Build.VERSION.SDK_INT < 21) {
//lollipop+ only!
rootRequireDeviceAuth.setVisibility(View.GONE);
}
bindPrefs();
switchRequireAuth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
App.instance().getPrefs().setRequireDeviceAuth(b);
}
});
}
 
private void bindPrefs() {
setStartingViewSelection();
switchRequireAuth.setChecked(App.instance().getPrefs().isRequireDeviceAuth());
}
 
private void setStartingViewSelection() {
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ package com.commit451.gitlab.adapter;
 
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.model.api.Label;
Loading
Loading
@@ -16,9 +17,11 @@ import java.util.Collection;
public class AddIssueLabelAdapter extends RecyclerView.Adapter<AddLabelViewHolder> {
 
private ArrayList<Label> mValues;
private Listener mListener;
 
public AddIssueLabelAdapter() {
public AddIssueLabelAdapter(Listener listener) {
mValues = new ArrayList<>();
mListener = listener;
}
 
public void setLabels(Collection<Label> labels) {
Loading
Loading
@@ -38,9 +41,24 @@ public class AddIssueLabelAdapter extends RecyclerView.Adapter<AddLabelViewHolde
notifyItemInserted(mValues.size()-1);
}
 
public void removeLabel(Label label) {
int indexOf = mValues.indexOf(label);
mValues.remove(indexOf);
notifyItemRemoved(indexOf);
}
@Override
public AddLabelViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return AddLabelViewHolder.inflate(parent);
final AddLabelViewHolder holder = AddLabelViewHolder.inflate(parent);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Label label = getEntry(holder.getAdapterPosition());
mListener.onLabelLongClicked(label);
return true;
}
});
return holder;
}
 
@Override
Loading
Loading
@@ -74,4 +92,8 @@ public class AddIssueLabelAdapter extends RecyclerView.Adapter<AddLabelViewHolde
labels = labels.substring(0, labels.length()-1);
return labels;
}
public interface Listener {
void onLabelLongClicked(Label label);
}
}
Loading
Loading
@@ -26,6 +26,7 @@ public class Prefs {
private static final String KEY_ACCOUNTS = "accounts";
private static final String KEY_VERSION = "current_version";
private static final String KEY_STARTING_VIEW = "starting_view";
private static final String KEY_REQUIRE_DEVICE_AUTH = "require_device_auth";
 
public static final int STARTING_VIEW_PROJECTS = 0;
public static final int STARTING_VIEW_GROUPS = 1;
Loading
Loading
@@ -53,7 +54,7 @@ public class Prefs {
return LoganSquare.parseList(accountsJson, Account.class);
} catch (IOException e) {
//why would this ever happen?!?!?1
mSharedPreferences.edit().remove(KEY_ACCOUNTS).commit();
mSharedPreferences.edit().remove(KEY_ACCOUNTS).apply();
}
return new ArrayList<>();
} else {
Loading
Loading
@@ -86,7 +87,7 @@ public class Prefs {
mSharedPreferences
.edit()
.putString(KEY_ACCOUNTS, json)
.commit();
.apply();
} catch (IOException e) {
//this wont happen! Right?!?!?!
}
Loading
Loading
@@ -100,7 +101,7 @@ public class Prefs {
mSharedPreferences
.edit()
.putInt(KEY_VERSION, BuildConfig.VERSION_CODE)
.commit();
.apply();
}
 
public int getStartingView() {
Loading
Loading
@@ -111,6 +112,17 @@ public class Prefs {
mSharedPreferences
.edit()
.putInt(KEY_STARTING_VIEW, startingView)
.commit();
.apply();
}
public boolean isRequireDeviceAuth() {
return mSharedPreferences.getBoolean(KEY_REQUIRE_DEVICE_AUTH, false);
}
public void setRequireDeviceAuth(boolean require) {
mSharedPreferences
.edit()
.putBoolean(KEY_REQUIRE_DEVICE_AUTH, require)
.apply();
}
}
Loading
Loading
@@ -134,6 +134,7 @@
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:visibility="gone"
android:animateLayoutChanges="true"
android:background="?attr/selectableItemBackground">
 
<com.commit451.adapterflowlayout.AdapterFlowLayout
Loading
Loading
@@ -146,6 +147,7 @@
android:id="@+id/text_add_labels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="@string/add_labels"/>
 
</LinearLayout>
Loading
Loading
Loading
Loading
@@ -40,6 +40,31 @@
 
</FrameLayout>
 
<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_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
</FrameLayout>
 
</LinearLayout>
 
Loading
Loading
Loading
Loading
@@ -131,9 +131,6 @@
<string name="user_error">User could not be added</string>
<string name="user_remove_error">User could not be removed</string>
 
<string name="files_not_supported">To browse files GitLab 5.3 or higher is needed</string>
<string name="groups_not_supported">To add and remove users from groups GitLab 6.1 or higher is needed</string>
<string name="not_in_group">User management is only available for projects that are assigned to groups</string>
<string name="error_could_not_share">Could not share the link</string>
<string name="error_no_browser">No browser on device. What are you doing?</string>
<string name="error_user_conflict">There is a conflict in adding this user.</string>
Loading
Loading
@@ -161,6 +158,7 @@
<string name="discard">Discard</string>
<string name="are_you_sure_you_want_to_discard">Are you sure you want to discard?</string>
<string name="failed_to_upload_file">Failed to upload file</string>
<string name="are_you_sure_you_want_to_remove">Are you sure you want to remove?</string>
 
<!-- Project -->
<string name="no_readme_found">No README found for project</string>
Loading
Loading
@@ -178,9 +176,6 @@
<!-- Commits -->
<string name="no_commits_found">No commits found.</string>
 
<!-- Diffs -->
<string name="text_wrap_checkbox">Wrap text</string>
<!-- Files -->
<string name="file_saved">File saved successfully to Download folder</string>
<string name="no_files_found">No files found.</string>
Loading
Loading
@@ -293,7 +288,7 @@
<string name="contributors">Contributors</string>
<string name="sauce">See the source</string>
<string name="source_url">https://gitlab.com/Commit451/LabCoat</string>
<string name="failed_to_load_contributors">Failed to load contributors :(</string>
<string name="failed_to_load_contributors">Failed to load contributors</string>
 
<!-- Account -->
<string name="add_account">Add account</string>
Loading
Loading
@@ -374,13 +369,6 @@
 
<!-- Settings -->
<string name="settings">Settings</string>
<string name="preference_category_theme">Theme</string>
<string name="dark_theme">Dark Theme</string>
<string name="dark_theme_summary">Apply a dark theme throughout the app</string>
<string name="primary_color">Primary Color</string>
<string name="primary_color_summary">Change the primary theme color</string>
<string name="accent_color">Accent Color</string>
<string name="accent_color_summary">Change the accent theme color</string>
 
<!-- Builds -->
<string name="no_builds">No builds</string>
Loading
Loading
@@ -438,6 +426,9 @@
<item>@string/setting_starting_view_activity</item>
<item>@string/setting_starting_view_todos</item>
</string-array>
<string name="setting_require_device_auth">Require device authentication</string>
<string name="device_auth_title">Authenticate</string>
<string name="device_auth_message">Please authenticate to access LabCoat</string>
 
<!-- Todos -->
<string name="no_todos">No todos.</string>
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