Search in sources :

Example 1 with GranularityEnum

use of it.angelic.mpw.model.db.GranularityEnum in project MPW by shineangelic.

the class MainActivity method issueRefresh.

private void issueRefresh(final PoolDbHelper mDbHelper, final GsonBuilder builder) {
    Log.i(Constants.TAG, "JsonObjectRequest for: " + Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)));
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.d(Constants.TAG, response.toString());
            hashText.post(new Runnable() {

                @Override
                public void run() {
                    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
                    int radioButtonID = radioGroupBackTo.getCheckedRadioButtonId();
                    View radioButton = findViewById(radioButtonID);
                    storia = mDbHelper.getHistoryData(BackToEnum.valueOf((String) radioButton.getTag()));
                    updateCurrentStats();
                    final RadioButton radioDay = findViewById(R.id.radioButtonDay);
                    final RadioButton radioMin = findViewById(R.id.radioButtonMinutes);
                    GranularityEnum granoEnum = GranularityEnum.HOUR;
                    if (radioDay.isChecked())
                        granoEnum = GranularityEnum.DAY;
                    else if (radioMin.isChecked())
                        granoEnum = GranularityEnum.MINUTE;
                    ChartUtils.drawDifficultyHistory(textViewNetDiffTitle, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_difficulty), granoEnum);
                    ChartUtils.drawHashrateHistory(hashText, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_hashrate), granoEnum);
                }
            });
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
            Snackbar.make(findViewById(android.R.id.content), "Network Error", Snackbar.LENGTH_SHORT).show();
            // prevent stale data appear
            updateCurrentStats();
        }
    });
    /*
        JsonArrayRequest jsonArrayCurrenciesReq = new JsonArrayRequest(Request.Method.GET,
                Constants.ETHER_STATS_URL, null,
                new Response.Listener<JSONArray>() {

                    @Override
                    public void onResponse(final JSONArray response) {
                        Log.d(Constants.TAG, response.toString());
                        hashText.post(new Runnable() {
                            @Override
                            public void run() {
                                Gson gson = builder.create();
                                Log.d(Constants.TAG, response.toString());
                                Type listType = new TypeToken<List<Ticker>>() {}.getType();
                                List<Ticker> posts = gson.fromJson(response.toString(), listType);
                                Ticker fnd = null;
                                for (Ticker currency : posts) {
                                    if (mCur.name().equalsIgnoreCase(currency.getSymbol()) || mCur.toString().equalsIgnoreCase(currency.getName())) {
                                        fnd = currency;
                                    }
                                    //always save ETH
                                    if (CurrencyEnum.ETH.name().equalsIgnoreCase(currency.getSymbol())) {
                                        CryptoSharedPreferencesUtils.saveEthereumValues(currency, MainActivity.this);
                                    }
                                    //always save BTC
                                    if (CurrencyEnum.BTC.name().equalsIgnoreCase(currency.getSymbol())) {
                                        CryptoSharedPreferencesUtils.saveBtcValues(currency, MainActivity.this);
                                    }
                                }
                                //eventually resets  when fnd = null
                                CryptoSharedPreferencesUtils.saveEtherValues(fnd, MainActivity.this);
                            }
                        });
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
                Crashlytics.logException(error);
            }
        });*/
    // Adding request to request queue
    JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
// JSONClientSingleton.getInstance(this).addToRequestQueue(jsonArrayCurrenciesReq);
}
Also used : VolleyError(com.android.volley.VolleyError) Gson(com.google.gson.Gson) HomeStats(it.angelic.mpw.model.jsonpojos.home.HomeStats) RadioButton(android.widget.RadioButton) NavigationView(android.support.design.widget.NavigationView) LineView(im.dacer.androidcharts.LineView) View(android.view.View) AdView(com.google.android.gms.ads.AdView) TextView(android.widget.TextView) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) GranularityEnum(it.angelic.mpw.model.db.GranularityEnum) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 2 with GranularityEnum

use of it.angelic.mpw.model.db.GranularityEnum in project MPW by shineangelic.

the class MainActivity method onCreate.

