small refactoring
This commit is contained in:
parent
ca03a530ff
commit
e3b4786556
2 changed files with 95 additions and 99 deletions
|
@ -76,16 +76,17 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
private OnLiveUpdatesForLocalChange onLiveUpdatesForLocalChange;
|
|
||||||
|
private BaseBottomSheetItem itemLastCheck;
|
||||||
|
private BaseBottomSheetItem itemSwitchLiveUpdate;
|
||||||
|
private BaseBottomSheetItem itemFrequencyHelpMessage;
|
||||||
|
private BaseBottomSheetItem itemClear;
|
||||||
|
private BaseBottomSheetItem itemViaWiFi;
|
||||||
private MultiStateToggleButton frequencyToggleButton;
|
private MultiStateToggleButton frequencyToggleButton;
|
||||||
private MultiStateToggleButton timeOfDayToggleButton;
|
private MultiStateToggleButton timeOfDayToggleButton;
|
||||||
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
private int indexLastCheckItem = -1;
|
private OnLiveUpdatesForLocalChange onLiveUpdatesForLocalChange;
|
||||||
private int indexSwitchLiveUpdateItem = -1;
|
|
||||||
private int indexFrequencyHelpMessageItem = -1;
|
|
||||||
private int indexClearItem = -1;
|
|
||||||
private int indexViaWiFiItem = -1;
|
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fragmentManager, Fragment target, String fileName) {
|
public static void showInstance(@NonNull FragmentManager fragmentManager, Fragment target, String fileName) {
|
||||||
if (!fragmentManager.isStateSaved()) {
|
if (!fragmentManager.isStateSaved()) {
|
||||||
|
@ -122,20 +123,20 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_title_big)
|
.setLayoutId(R.layout.bottom_sheet_item_title_big)
|
||||||
.create());
|
.create());
|
||||||
|
|
||||||
items.add(new ShortDescriptionItem.Builder()
|
itemLastCheck = new ShortDescriptionItem.Builder()
|
||||||
.setDescription(getLastCheckString())
|
.setDescription(getLastCheckString())
|
||||||
.setDescriptionColorId(getSecondaryTextColorId(nightMode))
|
.setDescriptionColorId(getSecondaryTextColorId(nightMode))
|
||||||
.setDescriptionMaxLines(2)
|
.setDescriptionMaxLines(2)
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_description)
|
.setLayoutId(R.layout.bottom_sheet_item_description)
|
||||||
.create());
|
.create();
|
||||||
indexLastCheckItem = items.size() - 1;
|
items.add(itemLastCheck);
|
||||||
|
|
||||||
View itemLiveUpdate = getCustomButtonView(app, null, localUpdatePreference.get(), nightMode);
|
View itemLiveUpdate = getCustomButtonView(app, null, localUpdatePreference.get(), nightMode);
|
||||||
View itemLiveUpdateButton = itemLiveUpdate.findViewById(R.id.button_container);
|
View itemLiveUpdateButton = itemLiveUpdate.findViewById(R.id.button_container);
|
||||||
CompoundButton button = (CompoundButton) itemLiveUpdateButton.findViewById(R.id.compound_button);
|
CompoundButton button = (CompoundButton) itemLiveUpdateButton.findViewById(R.id.compound_button);
|
||||||
UiUtilities.setupCompoundButton(button, nightMode, TOOLBAR);
|
UiUtilities.setupCompoundButton(button, nightMode, TOOLBAR);
|
||||||
itemLiveUpdateButton.setMinimumHeight(getDimen(R.dimen.bottom_sheet_selected_item_title_height));
|
itemLiveUpdateButton.setMinimumHeight(getDimen(R.dimen.bottom_sheet_selected_item_title_height));
|
||||||
items.add(new BottomSheetItemWithCompoundButton.Builder()
|
itemSwitchLiveUpdate = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
.setChecked(localUpdatePreference.get())
|
.setChecked(localUpdatePreference.get())
|
||||||
.setTitle(getStateText(localUpdatePreference.get()))
|
.setTitle(getStateText(localUpdatePreference.get()))
|
||||||
.setTitleColorId(getActiveTabTextColorId(nightMode))
|
.setTitleColorId(getActiveTabTextColorId(nightMode))
|
||||||
|
@ -143,11 +144,11 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (indexSwitchLiveUpdateItem != -1) {
|
BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) itemSwitchLiveUpdate;
|
||||||
BottomSheetItemWithCompoundButton button = (BottomSheetItemWithCompoundButton) items.get(indexSwitchLiveUpdateItem);
|
boolean checked = item.isChecked();
|
||||||
button.setChecked(!button.isChecked());
|
item.setChecked(!checked);
|
||||||
if (onLiveUpdatesForLocalChange != null
|
if (onLiveUpdatesForLocalChange != null
|
||||||
&& onLiveUpdatesForLocalChange.onUpdateLocalIndex(fileName, button.isChecked(), new Runnable() {
|
&& onLiveUpdatesForLocalChange.onUpdateLocalIndex(fileName, !checked, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateLastCheck();
|
updateLastCheck();
|
||||||
|
@ -155,20 +156,17 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
updateFileSize();
|
updateFileSize();
|
||||||
}
|
}
|
||||||
})) {
|
})) {
|
||||||
if (indexSwitchLiveUpdateItem != -1 && items.size() > 0) {
|
item.setTitle(getStateText(!checked));
|
||||||
button.setTitle(getStateText(button.isChecked()));
|
updateCustomButtonView(app, null, item.getView(), !checked, nightMode);
|
||||||
updateCustomButtonView(app, null, button.getView(), button.isChecked(), nightMode);
|
|
||||||
}
|
|
||||||
CommonPreference<Boolean> localUpdatePreference = preferenceForLocalIndex(fileName, settings);
|
CommonPreference<Boolean> localUpdatePreference = preferenceForLocalIndex(fileName, settings);
|
||||||
frequencyToggleButton.updateView(localUpdatePreference.get());
|
frequencyToggleButton.updateView(localUpdatePreference.get());
|
||||||
timeOfDayToggleButton.updateView(localUpdatePreference.get());
|
timeOfDayToggleButton.updateView(localUpdatePreference.get());
|
||||||
setStateViaWiFiButton(localUpdatePreference);
|
setStateViaWiFiButton(localUpdatePreference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.create());
|
.create();
|
||||||
indexSwitchLiveUpdateItem = items.size() - 1;
|
items.add(itemSwitchLiveUpdate);
|
||||||
|
|
||||||
TextViewEx frequencyTitle = (TextViewEx) inflater.inflate(R.layout.bottom_sheet_item_title, null);
|
TextViewEx frequencyTitle = (TextViewEx) inflater.inflate(R.layout.bottom_sheet_item_title, null);
|
||||||
frequencyTitle.setHeight(dp48);
|
frequencyTitle.setHeight(dp48);
|
||||||
|
@ -181,7 +179,8 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
.create());
|
.create());
|
||||||
|
|
||||||
LinearLayout itemFrequencyButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
|
LinearLayout itemFrequencyButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
|
||||||
LinearLayout.MarginLayoutParams itemFrequencyParams = new LinearLayout.MarginLayoutParams(LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
|
LinearLayout.MarginLayoutParams itemFrequencyParams = new LinearLayout.MarginLayoutParams(
|
||||||
|
LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
|
||||||
AndroidUtils.setMargins(itemFrequencyParams, dp16, 0, dp16, dp12);
|
AndroidUtils.setMargins(itemFrequencyParams, dp16, 0, dp16, dp12);
|
||||||
itemFrequencyButtons.setLayoutParams(itemFrequencyParams);
|
itemFrequencyButtons.setLayoutParams(itemFrequencyParams);
|
||||||
|
|
||||||
|
@ -211,7 +210,8 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
.create());
|
.create());
|
||||||
|
|
||||||
LinearLayout itemTimeOfDayButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
|
LinearLayout itemTimeOfDayButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
|
||||||
LinearLayout.MarginLayoutParams itemTimeOfDayParams = new LinearLayout.MarginLayoutParams(LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
|
LinearLayout.MarginLayoutParams itemTimeOfDayParams = new LinearLayout.MarginLayoutParams(
|
||||||
|
LinearLayout.MarginLayoutParams.MATCH_PARENT, LinearLayout.MarginLayoutParams.WRAP_CONTENT);
|
||||||
AndroidUtils.setMargins(itemTimeOfDayParams, dp16, 0, dp16, getDimen(R.dimen.context_menu_padding_margin_medium));
|
AndroidUtils.setMargins(itemTimeOfDayParams, dp16, 0, dp16, getDimen(R.dimen.context_menu_padding_margin_medium));
|
||||||
itemTimeOfDayButtons.setLayoutParams(itemTimeOfDayParams);
|
itemTimeOfDayButtons.setLayoutParams(itemTimeOfDayParams);
|
||||||
|
|
||||||
|
@ -236,14 +236,15 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
.create()
|
.create()
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(new ShortDescriptionItem.Builder()
|
itemFrequencyHelpMessage = new ShortDescriptionItem.Builder()
|
||||||
.setDescription(getFrequencyHelpMessage())
|
.setDescription(getFrequencyHelpMessage())
|
||||||
.setDescriptionColorId(getSecondaryTextColorId(nightMode))
|
.setDescriptionColorId(getSecondaryTextColorId(nightMode))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_description)
|
.setLayoutId(R.layout.bottom_sheet_item_description)
|
||||||
.create());
|
.create();
|
||||||
indexFrequencyHelpMessageItem = items.size() - 1;
|
items.add(itemFrequencyHelpMessage);
|
||||||
|
|
||||||
LinearLayout itemUpdateNowButton = (LinearLayout) inflater.inflate(R.layout.bottom_sheet_button_with_icon_center, null);
|
LinearLayout itemUpdateNowButton =
|
||||||
|
(LinearLayout) inflater.inflate(R.layout.bottom_sheet_button_with_icon_center, null);
|
||||||
LinearLayout.MarginLayoutParams itemUpdateNowParams = new LinearLayout.MarginLayoutParams(
|
LinearLayout.MarginLayoutParams itemUpdateNowParams = new LinearLayout.MarginLayoutParams(
|
||||||
LinearLayout.MarginLayoutParams.MATCH_PARENT, getDimen(R.dimen.measurement_tool_button_height));
|
LinearLayout.MarginLayoutParams.MATCH_PARENT, getDimen(R.dimen.measurement_tool_button_height));
|
||||||
AndroidUtils.setMargins(itemUpdateNowParams, dp12, dp12, dp16, dp12);
|
AndroidUtils.setMargins(itemUpdateNowParams, dp12, dp12, dp16, dp12);
|
||||||
|
@ -281,8 +282,7 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
int iconDeleteColor = ContextCompat.getColor(app, R.color.color_osm_edit_delete);
|
int iconDeleteColor = ContextCompat.getColor(app, R.color.color_osm_edit_delete);
|
||||||
Drawable iconDelete = AppCompatResources.getDrawable(app, R.drawable.ic_action_delete_dark);
|
Drawable iconDelete = AppCompatResources.getDrawable(app, R.drawable.ic_action_delete_dark);
|
||||||
|
|
||||||
items.add(
|
itemClear = new BottomSheetItemWithDescription.Builder()
|
||||||
new BottomSheetItemWithDescription.Builder()
|
|
||||||
.setDescription(getUpdatesSizeStr())
|
.setDescription(getUpdatesSizeStr())
|
||||||
.setIcon(UiUtilities.tintDrawable(iconDelete, iconDeleteColor))
|
.setIcon(UiUtilities.tintDrawable(iconDelete, iconDeleteColor))
|
||||||
.setTitle(getString(R.string.updates_size))
|
.setTitle(getString(R.string.updates_size))
|
||||||
|
@ -298,14 +298,12 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create()
|
.create();
|
||||||
);
|
items.add(itemClear);
|
||||||
indexClearItem = items.size() - 1;
|
|
||||||
|
|
||||||
items.add(createDividerItem());
|
items.add(createDividerItem());
|
||||||
|
|
||||||
items.add(
|
itemViaWiFi = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
new BottomSheetItemWithCompoundButton.Builder()
|
|
||||||
.setChecked(downloadViaWiFiPreference.get())
|
.setChecked(downloadViaWiFiPreference.get())
|
||||||
.setDescription(getStateText(downloadViaWiFiPreference.get()))
|
.setDescription(getStateText(downloadViaWiFiPreference.get()))
|
||||||
.setIconHidden(true)
|
.setIconHidden(true)
|
||||||
|
@ -314,17 +312,17 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (preferenceForLocalIndex(fileName, settings).get() && indexViaWiFiItem != -1 && items.size() > 0) {
|
if (preferenceForLocalIndex(fileName, settings).get()) {
|
||||||
BottomSheetItemWithCompoundButton button = (BottomSheetItemWithCompoundButton) items.get(indexViaWiFiItem);
|
BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) itemViaWiFi;
|
||||||
button.setChecked(!button.isChecked());
|
boolean checked = item.isChecked();
|
||||||
button.setDescription(getStateText(button.isChecked()));
|
item.setChecked(!checked);
|
||||||
preferenceDownloadViaWiFi(fileName, settings).set(button.isChecked());
|
item.setDescription(getStateText(!checked));
|
||||||
|
preferenceDownloadViaWiFi(fileName, settings).set(!checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create()
|
.create();
|
||||||
);
|
items.add(itemViaWiFi);
|
||||||
indexViaWiFiItem = items.size() - 1;
|
|
||||||
|
|
||||||
items.add(new DividerSpaceItem(app, getDimen(R.dimen.context_menu_padding_margin_large)));
|
items.add(new DividerSpaceItem(app, getDimen(R.dimen.context_menu_padding_margin_large)));
|
||||||
}
|
}
|
||||||
|
@ -345,12 +343,12 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStateViaWiFiButton(CommonPreference<Boolean> localUpdatePreference) {
|
private void setStateViaWiFiButton(CommonPreference<Boolean> localUpdatePreference) {
|
||||||
if (indexViaWiFiItem != -1 && items.size() > 0) {
|
if (itemViaWiFi != null) {
|
||||||
BottomSheetItemWithCompoundButton button = (BottomSheetItemWithCompoundButton) items.get(indexViaWiFiItem);
|
BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) itemViaWiFi;
|
||||||
if (button.getView() != null) {
|
if (item.getView() != null) {
|
||||||
TextView title = button.getView().findViewById(R.id.title);
|
TextView title = item.getView().findViewById(R.id.title);
|
||||||
TextView description = button.getView().findViewById(R.id.description);
|
TextView description = item.getView().findViewById(R.id.description);
|
||||||
CompoundButton compoundButton = button.getView().findViewById(R.id.compound_button);
|
CompoundButton compoundButton = item.getView().findViewById(R.id.compound_button);
|
||||||
if (localUpdatePreference.get()) {
|
if (localUpdatePreference.get()) {
|
||||||
AndroidUtils.setTextPrimaryColor(app, title, nightMode);
|
AndroidUtils.setTextPrimaryColor(app, title, nightMode);
|
||||||
AndroidUtils.setTextSecondaryColor(app, description, nightMode);
|
AndroidUtils.setTextSecondaryColor(app, description, nightMode);
|
||||||
|
@ -365,23 +363,20 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLastCheck() {
|
private void updateLastCheck() {
|
||||||
if (indexLastCheckItem != -1 && items.size() > 0) {
|
if (itemLastCheck != null) {
|
||||||
((BottomSheetItemWithDescription) items.get(indexLastCheckItem))
|
((BottomSheetItemWithDescription) itemLastCheck).setDescription(getLastCheckString());
|
||||||
.setDescription(getLastCheckString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFrequencyHelpMessage() {
|
private void updateFrequencyHelpMessage() {
|
||||||
if (indexFrequencyHelpMessageItem != -1 && items.size() > 0) {
|
if (itemFrequencyHelpMessage != null) {
|
||||||
((BottomSheetItemWithDescription) items.get(indexFrequencyHelpMessageItem))
|
((BottomSheetItemWithDescription) itemFrequencyHelpMessage).setDescription(getFrequencyHelpMessage());
|
||||||
.setDescription(getFrequencyHelpMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFileSize() {
|
private void updateFileSize() {
|
||||||
if (indexClearItem != -1 && items.size() > 0) {
|
if (itemClear != null) {
|
||||||
((BottomSheetItemWithDescription) items.get(indexClearItem))
|
((BottomSheetItemWithDescription) itemClear).setDescription(getUpdatesSizeStr());
|
||||||
.setDescription(getUpdatesSizeStr());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +408,8 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
CommonPreference<Integer> updateFrequency = preferenceUpdateFrequency(fileName, settings);
|
CommonPreference<Integer> updateFrequency = preferenceUpdateFrequency(fileName, settings);
|
||||||
CommonPreference<Integer> timeOfDayToUpdate = preferenceTimeOfDayToUpdate(fileName, settings);
|
CommonPreference<Integer> timeOfDayToUpdate = preferenceTimeOfDayToUpdate(fileName, settings);
|
||||||
final long lastUpdate = preferenceLatestUpdateAvailable(fileName, settings).get();
|
final long lastUpdate = preferenceLatestUpdateAvailable(fileName, settings).get();
|
||||||
return formatHelpDateTime(app, UpdateFrequency.values()[updateFrequency.get()], TimeOfDay.values()[timeOfDayToUpdate.get()], lastUpdate);
|
return formatHelpDateTime(app, UpdateFrequency.values()[updateFrequency.get()],
|
||||||
|
TimeOfDay.values()[timeOfDayToUpdate.get()], lastUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getUpdatesSize() {
|
private long getUpdatesSize() {
|
||||||
|
@ -458,7 +454,8 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnRadioItemClickListener getFrequencyButtonListener(@NonNull final UpdateFrequency type, final View... timeOfDayLayouts) {
|
private OnRadioItemClickListener getFrequencyButtonListener(
|
||||||
|
@NonNull final UpdateFrequency type, final View... timeOfDayLayouts) {
|
||||||
return new OnRadioItemClickListener() {
|
return new OnRadioItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onRadioItemClick(RadioItem radioItem, View view) {
|
public boolean onRadioItemClick(RadioItem radioItem, View view) {
|
||||||
|
@ -543,5 +540,4 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
protected int getDismissButtonTextId() {
|
protected int getDismissButtonTextId() {
|
||||||
return R.string.shared_string_close;
|
return R.string.shared_string_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,9 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
|
|
||||||
|
private BaseBottomSheetItem itemTitle;
|
||||||
|
private BaseBottomSheetItem itemDescription;
|
||||||
|
|
||||||
private List<LocalIndexInfo> mapsList;
|
private List<LocalIndexInfo> mapsList;
|
||||||
private LiveUpdateListener listener;
|
private LiveUpdateListener listener;
|
||||||
|
|
||||||
|
@ -61,9 +64,6 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseBottomSheetItem itemTitle;
|
|
||||||
BaseBottomSheetItem itemDescription;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
app = getMyApplication();
|
app = getMyApplication();
|
||||||
|
|
Loading…
Reference in a new issue