Skip to content

[Android] display bookmark export file path #20366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BraveBookmarkBridge extends BookmarkBridge {
// Overridden Chromium's BookmarkBridge.mNativeBookmarkBridge
private long mNativeBookmarkBridge;
private WindowAndroid mWindowAndroid;
private String mExportFilePath;

BraveBookmarkBridge(long nativeBookmarkBridge) {
super(nativeBookmarkBridge);
Expand All @@ -28,7 +29,8 @@ public void bookmarksImported(boolean isSuccess) {
@Override
public void run() {
BraveBookmarkUtils.showBookmarkImportExportDialog(
(AppCompatActivity) mWindowAndroid.getContext().get(), true, isSuccess);
(AppCompatActivity) mWindowAndroid.getContext().get(), true, isSuccess,
null);
}
});
}
Expand All @@ -42,8 +44,8 @@ public void bookmarksExported(boolean isSuccess) {
@Override
public void run() {
BraveBookmarkUtils.showBookmarkImportExportDialog(
(AppCompatActivity) mWindowAndroid.getContext().get(), false,
isSuccess);
(AppCompatActivity) mWindowAndroid.getContext().get(), false, isSuccess,
mExportFilePath);
}
});
}
Expand All @@ -57,6 +59,7 @@ public void importBookmarks(WindowAndroid windowAndroid, String importFilePath)

