Fix build

This commit is contained in:
Vitaliy 2021-01-11 11:42:59 +02:00
parent 40a0380076
commit 60bf9843de

View file

@ -13,6 +13,8 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -25,6 +27,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.Filter;
import android.widget.Filterable;
@ -100,19 +103,20 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static net.osmand.plus.GpxSelectionHelper.CURRENT_TRACK;
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.OPEN_GPX_REQUEST;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
import static net.osmand.util.Algorithms.collectDirs;
import static net.osmand.util.Algorithms.formatDuration;
import static net.osmand.util.Algorithms.objectEquals;
import static net.osmand.util.Algorithms.removeAllFiles;
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
FavoritesFragmentStateHolder, OsmAuthorizationListener, OnTrackFileMoveListener, RenameCallback {
FavoritesFragmentStateHolder, OsmAuthorizationListener, RenameCallback {
public static final int SEARCH_ID = -1;
// public static final int ACTION_ID = 0;
@ -796,104 +800,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
if (activity != null) {
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(), this, info.file.getAbsolutePath(), false);
}
menuAdapter.addItem(itemBuilder.setTitleId(R.string.add_new_folder, app)
.setIcon(R.drawable.ic_zoom_in).setTag(-1).createItem());
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final ArrayAdapter<ContextMenuItem> listAdapter =
menuAdapter.createListAdapter(getActivity(), app.getSettings().isLightContent());
builder.setTitle(R.string.select_gpx_folder);
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ContextMenuItem item = menuAdapter.getItem(which);
int index = item.getTag();
if (index == -1) {
Activity a = getActivity();
AlertDialog.Builder b = new AlertDialog.Builder(a);
b.setTitle(R.string.add_new_folder);
final EditText editText = new EditText(a);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Editable text = editText.getText();
if (text.length() >= 1) {
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(text).find()) {
editText.setError(app.getString(R.string.file_name_containes_illegal_char));
}
}
}
});
int leftPadding = AndroidUtils.dpToPx(a, 24f);
int topPadding = AndroidUtils.dpToPx(a, 4f);
b.setView(editText, leftPadding, topPadding, leftPadding, topPadding);
// Behaviour will be overwritten later;
b.setPositiveButton(R.string.shared_string_ok, null);
b.setNegativeButton(R.string.shared_string_cancel, null);
final AlertDialog alertDialog = b.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
String newName = editText.getText().toString();
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(newName).find()) {
Toast.makeText(app, R.string.file_name_containes_illegal_char,
Toast.LENGTH_LONG).show();
return;
}
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), newName);
if (destFolder.exists()) {
Toast.makeText(app, R.string.file_with_name_already_exists,
Toast.LENGTH_LONG).show();
return;
} else if (destFolder.mkdirs()) {
File dest = new File(destFolder, info.fileName);
if (info.file.renameTo(dest)) {
app.getGpxDbHelper().rename(info.file, dest);
reloadTracks();
} else {
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
}
alertDialog.dismiss();
}
});
}
});
alertDialog.show();
} else {
File dir = dirs.get(index);
File dest = new File(dir, info.file.getName());
if (dest.exists()) {
Toast.makeText(app, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
} else {
if (info.file.renameTo(dest)) {
app.getGpxDbHelper().rename(info.file, dest);
reloadTracks();
} else {
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
}
}
}
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
}
@Override