Refactor
This commit is contained in:
parent
e1e3f17667
commit
c02c2e47e2
3 changed files with 28 additions and 28 deletions
|
@ -1,6 +1,6 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -36,11 +36,11 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
|
|||
private OnItemClickListener onItemClickListener;
|
||||
private UiUtilities iconsCache;
|
||||
|
||||
GpxTrackAdapter(Activity activity, List<GpxUiHelper.GPXInfo> gpxInfoList, boolean showCurrentGpx) {
|
||||
GpxTrackAdapter(Context ctx, List<GpxUiHelper.GPXInfo> gpxInfoList, boolean showCurrentGpx) {
|
||||
this.showCurrentGpx = showCurrentGpx;
|
||||
app = (OsmandApplication) activity.getApplication();
|
||||
app = (OsmandApplication) ctx.getApplicationContext();
|
||||
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
themedInflater = UiUtilities.getInflater(activity, nightMode);
|
||||
themedInflater = UiUtilities.getInflater(ctx, nightMode);
|
||||
this.gpxInfoList = gpxInfoList;
|
||||
iconsCache = app.getUIUtilities();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import androidx.appcompat.widget.ListPopupWindow;
|
|||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
|
@ -257,7 +258,7 @@ public class GpxUiHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void selectSingleGPXFile(final MapActivity activity, boolean showCurrentGpx,
|
||||
public static void selectSingleGPXFile(final FragmentActivity activity, boolean showCurrentGpx,
|
||||
final CallbackWithObject<GPXFile[]> callbackWithObject) {
|
||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
int gpxDirLength = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath().length();
|
||||
|
@ -277,7 +278,7 @@ public class GpxUiHelper {
|
|||
list.add(new GPXInfo(gpxFile.path.substring(gpxDirLength + 1), gpxFile.modifiedTime, 0));
|
||||
}
|
||||
}
|
||||
SelectGpxTrackBottomSheet.showInstance(activity, showCurrentGpx, callbackWithObject, list);
|
||||
SelectGpxTrackBottomSheet.showInstance(activity.getSupportFragmentManager(), showCurrentGpx, callbackWithObject, list);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -15,7 +15,6 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
|
||||
|
@ -24,24 +23,23 @@ import java.util.List;
|
|||
|
||||
public class SelectGpxTrackBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "SelectGpxTrackBottomSheet";
|
||||
public static final String TAG = SelectGpxTrackBottomSheet.class.getSimpleName();
|
||||
|
||||
protected View mainView;
|
||||
protected GpxTrackAdapter adapter;
|
||||
|
||||
private List<GpxUiHelper.GPXInfo> gpxInfoList;
|
||||
private OsmandApplication app;
|
||||
private boolean showCurrentGpx;
|
||||
private CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject;
|
||||
private Activity activity;
|
||||
|
||||
private SelectGpxTrackBottomSheet(Activity activity, boolean showCurrentGpx, CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject,
|
||||
List<GpxUiHelper.GPXInfo> gpxInfoList) {
|
||||
super();
|
||||
app = (OsmandApplication) activity.getApplication();
|
||||
this.activity = activity;
|
||||
this.showCurrentGpx = showCurrentGpx;
|
||||
private void setGpxInfoList(List<GpxUiHelper.GPXInfo> gpxInfoList) {
|
||||
this.gpxInfoList = gpxInfoList;
|
||||
}
|
||||
|
||||
private void setShowCurrentGpx(boolean showCurrentGpx) {
|
||||
this.showCurrentGpx = showCurrentGpx;
|
||||
}
|
||||
|
||||
private void setCallbackWithObject(CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject) {
|
||||
this.callbackWithObject = callbackWithObject;
|
||||
}
|
||||
|
||||
|
@ -53,7 +51,7 @@ public class SelectGpxTrackBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
|
||||
final RecyclerView recyclerView = mainView.findViewById(R.id.gpx_track_list);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapter = createAdapter();
|
||||
adapter = new GpxTrackAdapter(requireContext(), gpxInfoList, showCurrentGpx);
|
||||
adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(int position) {
|
||||
|
@ -68,12 +66,9 @@ public class SelectGpxTrackBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
|
||||
}
|
||||
|
||||
private GpxTrackAdapter createAdapter() {
|
||||
return new GpxTrackAdapter(activity, gpxInfoList, showCurrentGpx);
|
||||
}
|
||||
|
||||
private void onItemClick(int position) {
|
||||
if (position != -1 && position < gpxInfoList.size()) {
|
||||
OsmandApplication app = (OsmandApplication) requireActivity().getApplication();
|
||||
if (showCurrentGpx && position == 0) {
|
||||
callbackWithObject.processResult(null);
|
||||
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(null);
|
||||
|
@ -86,24 +81,28 @@ public class SelectGpxTrackBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
callbackWithObject.processResult(new GPXUtilities.GPXFile[]{selectedGpxFile.getGpxFile()});
|
||||
} else {
|
||||
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
GpxUiHelper.loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
|
||||
GpxUiHelper.loadGPXFileInDifferentThread(requireActivity(), callbackWithObject, dir, null, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
public static void showInstance(MapActivity mapActivity, boolean showCurrentGpx,
|
||||
public static void showInstance(FragmentManager fragmentManager, boolean showCurrentGpx,
|
||||
CallbackWithObject<GPXUtilities.GPXFile[]> callbackWithObject, List<GpxUiHelper.GPXInfo> gpxInfoList) {
|
||||
SelectGpxTrackBottomSheet fragment = new SelectGpxTrackBottomSheet(mapActivity, showCurrentGpx, callbackWithObject, gpxInfoList);
|
||||
SelectGpxTrackBottomSheet fragment = new SelectGpxTrackBottomSheet();
|
||||
fragment.setUsedOnMap(true);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), SelectGpxTrackBottomSheet.TAG);
|
||||
fragment.setShowCurrentGpx(showCurrentGpx);
|
||||
fragment.setCallbackWithObject(callbackWithObject);
|
||||
fragment.setGpxInfoList(gpxInfoList);
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
fragment.show(fragmentManager, SelectGpxTrackBottomSheet.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue