Use of ViewBinding in AddFeedFragment (#4647)
This commit is contained in:
parent
97a2af06d0
commit
5982ee07b4
|
@ -75,8 +75,8 @@ public class MainActivityTest {
|
|||
final Feed feed = uiTestUtils.hostedFeeds.get(0);
|
||||
openNavDrawer();
|
||||
onView(withText(R.string.add_feed_label)).perform(click());
|
||||
onView(withId(R.id.btn_add_via_url)).perform(scrollTo(), click());
|
||||
onView(withId(R.id.text)).perform(replaceText(feed.getDownload_url()));
|
||||
onView(withId(R.id.addViaUrlButton)).perform(scrollTo(), click());
|
||||
onView(withId(R.id.urlEditText)).perform(replaceText(feed.getDownload_url()));
|
||||
onView(withText(R.string.confirm_label)).perform(scrollTo(), click());
|
||||
Espresso.closeSoftKeyboard();
|
||||
onView(withText(R.string.subscribe_label)).perform(click());
|
||||
|
|
|
@ -11,6 +11,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.databinding.EditTextDialogBinding;
|
||||
|
||||
public class RenameFeedDialog {
|
||||
|
||||
|
@ -29,13 +30,14 @@ public class RenameFeedDialog {
|
|||
}
|
||||
|
||||
View content = View.inflate(activity, R.layout.edit_text_dialog, null);
|
||||
EditText editText = content.findViewById(R.id.text);
|
||||
editText.setText(feed.getTitle());
|
||||
EditTextDialogBinding alertViewBinding = EditTextDialogBinding.bind(content);
|
||||
|
||||
alertViewBinding.urlEditText.setText(feed.getTitle());
|
||||
AlertDialog dialog = new AlertDialog.Builder(activity)
|
||||
.setView(content)
|
||||
.setTitle(de.danoeh.antennapod.core.R.string.rename_feed_label)
|
||||
.setPositiveButton(android.R.string.ok, (d, input) -> {
|
||||
feed.setCustomTitle(editText.getText().toString());
|
||||
feed.setCustomTitle(alertViewBinding.urlEditText.getText().toString());
|
||||
DBWriter.setFeedCustomTitle(feed);
|
||||
})
|
||||
.setNeutralButton(de.danoeh.antennapod.core.R.string.reset, null)
|
||||
|
@ -44,7 +46,7 @@ public class RenameFeedDialog {
|
|||
|
||||
// To prevent cancelling the dialog on button click
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(
|
||||
(view) -> editText.setText(feed.getFeedTitle()));
|
||||
(view) -> alertViewBinding.urlEditText.setText(feed.getFeedTitle()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ import de.danoeh.antennapod.core.feed.Feed;
|
|||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||
import de.danoeh.antennapod.core.util.SortOrder;
|
||||
import de.danoeh.antennapod.databinding.AddfeedBinding;
|
||||
import de.danoeh.antennapod.databinding.EditTextDialogBinding;
|
||||
import de.danoeh.antennapod.discovery.CombinedSearcher;
|
||||
import de.danoeh.antennapod.discovery.FyydPodcastSearcher;
|
||||
import de.danoeh.antennapod.discovery.ItunesPodcastSearcher;
|
||||
|
@ -50,7 +52,6 @@ public class AddFeedFragment extends Fragment {
|
|||
private static final int REQUEST_CODE_CHOOSE_OPML_IMPORT_PATH = 1;
|
||||
private static final int REQUEST_CODE_ADD_LOCAL_FOLDER = 2;
|
||||
|
||||
private EditText combinedFeedSearchBox;
|
||||
private MainActivity activity;
|
||||
|
||||
@Override
|
||||
|
@ -59,29 +60,31 @@ public class AddFeedFragment extends Fragment {
|
|||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
View root = inflater.inflate(R.layout.addfeed, container, false);
|
||||
AddfeedBinding viewBinding = AddfeedBinding.inflate(getLayoutInflater());
|
||||
activity = (MainActivity) getActivity();
|
||||
Toolbar toolbar = root.findViewById(R.id.toolbar);
|
||||
|
||||
Toolbar toolbar = viewBinding.toolbar;
|
||||
((MainActivity) getActivity()).setupToolbarToggle(toolbar);
|
||||
|
||||
root.findViewById(R.id.btn_search_itunes).setOnClickListener(v
|
||||
viewBinding.searchItunesButton.setOnClickListener(v
|
||||
-> activity.loadChildFragment(OnlineSearchFragment.newInstance(ItunesPodcastSearcher.class)));
|
||||
root.findViewById(R.id.btn_search_fyyd).setOnClickListener(v
|
||||
viewBinding.searchFyydButton.setOnClickListener(v
|
||||
-> activity.loadChildFragment(OnlineSearchFragment.newInstance(FyydPodcastSearcher.class)));
|
||||
root.findViewById(R.id.btn_search_gpodder).setOnClickListener(v
|
||||
viewBinding.searchGPodderButton.setOnClickListener(v
|
||||
-> activity.loadChildFragment(new GpodnetMainFragment()));
|
||||
root.findViewById(R.id.btn_search_podcastindex).setOnClickListener(v
|
||||
viewBinding.searchPodcastIndexButton.setOnClickListener(v
|
||||
-> activity.loadChildFragment(OnlineSearchFragment.newInstance(PodcastIndexPodcastSearcher.class)));
|
||||
|
||||
combinedFeedSearchBox = root.findViewById(R.id.combinedFeedSearchBox);
|
||||
combinedFeedSearchBox.setOnEditorActionListener((v, actionId, event) -> {
|
||||
performSearch();
|
||||
viewBinding.combinedFeedSearchEditText.setOnEditorActionListener((v, actionId, event) -> {
|
||||
String query = viewBinding.combinedFeedSearchEditText.getText().toString();
|
||||
performSearch(query);
|
||||
return true;
|
||||
});
|
||||
root.findViewById(R.id.btn_add_via_url).setOnClickListener(v
|
||||
|
||||
viewBinding.addViaUrlButton.setOnClickListener(v
|
||||
-> showAddViaUrlDialog());
|
||||
|
||||
root.findViewById(R.id.btn_opml_import).setOnClickListener(v -> {
|
||||
viewBinding.opmlImportButton.setOnClickListener(v -> {
|
||||
try {
|
||||
Intent intentGetContentAction = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intentGetContentAction.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
@ -93,7 +96,8 @@ public class AddFeedFragment extends Fragment {
|
|||
.showSnackbarAbovePlayer(R.string.unable_to_start_system_file_manager, Snackbar.LENGTH_LONG);
|
||||
}
|
||||
});
|
||||
root.findViewById(R.id.btn_add_local_folder).setOnClickListener(v -> {
|
||||
|
||||
viewBinding.addLocalFolderButton.setOnClickListener(v -> {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
return;
|
||||
}
|
||||
|
@ -108,25 +112,30 @@ public class AddFeedFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
root.findViewById(R.id.btn_add_local_folder).setVisibility(View.GONE);
|
||||
viewBinding.addLocalFolderButton.setVisibility(View.GONE);
|
||||
}
|
||||
root.findViewById(R.id.search_icon).setOnClickListener(view -> performSearch());
|
||||
return root;
|
||||
|
||||
String query = viewBinding.combinedFeedSearchEditText.getText().toString();
|
||||
viewBinding.searchButton.setOnClickListener(view -> performSearch(query));
|
||||
|
||||
return viewBinding.getRoot();
|
||||
}
|
||||
|
||||
private void showAddViaUrlDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(R.string.add_podcast_by_url);
|
||||
View content = View.inflate(getContext(), R.layout.edit_text_dialog, null);
|
||||
EditText editText = content.findViewById(R.id.text);
|
||||
editText.setHint(R.string.add_podcast_by_url_hint);
|
||||
EditTextDialogBinding alertViewBinding = EditTextDialogBinding.bind(content);
|
||||
alertViewBinding.urlEditText.setHint(R.string.add_podcast_by_url_hint);
|
||||
|
||||
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
String clipboardContent = clipboard.getText() != null ? clipboard.getText().toString() : "";
|
||||
if (clipboardContent.trim().startsWith("http")) {
|
||||
editText.setText(clipboardContent.trim());
|
||||
alertViewBinding.urlEditText.setText(clipboardContent.trim());
|
||||
}
|
||||
builder.setView(content);
|
||||
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> addUrl(editText.getText().toString()));
|
||||
builder.setView(alertViewBinding.getRoot());
|
||||
builder.setPositiveButton(R.string.confirm_label,
|
||||
(dialog, which) -> addUrl(alertViewBinding.urlEditText.getText().toString()));
|
||||
builder.setNegativeButton(R.string.cancel_label, null);
|
||||
builder.show();
|
||||
}
|
||||
|
@ -137,8 +146,7 @@ public class AddFeedFragment extends Fragment {
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void performSearch() {
|
||||
String query = combinedFeedSearchBox.getText().toString();
|
||||
private void performSearch(String query) {
|
||||
|
||||
if (query.matches("http[s]?://.*")) {
|
||||
addUrl(query);
|
||||
|
|
|
@ -35,11 +35,11 @@
|
|||
android:layout_marginRight="8dp"
|
||||
android:contentDescription="@string/search_podcast_hint"
|
||||
app:srcCompat="?attr/action_search"
|
||||
android:id="@+id/search_icon"
|
||||
android:id="@+id/searchButton"
|
||||
android:scaleType="center"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/combinedFeedSearchBox"
|
||||
android:id="@+id/combinedFeedSearchEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
@ -87,7 +87,7 @@
|
|||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_add_via_url"
|
||||
android:id="@+id/addViaUrlButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/feed"
|
||||
|
@ -96,7 +96,7 @@
|
|||
android:text="@string/add_podcast_by_url"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_add_local_folder"
|
||||
android:id="@+id/addLocalFolderButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/ic_folder"
|
||||
|
@ -105,7 +105,7 @@
|
|||
android:text="@string/add_local_folder"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_search_itunes"
|
||||
android:id="@+id/searchItunesButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/action_search"
|
||||
|
@ -114,7 +114,7 @@
|
|||
android:text="@string/search_itunes_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_search_fyyd"
|
||||
android:id="@+id/searchFyydButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/action_search"
|
||||
|
@ -123,7 +123,7 @@
|
|||
android:text="@string/search_fyyd_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_search_gpodder"
|
||||
android:id="@+id/searchGPodderButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/action_search"
|
||||
|
@ -132,7 +132,7 @@
|
|||
android:text="@string/browse_gpoddernet_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_search_podcastindex"
|
||||
android:id="@+id/searchPodcastIndexButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/action_search"
|
||||
|
@ -141,7 +141,7 @@
|
|||
android:text="@string/search_podcastindex_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_opml_import"
|
||||
android:id="@+id/opmlImportButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="?attr/av_download"
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:ems="10"
|
||||
android:id="@+id/text" />
|
||||
android:id="@+id/urlEditText" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue