mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Hide subkeys, certs tabs in key view, checkable menu item to show/hide them
This commit is contained in:
parent
255462def4
commit
341247d446
@ -92,6 +92,8 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
|
|
||||||
private static final int LOADER_ID_UNIFIED = 0;
|
private static final int LOADER_ID_UNIFIED = 0;
|
||||||
|
|
||||||
|
private boolean mShowAdvancedTabs;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -116,9 +118,6 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
mViewPager = (ViewPager) findViewById(R.id.view_key_pager);
|
mViewPager = (ViewPager) findViewById(R.id.view_key_pager);
|
||||||
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.view_key_sliding_tab_layout);
|
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.view_key_sliding_tab_layout);
|
||||||
|
|
||||||
mTabsAdapter = new PagerTabStripAdapter(this);
|
|
||||||
mViewPager.setAdapter(mTabsAdapter);
|
|
||||||
|
|
||||||
int switchToTab = TAB_MAIN;
|
int switchToTab = TAB_MAIN;
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent.getExtras() != null && intent.getExtras().containsKey(EXTRA_SELECTED_TAB)) {
|
if (intent.getExtras() != null && intent.getExtras().containsKey(EXTRA_SELECTED_TAB)) {
|
||||||
@ -136,6 +135,18 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
|
|
||||||
initNfc(dataUri);
|
initNfc(dataUri);
|
||||||
|
|
||||||
|
mShowAdvancedTabs = false;
|
||||||
|
|
||||||
|
initTabs(dataUri);
|
||||||
|
|
||||||
|
// switch to tab selected by extra
|
||||||
|
mViewPager.setCurrentItem(switchToTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTabs(Uri dataUri) {
|
||||||
|
mTabsAdapter = new PagerTabStripAdapter(this);
|
||||||
|
mViewPager.setAdapter(mTabsAdapter);
|
||||||
|
|
||||||
Bundle mainBundle = new Bundle();
|
Bundle mainBundle = new Bundle();
|
||||||
mainBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
|
mainBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
|
||||||
mTabsAdapter.addTab(ViewKeyMainFragment.class,
|
mTabsAdapter.addTab(ViewKeyMainFragment.class,
|
||||||
@ -146,6 +157,11 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
mTabsAdapter.addTab(ViewKeyShareFragment.class,
|
mTabsAdapter.addTab(ViewKeyShareFragment.class,
|
||||||
mainBundle, getString(R.string.key_view_tab_share));
|
mainBundle, getString(R.string.key_view_tab_share));
|
||||||
|
|
||||||
|
// update layout after operations
|
||||||
|
mSlidingTabLayout.setViewPager(mViewPager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAdvancedTabs(Uri dataUri) {
|
||||||
Bundle keyDetailsBundle = new Bundle();
|
Bundle keyDetailsBundle = new Bundle();
|
||||||
keyDetailsBundle.putParcelable(ViewKeyKeysFragment.ARG_DATA_URI, dataUri);
|
keyDetailsBundle.putParcelable(ViewKeyKeysFragment.ARG_DATA_URI, dataUri);
|
||||||
mTabsAdapter.addTab(ViewKeyKeysFragment.class,
|
mTabsAdapter.addTab(ViewKeyKeysFragment.class,
|
||||||
@ -156,11 +172,46 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
mTabsAdapter.addTab(ViewKeyCertsFragment.class,
|
mTabsAdapter.addTab(ViewKeyCertsFragment.class,
|
||||||
certBundle, getString(R.string.key_view_tab_certs));
|
certBundle, getString(R.string.key_view_tab_certs));
|
||||||
|
|
||||||
// NOTE: must be after adding the tabs!
|
// update layout after operations
|
||||||
|
mSlidingTabLayout.setViewPager(mViewPager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeAdvancedTabs() {
|
||||||
|
// before removing, switch to the first tab if necessary
|
||||||
|
if (mViewPager.getCurrentItem() >= TAB_KEYS) {
|
||||||
|
// remove _after_ switching to the main tab
|
||||||
|
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
if (ViewPager.SCROLL_STATE_SETTLING == state) {
|
||||||
|
mTabsAdapter.removeTab(TAB_CERTS);
|
||||||
|
mTabsAdapter.removeTab(TAB_KEYS);
|
||||||
|
|
||||||
|
// update layout after operations
|
||||||
mSlidingTabLayout.setViewPager(mViewPager);
|
mSlidingTabLayout.setViewPager(mViewPager);
|
||||||
|
|
||||||
// switch to tab selected by extra
|
// remove this listener again
|
||||||
mViewPager.setCurrentItem(switchToTab);
|
// mViewPager.setOnPageChangeListener(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mViewPager.setCurrentItem(TAB_MAIN);
|
||||||
|
} else {
|
||||||
|
mTabsAdapter.removeTab(TAB_CERTS);
|
||||||
|
mTabsAdapter.removeTab(TAB_KEYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update layout after operations
|
||||||
|
mSlidingTabLayout.setViewPager(mViewPager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadData(Uri dataUri) {
|
private void loadData(Uri dataUri) {
|
||||||
@ -177,6 +228,9 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
getMenuInflater().inflate(R.menu.key_view, menu);
|
getMenuInflater().inflate(R.menu.key_view, menu);
|
||||||
|
|
||||||
|
MenuItem showAdvancedInfoItem = menu.findItem(R.id.menu_key_view_advanced);
|
||||||
|
showAdvancedInfoItem.setChecked(mShowAdvancedTabs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,24 +238,37 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
try {
|
try {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home: {
|
||||||
Intent homeIntent = new Intent(this, KeyListActivity.class);
|
Intent homeIntent = new Intent(this, KeyListActivity.class);
|
||||||
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
startActivity(homeIntent);
|
startActivity(homeIntent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_update:
|
}
|
||||||
|
case R.id.menu_key_view_update: {
|
||||||
updateFromKeyserver(mDataUri, mProviderHelper);
|
updateFromKeyserver(mDataUri, mProviderHelper);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_export_keyserver:
|
}
|
||||||
|
case R.id.menu_key_view_export_keyserver: {
|
||||||
uploadToKeyserver(mDataUri);
|
uploadToKeyserver(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_export_file:
|
}
|
||||||
|
case R.id.menu_key_view_export_file: {
|
||||||
exportToFile(mDataUri, mExportHelper, mProviderHelper);
|
exportToFile(mDataUri, mExportHelper, mProviderHelper);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
case R.id.menu_key_view_delete: {
|
case R.id.menu_key_view_delete: {
|
||||||
deleteKey(mDataUri, mExportHelper);
|
deleteKey(mDataUri, mExportHelper);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case R.id.menu_key_view_advanced: {
|
||||||
|
mShowAdvancedTabs = !mShowAdvancedTabs;
|
||||||
|
item.setChecked(mShowAdvancedTabs);
|
||||||
|
if (mShowAdvancedTabs) {
|
||||||
|
addAdvancedTabs(mDataUri);
|
||||||
|
} else {
|
||||||
|
removeAdvancedTabs();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
|
AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
|
||||||
|
@ -20,8 +20,13 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -52,6 +57,11 @@ public class PagerTabStripAdapter extends FragmentPagerAdapter {
|
|||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeTab(int index) {
|
||||||
|
mTabs.remove(index);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mTabs.size();
|
return mTabs.size();
|
||||||
|
@ -31,4 +31,10 @@
|
|||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
android:title="@string/menu_delete_key" />
|
android:title="@string/menu_delete_key" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_key_view_advanced"
|
||||||
|
app:showAsAction="never"
|
||||||
|
android:checkable="true"
|
||||||
|
android:title="@string/menu_advanced" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
@ -102,6 +102,7 @@
|
|||||||
<string name="menu_select_all">Select all</string>
|
<string name="menu_select_all">Select all</string>
|
||||||
<string name="menu_add_keys">Add keys</string>
|
<string name="menu_add_keys">Add keys</string>
|
||||||
<string name="menu_export_all_keys">Export all keys</string>
|
<string name="menu_export_all_keys">Export all keys</string>
|
||||||
|
<string name="menu_advanced">Show advanced info</string>
|
||||||
|
|
||||||
<!-- label -->
|
<!-- label -->
|
||||||
<string name="label_sign">Sign</string>
|
<string name="label_sign">Sign</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user