mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Fix #1197 Switch to MaterialDrawer library
This commit is contained in:
parent
3ee2c6fc6a
commit
b323fc29c2
@ -21,56 +21,48 @@ package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
|
||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||
import com.mikepenz.iconics.typeface.FontAwesome;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
|
||||
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||
|
||||
public Drawer.Result result;
|
||||
|
||||
// public Drawer.Result result;
|
||||
private KeyListFragment mKeyListFragment ;
|
||||
private AppsListFragment mAppsListFragment;
|
||||
private EncryptDecryptOverviewFragment mEncryptDecryptOverviewFragment;
|
||||
private Fragment lastUsedFragment;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
// // don't open drawer on first run
|
||||
// disableLearningPattern();
|
||||
//
|
||||
//// addMultiPaneSupport();
|
||||
//
|
||||
// // set the header image
|
||||
// // create and set the header
|
||||
// setDrawerHeaderImage(R.drawable.drawer_header);
|
||||
//
|
||||
// // create sections
|
||||
// addSection(newSection(getString(R.string.nav_keys), R.drawable.ic_vpn_key_black_24dp, new KeyListFragment()));
|
||||
// addSection(newSection(getString(R.string.nav_encrypt_decrypt), R.drawable.ic_lock_black_24dp, new EncryptDecryptOverviewFragment()));
|
||||
// addSection(newSection(getString(R.string.title_api_registered_apps), R.drawable.ic_apps_black_24dp, new AppsListFragment()));
|
||||
//
|
||||
// // create bottom section
|
||||
// addBottomSection(newSection(getString(R.string.menu_preferences), R.drawable.ic_settings_black_24dp, new Intent(this, SettingsActivity.class)));
|
||||
// addBottomSection(newSection(getString(R.string.menu_help), R.drawable.ic_help_black_24dp, new Intent(this, HelpActivity.class)));
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main_activity);
|
||||
|
||||
//initialize FragmentLayout with KeyListFragment at first
|
||||
Fragment mainFragment = new KeyListFragment();
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
FragmentTransaction transaction = fm.beginTransaction();
|
||||
transaction.replace(R.id.main_fragment_container, mainFragment);
|
||||
transaction.commit();
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
|
||||
toolbar.setTitle(R.string.app_name);
|
||||
setSupportActionBar(toolbar);
|
||||
@ -82,8 +74,10 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||
.addDrawerItems(
|
||||
new PrimaryDrawerItem().withName(R.string.nav_keys).withIcon(CommunityMaterial.Icon.cmd_key).withIdentifier(1).withCheckable(false),
|
||||
new PrimaryDrawerItem().withName(R.string.nav_encrypt_decrypt).withIcon(FontAwesome.Icon.faw_lock).withIdentifier(2).withCheckable(false),
|
||||
new PrimaryDrawerItem().withName(R.string.title_api_registered_apps).withIcon(CommunityMaterial.Icon.cmd_apps).withIdentifier(3).withCheckable(false),
|
||||
new DividerDrawerItem(),
|
||||
new PrimaryDrawerItem().withName(R.string.title_api_registered_apps).withIcon(CommunityMaterial.Icon.cmd_apps).withIdentifier(3).withCheckable(false)
|
||||
)
|
||||
.addStickyDrawerItems(
|
||||
// display and stick on bottom of drawer
|
||||
new PrimaryDrawerItem().withName(R.string.menu_preferences).withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(4).withCheckable(false),
|
||||
new PrimaryDrawerItem().withName(R.string.menu_help).withIcon(CommunityMaterial.Icon.cmd_help_circle).withIdentifier(5).withCheckable(false)
|
||||
)
|
||||
@ -94,10 +88,13 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||
Intent intent = null;
|
||||
switch(drawerItem.getIdentifier()) {
|
||||
case 1:
|
||||
onKeysSelected();
|
||||
break;
|
||||
case 2:
|
||||
onEnDecryptSelected();
|
||||
break;
|
||||
case 3:
|
||||
onAppsSelected();
|
||||
break;
|
||||
case 4:
|
||||
intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
@ -110,7 +107,6 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||
MainActivity.this.startActivity(intent);
|
||||
}
|
||||
}
|
||||
Toast.makeText(MainActivity.this, Integer.toString(drawerItem.getIdentifier()), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.withSelectedItem(-1)
|
||||
@ -135,15 +131,58 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||
}
|
||||
}
|
||||
|
||||
// private void onPreferenceSelected() {
|
||||
// Intent intent = new Intent(this, SettingsActivity.class);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
//
|
||||
// private void onHelpSelected() {
|
||||
// Intent intent = new Intent(this, HelpActivity.class);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
private void clearFragments() {
|
||||
mKeyListFragment = null;
|
||||
mAppsListFragment = null;
|
||||
mEncryptDecryptOverviewFragment = null;
|
||||
|
||||
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
setFragment(fragment, true);
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment, boolean addToBackStack) {
|
||||
this.lastUsedFragment = fragment;
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.main_fragment_container, fragment);
|
||||
if (addToBackStack) {
|
||||
ft.addToBackStack(null);
|
||||
}
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
private boolean onKeysSelected() {
|
||||
clearFragments();
|
||||
|
||||
if (mKeyListFragment == null) {
|
||||
mKeyListFragment = new KeyListFragment();
|
||||
}
|
||||
|
||||
setFragment(mKeyListFragment, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onEnDecryptSelected() {
|
||||
clearFragments();
|
||||
if (mEncryptDecryptOverviewFragment == null) {
|
||||
mEncryptDecryptOverviewFragment = new EncryptDecryptOverviewFragment();
|
||||
}
|
||||
|
||||
setFragment(mEncryptDecryptOverviewFragment);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onAppsSelected() {
|
||||
clearFragments();
|
||||
if (mAppsListFragment == null) {
|
||||
mAppsListFragment = new AppsListFragment();
|
||||
}
|
||||
|
||||
setFragment(mAppsListFragment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
@ -164,18 +203,20 @@ public class MainActivity extends ActionBarActivity implements FabContainer {
|
||||
|
||||
@Override
|
||||
public void fabMoveUp(int height) {
|
||||
// Object fragment = getCurrentSection().getTargetFragment();
|
||||
// if (fragment instanceof FabContainer) {
|
||||
// ((FabContainer) fragment).fabMoveUp(height);
|
||||
// }
|
||||
Object fragment = getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_fragment_container);
|
||||
if (fragment instanceof FabContainer) {
|
||||
((FabContainer) fragment).fabMoveUp(height);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabRestorePosition() {
|
||||
// Object fragment = getCurrentSection().getTargetFragment();
|
||||
// if (fragment instanceof FabContainer) {
|
||||
// ((FabContainer) fragment).fabRestorePosition();
|
||||
// }
|
||||
Object fragment = getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_fragment_container);
|
||||
if (fragment instanceof FabContainer) {
|
||||
((FabContainer) fragment).fabRestorePosition();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,11 +7,13 @@
|
||||
android:id="@+id/activity_main_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:elevation="4dp"
|
||||
android:background="?attr/colorPrimary"/>
|
||||
|
||||
<fragment android:name="org.sufficientlysecure.keychain.ui.KeyListFragment"
|
||||
android:id="@+id/keys_fragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/main_fragment_container"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user