Skip to content

Commit

Permalink
Merge branch 'release/2.0.6'
Browse files Browse the repository at this point in the history
Fixed problem with importing rdfs that don't have a default profile, and profiles that weren't visible to the user was used.
Changed how the UI worked a tad to hopefully help out on usage
  • Loading branch information
James committed Sep 17, 2014
2 parents efd0723 + b6dd2f5 commit 212cc8c
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 44 deletions.
2 changes: 1 addition & 1 deletion passwordmaker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.intellij:annotations:12.0@jar'
compile 'org.passwordmaker:passwordmaker-je-lib:0.9.6'
compile 'org.passwordmaker:passwordmaker-je-lib:0.9.8'
compile 'com.madgag.spongycastle:core:1.50.0.0'
compile 'com.madgag.spongycastle:prov:1.50.0.0'
androidTestCompile 'junit:junit:4.8.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void onFocusChange(View v, boolean hasFocus) {
* indicating that the item with the given ID was selected.
*/
@Override
public void onItemSelected(Account account) {
public void onItemView(Account account) {
if (mTwoPane) {
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
Expand Down Expand Up @@ -201,7 +201,7 @@ public void onFolderSelected(Account account) {
}

@Override
public void onItemLongSelected(Account account) {
public void onItemManuallySelected(Account account) {
PwmApplication.getInstance().getAccountManager().selectAccountById(account.getId());
NavUtils.navigateUpFromSameTask(this);
Toast.makeText(this, "Manually selected '" + account.getName() + "'", Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class AccountListFragment extends ListFragment {
private Callbacks mCallbacks = sDummyCallbacks;

private ActionMode mActionMode;
private Menu mActionMenu;

private boolean autoActivateMode = false;

Expand All @@ -68,9 +69,9 @@ public interface Callbacks {
/**
* Callback for when an item has been selected.
*/
public void onItemSelected(Account account);
public void onItemView(Account account);
public void onFolderSelected(Account account);
public void onItemLongSelected(Account account);
public void onItemManuallySelected(Account account);
}

/**
Expand All @@ -79,7 +80,7 @@ public interface Callbacks {
*/
private final static Callbacks sDummyCallbacks = new Callbacks() {
@Override
public void onItemSelected(Account account) {
public void onItemView(Account account) {
}

@Override
Expand All @@ -88,7 +89,7 @@ public void onFolderSelected(Account account) {
}

@Override
public void onItemLongSelected(Account account) {
public void onItemManuallySelected(Account account) {

}
};
Expand Down Expand Up @@ -123,23 +124,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
&& savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (mActionMode != null) {
return false;
}

if ( ! autoActivateMode ) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
getListView().setItemChecked(position, true);

// Start the CAB using the ActionMode.Callback defined above
mActionMode = getActivity().startActionMode(mActionModeCallback);
return true;
}
});
}

private void loadIncomingAccount() {
Expand Down Expand Up @@ -175,7 +159,7 @@ public void onAttach(Activity activity) {
if ( loadedAccount != null ) {
Account acc = loadedAccount;
loadedAccount = null;
mCallbacks.onItemSelected(acc);
mCallbacks.onItemView(acc);
}

}
Expand All @@ -197,7 +181,23 @@ public void onListItemClick(ListView listView, View view, int position, long id)
if ( selected.hasChildren() ) {
goIntoFolder(selected);
} else {
mCallbacks.onItemSelected(selected);
if (mActionMode != null ) {
if (mActionMenu != null) {
if (getCheckedAccount().isDefault()) {
mActionMenu.findItem(R.id.menu_item_delete).setVisible(false);
} else {
mActionMenu.findItem(R.id.menu_item_delete).setVisible(true);
}
}
return;
}
if ( ! autoActivateMode ) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
getListView().setItemChecked(position, true);

// Start the CAB using the ActionMode.Callback defined above
mActionMode = getActivity().startActionMode(mActionModeCallback);
}
}

Expand Down Expand Up @@ -266,7 +266,7 @@ public void createNewAccount(String accountName) {
account.getPatterns().clear();
accountManager.getPwmProfiles().addAccount(accountStack.getCurrentAccount(), account);
getCurrentAccountList().notifyDataSetChanged();
mCallbacks.onItemSelected(account);
mCallbacks.onItemView(account);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -398,6 +398,7 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
} else {
menu.findItem(R.id.menu_item_delete).setVisible(true);
}
mActionMenu = menu;
return true;
}

Expand All @@ -413,13 +414,17 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_select:
mCallbacks.onItemLongSelected(getCheckedAccount());
mCallbacks.onItemManuallySelected(getCheckedAccount());
mode.finish(); // Action picked, so close the CAB
return true;
case R.id.menu_item_delete:
deleteAccount(getCheckedAccount());
mode.finish();
return true;
case R.id.menu_item_view:
mCallbacks.onItemView(getCheckedAccount());
mode.finish();
return true;
default:
return false;
}
Expand All @@ -429,13 +434,14 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
mActionMenu = null;
clearAllChecked();
}
};


public Account getCheckedAccount() {
return getCurrentAccountList().getItem(getListView().getCheckedItemPosition());
}
};

