fedilab-Android-App/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java

216 lines
7.7 KiB
Java
Raw Normal View History

2019-07-01 18:39:46 +02:00
/* Copyright 2019 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
package app.fedilab.android.activities;
2019-09-21 17:38:38 +02:00
2019-07-01 18:39:46 +02:00
import android.content.SharedPreferences;
import android.os.Bundle;
2019-07-02 17:42:10 +02:00
2019-07-01 18:39:46 +02:00
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
2019-09-21 17:38:38 +02:00
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
2019-07-01 18:39:46 +02:00
2019-09-21 17:38:38 +02:00
import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
2019-07-01 18:39:46 +02:00
import app.fedilab.android.R;
2019-11-06 14:09:38 +01:00
import app.fedilab.android.fragments.ColorSettingsFragment;
2019-07-01 18:39:46 +02:00
import app.fedilab.android.fragments.ContentSettingsFragment;
import app.fedilab.android.helper.Helper;
/**
* Created by Thomas on 01/07/2019.
* Settings activity
*/
2019-09-21 17:38:38 +02:00
public class SettingsActivity extends BaseActivity {
2019-07-01 18:39:46 +02:00
2019-09-06 17:55:14 +02:00
2019-07-01 18:39:46 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2019-09-06 17:55:14 +02:00
switch (theme) {
2019-07-01 18:39:46 +02:00
case Helper.THEME_LIGHT:
2019-09-21 17:38:38 +02:00
setTheme(R.style.AppTheme);
2019-07-01 18:39:46 +02:00
break;
case Helper.THEME_DARK:
2019-09-21 17:38:38 +02:00
setTheme(R.style.AppThemeDark);
2019-07-01 18:39:46 +02:00
break;
case Helper.THEME_BLACK:
2019-09-21 17:38:38 +02:00
setTheme(R.style.AppThemeBlack);
2019-07-01 18:39:46 +02:00
break;
default:
2019-09-21 17:38:38 +02:00
setTheme(R.style.AppThemeDark);
2019-07-01 18:39:46 +02:00
}
2019-09-06 17:55:14 +02:00
if (getSupportActionBar() != null)
2019-07-01 18:39:46 +02:00
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
2019-09-06 17:55:14 +02:00
if (actionBar != null) {
2019-07-01 18:39:46 +02:00
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
2019-09-06 17:55:14 +02:00
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
2019-07-01 18:39:46 +02:00
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
2019-09-21 17:38:38 +02:00
toolbar_title.setText(R.string.settings);
2019-09-06 17:55:14 +02:00
if (theme == Helper.THEME_LIGHT) {
2019-07-01 18:39:46 +02:00
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, SettingsActivity.this);
}
}
setContentView(R.layout.activity_settings);
2019-09-21 17:38:38 +02:00
ViewPager mPager = findViewById(R.id.settings_viewpager);
TabLayout tabLayout = findViewById(R.id.settings_tablayout);
2019-07-01 18:39:46 +02:00
2019-09-21 17:38:38 +02:00
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.settings_category_label_timelines)));
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)));
2019-11-06 14:09:38 +01:00
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.colors)));
2019-09-21 17:38:38 +02:00
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)));
PagerAdapter mPagerAdapter = new SettingsPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
2019-07-01 18:39:46 +02:00
}
@Override
2019-09-21 17:38:38 +02:00
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if (tab != null)
tab.select();
2019-07-01 18:39:46 +02:00
}
2019-09-21 17:38:38 +02:00
@Override
public void onPageScrollStateChanged(int state) {
2019-07-01 18:39:46 +02:00
2019-09-21 17:38:38 +02:00
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
2019-07-03 11:58:26 +02:00
2019-07-02 19:17:54 +02:00
}
2019-07-01 18:39:46 +02:00
2019-09-21 17:38:38 +02:00
private class SettingsPagerAdapter extends FragmentStatePagerAdapter {
2019-07-01 18:39:46 +02:00
2019-09-21 17:38:38 +02:00
SettingsPagerAdapter(FragmentManager fm) {
super(fm);
2019-07-01 18:39:46 +02:00
}
2019-09-21 17:38:38 +02:00
@NotNull
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
ContentSettingsFragment.type typeOfSettings;
switch (position) {
case 0:
typeOfSettings = ContentSettingsFragment.type.TIMELINES;
break;
case 1:
typeOfSettings = ContentSettingsFragment.type.NOTIFICATIONS;
break;
case 2:
typeOfSettings = ContentSettingsFragment.type.INTERFACE;
break;
case 3:
typeOfSettings = ContentSettingsFragment.type.COMPOSE;
break;
case 4:
2019-11-06 14:09:38 +01:00
return new ColorSettingsFragment();
case 5:
2019-09-21 17:38:38 +02:00
typeOfSettings = ContentSettingsFragment.type.MENU;
break;
2019-11-06 14:09:38 +01:00
case 6:
2019-09-21 17:38:38 +02:00
typeOfSettings = ContentSettingsFragment.type.ADMIN;
break;
2019-11-06 14:09:38 +01:00
case 7:
2019-09-21 17:38:38 +02:00
typeOfSettings = ContentSettingsFragment.type.LANGUAGE;
break;
default:
typeOfSettings = ContentSettingsFragment.type.TIMELINES;
2019-07-01 18:39:46 +02:00
2019-09-21 17:38:38 +02:00
}
ContentSettingsFragment contentSettingsFragment = new ContentSettingsFragment();
bundle.putSerializable("typeOfSettings", typeOfSettings);
contentSettingsFragment.setArguments(bundle);
return contentSettingsFragment;
2019-07-01 18:39:46 +02:00
}
2019-09-21 17:38:38 +02:00
@Override
public int getCount() {
2019-11-06 14:09:38 +01:00
return 8;
2019-07-01 18:39:46 +02:00
}
}
@Override
2019-09-21 17:38:38 +02:00
public void onDestroy() {
super.onDestroy();
2019-07-01 18:39:46 +02:00
}
2019-09-21 17:38:38 +02:00
2019-07-01 18:39:46 +02:00
@Override
2019-09-21 17:38:38 +02:00
public void onResume() {
super.onResume();
2019-07-01 18:39:46 +02:00
}
2019-09-21 17:38:38 +02:00
2019-07-01 18:39:46 +02:00
}