Skip to content

Commit

Permalink
Merge branch 'hotfix/5.2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Oct 17, 2016
2 parents 7b4447b + 81ac9c5 commit af72071
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 198 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

MIN_SDK=14
TARGET_SDK=23
VERSION_NAME=5.2.18
VERSION_CODE=228
VERSION_NAME=5.2.19
VERSION_CODE=229
PACKAGE=it.feio.android.omninotes

# The following properties are empty defaults to allow build and can EVENTUALLY be overridden to allow:
Expand Down
107 changes: 28 additions & 79 deletions omniNotes/src/main/java/it/feio/android/omninotes/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.*;
import android.widget.EditText;
import android.widget.Toast;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.MaterialDialog.SingleButtonCallback;
import it.feio.android.omninotes.models.Note;
import it.feio.android.omninotes.models.PasswordValidator;
import it.feio.android.omninotes.utils.Constants;
import it.feio.android.omninotes.utils.KeyboardUtils;
import it.feio.android.omninotes.utils.Navigation;
import it.feio.android.omninotes.utils.Security;
import it.feio.android.omninotes.utils.*;
import it.feio.android.omninotes.widget.ListWidgetProvider;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -102,82 +102,31 @@ protected void showToast(CharSequence text, int duration) {
}


/**
* Method to validate security password to protect notes.
* It uses an interface callback.
*/
public static void requestPassword(final Activity mActivity, final PasswordValidator mPasswordValidator) {

// Inflate layout
LayoutInflater inflater = mActivity.getLayoutInflater();
final View v = inflater.inflate(R.layout.password_request_dialog_layout, null);
final EditText passwordEditText = (EditText) v.findViewById(R.id.password_request);

MaterialDialog dialog = new MaterialDialog.Builder(mActivity)
.autoDismiss(false)
.title(R.string.insert_security_password)
.customView(v, false)
.positiveText(R.string.ok)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// When positive button is pressed password correctness is checked
String oldPassword = mActivity.getSharedPreferences(Constants.PREFS_NAME, MODE_MULTI_PROCESS)
.getString(Constants.PREF_PASSWORD, "");
String password = passwordEditText.getText().toString();
// The check is done on password's hash stored in preferences
boolean result = Security.md5(password).equals(oldPassword);

// In case password is ok dialog is dismissed and result sent to callback
if (result) {
KeyboardUtils.hideKeyboard(passwordEditText);
dialog.dismiss();
mPasswordValidator.onPasswordValidated(true);
// If password is wrong the auth flow is not interrupted and simply a message is shown
} else {
passwordEditText.setError(mActivity.getString(R.string.wrong_password));
}
}
}).build();

dialog.setOnCancelListener(dialog1 -> {
KeyboardUtils.hideKeyboard(passwordEditText);
dialog1.dismiss();
mPasswordValidator.onPasswordValidated(false);
});

dialog.show();

// Force focus and shows soft keyboard
new Handler().postDelayed(() -> KeyboardUtils.showKeyboard(passwordEditText), 100);
}


/**
* Method to validate security password to protect a list of notes.
* When "Request password on access" in switched on this check not required all the times.
* It uses an interface callback.
*/
public void requestPassword(final Activity mActivity, List<Note> notes,
final PasswordValidator mPasswordValidator) {
if (prefs.getBoolean("settings_password_access", false)) {
mPasswordValidator.onPasswordValidated(true);
return;
}
/**
* Method to validate security password to protect a list of notes.
* When "Request password on access" in switched on this check not required all the times.
* It uses an interface callback.
*/
public void requestPassword(final Activity mActivity, List<Note> notes,
final PasswordValidator mPasswordValidator) {
if (prefs.getBoolean("settings_password_access", false)) {
mPasswordValidator.onPasswordValidated(true);
return;
}

boolean askForPassword = false;
for (Note note : notes) {
if (note.isLocked()) {
askForPassword = true;
break;
}
}
if (askForPassword) {
BaseActivity.requestPassword(mActivity, mPasswordValidator::onPasswordValidated);
} else {
mPasswordValidator.onPasswordValidated(true);
}
}
boolean askForPassword = false;
for (Note note : notes) {
if (note.isLocked()) {
askForPassword = true;
break;
}
}
if (askForPassword) {
PasswordHelper.requestPassword(mActivity, mPasswordValidator);
} else {
mPasswordValidator.onPasswordValidated(true);
}
}