/* private static long getAverageBlockSecondsSincePoolsBirth(HomeStats lastHit) {
        final Date firstBlockDate = new Date();//2017/07/15
        firstBlockDate.setTime(1500099900000L);
        long datediffFirst = (new Date().getTime() - firstBlockDate.getTime()) / 1000;
        //meno uno perche` il conto parte dal secondo blocco. Il primo boh
        return datediffFirst / (lastHit.getMaturedTotal() - 1);
    }*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Locale current = getResources().getConfiguration().locale;
    mDbHelper = new PoolDbHelper(this, mPool, mCur);
    builder = new GsonBuilder();
    // gestione UNIX time lungo e non
    builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
    builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
    noobText = findViewById(R.id.textViewWalletTitle);
    hashText = findViewById(R.id.hashrateText);
    textViewNetDiffTitle = findViewById(R.id.textViewWalHashrateTitle);
    poolLastBeat = findViewById(R.id.textViewWalLastShareValue);
    textViewNetDiffValue = findViewById(R.id.textViewNetDiffValue);
    lastFoundTextLabel = findViewById(R.id.textViewLastBlock);
    lastFoundText = findViewById(R.id.textViewWalPaymentsValue);
    onlineMinersText = findViewById(R.id.textViewWalCurHashrateValue);
    textViewBlockChainHeightValue = findViewById(R.id.textViewBlockChainHeightValue);
    poolHashrateText = findViewById(R.id.textViewPoolHashrateValue);
    roundSharesText = findViewById(R.id.textViewRoundSharesValue);
    textViewVarianceValue = findViewById(R.id.textViewVarianceValue);
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Async Refresh Sent", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
            issueRefresh(mDbHelper, builder);
        }
    });
    // i grafici hanno controlli globali
    RadioGroup radioGroupChartGranularity = findViewById(R.id.radioDifficultyGranularity);
    radioGroupBackTo = findViewById(R.id.radioBackto);
    final RadioButton radioDay = findViewById(R.id.radioButtonDay);
    final RadioButton radioMin = findViewById(R.id.radioButtonMinutes);
    final RadioGroup.OnCheckedChangeListener mescola = new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            radioGroupBackTo.post(new Runnable() {

                @Override
                public void run() {
                    GranularityEnum granoEnum = GranularityEnum.HOUR;
                    if (radioDay.isChecked())
                        granoEnum = GranularityEnum.DAY;
                    else if (radioMin.isChecked())
                        granoEnum = GranularityEnum.MINUTE;
                    int radioButtonID = radioGroupBackTo.getCheckedRadioButtonId();
                    View radioButton = findViewById(radioButtonID);
                    LinkedMap<Date, HomeStats> storia = mDbHelper.getHistoryData(BackToEnum.valueOf((String) radioButton.getTag()));
                    ChartUtils.drawDifficultyHistory(textViewNetDiffTitle, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_difficulty), granoEnum);
                    ChartUtils.drawHashrateHistory(hashText, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_hashrate), granoEnum);
                }
            });
        }
    };
    radioGroupBackTo.setOnCheckedChangeListener(mescola);
    radioGroupChartGranularity.setOnCheckedChangeListener(mescola);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
    Job myJob = MPWCoinmarketcapService.getJobUpdate(dispatcher);
    dispatcher.schedule(myJob);
    // ADS
    AdView mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}
Also used : RadioGroup(android.widget.RadioGroup) MyDateTypeAdapter(it.angelic.mpw.model.MyDateTypeAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) LinkedMap(org.apache.commons.collections4.map.LinkedMap) AdRequest(com.google.android.gms.ads.AdRequest) MyTimeStampTypeAdapter(it.angelic.mpw.model.MyTimeStampTypeAdapter) FloatingActionButton(android.support.design.widget.FloatingActionButton) DrawerLayout(android.support.v4.widget.DrawerLayout) Job(com.firebase.jobdispatcher.Job) AdView(com.google.android.gms.ads.AdView) PoolDbHelper(it.angelic.mpw.model.db.PoolDbHelper) Toolbar(android.support.v7.widget.Toolbar) FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) GsonBuilder(com.google.gson.GsonBuilder) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) RadioButton(android.widget.RadioButton) NavigationView(android.support.design.widget.NavigationView) LineView(im.dacer.androidcharts.LineView) View(android.view.View) AdView(com.google.android.gms.ads.AdView) TextView(android.widget.TextView) LineView(im.dacer.androidcharts.LineView) GranularityEnum(it.angelic.mpw.model.db.GranularityEnum)

Aggregations

NavigationView (android.support.design.widget.NavigationView)2 View (android.view.View)2 RadioButton (android.widget.RadioButton)2 TextView (android.widget.TextView)2 AdView (com.google.android.gms.ads.AdView)2 LineView (im.dacer.androidcharts.LineView)2 GranularityEnum (it.angelic.mpw.model.db.GranularityEnum)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1 RadioGroup (android.widget.RadioGroup)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)1 FirebaseJobDispatcher (com.firebase.jobdispatcher.FirebaseJobDispatcher)1 GooglePlayDriver (com.firebase.jobdispatcher.GooglePlayDriver)1 Job (com.firebase.jobdispatcher.Job)1 AdRequest (com.google.android.gms.ads.AdRequest)1 Gson (com.google.gson.Gson)1