Some more intro logic fixes

This commit is contained in:
Alexander Bakker 2017-12-11 14:01:43 +01:00
parent 7d5bd8f812
commit f26dfac1b6
4 changed files with 33 additions and 31 deletions

View file

@ -19,7 +19,7 @@ import android.widget.TextView;
import com.github.paolorotolo.appintro.ISlidePolicy;
public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy {
public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy, RadioGroup.OnCheckedChangeListener {
public static final int CRYPT_TYPE_INVALID = 0;
public static final int CRYPT_TYPE_NONE = 1;
public static final int CRYPT_TYPE_PASS = 2;
@ -34,31 +34,8 @@ public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy
final Context context = getContext();
_buttonGroup = (RadioGroup) view.findViewById(R.id.rg_authenticationMethod);
_buttonGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == -1) {
return;
}
int id;
switch (checkedId) {
case R.id.rb_none:
id = CRYPT_TYPE_NONE;
break;
case R.id.rb_password:
id = CRYPT_TYPE_PASS;
break;
case R.id.rb_fingerprint:
id = CRYPT_TYPE_FINGER;
break;
default:
throw new RuntimeException();
}
Intent intent = getActivity().getIntent();
intent.putExtra("cryptType", id);
}
});
_buttonGroup.setOnCheckedChangeListener(this);
onCheckedChanged(_buttonGroup, _buttonGroup.getCheckedRadioButtonId());
// only show the fingerprint option if the api version is new enough, permission is granted and a scanner is found
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -89,4 +66,28 @@ public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy
Snackbar snackbar = Snackbar.make(getView(), "Please select an authentication method", Snackbar.LENGTH_LONG);
snackbar.show();
}
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (i == -1) {
return;
}
int id;
switch (i) {
case R.id.rb_none:
id = CRYPT_TYPE_NONE;
break;
case R.id.rb_password:
id = CRYPT_TYPE_PASS;
break;
case R.id.rb_fingerprint:
id = CRYPT_TYPE_FINGER;
break;
default:
throw new RuntimeException();
}
Intent intent = getActivity().getIntent();
intent.putExtra("cryptType", id);
}
}

View file

@ -112,8 +112,8 @@ public class IntroActivity extends AppIntro implements DerivationTask.Callback {
int cryptType = _authenticatedSlide.getCryptType();
// wait for the key derivation background task
if (cryptType == CustomAuthenticationSlide.CRYPT_TYPE_NONE ||
_passwordSlot == null || _passwordCipher == null) {
if (cryptType != CustomAuthenticationSlide.CRYPT_TYPE_NONE &&
(_passwordSlot == null || _passwordCipher == null)) {
return;
}

View file

@ -73,8 +73,6 @@ public class MainActivity extends AppCompatActivity {
Intent intent = new Intent(this, AuthActivity.class);
intent.putExtra("slots", _db.getFile().getSlots());
startActivityForResult(intent, CODE_DECRYPT);
} else {
loadKeyProfiles();
}
} catch (FileNotFoundException e) {
// start the intro if the db file was not found
@ -118,6 +116,9 @@ public class MainActivity extends AppCompatActivity {
_keyProfiles = new ArrayList<>();
_keyProfileAdapter = new KeyProfileAdapter(_keyProfiles);
_keyProfileAdapter.setOnItemClickListener((position, v) -> createBottomSheet(position).show());
if (_db.isDecrypted()) {
loadKeyProfiles();
}
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);