mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	custom dialog
This commit is contained in:
		
							parent
							
								
									fdbb3b04f3
								
							
						
					
					
						commit
						a1b08b8edc
					
				
					 6 changed files with 29 additions and 16 deletions
				
			
		|  | @ -1067,13 +1067,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|             } catch (DBException e) { |             } catch (DBException e) { | ||||||
|                 e.printStackTrace(); |                 e.printStackTrace(); | ||||||
|             } |             } | ||||||
|  |             //Apply the custom theme | ||||||
|             if (currentAccount != null && currentInstance == null) { |             if (currentAccount != null && currentInstance == null) { | ||||||
|                 currentInstance = currentAccount.instance; |                 currentInstance = currentAccount.instance; | ||||||
|                 currentUserID = currentAccount.user_id; |                 currentUserID = currentAccount.user_id; | ||||||
|                 Handler mainHandler = new Handler(Looper.getMainLooper()); |                 Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||||
|                 Runnable myRunnable = () -> { |                 Runnable myRunnable = this::recreate; | ||||||
|                     recreate(); |  | ||||||
|                 }; |  | ||||||
|                 mainHandler.post(myRunnable); |                 mainHandler.post(myRunnable); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,7 +21,6 @@ import static app.fedilab.android.BaseMainActivity.currentUserID; | ||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| import android.os.Build; | import android.os.Build; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.util.Log; |  | ||||||
| 
 | 
 | ||||||
| import androidx.appcompat.app.AlertDialog; | import androidx.appcompat.app.AlertDialog; | ||||||
| import androidx.navigation.NavOptions; | import androidx.navigation.NavOptions; | ||||||
|  | @ -101,8 +100,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements | ||||||
|                 editor.putInt(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_CUSTOM_ACCENT_VALUE.getColor()); |                 editor.putInt(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_CUSTOM_ACCENT_VALUE.getColor()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         Log.v(Helper.TAG, "currentUserID: " + currentUserID); |  | ||||||
|         Log.v(Helper.TAG, "currentInstance: " + currentInstance); |  | ||||||
|         editor.apply(); |         editor.apply(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -115,7 +112,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements | ||||||
|         if (getPreferenceScreen() == null) { |         if (getPreferenceScreen() == null) { | ||||||
|             Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); |             Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); | ||||||
|         } |         } | ||||||
| 
 |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||||
|         SwitchPreferenceCompat SET_DYNAMIC_COLOR = findPreference(getString(R.string.SET_DYNAMICCOLOR)); |         SwitchPreferenceCompat SET_DYNAMIC_COLOR = findPreference(getString(R.string.SET_DYNAMICCOLOR)); | ||||||
|         SwitchPreferenceCompat SET_CUSTOM_ACCENT = findPreference(getString(R.string.SET_CUSTOM_ACCENT)); |         SwitchPreferenceCompat SET_CUSTOM_ACCENT = findPreference(getString(R.string.SET_CUSTOM_ACCENT)); | ||||||
|         ColorPreferenceCompat SET_CUSTOM_ACCENT_DARK_VALUE = findPreference(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE)); |         ColorPreferenceCompat SET_CUSTOM_ACCENT_DARK_VALUE = findPreference(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE)); | ||||||
|  | @ -133,6 +130,19 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements | ||||||
|             if (SET_CUSTOM_ACCENT_LIGHT_VALUE != null) { |             if (SET_CUSTOM_ACCENT_LIGHT_VALUE != null) { | ||||||
|                 getPreferenceScreen().removePreference(SET_CUSTOM_ACCENT_LIGHT_VALUE); |                 getPreferenceScreen().removePreference(SET_CUSTOM_ACCENT_LIGHT_VALUE); | ||||||
|             } |             } | ||||||
|  |         } else { | ||||||
|  |             if (SET_CUSTOM_ACCENT != null) { | ||||||
|  |                 boolean customAccentEnabled = sharedpreferences.getBoolean(getString(R.string.SET_CUSTOM_ACCENT) + currentUserID + currentInstance, false); | ||||||
|  |                 SET_CUSTOM_ACCENT.setChecked(customAccentEnabled); | ||||||
|  |             } | ||||||
|  |             if (SET_CUSTOM_ACCENT_DARK_VALUE != null) { | ||||||
|  |                 int darkValue = sharedpreferences.getInt(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE) + currentUserID + currentInstance, -1); | ||||||
|  |                 SET_CUSTOM_ACCENT_DARK_VALUE.setColor(darkValue); | ||||||
|  |             } | ||||||
|  |             if (SET_CUSTOM_ACCENT_LIGHT_VALUE != null) { | ||||||
|  |                 int darkValue = sharedpreferences.getInt(getString(R.string.SET_CUSTOM_ACCENT_LIGHT_VALUE) + currentUserID + currentInstance, -1); | ||||||
|  |                 SET_CUSTOM_ACCENT_LIGHT_VALUE.setColor(darkValue); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         Preference SET_CUSTOMIZE_LIGHT_COLORS_ACTION = findPreference(getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS_ACTION)); |         Preference SET_CUSTOMIZE_LIGHT_COLORS_ACTION = findPreference(getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS_ACTION)); | ||||||
|  |  | ||||||
|  | @ -2,11 +2,4 @@ | ||||||
| <resources> | <resources> | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     <string name="auto">Auto</string> |  | ||||||
|     <string name="set_custom_accent">Custom accent color</string> |  | ||||||
|     <string name="set_custom_accent_indication">Define a theme color per account</string> |  | ||||||
|     <string name="set_custom_accent_light_value">Light accent color</string> |  | ||||||
|     <string name="set_custom_accent_dark_value">Dark accent color</string> |  | ||||||
|     <string name="set_custom_accent_value_light_description">Color that will be applied to the light theme</string> |  | ||||||
|     <string name="set_custom_accent_value_dark_description">Color that will be applied to the dark theme</string> |  | ||||||
| </resources> | </resources> | ||||||
|  | @ -1970,4 +1970,12 @@ | ||||||
| 
 | 
 | ||||||
