Custom dialog for profile edit with 2 tabs (with console fragment stubs inside)

This commit is contained in:
Yaroslav Berezanskyi 2015-08-16 14:09:28 +03:00
parent 11a3961ef5
commit 8ef8e7dd9c
25 changed files with 240 additions and 41 deletions

View File

@ -15,7 +15,6 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Patterns;
@ -55,6 +54,7 @@ import io.syng.adapter.ProfileDrawerAdapter;
import io.syng.adapter.ProfileDrawerAdapter.OnProfileClickListener;
import io.syng.entity.Dapp;
import io.syng.entity.Profile;
import io.syng.fragment.ProfileDialogFragment;
import io.syng.util.GeneralUtil;
import io.syng.util.PrefsUtil;
import io.syng.util.ProfileManager;
@ -107,7 +107,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
FrameLayout content = (FrameLayout) findViewById(R.id.content);
ViewGroup inflated = (ViewGroup) inflater.inflate(layoutResID, content, true);
Toolbar toolbar = (Toolbar) inflated.findViewById(R.id.myToolbar);
Toolbar toolbar = (Toolbar) inflated.findViewById(R.id.profile_toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
@ -178,19 +178,6 @@ public abstract class BaseActivity extends AppCompatActivity implements
mHandler.postDelayed(mRunnable, DRAWER_CLOSE_DELAY_SHORT);
}
private void changeProfile(Profile profile) {
ProfileManager.setCurrentProfile(profile);
updateCurrentProfileName();
Glide.with(this).load(PrefsUtil.getBackgroundResourceId(profile.getId())).into(mHeaderImageView);
populateDApps();
flipDrawer();
}
private void updateCurrentProfileName() {
TextView textView = (TextView) findViewById(R.id.tv_name);
textView.setText(ProfileManager.getCurrentProfile().getName());
}
private void requestChangeProfile(final Profile profile) {
Dialog dialog = new MaterialDialog.Builder(BaseActivity.this)
.title(R.string.request_profile_password)
@ -215,6 +202,19 @@ public abstract class BaseActivity extends AppCompatActivity implements
GeneralUtil.showKeyBoard(name, this);
}
private void changeProfile(Profile profile) {
ProfileManager.setCurrentProfile(profile);
updateCurrentProfileName();
Glide.with(this).load(PrefsUtil.getBackgroundResourceId(profile.getId())).into(mHeaderImageView);
populateDApps();
flipDrawer();
}
private void updateCurrentProfileName() {
TextView textView = (TextView) findViewById(R.id.tv_name);
textView.setText(ProfileManager.getCurrentProfile().getName());
}
private void initSearch() {
mSearchTextView.addTextChangedListener(new TextWatcher() {
@Override
@ -503,21 +503,24 @@ public abstract class BaseActivity extends AppCompatActivity implements
@SuppressWarnings("ConstantConditions")
@Override
public void onProfilePress(final Profile profile) {
MaterialDialog dialog = new MaterialDialog.Builder(this)
.title("Edit account")
.content("Put your name to create new account")
.inputType(InputType.TYPE_CLASS_TEXT)
.input("Name", "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
profile.setName(input.toString());
ProfileManager.updateProfile(profile);
mProfileDrawerAdapter.swapData(ProfileManager.getProfiles());
updateCurrentProfileName();
}
}).show();
dialog.getInputEditText().setSingleLine();
dialog.getInputEditText().setText(profile.getName());
// MaterialDialog dialog = new MaterialDialog.Builder(this)
// .title("Edit account")
// .content("Put your name to create new account")
// .inputType(InputType.TYPE_CLASS_TEXT)
// .input("Name", "", new MaterialDialog.InputCallback() {
// @Override
// public void onInput(MaterialDialog dialog, CharSequence input) {
// profile.setName(input.toString());
// ProfileManager.updateProfile(profile);
// mProfileDrawerAdapter.swapData(ProfileManager.getProfiles());
// updateCurrentProfileName();
// }
// }).show();
// dialog.getInputEditText().setSingleLine();
// dialog.getInputEditText().setText(profile.getName());
ProfileDialogFragment dialogFragment = ProfileDialogFragment.newInstance();
dialogFragment.show(getSupportFragmentManager(), "profile_dialog");
}
@Override

View File

@ -0,0 +1,48 @@
package io.syng.adapter;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;
import io.syng.fragment.ConsoleFragment;
public final class ProfileViewPagerAdapter extends FragmentPagerAdapter {
public static final int GENERAL_POSITION = 0;
public static final int KEYS_POSITION = 1;
public static final String[] LABELS = new String[]{"General", "Keys"};
private final Context mContext;
public ProfileViewPagerAdapter(FragmentManager fragmentManager, Context context) {
super(fragmentManager);
this.mContext = context;
}
@Override
public Fragment getItem(int position) {
return new ConsoleFragment();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();
super.destroyItem(container, position, object);
}
@Override
public int getCount() {
return LABELS.length;
}
@Override
public CharSequence getPageTitle(int position) {
return LABELS[position];
}
}

View File

@ -0,0 +1,98 @@
package io.syng.fragment;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import io.syng.R;
import io.syng.adapter.ProfileViewPagerAdapter;
public class ProfileDialogFragment extends DialogFragment implements OnPageChangeListener {
private ViewPager mViewPager;
private TabLayout mTabLayout;
private Toolbar mToolbar;
public static ProfileDialogFragment newInstance() {
return new ProfileDialogFragment();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profile_edit_dialog, container);
mTabLayout = (TabLayout) view.findViewById(R.id.profile_tabs);
mViewPager = (ViewPager) view.findViewById(R.id.profile_view_pager);
mViewPager.addOnPageChangeListener(this);
mToolbar = (Toolbar) view.findViewById(R.id.profile_toolbar);
mToolbar.setTitle("Edit Profile");
mToolbar.inflateMenu(R.menu.profile_menu);
mToolbar.getMenu().findItem(R.id.action_key_export).setVisible(false);
mToolbar.getMenu().findItem(R.id.action_key_import).setVisible(false);
tintMenuItem();
mViewPager.setAdapter(new ProfileViewPagerAdapter(getChildFragmentManager(), getActivity()));
mTabLayout.setupWithViewPager(mViewPager);
return view;
}
private void tintMenuItem() {
Drawable drawable1 = mToolbar.getMenu().findItem(R.id.action_key_export).getIcon();
drawable1 = DrawableCompat.wrap(drawable1);
DrawableCompat.setTint(drawable1, getResources().getColor(R.color.drawer_icon_color));
mToolbar.getMenu().findItem(R.id.action_key_export).setIcon(drawable1);
Drawable drawable2 = mToolbar.getMenu().findItem(R.id.action_key_import).getIcon();
drawable2 = DrawableCompat.wrap(drawable2);
DrawableCompat.setTint(drawable2, getResources().getColor(R.color.drawer_icon_color));
mToolbar.getMenu().findItem(R.id.action_key_import).setIcon(drawable2);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
invalidateToolbarMenu();
}
@Override
public void onPageScrollStateChanged(int state) {
}
private void invalidateToolbarMenu() {
MenuItem exp = mToolbar.getMenu().findItem(R.id.action_key_export);
MenuItem imp = mToolbar.getMenu().findItem(R.id.action_key_import);
boolean showExport = mViewPager.getCurrentItem() == ProfileViewPagerAdapter.KEYS_POSITION;
exp.setVisible(showExport);
imp.setVisible(showExport);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

View File

@ -1,5 +1,5 @@
<android.support.v7.widget.Toolbar
android:id="@+id/myToolbar"
android:id="@+id/profile_toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"

View File

@ -27,7 +27,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_add_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
style="@style/Base.TextAppearance.AppCompat.Body2"

View File

@ -13,7 +13,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_search_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
android:layout_width="wrap_content"

View File

@ -14,7 +14,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_favorite_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
android:id="@+id/text"

View File

@ -31,7 +31,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_add_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
android:id="@+id/tv_import_wallet"
@ -60,7 +60,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_settings_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
android:id="@+id/settings"
@ -90,7 +90,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_github_circle_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
android:id="@+id/tv_contribute"

View File

@ -40,7 +40,7 @@
android:layout_marginStart="25dp"
android:gravity="center_vertical"
android:src="@drawable/ic_search_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
</RelativeLayout>

View File

@ -13,7 +13,7 @@
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_add_black_24dp"
android:tint="@color/drawer_icons_color"/>
android:tint="@color/drawer_icon_color"/>
<TextView
android:id="@+id/tv_add_account"

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/toolbar"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/profile_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/profile_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="scrollable"/>
<android.support.v4.view.ViewPager
android:id="@+id/profile_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View File

@ -0,0 +1,20 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_key_import"
android:icon="@drawable/ic_add_black_24dp"
android:orderInCategory="100"
android:title="@string/menu.profile.key.import"
app:showAsAction="always"/>
<item
android:id="@+id/action_key_export"
android:icon="@drawable/ic_forward_black_24dp"
android:orderInCategory="100"
android:title="@string/menu.profile.key.export"
app:showAsAction="always"/>
</menu>

View File

@ -4,7 +4,7 @@
tools:context=".webview">
<item
android:id="@+id/fav"
android:id="@+id/action_key_export"
android:icon="@drawable/fav"
android:orderInCategory="100"
android:title="Favourite"

View File

@ -9,6 +9,6 @@
<color name="accent">#536DFE</color>
<color name="fab_dark_color">#cfcfcf</color>
<color name="drawer_icons_color">#737373</color>
<color name="drawer_icon_color">#737373</color>
</resources>

View File

@ -35,5 +35,7 @@
<string name="hitn.profile.repeat.pass">Repeat password</string>
<string name="dialog.button.create">Create</string>
<string name="dialog.button.cancel">Cancel</string>
<string name="menu.profile.key.import">Import</string>
<string name="menu.profile.key.export">Export</string>
</resources>