Search in sources :

Example 1 with PoolDbHelper

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

the class WalletPrefChangeListener method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (isValidEthAddress((String) newValue))
        return false;
    PoolDbHelper db = new PoolDbHelper(mCtx, pool, cur);
    db.truncateWallets(db.getWritableDatabase());
    db.close();
    // salvo wallet in SharedPrefs preciso
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mCtx);
    // change specific
    prefs.edit().putString("wallet_addr_" + pool.name() + "_" + cur.name(), (String) newValue).apply();
    // change active one, tanto per
    prefs.edit().putString("wallet_addr", (String) newValue).commit();
    Bundle bundle = new Bundle();
    // bundle.putString(FirebaseAnalytics.Param.ITEM_ID, (String) newValue);
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, bundle);
    Crashlytics.setUserIdentifier((String) newValue);
    return true;
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) PoolDbHelper(it.angelic.mpw.model.db.PoolDbHelper)

Example 2 with PoolDbHelper

use of it.angelic.mpw.model.db.PoolDbHelper 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 3 with PoolDbHelper

use of it.angelic.mpw.model.db.PoolDbHelper 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 4 with PoolDbHelper

use of it.angelic.mpw.model.db.PoolDbHelper 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)

Example 5 with PoolDbHelper

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

the class MainActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setCheckedItem(R.id.nav_home);
    Utils.fillEthereumStats(this, mDbHelper, (NavigationView) findViewById(R.id.nav_view), mPool, mCur);
    // importante refresh
    mDbHelper = new PoolDbHelper(this, mPool, mCur);
    issueRefresh(mDbHelper, builder);
}
Also used : NavigationView(android.support.design.widget.NavigationView) PoolDbHelper(it.angelic.mpw.model.db.PoolDbHelper)

Aggregations

PoolDbHelper (it.angelic.mpw.model.db.PoolDbHelper)10 NavigationView (android.support.design.widget.NavigationView)7 GsonBuilder (com.google.gson.GsonBuilder)6 MyDateTypeAdapter (it.angelic.mpw.model.MyDateTypeAdapter)6 MyTimeStampTypeAdapter (it.angelic.mpw.model.MyTimeStampTypeAdapter)6 SharedPreferences (android.content.SharedPreferences)4 View (android.view.View)4 TextView (android.widget.TextView)4 AdView (com.google.android.gms.ads.AdView)4 DrawerLayout (android.support.v4.widget.DrawerLayout)3 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)3 Toolbar (android.support.v7.widget.Toolbar)3 AdRequest (com.google.android.gms.ads.AdRequest)3 LineView (im.dacer.androidcharts.LineView)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RadioGroup (android.widget.RadioGroup)2 LinkedMap (org.apache.commons.collections4.map.LinkedMap)2 NotificationManager (android.app.NotificationManager)1