android.arch.lifecycle.ViewModelProviders Java Examples

The following examples show how to use android.arch.lifecycle.ViewModelProviders. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example #2
Source File: LoginActivity.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
private void init() {
  progressDialog = new ProgressDialog(this);
  dataStore = new DataStore();
  getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  steemConnect = SteemConnectUtils.getSteemConnectInstance();
  connectivityViewModel = ViewModelProviders.of(this).get(ConnectivityViewModel.class);
  connectivityViewModel.getConnectivityState().observeForever(new Observer<Boolean>() {
    @Override
    public void onChanged(@Nullable Boolean isConnected) {
      if (isConnected) {
        enableSigninButton();
        showConnectivityBar();
      } else {
        disableSigninButton();
        showConnectivityErrorBar();
      }
    }
  });
}
 
Example #3
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example #4
Source File: EarthquakeMapFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
  mMap = googleMap;

  // Retrieve the Earthquake View Model for this Fragment.
  earthquakeViewModel =
    ViewModelProviders.of(getActivity()).get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // Update the UI with the updated database results.
        if (earthquakes != null)
          setEarthquakeMarkers(earthquakes);
      }
    });
}
 
Example #5
Source File: Erc20DetailActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AndroidInjection.inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_erc20_token_detail);
    toolbar();
    setTitle("");
    getIntentData();
    myAddress = wallet.address;
    txUpdateCounter = 0;
    toolbarView = findViewById(R.id.toolbar);

    viewModel = ViewModelProviders.of(this, erc20DetailViewModelFactory)
            .get(Erc20DetailViewModel.class);
    viewModel.defaultWallet().observe(this, this::onDefaultWallet);
    viewModel.transactions().observe(this, this::onTransactions);
    viewModel.token().observe(this, this::onTokenData);
    viewModel.tokenTicker().observe(this, this::onTokenTicker);
    viewModel.transactionUpdate().observe(this, this::newTransactions);
    viewModel.sig().observe(this, sigData -> toolbarView.onSigData(sigData, this));
    viewModel.newScriptFound().observe(this, this::onNewScript);
    viewModel.checkForNewScript(token);
}
 
Example #6
Source File: MainActivity.java    From Room-Library-Login-Example with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    binding = DataBindingUtil.setContentView(MainActivity.this, R.layout.activity_main);

    binding.setClickListener((MainActivity) this);


    loginViewModel = ViewModelProviders.of(MainActivity.this).get(LoginViewModel.class);

    loginViewModel.getGetAllData().observe(this, new Observer<List<LoginTable>>() {
        @Override
        public void onChanged(@Nullable List<LoginTable> data) {

            try {
                binding.lblEmailAnswer.setText((Objects.requireNonNull(data).get(0).getEmail()));
                binding.lblPasswordAnswer.setText((Objects.requireNonNull(data.get(0).getPassword())));
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });

}
 
Example #7
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  MyViewModel myViewModel = ViewModelProviders.of(this)
                              .get(MyViewModel.class);

  // Get the current data and observe it for changes.
  myViewModel.getData()
    .observe(this, new Observer<List<String>>() {
      @Override
      public void onChanged(@Nullable List<String> data) {
        // Update your UI with the loaded data.
        // Returns cached data automatically after a configuration change,
        // and will be fired again if underlying Live Data object is modified.
      }
    });
}
 
Example #8
Source File: TokenDetailActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AndroidInjection.inject(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_token_detail);
    viewModel = ViewModelProviders.of(this, tokenFunctionViewModelFactory)
            .get(TokenFunctionViewModel.class);

    if (getIntent() != null && getIntent().getExtras() != null) {
        asset = getIntent().getExtras().getParcelable("asset");
        token = getIntent().getExtras().getParcelable("token");
        initViews();
        toolbar();
        setTitle(token.getFullName());
        setupPage();
    } else {
        finish();
    }
}
 
