mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 19:49:59 +02:00
Sort List of views as well and pass that when saving order
This commit is contained in:
@@ -536,7 +536,7 @@ public class DataEntryActivity extends AppCompatActivity {
|
||||
}
|
||||
break;
|
||||
case DragEvent.ACTION_DROP:
|
||||
View draggedView = (View) event.getLocalState();
|
||||
MeasurementView draggedView = (MeasurementView) event.getLocalState();
|
||||
TableLayout table = (TableLayout) draggedView.getParent();
|
||||
final int draggedIndex = table.indexOfChild(draggedView);
|
||||
final int targetIndex = table.indexOfChild(view);
|
||||
@@ -545,7 +545,9 @@ public class DataEntryActivity extends AppCompatActivity {
|
||||
// and a view that is moved up is placed before the target view.
|
||||
table.removeView(draggedView);
|
||||
table.addView(draggedView, targetIndex);
|
||||
MeasurementView.saveMeasurementViewsOrder(table);
|
||||
dataEntryMeasurements.remove(draggedView);
|
||||
dataEntryMeasurements.add(targetIndex, draggedView);
|
||||
MeasurementView.saveMeasurementViewsOrder(getApplicationContext(), dataEntryMeasurements);
|
||||
}
|
||||
break;
|
||||
case DragEvent.ACTION_DRAG_ENDED:
|
||||
|
@@ -144,17 +144,15 @@ public abstract class MeasurementView extends TableLayout {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
public static void saveMeasurementViewsOrder(TableLayout tableLayout) {
|
||||
public static void saveMeasurementViewsOrder(Context context, List<MeasurementView> measurementViews) {
|
||||
ArrayList<String> order = new ArrayList<>();
|
||||
for (int i = 0; i < tableLayout.getChildCount(); ++i) {
|
||||
MeasurementView view = (MeasurementView) tableLayout.getChildAt(i);
|
||||
if (view instanceof DateMeasurementView || view instanceof TimeMeasurementView) {
|
||||
for (MeasurementView measurement : measurementViews) {
|
||||
if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
|
||||
continue;
|
||||
}
|
||||
order.add(view.getKey());
|
||||
order.add(measurement.getKey());
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(tableLayout.getContext())
|
||||
.edit()
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||
.putString(PREF_MEASUREMENT_ORDER, TextUtils.join(",", order))
|
||||
.commit();
|
||||
}
|
||||
|
Reference in New Issue
Block a user