diff --git a/app/build.gradle b/app/build.gradle index 6053c2726..fc6a5321c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,6 +70,9 @@ android { archivesBaseName = "${versionName}(${versionCode})" buildConfigField "String", "INFURA_KEY", "\"set the infura key here\"" + buildConfigField "String", "LITEWALLET_API_URL_PROD", "\"https://api-prod.lite-wallet.org\"" + buildConfigField "String", "LITEWALLET_API_URL_DEV", "\"https://api-dev.lite-wallet.org\"" + // Similar to other properties in the defaultConfig block, // you can configure the ndk block for each product flavor diff --git a/app/src/main/java/com/breadwallet/presenter/activities/settings/AdvancedActivity.java b/app/src/main/java/com/breadwallet/presenter/activities/settings/AdvancedActivity.java index 8b4ce7079..df2062ddd 100644 --- a/app/src/main/java/com/breadwallet/presenter/activities/settings/AdvancedActivity.java +++ b/app/src/main/java/com/breadwallet/presenter/activities/settings/AdvancedActivity.java @@ -1,12 +1,17 @@ package com.breadwallet.presenter.activities.settings; +import static com.breadwallet.BuildConfig.LITEWALLET_API_URL_DEV; +import static com.breadwallet.R.layout.settings_list_item; +import static com.breadwallet.R.layout.settings_list_section; +import static com.breadwallet.R.layout.settings_list_switch; +import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.ADDON; +import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.SECTION; +import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.SWITCH; + import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.LayoutRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,16 +19,19 @@ import android.widget.ListView; import android.widget.TextView; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.SwitchCompat; + import com.breadwallet.R; import com.breadwallet.presenter.activities.util.BRActivity; import com.breadwallet.presenter.entities.BRSettingsItem; +import com.breadwallet.tools.manager.BRSharedPrefs; import java.util.ArrayList; import java.util.List; -import static com.breadwallet.R.layout.settings_list_item; -import static com.breadwallet.R.layout.settings_list_section; - public class AdvancedActivity extends BRActivity { private static final String TAG = AdvancedActivity.class.getName(); private ListView listView; @@ -41,10 +49,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_advanced); listView = (ListView) findViewById(R.id.settings_list); - } - public class SettingsListAdapter extends ArrayAdapter { private List items; @@ -64,19 +70,30 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup BRSettingsItem item = items.get(position); LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); - if (item.isSection) { - v = inflater.inflate(settings_list_section, parent, false); - } else { - v = inflater.inflate(settings_list_item, parent, false); - TextView addon = (TextView) v.findViewById(R.id.item_addon); - addon.setText(item.addonText); - v.setOnClickListener(item.listener); + switch (item.type) { + case SECTION: + v = inflater.inflate(settings_list_section, parent, false); + v.setOnClickListener(item.listener); + break; + case SWITCH: + v = inflater.inflate(settings_list_switch, parent, false); + View switchView = v.findViewById(R.id.item_switch); + if (switchView instanceof SwitchCompat) { + ((SwitchCompat) switchView).setChecked(item.isChecked); + switchView.setOnClickListener(item.listener); + } + break; + default: + v = inflater.inflate(settings_list_item, parent, false); + TextView addon = (TextView) v.findViewById(R.id.item_addon); + addon.setText(item.addonText); + v.setOnClickListener(item.listener); + break; } TextView title = (TextView) v.findViewById(R.id.item_title); title.setText(item.title); return v; - } @Override @@ -113,21 +130,24 @@ public void onBackPressed() { private void populateItems() { - items.add(new BRSettingsItem("", "", null, true)); - - items.add(new BRSettingsItem(getString(R.string.NodeSelector_title), "", new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(AdvancedActivity.this, NodesActivity.class); - startActivity(intent); - overridePendingTransition(R.anim.enter_from_right, R.anim.empty_300); - - } - }, false)); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { + items.add(new BRSettingsItem(SECTION, null, null, null, null)); + + items.add(new BRSettingsItem(ADDON, getString(R.string.NodeSelector_title), "", null, v -> { + Intent intent = new Intent(AdvancedActivity.this, NodesActivity.class); + startActivity(intent); + overridePendingTransition(R.anim.enter_from_right, R.anim.empty_300); + })); + + items.add(new BRSettingsItem(SWITCH, getString(R.string.DeveloperMode_title), "", + BRSharedPrefs.getApiServerMode(getApplicationContext()) == LITEWALLET_API_URL_DEV, v -> { + if (v instanceof SwitchCompat) { + if (((SwitchCompat) v).isChecked()) { + BRSharedPrefs.setApiServerMode(v.getContext(), BRSharedPrefs.PrefsServerMode.DEV); + } else { + BRSharedPrefs.setApiServerMode(v.getContext(), BRSharedPrefs.PrefsServerMode.PROD); + } + } + })); } @Override diff --git a/app/src/main/java/com/breadwallet/presenter/activities/settings/SettingsActivity.java b/app/src/main/java/com/breadwallet/presenter/activities/settings/SettingsActivity.java index 715783336..b7275eefd 100644 --- a/app/src/main/java/com/breadwallet/presenter/activities/settings/SettingsActivity.java +++ b/app/src/main/java/com/breadwallet/presenter/activities/settings/SettingsActivity.java @@ -1,5 +1,11 @@ package com.breadwallet.presenter.activities.settings; +import static com.breadwallet.R.layout.settings_list_item; +import static com.breadwallet.R.layout.settings_list_section; +import static com.breadwallet.R.layout.settings_list_switch; +import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.ADDON; +import static com.breadwallet.presenter.entities.BRSettingsItem.SettingItemsType.SECTION; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -16,20 +22,16 @@ import androidx.annotation.Nullable; import com.breadwallet.R; -import com.breadwallet.presenter.language.ChangeLanguageBottomSheet; import com.breadwallet.presenter.activities.util.BRActivity; import com.breadwallet.presenter.entities.BRSettingsItem; import com.breadwallet.presenter.interfaces.BRAuthCompletion; +import com.breadwallet.presenter.language.ChangeLanguageBottomSheet; import com.breadwallet.tools.manager.BRSharedPrefs; import com.breadwallet.tools.security.AuthManager; -import com.platform.APIClient; import java.util.ArrayList; import java.util.List; -import static com.breadwallet.R.layout.settings_list_item; -import static com.breadwallet.R.layout.settings_list_section; - public class SettingsActivity extends BRActivity { private ListView listView; public List items; @@ -67,19 +69,32 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup BRSettingsItem item = items.get(position); LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); - if (item.isSection) { - v = inflater.inflate(settings_list_section, parent, false); - } else { - v = inflater.inflate(settings_list_item, parent, false); - TextView addon = (TextView) v.findViewById(R.id.item_addon); - addon.setText(item.addonText); - v.setOnClickListener(item.listener); + + switch (item.type) { + case SECTION: + v = inflater.inflate(settings_list_section, parent, false); + v.setOnClickListener(item.listener); + break; + case SWITCH: + v = inflater.inflate(settings_list_switch, parent, false); + if (item.isChecked) { + View switchView = v.findViewById(R.id.button_switch); + if (switchView != null) { + switchView.setOnClickListener(item.listener); + } + } + break; + default: + v = inflater.inflate(settings_list_item, parent, false); + TextView addon = (TextView) v.findViewById(R.id.item_addon); + addon.setText(item.addonText); + v.setOnClickListener(item.listener); + break; } TextView title = (TextView) v.findViewById(R.id.item_title); title.setText(item.title); return v; - } @Override @@ -116,29 +131,29 @@ public void onBackPressed() { private void populateItems() { /*Wallet Title*/ - items.add(new BRSettingsItem(getString(R.string.Settings_wallet), "", null, true)); + items.add(new BRSettingsItem(SECTION, getString(R.string.Settings_wallet), "", null, null)); /*Import Title*/ - items.add(new BRSettingsItem(getString(R.string.Settings_importTitle), "", v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_importTitle), "", null, v -> { Intent intent = new Intent(SettingsActivity.this, ImportActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_bottom, R.anim.empty_300); - }, false)); + })); /*Wipe Start_Recover Wallet*/ - items.add(new BRSettingsItem(getString(R.string.Settings_wipe), "", v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_wipe), "", null, v -> { Intent intent = new Intent(SettingsActivity.this, WipeActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_bottom, R.anim.empty_300); - }, false)); + })); /*Manage Title*/ - items.add(new BRSettingsItem(getString(R.string.Settings_manage), "", null, true)); + items.add(new BRSettingsItem(SECTION, getString(R.string.Settings_manage), "", null, null)); /*Fingerprint Limits*/ if (AuthManager.isFingerPrintAvailableAndSetup(this)) { - items.add(new BRSettingsItem(getString(R.string.Settings_touchIdLimit_android), "", v -> AuthManager.getInstance().authPrompt(SettingsActivity.this, null, getString(R.string.VerifyPin_continueBody), true, false, new BRAuthCompletion() { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_touchIdLimit_android), "", null, v -> AuthManager.getInstance().authPrompt(SettingsActivity.this, null, getString(R.string.VerifyPin_continueBody), true, false, new BRAuthCompletion() { @Override public void onComplete() { Intent intent = new Intent(SettingsActivity.this, SpendLimitActivity.class); @@ -150,58 +165,58 @@ public void onComplete() { public void onCancel() { } - }), false)); + }))); } /*Languages*/ - items.add(new BRSettingsItem(getString(R.string.Settings_languages), null, v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_languages), null, null, v -> { ChangeLanguageBottomSheet fragment = new ChangeLanguageBottomSheet(); fragment.show(getSupportFragmentManager(), fragment.getTag()); - }, false)); + })); /*Display Currency*/ - items.add(new BRSettingsItem(getString(R.string.Settings_currency), BRSharedPrefs.getIso(this), v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_currency), BRSharedPrefs.getIso(this), null, v -> { Intent intent = new Intent(SettingsActivity.this, DisplayCurrencyActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left); - }, false)); + })); /*Sync Blockchain*/ - items.add(new BRSettingsItem(getString(R.string.Settings_sync), "", v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_sync), "", null, v -> { Intent intent = new Intent(SettingsActivity.this, SyncBlockchainActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left); - }, false)); + })); /*SPACER*/ - items.add(new BRSettingsItem("", "", null, true)); + items.add(new BRSettingsItem(SECTION, "", "", null, null)); /*Share Anonymous Data*/ - items.add(new BRSettingsItem(getString(R.string.Settings_shareData), "", v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_shareData), "", null, v -> { Intent intent = new Intent(SettingsActivity.this, ShareDataActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left); - }, false)); + })); /*About*/ - items.add(new BRSettingsItem(getString(R.string.Settings_about), "", v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_about), "", null, v -> { Intent intent = new Intent(SettingsActivity.this, AboutActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left); - }, false)); + })); /*SPACER*/ - items.add(new BRSettingsItem("", "", null, true)); + items.add(new BRSettingsItem(SECTION, "", "", null, null)); /*Advanced Settings*/ - items.add(new BRSettingsItem(getString(R.string.Settings_advancedTitle), "", v -> { + items.add(new BRSettingsItem(ADDON, getString(R.string.Settings_advancedTitle), "", null, v -> { Intent intent = new Intent(SettingsActivity.this, AdvancedActivity.class); startActivity(intent); overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left); - }, false)); + })); /*SPACER*/ - items.add(new BRSettingsItem("", "", null, true)); + items.add(new BRSettingsItem(SECTION, "", "", null, null)); } @Override diff --git a/app/src/main/java/com/breadwallet/presenter/entities/BRSettingsItem.java b/app/src/main/java/com/breadwallet/presenter/entities/BRSettingsItem.java index e55c1f375..879e362a8 100644 --- a/app/src/main/java/com/breadwallet/presenter/entities/BRSettingsItem.java +++ b/app/src/main/java/com/breadwallet/presenter/entities/BRSettingsItem.java @@ -4,16 +4,21 @@ public class BRSettingsItem { - public boolean isSection; + public enum SettingItemsType { + SECTION, ADDON, SWITCH + } + + public SettingItemsType type; public String title; public String addonText; + public Boolean isChecked; public View.OnClickListener listener; - public BRSettingsItem(String title, String addonText, View.OnClickListener listener, boolean isSection) { + public BRSettingsItem(SettingItemsType type, String title, String addonText, Boolean isChecked, View.OnClickListener listener) { + this.type = type; this.title = title; this.addonText = addonText; + this.isChecked = isChecked; this.listener = listener; - this.isSection = isSection; } - } \ No newline at end of file diff --git a/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBuy.java b/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBuy.java index 8c2f0b2ea..c601b55c7 100644 --- a/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBuy.java +++ b/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBuy.java @@ -45,7 +45,6 @@ public class FragmentBuy extends Fragment { private ProgressBar progress; private WebView webView; private String onCloseUrl; - private static final String URL_BUY_LTC = BuildConfig.DEBUG ? "https://api-stage.lite-wallet.org" : "https://api-prod.lite-wallet.org"; private static final String CURRENCY_KEY = "currency_code_key"; private static final String PARTNER_KEY = "partner_key"; private ValueCallback uploadMessage; @@ -109,12 +108,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } - public static String url(Context context, Partner partner, String currency) { + public static String url(Context context, Partner partner, String currency) { String walletAddress = BRSharedPrefs.getReceiveAddress(context); Long timestamp = new Date().getTime(); String uuid = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); String prefix = partner == Partner.MOONPAY ? "/moonpay/buy" : ""; - return String.format(URL_BUY_LTC + prefix + "?address=%s&code=%s&idate=%s&uid=%s", walletAddress, currency, timestamp, uuid); + return String.format(BRSharedPrefs.getApiServerMode(context) + prefix + "?address=%s&code=%s&idate=%s&uid=%s", walletAddress, currency, timestamp, uuid); } private void closePayment() { diff --git a/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java b/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java index b70fc8492..31fcc1246 100644 --- a/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java +++ b/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java @@ -1,8 +1,13 @@ package com.breadwallet.tools.manager; +import static com.breadwallet.tools.manager.BRSharedPrefs.PrefsServerMode.PROD; +import static com.breadwallet.tools.util.BRConstants.GEO_PERMISSIONS_REQUESTED; +import static com.breadwallet.tools.util.BRConstants.PREFS_LITEWALLET_SERVER_MODE; + import android.content.Context; import android.content.SharedPreferences; +import com.breadwallet.BuildConfig; import com.breadwallet.tools.util.BRConstants; import org.json.JSONArray; @@ -15,8 +20,6 @@ import timber.log.Timber; -import static com.breadwallet.tools.util.BRConstants.GEO_PERMISSIONS_REQUESTED; - public class BRSharedPrefs { private static final List isoChangedListeners = new ArrayList<>(); @@ -438,4 +441,20 @@ public static void inAppReviewDone(Context context) { context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE) .edit().putBoolean(IN_APP_REVIEW_DONE, true).apply(); } + + public enum PrefsServerMode { + DEV, PROD + } + + public static String getApiServerMode(Context context) { + return context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE) + .getString(PREFS_LITEWALLET_SERVER_MODE, BuildConfig.LITEWALLET_API_URL_PROD); + } + + public static void setApiServerMode(Context context, PrefsServerMode serverMode) { + context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE) + .edit().putString(PREFS_LITEWALLET_SERVER_MODE, + (serverMode == PROD) ? BuildConfig.LITEWALLET_API_URL_PROD : BuildConfig.LITEWALLET_API_URL_DEV + ).commit(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/breadwallet/tools/util/BRConstants.java b/app/src/main/java/com/breadwallet/tools/util/BRConstants.java index c68c1b41c..4b2a34d6a 100644 --- a/app/src/main/java/com/breadwallet/tools/util/BRConstants.java +++ b/app/src/main/java/com/breadwallet/tools/util/BRConstants.java @@ -62,6 +62,7 @@ public class BRConstants { public static final String ALLOW_SPEND = "allowSpend"; public static final String USER_ID = "userId"; public static final String GEO_PERMISSIONS_REQUESTED = "geoPermissionsRequested"; + public static final String PREFS_LITEWALLET_SERVER_MODE = "PREFS_LITEWALLET_SERVER_MODE"; /** * Currency units @@ -105,6 +106,7 @@ public class BRConstants { public static final String RESET_CARD_PWD_LINK = "https://litecoin.dashboard.getblockcard.com/password/forgot"; + private BRConstants() { } diff --git a/app/src/main/res/layout/settings_list_item.xml b/app/src/main/res/layout/settings_list_item.xml index 0ecc16d9d..8db822ce7 100644 --- a/app/src/main/res/layout/settings_list_item.xml +++ b/app/src/main/res/layout/settings_list_item.xml @@ -1,32 +1,46 @@ - + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/item_addon" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="item title" /> + + android:textColor="@color/light_gray" + android:textSize="@dimen/sub_header" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="item addon" /> - + diff --git a/app/src/main/res/layout/settings_list_section.xml b/app/src/main/res/layout/settings_list_section.xml index 6d6ff1985..dd8757cca 100644 --- a/app/src/main/res/layout/settings_list_section.xml +++ b/app/src/main/res/layout/settings_list_section.xml @@ -2,19 +2,18 @@ + android:textColor="@color/light_gray" + android:textSize="@dimen/sub_header" /> diff --git a/app/src/main/res/layout/settings_list_switch.xml b/app/src/main/res/layout/settings_list_switch.xml new file mode 100644 index 000000000..d66194324 --- /dev/null +++ b/app/src/main/res/layout/settings_list_switch.xml @@ -0,0 +1,38 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a911ff526..b31499db1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -229,6 +229,8 @@ Node Connection Status Litecoin Nodes + + Developer Mode Bad Payment Request diff --git a/partnerapi b/partnerapi index 3b0881891..b205eef71 160000 --- a/partnerapi +++ b/partnerapi @@ -1 +1 @@ -Subproject commit 3b0881891df58518fb2b235154e72d055503b3a9 +Subproject commit b205eef7120fddea16fd8bcb64b56bf10c5137e9