mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 10:17:56 +00:00
Add a category dropdown in the help fragment.
This commit is contained in:
@@ -6,8 +6,11 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
@@ -32,14 +35,16 @@ import java.util.List;
|
||||
|
||||
public class HelpFragment extends LoggingFragment {
|
||||
|
||||
private EditText problem;
|
||||
private CheckBox includeDebugLogs;
|
||||
private View debugLogInfo;
|
||||
private View faq;
|
||||
private CircularProgressButton next;
|
||||
private View toaster;
|
||||
private List<EmojiImageView> emoji;
|
||||
private HelpViewModel helpViewModel;
|
||||
private EditText problem;
|
||||
private CheckBox includeDebugLogs;
|
||||
private View debugLogInfo;
|
||||
private View faq;
|
||||
private CircularProgressButton next;
|
||||
private View toaster;
|
||||
private List<EmojiImageView> emoji;
|
||||
private HelpViewModel helpViewModel;
|
||||
private Spinner categorySpinner;
|
||||
private ArrayAdapter<CharSequence> categoryAdapter;
|
||||
|
||||
@Override
|
||||
public @Nullable View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -57,7 +62,7 @@ public class HelpFragment extends LoggingFragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__help);
|
||||
((ApplicationPreferencesActivity) requireActivity()).requireSupportActionBar().setTitle(R.string.preferences__help);
|
||||
|
||||
cancelSpinning(next);
|
||||
problem.setEnabled(true);
|
||||
@@ -74,6 +79,7 @@ public class HelpFragment extends LoggingFragment {
|
||||
faq = view.findViewById(R.id.help_fragment_faq);
|
||||
next = view.findViewById(R.id.help_fragment_next);
|
||||
toaster = view.findViewById(R.id.help_fragment_next_toaster);
|
||||
categorySpinner = view.findViewById(R.id.help_fragment_category);
|
||||
emoji = new ArrayList<>(Feeling.values().length);
|
||||
|
||||
for (Feeling feeling : Feeling.values()) {
|
||||
@@ -81,6 +87,11 @@ public class HelpFragment extends LoggingFragment {
|
||||
emojiView.setImageEmoji(feeling.getEmojiCode());
|
||||
emoji.add(view.findViewById(feeling.getViewId()));
|
||||
}
|
||||
|
||||
categoryAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.HelpFragment__categories, android.R.layout.simple_spinner_item);
|
||||
categoryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
|
||||
categorySpinner.setAdapter(categoryAdapter);
|
||||
}
|
||||
|
||||
private void initializeListeners() {
|
||||
@@ -90,6 +101,16 @@ public class HelpFragment extends LoggingFragment {
|
||||
debugLogInfo.setOnClickListener(v -> launchDebugLogInfo());
|
||||
next.setOnClickListener(v -> submitForm());
|
||||
toaster.setOnClickListener(v -> Toast.makeText(requireContext(), R.string.HelpFragment__please_be_as_descriptive_as_possible, Toast.LENGTH_LONG).show());
|
||||
categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
helpViewModel.onCategorySelected(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeObservers() {
|
||||
@@ -144,6 +165,7 @@ public class HelpFragment extends LoggingFragment {
|
||||
.map(view -> Feeling.getByViewId(view.getId()))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
|
||||
CommunicationActions.openEmail(requireContext(),
|
||||
SupportEmailUtil.getSupportEmailAddress(requireContext()),
|
||||
getEmailSubject(),
|
||||
@@ -171,8 +193,11 @@ public class HelpFragment extends LoggingFragment {
|
||||
suffix.append(getString(feeling.getStringId()));
|
||||
}
|
||||
|
||||
String category = categoryAdapter.getItem(helpViewModel.getCategoryIndex()).toString();
|
||||
|
||||
return SupportEmailUtil.generateSupportEmailBody(requireContext(),
|
||||
R.string.HelpFragment__signal_android_support_request,
|
||||
" - " + category,
|
||||
problem.getText().toString() + "\n\n",
|
||||
suffix.toString());
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public class HelpViewModel extends ViewModel {
|
||||
private MutableLiveData<Boolean> problemMeetsLengthRequirements = new MutableLiveData<>();
|
||||
private MutableLiveData<Boolean> hasLines = new MutableLiveData<>(false);
|
||||
private LiveData<Boolean> isFormValid = Transformations.map(new LiveDataPair<>(problemMeetsLengthRequirements, hasLines), this::transformValidationData);
|
||||
private int categoryIndex = 0;
|
||||
|
||||
private final SubmitDebugLogRepository submitDebugLogRepository;
|
||||
|
||||
@@ -43,6 +44,14 @@ public class HelpViewModel extends ViewModel {
|
||||
problemMeetsLengthRequirements.setValue(problem.length() >= MINIMUM_PROBLEM_CHARS);
|
||||
}
|
||||
|
||||
void onCategorySelected(int index) {
|
||||
this.categoryIndex = index;
|
||||
}
|
||||
|
||||
int getCategoryIndex() {
|
||||
return this.categoryIndex;
|
||||
}
|
||||
|
||||
LiveData<SubmitResult> onSubmitClicked(boolean includeDebugLogs) {
|
||||
MutableLiveData<SubmitResult> resultLiveData = new MutableLiveData<>();
|
||||
|
||||
|
||||
@@ -27,21 +27,35 @@ public final class SupportEmailUtil {
|
||||
* Generates a support email body with system info near the top.
|
||||
*/
|
||||
public static @NonNull String generateSupportEmailBody(@NonNull Context context,
|
||||
@StringRes int subject,
|
||||
@StringRes int filter,
|
||||
@Nullable String prefix,
|
||||
@Nullable String suffix)
|
||||
{
|
||||
prefix = Util.firstNonNull(prefix, "");
|
||||
suffix = Util.firstNonNull(suffix, "");
|
||||
return String.format("%s\n%s\n%s", prefix, buildSystemInfo(context, subject), suffix);
|
||||
return generateSupportEmailBody(context, filter, null, prefix, suffix);
|
||||
}
|
||||
|
||||
private static @NonNull String buildSystemInfo(@NonNull Context context, @StringRes int subject) {
|
||||
/**
|
||||
* Generates a support email body with system info near the top.
|
||||
*/
|
||||
public static @NonNull String generateSupportEmailBody(@NonNull Context context,
|
||||
@StringRes int filter,
|
||||
@Nullable String filterSuffix,
|
||||
@Nullable String prefix,
|
||||
@Nullable String suffix)
|
||||
{
|
||||
filterSuffix = Util.emptyIfNull(filterSuffix);
|
||||
prefix = Util.emptyIfNull(prefix);
|
||||
suffix = Util.emptyIfNull(suffix);
|
||||
|
||||
return String.format("%s\n%s\n%s", prefix, buildSystemInfo(context, filter, filterSuffix), suffix);
|
||||
}
|
||||
|
||||
private static @NonNull String buildSystemInfo(@NonNull Context context, @StringRes int filter, @NonNull String filterSuffix) {
|
||||
Resources englishResources = ResourceUtil.getEnglishResources(context);
|
||||
|
||||
return "--- " + context.getString(R.string.HelpFragment__support_info) + " ---" +
|
||||
"\n" +
|
||||
context.getString(R.string.SupportEmailUtil_filter) + " " + englishResources.getString(subject) +
|
||||
context.getString(R.string.SupportEmailUtil_filter) + " " + englishResources.getString(filter) + filterSuffix +
|
||||
"\n" +
|
||||
context.getString(R.string.SupportEmailUtil_device_info) + " " + getDeviceInfo() +
|
||||
"\n" +
|
||||
|
||||
Reference in New Issue
Block a user