Search in sources :

Example 1 with CurrencyEnum

use of it.angelic.mpw.model.enums.CurrencyEnum in project MPW by shineangelic.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences);
    // Crashlytics.getInstance().crash();
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());
    PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
    CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
    final android.support.v7.preference.SwitchPreferenceCompat globalNotifications = (SwitchPreferenceCompat) findPreference("pref_notify");
    final android.support.v7.preference.EditTextPreference walletAddr = (EditTextPreference) findPreference("wallet_addr");
    final android.support.v7.preference.SwitchPreferenceCompat service = (SwitchPreferenceCompat) findPreference("pref_sync");
    final android.support.v7.preference.ListPreference listFreqPreference = (ListPreference) findPreference("pref_sync_freq");
    final android.support.v7.preference.SwitchPreferenceCompat offlineNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_offline");
    final android.support.v7.preference.SwitchPreferenceCompat blockNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_block");
    final android.support.v7.preference.SwitchPreferenceCompat paymentNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_payment");
    // Service Enabled listener
    Preference.OnPreferenceChangeListener listenerServ = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // newValue is the value you choose
            listFreqPreference.setEnabled((Boolean) newValue);
            Boolean nv = (Boolean) newValue;
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
            dispatcher.cancelAll();
            if (nv) {
                Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
                int res = dispatcher.schedule(myJob);
                if (res != dispatcher.SCHEDULE_RESULT_SUCCESS) {
                    Toast.makeText(getActivity(), "Cannot enable service. Is Play Services up to date? Notifications won't work", Toast.LENGTH_SHORT).show();
                    return false;
                }
                Log.w(Constants.TAG, "SERVICE ACTIVE, schedule res: " + res);
            }
            // firebase log event
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, nv.toString());
            mFirebaseAnalytics.logEvent("service_active", bundle);
            return true;
        }
    };
    service.setOnPreferenceChangeListener(listenerServ);
    // Service FREQ listener
    Preference.OnPreferenceChangeListener listenerServF = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Integer nv = Integer.valueOf((String) newValue);
            // newValue is the value you choose
            Log.w(Constants.TAG, "Changed FREQ setting to: " + nv);
            // pezza perche il val ancora non c'e
            prefs.edit().putString("pref_sync_freq", "" + nv).apply();
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
            Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
            dispatcher.schedule(myJob);
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
            mFirebaseAnalytics.logEvent("service_freq", bundle);
            return true;
        }
    };
    listFreqPreference.setOnPreferenceChangeListener(listenerServF);
    // Notification global
    Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.w(Constants.TAG, "Changed NOTIF setting to: " + newValue);
            Boolean nv = (Boolean) newValue;
            // newValue is the value you choose
            blockNotifications.setEnabled(nv);
            offlineNotifications.setEnabled(nv);
            paymentNotifications.setEnabled(nv);
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
            mFirebaseAnalytics.logEvent("service_notifications", bundle);
            return true;
        }
    };
    globalNotifications.setOnPreferenceChangeListener(listener);
    // Listener x controllo correttezza
    walletAddr.setOnPreferenceChangeListener(new WalletPrefChangeListener(getActivity(), mPool, mCur));
    walletAddr.setSummary(getString(R.string.wallet_info, mPool.toString(), mCur.toString()));
    walletAddr.setDialogTitle(mPool.toString() + " Network Login");
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) SharedPreferences(android.content.SharedPreferences) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) Bundle(android.os.Bundle) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) ListPreference(android.support.v7.preference.ListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) PoolEnum(it.angelic.mpw.model.enums.PoolEnum) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) Job(com.firebase.jobdispatcher.Job) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum)

Example 2 with CurrencyEnum

use of it.angelic.mpw.model.enums.CurrencyEnum in project MPW by shineangelic.

