[WIP]
Bug 1232439 (972193) - Add dialog for selecting folder in which to place new bookmarks folder.
MozReview-Commit-ID: C9ohxgMoZlC
--- a/mobile/android/base/java/org/mozilla/gecko/CreateBookmarkFolderDialog.java
+++ b/mobile/android/base/java/org/mozilla/gecko/CreateBookmarkFolderDialog.java
@@ -4,34 +4,38 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UIAsyncTask;
+import android.app.Activity;
import android.content.ContentResolver;
+import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
+import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
public class CreateBookmarkFolderDialog extends BookmarkToolbarDialog {
// The id and name of the folder in which the new folder will be created.
private int parentFolderId;
private String parentFolderName;
private ViewGroup rootView;
private EditText newFolderNameEdit;
+ private EditText selectParentFolderEdit;
public static CreateBookmarkFolderDialog newInstance(int currentFolderId, String currentFolderName) {
final CreateBookmarkFolderDialog dialog = new CreateBookmarkFolderDialog();
dialog.setDialogFolderArguments(currentFolderId, currentFolderName);
return dialog;
}
@Override
@@ -97,20 +101,48 @@ public class CreateBookmarkFolderDialog
setupToolbar(folderCreateView, R.menu.bookmarks_dialog_menu_save);
final TextInputLayout newFolderNameLayout = (TextInputLayout) folderCreateView.findViewById(R.id.new_folder_name_layout);
newFolderNameEdit = (EditText) folderCreateView.findViewById(R.id.new_folder_name);
final String emptyFolderNameErrorText = getString(R.string.bookmark_add_folder_name_empty_error);
newFolderNameEdit.addTextChangedListener(new EmptyTextWatcher(newFolderNameLayout, emptyFolderNameErrorText));
- final EditText selectParentFolderEdit = (EditText) folderCreateView.findViewById(R.id.select_parent_folder);
- selectParentFolderEdit.setText(parentFolderName);
+ selectParentFolderEdit = (EditText) folderCreateView.findViewById(R.id.select_parent_folder);
+ // The parent folder text is set in onResume (see the note there for explanation).
+
selectParentFolderEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- // TODO: Create new fragment to select the parent folder of the new folder.
+ final SelectFolderForNewBookmarkFolderDialog dialog =
+ SelectFolderForNewBookmarkFolderDialog.newInstance(parentFolderId);
+ dialog.setTargetFragment(CreateBookmarkFolderDialog.this, TARGET_FRAGMENT_CODE_UNUSED);
+ final FragmentTransaction transaction = getFragmentManager().beginTransaction();
+ transaction.replace(android.R.id.content, dialog)
+ .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
+ .addToBackStack(null)
+ .commit();
}
});
return folderCreateView;
}
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode != Activity.RESULT_OK || data == null) {
+ return;
+ }
+
+ parentFolderName = data.getStringExtra(ARG_FOLDER_NAME);
+ parentFolderId = data.getIntExtra(ARG_FOLDER_ID, INVALID_FOLDER_ID);
+ // The EditText displaying the parent folder is updated in onResume.
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ // Updating the folder text after a new folder has been chosen doesn't work in
+ // onActivityResult or onCreateView, so we just always set it here.
+ selectParentFolderEdit.setText(parentFolderName);
+ }
}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/SelectFolderForNewBookmarkFolderDialog.java
@@ -0,0 +1,53 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.annotation.StringRes;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class SelectFolderForNewBookmarkFolderDialog extends BookmarkFolderTreeDialog {
+ private int currentFolderId;
+
+ public static SelectFolderForNewBookmarkFolderDialog newInstance(int currentFolderId) {
+ final SelectFolderForNewBookmarkFolderDialog dialog = new SelectFolderForNewBookmarkFolderDialog();
+ final Bundle args = new Bundle();
+ args.putInt(ARG_FOLDER_ID, currentFolderId);
+ dialog.setArguments(args);
+ return dialog;
+ }
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final Bundle args = getArguments();
+ currentFolderId = args.getInt(ARG_FOLDER_ID);
+ }
+
+ @Override
+ protected @StringRes int toolbarTitle() {
+ return R.string.bookmark_dialog_choose_folder;
+ }
+
+ @Override
+ protected int currentFolderId() {
+ return currentFolderId;
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
+ final View view = inflater.inflate(R.layout.choose_folder_for_new_folder, container, false);
+
+ setupToolbar(view, null);
+ setupFolderTree(view, false);
+ return view;
+ }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -684,16 +684,17 @@ gbjar.sources += ['java/org/mozilla/geck
'restrictions/RestrictedProfileConfiguration.java',
'restrictions/RestrictionCache.java',
'restrictions/RestrictionConfiguration.java',
'restrictions/RestrictionProvider.java',
'restrictions/Restrictions.java',
'ScreenshotObserver.java',
'search/SearchEngine.java',
'search/SearchEngineManager.java',
+ 'SelectFolderForNewBookmarkFolderDialog.java',
'SessionParser.java',
'SharedPreferencesHelper.java',
'SiteIdentity.java',
'SnackbarBuilder.java',
'SuggestClient.java',
'Tab.java',
'tabqueue/TabQueueHelper.java',
'tabqueue/TabQueuePrompt.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/choose_folder_for_new_folder.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@android:color/white"
+ android:theme="@style/GeckoAlertDialog">
+
+ <include layout="@layout/bookmark_dialog_toolbar"/>
+
+ <include layout="@layout/folder_tree_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginTop="18dp"/>
+
+</LinearLayout>