Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Oct 28, 2023
2 parents 49420f2 + c5fb0a7 commit ce237e3
Show file tree
Hide file tree
Showing 57 changed files with 705 additions and 545 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
minSdkVersion 23
targetSdkVersion 34
versionCode 130 // is updated automatically by BitRise; only used when building locally
versionName '1.18.7'
versionName '1.18.8'

def includeObjectBoxBrowser = System.getenv("INCLUDE_OBJECTBOX_BROWSER") ?: "false"
def includeLeakCanary = System.getenv("INCLUDE_LEAK_CANARY") ?: "false"
Expand Down Expand Up @@ -238,6 +238,7 @@ dependencies {
def okhttpVersion = "4.10.0"
implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttpVersion"
implementation "com.squareup.okhttp3:okhttp-brotli:$okhttpVersion"

// Retrofit-ready-ready HTML parser with CSS selectors : https://github.com/DroidsOnRoids/jspoon; uses JSOUP
def jspoon_version = "1.3.2"
Expand Down Expand Up @@ -312,7 +313,7 @@ dependencies {
implementation 'info.debatty:java-string-similarity:2.0.0'

// Biometrics
implementation 'dev.skomlach:biometric:2.2.5'
implementation 'dev.skomlach:biometric:2.2.13'

// Searchable prefs
implementation 'com.github.ByteHamster:SearchPreference:v2.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import me.devsaki.hentoid.fragments.intro.SourcesIntroFragment
import me.devsaki.hentoid.fragments.intro.ThemeIntroFragment
import me.devsaki.hentoid.fragments.intro.WelcomeIntroFragment
import me.devsaki.hentoid.util.Preferences
import me.devsaki.hentoid.util.Settings
import me.devsaki.hentoid.util.ThemeHelper

/**
Expand Down Expand Up @@ -109,7 +110,7 @@ class IntroActivity : AppIntro2() {
autoEndHandler!!.removeCallbacksAndMessages(null)
Preferences.setIsFirstRun(false)
// Need to do that to avoid a useless reloading of the library screen upon loading prefs for the first time
Preferences.setLibraryDisplay(Preferences.Default.LIBRARY_DISPLAY)
Settings.libraryDisplay = Settings.Value.LIBRARY_DISPLAY_DEFAULT

// Load library screen
val intent = Intent(this, LibraryActivity::class.java)
Expand Down
116 changes: 100 additions & 16 deletions app/src/main/java/me/devsaki/hentoid/activities/LibraryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.select.SelectExtension
import com.skydoves.balloon.ArrowOrientation
import com.skydoves.powermenu.MenuAnimation
Expand Down Expand Up @@ -64,11 +66,13 @@ import me.devsaki.hentoid.util.Helper
import me.devsaki.hentoid.util.LocaleHelper
import me.devsaki.hentoid.util.Preferences
import me.devsaki.hentoid.util.SearchHelper.AdvancedSearchCriteria
import me.devsaki.hentoid.util.Settings
import me.devsaki.hentoid.util.ToastHelper
import me.devsaki.hentoid.util.TooltipHelper
import me.devsaki.hentoid.util.file.FileHelper
import me.devsaki.hentoid.util.file.FileHelper.MemoryUsageFigures
import me.devsaki.hentoid.util.file.PermissionHelper
import me.devsaki.hentoid.viewholders.TextItem
import me.devsaki.hentoid.viewmodels.LibraryViewModel
import me.devsaki.hentoid.viewmodels.ViewModelFactory
import me.devsaki.hentoid.widget.ContentSearchManager.ContentSearchBundle
Expand Down Expand Up @@ -104,6 +108,10 @@ class LibraryActivity : BaseActivity() {
// List / grid view
private var displayTypeMenu: MenuItem? = null

// Grid size selection menu
private val gridSizeItemAdapter = ItemAdapter<TextItem<Int>>()
private val gridSizefastAdapter = FastAdapter.with(gridSizeItemAdapter)

// Reorder books (only when inside a group that allows it)
private var reorderMenu: MenuItem? = null
private var reorderConfirmMenu: MenuItem? = null
Expand Down Expand Up @@ -139,12 +147,16 @@ class LibraryActivity : BaseActivity() {
// Used to ignore native calls to onQueryTextChange
private var invalidateNextQueryTextChange = false

// TODO
// Used to prevent search history to show up when unneeded
private var preventShowSearchHistoryNextExpand = false

// TODO
// Menu for search history; useful to dismiss when search bar is dismissed
private var searchHistory: PowerMenu? = null

// True if display settings have been changed
private var hasChangedDisplaySettings = false


// Current text search query; one per tab
private val query = mutableListOf<String?>("", "")

Expand All @@ -162,16 +174,16 @@ class LibraryActivity : BaseActivity() {
// Titles of each of the Viewpager2's tabs
private val titles: MutableMap<Int, String> = HashMap()

// TODO doc
// Current group
private var group: Group? = null

// TODO doc
// Current grouping
private var grouping = Preferences.getGroupingDisplay()

// TODO doc
// Current Content search query
private var contentSearchBundle: Bundle? = null

// TODO doc
// Current Group search query
private var groupSearchBundle: Bundle? = null

// Used to avoid closing search panel immediately when user uses backspace to correct what he typed
Expand Down Expand Up @@ -304,6 +316,7 @@ class LibraryActivity : BaseActivity() {
)
}
Preferences.registerPrefsChangedListener(prefsListener)
Settings.registerPrefsChangedListener(prefsListener)
pagerAdapter = LibraryPagerAdapter(this)
initToolbar()
initSelectionToolbar()
Expand All @@ -324,6 +337,7 @@ class LibraryActivity : BaseActivity() {

override fun onDestroy() {
Preferences.unregisterPrefsChangedListener(prefsListener)
Settings.unregisterPrefsChangedListener(prefsListener)
if (EventBus.getDefault().isRegistered(this)) EventBus.getDefault().unregister(this)

// Empty all handlers to avoid leaks
Expand Down Expand Up @@ -351,6 +365,24 @@ class LibraryActivity : BaseActivity() {
it.toolbar, this
)
updateAlertBanner()
if (hasChangedGridDisplay) {
it.gridSizeBanner.root.alpha = 1f
it.gridSizeBanner.root.isVisible = true
hasChangedGridDisplay = false
// Fade away after 3s
Debouncer<Int>(
this.lifecycleScope,
3000
) {
binding?.gridSizeBanner?.root?.apply {
animate()
.alpha(0f)
.setDuration(1000)
.setListener(null)
isVisible = false
}
}.submit(1)
}
}
}

Expand Down Expand Up @@ -395,6 +427,11 @@ class LibraryActivity : BaseActivity() {
}
}

override fun onResume() {
super.onResume()
if (hasChangedDisplaySettings) resetActivity()
}

/**
* Initialize the UI components
*/
Expand Down Expand Up @@ -428,6 +465,34 @@ class LibraryActivity : BaseActivity() {
}
updateDisplay(Preferences.getGroupingDisplay().id)
}
// Grid size choice
binding?.gridSizeBanner?.let {
it.recyclerView.adapter = gridSizefastAdapter
val labels = resources.getStringArray(R.array.pref_grid_card_width_entries)
val values =
resources.getStringArray(R.array.pref_grid_card_width_values).map { s -> s.toInt() }
val gridSizePref = Settings.libraryGridCardWidthDP
labels.forEachIndexed { index, s ->
val item = TextItem(
s, index,
draggable = false,
reformatCase = false,
isHighlighted = values[index] == gridSizePref,
centered = true,
touchHelper = null
)
item.isSimple = true
item.isSelected = item.isHighlighted
gridSizeItemAdapter.add(item)
}
gridSizefastAdapter.onClickListener =
{ _, _, _, p ->
Settings.libraryGridCardWidthDP = values[p]
hasChangedGridDisplay = true
resetActivity()
true
}
}
}

