mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Implement auto switcher for light and dark theme (#388)
Remove import and add author Implement auto switcher for light and dark theme. other ui fixes Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/388 Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
79944241fe
commit
f5d5264ef7
@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.FontsOverride;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
|
||||
/**
|
||||
@ -20,6 +21,18 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
if(tinyDb.getInt("themeId") == 1) {
|
||||
setTheme(R.style.AppThemeLight);
|
||||
}
|
||||
else if(tinyDb.getInt("themeId") == 2) {
|
||||
|
||||
boolean timeSetterFlag = TimeHelper.timeBetweenHours(18, 6); // 6pm to 6am
|
||||
|
||||
if(timeSetterFlag) {
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
else {
|
||||
setTheme(R.style.AppThemeLight);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class SettingsFragment extends Fragment {
|
||||
private static String[] customFontList = {"Roboto", "Manrope", "Source Code Pro"};
|
||||
private static int customFontSelectedChoice = 0;
|
||||
|
||||
private static String[] themeList = {"Dark", "Light"};
|
||||
private static String[] themeList = {"Dark", "Light", "Auto (Day/Night)"};
|
||||
private static int themeSelectedChoice = 0;
|
||||
|
||||
@Nullable
|
||||
|
@ -6,9 +6,14 @@ import org.ocpsoft.prettytime.PrettyTime;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class TimeHelper {
|
||||
|
||||
public static String customDateFormatForToast(String customDate) {
|
||||
@ -59,4 +64,29 @@ public class TimeHelper {
|
||||
|
||||
}
|
||||
|
||||
public static boolean timeBetweenHours(int fromHour, int toHour) {
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
Calendar from = Calendar.getInstance();
|
||||
from.set(Calendar.HOUR_OF_DAY, fromHour);
|
||||
from.set(Calendar.MINUTE, 0);
|
||||
|
||||
Calendar to = Calendar.getInstance();
|
||||
to.set(Calendar.HOUR_OF_DAY, toHour);
|
||||
to.set(Calendar.MINUTE, 0);
|
||||
|
||||
if(to.before(from)) {
|
||||
if (cal.after(to)) {
|
||||
to.add(Calendar.DATE, 1);
|
||||
}
|
||||
else {
|
||||
from.add(Calendar.DATE, -1);
|
||||
}
|
||||
}
|
||||
|
||||
return cal.after(from) && cal.before(to);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,15 @@
|
||||
android:id="@+id/pdfMode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="horizontal">
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pdfModeHeader"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="44dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="@string/settingsPdfModeHeaderText"
|
||||
|
@ -22,7 +22,7 @@
|
||||
android:id="@+id/langFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
|
@ -23,8 +23,8 @@
|
||||
android:id="@+id/certsFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="horizontal">
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCertHeader"
|
||||
|
Loading…
Reference in New Issue
Block a user