-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added manga reader and network security configs. Also changed bottom …
…bar a little
- Loading branch information
Showing
21 changed files
with
321 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../divyansh/tech/animeclassroom/manga/screens/mangaDetail/callbacks/MangaDetailCallbacks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package divyansh.tech.animeclassroom.manga.screens.mangaDetail.callbacks | ||
|
||
import divyansh.tech.animeclassroom.manga.screens.mangaDetail.MangaDetailFragment | ||
import divyansh.tech.animeclassroom.manga.screens.mangaDetail.MangaDetailFragmentDirections | ||
import divyansh.tech.animeclassroom.manga.screens.mangaDetail.MangaDetailViewModel | ||
import divyansh.tech.animeclassroom.mangaModels.Chapters | ||
|
||
class MangaDetailCallbacks( | ||
private val mangaDetailViewModel: MangaDetailViewModel | ||
) { | ||
|
||
fun onChapterClick(chapters: Chapters, mangaName: String) { | ||
val action = MangaDetailFragmentDirections.actionMangaDetailFragmentToMangaPlayerFragment( | ||
chapterName = chapters.chapterName, | ||
chapterUrl = chapters.chapterUrl, | ||
mangaName = mangaName | ||
) | ||
mangaDetailViewModel.changeNavigation(action) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...c/main/java/divyansh/tech/animeclassroom/manga/screens/mangaPlayer/MangaPlayerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,77 @@ | ||
package divyansh.tech.animeclassroom.manga.screens.mangaPlayer | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.Observer | ||
import androidx.navigation.fragment.findNavController | ||
import androidx.navigation.fragment.navArgs | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import divyansh.tech.animeclassroom.EventObserver | ||
import divyansh.tech.animeclassroom.databinding.FragmentMangaPlayerBinding | ||
import divyansh.tech.animeclassroom.manga.screens.mangaPlayer.epoxy.EpoxyMangaPlayerController | ||
|
||
@AndroidEntryPoint | ||
class MangaPlayerFragment: Fragment() { | ||
|
||
private lateinit var _binding: FragmentMangaPlayerBinding | ||
val binding get() = _binding | ||
|
||
private val viewModel by viewModels<MangaPlayerViewModel>() | ||
|
||
private val args by navArgs<MangaPlayerFragmentArgs>() | ||
|
||
private val controller by lazy { | ||
EpoxyMangaPlayerController() | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
_binding = FragmentMangaPlayerBinding.inflate(inflater, container, false) | ||
binding.mangaToolbar.title.text = args.mangaName + " - " + args.chapterName | ||
binding.mangaToolbar.goBack.setOnClickListener { findNavController().popBackStack() } | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setupRecyclerView() | ||
setupObservers() | ||
} | ||
|
||
private fun setupRecyclerView() { | ||
binding.mangaPlayerRv.apply { | ||
layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) | ||
adapter = controller.adapter | ||
} | ||
} | ||
|
||
private fun setupObservers() { | ||
|
||
viewModel.mangaChapterItemLiveData.observe( | ||
viewLifecycleOwner, | ||
Observer { | ||
controller.setData(it) | ||
} | ||
) | ||
|
||
viewModel.navigation.observe( | ||
viewLifecycleOwner, | ||
EventObserver { | ||
findNavController().navigate(it) | ||
} | ||
) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
viewModel.getChapterItems(args.chapterUrl) | ||
} | ||
} |
28 changes: 27 additions & 1 deletion
28
.../main/java/divyansh/tech/animeclassroom/manga/screens/mangaPlayer/MangaPlayerViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
package divyansh.tech.animeclassroom.manga.screens.mangaPlayer | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import divyansh.tech.animeclassroom.ResultWrapper | ||
import divyansh.tech.animeclassroom.common.CommonViewModel | ||
import divyansh.tech.animeclassroom.di.DispatcherModule | ||
import divyansh.tech.animeclassroom.mangaPlayer.MangaPlayerDefaultRepo | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MangaPlayerViewModel @Inject constructor(): CommonViewModel() { | ||
class MangaPlayerViewModel @Inject constructor( | ||
private val repo: MangaPlayerDefaultRepo, | ||
@DispatcherModule.IODispatcher private val coroutineDispatcher: CoroutineDispatcher | ||
): CommonViewModel() { | ||
|
||
private val _mangaChapterItemsLiveData = MutableLiveData<ArrayList<String>>() | ||
val mangaChapterItemLiveData get() = _mangaChapterItemsLiveData | ||
|
||
fun getChapterItems(url: String) { | ||
viewModelScope.launch(coroutineDispatcher) { | ||
val response = repo.getMangaChapter(url) | ||
response.collect { | ||
if (it is ResultWrapper.Success) | ||
_mangaChapterItemsLiveData.postValue(it.data as ArrayList<String>) | ||
else Log.i("MANGA PLAYER -> ", it.message.toString()) | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ivyansh/tech/animeclassroom/manga/screens/mangaPlayer/epoxy/EpoxyMangaPlayerController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package divyansh.tech.animeclassroom.manga.screens.mangaPlayer.epoxy | ||
|
||
import com.airbnb.epoxy.TypedEpoxyController | ||
|
||
class EpoxyMangaPlayerController(): TypedEpoxyController<ArrayList<String>>() { | ||
override fun buildModels(data: ArrayList<String>?) { | ||
data?.let { | ||
it.forEach { | ||
epoxyMangaPlayer { | ||
id(it) | ||
imageUrl(it) | ||
} | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ava/divyansh/tech/animeclassroom/manga/screens/mangaPlayer/epoxy/EpoxyMangaPlayerModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package divyansh.tech.animeclassroom.manga.screens.mangaPlayer.epoxy | ||
|
||
import androidx.databinding.ViewDataBinding | ||
import com.airbnb.epoxy.DataBindingEpoxyModel | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import com.airbnb.epoxy.databinding.BR | ||
import divyansh.tech.animeclassroom.R | ||
|
||
@EpoxyModelClass(layout = R.layout.recycler_manga_player_item) | ||
abstract class EpoxyMangaPlayerModel: DataBindingEpoxyModel() { | ||
@EpoxyAttribute | ||
lateinit var imageUrl: String | ||
|
||
override fun setDataBindingVariables(binding: ViewDataBinding) { | ||
binding.setVariable(BR.imageUrl, imageUrl) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<data /> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" | ||
> | ||
|
||
<include | ||
android:id="@+id/mangaToolbar" | ||
layout="@layout/toolbar_layout_general" | ||
/> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:layout_height="0dp" | ||
android:layout_width="match_parent" | ||
android:id="@+id/mangaPlayerRv" | ||
app:layout_constraintTop_toBottomOf="@id/mangaToolbar" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintStart_toStartOf="@+id/startGuideline" | ||
app:layout_constraintEnd_toEndOf="@+id/endGuideline" | ||
/> | ||
|
||
<include | ||
layout="@layout/guideline_views" | ||
/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<data> | ||
<variable | ||
name="imageUrl" | ||
type="String" | ||
/> | ||
</data> | ||
<androidx.appcompat.widget.AppCompatImageView | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" | ||
android:scaleType="fitXY" | ||
imageUrl="@{imageUrl}" | ||
/> | ||
</layout> |
Oops, something went wrong.