Example #9
Source File: TokenFunctionActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AndroidInjection.inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_script_view);

    viewModel = ViewModelProviders.of(this, tokenFunctionViewModelFactory)
            .get(TokenFunctionViewModel.class);
    viewModel.insufficientFunds().observe(this, this::errorInsufficientFunds);
    viewModel.invalidAddress().observe(this, this::errorInvalidAddress);
    viewModel.tokenUpdate().observe(this, this::onTokenUpdate);
    viewModel.walletUpdate().observe(this, this::onWalletUpdate);

    SystemView systemView = findViewById(R.id.system_view);
    systemView.hide();
    functionBar = findViewById(R.id.layoutButtons);
    initViews(getIntent().getParcelableExtra(TICKET));
    toolbar();
    setTitle(getString(R.string.token_function));

    viewModel.startGasPriceUpdate(token.tokenInfo.chainId);
}
 
Example #10
Source File: SelectNetworkActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AndroidInjection.inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    toolbar();
    setTitle(getString(R.string.select_active_networks));

    viewModel = ViewModelProviders.of(this, viewModelFactory)
            .get(SelectNetworkViewModel.class);

    if (getIntent() != null) {
        singleItem = getIntent().getBooleanExtra(C.EXTRA_SINGLE_ITEM, false);
        selectedChainId = getIntent().getStringExtra(C.EXTRA_CHAIN_ID);
    }

    if (selectedChainId == null || selectedChainId.isEmpty()) {
        selectedChainId = viewModel.getFilterNetworkList();
    }

    recyclerView = findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new ListDivider(this));
}
 
Example #11
Source File: TrackLocationActivity.java    From Track-My-Location with GNU General Public License v3.0 6 votes vote down vote up
private void initViewModel() {
    mViewModel = ViewModelProviders.of(this, mViewModelFactory).get(TrackLocationViewModel.class);
    mViewModel.getTrackingState().observe(this, tracking -> {
        if (tracking != null && tracking) {
            mTextDevId.setEnabled(false);
            mBtnTrack.setBackground(getResources().getDrawable(R.drawable.bg_btn_stop));
            mBtnTrack.setText(R.string.stop);
            mTextLocStat.setText(R.string.fetching);
        } else {
            mTextDevId.setEnabled(true);
            mBtnTrack.setBackground(getResources().getDrawable(R.drawable.bg_btn_start));
            mBtnTrack.setText(R.string.start);
            mTextLocStat.setText(R.string.disconnected);
        }
    });
}
 
Example #12
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });
}
 
Example #13
Source File: WalletActionsActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private void initViewModel() {
    viewModel = ViewModelProviders.of(this, walletActionsViewModelFactory)
            .get(WalletActionsViewModel.class);

    viewModel.saved().observe(this, this::onSaved);
    viewModel.deleteWalletError().observe(this, this::onDeleteError);
    viewModel.exportWalletError().observe(this, this::onExportError);
    viewModel.deleted().observe(this, this::onDeleteWallet);
    viewModel.exportedStore().observe(this, this::onBackupWallet);
    viewModel.isTaskRunning().observe(this, this::onTaskStatusChanged);

    if (isNewWallet) {
        wallet.name = getString(R.string.wallet_name_template, walletCount);
        viewModel.storeWallet(wallet);
    }
}
 
Example #14
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_earthquake_main);
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  ViewPager viewPager = findViewById(R.id.view_pager);
  if (viewPager != null) {
    PagerAdapter pagerAdapter =
      new EarthquakeTabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(pagerAdapter);
    TabLayout tabLayout = findViewById(R.id.tab_layout);
    tabLayout.setupWithViewPager(viewPager);
  }

  // Retrieve the Earthquake View Model for this Activity.
  earthquakeViewModel = ViewModelProviders.of(this)
                          .get(EarthquakeViewModel.class);
}
 
Example #15
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example #16
Source File: TransactionDetailActivity.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void initDatas() {

    transaction = getIntent().getParcelableExtra(TRANSACTION);
    if (transaction == null) {
        finish();
        return;
    }

    BigInteger gasFee = new BigInteger(transaction.gasUsed).multiply(new BigInteger(transaction.gasPrice));

    tvFrom.setText(transaction.from);
    tvTo.setText(transaction.to);
    tvGasFee.setText(BalanceUtils.weiToEth(gasFee).toPlainString());
    tvTxHash.setText(transaction.hash);
    tvTxTime.setText(getDate(transaction.timeStamp));
    tvBlockNumber.setText(transaction.blockNumber);

    transactionDetailViewModelFactory  = new TransactionDetailViewModelFactory();

    viewModel = ViewModelProviders.of(this, transactionDetailViewModelFactory)
            .get(TransactionDetailViewModel.class);
    viewModel.defaultNetwork().observe(this, this::onDefaultNetwork);
    viewModel.defaultWallet().observe(this, this::onDefaultWallet);

}
 
Example #17
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example #18
Source File: PropertyDetailActivity.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void initDatas() {

    Intent intent = getIntent();
    currWallet = intent.getStringExtra(C.EXTRA_ADDRESS);
    balance = intent.getStringExtra(C.EXTRA_BALANCE);
    contractAddress = intent.getStringExtra(C.EXTRA_CONTRACT_ADDRESS);
    decimals = intent.getIntExtra(C.EXTRA_DECIMALS, C.ETHER_DECIMALS);
    symbol = intent.getStringExtra(C.EXTRA_SYMBOL);
    symbol = symbol == null ? C.ETH_SYMBOL : symbol;

    tvTitle.setText(symbol);

    tvAmount.setText(balance);

    transactionsViewModelFactory = new TransactionsViewModelFactory();
    viewModel = ViewModelProviders.of(this, transactionsViewModelFactory)
            .get(TransactionsViewModel.class);

    viewModel.transactions().observe(this, this::onTransactions);
    viewModel.progress().observe(this, this::onProgress);

}
 
Example #19
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example #20
Source File: StatisticsFragment.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void doCreateView(Bundle savedInstanceState) {
    statisticViewModel = ViewModelProviders.of(this).get(StatisticViewModel.class);

    /*Config toolbar*/
    if (getActivity() != null) {
        ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
        if (ab != null) {
            ab.setTitle(R.string.statistic);
        }
    }

    /*Config default values*/
    getBinding().lcvNote.setValueSelectionEnabled(false);
    getBinding().lcvNote.setLineChartData(statisticViewModel.getDefaultAssignmentData(ColorUtils.primaryColor()));
    getBinding().ccvModels.setColumnChartData(statisticViewModel.getDefaultModelsData());
    getBinding().ccvAttachment.setColumnChartData(statisticViewModel.getDefaultAttachmentData());

    /*Output stats*/
    outputStats();
}
 
Example #21
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example #22
Source File: AdhellReportsFragment.java    From SABS with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    parentActivity.setTitle("Recent activity");
    if (parentActivity.getSupportActionBar() != null) {
        parentActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        parentActivity.getSupportActionBar().setHomeButtonEnabled(true);
    }
    View view = inflater.inflate(R.layout.fragment_adhell_reports, container, false);

    ((MainActivity)getActivity()).hideBottomBar();

    lastDayBlockedTextView = view.findViewById(R.id.lastDayBlockedTextView);
    blockedDomainsListView = view.findViewById(R.id.blockedDomainsListView);

    AdhellReportViewModel adhellReportViewModel = ViewModelProviders.of(getActivity()).get(AdhellReportViewModel.class);
    adhellReportViewModel.getReportBlockedUrls().observe(this, reportBlockedUrls -> {
        ReportBlockedUrlAdapter reportBlockedUrlAdapter = new ReportBlockedUrlAdapter(this.getContext(), reportBlockedUrls);
        blockedDomainsListView.setAdapter(reportBlockedUrlAdapter);
        lastDayBlockedTextView.setText(String.valueOf(reportBlockedUrls.size()));
        reportBlockedUrlAdapter.notifyDataSetChanged();
    });

    return view;
}
 
Example #23
Source File: WalletFragment.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private void initViewModel() {
    viewModel = ViewModelProviders.of(this, walletViewModelFactory)
            .get(WalletViewModel.class);
    viewModel.progress().observe(this, systemView::showProgress);
    viewModel.error().observe(this, this::onError);
    viewModel.tokens().observe(this, this::onTokens);
    viewModel.queueProgress().observe(this, progressView::updateProgress);
    viewModel.currentWalletBalance().observe(this, this::onBalanceChanged);
    viewModel.refreshTokens().observe(this, this::refreshTokens);
    viewModel.tokenUpdate().observe(this, this::onToken);
    viewModel.tokensReady().observe(this, this::tokensReady);
    viewModel.backupEvent().observe(this, this::backupEvent);
    viewModel.defaultWallet().observe(this, this::onDefaultWallet);
}
 
Example #24
Source File: AdhellPermissionInAppsFragment.java    From SABS with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (parentActivity.getSupportActionBar() != null) {
        parentActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        parentActivity.getSupportActionBar().setHomeButtonEnabled(true);
    }

    ((MainActivity)getActivity()).hideBottomBar();

    sharedAppPermissionViewModel = ViewModelProviders.of(getActivity()).get(SharedAppPermissionViewModel.class);
    View view = inflater.inflate(R.layout.fragment_permission_in_apps, container, false);
    permissionInAppsRecyclerView = view.findViewById(R.id.permissionInAppsRecyclerView);
    permissionInAppsRecyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));
    RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL);
    permissionInAppsRecyclerView.addItemDecoration(itemDecoration);

    sharedAppPermissionViewModel.getSelected().observe(this, permissionInfo -> {
        getActivity().setTitle(permissionInfo.name);
        appInfos = sharedAppPermissionViewModel.loadPermissionsApps(sharedAppPermissionViewModel.installedApps, permissionInfo.name);
        AdhellPermissionInAppsAdapter adhellPermissionInAppsAdapter = new AdhellPermissionInAppsAdapter(this.getContext(), appInfos);
        adhellPermissionInAppsAdapter.currentPermissionName = permissionInfo.name;
        adhellPermissionInAppsAdapter.updateRestrictedPackages();
        permissionInAppsRecyclerView.setAdapter(adhellPermissionInAppsAdapter);
        adhellPermissionInAppsAdapter.notifyDataSetChanged();
    });
    return view;
}
 
Example #25
Source File: TransactionDetailActivity.java    From trust-wallet-android-source with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AndroidInjection.inject(this);

    setContentView(R.layout.activity_transaction_detail);

    transaction = getIntent().getParcelableExtra(TRANSACTION);
    if (transaction == null) {
        finish();
        return;
    }
    toolbar();

    BigInteger gasFee = new BigInteger(transaction.gasUsed).multiply(new BigInteger(transaction.gasPrice));
    amount = findViewById(R.id.amount);
    ((TextView) findViewById(R.id.from)).setText(transaction.from);
    ((TextView) findViewById(R.id.to)).setText(transaction.to);
    ((TextView) findViewById(R.id.gas_fee)).setText(BalanceUtils.weiToEth(gasFee).toPlainString());
    ((TextView) findViewById(R.id.txn_hash)).setText(transaction.hash);
    ((TextView) findViewById(R.id.txn_time)).setText(getDate(transaction.timeStamp));
    ((TextView) findViewById(R.id.block_number)).setText(transaction.blockNumber);
    findViewById(R.id.more_detail).setOnClickListener(this);

    viewModel = ViewModelProviders.of(this, transactionDetailViewModelFactory)
            .get(TransactionDetailViewModel.class);
    viewModel.defaultNetwork().observe(this, this::onDefaultNetwork);
    viewModel.defaultWallet().observe(this, this::onDefaultWallet);
}
 
Example #26
Source File: SendActivity.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AndroidInjection.inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send);
    toolbar();
    setTitle("");

    viewModel = ViewModelProviders.of(this, sendViewModelFactory)
            .get(SendViewModel.class);
    handler = new Handler();

    contractAddress = getIntent().getStringExtra(C.EXTRA_CONTRACT_ADDRESS);

    decimals = getIntent().getIntExtra(C.EXTRA_DECIMALS, C.ETHER_DECIMALS);
    symbol = getIntent().getStringExtra(C.EXTRA_SYMBOL);
    symbol = symbol == null ? C.ETH_SYMBOL : symbol;
    wallet = getIntent().getParcelableExtra(WALLET);
    token = getIntent().getParcelableExtra(C.EXTRA_TOKEN_ID);
    QrUrlResult result = getIntent().getParcelableExtra(C.EXTRA_AMOUNT);
    currentChain = getIntent().getIntExtra(C.EXTRA_NETWORKID, 1);
    myAddress = wallet.address;

    if (!checkTokenValidity()) { return; }

    setupTokenContent();
    initViews();
    setupAddressEditField();

    if (token != null)
    {
        amountInput = new AmountEntryItem(this, tokenRepository, token); //ticker is used automatically now
    }

    if (result != null)
    {
        //restore payment request
        validateEIP681Request(result, true);
    }
}
 
