Open bookmarks in incognito mode
This commit is contained in:
@@ -6,6 +6,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
@@ -94,6 +95,7 @@ class BookmarksFragment :
|
|||||||
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
||||||
val intent = ReaderActivity.newIntent(view.context, item)
|
val intent = ReaderActivity.newIntent(view.context, item)
|
||||||
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
||||||
|
Toast.makeText(view.context, R.string.incognito_mode, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.text.method.LinkMovementMethod
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
@@ -40,7 +41,6 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaState
|
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
|
||||||
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingInfo
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingInfo
|
||||||
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.search.ui.SearchActivity
|
import org.koitharu.kotatsu.search.ui.SearchActivity
|
||||||
@@ -63,7 +63,6 @@ import javax.inject.Inject
|
|||||||
class DetailsFragment :
|
class DetailsFragment :
|
||||||
BaseFragment<FragmentDetailsBinding>(),
|
BaseFragment<FragmentDetailsBinding>(),
|
||||||
View.OnClickListener,
|
View.OnClickListener,
|
||||||
View.OnLongClickListener,
|
|
||||||
ChipsView.OnChipClickListener,
|
ChipsView.OnChipClickListener,
|
||||||
OnListItemClickListener<Bookmark> {
|
OnListItemClickListener<Bookmark> {
|
||||||
|
|
||||||
@@ -101,6 +100,7 @@ class DetailsFragment :
|
|||||||
ReaderActivity.newIntent(view.context, item),
|
ReaderActivity.newIntent(view.context, item),
|
||||||
scaleUpActivityOptionsOf(view).toBundle(),
|
scaleUpActivityOptionsOf(view).toBundle(),
|
||||||
)
|
)
|
||||||
|
Toast.makeText(view.context, R.string.incognito_mode, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemLongClick(item: Bookmark, view: View): Boolean {
|
override fun onItemLongClick(item: Bookmark, view: View): Boolean {
|
||||||
@@ -268,43 +268,6 @@ class DetailsFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLongClick(v: View): Boolean {
|
|
||||||
when (v.id) {
|
|
||||||
R.id.button_read -> {
|
|
||||||
if (viewModel.historyInfo.value?.history == null) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
val menu = PopupMenu(v.context, v)
|
|
||||||
menu.inflate(R.menu.popup_read)
|
|
||||||
menu.setOnMenuItemClickListener { menuItem ->
|
|
||||||
when (menuItem.itemId) {
|
|
||||||
R.id.action_read -> {
|
|
||||||
val branch = viewModel.selectedBranchValue
|
|
||||||
startActivity(
|
|
||||||
ReaderActivity.newIntent(
|
|
||||||
context = context ?: return@setOnMenuItemClickListener false,
|
|
||||||
manga = viewModel.manga.value ?: return@setOnMenuItemClickListener false,
|
|
||||||
state = viewModel.chapters.value?.firstOrNull { c ->
|
|
||||||
c.chapter.branch == branch
|
|
||||||
}?.let { c ->
|
|
||||||
ReaderState(c.chapter.id, 0, 0)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
menu.show()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onChipClick(chip: Chip, data: Any?) {
|
override fun onChipClick(chip: Chip, data: Any?) {
|
||||||
val tag = data as? MangaTag ?: return
|
val tag = data as? MangaTag ?: return
|
||||||
startActivity(MangaListActivity.newIntent(requireContext(), setOf(tag)))
|
startActivity(MangaListActivity.newIntent(requireContext(), setOf(tag)))
|
||||||
|
|||||||
@@ -395,6 +395,7 @@ class ReaderActivity :
|
|||||||
const val ACTION_MANGA_READ = "${BuildConfig.APPLICATION_ID}.action.READ_MANGA"
|
const val ACTION_MANGA_READ = "${BuildConfig.APPLICATION_ID}.action.READ_MANGA"
|
||||||
const val EXTRA_STATE = "state"
|
const val EXTRA_STATE = "state"
|
||||||
const val EXTRA_BRANCH = "branch"
|
const val EXTRA_BRANCH = "branch"
|
||||||
|
const val EXTRA_INCOGNITO = "incognito"
|
||||||
private const val TOAST_DURATION = 1500L
|
private const val TOAST_DURATION = 1500L
|
||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga): Intent {
|
fun newIntent(context: Context, manga: Manga): Intent {
|
||||||
@@ -415,8 +416,13 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun newIntent(context: Context, bookmark: Bookmark): Intent {
|
fun newIntent(context: Context, bookmark: Bookmark): Intent {
|
||||||
val state = ReaderState(bookmark.chapterId, bookmark.page, bookmark.scroll)
|
val state = ReaderState(
|
||||||
|
chapterId = bookmark.chapterId,
|
||||||
|
page = bookmark.page,
|
||||||
|
scroll = bookmark.scroll,
|
||||||
|
)
|
||||||
return newIntent(context, bookmark.manga, state)
|
return newIntent(context, bookmark.manga, state)
|
||||||
|
.putExtra(EXTRA_INCOGNITO, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun newIntent(context: Context, mangaId: Long): Intent {
|
fun newIntent(context: Context, mangaId: Long): Intent {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ class ReaderViewModel @Inject constructor(
|
|||||||
|
|
||||||
private val intent = MangaIntent(savedStateHandle)
|
private val intent = MangaIntent(savedStateHandle)
|
||||||
private val preselectedBranch = savedStateHandle.get<String>(ReaderActivity.EXTRA_BRANCH)
|
private val preselectedBranch = savedStateHandle.get<String>(ReaderActivity.EXTRA_BRANCH)
|
||||||
|
private val isIncognito = savedStateHandle.get<Boolean>(ReaderActivity.EXTRA_INCOGNITO) ?: false
|
||||||
|
|
||||||
private var loadingJob: Job? = null
|
private var loadingJob: Job? = null
|
||||||
private var pageSaveJob: Job? = null
|
private var pageSaveJob: Job? = null
|
||||||
@@ -145,11 +146,6 @@ class ReaderViewModel @Inject constructor(
|
|||||||
}.launchIn(viewModelScope)
|
}.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*override fun onCleared() {
|
|
||||||
pageLoader.close()
|
|
||||||
super.onCleared()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
fun reload() {
|
fun reload() {
|
||||||
loadingJob?.cancel()
|
loadingJob?.cancel()
|
||||||
loadImpl()
|
loadImpl()
|
||||||
@@ -175,6 +171,9 @@ class ReaderViewModel @Inject constructor(
|
|||||||
if (state != null) {
|
if (state != null) {
|
||||||
currentState.value = state
|
currentState.value = state
|
||||||
}
|
}
|
||||||
|
if (isIncognito) {
|
||||||
|
return
|
||||||
|
}
|
||||||
val readerState = state ?: currentState.value ?: return
|
val readerState = state ?: currentState.value ?: return
|
||||||
historyRepository.saveStateAsync(
|
historyRepository.saveStateAsync(
|
||||||
manga = mangaData.value ?: return,
|
manga = mangaData.value ?: return,
|
||||||
@@ -318,9 +317,11 @@ class ReaderViewModel @Inject constructor(
|
|||||||
|
|
||||||
chaptersLoader.loadSingleChapter(manga, requireNotNull(currentState.value).chapterId)
|
chaptersLoader.loadSingleChapter(manga, requireNotNull(currentState.value).chapterId)
|
||||||
// save state
|
// save state
|
||||||
currentState.value?.let {
|
if (!isIncognito) {
|
||||||
val percent = computePercent(it.chapterId, it.page)
|
currentState.value?.let {
|
||||||
historyRepository.addOrUpdate(manga, it.chapterId, it.page, it.scroll, percent)
|
val percent = computePercent(it.chapterId, it.page)
|
||||||
|
historyRepository.addOrUpdate(manga, it.chapterId, it.page, it.scroll, percent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
notifyStateChanged()
|
notifyStateChanged()
|
||||||
content.postValue(ReaderContent(chaptersLoader.snapshot(), currentState.value))
|
content.postValue(ReaderContent(chaptersLoader.snapshot(), currentState.value))
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_read"
|
|
||||||
android:title="@string/read_from_start" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
Reference in New Issue
Block a user