Search in sources :

Example 1 with MyTimeStampTypeAdapter

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

the class WalletActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wallet);
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    minerAddr = pref.getString("wallet_addr", null);
    final PoolDbHelper mDbHelper = new PoolDbHelper(this, mPool, mCur);
    builder = new GsonBuilder();
    builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
    builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
    hashRateChartTitleText = findViewById(R.id.hashrateText);
    walletTitleText = findViewById(R.id.textViewWalletTitle);
    walletValueText = findViewById(R.id.textViewWalletValue);
    walCurHashrateText = findViewById(R.id.textViewWalCurHashrateValue);
    walCurHashrate3HText = findViewById(R.id.textViewWalHashrate3hValue);
    walTotSharesText = findViewById(R.id.textViewWalSharesValue);
    walOnlineWorkersText = findViewById(R.id.textViewWalOnlineMinersValue);
    lineView = findViewById(R.id.line_view_onlineminers);
    lineViewRate = findViewById(R.id.line_view_hrate);
    textViewWalPaymentsValue = findViewById(R.id.textViewWalPaymentsValue);
    textViewWalLastShareValue = findViewById(R.id.textViewWalLastShareValue);
    textViewWalLastShare = findViewById(R.id.textViewWalLastShare);
    textViewWalRoundSharesPercValue = findViewById(R.id.textViewWalRoundSharesPercValue);
    textViewPendingBalanceValue = findViewById(R.id.textViewPendingBalanceValue);
    textViewAvgPending = findViewById(R.id.textViewAvgPendingValue);
    textViewPaidValue = findViewById(R.id.textViewPaidValue);
    fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Async Refresh Sent", Snackbar.LENGTH_LONG).setAction("Action", null).show();
            issueRefresh(mDbHelper, builder, Utils.getWalletStatsUrl(PreferenceManager.getDefaultSharedPreferences(WalletActivity.this)) + minerAddr);
        }
    });
    // i grafici hanno controlli globali
    RadioGroup radioGroupChartGranularity = findViewById(R.id.radioDifficultyGranularity);
    radioGroupBackTo = findViewById(R.id.radioBackto);
    RadioGroup.OnCheckedChangeListener mescola = new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            new UpdateUIAsynchTask().execute();
        }
    };
    radioGroupBackTo.setOnCheckedChangeListener(mescola);
    radioGroupChartGranularity.setOnCheckedChangeListener(mescola);
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    // ADS
    AdView mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}
Also used : NavigationView(android.support.design.widget.NavigationView) RadioGroup(android.widget.RadioGroup) SharedPreferences(android.content.SharedPreferences) GsonBuilder(com.google.gson.GsonBuilder) MyDateTypeAdapter(it.angelic.mpw.model.MyDateTypeAdapter) NavigationView(android.support.design.widget.NavigationView) LineView(im.dacer.androidcharts.LineView) View(android.view.View) TextView(android.widget.TextView) AdView(com.google.android.gms.ads.AdView) AdRequest(com.google.android.gms.ads.AdRequest) MyTimeStampTypeAdapter(it.angelic.mpw.model.MyTimeStampTypeAdapter) AdView(com.google.android.gms.ads.AdView) PoolDbHelper(it.angelic.mpw.model.db.PoolDbHelper)

Example 2 with MyTimeStampTypeAdapter

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

the class NoobPoolInstrumentedTest method testJsonRequest.

@Test
public void testJsonRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    // gestione UNIX time lungo e non
    builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
    builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getHomeStatsURL(sharedPreferences), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.d(Constants.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);
            assertNotNull(retrieved);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
            fail();
        // hide the progress dialog
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(InstrumentationRegistry.getTargetContext()).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) MyDateTypeAdapter(it.angelic.mpw.model.MyDateTypeAdapter) MyTimeStampTypeAdapter(it.angelic.mpw.model.MyTimeStampTypeAdapter) Gson(com.google.gson.Gson) HomeStats(it.angelic.mpw.model.jsonpojos.home.HomeStats) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 3 with MyTimeStampTypeAdapter

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

the class MaxHashInstrumentedTest method testJsonRequest.

@Test
public void testJsonRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    // gestione UNIX time lungo e non
    builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
    builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getHomeStatsURL(sharedPreferences), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.d(Constants.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);
            assertNotNull(retrieved);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
            fail();
        // hide the progress dialog
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(InstrumentationRegistry.getTargetContext()).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) MyDateTypeAdapter(it.angelic.mpw.model.MyDateTypeAdapter) MyTimeStampTypeAdapter(it.angelic.mpw.model.MyTimeStampTypeAdapter) Gson(com.google.gson.Gson) HomeStats(it.angelic.mpw.model.jsonpojos.home.HomeStats) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 4 with MyTimeStampTypeAdapter

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

the class BlocksActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_blocks);
    mDbHelper = new PoolDbHelper(this, mPool, mCur);
    textViewBlocksTitle = findViewById(R.id.textViewBlocksTitle);
    textViewMaxBlockTimeValue = findViewById(R.id.textViewMaxBlockTimeValue);
    textViewMinBlockTimeValue = findViewById(R.id.textViewMostPaidMinerValue);
    textViewMeanBlockTimeValue = findViewById(R.id.textViewMeanBlockTimeValue);
    textViewBlockTimeStdDevValue = findViewById(R.id.textViewBlockTimeStdDevValue);
    textViewBlocksPerDayValue = findViewById(R.id.textViewBlocksPerDayValue);
    GsonBuilder builder = new GsonBuilder();
    mRecyclerView = findViewById(R.id.blocks_recycler_view);
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager mLayoutManager = new GridLayoutManager(this, getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 2 : 1);
    mRecyclerView.setLayoutManager(mLayoutManager);
    // gestione UNIX time lungo e non
    builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
    builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
    issueRefresh(builder);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) GsonBuilder(com.google.gson.GsonBuilder) MyDateTypeAdapter(it.angelic.mpw.model.MyDateTypeAdapter) MyTimeStampTypeAdapter(it.angelic.mpw.model.MyTimeStampTypeAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PoolDbHelper(it.angelic.mpw.model.db.PoolDbHelper)

Example 5 with MyTimeStampTypeAdapter

use of it.angelic.mpw.model.MyTimeStampTypeAdapter 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

GsonBuilder (com.google.gson.GsonBuilder)9 MyDateTypeAdapter (it.angelic.mpw.model.MyDateTypeAdapter)9 MyTimeStampTypeAdapter (it.angelic.mpw.model.MyTimeStampTypeAdapter)9 PoolDbHelper (it.angelic.mpw.model.db.PoolDbHelper)6 NavigationView (android.support.design.widget.NavigationView)4 View (android.view.View)4 TextView (android.widget.TextView)4 Response (com.android.volley.Response)4 VolleyError (com.android.volley.VolleyError)4 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)4 Gson (com.google.gson.Gson)4 HomeStats (it.angelic.mpw.model.jsonpojos.home.HomeStats)4 JSONObject (org.json.JSONObject)4 SharedPreferences (android.content.SharedPreferences)3 AdView (com.google.android.gms.ads.AdView)3 LineView (im.dacer.androidcharts.LineView)3 Test (org.junit.Test)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)2