From b529bc81798eb8c3b8dc1d06f79cd5b75129de16 Mon Sep 17 00:00:00 2001 From: Yaroslav Berezanskyi Date: Wed, 9 Sep 2015 11:04:52 +0300 Subject: [PATCH] Remove DApp functionality --- .../main/java/io/syng/activity/BaseActivity.java | 4 ++-- app/src/main/java/io/syng/entity/Dapp.java | 8 ++++++++ app/src/main/java/io/syng/util/GeneralUtil.java | 15 +++++++++++---- .../main/java/io/syng/util/ProfileManager.java | 6 +++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/syng/activity/BaseActivity.java b/app/src/main/java/io/syng/activity/BaseActivity.java index 89e965f..31e2fcc 100644 --- a/app/src/main/java/io/syng/activity/BaseActivity.java +++ b/app/src/main/java/io/syng/activity/BaseActivity.java @@ -109,11 +109,11 @@ public abstract class BaseActivity extends AppCompatActivity implements private DAppDrawerAdapter mDAppsDrawerAdapter; private ProfileDrawerAdapter mProfileDrawerAdapter; - protected abstract void onDAppClick(Dapp dapp); - private ItemTouchHelper mDAppsTouchHelper; private ItemTouchHelper mProfilesTouchHelper; + protected abstract void onDAppClick(Dapp dapp); + @SuppressLint("InflateParams") @Override public void setContentView(final int layoutResID) { diff --git a/app/src/main/java/io/syng/entity/Dapp.java b/app/src/main/java/io/syng/entity/Dapp.java index 085ecfc..622c123 100644 --- a/app/src/main/java/io/syng/entity/Dapp.java +++ b/app/src/main/java/io/syng/entity/Dapp.java @@ -77,4 +77,12 @@ public class Dapp implements Serializable { this.id = id; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Dapp)) return false; + Dapp object = (Dapp) o; + return object.getId().equalsIgnoreCase(id); + } } diff --git a/app/src/main/java/io/syng/util/GeneralUtil.java b/app/src/main/java/io/syng/util/GeneralUtil.java index 39b6f4a..1e6aacf 100644 --- a/app/src/main/java/io/syng/util/GeneralUtil.java +++ b/app/src/main/java/io/syng/util/GeneralUtil.java @@ -43,16 +43,14 @@ import io.syng.entity.Profile; public final class GeneralUtil { public static void hideKeyBoard(View view, Context context) { - if (view == null) - return; + if (view == null) return; InputMethodManager imm = (InputMethodManager) context.getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } public static void showKeyBoard(View view, Context context) { - if (view == null) - return; + if (view == null) return; InputMethodManager imm = (InputMethodManager) context.getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } @@ -158,6 +156,8 @@ public final class GeneralUtil { .customView(R.layout.dapp_form, true) .positiveText(R.string.save) .negativeText(R.string.cancel) + .neutralText("Remove") + .neutralColorRes(android.R.color.holo_red_dark) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { @@ -185,6 +185,12 @@ public final class GeneralUtil { public void onNegative(MaterialDialog dialog) { dialog.hide(); } + + @Override + public void onNeutral(MaterialDialog dialog) { + ProfileManager.removeDAppInProfile(ProfileManager.getCurrentProfile(), dapp); + dialog.hide(); + } }) .autoDismiss(false) .build(); @@ -241,6 +247,7 @@ public final class GeneralUtil { .positiveText(R.string.sImport) .negativeText(R.string.cancel) .callback(new MaterialDialog.ButtonCallback() { + @SuppressWarnings("TryFinallyCanBeTryWithResources") @Override public void onPositive(MaterialDialog dialog) { diff --git a/app/src/main/java/io/syng/util/ProfileManager.java b/app/src/main/java/io/syng/util/ProfileManager.java index 4f2d9a0..5b238bd 100644 --- a/app/src/main/java/io/syng/util/ProfileManager.java +++ b/app/src/main/java/io/syng/util/ProfileManager.java @@ -96,7 +96,6 @@ public final class ProfileManager { } } - return new Profile(); } @@ -113,6 +112,11 @@ public final class ProfileManager { notifyListener(); } + public static void removeDAppInProfile(Profile profile, Dapp dapp) { + profile.removeDapp(dapp); + ProfileManager.updateProfile(profile); + notifyListener(); + } public static void updateDAppInProfile(Profile profile, Dapp dapp) { profile.updateDapp(dapp);