This commit is contained in:
androiddevkotlin 2021-04-19 14:25:53 +03:00
parent 66ba7ff2f6
commit bd1fbe859e
5 changed files with 76 additions and 42 deletions

View file

@ -79,6 +79,21 @@
</LinearLayout> </LinearLayout>
<androidx.appcompat.widget.AppCompatRadioButton
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/title_padding"
android:layout_marginRight="@dimen/title_padding"
android:layout_gravity="center_vertical"
android:scaleType="center"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:visibility="gone"
android:saveEnabled="false"
tools:visibility="visible"/>
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/secondary_icon" android:id="@+id/secondary_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -6,7 +6,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/list_background_color" android:background="?attr/list_background_color"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_cancel_button_height_small" android:minHeight="@dimen/bottom_sheet_list_item_height"
android:orientation="horizontal"> android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView

View file

@ -648,9 +648,8 @@ public class DownloadResources extends DownloadResourceGroup {
public static List<DownloadItem> findIndexItemsAt(OsmandApplication app, String groupTypeVoice) throws IOException { public static List<DownloadItem> findIndexItemsAt(OsmandApplication app, String groupTypeVoice) throws IOException {
DownloadIndexesThread downloadThread = app.getDownloadThread(); DownloadIndexesThread downloadThread = app.getDownloadThread();
DownloadResources indexes = downloadThread.getIndexes(); DownloadResources indexes = downloadThread.getIndexes();
DownloadResourceGroup groupVoice = indexes.getGroupById(groupTypeVoice); DownloadResourceGroup groupVoice = indexes.getSubGroupById(groupTypeVoice);
List<DownloadResourceGroup> groupList = groupVoice.getGroups(); List<DownloadItem> items = groupVoice.getIndividualDownloadItems();
List<DownloadItem> items = groupList.get(0).getIndividualDownloadItems();
return new ArrayList<>(items); return new ArrayList<>(items);
} }

View file

@ -1,9 +1,6 @@
package net.osmand.plus.settings.fragments; package net.osmand.plus.settings.fragments;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -23,21 +20,13 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.bottomsheets.AnnouncementTimeBottomSheet; import net.osmand.plus.settings.bottomsheets.AnnouncementTimeBottomSheet;
import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import java.util.Set;
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
import static net.osmand.plus.settings.backend.OsmandSettings.VOICE_PROVIDER_NOT_USE;
public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPreferenceChanged { public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPreferenceChanged {
@ -204,7 +193,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr
@Override @Override
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
super.onBindPreferenceViewHolder(preference, holder); super.onBindPreferenceViewHolder(preference, holder);
if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) { if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) {
setupPrefRoundedBg(holder); setupPrefRoundedBg(holder);
} }
} }
@ -232,7 +221,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr
@Override @Override
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) { public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) { if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
// Sync DEFAULT value with CAR value, as we have other way to set it for now // Sync DEFAULT value with CAR value, as we have other way to set it for now
if (getSelectedAppMode().equals(ApplicationMode.CAR) && newValue instanceof Integer) { if (getSelectedAppMode().equals(ApplicationMode.CAR) && newValue instanceof Integer) {
@ -251,8 +240,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr
String prefId = preference.getKey(); String prefId = preference.getKey();
if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId)) { if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId)) {
SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this); SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this);
} else if (settings.VOICE_PROVIDER.getId().equals(prefId)) {
VoiceLanguageBottomSheetFragment.showInstance(requireActivity().getSupportFragmentManager(), this);
} }
return super.onPreferenceClick(preference); return super.onPreferenceClick(preference);
} }
@ -260,12 +247,13 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPr
@Override @Override
public void onDisplayPreferenceDialog(Preference preference) { public void onDisplayPreferenceDialog(Preference preference) {
String prefId = preference.getKey(); String prefId = preference.getKey();
if (settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(prefId)) { if (settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) { if (fragmentManager != null) {
AnnouncementTimeBottomSheet.showInstance(fragmentManager, preference.getKey(), this, getSelectedAppMode(), false); AnnouncementTimeBottomSheet.showInstance(fragmentManager, preference.getKey(), this, getSelectedAppMode(), false);
} }
} else if (settings.VOICE_PROVIDER.getId().equals(prefId)) {
VoiceLanguageBottomSheetFragment.showInstance(requireActivity().getSupportFragmentManager(), this, preference.getKey(), false);
} else { } else {
super.onDisplayPreferenceDialog(preference); super.onDisplayPreferenceDialog(preference);
} }

View file

@ -10,6 +10,7 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -17,6 +18,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
@ -24,7 +26,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadItem; import net.osmand.plus.download.DownloadItem;
@ -39,6 +41,8 @@ import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
import net.osmand.plus.widgets.MultiStateToggleButton; import net.osmand.plus.widgets.MultiStateToggleButton;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem; import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
import org.apache.commons.logging.Log;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -47,23 +51,39 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType;
import static net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType.OTHER_GROUP;
import static net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType.VOICE_HEADER_REC;
import static net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType.VOICE_HEADER_TTS;
import static net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet.PREFERENCE_ID;
public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragment implements DownloadIndexesThread.DownloadEvents { public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragment implements DownloadIndexesThread.DownloadEvents {
private static final String TAG = TrackSelectSegmentBottomSheet.class.getSimpleName(); private static final String TAG = TrackSelectSegmentBottomSheet.class.getSimpleName();
private static final String VOICE_REC = "#other_group#voice_rec"; private static final String VOICE_REC = OTHER_GROUP.getDefaultId() + "#" + DownloadResourceGroupType.VOICE_TTS.getDefaultId() + "#" + VOICE_HEADER_TTS.getDefaultId();
private static final String VOICE_TTS = "#other_group#voice_tts"; private static final String VOICE_TTS = OTHER_GROUP.getDefaultId() + "#" + DownloadResourceGroupType.VOICE_REC.getDefaultId() + "#" + VOICE_HEADER_REC.getDefaultId();
private static final int DEFAULT_LANGUAGE_POSITION = 6; private static final int DEFAULT_LANGUAGE_POSITION = 6;
private static final Log LOG = PlatformUtil.getLog(VoiceLanguageBottomSheetFragment.class);
protected OsmandSettings settings; protected OsmandSettings settings;
private OsmandApplication app; private OsmandApplication app;
private Context context; private Context context;
private Context themedCtx;
private InfoType selectedVoiceType = InfoType.TTS; private InfoType selectedVoiceType = InfoType.TTS;
private boolean isTtsDescription; private boolean isTtsDescription;
private int padding; private int padding;
public static void showInstance(@NonNull FragmentManager fm, Fragment targetFragment) { public static void showInstance(@NonNull FragmentManager fm, Fragment targetFragment, String key, boolean usedOnMap) {
VoiceLanguageBottomSheetFragment fragment = new VoiceLanguageBottomSheetFragment(); try {
fragment.setTargetFragment(targetFragment, 0); if (!fm.isStateSaved()) {
fragment.show(fm, TAG); Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key);
VoiceLanguageBottomSheetFragment fragment = new VoiceLanguageBottomSheetFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap);
fragment.setTargetFragment(targetFragment, 0);
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
} }
@Override @Override
@ -73,7 +93,6 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
private void updateItems() { private void updateItems() {
Activity activity = getActivity(); Activity activity = getActivity();
themedCtx = UiUtilities.getThemedContext(activity, nightMode);
View mainView = getView(); View mainView = getView();
if (activity != null && mainView != null) { if (activity != null && mainView != null) {
LinearLayout itemsContainer = (LinearLayout) mainView.findViewById(useScrollableItemsContainer() LinearLayout itemsContainer = (LinearLayout) mainView.findViewById(useScrollableItemsContainer()
@ -84,7 +103,7 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
items.clear(); items.clear();
createMenuItems(null); createMenuItems(null);
for (BaseBottomSheetItem item : items) { for (BaseBottomSheetItem item : items) {
item.inflate(themedCtx, itemsContainer, nightMode); item.inflate(context, itemsContainer, nightMode);
} }
setupHeightAndBackground(mainView); setupHeightAndBackground(mainView);
} }
@ -126,7 +145,6 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
createVoiceView();
} }
@Override @Override
@ -137,11 +155,9 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
context = requireContext(); context = requireContext();
themedCtx = UiUtilities.getThemedContext(app, nightMode);
settings = app.getSettings(); settings = app.getSettings();
padding = getResources().getDimensionPixelSize(R.dimen.content_padding_small); padding = getDimen(R.dimen.content_padding_small);
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder() BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder()
@ -151,7 +167,7 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
.create(); .create();
items.add(titleItem); items.add(titleItem);
items.add(new DividerSpaceItem(themedCtx, padding)); items.add(new DividerSpaceItem(context, padding));
LinearLayout voiceTypeButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null); LinearLayout voiceTypeButtons = (LinearLayout) inflater.inflate(R.layout.custom_radio_buttons, null);
LinearLayout.MarginLayoutParams itemTimeOfDayParams = new LinearLayout.MarginLayoutParams( LinearLayout.MarginLayoutParams itemTimeOfDayParams = new LinearLayout.MarginLayoutParams(
@ -209,24 +225,23 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
private void createSuggestedVoiceItems(List<DownloadItem> suggestedMaps) { private void createSuggestedVoiceItems(List<DownloadItem> suggestedMaps) {
final OsmandApplication app = requiredMyApplication(); final OsmandApplication app = requiredMyApplication();
themedCtx = UiUtilities.getThemedContext(app, nightMode);
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
final ApplicationMode applicationMode = routingHelper.getAppMode(); final ApplicationMode applicationMode = routingHelper.getAppMode();
items.add(new DividerSpaceItem(themedCtx, padding)); items.add(new DividerSpaceItem(context, padding));
BaseBottomSheetItem switchStartAndEndItem = new BottomSheetItemWithDescription.Builder() BaseBottomSheetItem switchStartAndEndItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(isTtsDescription ? R.string.tts_description : R.string.recorded_description)) .setDescription(getString(isTtsDescription ? R.string.tts_description : R.string.recorded_description))
.setLayoutId(R.layout.bottom_sheet_item_description_long) .setLayoutId(R.layout.bottom_sheet_item_description_long)
.create(); .create();
items.add(switchStartAndEndItem); items.add(switchStartAndEndItem);
items.add(new DividerHalfItem(themedCtx)); items.add(createDividerItem());
final DownloadIndexesThread downloadThread = app.getDownloadThread(); final DownloadIndexesThread downloadThread = app.getDownloadThread();
for (final DownloadItem indexItem : suggestedMaps) { for (final DownloadItem indexItem : suggestedMaps) {
View view = UiUtilities.getInflater(themedCtx, nightMode).inflate(R.layout.list_item_icon_and_download, null); View view = UiUtilities.getInflater(context, nightMode).inflate(R.layout.list_item_icon_and_download, null);
AndroidUtils.setBackground(view, UiUtilities.getSelectableDrawable(themedCtx)); AndroidUtils.setBackground(view, UiUtilities.getSelectableDrawable(context));
view.findViewById(R.id.divider).setVisibility(View.GONE); view.findViewById(R.id.divider).setVisibility(View.GONE);
String systemLanguage = Locale.getDefault().getLanguage(); String systemLanguage = Locale.getDefault().getLanguage();
@ -239,10 +254,12 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
final ImageView secondaryIcon = view.findViewById(R.id.secondary_icon); final ImageView secondaryIcon = view.findViewById(R.id.secondary_icon);
int color = ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light); int color = ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light);
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
secondaryIcon.setColorFilter(color, android.graphics.PorterDuff.Mode.MULTIPLY); secondaryIcon.setColorFilter(color, android.graphics.PorterDuff.Mode.MULTIPLY);
final ProgressBar progressBar = view.findViewById(R.id.ProgressBar); final ProgressBar progressBar = view.findViewById(R.id.ProgressBar);
final TextView textDescription = view.findViewById(R.id.description); final TextView textDescription = view.findViewById(R.id.description);
final TextView compoundButton = view.findViewById(R.id.compound_button);
AndroidUiHelper.updateVisibility(secondaryIcon, true); AndroidUiHelper.updateVisibility(secondaryIcon, true);
AndroidUiHelper.updateVisibility(progressBar, downloadThread.isDownloading((IndexItem) indexItem)); AndroidUiHelper.updateVisibility(progressBar, downloadThread.isDownloading((IndexItem) indexItem));
@ -257,14 +274,16 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
} }
if (indexItem.isDownloaded()) { if (indexItem.isDownloaded()) {
AndroidUiHelper.updateVisibility(compoundButton, true);
AndroidUiHelper.updateVisibility(secondaryIcon, false);
final BottomSheetItemWithCompoundButton[] voiceDownloadedItem = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] voiceDownloadedItem = new BottomSheetItemWithCompoundButton[1];
voiceDownloadedItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() voiceDownloadedItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(activeColorResId)
.setChecked(settings.VOICE_PROVIDER.getModeValue(applicationMode).contains(indexItem.getBasename())) .setChecked(settings.VOICE_PROVIDER.getModeValue(applicationMode).contains(indexItem.getBasename()))
.setDescription(description) .setDescription(description)
.setIconHidden(true) .setIconHidden(true)
.setTitle(title) .setTitle(title)
.setPosition(position) .setPosition(position)
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_radio_btn)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -274,6 +293,7 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
updateItems(); updateItems();
} }
}) })
.setCustomView(view)
.create(); .create();
items.add(voiceDownloadedItem[0]); items.add(voiceDownloadedItem[0]);
} else { } else {
@ -306,6 +326,18 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
} }
} }
public int getDimen(@DimenRes int id) {
return getResources().getDimensionPixelSize(id);
}
private BaseBottomSheetItem createDividerItem() {
DividerItem dividerItem = new DividerItem(app);
int start = getDimen(R.dimen.content_padding);
int vertical = getDimen(R.dimen.content_padding_small_half);
dividerItem.setMargins(start, vertical, 0, vertical);
return dividerItem;
}
public List<DownloadItem> getVoiceList(String type) { public List<DownloadItem> getVoiceList(String type) {
List<DownloadItem> suggestedVoice = new ArrayList<>(); List<DownloadItem> suggestedVoice = new ArrayList<>();
@ -329,7 +361,7 @@ public class VoiceLanguageBottomSheetFragment extends MenuBottomSheetDialogFragm
try { try {
return DownloadResources.findIndexItemsAt(app, type); return DownloadResources.findIndexItemsAt(app, type);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error(e);
} }
return Collections.emptyList(); return Collections.emptyList();
} }