Store theme in a csv file
This commit is contained in:
parent
cdb18f0870
commit
8b32f9c19b
|
@ -95,7 +95,7 @@ public class MainApplication extends MultiDexApplication {
|
||||||
int primary = prefs.getInt("theme_primary", -1);
|
int primary = prefs.getInt("theme_primary", -1);
|
||||||
int pref_color_background = prefs.getInt("pref_color_background", -1);
|
int pref_color_background = prefs.getInt("pref_color_background", -1);
|
||||||
boolean pref_color_navigation_bar = prefs.getBoolean("pref_color_navigation_bar", true);
|
boolean pref_color_navigation_bar = prefs.getBoolean("pref_color_navigation_bar", true);
|
||||||
|
boolean pref_color_status_bar = prefs.getBoolean("pref_color_status_bar", true);
|
||||||
Cyanea.Editor editor = Cyanea.getInstance().edit();
|
Cyanea.Editor editor = Cyanea.getInstance().edit();
|
||||||
if( primary != -1 ) {
|
if( primary != -1 ) {
|
||||||
editor.primary(primary);
|
editor.primary(primary);
|
||||||
|
@ -109,7 +109,7 @@ public class MainApplication extends MultiDexApplication {
|
||||||
.backgroundLight(pref_color_background)
|
.backgroundLight(pref_color_background)
|
||||||
.backgroundDark(pref_color_background).apply();
|
.backgroundDark(pref_color_background).apply();
|
||||||
}
|
}
|
||||||
|
editor.shouldTintStatusBar(pref_color_status_bar).apply();
|
||||||
editor.shouldTintNavBar(pref_color_navigation_bar).apply();
|
editor.shouldTintNavBar(pref_color_navigation_bar).apply();
|
||||||
|
|
||||||
ApplicationJob.cancelAllJob(BackupStatusesSyncJob.BACKUP_SYNC);
|
ApplicationJob.cancelAllJob(BackupStatusesSyncJob.BACKUP_SYNC);
|
||||||
|
|
|
@ -2,9 +2,16 @@ package app.fedilab.android.fragments;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
@ -19,13 +26,24 @@ import com.jaredrummler.cyanea.Cyanea;
|
||||||
import com.jaredrummler.cyanea.prefs.CyaneaTheme;
|
import com.jaredrummler.cyanea.prefs.CyaneaTheme;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.SettingsActivity;
|
import app.fedilab.android.activities.SettingsActivity;
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
|
|
||||||
public class ColorSettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class ColorSettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
@ -35,12 +53,7 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle bundle, String s) {
|
public void onCreatePreferences(Bundle bundle, String s) {
|
||||||
addPreferencesFromResource(R.xml.fragment_settings_color);
|
addPreferencesFromResource(R.xml.fragment_settings_color);
|
||||||
|
|
||||||
|
|
||||||
createPref();
|
createPref();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +77,40 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
|
||||||
SettingsActivity.needRestart = true;
|
SettingsActivity.needRestart = true;
|
||||||
|
|
||||||
if (key.equals("use_custom_theme")) {
|
if (key.equals("use_custom_theme")) {
|
||||||
|
if( !sharedPreferences.getBoolean("use_custom_theme", false)){
|
||||||
|
|
||||||
|
FragmentActivity context = getActivity();
|
||||||
|
assert context != null;
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
|
||||||
|
dialogBuilder.setMessage(R.string.reset_color);
|
||||||
|
dialogBuilder.setPositiveButton(R.string.disable, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
reset();
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogBuilder.setNegativeButton(R.string.store_before, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
|
||||||
|
exportColors();
|
||||||
|
reset();
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogBuilder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putBoolean("use_custom_theme", true);
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
|
alertDialog.setCancelable(false);
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
createPref();
|
createPref();
|
||||||
}
|
}
|
||||||
if( key.compareTo("pref_theme_picker") == 0){
|
if( key.compareTo("pref_theme_picker") == 0){
|
||||||
|
@ -105,6 +152,7 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
|
||||||
Preference theme_primary = findPreference("theme_primary");
|
Preference theme_primary = findPreference("theme_primary");
|
||||||
Preference theme_accent = findPreference("theme_accent");
|
Preference theme_accent = findPreference("theme_accent");
|
||||||
Preference pref_color_navigation_bar = findPreference("pref_color_navigation_bar");
|
Preference pref_color_navigation_bar = findPreference("pref_color_navigation_bar");
|
||||||
|
Preference pref_color_status_bar = findPreference("pref_color_status_bar");
|
||||||
Preference pref_color_background = findPreference("pref_color_background");
|
Preference pref_color_background = findPreference("pref_color_background");
|
||||||
Preference reset_pref = findPreference("reset_pref");
|
Preference reset_pref = findPreference("reset_pref");
|
||||||
if( !sharedpreferences.getBoolean("use_custom_theme", false)){
|
if( !sharedpreferences.getBoolean("use_custom_theme", false)){
|
||||||
|
@ -116,6 +164,7 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
|
||||||
preferenceScreen.removePreference(theme_primary);
|
preferenceScreen.removePreference(theme_primary);
|
||||||
preferenceScreen.removePreference(theme_accent);
|
preferenceScreen.removePreference(theme_accent);
|
||||||
preferenceScreen.removePreference(pref_color_navigation_bar);
|
preferenceScreen.removePreference(pref_color_navigation_bar);
|
||||||
|
preferenceScreen.removePreference(pref_color_status_bar);
|
||||||
preferenceScreen.removePreference(pref_color_background);
|
preferenceScreen.removePreference(pref_color_background);
|
||||||
preferenceScreen.removePreference(reset_pref);
|
preferenceScreen.removePreference(reset_pref);
|
||||||
|
|
||||||
|
@ -141,17 +190,7 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
|
||||||
dialogBuilder.setPositiveButton(R.string.reset, new DialogInterface.OnClickListener() {
|
dialogBuilder.setPositiveButton(R.string.reset, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
reset();
|
||||||
editor.remove("theme_boost_header_color");
|
|
||||||
editor.remove("theme_statuses_color");
|
|
||||||
editor.remove("theme_link_color");
|
|
||||||
editor.remove("theme_icons_color");
|
|
||||||
editor.remove("pref_color_background");
|
|
||||||
editor.remove("pref_color_navigation_bar");
|
|
||||||
editor.remove("theme_accent");
|
|
||||||
editor.remove("theme_text_color");
|
|
||||||
editor.remove("theme_primary");
|
|
||||||
editor.commit();
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
setPreferenceScreen(null);
|
setPreferenceScreen(null);
|
||||||
addPreferencesFromResource(R.xml.fragment_settings_color);
|
addPreferencesFromResource(R.xml.fragment_settings_color);
|
||||||
|
@ -171,4 +210,112 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reset(){
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.remove("theme_boost_header_color");
|
||||||
|
editor.remove("theme_statuses_color");
|
||||||
|
editor.remove("theme_link_color");
|
||||||
|
editor.remove("theme_icons_color");
|
||||||
|
editor.remove("pref_color_background");
|
||||||
|
editor.remove("pref_color_status_bar");
|
||||||
|
editor.remove("pref_color_navigation_bar");
|
||||||
|
editor.remove("theme_accent");
|
||||||
|
editor.remove("theme_text_color");
|
||||||
|
editor.remove("theme_primary");
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void exportColors() {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
try {
|
||||||
|
String fileName = "Fedilab_color_export_" + Helper.dateFileToString(getActivity(), new Date()) + ".csv";
|
||||||
|
String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
|
||||||
|
String fullPath = filePath + "/" + fileName;
|
||||||
|
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(fullPath)), "UTF-8"));
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("type").append(',');
|
||||||
|
builder.append("value").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
int theme_boost_header_color = prefs.getInt("theme_boost_header_color", -1);
|
||||||
|
int theme_statuses_color = prefs.getInt("theme_statuses_color", -1);
|
||||||
|
int theme_link_color = prefs.getInt("theme_link_color", -1);
|
||||||
|
int theme_icons_color = prefs.getInt("theme_icons_color", -1);
|
||||||
|
int pref_color_background = prefs.getInt("pref_color_background", -1);
|
||||||
|
boolean pref_color_navigation_bar = prefs.getBoolean("pref_color_navigation_bar", true);
|
||||||
|
boolean pref_color_status_bar = prefs.getBoolean("pref_color_status_bar", true);
|
||||||
|
int theme_accent = prefs.getInt("theme_accent", -1);
|
||||||
|
int theme_text_color = prefs.getInt("theme_text_color", -1);
|
||||||
|
int theme_primary = prefs.getInt("theme_primary", -1);
|
||||||
|
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
|
||||||
|
|
||||||
|
builder.append("\"").append("base_theme").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_boost_header_color").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_boost_header_color).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_statuses_color").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_statuses_color).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_link_color").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_link_color).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_icons_color").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_icons_color).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("pref_color_background").append("\"").append(',');
|
||||||
|
builder.append("\"").append(pref_color_background).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("pref_color_navigation_bar").append("\"").append(',');
|
||||||
|
builder.append("\"").append(pref_color_navigation_bar).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("pref_color_status_bar").append("\"").append(',');
|
||||||
|
builder.append("\"").append(pref_color_status_bar).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_accent").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_accent).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_text_color").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_text_color).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
builder.append("\"").append("theme_primary").append("\"").append(',');
|
||||||
|
builder.append("\"").append(theme_primary).append("\"").append(',');
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
|
||||||
|
pw.write(builder.toString());
|
||||||
|
pw.close();
|
||||||
|
String message = getString(R.string.data_export_theme_success);
|
||||||
|
Intent intentOpen = new Intent();
|
||||||
|
intentOpen.setAction(android.content.Intent.ACTION_VIEW);
|
||||||
|
Uri uri = Uri.parse("file://" + fullPath);
|
||||||
|
intentOpen.setDataAndType(uri, "text/csv");
|
||||||
|
String title = getString(R.string.data_export_theme);
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getActivity()));
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(getActivity(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
Account account = new AccountDAO(getActivity(), db).getUniqAccount(userId, instance);
|
||||||
|
Helper.notify_user(getActivity(), account, intentOpen, BitmapFactory.decodeResource(getResources(),
|
||||||
|
Helper.getMainLogo(getActivity())), Helper.NotifType.BACKUP, title, message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Toasty.error(getActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1276,5 +1276,10 @@
|
||||||
<string name="pref_custom_theme">Use a custom theme</string>
|
<string name="pref_custom_theme">Use a custom theme</string>
|
||||||
<string name="pref_custom_theme_summary">Allow to override colors of the selected theme above</string>
|
<string name="pref_custom_theme_summary">Allow to override colors of the selected theme above</string>
|
||||||
<string name="theming">Theming</string>
|
<string name="theming">Theming</string>
|
||||||
|
<string name="store_before">Store before</string>
|
||||||
|
<string name="data_export_theme">The theme was exported</string>
|
||||||
|
<string name="data_export_theme_success">The theme has been successfuly exported in CSV</string>
|
||||||
|
<string name="pref_colored_status_bar_summary">Apply the primary color to the status bar</string>
|
||||||
|
<string name="pref_colored_status_bar_title">Status bar color</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -83,6 +83,14 @@
|
||||||
android:title="@string/pref_colored_navigation_bar_title"
|
android:title="@string/pref_colored_navigation_bar_title"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<androidx.preference.SwitchPreferenceCompat
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
android:defaultValue="@bool/should_tint_status_bar"
|
||||||
|
android:key="pref_color_status_bar"
|
||||||
|
android:summary="@string/pref_colored_status_bar_summary"
|
||||||
|
android:title="@string/pref_colored_status_bar_title"
|
||||||
|
/>
|
||||||
|
|
||||||
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
android:defaultValue="-1"
|
android:defaultValue="-1"
|
||||||
|
|
Loading…
Reference in New Issue