Skip to content

Commit

Permalink
Solved bug on Navigating back from ConversionResultActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
demistry committed Mar 16, 2018
1 parent d0c4595 commit c0a5218
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.TextView;

import com.android.cryptocurapp.R;
import com.android.cryptocurapp.utils.TextSingleton;

public class ConversionEntryActivity extends AppCompatActivity {
private String cryptoText, baseText;
Expand All @@ -22,15 +23,16 @@ protected void onCreate(Bundle savedInstanceState) {
if (getSupportActionBar()!=null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

currencyAmountEntered = (EditText) findViewById(R.id.base_currency_amount_entered);
baseCurrencyTextView = (TextView) findViewById(R.id.base_currency_text);
cryptoCurrencyTextView = (TextView) findViewById(R.id.crypto_currency_text);
button = (Button) findViewById(R.id.convert_button);
currencyAmountEntered = findViewById(R.id.base_currency_amount_entered);
baseCurrencyTextView = findViewById(R.id.base_currency_text);
cryptoCurrencyTextView = findViewById(R.id.crypto_currency_text);
button = findViewById(R.id.convert_button);


Bundle bundle = getIntent().getExtras();
cryptoText = bundle.getString("crypto");
baseText = bundle.getString("base");

cryptoText = TextSingleton.getInstance().getCryptoText();
baseText = TextSingleton.getInstance().getBaseText();

baseCurrencyTextView.setText(baseText);
cryptoCurrencyTextView.setText(cryptoText);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class ConversionResultActivity extends AppCompatActivity implements Loade
private Button homeButton;
private TextView convertedCryptoText, convertedCryptoAmount, convertedBaseCurrency, convertedBaseAmount;
private double currencyAmountEntered;
ArrayList<Map<String, Double>> btcAgainstBase;
ArrayList<Map<String, Double>> ethAgainstBase;
ArrayList<Map<String, Double>> sbdAgainstBase;
ArrayList<Map<String, Double>> ltcAgainstBase;
ArrayList<Map<String, Double>> xrpAgainstBase;
ArrayList<Map<String, Double>> bchAgainstBase;
static ArrayList<Map<String, Double>> btcAgainstBase;
static ArrayList<Map<String, Double>> ethAgainstBase;
static ArrayList<Map<String, Double>> sbdAgainstBase;
static ArrayList<Map<String, Double>> ltcAgainstBase;
static ArrayList<Map<String, Double>> xrpAgainstBase;
static ArrayList<Map<String, Double>> bchAgainstBase;
private Bundle bundle;
private static double amount;
private static Map<String, Double> map = new HashMap<>();
Expand Down Expand Up @@ -88,12 +88,12 @@ public void onLoadFinished(Loader loader, String data) {
xrpAgainstBase = parseRawJsonString(data, 4);
bchAgainstBase = parseRawJsonString(data, 5);

convertedCryptoAmount.setText(convertAmount(bundle.getString("cryptoText"), bundle.getString("baseText"), currencyAmountEntered));
convertedCryptoAmount.setText(convertAmount(bundle.getString("cryptoText"), bundle.getString("baseText"), currencyAmountEntered, this));

}

public String convertAmount(String cryptoText, String baseText, double currencyAmountEntered){
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
public static String convertAmount(String cryptoText, String baseText, double currencyAmountEntered, Context context){
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork!=null && activeNetwork.isConnectedOrConnecting();
if (isConnected){
Expand Down Expand Up @@ -147,7 +147,7 @@ else if (cryptoText.equals("BCH")){
}
}
else{
Toast.makeText(this, "Check internet connection", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "Check internet connection", Toast.LENGTH_SHORT).show();
return "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.android.cryptocurapp.storage.RoomEntity;
import com.android.cryptocurapp.utils.ExchangeRateAdapter;
import com.android.cryptocurapp.utils.MyMapEntry;
import com.android.cryptocurapp.utils.TextSingleton;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -77,8 +78,10 @@ public class UserExchangeActivity extends AppCompatActivity implements Conversio
@Override
public void conversionCardClicked(String cryptoText, String baseText, int position) {
Intent intent = new Intent(UserExchangeActivity.this, ConversionEntryActivity.class);
intent.putExtra("crypto",cryptoText);
intent.putExtra("base", baseText);
//intent.putExtra("crypto",cryptoText);
TextSingleton.getInstance().setCryptoText(cryptoText);
TextSingleton.getInstance().setBaseText(baseText);
//intent.putExtra("base", baseText);
startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.android.cryptocurapp.utils;

/**
* Created by ILENWABOR DAVID on 16/03/2018.
*/

public class TextSingleton {
private static final TextSingleton ourInstance = new TextSingleton();
private String cryptoText, baseText;

public static TextSingleton getInstance() {
return ourInstance;
}

private TextSingleton() {
}

public String getCryptoText() {
return cryptoText;
}

public void setCryptoText(String cryptoText) {
this.cryptoText = cryptoText;
}

public String getBaseText() {
return baseText;
}

public void setBaseText(String baseText) {
this.baseText = baseText;
}
}

0 comments on commit c0a5218

Please sign in to comment.