From 8ef8e7dd9c38e2cbb04541a8107ee5445d215210 Mon Sep 17 00:00:00 2001 From: Yaroslav Berezanskyi Date: Sun, 16 Aug 2015 14:09:28 +0300 Subject: [PATCH] Custom dialog for profile edit with 2 tabs (with console fragment stubs inside) --- .../java/io/syng/activity/BaseActivity.java | 63 +++++------ .../syng/adapter/ProfileViewPagerAdapter.java | 48 +++++++++ .../syng/fragment/ProfileDialogFragment.java | 98 ++++++++++++++++++ .../drawable-hdpi/ic_forward_black_24dp.png | Bin 0 -> 133 bytes .../ic_import_export_black_24dp.png | Bin 0 -> 163 bytes .../drawable-mdpi/ic_forward_black_24dp.png | Bin 0 -> 114 bytes .../ic_import_export_black_24dp.png | Bin 0 -> 128 bytes .../drawable-xhdpi/ic_forward_black_24dp.png | Bin 0 -> 150 bytes .../ic_import_export_black_24dp.png | Bin 0 -> 186 bytes .../drawable-xxhdpi/ic_forward_black_24dp.png | Bin 0 -> 192 bytes .../ic_import_export_black_24dp.png | Bin 0 -> 230 bytes .../ic_forward_black_24dp.png | Bin 0 -> 231 bytes .../ic_import_export_black_24dp.png | Bin 0 -> 302 bytes app/src/main/res/layout/app_toolbar.xml | 2 +- .../main/res/layout/dapp_drawer_add_item.xml | 2 +- .../dapp_drawer_continue_search_item.xml | 2 +- .../main/res/layout/dapp_drawer_list_item.xml | 2 +- .../main/res/layout/drawer_bottom_part.xml | 6 +- app/src/main/res/layout/drawer_front_view.xml | 2 +- .../res/layout/profile_drawer_list_add.xml | 2 +- .../main/res/layout/profile_edit_dialog.xml | 28 +++++ app/src/main/res/menu/profile_menu.xml | 20 ++++ app/src/main/res/menu/webview_menu.xml | 2 +- app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 2 + 25 files changed, 240 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/io/syng/adapter/ProfileViewPagerAdapter.java create mode 100644 app/src/main/java/io/syng/fragment/ProfileDialogFragment.java create mode 100644 app/src/main/res/drawable-hdpi/ic_forward_black_24dp.png create mode 100644 app/src/main/res/drawable-hdpi/ic_import_export_black_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_forward_black_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_import_export_black_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_forward_black_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_import_export_black_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_forward_black_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_import_export_black_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_forward_black_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_import_export_black_24dp.png create mode 100644 app/src/main/res/layout/profile_edit_dialog.xml create mode 100644 app/src/main/res/menu/profile_menu.xml diff --git a/app/src/main/java/io/syng/activity/BaseActivity.java b/app/src/main/java/io/syng/activity/BaseActivity.java index 602a31f..dfc61d7 100644 --- a/app/src/main/java/io/syng/activity/BaseActivity.java +++ b/app/src/main/java/io/syng/activity/BaseActivity.java @@ -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 diff --git a/app/src/main/java/io/syng/adapter/ProfileViewPagerAdapter.java b/app/src/main/java/io/syng/adapter/ProfileViewPagerAdapter.java new file mode 100644 index 0000000..65486f9 --- /dev/null +++ b/app/src/main/java/io/syng/adapter/ProfileViewPagerAdapter.java @@ -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]; + } +} \ No newline at end of file diff --git a/app/src/main/java/io/syng/fragment/ProfileDialogFragment.java b/app/src/main/java/io/syng/fragment/ProfileDialogFragment.java new file mode 100644 index 0000000..bc3e200 --- /dev/null +++ b/app/src/main/java/io/syng/fragment/ProfileDialogFragment.java @@ -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); + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_forward_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_forward_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..13a912841c7b294a3bdbb66b21fed6fbb4d2b7bf GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K;kEe@cNCo5DD~4PQ3OolK=Fgjd zTwfzaBWc%tg>A2I)`d(EO?8b744blj3cE9_ERX@@SDNxPOMJc2^J_wiceF!~RZfr9 ezcu$K=N{Z4_vhEFt@%K689ZJ6T-G@yGywo|uq?R% literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi/ic_import_export_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_import_export_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..b4466c8492b33165e2aac9c62a968c671f933aa0 GIT binary patch literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K8mZytjNCo5Dsfv8ehCD3a)lUZh z+R)_t>x1pdu7fKz${ZTfC!AF9?iM-9?k*uvp|-dt%Sn&z(4Pgzopr026B^*Z=?k literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_import_export_black_24dp.png b/app/src/main/res/drawable-mdpi/ic_import_export_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..90f8c4567e2aacf7295f7aa61568b65a4d5bb76c GIT binary patch literal 128 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1cTX3`kP61DXASv|C$74nP9&quv>-pH84H2Z+s22LRLK>y%POLZ_4BGRwH5LA0|WnIR~e{UY~ p&$%~o=Bur$S63(NMc=<3rGGB&qdQ$w!t&+ca*7L?3JECyIq2Ed` ldC}x0>hr#L@-2N*&Fq-{?t4VOtU1sz44$rjF6*2UngC=SOwIrR literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_forward_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_forward_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9a05bf2697e1bf4a061a62d135ceea99b2ddd248 GIT binary patch literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw+C5zyLn;{G-n_`!U?6bdLSNnN z3Cb_}W#DIj-PezO z%gYJ%4ayQC(o2u;@5@a5+H(0)@xRR$@3Rtj%@Ya(+Q1l8UVU}WA=VW@Coy=s`njxg HN@xNA&=)~b literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_import_export_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_import_export_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..78e865dfae18994c1e7c0f40fdc9a57294a00fc0 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw)_S@)hEy=Vy=lwGWXQw%u>7;d zP5E^`jVV%HQ(HM$i*!srpE8M;?e6HPn|Ly0h2He*io8Fw_lhlN$(-EItD7@@|IM(* z;D(YD_Br82%WF0*7E_;EGP!h**57GSAkRVsh3`PXDmxSYTv%pI=5wm-9sJqnOrFogIiPnmusjg bEmB{gCV4q2c*1p{!x=nX{an^LB{Ts56RcS| literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_forward_black_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_forward_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..2187b5fe8cbc94a0aeac8d106ff21735371e02b1 GIT binary patch literal 231 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeG3?%1&o4*=JaR&H=xB_ViXik240LWr03GxeO zXqc_-CjsPjd%8G=R4~51vQhAmg9vk=S8!)|i_kW&pbux*x(X7Oa@|Y#_wwtLeVwAm zyP`gBV{$fNK|wo|YE;8yw6l)#Hz`V>qL_(WU-YE^ZJcYLbj^O%XTucR9p~I-Yb}CG w>gGhUFZg^SMRwD<3GsGE{>_;=bLPzx9tFa#PleK6r3*LeUOD{i&GX}e zVXHQ_PB43wqRseL# nC+XYgzi-zyHa6Z|f6Y8^((bn>+9SgTe~DWM4fgX4RM literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/app_toolbar.xml b/app/src/main/res/layout/app_toolbar.xml index 6bf26ab..9f37652 100644 --- a/app/src/main/res/layout/app_toolbar.xml +++ b/app/src/main/res/layout/app_toolbar.xml @@ -1,5 +1,5 @@ + android:tint="@color/drawer_icon_color"/> + android:tint="@color/drawer_icon_color"/> + android:tint="@color/drawer_icon_color"/> + android:tint="@color/drawer_icon_color"/> + android:tint="@color/drawer_icon_color"/> + android:tint="@color/drawer_icon_color"/> + android:tint="@color/drawer_icon_color"/> diff --git a/app/src/main/res/layout/profile_drawer_list_add.xml b/app/src/main/res/layout/profile_drawer_list_add.xml index f573c5c..7594f8f 100644 --- a/app/src/main/res/layout/profile_drawer_list_add.xml +++ b/app/src/main/res/layout/profile_drawer_list_add.xml @@ -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"/> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/profile_menu.xml b/app/src/main/res/menu/profile_menu.xml new file mode 100644 index 0000000..4c0112f --- /dev/null +++ b/app/src/main/res/menu/profile_menu.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/app/src/main/res/menu/webview_menu.xml b/app/src/main/res/menu/webview_menu.xml index cb474b9..8895455 100644 --- a/app/src/main/res/menu/webview_menu.xml +++ b/app/src/main/res/menu/webview_menu.xml @@ -4,7 +4,7 @@ tools:context=".webview"> #536DFE #cfcfcf - #737373 + #737373 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 719cb56..746d0fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,5 +35,7 @@ Repeat password Create Cancel + Import + Export