Commit 90263e96 authored by Thomas's avatar Thomas
Browse files

export/import settings

parent 7f28d208
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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()
    }


}
+2 −2
Original line number Diff line number Diff line
@@ -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();

+3 −4
Original line number Diff line number Diff line
@@ -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();
+37 −11
Original line number Diff line number Diff line
@@ -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) {
+1 −4
Original line number Diff line number Diff line
@@ -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"
Loading