the class ChoosePoolActivity method attemptLogin.

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 */
private void attemptLogin() {
    if (mAuthTask != null) {
        return;
    }
    // Reset errors.
    mWalletView.setError(null);
    // Store values at the time of the login attempt.
    String email = mWalletView.getText().toString();
    boolean cancel = false;
    View focusView = null;
    if (cancel) {
    // There was an error; don't attempt login and focus the first
    // form field with an error.
    // focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        showProgress(true);
        mAuthTask = new UserLoginTask(email, (PoolEnum) poolSpinner.getItemAtPosition(poolSpinner.getSelectedItemPosition()), (CurrencyEnum) currencySpinner.getItemAtPosition(currencySpinner.getSelectedItemPosition()));
        mAuthTask.execute((Void) null);
    }
}
Also used : PoolEnum(it.angelic.mpw.model.enums.PoolEnum) View(android.view.View) AdapterView(android.widget.AdapterView) AdView(com.google.android.gms.ads.AdView) TextView(android.widget.TextView) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum)

Example 3 with CurrencyEnum

use of it.angelic.mpw.model.enums.CurrencyEnum in project MPW by shineangelic.

the class MPWCoinmarketcapService method onStartJob.

@Override
public boolean onStartJob(JobParameters job) {
    final JobParameters jobC = job;
    Log.e(TAG, "SERVICE START");
    final Context ctx = MPWCoinmarketcapService.this;
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    try {
        final PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
        final CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
        Log.w(TAG, "Miner Pool Watcher Coinmarketcap Service call:" + Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(ctx)));
        Log.i(TAG, "SERVICE MARKETCAP working on:" + mPool.toString() + " - " + mCur.toString());
        // load extra
        // REFRESH coin values sincrono
        Log.e(TAG, "SERVICE MARKETCAP UPDATING CURRENCIES");
        asynchCurrenciesFromCoinmarketcap(ctx, mCur, job);
    } catch (Exception se) {
        Log.e(TAG, "SERVICE MARKETCAP ERROR: " + se);
        Crashlytics.logException(se);
    }
    // Answers the question: "Is there still work going on?"
    return true;
}
Also used : Context(android.content.Context) PoolEnum(it.angelic.mpw.model.enums.PoolEnum) SharedPreferences(android.content.SharedPreferences) JobParameters(com.firebase.jobdispatcher.JobParameters) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum)

Example 4 with CurrencyEnum

use of it.angelic.mpw.model.enums.CurrencyEnum in project MPW by shineangelic.

the class ChoosePoolActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ChoosePoolActivity.this);
    AppCompatDelegate.setDefaultNightMode(Integer.valueOf(prefs.getString("pref_theme", "0")));
    setContentView(R.layout.activity_choose_pool);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    // Set up the login form.
    mWalletView = findViewById(R.id.wallet);
    poolSpinner = findViewById(R.id.spinnerPoolChooser);
    skipIntro = findViewById(R.id.skipIntro);
    skipIntro.setChecked(prefs.getBoolean("skipIntro", false));
    Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, new Boolean(prefs.getBoolean("skipIntro", false)).toString());
    mFirebaseAnalytics.logEvent("skip_intro", bundle);
    // SERVICE Schedule
    Boolean synchActive = prefs.getBoolean("pref_sync", true);
    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
    if (synchActive) {
        Job myJob = MPWService.getJobUpdate(prefs, dispatcher, false);
        dispatcher.schedule(myJob);
    } else {
        dispatcher.cancelAll();
    }
    if (skipIntro.isChecked()) {
        Intent miner = new Intent(ChoosePoolActivity.this, MainActivity.class);
        startActivity(miner);
        finish();
    }
    // admob
    MobileAds.initialize(this, "ca-app-pub-2379213694485575~9889984422");
    ArrayAdapter poolSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, PoolEnum.values());
    poolSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    poolSpinner.setAdapter(poolSpinnerAdapter);
    currencySpinner = findViewById(R.id.spinnerCurrencyChooser);
    ArrayAdapter curAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, CurrencyEnum.values());
    curAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    currencySpinner.setAdapter(curAdapter);
    poolSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            ArrayAdapter arra = new ArrayAdapter<>(ChoosePoolActivity.this, android.R.layout.simple_spinner_item, ((PoolEnum) poolSpinner.getAdapter().getItem(position)).getSupportedCurrencies());
            arra.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            currencySpinner.setAdapter(arra);
            String prevWallet = prefs.getString("wallet_addr_" + ((PoolEnum) poolSpinner.getAdapter().getItem(position)).name() + "_" + ((CurrencyEnum) currencySpinner.getAdapter().getItem(currencySpinner.getSelectedItemPosition())).name(), "");
            mWalletView.setText(prevWallet);
            Log.d(Constants.TAG, "poolSpinner list: " + ((PoolEnum) poolSpinner.getAdapter().getItem(position)).name());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
        }
    });
    currencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            // read saved wallet from pref
            String xCode = "wallet_addr_" + ((PoolEnum) poolSpinner.getItemAtPosition(poolSpinner.getSelectedItemPosition())).name() + "_" + ((CurrencyEnum) currencySpinner.getAdapter().getItem(position)).name();
            String prevWallet = prefs.getString(xCode, "");
            mWalletView.setText(prevWallet.length() == 0 ? getString(R.string.no_wallet_set) : Utils.formatEthAddress(prevWallet));
            Log.d(Constants.TAG, "currencySpinner list: " + currencySpinner.getItemAtPosition(currencySpinner.getSelectedItemPosition()));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
        }
    });
    Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
    mEmailSignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) AdView(com.google.android.gms.ads.AdView) TextView(android.widget.TextView) PoolEnum(it.angelic.mpw.model.enums.PoolEnum) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView) Job(com.firebase.jobdispatcher.Job) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with CurrencyEnum