public Account getCheckedAccount() {
return getCurrentAccountList().getItem(getListView().getCheckedItemPosition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.*;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.daveware.passwordmaker.*;
import org.passwordmaker.android.adapters.SubstringArrayAdapter;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

import static java.lang.String.format;

Expand All @@ -41,13 +43,16 @@ public class MainActivity extends ActionBarActivity implements AccountManagerLis
private static final int UPDATE_VER_CODE = 0xccaabb;
private static final int VER_CODE_DELAY = 600;
private ImageButton btnClearSelectedProfile;
private Spinner spinAccount;
private List<Account> accounts = new ArrayList<Account>();

private ArrayAdapter<String> favoritesAdapter;
private final ArrayList<String> favoritesList = new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

accountManager = PwmApplication.getInstance().getAccountManager();
setContentView(R.layout.activity_main);

Expand All @@ -69,12 +74,16 @@ protected void onCreate(Bundle savedInstanceState) {
text.addTextChangedListener(createUpdatePasswordKeyListener());
if (text != null)
text.setOnFocusChangeListener(mUpdatePasswordFocusListener);
Button button = (Button) findViewById(R.id.btnCopy);
ImageButton button = (ImageButton) findViewById(R.id.btnCopy);
if (button != null)
button.setOnClickListener(mCopyButtonClick);

btnClearSelectedProfile = (ImageButton)findViewById(R.id.btnClearSelected);
btnClearSelectedProfile.setOnClickListener(mClearProfileButtonClick);


spinAccount = (Spinner)findViewById(R.id.spinProfile);
spinAccount.setOnItemSelectedListener(mSpinAccountOnProfileSelect);
}

@Override
Expand Down Expand Up @@ -105,12 +114,42 @@ private void createFavoritesList() {
protected void onResume() {
super.onResume();
loadDefaultValueForFields();
updateProfileDropDown();
showUsernameBasedOnPreference();
showPassStrengthBasedOnPreference();
favoritesAdapter.notifyDataSetChanged();
updateSelectedProfileText();
}

private void updateProfileDropDown() {
accounts = accountManager.getPwmProfiles().getAllAccounts();
List<String> names = ImmutableList.<String>builder().add("Auto-select").addAll(FluentIterable.from(accounts)
.transform(new Function<Account, String>() {
@Override
public String apply(Account input) {
return input.getName();
}
})).build();
spinAccount.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names));

setProfileDropdownBySelectedAccount();
}

private void setProfileDropdownBySelectedAccount() {
final Account selected = PwmApplication.getInstance().getAccountManager().getSelectedProfile();
if ( selected == null ) {
spinAccount.setSelection(0);
} else {
int index = Iterables.indexOf(accounts, new Predicate<Account>() {
@Override
public boolean apply(Account input) {
return selected.getId().equals(input.getId());
}
}) + 1;
spinAccount.setSelection(index);
}
}

@Override
protected void onStop() {
super.onStop();
Expand Down Expand Up @@ -280,6 +319,7 @@ protected void updateSelectedProfileText() {

@SuppressWarnings("UnusedDeclaration")
public void setCurrentProfile(String profileId) {
Log.i(LOG_TAG, "scp: " + profileId);
accountManager.selectAccountById(profileId);
}

Expand Down Expand Up @@ -389,6 +429,7 @@ private void setInputText(String value) {
public void onSelectedProfileChange(Account newProfile) {
TextView text = (TextView) findViewById(R.id.lblCurrentProfile);
text.setText(newProfile.getName());
updatePassword(false);
}


Expand Down Expand Up @@ -495,6 +536,7 @@ public void onClick(View v) {
@SuppressWarnings("deprecation")
public void onClick(View v) {
accountManager.clearSelectedAccount();
setProfileDropdownBySelectedAccount();
updatePassword(true);
Toast.makeText(MainActivity.this, "Cleared manually selected account", Toast.LENGTH_SHORT).show();
}
Expand All @@ -512,4 +554,23 @@ public boolean handleMessage(Message msg) {
return true;
}
});

private final AdapterView.OnItemSelectedListener mSpinAccountOnProfileSelect = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if ( position == 0 ) {
accountManager.clearSelectedAccount();
updatePassword(false);
} else {
Account account = accounts.get(position - 1);
accountManager.selectAccountById(account.getId());
onSelectedProfileChange(account);
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 29 additions & 4 deletions passwordmaker/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
android:visibility="gone"/>

</LinearLayout>

<Spinner
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/spinProfile"
android:entries="@array/HashAlgos"
/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/Input" android:id="@+id/lblInputText"/>
Expand Down Expand Up @@ -62,10 +70,30 @@
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:text="@string/Password"
android:id="@+id/lblPassword"/>
<LinearLayout
android:id="@+id/layPassfield"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/txtPassword" android:singleLine="true"
android:inputType="textVisiblePassword"/>
android:inputType="textVisiblePassword"
android:layout_gravity="left"
android:layout_weight="1"
/>

<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/btnCopy"
android:src="@drawable/ic_menu_copy_holo_light"
android:contentDescription="@string/LblCopy"
android:layout_weight="1"
android:minWidth="82dp"
android:baselineAlignBottom="false"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/layPassStrength"
android:orientation="horizontal"
Expand All @@ -89,7 +117,4 @@
/>
</LinearLayout>

<Button android:text="@string/LblCopy" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/btnCopy"/>

</LinearLayout>
6 changes: 6 additions & 0 deletions passwordmaker/src/main/res/menu/account_list_menu.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- menu_item_view -->

<item android:id="@+id/menu_item_view"
android:icon="@android:drawable/ic_menu_view"
android:showAsAction="ifRoom|withText"
android:title="@string/ViewAccount"
android:titleCondensed="@string/ViewAccountShort" />
<item android:id="@+id/menu_item_select"
android:icon="@android:drawable/ic_input_get"
android:showAsAction="ifRoom|withText"
Expand Down
Loading

0 comments on commit 212cc8c

Please sign in to comment.