public boolean updateNavigation(String nav) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private void checkNoteLock(Note note) {
if (note.isLocked()
&& prefs.getString(Constants.PREF_PASSWORD, null) != null
&& !prefs.getBoolean("settings_password_access", false)) {
BaseActivity.requestPassword(mainActivity, passwordConfirmed -> {
PasswordHelper.requestPassword(mainActivity, passwordConfirmed -> {
if (passwordConfirmed) {
noteTmp.setPasswordChecked(true);
init();
Expand Down Expand Up @@ -1738,7 +1738,7 @@ private void lockNote() {
}

// Password will be requested here
BaseActivity.requestPassword(mainActivity, passwordConfirmed -> {
PasswordHelper.requestPassword(mainActivity, passwordConfirmed -> {
if (passwordConfirmed) {
lockUnlock();
}
Expand Down
33 changes: 16 additions & 17 deletions omniNotes/src/main/java/it/feio/android/omninotes/ListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.os.*;
import android.support.annotation.NonNull;
import android.support.v4.util.Pair;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.MenuItemCompat;
Expand All @@ -45,6 +46,7 @@
import android.widget.ListView;
import butterknife.Bind;
import butterknife.ButterKnife;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.neopixl.pixlui.components.textview.TextView;
import com.nhaarman.listviewanimations.itemmanipulation.DynamicListView;
Expand Down Expand Up @@ -861,7 +863,7 @@ private void switchNotesView() {

void editNote(final Note note, final View view) {
if (note.isLocked() && !prefs.getBoolean("settings_password_access", false)) {
BaseActivity.requestPassword(mainActivity, passwordConfirmed -> {
PasswordHelper.requestPassword(mainActivity, passwordConfirmed -> {
if (passwordConfirmed) {
note.setPasswordChecked(true);
AnimationsHelper.zoomListItem(mainActivity, view, getZoomListItemView(view, note),
Expand Down Expand Up @@ -1263,22 +1265,19 @@ private void selectAllNotes() {
/**
* Batch note permanent deletion
*/
private void deleteNotes() {
new MaterialDialog.Builder(mainActivity)
.content(R.string.delete_note_confirmation)
.positiveText(R.string.ok)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog materialDialog) {
mainActivity.requestPassword(mainActivity, getSelectedNotes(),
passwordConfirmed -> {
if (passwordConfirmed) {
deleteNotesExecute();
}
});
}
}).build().show();
}
private void deleteNotes() {
new MaterialDialog.Builder(mainActivity)
.content(R.string.delete_note_confirmation)
.positiveText(R.string.ok)
.onPositive((dialog, which) -> mainActivity.requestPassword(mainActivity, getSelectedNotes(),
passwordConfirmed -> {
if (passwordConfirmed) {
deleteNotesExecute();
}
}))
.build()
.show();
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
Expand All @@ -44,6 +43,7 @@
import de.keyboardsurfer.android.widget.crouton.Style;
import edu.emory.mathcs.backport.java.util.Arrays;
import it.feio.android.omninotes.async.UpdaterTask;
import it.feio.android.omninotes.async.bus.PasswordRemovedEvent;
import it.feio.android.omninotes.async.bus.SwitchFragmentEvent;
import it.feio.android.omninotes.async.notes.NoteProcessorDelete;
import it.feio.android.omninotes.db.DbHelper;
Expand All @@ -53,6 +53,7 @@
import it.feio.android.omninotes.models.Note;
import it.feio.android.omninotes.utils.Constants;
import it.feio.android.omninotes.utils.MiscUtils;
import it.feio.android.omninotes.utils.PasswordHelper;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -78,6 +79,7 @@ protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.OmniNotesTheme_ApiSpec);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
EventBus.getDefault().register(this);

// This method starts the bootstrap chain.
checkPassword();
Expand All @@ -99,10 +101,10 @@ private void initUI() {
}


private void checkPassword() {
if (prefs.getString(Constants.PREF_PASSWORD, null) != null
&& prefs.getBoolean("settings_password_access", false)) {
requestPassword(this, passwordConfirmed -> {
private void checkPassword() {
if (prefs.getString(Constants.PREF_PASSWORD, null) != null
&& prefs.getBoolean("settings_password_access", false)) {
PasswordHelper.requestPassword(this, passwordConfirmed -> {
if (passwordConfirmed) {
init();
} else {
Expand All @@ -111,11 +113,16 @@ private void checkPassword() {
});
} else {
init();
}
}
}
}


public void onEvent(PasswordRemovedEvent passwordRemovedEvent) {
init();
}


private void init() {
private void init() {
mFragmentManager = getSupportFragmentManager();

NavigationDrawerFragment mNavigationDrawerFragment = (NavigationDrawerFragment) mFragmentManager
Expand Down
Loading

0 comments on commit af72071

Please sign in to comment.