From 1115bbb70627bcae0e74c1bda3d8459d591ede32 Mon Sep 17 00:00:00 2001 From: m2049r Date: Mon, 23 Apr 2018 23:43:45 +0200 Subject: [PATCH] Popup notice for new CrAzYpass feature (#254) * make add notices more flexible * and add CrAzYpass notice * added notice translations --- .../com/m2049r/xmrwallet/LoginFragment.java | 44 ++---- .../xmrwallet/fragment/send/SendFragment.java | 24 +--- .../com/m2049r/xmrwallet/util/Notice.java | 135 ++++++++++++++++++ app/src/main/res/layout/fragment_login.xml | 28 +--- app/src/main/res/layout/fragment_send.xml | 30 +--- app/src/main/res/layout/template_notice.xml | 32 +++++ app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-nb/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 + 11 files changed, 189 insertions(+), 110 deletions(-) create mode 100644 app/src/main/java/com/m2049r/xmrwallet/util/Notice.java create mode 100644 app/src/main/res/layout/template_notice.xml diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java index b52fceb..a7c3fb4 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java @@ -18,12 +18,15 @@ package com.m2049r.xmrwallet; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.ColorStateList; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; +import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -38,7 +41,9 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.FrameLayout; +import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -49,6 +54,7 @@ import com.m2049r.xmrwallet.model.NetworkType; import com.m2049r.xmrwallet.model.WalletManager; import com.m2049r.xmrwallet.util.Helper; import com.m2049r.xmrwallet.util.NodeList; +import com.m2049r.xmrwallet.util.Notice; import com.m2049r.xmrwallet.widget.DropDownEditText; import com.m2049r.xmrwallet.widget.Toolbar; @@ -71,9 +77,6 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter private DropDownEditText etDaemonAddress; private ArrayAdapter nodeAdapter; - private View llXmrToEnabled; - private View ibXmrToInfoClose; - private Listener activityCallback; // Container Activity must implement this interface @@ -173,23 +176,8 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter etDummy = (EditText) view.findViewById(R.id.etDummy); - llXmrToEnabled = view.findViewById(R.id.llXmrToEnabled); - llXmrToEnabled.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - HelpFragment.display(getChildFragmentManager(), R.string.help_xmrto); - - } - }); - ibXmrToInfoClose = view.findViewById(R.id.ibXmrToInfoClose); - ibXmrToInfoClose.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - llXmrToEnabled.setVisibility(View.GONE); - showXmrtoEnabled = false; - saveXmrToPrefs(); - } - }); + ViewGroup llNotice = (ViewGroup) view.findViewById(R.id.llNotice); + Notice.showAll(llNotice,".*_login"); etDaemonAddress = (DropDownEditText) view.findViewById(R.id.etDaemonAddress); nodeAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line); @@ -237,9 +225,6 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter }); loadPrefs(); - if (!showXmrtoEnabled) { - llXmrToEnabled.setVisibility(View.GONE); - } return view; } @@ -379,7 +364,6 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter private static final String PREF_DAEMON_TESTNET = "daemon_testnet"; private static final String PREF_DAEMON_MAINNET = "daemon_mainnet"; - private static final String PREF_SHOW_XMRTO_ENABLED = "info_xmrto_enabled_login"; private static final String PREF_DAEMONLIST_MAINNET = "node.moneroworld.com:18089;node.xmrbackb.one;node.xmr.be"; @@ -390,23 +374,12 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter private NodeList daemonTestNet; private NodeList daemonMainNet; - boolean showXmrtoEnabled = true; - void loadPrefs() { SharedPreferences sharedPref = activityCallback.getPrefs(); daemonMainNet = new NodeList(sharedPref.getString(PREF_DAEMON_MAINNET, PREF_DAEMONLIST_MAINNET)); daemonTestNet = new NodeList(sharedPref.getString(PREF_DAEMON_TESTNET, PREF_DAEMONLIST_TESTNET)); setNet(testnetCheckMenu, false); - - showXmrtoEnabled = sharedPref.getBoolean(PREF_SHOW_XMRTO_ENABLED, true); - } - - void saveXmrToPrefs() { - SharedPreferences sharedPref = activityCallback.getPrefs(); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.putBoolean(PREF_SHOW_XMRTO_ENABLED, showXmrtoEnabled); - editor.apply(); } void savePrefs() { @@ -428,7 +401,6 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(PREF_DAEMON_MAINNET, daemonMainNet.toString()); editor.putString(PREF_DAEMON_TESTNET, daemonTestNet.toString()); - editor.putBoolean(PREF_SHOW_XMRTO_ENABLED, showXmrtoEnabled); editor.apply(); } diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendFragment.java index bdafc04..05dcdc8 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendFragment.java @@ -47,6 +47,7 @@ import com.m2049r.xmrwallet.layout.SpendViewPager; import com.m2049r.xmrwallet.model.PendingTransaction; import com.m2049r.xmrwallet.util.Helper; import com.m2049r.xmrwallet.util.NodeList; +import com.m2049r.xmrwallet.util.Notice; import com.m2049r.xmrwallet.util.UserNotes; import com.m2049r.xmrwallet.widget.DotBar; import com.m2049r.xmrwallet.widget.Toolbar; @@ -119,27 +120,8 @@ public class SendFragment extends Fragment arrowPrev = getResources().getDrawable(R.drawable.ic_navigate_prev_white_24dp); arrowNext = getResources().getDrawable(R.drawable.ic_navigate_next_white_24dp); - llXmrToEnabled = view.findViewById(R.id.llXmrToEnabled); - llXmrToEnabled.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - HelpFragment.display(getChildFragmentManager(), R.string.help_xmrto); - - } - }); - ibXmrToInfoClose = view.findViewById(R.id.ibXmrToInfoClose); - ibXmrToInfoClose.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - llXmrToEnabled.setVisibility(View.GONE); - showXmrtoEnabled = false; - saveXmrToPrefs(); - } - }); - loadPrefs(); - if (!showXmrtoEnabled) { - llXmrToEnabled.setVisibility(View.GONE); - } + ViewGroup llNotice = (ViewGroup) view.findViewById(R.id.llNotice); + Notice.showAll(llNotice,".*_send"); spendViewPager = (SpendViewPager) view.findViewById(R.id.pager); pagerAdapter = new SpendPagerAdapter(getChildFragmentManager()); diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java b/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java new file mode 100644 index 0000000..1b0b1c8 --- /dev/null +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2018 m2049r + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.m2049r.xmrwallet.util; + +import android.content.Context; +import android.content.SharedPreferences; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.m2049r.xmrwallet.R; +import com.m2049r.xmrwallet.dialog.HelpFragment; + +import java.util.ArrayList; +import java.util.List; + +public class Notice { + private static final String PREFS_NAME = "notice"; + private static List notices = null; + + private static final String NOTICE_SHOW_XMRTO_ENABLED_LOGIN = "notice_xmrto_enabled_login"; + private static final String NOTICE_SHOW_XMRTO_ENABLED_SEND = "notice_xmrto_enabled_send"; + private static final String NOTICE_SHOW_CRAZYPASS = "notice_crazypass_enabled_login"; + + private static void init() { + synchronized (Notice.class) { + if (notices != null) return; + notices = new ArrayList<>(); + notices.add( + new Notice(NOTICE_SHOW_XMRTO_ENABLED_SEND, + R.string.info_xmrto_enabled, + R.string.help_xmrto, + 1) + ); + notices.add( + new Notice(NOTICE_SHOW_XMRTO_ENABLED_LOGIN, + R.string.info_xmrto_enabled, + R.string.help_xmrto, + 1) + ); + notices.add( + new Notice(NOTICE_SHOW_CRAZYPASS, + R.string.info_crazypass_enabled, + R.string.help_details, + 2) + ); + } + } + + public static void showAll(ViewGroup parent, String selector) { + if (notices == null) init(); + for (Notice notice : notices) { + if (notice.id.matches(selector)) + notice.show(parent); + } + } + + private final String id; + private final int textResId; + private final int helpResId; + private final int defaultCount; + private transient int count = -1; + + private Notice(final String id, final int textResId, final int helpResId, final int defaultCount) { + this.id = id; + this.textResId = textResId; + this.helpResId = helpResId; + this.defaultCount = defaultCount; + } + + // show this notice as a child of the given parent view + // NB: it assumes the parent is in a Fragment + private void show(final ViewGroup parent) { + final Context context = parent.getContext(); + if (getCount(context) <= 0) return; // don't add it + + final LinearLayout ll = + (LinearLayout) LayoutInflater.from(context) + .inflate(R.layout.template_notice, parent, false); + + ((TextView) ll.findViewById(R.id.tvNotice)).setText(textResId); + + final FragmentManager fragmentManager = + ((FragmentActivity) context).getSupportFragmentManager(); + ll.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + HelpFragment.display(fragmentManager, helpResId); + } + }); + + ImageButton ib = (ImageButton) ll.findViewById(R.id.ibClose); + ib.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ll.setVisibility(View.GONE); + decCount(context); + } + }); + parent.addView(ll); + } + + private int getCount(final Context context) { + count = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + .getInt(id, defaultCount); + return count; + } + + private void decCount(final Context context) { + final SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + if (count < 0) // not initialized yet + count = prefs.getInt(id, defaultCount); + if (count > 0) + prefs.edit().putInt(id, count - 1).apply(); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_login.xml b/app/src/main/res/layout/fragment_login.xml index 3a25db6..c52d203 100644 --- a/app/src/main/res/layout/fragment_login.xml +++ b/app/src/main/res/layout/fragment_login.xml @@ -11,34 +11,10 @@ android:orientation="vertical"> - - - - - - + android:orientation="vertical" /> - - - - - - + android:orientation="vertical" /> + + + + + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 416219d..04176f3 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -345,4 +345,5 @@ Soy monerujo Orden XMR.TO Pago en BTC activado, toca para más info. + CrAzYpass activado, toca para más info. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0762b5d..0cbc341 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -34,6 +34,7 @@ Priorità più alta = Commissioni più alte Pagamento BTC abilitato, tocca per maggiori informazioni. + CrAzYpass abilitato, tocca per maggiori informazioni. Hai inserito un indirizzo Bitcoin.
diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 1e777c3..79ecb73 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -34,6 +34,7 @@ Høyere prioritet = høyere avgifter BTC betaling tilgjengelig, trykk for mer info. + CrAzYpass tilgjengelig, trykk for mer info. Du skrev inn en Bitcoin addresse.
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 7f7ebb1..1793bb0 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -34,6 +34,7 @@ 較高優先權 = 較高手續費 BTC付款已啟用, 點選我獲得更多資訊 + CrAzYpass已啟用, 點選我獲得更多資訊 你已輸入Bitcoin地址
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14490ed..aac6698 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,6 +37,8 @@ BTC payment enabled, tap for more info. + CrAzYpass enabled, tap for more info. + You entered a Bitcoin address.
You'll send XMR and the receiver will get BTC using the XMR.TO service.