forked from upstream-mirrors/OpenTracks
DialogFragments: do not save state.
This commit is contained in:
@@ -182,8 +182,7 @@ public abstract class AbstractListActivity extends AbstractActivity implements C
|
|||||||
* @param trackIds the track ids
|
* @param trackIds the track ids
|
||||||
*/
|
*/
|
||||||
protected void deleteTracks(long[] trackIds) {
|
protected void deleteTracks(long[] trackIds) {
|
||||||
ConfirmDeleteDialogFragment.newInstance(trackIds)
|
ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackIds);
|
||||||
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -300,8 +300,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
if (markerIds.length > 1 && markerIds.length == listView.getCount()) {
|
if (markerIds.length > 1 && markerIds.length == listView.getCount()) {
|
||||||
markerIds = new long[]{-1L};
|
markerIds = new long[]{-1L};
|
||||||
}
|
}
|
||||||
DeleteMarkerDialogFragment.newInstance(markerIds)
|
DeleteMarkerDialogFragment.showDialog(getSupportFragmentManager(), markerIds);
|
||||||
.show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_select_all:
|
case R.id.list_context_menu_select_all:
|
||||||
int size = listView.getCount();
|
int size = listView.getCount();
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_delete:
|
case R.id.list_context_menu_delete:
|
||||||
if (markerId != null) {
|
if (markerId != null) {
|
||||||
DeleteMarkerDialogFragment.newInstance(new long[]{markerId}).show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
DeleteMarkerDialogFragment.showDialog(getSupportFragmentManager(), new long[]{markerId});
|
||||||
} else {
|
} else {
|
||||||
deleteTracks(new long[]{trackId});
|
deleteTracks(new long[]{trackId});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,12 +361,10 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_voice_frequency:
|
case R.id.track_detail_voice_frequency:
|
||||||
FrequencyDialogFragment.newInstance(R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.string.menu_voice_frequency)
|
FrequencyDialogFragment.showDialog(getSupportFragmentManager(), R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.string.menu_voice_frequency);
|
||||||
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_split_frequency:
|
case R.id.track_detail_split_frequency:
|
||||||
FrequencyDialogFragment.newInstance(R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT, R.string.menu_split_frequency)
|
FrequencyDialogFragment.showDialog(getSupportFragmentManager(), R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT, R.string.menu_split_frequency);
|
||||||
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_edit:
|
case R.id.track_detail_edit:
|
||||||
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.util.DialogUtils;
|
import de.dennisguse.opentracks.util.DialogUtils;
|
||||||
@@ -34,22 +35,21 @@ import de.dennisguse.opentracks.util.DialogUtils;
|
|||||||
*/
|
*/
|
||||||
public class ConfirmDeleteDialogFragment extends DialogFragment {
|
public class ConfirmDeleteDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public static final String CONFIRM_DELETE_DIALOG_TAG = "confirmDeleteDialog";
|
private static final String CONFIRM_DELETE_DIALOG_TAG = "confirmDeleteDialog";
|
||||||
private static final String KEY_TRACK_IDS = "trackIds";
|
|
||||||
private ConfirmDeleteCaller caller;
|
private ConfirmDeleteCaller caller;
|
||||||
|
private long[] trackIds;
|
||||||
|
|
||||||
|
public ConfirmDeleteDialogFragment(long[] trackIds) {
|
||||||
|
this.trackIds = trackIds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
* @param trackIds list of track ids to delete. To delete all, set to size 1 with trackIds[0] == -1L
|
* @param trackIds list of track ids to delete. To delete all, set to size 1 with trackIds[0] == -1L
|
||||||
*/
|
*/
|
||||||
public static ConfirmDeleteDialogFragment newInstance(long[] trackIds) {
|
public static void showDialog(FragmentManager fragmentManager, long[] trackIds) {
|
||||||
Bundle bundle = new Bundle();
|
new ConfirmDeleteDialogFragment(trackIds).show(fragmentManager, CONFIRM_DELETE_DIALOG_TAG);
|
||||||
bundle.putLongArray(KEY_TRACK_IDS, trackIds);
|
|
||||||
|
|
||||||
ConfirmDeleteDialogFragment deleteTrackDialogFragment = new ConfirmDeleteDialogFragment();
|
|
||||||
deleteTrackDialogFragment.setArguments(bundle);
|
|
||||||
return deleteTrackDialogFragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,11 +62,9 @@ public class ConfirmDeleteDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final long[] trackIds = getArguments().getLongArray(KEY_TRACK_IDS);
|
|
||||||
int titleId;
|
int titleId;
|
||||||
int messageId;
|
int messageId;
|
||||||
titleId = trackIds.length > 1 ? R.string.generic_delete_selected_confirm_title : R.string.track_delete_one_confirm_title;
|
titleId = trackIds.length > 1 ? R.string.generic_delete_selected_confirm_title : R.string.track_delete_one_confirm_title;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
@@ -37,17 +38,17 @@ import de.dennisguse.opentracks.util.DialogUtils;
|
|||||||
*/
|
*/
|
||||||
public class DeleteMarkerDialogFragment extends DialogFragment {
|
public class DeleteMarkerDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public static final String DELETE_MARKER_DIALOG_TAG = "deleteMarkerDialog";
|
private static final String DELETE_MARKER_DIALOG_TAG = "deleteMarkerDialog";
|
||||||
private static final String KEY_MARKER_IDS = "markerIds";
|
private long[] markerIds;
|
||||||
|
|
||||||
private DeleteMarkerCaller caller;
|
private DeleteMarkerCaller caller;
|
||||||
|
|
||||||
public static DeleteMarkerDialogFragment newInstance(long[] markerIds) {
|
public DeleteMarkerDialogFragment(long[] markerIds) {
|
||||||
Bundle bundle = new Bundle();
|
this.markerIds = markerIds;
|
||||||
bundle.putLongArray(KEY_MARKER_IDS, markerIds);
|
}
|
||||||
|
|
||||||
DeleteMarkerDialogFragment deleteMarkerDialogFragment = new DeleteMarkerDialogFragment();
|
public static void showDialog(FragmentManager fragmentManager, long[] markerIds) {
|
||||||
deleteMarkerDialogFragment.setArguments(bundle);
|
new DeleteMarkerDialogFragment(markerIds).show(fragmentManager, DELETE_MARKER_DIALOG_TAG);
|
||||||
return deleteMarkerDialogFragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,7 +65,6 @@ public class DeleteMarkerDialogFragment extends DialogFragment {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final FragmentActivity fragmentActivity = getActivity();
|
final FragmentActivity fragmentActivity = getActivity();
|
||||||
final long[] markerIds = getArguments().getLongArray(KEY_MARKER_IDS);
|
|
||||||
int titleId;
|
int titleId;
|
||||||
int messageId;
|
int messageId;
|
||||||
if (markerIds.length == 1 && markerIds[0] == -1L) {
|
if (markerIds.length == 1 && markerIds[0] == -1L) {
|
||||||
@@ -81,8 +81,7 @@ public class DeleteMarkerDialogFragment extends DialogFragment {
|
|||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(
|
ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(fragmentActivity);
|
||||||
fragmentActivity);
|
|
||||||
for (long markerId : markerIds) {
|
for (long markerId : markerIds) {
|
||||||
contentProviderUtils.deleteWaypoint(fragmentActivity,
|
contentProviderUtils.deleteWaypoint(fragmentActivity,
|
||||||
markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -39,19 +40,19 @@ import de.dennisguse.opentracks.util.FileUtils;
|
|||||||
*/
|
*/
|
||||||
public class FileTypeDialogFragment extends DialogFragment {
|
public class FileTypeDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public static final String FILE_TYPE_DIALOG_TAG = "fileType";
|
private static final String FILE_TYPE_DIALOG_TAG = "fileType";
|
||||||
private static final String KEY_TITLE_ID = "titleId";
|
private int titleId;
|
||||||
private static final String KEY_OPTION_ID = "optionId";
|
|
||||||
private FileTypeCaller caller;
|
private FileTypeCaller caller;
|
||||||
|
private int optionId;
|
||||||
|
|
||||||
public static FileTypeDialogFragment newInstance(int titleId, int optionId) {
|
public FileTypeDialogFragment(int titleId, int optionId) {
|
||||||
Bundle bundle = new Bundle();
|
this.titleId = titleId;
|
||||||
bundle.putInt(KEY_TITLE_ID, titleId);
|
this.optionId = optionId;
|
||||||
bundle.putInt(KEY_OPTION_ID, optionId);
|
}
|
||||||
|
|
||||||
FileTypeDialogFragment fileTypeDialogFragment = new FileTypeDialogFragment();
|
public static void showDialog(FragmentManager fragmentManager, int titleId, int optionId) {
|
||||||
fileTypeDialogFragment.setArguments(bundle);
|
new FileTypeDialogFragment(titleId, optionId).show(fragmentManager, FILE_TYPE_DIALOG_TAG);
|
||||||
return fileTypeDialogFragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,8 +68,6 @@ public class FileTypeDialogFragment extends DialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
int optionId = getArguments().getInt(KEY_OPTION_ID);
|
|
||||||
final int titleId = getArguments().getInt(KEY_TITLE_ID);
|
|
||||||
final TrackFileFormat[] trackFileFormats = {TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES, TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA, TrackFileFormat.GPX};
|
final TrackFileFormat[] trackFileFormats = {TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES, TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA, TrackFileFormat.GPX};
|
||||||
String[] choices = new String[trackFileFormats.length];
|
String[] choices = new String[trackFileFormats.length];
|
||||||
for (int i = 0; i < choices.length; i++) {
|
for (int i = 0; i < choices.length; i++) {
|
||||||
@@ -96,7 +95,7 @@ public class FileTypeDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(@NonNull DialogInterface dialog) {
|
||||||
onDismissed();
|
onDismissed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
@@ -36,21 +37,19 @@ import de.dennisguse.opentracks.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class FrequencyDialogFragment extends DialogFragment {
|
public class FrequencyDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public static final String FREQUENCY_DIALOG_TAG = "frequencyDialog";
|
private static final String FREQUENCY_DIALOG_TAG = "frequencyDialog";
|
||||||
|
private int preferenceId;
|
||||||
|
private int defaultValue;
|
||||||
|
private int titleId;
|
||||||
|
|
||||||
private static final String KEY_PREFERENCE_ID = "preferenceId";
|
public FrequencyDialogFragment(int preferenceId, int defaultValue, int titleId) {
|
||||||
private static final String KEY_DEFAULT_VALUE = "defaultValue";
|
this.preferenceId = preferenceId;
|
||||||
private static final String KEY_TITLE_ID = "titleId";
|
this.defaultValue = defaultValue;
|
||||||
|
this.titleId = titleId;
|
||||||
|
}
|
||||||
|
|
||||||
public static FrequencyDialogFragment newInstance(int preferenceId, int defaultValue, int titleId) {
|
public static void showDialog(FragmentManager fragmentManager, int preferenceId, int defaultValue, int titleId) {
|
||||||
Bundle bundle = new Bundle();
|
new FrequencyDialogFragment(preferenceId, defaultValue, titleId).show(fragmentManager, FREQUENCY_DIALOG_TAG);
|
||||||
bundle.putInt(KEY_PREFERENCE_ID, preferenceId);
|
|
||||||
bundle.putInt(KEY_DEFAULT_VALUE, defaultValue);
|
|
||||||
bundle.putInt(KEY_TITLE_ID, titleId);
|
|
||||||
|
|
||||||
FrequencyDialogFragment frequencyDialogFragment = new FrequencyDialogFragment();
|
|
||||||
frequencyDialogFragment.setArguments(bundle);
|
|
||||||
return frequencyDialogFragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,9 +57,6 @@ public class FrequencyDialogFragment extends DialogFragment {
|
|||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
FragmentActivity fragmentActivity = getActivity();
|
FragmentActivity fragmentActivity = getActivity();
|
||||||
|
|
||||||
final int preferenceId = getArguments().getInt(KEY_PREFERENCE_ID);
|
|
||||||
int defaultValue = getArguments().getInt(KEY_DEFAULT_VALUE);
|
|
||||||
int titleId = getArguments().getInt(KEY_TITLE_ID);
|
|
||||||
int frequencyValue = PreferencesUtils.getInt(fragmentActivity, preferenceId, defaultValue);
|
int frequencyValue = PreferencesUtils.getInt(fragmentActivity, preferenceId, defaultValue);
|
||||||
|
|
||||||
return new AlertDialog.Builder(fragmentActivity).setPositiveButton(
|
return new AlertDialog.Builder(fragmentActivity).setPositiveButton(
|
||||||
|
|||||||
@@ -192,8 +192,7 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.marker_detail_delete:
|
case R.id.marker_detail_delete:
|
||||||
DeleteMarkerDialogFragment.newInstance(new long[]{markerId})
|
DeleteMarkerDialogFragment.showDialog(getChildFragmentManager(), new long[]{markerId});
|
||||||
.show(getChildFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|||||||
@@ -84,9 +84,7 @@ public class ExportActivity extends FragmentActivity implements FileTypeDialogFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fileTypeDialogStart() {
|
private void fileTypeDialogStart() {
|
||||||
FileTypeDialogFragment
|
FileTypeDialogFragment.showDialog(getSupportFragmentManager(), R.string.export_all_title, R.string.export_all_option);
|
||||||
.newInstance(R.string.export_all_title, R.string.export_all_option)
|
|
||||||
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -85,9 +85,7 @@ public class ImportActivity extends FragmentActivity implements FileTypeDialogFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fileTypeDialogStart() {
|
private void fileTypeDialogStart() {
|
||||||
FileTypeDialogFragment
|
FileTypeDialogFragment.showDialog(getSupportFragmentManager(), R.string.import_selection_title, R.string.import_selection_option);
|
||||||
.newInstance(R.string.import_selection_title, R.string.import_selection_option)
|
|
||||||
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user