use of it.angelic.mpw.model.enums.CurrencyEnum in project MPW by shineangelic.

the class MPWService method onStartJob.

@Override
public boolean onStartJob(JobParameters job) {
    final JobParameters jobC = job;
    Log.e(TAG, "SERVICE START");
    final Context ctx = MPWService.this;
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    try {
        final PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
        final CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
        Log.i(TAG, "Miner Pool Watcher Service call:" + Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(ctx)));
        Log.i(TAG, "SERVICE working on:" + mPool.toString() + " - " + mCur.toString());
        final PoolDbHelper mDbHelper = new PoolDbHelper(ctx, mPool, mCur);
        final NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(NOTIFICATION_SERVICE);
        final GsonBuilder builder = new GsonBuilder();
        // gestione UNIX time lungo e non
        builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
        builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
        // load extra
        final String minerAddr = job.getExtras().getString("WALLETURL");
        final Boolean notifyBlock = job.getExtras().getBoolean("NOTIFY_BLOCK", false);
        final Boolean notifyOffline = job.getExtras().getBoolean("NOTIFY_OFFLINE", false);
        final Boolean notifyPayment = job.getExtras().getBoolean("NOTIFY_PAYMENT", false);
        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(ctx)), null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                Log.d(TAG, response.toString());
                Gson gson = builder.create();
                // Register an adapter to manage the date types as long values
                HomeStats retrieved = gson.fromJson(response.toString(), HomeStats.class);
                mDbHelper.logHomeStats(retrieved);
                // dati semi grezzi
                LinkedMap<Date, HomeStats> ultimi = mDbHelper.getLastHomeStats(LAST_TWO);
                Log.d(TAG, "data size: " + ultimi.size() + " notifyOffline: " + ultimi.get(ultimi.get(0)).getMaturedTotal());
                // controllo se manca qualcuno
                if (notifyBlock && ultimi.size() > 1 && ultimi.get(ultimi.get(0)).getMaturedTotal().compareTo(ultimi.get(ultimi.get(1)).getMaturedTotal()) > 0) {
                    int diff = ultimi.get(ultimi.get(0)).getMaturedTotal() - ultimi.get(ultimi.get(1)).getMaturedTotal();
                    sendBlockNotification(getApplication(), diff + " new block. " + mPool.toString() + " has found " + ultimi.get(ultimi.get(0)).getMaturedTotal() + " blocks", mPool);
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
            }
        });
        if (minerAddr != null) {
            Log.i(TAG, "refreshing wallet " + minerAddr + " notify: " + notifyBlock);
            JsonObjectRequest jsonObjReqWallet = new JsonObjectRequest(Request.Method.GET, Utils.getWalletStatsUrl(PreferenceManager.getDefaultSharedPreferences(ctx)) + minerAddr, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                    Gson gson = builder.create();
                    // Register an adapter to manage the date types as long values
                    Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
                    mDbHelper.logWalletStats(retrieved);
                    // dati semi grezzi
                    LinkedMap<Date, Wallet> ultimi = mDbHelper.getLastWallets(LAST_TWO);
                    // controllo se manca qualcuno
                    if (notifyOffline && ultimi.keySet().size() >= LAST_TWO) {
                        if (ultimi.get(ultimi.firstKey()).getWorkersOnline() < ultimi.get(ultimi.get(1)).getWorkersOnline()) {
                            sendOfflineNotification(ctx, "A Worker has gone OFFLINE. Online Workers: " + ultimi.get(ultimi.firstKey()).getWorkersOnline(), mPool);
                        } else if (ultimi.get(ultimi.firstKey()).getWorkersOnline() > ultimi.get(ultimi.get(1)).getWorkersOnline()) {
                            // togli notifiche di offline
                            mNotifyMgr.cancel(NOTIFICATION_MINER_OFFLINE);
                        }
                    // else uguali, fa nulla
                    }
                    if (notifyPayment && ultimi.keySet().size() >= LAST_TWO && ultimi.get(ultimi.firstKey()).getPayments().size() > ultimi.get(ultimi.get(1)).getPayments().size()) {
                        sendPaymentNotification(ctx, "You received a payment: " + Utils.formatEthCurrency(ctx, ultimi.get(ultimi.firstKey()).getPayments().get(0).getAmount()), mCur.toString() + " payment from " + mPool.toString());
                    }
                    Log.e(TAG, "SERVICE END Ok1");
                    MPWService.this.jobFinished(jobC, false);
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e(TAG, "SERVICE END KO1");
                    MPWService.this.jobFinished(jobC, true);
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                // hide the progress dialog
                }
            });
            JSONClientSingleton.getInstance(ctx).addToRequestQueue(jsonObjReqWallet);
        } else {
            // job end tutto bene
            MPWService.this.jobFinished(job, false);
        }
        // Adding request to request queue
        JSONClientSingleton.getInstance(ctx).addToRequestQueue(jsonObjReq);
    } catch (Exception se) {
        Log.e(TAG, "SERVICE ERROR: " + se);
        Crashlytics.logException(se);
    }
    // Answers the question: "Is there still work going on?"
    return true;
}
Also used : Context(android.content.Context) VolleyError(com.android.volley.VolleyError) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) GsonBuilder(com.google.gson.GsonBuilder) MyDateTypeAdapter(it.angelic.mpw.model.MyDateTypeAdapter) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) HomeStats(it.angelic.mpw.model.jsonpojos.home.HomeStats) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Response(com.android.volley.Response) PoolEnum(it.angelic.mpw.model.enums.PoolEnum) JSONObject(org.json.JSONObject) MyTimeStampTypeAdapter(it.angelic.mpw.model.MyTimeStampTypeAdapter) JobParameters(com.firebase.jobdispatcher.JobParameters) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum) PoolDbHelper(it.angelic.mpw.model.db.PoolDbHelper)

Aggregations

CurrencyEnum (it.angelic.mpw.model.enums.CurrencyEnum)5 PoolEnum (it.angelic.mpw.model.enums.PoolEnum)5 SharedPreferences (android.content.SharedPreferences)4 Context (android.content.Context)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 FirebaseJobDispatcher (com.firebase.jobdispatcher.FirebaseJobDispatcher)2 GooglePlayDriver (com.firebase.jobdispatcher.GooglePlayDriver)2 Job (com.firebase.jobdispatcher.Job)2 JobParameters (com.firebase.jobdispatcher.JobParameters)2 AdView (com.google.android.gms.ads.AdView)2 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 EditTextPreference (android.support.v7.preference.EditTextPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)1 OnClickListener (android.view.View.OnClickListener)1