|     <string name="track_selection_title">Select tracks</string> |     <string name="track_selection_title">Select tracks</string> | ||||||
| 
 | 
 | ||||||
|  |     <string name="auto">Auto</string> | ||||||
|  |     <string name="set_custom_accent">Custom accent color</string> | ||||||
|  |     <string name="set_custom_accent_indication">Define a theme color per account</string> | ||||||
|  |     <string name="set_custom_accent_light_value">Light accent color</string> | ||||||
|  |     <string name="set_custom_accent_dark_value">Dark accent color</string> | ||||||
|  |     <string name="set_custom_accent_value_light_description">Color that will be applied to the light theme</string> | ||||||
|  |     <string name="set_custom_accent_value_dark_description">Color that will be applied to the dark theme</string> | ||||||
|  | 
 | ||||||
| </resources> | </resources> | ||||||
|  | @ -31,6 +31,7 @@ dependencies { | ||||||
|     //noinspection GradleCompatible |     //noinspection GradleCompatible | ||||||
|     implementation 'androidx.appcompat:appcompat:1.5.1' |     implementation 'androidx.appcompat:appcompat:1.5.1' | ||||||
|     implementation 'androidx.preference:preference:1.2.0' |     implementation 'androidx.preference:preference:1.2.0' | ||||||
|  |     implementation 'com.google.android.material:material:1.8.0' | ||||||
|     testImplementation 'junit:junit:4.13.2' |     testImplementation 'junit:junit:4.13.2' | ||||||
|     androidTestImplementation 'androidx.test:runner:1.5.2' |     androidTestImplementation 'androidx.test:runner:1.5.2' | ||||||
|     androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' |     androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' | ||||||
|  |  | ||||||
|  | @ -53,6 +53,8 @@ import androidx.core.graphics.ColorUtils; | ||||||
| import androidx.fragment.app.DialogFragment; | import androidx.fragment.app.DialogFragment; | ||||||
| import androidx.fragment.app.FragmentActivity; | import androidx.fragment.app.FragmentActivity; | ||||||
| 
 | 
 | ||||||
|  | import com.google.android.material.dialog.MaterialAlertDialogBuilder; | ||||||
|  | 
 | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.Locale; | import java.util.Locale; | ||||||
| 
 | 
 | ||||||
|  | @ -183,8 +185,8 @@ public class ColorPickerDialog extends DialogFragment implements ColorPickerView | ||||||
|         if (selectedButtonStringRes == 0) { |         if (selectedButtonStringRes == 0) { | ||||||
|             selectedButtonStringRes = R.string.cpv_select; |             selectedButtonStringRes = R.string.cpv_select; | ||||||
|         } |         } | ||||||
| 
 |         MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()).setView(rootView) | ||||||
|         AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()).setView(rootView) |                 //    AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()).setView(rootView) | ||||||
|                 .setPositiveButton(selectedButtonStringRes, new DialogInterface.OnClickListener() { |                 .setPositiveButton(selectedButtonStringRes, new DialogInterface.OnClickListener() { | ||||||
|                     @Override |                     @Override | ||||||
|                     public void onClick(DialogInterface dialog, int which) { |                     public void onClick(DialogInterface dialog, int which) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue