Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/ranobe/ranobe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.google.android.material.color.DynamicColors;

import org.ranobe.ranobe.config.Ranobe;

public class App extends Application {
@SuppressLint("StaticFieldLeak")
private static Context context;
Expand All @@ -14,8 +17,11 @@ public static Context getContext() {
return App.context;
}

@Override
public void onCreate() {
super.onCreate();

Log.d(Ranobe.DEBUG, "app launched");
DynamicColors.applyToActivitiesIfAvailable(this);
App.context = getApplicationContext();
}
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/org/ranobe/ranobe/config/Ranobe.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import org.ranobe.ranobe.App;
import org.ranobe.ranobe.models.ReaderTheme;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@SuppressWarnings({
"squid:S3599", "squid:S2386", "squid:S1171", "squid:S1118"
})
public class Ranobe {
public static final String DEBUG = "ranobe.debug";
public static final String PACKAGE_NAME = "org.ranobe.ranobe";
Expand All @@ -30,15 +34,11 @@ public class Ranobe {
"(=____=)"
};

public static final HashMap<String, ReaderTheme> themes = new HashMap<String, ReaderTheme>() {{
put("basic", new ReaderTheme("#fffbe0", "#222831"));
put("basic_inverse", new ReaderTheme("#222831", "#fffbe0"));
put("basic_dim", new ReaderTheme("#fef8e6", "#222831"));
put("basic_dim_inverse", new ReaderTheme("#222831", "#fef8e6"));
put("grey", new ReaderTheme("#eae7e7", "#161c2e"));
put("grey_inverse", new ReaderTheme("#161c2e", "#eae7e7"));
put("terminal", new ReaderTheme("#161c2e", "#feff89"));
put("green", new ReaderTheme("#74f6a7", "#161c2e"));
public static final Map<String, ReaderTheme> themes = new LinkedHashMap<String, ReaderTheme>() {{
put("default", null);
put("light", new ReaderTheme("#202124", "#FFFFFF"));
put("dark", new ReaderTheme("#E8EAED", "#202124"));
put("warm", new ReaderTheme("#6E4D2E", "#F7DFC6"));
}};

private static SharedPreferences.Editor getEditor(Context context) {
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void storeReaderTheme(Context context, String theme) {
}

public static String getReaderTheme(Context context) {
return getSharedPref(context).getString(Ranobe.SETTINGS_READER_THEME, null);
return getSharedPref(context).getString(Ranobe.SETTINGS_READER_THEME, "default");
}

public static void storeReaderFont(Context context, Float size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ public void setFontSize(float size) {
@Override
public void setReaderTheme(String themeName) {
ReaderTheme theme = Ranobe.themes.get(themeName);
if (theme != null) {
adapter.setTheme(theme);
adapter.notifyItemRangeChanged(0, chapters.size());
Ranobe.storeReaderTheme(this, themeName);
}
adapter.setTheme(theme);
adapter.notifyItemRangeChanged(0, chapters.size());
Ranobe.storeReaderTheme(this, themeName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.color.MaterialColors;

import org.ranobe.ranobe.App;
import org.ranobe.ranobe.config.Ranobe;
import org.ranobe.ranobe.databinding.ItemPageBinding;
Expand Down Expand Up @@ -54,7 +57,15 @@ public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
if (theme != null) {
holder.binding.pageLayout.setBackgroundColor(theme.getBackground());
holder.binding.content.setTextColor(theme.getText());
} else {
holder.binding.pageLayout.setBackgroundColor(
getThemeColor(holder.binding.pageLayout, com.google.android.material.R.attr.colorSurface)
);
holder.binding.content.setTextColor(
getThemeColor(holder.binding.content, com.google.android.material.R.attr.colorOnSurface)
);
}

holder.binding.content.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);

holder.binding.pageStart.setText(String.format(Locale.getDefault(), "Start of Chapter %.1f", chapter.id));
Expand All @@ -64,6 +75,10 @@ public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.binding.content.setLayoutParams(params);
}

private int getThemeColor(View view, int attr) {
return MaterialColors.getColor(view, attr);
}

@Override
public int getItemCount() {
return chapters.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.ranobe.ranobe.ui.reader.sheet.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.color.MaterialColors;

import org.ranobe.ranobe.config.Ranobe;
import org.ranobe.ranobe.databinding.ItemReaderThemeBinding;
import org.ranobe.ranobe.models.ReaderTheme;
Expand Down Expand Up @@ -33,8 +36,21 @@ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.binding.textLayout.setCardBackgroundColor(themes.get(position).getBackground());
holder.binding.textAa.setTextColor(themes.get(position).getText());
ReaderTheme theme = themes.get(position);

if (theme != null) {
holder.binding.textLayout.setCardBackgroundColor(themes.get(position).getBackground());
holder.binding.textAa.setTextColor(themes.get(position).getText());
} else {
holder.binding.textLayout.setCardBackgroundColor(null);
holder.binding.textAa.setTextColor(
getThemeColor(holder.binding.textAa, com.google.android.material.R.attr.colorOnSurface)
);
}
}

private int getThemeColor(View view, int attr) {
return MaterialColors.getColor(view, attr);
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/item_reader_theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:layout_marginVertical="10dp"
app:cardBackgroundColor="#e7edde"
app:cardElevation="5dp">

<TextView
Expand All @@ -18,7 +17,6 @@
android:paddingHorizontal="12dp"
android:paddingVertical="15dp"
android:text="@string/aa"
android:textColor="#5d5f5a"
android:textSize="40sp"
android:textStyle="bold" />

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists