Skip to content

Commit

Permalink
Solved some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Jan 25, 2018
1 parent 0807494 commit 8340e16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Expand Up @@ -54,6 +54,7 @@ public static final class LOG {
public static final String LOADING_TABLE = "Loading table in a new thread...";
public static final String MARKET_PRICE_ERROR = "Error on MainActivity.initMPU(): ";
public static final String DATA_ERROR = "Error on MainActivity.initRD(): ";
public static final String JOIN_ERROR = "Failed to join thread ";

public static final String STAG = "SpinnerActivity";
public static final String INIT_SETTINGS_VIEW = "Starting settings view...";
Expand Down
28 changes: 24 additions & 4 deletions app/src/main/java/javinator9889/bitcoinpools/MainActivity.java
Expand Up @@ -47,6 +47,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private static Map<String, Float> RETRIEVED_DATA = new LinkedHashMap<>();
private static float MARKET_PRICE_USD;
private static ViewGroup.LayoutParams TABLE_PARAMS;
private Thread rdThread;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -85,7 +86,6 @@ protected void onCreate(Bundle savedInstanceState) {
initRD();
initT();
CheckUpdates ck = new CheckUpdates(Constants.GITHUB_USER, Constants.GITHUB_REPO);
setTitle(getString(R.string.BTCP) + MARKET_PRICE_USD);

final FloatingActionsMenu mainButton = (FloatingActionsMenu) findViewById(R.id.menu_fab);
final FloatingActionButton licenseButton = (FloatingActionButton) findViewById(R.id.license);
Expand Down Expand Up @@ -142,14 +142,17 @@ public void run() {
} catch (InterruptedException | ExecutionException | JSONException e) {
Log.e(Constants.LOG.MATAG, Constants.LOG.MARKET_PRICE_ERROR + e.getMessage());
MARKET_PRICE_USD = 0;
} finally {
setTitle(getString(R.string.BTCP) + MARKET_PRICE_USD);
}
}
};
mpuThread.setName("mpu_thread");
mpuThread.start();
}

private void initRD() {
Thread rdThread = new Thread() {
rdThread = new Thread() {
public void run() {
int days = BitCoinApp.getSharedPreferences().getInt(Constants.SHARED_PREFERENCES.DAYS_TO_CHECK, 1);
Log.d(Constants.LOG.MATAG, Constants.LOG.LOADING_RD);
Expand All @@ -164,6 +167,7 @@ public void run() {
}
}
};
rdThread.setName("rd_thread");
rdThread.start();
}

Expand Down Expand Up @@ -200,7 +204,14 @@ public void run() {
destinationChart.invalidate();
}
};
pieChartThread.start();
try {
rdThread.join();
} catch (InterruptedException e) {
Log.e(Constants.LOG.MATAG, Constants.LOG.JOIN_ERROR + rdThread.getName());
} finally {
pieChartThread.setName("chart_thread");
pieChartThread.start();
}
}

private void createTable(final TableLayout destinationTable) {
Expand Down Expand Up @@ -252,7 +263,14 @@ public void run() {
destinationTable.invalidate();
}
};
tableThread.start();
try {
rdThread.join();
} catch (InterruptedException e) {
Log.e(Constants.LOG.MATAG, Constants.LOG.JOIN_ERROR + rdThread.getName());
} finally {
tableThread.setName("table_thread");
tableThread.start();
}
}

/**
Expand All @@ -275,6 +293,7 @@ public void run() {
startActivity(intentLicense);
}
};
licenseThread.setName("license_thread");
licenseThread.start();
break;
case R.id.settings:
Expand All @@ -285,6 +304,7 @@ public void run() {
MainActivity.this.finish();
}
};
settingsThread.setName("settings_thread");
settingsThread.start();
break;
case R.id.update:
Expand Down

0 comments on commit 8340e16

Please sign in to comment.