1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-30 11:40:23 +02:00

Use constants for the name of extra values in intents

This commit is contained in:
Erik Johansson
2018-01-31 22:23:15 +01:00
parent 70f263c08b
commit 640c9665bf
7 changed files with 24 additions and 20 deletions

View File

@@ -130,7 +130,7 @@ public class MainActivity extends AppCompatActivity {
if (prefs.getBoolean("firstStart", true)) {
Intent intent = new Intent(this, UserSettingsActivity.class);
intent.putExtra("mode", UserSettingsActivity.ADD_USER_REQUEST);
intent.putExtra(UserSettingsActivity.EXTRA_MODE, UserSettingsActivity.ADD_USER_REQUEST);
startActivity(intent);
prefs.edit().putBoolean("firstStart", false).commit();
@@ -252,7 +252,7 @@ public class MainActivity extends AppCompatActivity {
break;
case R.id.nav_settings:
Intent settingsIntent = new Intent(this, SettingsActivity.class);
settingsIntent.putExtra("tintColor", navDrawer.getItemTextColor().getDefaultColor());
settingsIntent.putExtra(SettingsActivity.EXTRA_TINT_COLOR, navDrawer.getItemTextColor().getDefaultColor());
startActivityForResult(settingsIntent, 1);
return;
default:

View File

@@ -59,6 +59,8 @@ import java.util.Date;
import lecho.lib.hellocharts.util.ChartUtils;
public class DataEntryActivity extends Activity {
public static String EXTRA_ID = "id";
private ArrayList<MeasurementView> dataEntryMeasurements;
private TableLayout tableLayoutDataEntry;
@@ -168,8 +170,8 @@ public class DataEntryActivity extends Activity {
}
int id = 0;
if (getIntent().hasExtra("id")) {
id = getIntent().getExtras().getInt("id");
if (getIntent().hasExtra(EXTRA_ID)) {
id = getIntent().getExtras().getInt(EXTRA_ID);
}
if (scaleMeasurement == null || scaleMeasurement.getId() != id) {
@@ -289,7 +291,7 @@ public class DataEntryActivity extends Activity {
private boolean moveLeft() {
if (previousMeasurement != null) {
saveScaleData();
getIntent().putExtra("id", previousMeasurement.getId());
getIntent().putExtra(EXTRA_ID, previousMeasurement.getId());
updateOnView();
return true;
}
@@ -300,7 +302,7 @@ public class DataEntryActivity extends Activity {
private boolean moveRight() {
if (nextMeasurement != null) {
saveScaleData();
getIntent().putExtra("id", nextMeasurement.getId());
getIntent().putExtra(EXTRA_ID, nextMeasurement.getId());
updateOnView();
return true;
}

View File

@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
public class SettingsActivity extends PreferenceActivity {
public static String EXTRA_TINT_COLOR = "tintColor";
private static List<String> fragments = new ArrayList<String>();
@Override
@@ -44,7 +45,7 @@ public class SettingsActivity extends PreferenceActivity {
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.header_preferences, target);
int tintColor = getIntent().getIntExtra("tintColor", 0);
int tintColor = getIntent().getIntExtra(EXTRA_TINT_COLOR, 0);
fragments.clear();
for (Header header : target) {

View File

@@ -40,6 +40,8 @@ import java.util.Date;
import java.util.List;
public class UserSettingsActivity extends Activity {
public static String EXTRA_ID = "id";
public static String EXTRA_MODE = "mode";
public static final int ADD_USER_REQUEST = 0;
public static final int EDIT_USER_REQUEST = 1;
@@ -126,11 +128,10 @@ public class UserSettingsActivity extends Activity {
});
if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST)
{
if (getIntent().getExtras().getInt(EXTRA_MODE) == EDIT_USER_REQUEST) {
editMode();
} else
{
}
else {
btnOk.setText(getResources().getString(R.string.label_add));
btnDelete.setVisibility(View.GONE);
}
@@ -138,7 +139,7 @@ public class UserSettingsActivity extends Activity {
private void editMode()
{
int id = getIntent().getExtras().getInt("id");
int id = getIntent().getExtras().getInt(EXTRA_ID);
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
@@ -240,7 +241,7 @@ public class UserSettingsActivity extends Activity {
deleteAllDialog.setPositiveButton(getResources().getString(R.string.label_yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
int userId = getIntent().getExtras().getInt("id");
int userId = getIntent().getExtras().getInt(EXTRA_ID);
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
openScale.clearScaleData(userId);
@@ -324,8 +325,8 @@ public class UserSettingsActivity extends Activity {
scaleUser.setGoalWeight(goal_weight);
scaleUser.setGoalDate(goal_date);
if (getIntent().getExtras().getInt("mode") == EDIT_USER_REQUEST) {
int id = getIntent().getExtras().getInt("id");
if (getIntent().getExtras().getInt(EXTRA_MODE) == EDIT_USER_REQUEST) {
int id = getIntent().getExtras().getInt(EXTRA_ID);
scaleUser.setId(id);
openScale.updateScaleUser(scaleUser);
} else {

View File

@@ -608,7 +608,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
int id = scaleMeasurement.getId();
Intent intent = new Intent(graphView.getContext(), DataEntryActivity.class);
intent.putExtra("id", id);
intent.putExtra(DataEntryActivity.EXTRA_ID, id);
startActivityForResult(intent, 1);
}

View File

@@ -270,7 +270,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
int id = Integer.parseInt(idTextView.getText().toString());
Intent intent = new Intent(tableView.getContext(), DataEntryActivity.class);
intent.putExtra("id", id);
intent.putExtra(DataEntryActivity.EXTRA_ID, id);
startActivityForResult(intent, 1); }
}

View File

@@ -97,8 +97,8 @@ public class UsersPreferences extends PreferenceFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(preference.getContext(), UserSettingsActivity.class);
intent.putExtra("mode", UserSettingsActivity.EDIT_USER_REQUEST);
intent.putExtra("id", Integer.parseInt(preference.getKey()));
intent.putExtra(UserSettingsActivity.EXTRA_MODE, UserSettingsActivity.EDIT_USER_REQUEST);
intent.putExtra(UserSettingsActivity.EXTRA_ID, Integer.parseInt(preference.getKey()));
startActivityForResult(intent, UserSettingsActivity.EDIT_USER_REQUEST);
return false;
@@ -109,7 +109,7 @@ public class UsersPreferences extends PreferenceFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(preference.getContext(), UserSettingsActivity.class);
intent.putExtra("mode", UserSettingsActivity.ADD_USER_REQUEST);
intent.putExtra(UserSettingsActivity.EXTRA_MODE, UserSettingsActivity.ADD_USER_REQUEST);
startActivityForResult(intent, UserSettingsActivity.ADD_USER_REQUEST);
return false;