forked from github/wulkanowy-mirror
Add dark theme (#133)
This commit is contained in:

committed by
Rafał Borcz

parent
b63e28f9a9
commit
11578aa735
@ -21,6 +21,8 @@ public interface SharedPrefContract {
|
||||
|
||||
boolean isShowAttendancePresent();
|
||||
|
||||
int getCurrentTheme();
|
||||
|
||||
int getServicesInterval();
|
||||
|
||||
boolean isMobileDisable();
|
||||
|
@ -69,6 +69,11 @@ public class SharedPrefRepository implements SharedPrefContract {
|
||||
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_ATTENDANCE_PRESENT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentTheme() {
|
||||
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_THEME, "1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getServicesInterval() {
|
||||
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_SERVICES_INTERVAL, "60"));
|
||||
|
@ -54,5 +54,6 @@ public abstract class BaseActivity extends DaggerAppCompatActivity implements Ba
|
||||
if (unbinder != null) {
|
||||
unbinder.unbind();
|
||||
}
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.ui.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
@ -19,6 +18,7 @@ import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
@ -27,6 +27,7 @@ import io.github.wulkanowy.ui.main.exams.ExamsFragment;
|
||||
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
||||
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
||||
import io.github.wulkanowy.utils.CommonUtils;
|
||||
|
||||
public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
AHBottomNavigation.OnTabSelectedListener, OnFragmentIsReadyListener {
|
||||
@ -52,6 +53,9 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
@Inject
|
||||
MainContract.Presenter presenter;
|
||||
|
||||
@Inject
|
||||
RepositoryContract repository;
|
||||
|
||||
public static Intent getStartIntent(Context context) {
|
||||
return new Intent(context, MainActivity.class);
|
||||
}
|
||||
@ -93,6 +97,7 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
public boolean onTabSelected(int position, boolean wasSelected) {
|
||||
presenter.onTabSelected(position, wasSelected);
|
||||
appBar.setExpanded(true, true);
|
||||
invalidateOptionsMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -124,8 +129,8 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
R.drawable.ic_menu_other_24dp));
|
||||
|
||||
bottomNavigation.setAccentColor(getResources().getColor(R.color.colorPrimary));
|
||||
bottomNavigation.setInactiveColor(Color.BLACK);
|
||||
bottomNavigation.setBackgroundColor(getResources().getColor(R.color.colorBackgroundBottomNav));
|
||||
bottomNavigation.setInactiveColor(CommonUtils.getThemeAttrColor(this, android.R.attr.textColorTertiary));
|
||||
bottomNavigation.setDefaultBackgroundColor(CommonUtils.getThemeAttrColor(this, R.attr.bottomNavBackground));
|
||||
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
|
||||
bottomNavigation.setOnTabSelectedListener(this);
|
||||
bottomNavigation.setCurrentItem(tabPosition);
|
||||
|
@ -78,7 +78,7 @@ public class AttendanceDialogFragment extends DialogFragment {
|
||||
description.setText(lesson.getDescription());
|
||||
|
||||
if (lesson.getAbsenceUnexcused()) {
|
||||
description.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
|
||||
description.setTextColor(getResources().getColor(R.color.colorPrimary));
|
||||
}
|
||||
|
||||
return view;
|
||||
|
@ -14,7 +14,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindColor;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
@ -23,6 +22,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.viewholders.ExpandableViewHolder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Day;
|
||||
import io.github.wulkanowy.utils.CommonUtils;
|
||||
|
||||
public class AttendanceHeader
|
||||
extends AbstractExpandableHeaderItem<AttendanceHeader.HeaderViewHolder, AttendanceSubItem> {
|
||||
@ -86,15 +86,6 @@ public class AttendanceHeader
|
||||
@BindView(R.id.attendance_header_free_name)
|
||||
TextView freeName;
|
||||
|
||||
@BindColor(R.color.secondary_text)
|
||||
int secondaryColor;
|
||||
|
||||
@BindColor(R.color.free_day)
|
||||
int backgroundFreeDay;
|
||||
|
||||
@BindColor(android.R.color.black)
|
||||
int black;
|
||||
|
||||
private Context context;
|
||||
|
||||
HeaderViewHolder(View view, FlexibleAdapter adapter) {
|
||||
@ -117,16 +108,15 @@ public class AttendanceHeader
|
||||
setInactiveHeader(item.getAttendanceLessons().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
private void setInactiveHeader(boolean inactive) {
|
||||
((FrameLayout) getContentView()).setForeground(inactive ? null : getSelectableDrawable());
|
||||
dayName.setTextColor(inactive ? secondaryColor : black);
|
||||
dayName.setTextColor(CommonUtils.getThemeAttrColor(context,
|
||||
inactive ? android.R.attr.textColorSecondary : android.R.attr.textColorPrimary));
|
||||
|
||||
if (inactive) {
|
||||
getContentView().setBackgroundColor(backgroundFreeDay);
|
||||
getContentView().setBackgroundColor(CommonUtils.getThemeAttrColor(context, R.attr.colorControlHighlight));
|
||||
} else {
|
||||
getContentView().setBackgroundDrawable(context.getResources()
|
||||
.getDrawable(R.drawable.ic_border));
|
||||
getContentView().setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_border));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,9 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear();
|
||||
inflater.inflate(R.menu.grades_action_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.widget.Toast;
|
||||
@ -14,6 +15,7 @@ import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
|
||||
import io.github.wulkanowy.BuildConfig;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
import io.github.wulkanowy.ui.main.MainActivity;
|
||||
import io.github.wulkanowy.utils.AppConstant;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat
|
||||
@ -25,6 +27,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
public static final String SHARED_KEY_ATTENDANCE_PRESENT = "attendance_present";
|
||||
|
||||
public static final String SHARED_KEY_THEME = "theme";
|
||||
|
||||
public static final String SHARED_KEY_SERVICES_ENABLE = "services_enable";
|
||||
|
||||
public static final String SHARED_KEY_NOTIFY_ENABLE = "notify_enable";
|
||||
@ -39,6 +43,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
public static final String SHARED_KEY_ABOUT_REPO = "about_repo";
|
||||
|
||||
private boolean isStarted;
|
||||
|
||||
private boolean isVisible;
|
||||
|
||||
private Preference.OnPreferenceClickListener onProgrammerListener = new Preference.OnPreferenceClickListener() {
|
||||
private int clicks = 0;
|
||||
|
||||
@ -93,6 +101,20 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
launchServices(sharedPreferences.getBoolean(SHARED_KEY_SERVICES_ENABLE, true),
|
||||
sharedPreferences);
|
||||
}
|
||||
|
||||
if (key.equals(SHARED_KEY_THEME)) {
|
||||
setCurrentTheme(sharedPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
private void setCurrentTheme(SharedPreferences sharedPreferences) {
|
||||
AppCompatDelegate.setDefaultNightMode(Integer.parseInt(sharedPreferences.getString(SHARED_KEY_THEME, "1")));
|
||||
getActivity().finish();
|
||||
startActivity(MainActivity
|
||||
.getStartIntent(getContext())
|
||||
.putExtra(MainActivity.EXTRA_CARD_ID_KEY, 4)
|
||||
);
|
||||
getActivity().overridePendingTransition(0, 0);
|
||||
}
|
||||
|
||||
private void launchServices(boolean start, SharedPreferences sharedPref) {
|
||||
@ -107,11 +129,25 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
}
|
||||
}
|
||||
|
||||
private void setTitle() {
|
||||
getActivity().setTitle(R.string.settings_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMenuVisibility(boolean menuVisible) {
|
||||
super.setMenuVisibility(menuVisible);
|
||||
if (menuVisible) {
|
||||
getActivity().setTitle(R.string.settings_text);
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
isVisible = isVisibleToUser;
|
||||
if (isVisible && isStarted) {
|
||||
setTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
isStarted = true;
|
||||
if (isVisible) {
|
||||
setTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,4 +164,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
isStarted = false;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindColor;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
@ -23,6 +22,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.viewholders.ExpandableViewHolder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Day;
|
||||
import io.github.wulkanowy.utils.CommonUtils;
|
||||
|
||||
public class TimetableHeader
|
||||
extends AbstractExpandableHeaderItem<TimetableHeader.HeaderViewHolder, TimetableSubItem> {
|
||||
@ -83,15 +83,6 @@ public class TimetableHeader
|
||||
@BindView(R.id.timetable_header_free_name)
|
||||
TextView freeName;
|
||||
|
||||
@BindColor(R.color.secondary_text)
|
||||
int secondaryColor;
|
||||
|
||||
@BindColor(R.color.free_day)
|
||||
int backgroundFreeDay;
|
||||
|
||||
@BindColor(android.R.color.black)
|
||||
int black;
|
||||
|
||||
private Context context;
|
||||
|
||||
HeaderViewHolder(View view, FlexibleAdapter adapter) {
|
||||
@ -112,13 +103,13 @@ public class TimetableHeader
|
||||
|
||||
private void setInactiveHeader(boolean inactive) {
|
||||
((FrameLayout) getContentView()).setForeground(inactive ? null : getSelectableDrawable());
|
||||
dayName.setTextColor(inactive ? secondaryColor : black);
|
||||
dayName.setTextColor(CommonUtils.getThemeAttrColor(context,
|
||||
inactive ? android.R.attr.textColorSecondary : android.R.attr.textColorPrimary));
|
||||
|
||||
if (inactive) {
|
||||
getContentView().setBackgroundColor(backgroundFreeDay);
|
||||
getContentView().setBackgroundColor(CommonUtils.getThemeAttrColor(context, R.attr.colorControlHighlight));
|
||||
} else {
|
||||
getContentView().setBackgroundDrawable(context.getResources()
|
||||
.getDrawable(R.drawable.ic_border));
|
||||
getContentView().setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_border));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.splash;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -38,6 +39,10 @@ public class SplashActivity extends BaseActivity implements SplashContract.View
|
||||
finish();
|
||||
}
|
||||
|
||||
public void setCurrentThemeMode(int mode) {
|
||||
AppCompatDelegate.setDefaultNightMode(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelNotifications() {
|
||||
new NotificationService(getApplicationContext()).cancelAll();
|
||||
|
@ -11,6 +11,8 @@ public interface SplashContract {
|
||||
void openMainActivity();
|
||||
|
||||
void cancelNotifications();
|
||||
|
||||
void setCurrentThemeMode(int mode);
|
||||
}
|
||||
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
@ -18,6 +18,7 @@ public class SplashPresenter extends BasePresenter<SplashContract.View>
|
||||
@Override
|
||||
public void attachView(@NonNull SplashContract.View view) {
|
||||
super.attachView(view);
|
||||
getView().setCurrentThemeMode(getRepository().getSharedRepo().getCurrentTheme());
|
||||
getView().cancelNotifications();
|
||||
|
||||
if (getRepository().getSharedRepo().isUserLoggedIn()) {
|
||||
|
@ -1,7 +1,11 @@
|
||||
package io.github.wulkanowy.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
@ -37,4 +41,14 @@ public final class CommonUtils {
|
||||
return R.string.noColor_text;
|
||||
}
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getThemeAttrColor(Context context, @AttrRes int colorAttr) {
|
||||
final TypedArray array = context.obtainStyledAttributes(null, new int[]{colorAttr});
|
||||
try {
|
||||
return array.getColor(0, 0);
|
||||
} finally {
|
||||
array.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user