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