Skip to content

Commit

Permalink
Bug fixes , download page redesign , new theme(Emerald) (#95)
Browse files Browse the repository at this point in the history
* Restart option when choosing custom theme
Typo fix
Extension page bug fix

* Downloaded manga page redesign(lol)

* quick fix

* New theme(Emerald)
Fine-tuned colors.xml

* Toggle for list view and compact view in downloaded manga and novels (much more)
  • Loading branch information
aayush2622 authored Dec 26, 2023
1 parent 5339593 commit eb75d29
Show file tree
Hide file tree
Showing 15 changed files with 762 additions and 449 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package ani.dantotsu.download.manga

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.cardview.widget.CardView
import ani.dantotsu.R
Expand All @@ -32,10 +34,18 @@ class OfflineMangaAdapter(
return position.toLong()
}

@SuppressLint("SetTextI18n")
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {

val style = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)

var view = convertView
if (view == null) {
view = inflater.inflate(R.layout.item_media_compact, parent, false)

if (view == null && style == 0 ) {
view = inflater.inflate(R.layout.item_media_large, parent, false) // large view
}
else if (view == null && style == 1){
view = inflater.inflate(R.layout.item_media_compact, parent, false) // compact view
}

val item = getItem(position) as OfflineMangaModel
Expand All @@ -44,11 +54,31 @@ class OfflineMangaAdapter(
val itemScore = view.findViewById<TextView>(R.id.itemCompactScore)
val itemScoreBG = view.findViewById<View>(R.id.itemCompactScoreBG)
val ongoing = view.findViewById<CardView>(R.id.itemCompactOngoing)
val totalchapter = view.findViewById<TextView>(R.id.itemCompactTotal)
val type = view.findViewById<TextView>(R.id.itemCompactRelation)
val typeView = view.findViewById<LinearLayout>(R.id.itemCompactType)

if (style == 0){
val bannerView = view.findViewById<ImageView>(R.id.itemCompactBanner) // for large view
val chapters = view.findViewById<TextView>(R.id.itemTotal)
chapters.text = " Chapters"
bannerView.setImageURI(item.banner)
totalchapter.text = item.totalchapter
}

else if (style == 1){
val readchapter = view.findViewById<TextView>(R.id.itemCompactUserProgress) // for compact view
readchapter.text = item.readchapter
totalchapter.text = " | "+item.totalchapter
}

// Bind item data to the views
// For example:
type.text = item.type
typeView.visibility = View.VISIBLE
imageView.setImageURI(item.image)
titleTextView.text = item.title
itemScore.text = item.score

if (item.isOngoing) {
ongoing.visibility = View.VISIBLE
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ani.dantotsu.download.manga

import android.animation.ObjectAnimator
import android.content.Context
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Build
Expand All @@ -16,17 +17,23 @@ import android.view.ViewGroup
import android.view.animation.OvershootInterpolator
import android.widget.AutoCompleteTextView
import android.widget.GridView
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import androidx.core.app.ActivityCompat.recreate
import androidx.fragment.app.Fragment
import ani.dantotsu.R
import ani.dantotsu.Refresh
import ani.dantotsu.currActivity
import ani.dantotsu.currContext
import ani.dantotsu.download.Download
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.initActivity
import ani.dantotsu.logger
import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.SettingsActivity
import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
Expand All @@ -45,6 +52,7 @@ import kotlin.math.max
import kotlin.math.min

class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {

private val downloadManager = Injekt.get<DownloadsManager>()
private var downloads: List<OfflineMangaModel> = listOf()
private lateinit var gridView: GridView
Expand Down Expand Up @@ -91,15 +99,49 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
override fun afterTextChanged(s: Editable?) {
}

override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int, ) {
}

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
onSearchQuery(s.toString())
}
})
var style = context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getInt("offline_view", 0)
val layoutList = view.findViewById<ImageView>(R.id.downloadedList)
val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid)
var selected = when (style) {
0 -> layoutList
1 -> layoutcompact
else -> layoutList
}
selected.alpha = 1f

fun selected(it: ImageView) {
selected.alpha = 0.33f
selected = it
selected.alpha = 1f
}

layoutList.setOnClickListener {
selected(it as ImageView)
style = 0
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
?.putInt("offline_view", style!!)?.apply()
recreate(requireActivity())

gridView = view.findViewById(R.id.gridView)
}

layoutcompact.setOnClickListener {
selected(it as ImageView)
style = 1
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
?.putInt("offline_view", style!!)?.apply()
recreate(requireActivity())
}

gridView = if(style == 0) view.findViewById(R.id.gridView) else view.findViewById(R.id.gridView1)
gridView.visibility = View.VISIBLE
getDownloads()
adapter = OfflineMangaAdapter(requireContext(), downloads, this)
gridView.adapter = adapter
Expand Down Expand Up @@ -286,20 +328,25 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
val cover = File(directory, "cover.jpg")
val coverUri: Uri? = if (cover.exists()) {
Uri.fromFile(cover)
} else {
null
}
} else null
val banner = File(directory, "banner.jpg")
val bannerUri: Uri? = if (banner.exists()) {
Uri.fromFile(banner)
} else null
val title = mediaModel.nameMAL ?: mediaModel.nameRomaji
val score = ((if (mediaModel.userScore == 0) (mediaModel.meanScore
?: 0) else mediaModel.userScore) / 10.0).toString()
val isOngoing = false
val isOngoing = mediaModel.status == currActivity()!!.getString(R.string.status_releasing)
val isUserScored = mediaModel.userScore != 0
return OfflineMangaModel(title, score, isOngoing, isUserScored, coverUri)
val readchapter = (mediaModel.userProgress ?: "~").toString()
val totalchapter = "${mediaModel.manga?.totalChapters ?: "??"}"
val chapters = " Chapters"
return OfflineMangaModel(title, score, totalchapter, readchapter, type, chapters, isOngoing, isUserScored, coverUri , bannerUri )
} catch (e: Exception) {
logger("Error loading media.json: ${e.message}")
logger(e.printStackTrace())
FirebaseCrashlytics.getInstance().recordException(e)
return OfflineMangaModel("unknown", "0", false, false, null)
return OfflineMangaModel("unknown", "0", "??", "??","movie" ,"hmm", false, false, null , null)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import android.net.Uri
data class OfflineMangaModel(
val title: String,
val score: String,
val totalchapter: String,
val readchapter : String,
val type: String,
val chapters: String,
val isOngoing: Boolean,
val isUserScored: Boolean,
val image: Uri?
val image: Uri?,
val banner: Uri?
)
2 changes: 1 addition & 1 deletion app/src/main/java/ani/dantotsu/media/MediaAdaptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MediaAdaptor(
val media = mediaList?.get(position)
if (media != null) {
b.itemCompactImage.loadImage(media.cover)
b.itemCompactBanner.loadImage(media.banner ?: media.cover, 400)
b.itemCompactBanner.loadImage(media.banner ?: media.cover)
b.itemCompactOngoing.visibility =
if (media.status == currActivity()!!.getString(R.string.status_releasing)) View.VISIBLE else View.GONE
b.itemCompactTitle.text = media.userPreferredName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ani.dantotsu.settings

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.NotificationManager
import android.content.Context
Expand Down Expand Up @@ -49,6 +50,19 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
private val animeExtensionManager: AnimeExtensionManager = Injekt.get()
private val extensionsAdapter = AnimeExtensionsAdapter(
{ pkg ->
val name= pkg.name
val changeUIVisibility: (Boolean) -> Unit = { show ->
val activity = requireActivity() as ExtensionsActivity
val visibility = if (show) View.VISIBLE else View.GONE
activity.findViewById<ViewPager2>(R.id.viewPager).visibility = visibility
activity.findViewById<TabLayout>(R.id.tabLayout).visibility = visibility
activity.findViewById<TextInputLayout>(R.id.searchView).visibility = visibility
activity.findViewById<ImageView>(R.id.languageselect).visibility = visibility
activity.findViewById<TextView>(R.id.extensions).text = if (show) getString(R.string.extensions) else name
activity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
if (show) View.GONE else View.VISIBLE
}
var itemSelected = false
val allSettings = pkg.sources.filterIsInstance<ConfigurableAnimeSource>()
if (allSettings.isNotEmpty()) {
var selectedSetting = allSettings[0]
Expand All @@ -58,65 +72,44 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Select a Source")
.setSingleChoiceItems(names, selectedIndex) { dialog, which ->
itemSelected = true
selectedIndex = which
selectedSetting = allSettings[selectedIndex]
dialog.dismiss()

// Move the fragment transaction here
val eActivity = requireActivity() as ExtensionsActivity
eActivity.runOnUiThread {
val fragment =
AnimeSourcePreferencesFragment().getInstance(selectedSetting.id) {

eActivity.findViewById<ViewPager2>(R.id.viewPager).visibility =
View.VISIBLE
eActivity.findViewById<TabLayout>(R.id.tabLayout).visibility =
View.VISIBLE
eActivity.findViewById<TextInputLayout>(R.id.searchView).visibility =
View.VISIBLE
eActivity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
View.GONE
}
parentFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.replace(R.id.fragmentExtensionsContainer, fragment)
.addToBackStack(null)
.commit()
val fragment =
AnimeSourcePreferencesFragment().getInstance(selectedSetting.id) {
changeUIVisibility(true)
}
parentFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.replace(R.id.fragmentExtensionsContainer, fragment)
.addToBackStack(null)
.commit()
}
.setOnDismissListener {
if (!itemSelected) {
changeUIVisibility(true)
}
}
.show()
dialog.window?.setDimAmount(0.8f)
} else {
// If there's only one setting, proceed with the fragment transaction
val eActivity = requireActivity() as ExtensionsActivity
eActivity.runOnUiThread {
val fragment =
AnimeSourcePreferencesFragment().getInstance(selectedSetting.id) {
val fragment =
AnimeSourcePreferencesFragment().getInstance(selectedSetting.id) {
changeUIVisibility(true)
}
parentFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.replace(R.id.fragmentExtensionsContainer, fragment)
.addToBackStack(null)
.commit()

eActivity.findViewById<ViewPager2>(R.id.viewPager).visibility =
View.VISIBLE
eActivity.findViewById<TabLayout>(R.id.tabLayout).visibility =
View.VISIBLE
eActivity.findViewById<TextInputLayout>(R.id.searchView).visibility =
View.VISIBLE
eActivity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
View.GONE
}
parentFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.replace(R.id.fragmentExtensionsContainer, fragment)
.addToBackStack(null)
.commit()
}
}

// Hide ViewPager2 and TabLayout
val activity = requireActivity() as ExtensionsActivity
activity.findViewById<ViewPager2>(R.id.viewPager).visibility = View.GONE
activity.findViewById<TabLayout>(R.id.tabLayout).visibility = View.GONE
activity.findViewById<TextInputLayout>(R.id.searchView).visibility = View.GONE
activity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
View.VISIBLE
changeUIVisibility(false)
} else {
Toast.makeText(requireContext(), "Source is not configurable", Toast.LENGTH_SHORT)
.show()
Expand Down Expand Up @@ -225,6 +218,7 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
return ViewHolder(view)
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val extension = getItem(position) // Use getItem() from ListAdapter
val nsfw = if (extension.isNsfw) "(18+)" else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
val skipIcons = loadData("skip_extension_icons") ?: false
private val mangaExtensionManager: MangaExtensionManager = Injekt.get()
private val extensionsAdapter = MangaExtensionsAdapter({ pkg ->
val name= pkg.name
val changeUIVisibility: (Boolean) -> Unit = { show ->
val activity = requireActivity() as ExtensionsActivity
val visibility = if (show) View.VISIBLE else View.GONE
activity.findViewById<ViewPager2>(R.id.viewPager).visibility = visibility
activity.findViewById<TabLayout>(R.id.tabLayout).visibility = visibility
activity.findViewById<TextInputLayout>(R.id.searchView).visibility = visibility
activity.findViewById<ImageView>(R.id.languageselect).visibility = visibility
activity.findViewById<TextView>(R.id.extensions).text = if (show) getString(R.string.extensions) else name
activity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
if (show) View.GONE else View.VISIBLE
}
var itemSelected = false
val allSettings = pkg.sources.filterIsInstance<ConfigurableSource>()
if (allSettings.isNotEmpty()) {
var selectedSetting = allSettings[0]
Expand All @@ -65,6 +69,7 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
val dialog = AlertDialog.Builder(requireContext(), R.style.MyPopup)
.setTitle("Select a Source")
.setSingleChoiceItems(names, selectedIndex) { dialog, which ->
itemSelected = true
selectedIndex = which
selectedSetting = allSettings[selectedIndex]
dialog.dismiss()
Expand All @@ -80,6 +85,11 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
.addToBackStack(null)
.commit()
}
.setOnDismissListener {
if (!itemSelected) {
changeUIVisibility(true)
}
}
.show()
dialog.window?.setDimAmount(0.8f)
} else {
Expand Down
Loading

0 comments on commit eb75d29

Please sign in to comment.