Example #27
Source File: NavigationView.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void initializeNavigationViewModel() {
  try {
    navigationViewModel = ViewModelProviders.of((FragmentActivity) getContext()).get(NavigationViewModel.class);
  } catch (ClassCastException exception) {
    throw new ClassCastException("Please ensure that the provided Context is a valid FragmentActivity");
  }
}
 
Example #28
Source File: MainActivity.java    From Dagger2-Sample with MIT License 5 votes vote down vote up
private void initialiseViewModel() {
    movieListViewModel = ViewModelProviders.of(this, viewModelFactory).get(MovieListViewModel.class);
    movieListViewModel.getMoviesLiveData().observe(this, resource -> {
        if(resource.isLoading()) {
            displayLoader();

        } else if(!resource.data.isEmpty()) {
            updateMoviesList(resource.data);

        } else handleErrorResponse();
    });

    /* Fetch movies list  */
    movieListViewModel.loadMoreMovies();
}
 
Example #29
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_earthquake_main);

  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  FragmentManager fm = getSupportFragmentManager();

  // Android will automatically re-add any Fragments that
  // have previously been added after a configuration change,
  // so only add it if this isn't an automatic restart.
  if (savedInstanceState == null) {
    FragmentTransaction ft = fm.beginTransaction();

    mEarthquakeListFragment = new EarthquakeListFragment();
    ft.add(R.id.main_activity_frame,
      mEarthquakeListFragment, TAG_LIST_FRAGMENT);

    ft.commitNow();
  } else {
    mEarthquakeListFragment =
      (EarthquakeListFragment) fm.findFragmentByTag(TAG_LIST_FRAGMENT);
  }

  // Retrieve the Earthquake View Model for this Activity.
  earthquakeViewModel = ViewModelProviders.of(this)
                          .get(EarthquakeViewModel.class);
}
 
Example #30
Source File: AdhellPermissionInfoFragment.java    From SABS with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    getActivity().setTitle("App Permissions");
    if (parentActivity.getSupportActionBar() != null) {
        parentActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        parentActivity.getSupportActionBar().setHomeButtonEnabled(false);
    }

    ((MainActivity)getActivity()).showBottomBar();

    sharedAppPermissionViewModel = ViewModelProviders.of(getActivity()).get(SharedAppPermissionViewModel.class);
    fragmentManager = getActivity().getSupportFragmentManager();
    adhellPermissionInfos = AdhellPermissionInfo.loadPermissions();
    View view = inflater.inflate(R.layout.fragment_adhell_permission_info, container, false);
    RecyclerView permissionInfoRecyclerView = view.findViewById(R.id.permissionInfoRecyclerView);
    AdhellPermissionInfoAdapter adhellPermissionInfoAdapter = new AdhellPermissionInfoAdapter(this.getContext(), adhellPermissionInfos);
    permissionInfoRecyclerView.setAdapter(adhellPermissionInfoAdapter);
    permissionInfoRecyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));
    RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL);

    sharedAppPermissionViewModel.loadInstalledAppsLiveData().observe(this, installedApps -> {
        sharedAppPermissionViewModel.installedApps = installedApps;
    });


    permissionInfoRecyclerView.addItemDecoration(itemDecoration);
    ItemClickSupport.addTo(permissionInfoRecyclerView).setOnItemClickListener(
            (recyclerView, position, v) -> {
                sharedAppPermissionViewModel.select(adhellPermissionInfos.get(position));
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.fragmentContainer, new AdhellPermissionInAppsFragment());
                fragmentTransaction.addToBackStack("permissionsInfo_permissionsInApp");
                fragmentTransaction.commit();
            }
    );
    setHasOptionsMenu(true);
    return view;
}