export/import settings
This commit is contained in:
parent
7f28d208a3
commit
90263e96b8
|
@ -41,8 +41,11 @@ class SettingsActivity : BaseActivity() {
|
|||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
}
|
||||
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
val navController = findNavController(R.id.fragment_container)
|
||||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1483,7 +1483,7 @@ public class Helper {
|
|||
message = message.substring(0, 499) + "…";
|
||||
}
|
||||
}*/
|
||||
notificationBuilder.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
||||
notificationBuilder.setGroup(account.mastodon_account != null ? account.mastodon_account.acct : "" + "@" + account.instance)
|
||||
.setContentIntent(pIntent)
|
||||
.setContentText(message);
|
||||
int ledColour = Color.BLUE;
|
||||
|
@ -1558,7 +1558,7 @@ public class Helper {
|
|||
.setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
|
||||
.setGroup(account.mastodon_account.acct + "@" + account.instance)
|
||||
.setGroup(account.mastodon_account != null ? account.mastodon_account.acct : "" + "@" + account.instance)
|
||||
.setGroupSummary(true)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.os.Environment;
|
|||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@ -55,7 +54,7 @@ public class SettingsStorage {
|
|||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
output.writeObject(sharedpreferences.getAll());
|
||||
res = true;
|
||||
String message = context.getString(R.string.data_export_theme_success);
|
||||
String message = context.getString(R.string.data_export_settings_success);
|
||||
Intent intentOpen = new Intent();
|
||||
intentOpen.setAction(android.content.Intent.ACTION_VIEW);
|
||||
Uri uri = Uri.parse("file://" + fullPath);
|
||||
|
@ -80,11 +79,11 @@ public class SettingsStorage {
|
|||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@SuppressWarnings({"unchecked", "UnnecessaryUnboxing"})
|
||||
public static boolean loadSharedPreferencesFromFile(Context context, File src) {
|
||||
public static boolean loadSharedPreferencesFromFile(Context context, Uri srcUri) {
|
||||
boolean res = false;
|
||||
ObjectInputStream input = null;
|
||||
try {
|
||||
input = new ObjectInputStream(new FileInputStream(src));
|
||||
input = new ObjectInputStream(context.getContentResolver().openInputStream(srcUri));
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor prefEdit = sharedpreferences.edit();
|
||||
prefEdit.clear();
|
||||
|
|
|
@ -15,6 +15,8 @@ package app.fedilab.android.ui.fragment.settings
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
|
@ -25,17 +27,21 @@ import androidx.preference.PreferenceFragmentCompat
|
|||
import app.fedilab.android.BaseMainActivity.currentAccount
|
||||
import app.fedilab.android.R
|
||||
import app.fedilab.android.helper.SettingsStorage
|
||||
import es.dmoral.toasty.Toasty
|
||||
|
||||
|
||||
class FragmentSettingsCategories : PreferenceFragmentCompat() {
|
||||
|
||||
private val REQUEST_CODE = 5412
|
||||
private val PICKUP_FILE = 452
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.pref_categories, rootKey)
|
||||
|
||||
findPreference<Preference>(getString(R.string.pref_category_key_account))?.setOnPreferenceClickListener {
|
||||
|
||||
findNavController().navigate(FragmentSettingsCategoriesDirections.categoriesToAccount())
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
|
@ -68,9 +74,7 @@ class FragmentSettingsCategories : PreferenceFragmentCompat() {
|
|||
findNavController().navigate(FragmentSettingsCategoriesDirections.categoriesToTheming())
|
||||
false
|
||||
}
|
||||
|
||||
findPreference<Preference>(getString(R.string.pref_export_settings))?.setOnPreferenceClickListener {
|
||||
val permissionLauncher = registerForActivityResult(
|
||||
@Suppress("DEPRECATION") val permissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
if (isGranted) {
|
||||
|
@ -79,12 +83,22 @@ class FragmentSettingsCategories : PreferenceFragmentCompat() {
|
|||
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
findPreference<Preference>(getString(R.string.pref_export_settings))?.setOnPreferenceClickListener {
|
||||
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
false
|
||||
}
|
||||
|
||||
findPreference<Preference>(getString(R.string.pref_import_settings))?.setOnPreferenceClickListener {
|
||||
val openFileIntent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
openFileIntent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
openFileIntent.type = "text/plain"
|
||||
val mimeTypes = arrayOf("text/plain")
|
||||
openFileIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
|
||||
|
||||
startActivityForResult(
|
||||
Intent.createChooser(
|
||||
openFileIntent,
|
||||
getString(R.string.load_settings)), PICKUP_FILE)
|
||||
false
|
||||
}
|
||||
|
||||
|
@ -98,6 +112,18 @@ class FragmentSettingsCategories : PreferenceFragmentCompat() {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == PICKUP_FILE) {
|
||||
val result = SettingsStorage.loadSharedPreferencesFromFile(context, data?.data)
|
||||
if (result) {
|
||||
activity?.let { Toasty.success(it, getString(R.string.data_import_settings_success), Toasty.LENGTH_LONG).show() }
|
||||
} else {
|
||||
activity?.let { Toasty.error(it, getString(R.string.toast_error), Toasty.LENGTH_LONG).show() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
when (requestCode) {
|
||||
|
|
|
@ -12,10 +12,7 @@
|
|||
<action
|
||||
android:id="@+id/categories_to_account"
|
||||
app:destination="@id/EditProfileActivity"
|
||||
app:enterAnim="@anim/enter"
|
||||
app:exitAnim="@anim/exit"
|
||||
app:popEnterAnim="@anim/pop_enter"
|
||||
app:popExitAnim="@anim/pop_exit" />
|
||||
/>
|
||||
|
||||
<action
|
||||
android:id="@+id/categories_to_timelines"
|
||||
|
|
|
@ -618,6 +618,8 @@
|
|||
<string name="data_export_theme">The theme was exported</string>
|
||||
<string name="data_export_settings">The settings were exported</string>
|
||||
<string name="data_export_theme_success">The theme has been successfully exported in CSV</string>
|
||||
<string name="data_export_settings_success">Settings have been successfully exported</string>
|
||||
<string name="data_import_settings_success">Settings have been successfully imported</string>
|
||||
<string name="import_theme">Import a theme</string>
|
||||
<string name="import_theme_title">Tap here to import a theme from a previous export</string>
|
||||
<string name="export_theme">Export the theme</string>
|
||||
|
@ -1435,4 +1437,5 @@
|
|||
<string name="export_settings">Export settings</string>
|
||||
<string name="import_settings">Import settings</string>
|
||||
<string name="permission_missing">Permission not granted!</string>
|
||||
<string name="load_settings">Load exported settings</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue