Manage pref

This commit is contained in:
tom79 2019-11-12 19:44:56 +01:00
parent c964b268e1
commit d7840ba3f4
7 changed files with 4 additions and 201 deletions

View File

@ -65,9 +65,6 @@ public class SettingsActivity extends BaseActivity {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_Fedilab);
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark);
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack);
break;
@ -108,7 +105,7 @@ public class SettingsActivity extends BaseActivity {
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.notifications)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.settings_category_label_interface)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.compose)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.colors)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.theming)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.hide_menu_items)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.administration)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.languages)));

View File

@ -38,7 +38,7 @@ public class ColorSettingsFragment extends PreferenceFragmentCompat implements
createPref();
}

View File

@ -1433,60 +1433,6 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
fileListerDialog.show();
});
final Spinner set_night_mode = rootView.findViewById(R.id.set_night_mode);
ArrayAdapter<CharSequence> adapterTheme = ArrayAdapter.createFromResource(getContext(),
R.array.settings_theme, android.R.layout.simple_spinner_item);
set_night_mode.setAdapter(adapterTheme);
int positionSpinnerTheme;
switch (sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK)) {
case Helper.THEME_DARK:
positionSpinnerTheme = 0;
break;
case Helper.THEME_LIGHT:
positionSpinnerTheme = 1;
break;
case Helper.THEME_BLACK:
positionSpinnerTheme = 2;
break;
default:
positionSpinnerTheme = 0;
}
set_night_mode.setSelection(positionSpinnerTheme, false);
set_night_mode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
SharedPreferences.Editor editor = sharedpreferences.edit();
switch (position) {
case 0:
editor.putInt(Helper.SET_THEME, Helper.THEME_DARK);
editor.apply();
break;
case 1:
editor.putInt(Helper.SET_THEME, Helper.THEME_LIGHT);
editor.apply();
break;
case 2:
editor.putInt(Helper.SET_THEME, Helper.THEME_BLACK);
editor.apply();
break;
}
Bundle b = new Bundle();
b.putString("menu", "theme");
Intent intentBC = new Intent(Helper.RECEIVE_HIDE_ITEM);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
((SettingsActivity) context).recreate();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
SeekBar toot_per_page = rootView.findViewById(R.id.set_toot_per_page);
final TextView set_toot_per_page_count = rootView.findViewById(R.id.set_toot_per_page_count);

View File

@ -1927,131 +1927,11 @@ public class Helper {
ImageView profilePicture = headerLayout.findViewById(R.id.profilePicture);
TextView username = headerLayout.findViewById(R.id.username);
TextView displayedName = headerLayout.findViewById(R.id.displayedName);
LinearLayout more_option_container = headerLayout.findViewById(R.id.more_option_container);
LinearLayout more_account_container = headerLayout.findViewById(R.id.more_account_container);
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
ImageView icon = new ImageView(activity);
FloatingActionButton.LayoutParams layoutparmans = new FloatingActionButton.LayoutParams((int) Helper.convertDpToPixel(35, activity), (int) Helper.convertDpToPixel(35, activity));
FloatingActionButton.LayoutParams layoutparmanImg = new FloatingActionButton.LayoutParams((int) Helper.convertDpToPixel(25, activity), (int) Helper.convertDpToPixel(25, activity));
MenuFloating actionButton = null;
if (theme == THEME_LIGHT) {
icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush));
actionButton = new MenuFloating.Builder(activity)
.setContentView(icon, layoutparmanImg)
.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.circular))
.setLayoutParams(layoutparmans)
.setTag("THEME")
.intoView(more_option_container)
.build();
} else if (theme == THEME_DARK) {
icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
actionButton = new MenuFloating.Builder(activity)
.setContentView(icon, layoutparmanImg)
.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.circular_dark))
.setLayoutParams(layoutparmans)
.setTag("THEME")
.intoView(more_option_container)
.build();
} else if (theme == THEME_BLACK) {
icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
actionButton = new MenuFloating.Builder(activity)
.setContentView(icon, layoutparmanImg)
.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.circular_black))
.setLayoutParams(layoutparmans)
.setTag("THEME")
.intoView(more_option_container)
.build();
}
SubActionButton.Builder itemBuilder = new SubActionButton.Builder(activity);
// repeat many times:
ImageView itemIconLight = new ImageView(activity);
itemIconLight.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush));
SubActionButton buttonLight = itemBuilder
.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.circular))
.setContentView(itemIconLight).build();
ImageView itemDark = new ImageView(activity);
itemDark.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
SubActionButton buttonDark = itemBuilder
.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.circular_dark))
.setContentView(itemDark).build();
ImageView itemBlack = new ImageView(activity);
itemBlack.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
SubActionButton buttonBlack = itemBuilder
.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.circular_black))
.setContentView(itemBlack).build();
FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(activity)
.addSubActionView(buttonLight)
.addSubActionView(buttonDark)
.addSubActionView(buttonBlack)
.attachTo(actionButton)
.setStartAngle(0)
.setEndAngle(90)
.build();
if (actionButton != null) {
actionButton.setFocusableInTouchMode(true);
actionButton.setFocusable(true);
actionButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (actionMenu.isOpen())
actionMenu.close(true);
else
actionMenu.open(true);
return false;
}
});
actionButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
try {
actionMenu.close(true);
} catch (Exception ignored) {
}
}
});
}
List<CyaneaTheme> list = CyaneaTheme.Companion.from(activity.getAssets(), "themes/cyanea_themes.json");
buttonLight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actionMenu.close(true);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_THEME, Helper.THEME_LIGHT);
editor.commit();
list.get(0).apply(Cyanea.getInstance()).recreate(activity);
}
});
buttonDark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actionMenu.close(true);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_THEME, Helper.THEME_DARK);
editor.commit();
list.get(1).apply(Cyanea.getInstance()).recreate(activity);
}
});
buttonBlack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actionMenu.close(true);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_THEME, Helper.THEME_BLACK);
editor.commit();
list.get(2).apply(Cyanea.getInstance()).recreate(activity);
}
});
ImageView icon;
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();

View File

@ -2078,26 +2078,6 @@
</LinearLayout>
</LinearLayout>
<!-- THEME -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/set_theme"
android:textSize="16sp" />
<Spinner
android:id="@+id/set_night_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- NSFW Timeout -->
<TextView

View File

@ -52,7 +52,6 @@
android:contentDescription="@string/profile_picture" />
<LinearLayout
android:id="@+id/more_option_container"
android:layout_width="0dp"
android:layout_marginStart="20dp"
android:layout_weight="1"

View File

@ -1275,5 +1275,6 @@
<string name="restart">Restart</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="theming">Theming</string>
</resources>