-
Notifications
You must be signed in to change notification settings - Fork 7
Feature/channel first impl #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fabiosassu-sysdata
wants to merge
12
commits into
develop
Choose a base branch
from
feature/channel_first_impl
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b74e54c
first implementation of channel (To be updated)
39a2c53
Merge branch 'feature/feature_fixes_and_docs_update' into feature/cha…
fabiosassu-sysdata 1c9778b
refactoring channel
b4e56b5
updated documentation
c019bb8
fixed error in case of placeholder enabled for base datasources
d1db98c
added test mock datasource
a73065e
updated channel implementation
4e884b2
moved datasource outside of interactor
c707fb6
- added copyright
sranieri 8a901d6
added copyright and comments
eea3609
updated readme
26d8608
Merge branch 'develop' into feature/channel_first_impl
fabiosassu-sysdata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/sysdata/kt/ktandroidarchitecture/DIUtils.kt
This file contains hidden or 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 com.sysdata.kt.ktandroidarchitecture | ||
|
|
||
| import com.sysdata.kt.ktandroidarchitecture.repository.AuthRepository | ||
| import com.sysdata.kt.ktandroidarchitecture.ui.Note | ||
| import it.sysdata.ktandroidarchitecturecore.interactor.Channel | ||
|
|
||
| class DIUtils { | ||
|
|
||
| private object Holder { | ||
| val INSTANCE = Channel<Note>() | ||
| } | ||
|
|
||
| companion object { | ||
| val channel: Channel<Note> by lazy { | ||
| Holder.INSTANCE | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/sysdata/kt/ktandroidarchitecture/ui/Note.kt
This file contains hidden or 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 com.sysdata.kt.ktandroidarchitecture.ui | ||
|
|
||
| import androidx.recyclerview.widget.DiffUtil | ||
| import java.util.* | ||
|
|
||
| data class Note(val index:Int, val noteId: String = UUID.randomUUID().toString()) { | ||
| companion object { | ||
| val DiffCallback = object : DiffUtil.ItemCallback<Note>() { | ||
| override fun areItemsTheSame(oldItem: Note, newItem: Note): Boolean | ||
| = oldItem.noteId == newItem.noteId | ||
|
|
||
| override fun areContentsTheSame(oldItem: Note, newItem: Note): Boolean | ||
| = oldItem.noteId == newItem.noteId && oldItem.title == newItem.title && oldItem.content == newItem.content | ||
| } | ||
| } | ||
| var title: String = "" | ||
| var content: String = "" | ||
| } |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/sysdata/kt/ktandroidarchitecture/ui/NoteDataSource.kt
This file contains hidden or 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,5 @@ | ||
| package com.sysdata.kt.ktandroidarchitecture.ui | ||
|
|
||
| import it.sysdata.ktandroidarchitecturecore.BasePositionalDatasource | ||
|
|
||
| class NoteDataSource: BasePositionalDatasource<Note>() |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/sysdata/kt/ktandroidarchitecture/ui/PagedListAdapterImpl.kt
This file contains hidden or 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,37 @@ | ||
| package com.sysdata.kt.ktandroidarchitecture.ui | ||
|
|
||
| import android.util.Log | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import android.widget.TextView | ||
| import androidx.paging.PagedListAdapter | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.sysdata.kt.ktandroidarchitecture.R | ||
|
|
||
| class PagedListAdapterImpl(val onClick: (Note) -> Unit) : PagedListAdapter<Note, PagedListAdapterImpl.ListItemViewHolder>(Note.DiffCallback) { | ||
| class ListItemViewHolder(val view: View): RecyclerView.ViewHolder(view) { | ||
| var note: Note? = null | ||
| set(value) { | ||
| if(value != null){ | ||
| val tv: TextView = view.findViewById(R.id.itemText) | ||
| tv.text = value.toString() | ||
| } | ||
| field = value | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private val TAG = this::class.java.simpleName | ||
| } | ||
|
|
||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListItemViewHolder | ||
| = ListItemViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.note_list_item, parent, false)) | ||
|
|
||
| override fun onBindViewHolder(holder: ListItemViewHolder, position: Int) { | ||
| Log.d(TAG, "Binding view holder at position $position") | ||
| holder.note = getItem(position) | ||
| holder.view.setOnClickListener { onClick(holder.note!!) } | ||
| } | ||
|
|
||
| } |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/sysdata/kt/ktandroidarchitecture/ui/TestDataSource.kt
This file contains hidden or 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,58 @@ | ||
| package com.sysdata.kt.ktandroidarchitecture.ui | ||
|
|
||
| import androidx.paging.ItemKeyedDataSource | ||
|
|
||
| class TestDataSource: ItemKeyedDataSource<Int, Note>(){ | ||
|
|
||
| private val datas = listOf(Note(1), Note(2), Note(3), Note(4), Note(5)) | ||
|
|
||
| override fun loadInitial(params: LoadInitialParams<Int>, callback: LoadInitialCallback<Note>) { | ||
| val requestedLoadSize = params.requestedLoadSize | ||
| val requestedInitialKey = params.requestedInitialKey ?: 0 | ||
|
|
||
| val initItem = datas.firstOrNull { it.index == requestedInitialKey } | ||
| val initIndex = initItem?.let {datas.indexOf(initItem)} ?: 0 | ||
| val newData = getSubList(initIndex, initIndex + requestedLoadSize) | ||
| callback.onResult(newData) | ||
| } | ||
|
|
||
| private fun getSubList(initIndex: Int, finalIndex: Int): MutableList<Note> { | ||
| val newData = mutableListOf<Note>() | ||
| for (i in initIndex until finalIndex) { | ||
| newData.add(datas[i % datas.size]) | ||
| } | ||
| return newData | ||
| } | ||
|
|
||
| override fun loadAfter(params: LoadParams<Int>, callback: LoadCallback<Note>) { | ||
| val key = params.key | ||
| val requestedLoadSize = params.requestedLoadSize | ||
|
|
||
| val initItem = datas.firstOrNull { it.index == key } | ||
| val initIndex = initItem?.let {datas.indexOf(initItem)} ?: 0 | ||
| val newData = getSubList(initIndex, initIndex + requestedLoadSize) | ||
| callback.onResult(newData) | ||
| } | ||
|
|
||
| override fun loadBefore(params: LoadParams<Int>, callback: LoadCallback<Note>) { | ||
| val key = params.key | ||
| val requestedLoadSize = params.requestedLoadSize | ||
|
|
||
| val initItem = datas.firstOrNull { it.index == key } | ||
| var initIndex = initItem?.let {datas.indexOf(initItem)} ?: 0 | ||
| var finalIndex = initIndex | ||
| if(initIndex - requestedLoadSize >= 0){ | ||
| initIndex -= requestedLoadSize | ||
| } else { | ||
| initIndex = 0 | ||
| finalIndex = initIndex + requestedLoadSize | ||
| } | ||
| val newData = getSubList(initIndex, finalIndex) | ||
| callback.onResult(newData) | ||
| } | ||
|
|
||
| override fun getKey(item: Note): Int { | ||
| return item.index | ||
| } | ||
|
|
||
| } |
12 changes: 11 additions & 1 deletion
12
app/src/main/java/com/sysdata/kt/ktandroidarchitecture/viewmodel/LoginViewModel.kt
This file contains hidden or 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,15 +1,25 @@ | ||
| package com.sysdata.kt.ktandroidarchitecture.viewmodel | ||
|
|
||
| import com.sysdata.kt.ktandroidarchitecture.DIUtils | ||
| import com.sysdata.kt.ktandroidarchitecture.repository.model.UIUserLogged | ||
| import com.sysdata.kt.ktandroidarchitecture.repository.model.UserLogged | ||
| import com.sysdata.kt.ktandroidarchitecture.ui.Note | ||
| import com.sysdata.kt.ktandroidarchitecture.ui.NoteDataSource | ||
| import com.sysdata.kt.ktandroidarchitecture.ui.TestDataSource | ||
| import com.sysdata.kt.ktandroidarchitecture.usecase.LoginActionParams | ||
| import com.sysdata.kt.ktandroidarchitecture.usecase.LoginUseCase | ||
| import it.sysdata.ktandroidarchitecturecore.interactor.Action | ||
| import it.sysdata.ktandroidarchitecturecore.interactor.* | ||
| import it.sysdata.ktandroidarchitecturecore.platform.BaseViewModel | ||
|
|
||
| class LoginViewModel: BaseViewModel() { | ||
|
|
||
| val actionLogin = Action.Builder<LoginActionParams,UserLogged, UIUserLogged>() | ||
| .useCase(LoginUseCase::class.java) | ||
| .buildWithUiModel { UIUserLogged(it.username) } | ||
|
|
||
| val channelNotes = DataSourceChannel.Builder<Int, Note>() | ||
| .dataSource(TestDataSource::class.java) | ||
| .build() | ||
|
|
||
| val channelPostNotes = DIUtils.channel | ||
| } |
This file contains hidden or 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 hidden or 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"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/itemText" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:textSize="16sp" | ||
| android:padding="8dp" | ||
| android:textColor="#000" | ||
| /> | ||
|
|
||
| </LinearLayout> |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.