Popup notice for new CrAzYpass feature (#254)

* make add notices more flexible

* and add CrAzYpass notice

* added notice translations
This commit is contained in:
m2049r 2018-04-23 23:43:45 +02:00 committed by GitHub
parent 0b17ed4322
commit 1115bbb706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 189 additions and 110 deletions

View File

@ -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<String> 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();
}

View File

@ -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());

View File

@ -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<Notice> 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();
}
}

View File

@ -11,34 +11,10 @@
android:orientation="vertical">
<LinearLayout
android:id="@+id/llXmrToEnabled"
android:id="@+id/llNotice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/moneroBlue"
android:orientation="horizontal">
<TextView
style="@style/MoneroLabel.Heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_info_white_24dp"
android:gravity="start|center_vertical"
android:padding="8dp"
android:text="@string/info_xmrto_enabled"
android:textColor="@color/white" />
<ImageButton
android:id="@+id/ibXmrToInfoClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#00000000"
android:padding="8dp"
android:src="@drawable/ic_close_white_24dp" />
</LinearLayout>
android:orientation="vertical" />
<EditText
android:id="@+id/etDummy"

View File

@ -7,34 +7,10 @@
android:orientation="vertical">
<LinearLayout
android:id="@+id/llXmrToEnabled"
android:id="@+id/llNotice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/moneroBlue"
android:orientation="horizontal">
<TextView
style="@style/MoneroLabel.Heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_info_white_24dp"
android:gravity="start|center_vertical"
android:padding="8dp"
android:text="@string/info_xmrto_enabled"
android:textColor="@color/white" />
<ImageButton
android:id="@+id/ibXmrToInfoClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#00000000"
android:padding="8dp"
android:src="@drawable/ic_close_white_24dp" />
</LinearLayout>
android:orientation="vertical" />
<EditText
android:id="@+id/etDummy"
@ -46,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/llNavBar"
android:layout_below="@id/llXmrToEnabled"
android:layout_below="@id/llNotice"
android:padding="8dp" />
<LinearLayout

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llNotice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/moneroBlue"
android:orientation="horizontal">
<TextView
android:id="@+id/tvNotice"
style="@style/MoneroLabel.Heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_info_white_24dp"
android:gravity="start|center_vertical"
android:padding="8dp"
android:textColor="@color/white"
tools:text="This is an important notice!" />
<ImageButton
android:id="@+id/ibClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#00000000"
android:padding="8dp"
android:src="@drawable/ic_close_white_24dp" />
</LinearLayout>

View File

@ -345,4 +345,5 @@
<string name="about_whoami">Soy monerujo</string>
<string name="info_send_xmrto_success_order_label">Orden XMR.TO</string>
<string name="info_xmrto_enabled">Pago en BTC activado, toca para más info.</string>
<string name="info_crazypass_enabled">CrAzYpass activado, toca para más info.</string>
</resources>

View File

@ -34,6 +34,7 @@
<string name="info_send_prio_fees">Priorità più alta = Commissioni più alte</string>
<string name="info_xmrto_enabled">Pagamento BTC abilitato, tocca per maggiori informazioni.</string>
<string name="info_crazypass_enabled">CrAzYpass abilitato, tocca per maggiori informazioni.</string>
<string name="info_xmrto"><![CDATA[
<b>Hai inserito un indirizzo Bitcoin.</b><br/>

View File

@ -34,6 +34,7 @@
<string name="info_send_prio_fees">Høyere prioritet = høyere avgifter</string>
<string name="info_xmrto_enabled">BTC betaling tilgjengelig, trykk for mer info.</string>
<string name="info_crazypass_enabled">CrAzYpass tilgjengelig, trykk for mer info.</string>
<string name="info_xmrto"><![CDATA[
<b>Du skrev inn en Bitcoin addresse.</b><br/>

View File

@ -34,6 +34,7 @@
<string name="info_send_prio_fees">較高優先權 = 較高手續費</string>
<string name="info_xmrto_enabled">BTC付款已啟用, 點選我獲得更多資訊</string>
<string name="info_crazypass_enabled">CrAzYpass已啟用, 點選我獲得更多資訊</string>
<string name="info_xmrto"><![CDATA[
<b>你已輸入Bitcoin地址</b><br/>

View File

@ -37,6 +37,8 @@
<string name="info_xmrto_enabled">BTC payment enabled, tap for more info.</string>
<string name="info_crazypass_enabled">CrAzYpass enabled, tap for more info.</string>
<string name="info_xmrto"><![CDATA[
<b>You entered a Bitcoin address.</b><br/>
<i>You&apos;ll send XMR and the receiver will get BTC using the <b>XMR.TO</b> service.</i>