private fun updateAlertBanner() {
Expand Down Expand Up @@ -504,7 +569,7 @@ class LibraryActivity : BaseActivity() {
}
})
displayTypeMenu = toolbar.menu.findItem(R.id.action_display_type)
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay())
if (Settings.Value.LIBRARY_DISPLAY_LIST == Settings.libraryDisplay)
displayTypeMenu?.setIcon(R.drawable.ic_view_gallery)
else displayTypeMenu?.setIcon(R.drawable.ic_view_list)
reorderMenu = toolbar.menu.findItem(R.id.action_edit)
Expand Down Expand Up @@ -603,10 +668,12 @@ class LibraryActivity : BaseActivity() {
fun toolbarOnItemClicked(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.action_display_type -> {
var displayType = Preferences.getLibraryDisplay()
var displayType = Settings.libraryDisplay
displayType =
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == displayType) Preferences.Constant.LIBRARY_DISPLAY_GRID else Preferences.Constant.LIBRARY_DISPLAY_LIST
Preferences.setLibraryDisplay(displayType)
if (Settings.Value.LIBRARY_DISPLAY_LIST == displayType) Settings.Value.LIBRARY_DISPLAY_GRID else Settings.Value.LIBRARY_DISPLAY_LIST
Settings.libraryDisplay = displayType
hasChangedGridDisplay = Settings.Value.LIBRARY_DISPLAY_GRID == displayType
resetActivity()
}

R.id.action_browse_groups -> LibraryBottomGroupsFragment.invoke(
Expand Down Expand Up @@ -777,12 +844,17 @@ class LibraryActivity : BaseActivity() {
private fun onSharedPreferenceChanged(key: String?) {
Timber.i("Prefs change detected : %s", key)
when (key) {
Preferences.Key.COLOR_THEME, Preferences.Key.LIBRARY_DISPLAY -> {
// Restart the app with the library activity on top
val intent = Intent(this, LibraryActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK
finish()
startActivity(intent)
Preferences.Key.COLOR_THEME,
Settings.Key.LIBRARY_DISPLAY,
Settings.Key.LIBRARY_DISPLAY_GRID_STORAGE,
Settings.Key.LIBRARY_DISPLAY_GRID_LANG,
Settings.Key.LIBRARY_DISPLAY_GRID_FAV,
Settings.Key.LIBRARY_DISPLAY_GRID_RATING,
Settings.Key.LIBRARY_DISPLAY_GRID_SOURCE,
Settings.Key.LIBRARY_DISPLAY_GRID_TITLE,
Settings.Key.LIBRARY_GRID_CARD_WIDTH
-> {
hasChangedDisplaySettings = true
}

Preferences.Key.PRIMARY_STORAGE_URI, Preferences.Key.EXTERNAL_LIBRARY_URI -> {
Expand Down Expand Up @@ -1216,6 +1288,16 @@ class LibraryActivity : BaseActivity() {
updateSelectionToolbar(0, 0, 0, 0, 0, 0)
}

/**
* Restart the app with the library activity on top
*/
private fun resetActivity() {
val intent = Intent(this, LibraryActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK
finish()
startActivity(intent)
}

/**
* ============================== SUBCLASS
*/
Expand All @@ -1235,6 +1317,8 @@ class LibraryActivity : BaseActivity() {
}

companion object {
var hasChangedGridDisplay = false

@StringRes
fun getNameFromFieldCode(prefFieldCode: Int): Int {
return when (prefFieldCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class Hentai2ReadActivity extends BaseWebActivity {

private static final String DOMAIN_FILTER = "hentai2read.com";
private static final String[] GALLERY_FILTER = {GALLERY_PATTERN, GALLERY_PATTERN.replace("$", "") + "[0-9\\.]+/$"};
private static final String[] DIRTY_ELEMENTS = {"div[data-refresh]"}; // iframe[src*=ads]
private static final String[] REMOVABLE_ELEMENTS = {"div[data-refresh]", ".js-rotating"}; // iframe[src*=ads]
private static final String[] JS_WHITELIST = {DOMAIN_FILTER};
private static final String[] JS_CONTENT_BLACKLIST = {"exoloader", "popunder", "trackingurl", "exo_slider", "exojspop", "data-exo", "exoslider"};


Site getStartSite() {
return Site.HENTAI2READ;
Expand All @@ -18,7 +21,10 @@ Site getStartSite() {
protected CustomWebViewClient createWebClient() {
CustomWebViewClient client = new CustomWebViewClient(getStartSite(), GALLERY_FILTER, this);
client.restrictTo(DOMAIN_FILTER);
client.addRemovableElements(DIRTY_ELEMENTS);
client.addRemovableElements(REMOVABLE_ELEMENTS);
client.addJavascriptBlacklist(JS_CONTENT_BLACKLIST);
client.adBlocker.addToJsUrlWhitelist(JS_WHITELIST);
for (String s : JS_CONTENT_BLACKLIST) client.adBlocker.addJsContentBlacklist(s);
return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ protected Content processContent(@NonNull Content content, @NonNull String url,
parser.parseImageListWithWebview(content, webView); // Only fetch them when queue is processed
content.setStatus(StatusContent.SAVED);
} catch (Exception e) {
Helper.logException(e);
Timber.i(e);
content.setStatus(StatusContent.IGNORED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ToonilyActivity extends BaseWebActivity {
private static final String DOMAIN_FILTER = "toonily.com";
private static final String[] GALLERY_FILTER = {GALLERY_PATTERN, GALLERY_PATTERN.replace("$", "") + "ch[%\\w]+-[0-9]+/$"};
private static final String[] DIRTY_ELEMENTS = {".c-ads"};
private static final String[] JS_CONTENT_BLACKLIST = {"'iframe'", "'adsdomain'", "'closead'"};
private static final String[] JS_CONTENT_BLACKLIST = {"'iframe'", "'adsdomain'", "'closead'", "'plu_slider_frame'"};
private static final String[] BLOCKED_CONTENT = {".cloudfront.net"};

Site getStartSite() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import me.devsaki.hentoid.util.Debouncer
import me.devsaki.hentoid.util.Helper
import me.devsaki.hentoid.util.Preferences
import me.devsaki.hentoid.util.SearchHelper.AdvancedSearchCriteria
import me.devsaki.hentoid.util.Settings
import me.devsaki.hentoid.util.StringHelper
import me.devsaki.hentoid.util.ThemeHelper
import me.devsaki.hentoid.util.ToastHelper
Expand Down Expand Up @@ -388,13 +389,13 @@ class LibraryContentFragment : Fragment(), ChangeGroupDialogFragment.Parent,
private fun initUI(rootView: View) {
// RecyclerView
llm =
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay()) LinearLayoutManager(
if (Settings.Value.LIBRARY_DISPLAY_LIST == Settings.libraryDisplay) LinearLayoutManager(
requireContext(),
LinearLayoutManager.VERTICAL,
false
) else AutofitGridLayoutManager(
requireContext(),
resources.getDimension(R.dimen.card_grid_width).toInt()
Helper.dimensAsPx(requireContext(), Settings.libraryGridCardWidthDP)
)
binding?.recyclerView?.apply {
layoutManager = llm
Expand Down Expand Up @@ -1142,7 +1143,7 @@ class LibraryContentFragment : Fragment(), ChangeGroupDialogFragment.Parent,
// Adapter initialization
if (isEndless && !isEditMode) {
val viewType =
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay()) ContentItem.ViewType.LIBRARY else ContentItem.ViewType.LIBRARY_GRID
if (Settings.Value.LIBRARY_DISPLAY_LIST == Settings.libraryDisplay) ContentItem.ViewType.LIBRARY else ContentItem.ViewType.LIBRARY_GRID
pagedItemAdapter = PagedModelAdapter(
asyncDifferConfig,
{ ContentItem(viewType) }) { c: Content ->
Expand Down Expand Up @@ -1277,7 +1278,7 @@ class LibraryContentFragment : Fragment(), ChangeGroupDialogFragment.Parent,

// Drag, drop & swiping
@DimenRes val dimen: Int =
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay()) R.dimen.delete_drawer_width_list else R.dimen.delete_drawer_width_grid
if (Settings.Value.LIBRARY_DISPLAY_LIST == Settings.libraryDisplay) R.dimen.delete_drawer_width_list else R.dimen.delete_drawer_width_grid
val dragSwipeCallback = SimpleSwipeDrawerDragCallback(this, ItemTouchHelper.LEFT, this)
.withSwipeLeft(Helper.dimensAsDp(requireContext(), dimen))
.withSensitivity(1.5f)
Expand Down Expand Up @@ -1349,7 +1350,7 @@ class LibraryContentFragment : Fragment(), ChangeGroupDialogFragment.Parent,
val maxIndex = bounds.getRight()
// Paged mode won't be used in edit mode
val viewType =
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay()) ContentItem.ViewType.LIBRARY
if (Settings.Value.LIBRARY_DISPLAY_LIST == Settings.libraryDisplay) ContentItem.ViewType.LIBRARY
else ContentItem.ViewType.LIBRARY_GRID // Paged mode won't be used in edit mode
val contentItems =
iLibrary.subList(minIndex, maxIndex).filterNotNull().map { c ->
Expand All @@ -1370,7 +1371,7 @@ class LibraryContentFragment : Fragment(), ChangeGroupDialogFragment.Parent,
} else {
// Grid won't be used in edit mode
val viewType =
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay()
if (Settings.Value.LIBRARY_DISPLAY_LIST == Settings.libraryDisplay
|| activity.get()!!.isEditMode()
)
if (activity.get()!!.isEditMode())
Expand Down Expand Up @@ -1867,7 +1868,7 @@ class LibraryContentFragment : Fragment(), ChangeGroupDialogFragment.Parent,

Preferences.Constant.ORDER_FIELD_NB_PAGES -> c.qtyPages.toLong().toString()
Preferences.Constant.ORDER_FIELD_READS -> c.reads.toString()
Preferences.Constant.ORDER_FIELD_SIZE -> FileHelper.formatHumanReadableSize(
Preferences.Constant.ORDER_FIELD_SIZE -> FileHelper.formatHumanReadableSizeInt(
c.size,
resources
)
Expand Down
Loading

0 comments on commit ce237e3

Please sign in to comment.