Skip to content

Commit

Permalink
#3 formula attribute for activity
Browse files Browse the repository at this point in the history
  • Loading branch information
waj0 committed Apr 17, 2014
1 parent 5559547 commit d0d0038
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class CalculationActivity extends ActionBarActivity {

private static final String TAG = "cz.fi.android.formulamanager.CalculationActivity";

//TODO we probably do _not_ need this activity, we could use main activity, just change fragment in main activity to calculation fragment
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -27,8 +26,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
if (savedInstanceState == null) {
// During initial setup, plug in the details fragment.
CalculationFragment details = new CalculationFragment();
details.setArguments(getIntent().getExtras());
CalculationFragment details = new CalculationFragment((Formula) getIntent().getParcelableExtra(FormulaListFragment.FORMULA));
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(android.R.id.content, details).commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@ public class CalculationFragment extends Fragment {

private static final String TAG = "cz.fi.android.formulamanager.CalculationFragment";

private Formula formula;

//TODO button to share is visible if only list is on screen - vertical list fragment - we should it somehow in calculation fragment lifecycle
@Override
public void onPause() {
super.onPause();
//share action visible only if calculation fragment is on screen
(getActivity().findViewById(R.id.action_share)).setVisibility(View.GONE);
public CalculationFragment() {
formula = new Formula();
formula.setId(0l);
}

@Override
public void onResume() {
super.onResume();
//share action visible only if calculation fragment is on screen
(getActivity().findViewById(R.id.action_share)).setVisibility(View.VISIBLE);
public CalculationFragment(Formula formula) {
this.formula = formula;
}

//TODO button to share is visible if only list is on screen - vertical list fragment - we should remove it somehow in calculation fragment lifecycle

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Expand All @@ -49,6 +46,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.calculation, menu);
Log.i(TAG, "create menu calc fragment");
}

@Override
Expand All @@ -59,30 +57,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_share:
//TODO do stuff to share
Log.i(TAG, "share this now: " + getArguments().getInt(FormulaListFragment.F_INDEX));
Log.i(TAG, "share this now");
}
return super.onOptionsItemSelected(item);
}

/**
* Create a new instance of CalculationFragment, initialized to
* show the text at 'index'.
*/
//TODO redo this with id of formula not with index
public static CalculationFragment newInstance(int index) {
CalculationFragment f = new CalculationFragment();

// Supply index input as an argument.
Bundle args = new Bundle();
args.putInt(FormulaListFragment.F_INDEX, index);
f.setArguments(args);

return f;
}

//TODO redo this with id of formula not with index
public int getShownIndex() {
return getArguments().getInt(FormulaListFragment.F_INDEX, 0);
public long getShownId() {
return formula.getId();
}

@Override
Expand All @@ -103,10 +85,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
4, getActivity().getResources().getDisplayMetrics());
TextView text = new TextView(getActivity());

text.setPadding(padding, padding, padding, padding);
text.setText(MainActivity.valuesFromDB.get(getShownIndex()).getName());
text.append("\n" + MainActivity.valuesFromDB.get(getShownIndex()).getParamsAsString());
text.append("\n" + MainActivity.valuesFromDB.get(getShownIndex()).getRawFormula());
text.setText(formula.getName());
text.append("\n" + formula.getParamsAsString());
text.append("\n" + formula.getRawFormula());

scroller.addView(text);
return scroller;
Expand Down

0 comments on commit d0d0038

Please sign in to comment.