-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b444bbf
commit 4a6925d
Showing
9 changed files
with
437 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...oid/java/org/chromium/chrome/browser/settings/developer/BraveRewardsDebugPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* 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.chromium.chrome.browser.settings.developer; | ||
|
||
import android.app.Dialog; | ||
import android.content.DialogInterface; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AlertDialog; | ||
import android.support.v7.preference.Preference; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.BraveRelaunchUtils; | ||
import org.chromium.chrome.browser.settings.BravePreferenceFragment; | ||
import org.chromium.chrome.browser.settings.SettingsUtils; | ||
import org.chromium.chrome.browser.util.BraveDbUtil; | ||
|
||
/** | ||
* Settings fragment containing preferences for QA team. | ||
*/ | ||
public class BraveRewardsDebugPreferences extends BravePreferenceFragment { | ||
private static final String QA_EXPORT_REWARDS_DB = "export_rewards_db"; | ||
|
||
private Preference mExportRewardsDb; | ||
private BraveDbUtil mDbUtil; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
SettingsUtils.addPreferencesFromResource(this, R.xml.brave_rewards_debug_preferences); | ||
|
||
mDbUtil = BraveDbUtil.getInstance(); | ||
mExportRewardsDb = findPreference(QA_EXPORT_REWARDS_DB); | ||
setRewardsDbClickListeners(); | ||
} | ||
|
||
private void setRewardsDbClickListeners() { | ||
if (mExportRewardsDb != null) { | ||
mExportRewardsDb.setOnPreferenceClickListener(preference -> { | ||
if (isStoragePermissionGranted(true)) { | ||
requestRestart(); | ||
} | ||
return true; | ||
}); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
if (STORAGE_PERMISSION_EXPORT_REQUEST_CODE == requestCode) { | ||
requestRestart(); | ||
} | ||
} | ||
} | ||
|
||
private void requestRestart() { | ||
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int button) { | ||
if (button == AlertDialog.BUTTON_POSITIVE) { | ||
mDbUtil.setPerformDbExportOnStart(true); | ||
BraveRelaunchUtils.restart(); | ||
} | ||
} | ||
}; | ||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity(), R.style.Theme_Chromium_AlertDialog) | ||
.setMessage( | ||
"This operation requires restart. Would you like to restart application and start operation?") | ||
.setPositiveButton(R.string.ok, onClickListener).setNegativeButton(R.string.cancel, onClickListener); | ||
Dialog dialog = alertDialog.create(); | ||
dialog.setCanceledOnTouchOutside(false); | ||
dialog.show(); | ||
} | ||
} |
Oops, something went wrong.