public void exportBookmarks(WindowAndroid windowAndroid, String exportFilePath) {
mWindowAndroid = windowAndroid;
mExportFilePath = exportFilePath;
BraveBookmarkBridgeJni.get().exportBookmarks(
mNativeBookmarkBridge, BraveBookmarkBridge.this, windowAndroid, exportFilePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
package org.chromium.chrome.browser.bookmarks;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -24,21 +26,26 @@
import org.chromium.chrome.browser.util.TabUtils;
import org.chromium.ui.base.DeviceFormFactor;

import java.io.File;

public class BraveBookmarkImportExportDialogFragment
extends BraveDialogFragment implements View.OnClickListener {
private static final String IS_IMPORT = "is_import";
private static final String IS_SUCCESS = "is_success";
private static final String EXPORT_FILE_PATH = "export_filepath";

private boolean mIsImport;
private boolean mIsSuccess;
private String mExportFilePath;

public static BraveBookmarkImportExportDialogFragment newInstance(
boolean isImport, boolean isSuccess) {
boolean isImport, boolean isSuccess, String exportFilePath) {
final BraveBookmarkImportExportDialogFragment fragment =
new BraveBookmarkImportExportDialogFragment();
final Bundle args = new Bundle();
args.putBoolean(IS_IMPORT, isImport);
args.putBoolean(IS_SUCCESS, isSuccess);
args.putString(EXPORT_FILE_PATH, exportFilePath);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -50,6 +57,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (getArguments() != null) {
mIsImport = getArguments().getBoolean(IS_IMPORT);
mIsSuccess = getArguments().getBoolean(IS_SUCCESS);
mExportFilePath = getArguments().getString(EXPORT_FILE_PATH);
}
}

Expand All @@ -69,20 +77,45 @@ public View onCreateView(
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
ImageView imageView = view.findViewById(R.id.imageView);
TextView tvDesc = view.findViewById(R.id.tv_bookmark_desc);
TextView tvTitle = view.findViewById(R.id.tv_title);
TextView tvDesc = view.findViewById(R.id.tv_desc);

imageView.setImageResource(mIsSuccess ? R.drawable.ic_bookmark_import_export_success
: R.drawable.ic_bookmark_import_export_failed);

if (mIsImport) {
tvDesc.setText(mIsSuccess ? R.string.import_bookmarks_success
: R.string.import_bookmarks_failed);
tvTitle.setText(mIsSuccess ? R.string.import_bookmarks_success_title
: R.string.import_bookmarks_fail_title);
tvDesc.setText(mIsSuccess ? R.string.import_bookmarks_success_body
: R.string.import_bookmarks_fail_body);
} else {
tvDesc.setText(mIsSuccess ? R.string.export_bookmarks_success
: R.string.export_bookmarks_failed);
tvTitle.setText(mIsSuccess ? R.string.export_bookmarks_success_title
: R.string.export_bookmarks_fail_title);
if (mIsSuccess) {
tvDesc.setText(getResources().getString(
R.string.export_bookmarks_success_body, mExportFilePath));
Button openBtn = view.findViewById(R.id.btn_open);
openBtn.setVisibility(View.VISIBLE);
openBtn.setOnClickListener(btn -> {
Activity activity = getActivity();
if (activity != null) {
dismiss();
int pathIndex = mExportFilePath.lastIndexOf(File.separator);
if (pathIndex != -1) {
String path = mExportFilePath.substring(0, pathIndex);
Uri uri = Uri.parse(path);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "*/*");
activity.startActivity(intent);
}
}
});
} else {
tvDesc.setText(R.string.export_bookmarks_fail_body);
}
}
Button okBtn = view.findViewById(R.id.btn_ok);
okBtn.setOnClickListener(this);
Button closeBtn = view.findViewById(R.id.btn_close);
closeBtn.setOnClickListener(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ public static void showBookmarkManagerOnPhone(
}
}

public static void showBookmarkImportExportDialog(
AppCompatActivity appCompatActivity, boolean isImport, boolean isSuccess) {
public static void showBookmarkImportExportDialog(AppCompatActivity appCompatActivity,
boolean isImport, boolean isSuccess, String exportFilePath) {
try {
BraveBookmarkImportExportDialogFragment dialogFragment =
BraveBookmarkImportExportDialogFragment.newInstance(isImport, isSuccess);
BraveBookmarkImportExportDialogFragment.newInstance(
isImport, isSuccess, exportFilePath);
dialogFragment.show(appCompatActivity.getSupportFragmentManager(),
"BraveBookmarkImportExportDialogFragment");
} catch (IllegalStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,76 @@
You can obtain one at https://mozilla.org/MPL/2.0/.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="24dp"
android:paddingVertical="16dp"
android:orientation="vertical"
android:background="@drawable/rounded_bookmark_import_export_dialog_bg">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:tint="@color/bookmark_import_export_dialog_secondary_color"
android:contentDescription="@null"/>

<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/bookmarks"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/imageView"
android:layout_marginTop="10dp"
android:textColor="@color/bookmark_import_export_dialog_title_color"
android:textStyle="bold" />

<TextView
android:id="@+id/tv_bookmark_desc"
android:id="@+id/tv_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/tv_title"
android:layout_marginTop="5dp"
android:textColor="@color/bookmark_import_export_dialog_secondary_color"/>

<android.widget.Button
android:id="@+id/btn_ok"
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/tv_desc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_open"
android:background="@android:color/transparent"
android:text="@string/ok"
android:textAllCaps="false"
android:text="@string/close"
android:textColor="@color/bookmark_import_export_dialog_button_color"
android:textSize="16sp"
android:textStyle="bold"
style="?android:attr/borderlessButtonStyle"/>

</LinearLayout>
<android.widget.Button
android:id="@+id/btn_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@id/tv_desc"
app:layout_constraintStart_toEndOf="@id/btn_close"
app:layout_constraintEnd_toEndOf="parent"
android:background="@android:color/transparent"
android:textAllCaps="false"
android:text="@string/open_folder"
android:textColor="@color/bookmark_import_export_dialog_button_color"
android:textSize="16sp"
android:visibility="gone"
style="?android:attr/borderlessButtonStyle"/>

</androidx.constraintlayout.widget.ConstraintLayout>
29 changes: 22 additions & 7 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1278,17 +1278,32 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
<message name="IDS_IMPORT_BOOKMARKS_SELECT_FILE" desc="Import Bookmarks file chooser text">
Select a File to Import bookmarks
</message>
<message name="IDS_IMPORT_BOOKMARKS_SUCCESS" desc="Import Bookmarks success text message.">
<message name="IDS_EXPORT_BOOKMARKS_SUCCESS_TITLE" desc="Export Bookmarks success title text.">
Export successful
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Export succeeded (to match the opposite Export failed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</message>
<message name="IDS_EXPORT_BOOKMARKS_SUCCESS_BODY" desc="Export Bookmarks success text message.">
Bookmarks exported to <ph name="EXPORT_FILE_PATH">%1$s<ex>/Download/bookmarks.html</ex></ph>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Exported bookmarks to <ph...

</message>
<message name="IDS_EXPORT_BOOKMARKS_FAIL_TITLE" desc="Export Bookmarks fail title text.">
Export failed
</message>
<message name="IDS_EXPORT_BOOKMARKS_FAIL_BODY" desc="Export Bookmarks fail text message.">
Bookmarks export failed. Please try again.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Failed to export bookmarks...

</message>
<message name="IDS_IMPORT_BOOKMARKS_SUCCESS_TITLE" desc="Import Bookmarks success title text.">
Import successful
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Export succeeded

</message>
<message name="IDS_IMPORT_BOOKMARKS_SUCCESS_BODY" desc="Import Bookmarks success text message.">
Bookmarks imported successfully.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Imported bookmarks successfully.

</message>
<message name="IDS_IMPORT_BOOKMARKS_FAILED" desc="Import Bookmarks failed text message.">
Bookmark import failed.
<message name="IDS_IMPORT_BOOKMARKS_FAIL_TITLE" desc="Import Bookmarks fail title text.">
Import failed
</message>
<message name="IDS_EXPORT_BOOKMARKS_FAILED" desc="Export Bookmarks failed text message.">
Bookmark export failed.
<message name="IDS_IMPORT_BOOKMARKS_FAIL_BODY" desc="Import Bookmarks fail text message.">
Bookmark import failed. Please try again.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Failed to import bookmark(s?)...

</message>
<message name="IDS_EXPORT_BOOKMARKS_SUCCESS" desc="Export Bookmarks success text message.">
Bookmarks exported successfully.
<message name="IDS_OPEN_FOLDER" desc="Open folder button text for export bookmarks success.">
Open folder
</message>
<!-- Sync Infobar -->
<message name="IDS_BRAVE_SYNC_V2_MIGRATE_INFOBAR_MESSAGE" desc="Message text shown to users who used a previous version of Brave Sync and need to perform setup again for the new version.">
Expand Down