Skip to content

Commit

Permalink
refactor: address code smells inside the ui folder (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhpd authored Feb 16, 2024
2 parents 13207d1 + 24054a6 commit 1de3a72
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.ZoneOffset;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import de.dennisguse.opentracks.R;
Expand All @@ -38,9 +39,9 @@ public static void showDialog(FragmentManager fragmentManager) {
filterDialogFragment.show(fragmentManager, TAG);
}

public static void showDialog(FragmentManager fragmentManager, ArrayList<FilterItem> items) {
public static void showDialog(FragmentManager fragmentManager, List<FilterItem> items) {
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(KEY_FILTER_ITEMS, items);
bundle.putParcelableArrayList(KEY_FILTER_ITEMS,(ArrayList<? extends Parcelable>) items);

FilterDialogFragment filterDialogFragment = new FilterDialogFragment();
filterDialogFragment.setArguments(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<DataField> getFields() {

public RecordingLayout toRecordingLayout(boolean visibility) {
RecordingLayout result = new RecordingLayout(this.getName());
result.addFields(dataFields.stream().filter(f -> f.isVisible() == visibility).collect(Collectors.toList()));
result.addFields(dataFields.stream().filter(f -> f.isVisible() == visibility).toList());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class RecordingLayoutIO {
private static final String YES_VALUE = "1";
private static final String NOT_VALUE = "0";

// Private constructor to hide the implicit public one
private RecordingLayoutIO() {
throw new AssertionError("This class should not be instantiated.");
}

public static RecordingLayout fromCsv(@NonNull String csvLine, @NonNull Resources resources) {
List<String> csvParts = CsvLayoutUtils.getCsvLineParts(csvLine);
if (csvParts == null) {
Expand All @@ -32,7 +37,7 @@ public static RecordingLayout fromCsv(@NonNull String csvLine, @NonNull Resource
Log.e(TAG, "Invalid CSV layout. It shouldn't happen: " + csvLine);
return recordingLayout;
}
recordingLayout.addField(fromCSV(fieldParts, resources));
recordingLayout.addField(getFieldFromCSVRecord(fieldParts, resources));
}
return recordingLayout;
}
Expand All @@ -41,7 +46,7 @@ public static String toCSV(List<RecordingLayout> recordingLayouts) {
return recordingLayouts.stream().map(RecordingLayout::toCsv).collect(Collectors.joining(CsvLayoutUtils.LINE_SEPARATOR));
}

private static DataField fromCSV(String[] fieldParts, @NonNull Resources resources) {
private static DataField getFieldFromCSVRecord(String[] fieldParts, @NonNull Resources resources) {
return new DataField(
fieldParts[0],
YES_VALUE.equals(fieldParts[1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class IntervalStatistics {
private TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
private final List<Interval> intervalList;
private final Distance distanceInterval;
private Interval interval, lastInterval;

private Interval interval;
private Interval lastInterval;

/**
* @param distanceInterval distance of every interval.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
return viewBinding.getRoot();
}

/**
* This method is deprecated.
*
* This method is marked as deprecated and should be re-implemented with updated functionality.
* Deprecated methods are discouraged from use as they may be removed or replaced in future versions.
* Developers are advised to find alternative approaches or update the method to meet current requirements.
*
* @deprecated This method is deprecated and should be re-implemented.
*
*/
@Deprecated //TODO This method must be re-implemented.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ protected void onCreate(Bundle savedInstanceState) {
takePictureFromCamera = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
switch (result.getResultCode()) {
case RESULT_CANCELED ->
Toast.makeText(this, R.string.marker_add_photo_canceled, Toast.LENGTH_LONG).show();
case RESULT_OK -> viewModel.onNewCameraPhoto(cameraPhotoUri,
int resultCode = result.getResultCode();
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.marker_add_photo_canceled, Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_OK) {
viewModel.onNewCameraPhoto(cameraPhotoUri,
viewBinding.markerEditName.getText().toString(),
viewBinding.markerEditMarkerType.getText().toString(),
viewBinding.markerEditDescription.getText().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract public class RecyclerViewSwipeDeleteCallback extends ItemTouchHelper.Ca
private final int intrinsicWidth;
private final int intrinsicHeight;

public RecyclerViewSwipeDeleteCallback(Context context) {
protected RecyclerViewSwipeDeleteCallback(Context context) {
background = new ColorDrawable();
backgroundColor = ContextCompat.getColor(context, R.color.colorBackgroundDelete);
clearPaint = new Paint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import androidx.annotation.NonNull;

/**
* AbsListView.OnScrollListener class that can be used to know what views in a ListView are currently visible while scrolling.
* AbsListView.OnScrollListener class that can be used to know what views in a
* ListView are currently visible while scrolling.
*/
public class ScrollVisibleViews implements AbsListView.OnScrollListener {
private int from = -1;
Expand All @@ -20,12 +21,12 @@ public ScrollVisibleViews(@NonNull VisibleViewsListener visibleViewsListener) {

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
if (from >= 0 && to >= 0) {
for (int i = from; i < to; i++) {
View viewChild = view.getChildAt(i - from);
visibleViewsListener.onViewVisible(viewChild, i);
}
if ((scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE
|| scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING
|| scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) && (from >= 0 && to >= 0)) {
for (int i = from; i < to; i++) {
View viewChild = view.getChildAt(i - from);
visibleViewsListener.onViewVisible(viewChild, i);
}
}
}
Expand Down

0 comments on commit 1de3a72

Please sign in to comment.