diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7f5a082..0e2ac4b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,6 +33,11 @@ android:screenOrientation="portrait" android:name=".issuelist.IssueListActivity_" /> + + diff --git a/app/src/main/java/br/com/luisfernandez/github/client/koin/ModelModule.kt b/app/src/main/java/br/com/luisfernandez/github/client/koin/ModelModule.kt index 001a183..2722a39 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/koin/ModelModule.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/koin/ModelModule.kt @@ -1,9 +1,9 @@ package br.com.luisfernandez.github.client.koin -import br.com.luisfernandez.github.client.issuelist.IssueListModel -import br.com.luisfernandez.github.client.issuelist.IssueListModelImpl -import br.com.luisfernandez.github.client.pullrequest.PullRequestModel -import br.com.luisfernandez.github.client.pullrequest.PullRequestModelImpl +import br.com.luisfernandez.github.client.repodetails.issuelist.IssueListModel +import br.com.luisfernandez.github.client.repodetails.issuelist.IssueListModelImpl +import br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestModel +import br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestModelImpl import br.com.luisfernandez.github.client.repolist.RepoListModel import br.com.luisfernandez.github.client.repolist.RepoListModelImpl import org.koin.dsl.module.module @@ -16,8 +16,8 @@ val modelModule = module { ) } - single { - PullRequestModelImpl( + single { + br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestModelImpl( get() ) } diff --git a/app/src/main/java/br/com/luisfernandez/github/client/koin/PresenterModule.kt b/app/src/main/java/br/com/luisfernandez/github/client/koin/PresenterModule.kt index 351922c..93d955b 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/koin/PresenterModule.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/koin/PresenterModule.kt @@ -1,7 +1,5 @@ package br.com.luisfernandez.github.client.koin -import br.com.luisfernandez.github.client.pullrequest.PullRequestPresenter -import br.com.luisfernandez.github.client.pullrequest.PullRequestPresenterImpl import br.com.luisfernandez.github.client.repolist.RepoListPresenter import br.com.luisfernandez.github.client.repolist.RepoListPresenterImpl import org.koin.dsl.module.module @@ -10,8 +8,4 @@ val presenterModule = module { single { RepoListPresenterImpl(get()) } - - single { - PullRequestPresenterImpl(get()) - } } diff --git a/app/src/main/java/br/com/luisfernandez/github/client/koin/ViewModelModule.kt b/app/src/main/java/br/com/luisfernandez/github/client/koin/ViewModelModule.kt index 0ecf3d6..246ec37 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/koin/ViewModelModule.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/koin/ViewModelModule.kt @@ -2,8 +2,8 @@ package br.com.luisfernandez.github.client.koin -import br.com.luisfernandez.github.client.issuelist.IssueListViewModel -import br.com.luisfernandez.github.client.pullrequest.PullRequestViewModel +import br.com.luisfernandez.github.client.repodetails.issuelist.IssueListViewModel +import br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestViewModel import br.com.luisfernandez.github.client.repolist.RepoListViewModel import org.koin.android.viewmodel.ext.koin.viewModel import org.koin.dsl.module.module @@ -16,8 +16,8 @@ val viewModelModule = module { ) } - viewModel { - PullRequestViewModel( + viewModel { + br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestViewModel( get() ) } diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestPresenter.kt b/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestPresenter.kt deleted file mode 100644 index 2c48931..0000000 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestPresenter.kt +++ /dev/null @@ -1,9 +0,0 @@ -package br.com.luisfernandez.github.client.pullrequest - -/** - * Created by luisfernandez on 12/05/18. - */ -interface PullRequestPresenter { - fun loadPullRequestList(owner: String, repoName: String) - fun inject(pullRequestView: PullRequestListView) -} \ No newline at end of file diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestPresenterImpl.kt b/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestPresenterImpl.kt deleted file mode 100644 index 4919f77..0000000 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestPresenterImpl.kt +++ /dev/null @@ -1,36 +0,0 @@ -package br.com.luisfernandez.github.client.pullrequest - -import br.com.luisfernandez.github.client.http.CallbackWrapper -import br.com.luisfernandez.github.client.http.model.GitHubErrorBody -import br.com.luisfernandez.github.client.http.model.ServerError -import br.com.luisfernandez.github.client.pojo.PullRequestResponse -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.schedulers.Schedulers - -class PullRequestPresenterImpl ( - private val pullRequestModel: PullRequestModel -) : PullRequestPresenter -{ - - private lateinit var view: PullRequestListView - - override fun inject(view: PullRequestListView) { - this.view = view - } - - override fun loadPullRequestList(owner: String, repoName: String) { - pullRequestModel - .loadPullRequestList(owner, repoName) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(object: CallbackWrapper, GitHubErrorBody>(GitHubErrorBody::class.java) { - override fun onError(error: ServerError) { - view.handleError(error) - } - - override fun onSuccess(pullRequestList: List) { - view.showContent(pullRequestList) - } - }) - } -} \ No newline at end of file diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repodetails/BranchesFragment.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/BranchesFragment.kt new file mode 100644 index 0000000..204ec0e --- /dev/null +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/BranchesFragment.kt @@ -0,0 +1,21 @@ +package br.com.luisfernandez.github.client.repodetails + + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import br.com.luisfernandez.github.client.R + +class BranchesFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.fragment_branches, container, false) + } + + +} diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repodetails/CollaboratorsFragment.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/CollaboratorsFragment.kt new file mode 100644 index 0000000..22b6fab --- /dev/null +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/CollaboratorsFragment.kt @@ -0,0 +1,21 @@ +package br.com.luisfernandez.github.client.repodetails + + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import br.com.luisfernandez.github.client.R + +class CollaboratorsFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.fragment_collaborators, container, false) + } + + +} diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repodetails/CommitsFragment.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/CommitsFragment.kt new file mode 100644 index 0000000..fc7122b --- /dev/null +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/CommitsFragment.kt @@ -0,0 +1,21 @@ +package br.com.luisfernandez.github.client.repodetails + + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import br.com.luisfernandez.github.client.R + +class CommitsFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.fragment_commits, container, false) + } + + +} diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repodetails/RepoDetailsActivity.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/RepoDetailsActivity.kt new file mode 100644 index 0000000..61fcfbe --- /dev/null +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/RepoDetailsActivity.kt @@ -0,0 +1,45 @@ +package br.com.luisfernandez.github.client.repodetails + +import android.annotation.SuppressLint +import android.support.v7.app.AppCompatActivity +import br.com.luisfernandez.github.client.R +import kotlinx.android.synthetic.main.activity_repo_details.* +import org.androidannotations.annotations.AfterViews +import org.androidannotations.annotations.EActivity +import org.androidannotations.annotations.Extra + +@SuppressLint("Registered") +@EActivity(R.layout.activity_repo_details) +class RepoDetailsActivity : AppCompatActivity() { + + @Extra + lateinit var owner: String + + @Extra + lateinit var repoName: String + + @AfterViews + fun afterViews() { + this.configToolbar() + + val fragmentAdapter = RepoDetailsPagerAdapter(this, supportFragmentManager, owner, repoName) + viewPagerRepoDetail.adapter = fragmentAdapter + + tabLayoutRepoDetail.setupWithViewPager(viewPagerRepoDetail) + } + + private fun configToolbar() { + setSupportActionBar(toolbar) + supportActionBar?.let { + title = repoName + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowHomeEnabled(true) + supportActionBar?.setDisplayShowTitleEnabled(true) + } + } + + override fun onSupportNavigateUp(): Boolean { + onBackPressed() + return true + } +} diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repodetails/RepoDetailsPagerAdapter.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/RepoDetailsPagerAdapter.kt new file mode 100644 index 0000000..0ea97da --- /dev/null +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/RepoDetailsPagerAdapter.kt @@ -0,0 +1,59 @@ +package br.com.luisfernandez.github.client.repodetails + +import android.content.Context +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager +import android.support.v4.app.FragmentPagerAdapter +import br.com.luisfernandez.github.client.R +import br.com.luisfernandez.github.client.repodetails.issuelist.IssuesListFragment +import br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestListFragment + +class RepoDetailsPagerAdapter(private val context: Context, fm: FragmentManager, owner: String, repoName: String): + FragmentPagerAdapter(fm) { + + companion object { + const val OWNER = "OWNER" + const val REPONAME = "REPONAME" + } + + val owner = owner + val repoName = repoName + + override fun getCount(): Int { + return 5 + } + + override fun getItem(position: Int): Fragment { + val bundle = Bundle() + bundle.putString(OWNER, owner) + bundle.putString(REPONAME, repoName) + + var fragment = when(position) { + 0 -> PullRequestListFragment() + 1 -> IssuesListFragment() + 2 -> CommitsFragment() + 3 -> CollaboratorsFragment() + 4 -> BranchesFragment() + + else -> PullRequestListFragment() + } + + fragment.arguments = bundle + + return fragment + } + + override fun getPageTitle(position: Int): CharSequence? { + return when(position){ + 0 -> context.getString(R.string.titlePullRequestsTab) + 1 -> context.getString(R.string.titleIssuesTab) + 2 -> context.getString(R.string.titleCommitsTab) + 3 -> context.getString(R.string.titleCollaboratorsTab) + 4 -> context.getString(R.string.titleBranchesTab) + + else -> context.getString(R.string.titlePullRequestsTab) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListAdapter.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListAdapter.kt similarity index 96% rename from app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListAdapter.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListAdapter.kt index 145f1d5..5a0e58c 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListAdapter.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListAdapter.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.issuelist +package br.com.luisfernandez.github.client.repodetails.issuelist import android.support.v7.widget.RecyclerView import android.view.LayoutInflater diff --git a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListModel.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListModel.kt similarity index 79% rename from app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListModel.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListModel.kt index bf28b06..76ac5c5 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListModel.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListModel.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.issuelist +package br.com.luisfernandez.github.client.repodetails.issuelist import br.com.luisfernandez.github.client.pojo.IssueResponse import io.reactivex.Observable diff --git a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListModelImpl.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListModelImpl.kt similarity index 88% rename from app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListModelImpl.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListModelImpl.kt index f47063d..48a3cf0 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListModelImpl.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListModelImpl.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.issuelist +package br.com.luisfernandez.github.client.repodetails.issuelist import br.com.luisfernandez.github.client.http.GitHubService import br.com.luisfernandez.github.client.pojo.IssueResponse diff --git a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListView.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListView.kt similarity index 83% rename from app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListView.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListView.kt index 6ddda1a..bf9c886 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListView.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListView.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.issuelist +package br.com.luisfernandez.github.client.repodetails.issuelist import br.com.luisfernandez.github.client.http.model.GitHubErrorBody import br.com.luisfernandez.github.client.mvp.LoadContentView diff --git a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListViewModel.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListViewModel.kt similarity index 95% rename from app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListViewModel.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListViewModel.kt index 50147c5..2498ee6 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListViewModel.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssueListViewModel.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.issuelist +package br.com.luisfernandez.github.client.repodetails.issuelist import android.arch.lifecycle.MutableLiveData import android.arch.lifecycle.ViewModel diff --git a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListActivity.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssuesListFragment.kt similarity index 71% rename from app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListActivity.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssuesListFragment.kt index eab0573..8b64d56 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/issuelist/IssueListActivity.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/issuelist/IssuesListFragment.kt @@ -1,48 +1,55 @@ -package br.com.luisfernandez.github.client.issuelist +package br.com.luisfernandez.github.client.repodetails.issuelist -import android.annotation.SuppressLint import android.arch.lifecycle.Observer -import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v4.app.Fragment import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import br.com.luisfernandez.github.client.R import br.com.luisfernandez.github.client.extensions.setGone import br.com.luisfernandez.github.client.extensions.setVisible import br.com.luisfernandez.github.client.http.model.GitHubErrorBody import br.com.luisfernandez.github.client.http.model.ServerError import br.com.luisfernandez.github.client.pojo.IssueResponse -import kotlinx.android.synthetic.main.activity_list.* +import br.com.luisfernandez.github.client.repodetails.RepoDetailsPagerAdapter.Companion.OWNER +import br.com.luisfernandez.github.client.repodetails.RepoDetailsPagerAdapter.Companion.REPONAME +import kotlinx.android.synthetic.main.fragment_issues_list.* import kotlinx.android.synthetic.main.view_state_empty.* import kotlinx.android.synthetic.main.view_state_error.* import kotlinx.android.synthetic.main.view_state_loading.* -import org.androidannotations.annotations.AfterViews -import org.androidannotations.annotations.EActivity -import org.androidannotations.annotations.Extra import org.koin.android.viewmodel.ext.android.viewModel -@SuppressLint("Registered") -@EActivity(R.layout.activity_issues_list) -class IssueListActivity : AppCompatActivity(), IssueListView { +class IssuesListFragment : Fragment(), IssueListView { - @Extra lateinit var owner: String - - @Extra lateinit var repoName: String - val viewModel by viewModel() - @AfterViews - fun afterViews() { - this.configToolbar() + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val layoutManager = LinearLayoutManager(this) + val rootView = inflater.inflate(R.layout.fragment_issues_list, container, false) - recyclerView.layoutManager = layoutManager + val recyclerView = rootView.findViewById(R.id.recyclerView) as RecyclerView + + recyclerView.layoutManager = LinearLayoutManager(rootView.context) recyclerView.setHasFixedSize(true) + setupArguments() + setupViewModel() viewModel.loadIssueList(owner, repoName) + + return rootView + + } + + private fun setupArguments() { + owner = arguments!!.getString(OWNER) + repoName = arguments!!.getString(REPONAME) } private fun setupViewModel() { @@ -57,21 +64,6 @@ class IssueListActivity : AppCompatActivity(), IssueListView { }) } - private fun configToolbar() { - setSupportActionBar(toolbar) - supportActionBar?.let { - title = repoName - supportActionBar?.setDisplayHomeAsUpEnabled(true) - supportActionBar?.setDisplayShowHomeEnabled(true) - supportActionBar?.setDisplayShowTitleEnabled(true) - } - } - - override fun onSupportNavigateUp(): Boolean { - onBackPressed() - return true - } - override fun handleError(serverError: ServerError) { this.showErrorState() diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListAdapter.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListAdapter.kt similarity index 75% rename from app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListAdapter.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListAdapter.kt index 2d87858..0fafa9b 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListAdapter.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListAdapter.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.pullrequest +package br.com.luisfernandez.github.client.repodetails.pullrequest import android.support.v7.widget.RecyclerView import android.view.LayoutInflater @@ -18,18 +18,18 @@ import java.util.* class PullRequestListAdapter( private val pullRequestList: ArrayList = ArrayList(), private val onItemClickListener: OnItemClickListener -) : RecyclerView.Adapter() +) : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PullRequestViewHolder { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestListAdapter.PullRequestViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.item_pull_request_list, parent, false) - return PullRequestViewHolder(view) + return br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestListAdapter.PullRequestViewHolder(view) } override fun getItemCount(): Int { return pullRequestList.size } - override fun onBindViewHolder(holder: PullRequestViewHolder, position: Int) { + override fun onBindViewHolder(holder: br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestListAdapter.PullRequestViewHolder, position: Int) { val item = pullRequestList[position] diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListActivity.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListFragment.kt similarity index 73% rename from app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListActivity.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListFragment.kt index 5b1b519..259159c 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListActivity.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListFragment.kt @@ -1,57 +1,64 @@ -package br.com.luisfernandez.github.client.pullrequest +package br.com.luisfernandez.github.client.repodetails.pullrequest -import android.annotation.SuppressLint import android.arch.lifecycle.Observer import android.content.Intent import android.net.Uri -import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v4.app.Fragment import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import br.com.luisfernandez.github.client.OnItemClickListener import br.com.luisfernandez.github.client.R import br.com.luisfernandez.github.client.extensions.setGone import br.com.luisfernandez.github.client.extensions.setVisible -import br.com.luisfernandez.github.client.http.model.ServerError import br.com.luisfernandez.github.client.http.model.GitHubErrorBody +import br.com.luisfernandez.github.client.http.model.ServerError import br.com.luisfernandez.github.client.pojo.PullRequestResponse -import kotlinx.android.synthetic.main.activity_list.* +import br.com.luisfernandez.github.client.repodetails.RepoDetailsPagerAdapter.Companion.OWNER +import br.com.luisfernandez.github.client.repodetails.RepoDetailsPagerAdapter.Companion.REPONAME +import kotlinx.android.synthetic.main.fragment_issues_list.* import kotlinx.android.synthetic.main.view_state_empty.* import kotlinx.android.synthetic.main.view_state_error.* import kotlinx.android.synthetic.main.view_state_loading.* -import org.androidannotations.annotations.AfterViews -import org.androidannotations.annotations.EActivity -import org.androidannotations.annotations.Extra import org.koin.android.viewmodel.ext.android.viewModel -@SuppressLint("Registered") -@EActivity(R.layout.activity_pull_request_list) -class PullRequestListActivity : AppCompatActivity(), PullRequestListView { +class PullRequestListFragment : Fragment(), PullRequestListView { - @Extra lateinit var owner: String - - @Extra lateinit var repoName: String - val viewModel by viewModel() - @AfterViews - fun afterViews() { - this.configToolbar() + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val layoutManager = LinearLayoutManager(this) + val rootView = inflater.inflate(R.layout.fragment_pull_request_list, container, false) - recyclerView.layoutManager = layoutManager + val recyclerView = rootView.findViewById(R.id.recyclerView) as RecyclerView + + recyclerView.layoutManager = LinearLayoutManager(rootView.context) recyclerView.setHasFixedSize(true) -// + + setupArguments() + setupViewModel() viewModel.loadPullRequestList(owner, repoName) + + return rootView + + } + + private fun setupArguments() { + owner = arguments!!.getString(OWNER) + repoName = arguments!!.getString(REPONAME) } private fun setupViewModel() { viewModel.listPullRequest.observe(this, Observer { - listPullRequest -> - showContent(listPullRequest!!) + issueList -> + showContent(issueList!!) }) viewModel.serverError.observe(this, Observer { @@ -60,21 +67,6 @@ class PullRequestListActivity : AppCompatActivity(), PullRequestListView { }) } - private fun configToolbar() { - setSupportActionBar(toolbar) - supportActionBar?.let { - title = repoName - supportActionBar?.setDisplayHomeAsUpEnabled(true) - supportActionBar?.setDisplayShowHomeEnabled(true) - supportActionBar?.setDisplayShowTitleEnabled(true) - } - } - - override fun onSupportNavigateUp(): Boolean { - onBackPressed() - return true - } - override fun handleError(serverError: ServerError) { this.showErrorState() diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListView.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListView.kt similarity index 83% rename from app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListView.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListView.kt index 04b620b..d431c94 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestListView.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestListView.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.pullrequest +package br.com.luisfernandez.github.client.repodetails.pullrequest import br.com.luisfernandez.github.client.http.model.GitHubErrorBody import br.com.luisfernandez.github.client.mvp.LoadContentView diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestModel.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestModel.kt similarity index 80% rename from app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestModel.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestModel.kt index b5fe021..12f4fc6 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestModel.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestModel.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.pullrequest +package br.com.luisfernandez.github.client.repodetails.pullrequest import br.com.luisfernandez.github.client.pojo.PullRequestResponse import io.reactivex.Observable diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestModelImpl.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestModelImpl.kt similarity index 78% rename from app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestModelImpl.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestModelImpl.kt index 380b04e..52ba316 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestModelImpl.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestModelImpl.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.pullrequest +package br.com.luisfernandez.github.client.repodetails.pullrequest import br.com.luisfernandez.github.client.http.GitHubService import br.com.luisfernandez.github.client.pojo.PullRequestResponse @@ -6,7 +6,7 @@ import io.reactivex.Observable class PullRequestModelImpl ( private val gitHubService: GitHubService -) : PullRequestModel +) : br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestModel { override fun loadPullRequestList(owner: String, repoName: String): Observable> { return gitHubService diff --git a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestViewModel.kt b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestViewModel.kt similarity index 88% rename from app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestViewModel.kt rename to app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestViewModel.kt index e47256e..f23296f 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/pullrequest/PullRequestViewModel.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repodetails/pullrequest/PullRequestViewModel.kt @@ -1,4 +1,4 @@ -package br.com.luisfernandez.github.client.pullrequest +package br.com.luisfernandez.github.client.repodetails.pullrequest import android.arch.lifecycle.MutableLiveData import android.arch.lifecycle.ViewModel @@ -10,7 +10,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers class PullRequestViewModel ( - private val pullRequestModel: PullRequestModel + private val pullRequestModel: br.com.luisfernandez.github.client.repodetails.pullrequest.PullRequestModel ) : ViewModel() { diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListActivity.kt b/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListActivity.kt index 7862933..9e551a1 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListActivity.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListActivity.kt @@ -12,9 +12,8 @@ import br.com.luisfernandez.github.client.extensions.setGone import br.com.luisfernandez.github.client.extensions.setVisible import br.com.luisfernandez.github.client.http.model.GitHubErrorBody import br.com.luisfernandez.github.client.http.model.ServerError -import br.com.luisfernandez.github.client.issuelist.IssueListActivity_ import br.com.luisfernandez.github.client.pojo.Repo -import br.com.luisfernandez.github.client.pullrequest.PullRequestListActivity_ +import br.com.luisfernandez.github.client.repodetails.RepoDetailsActivity_ import com.crashlytics.android.answers.Answers import com.crashlytics.android.answers.SearchEvent import com.miguelcatalan.materialsearchview.MaterialSearchView @@ -24,7 +23,6 @@ import kotlinx.android.synthetic.main.view_state_error.* import kotlinx.android.synthetic.main.view_state_loading.* import org.androidannotations.annotations.AfterViews import org.androidannotations.annotations.EActivity -import org.koin.android.ext.android.inject import org.koin.android.viewmodel.ext.android.viewModel @@ -120,23 +118,14 @@ class RepoListActivity : AppCompatActivity(), RepoListView { private fun getRepoListAdapter(): RepoListAdapter { return RepoListAdapter( getOnItemClickListener(), - getOnLoadMoreContentClickListener(), - getOnIssueClickListener() + getOnLoadMoreContentClickListener() ) } private fun getOnItemClickListener(): OnItemClickListener { return object : OnItemClickListener { override fun onItemClick(type: Repo) { - goToPullRequestActivity(type) - } - } - } - - private fun getOnIssueClickListener(): OnItemClickListener { - return object : OnItemClickListener { - override fun onItemClick(type: Repo) { - goToIssueListActivity(type) + goToRepoDetailsActivity(type) } } } @@ -149,16 +138,8 @@ class RepoListActivity : AppCompatActivity(), RepoListView { } } - private fun goToPullRequestActivity(type: Repo) { - PullRequestListActivity_ - .intent(this@RepoListActivity) - .owner(type.owner.login) - .repoName(type.name) - .start() - } - - private fun goToIssueListActivity(type: Repo) { - IssueListActivity_ + private fun goToRepoDetailsActivity(type: Repo) { + RepoDetailsActivity_ .intent(this@RepoListActivity) .owner(type.owner.login) .repoName(type.name) diff --git a/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListAdapter.kt b/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListAdapter.kt index c5d85fe..9572f80 100644 --- a/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListAdapter.kt +++ b/app/src/main/java/br/com/luisfernandez/github/client/repolist/RepoListAdapter.kt @@ -18,8 +18,7 @@ import kotlin.collections.ArrayList */ class RepoListAdapter( private val onItemClickListener: OnItemClickListener, - private val onRetryClickListener: OnItemClickListener, - private val onIssueClickListener: OnItemClickListener + private val onRetryClickListener: OnItemClickListener ) : RecyclerView.Adapter() { companion object { @@ -76,10 +75,6 @@ class RepoListAdapter( viewHolder.itemView.setOnClickListener { _ -> onItemClickListener.onItemClick(repo) } - - viewHolder.textIssuesCount.setOnClickListener { _ -> - onIssueClickListener.onItemClick(repo) - } } ERROR_FOOTER -> { val errorFooterHolder = viewHolder as ErrorFooterViewHolder diff --git a/app/src/main/res/layout/activity_repo_details.xml b/app/src/main/res/layout/activity_repo_details.xml new file mode 100644 index 0000000..46f8ff9 --- /dev/null +++ b/app/src/main/res/layout/activity_repo_details.xml @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_branches.xml b/app/src/main/res/layout/fragment_branches.xml new file mode 100644 index 0000000..20a29b3 --- /dev/null +++ b/app/src/main/res/layout/fragment_branches.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_collaborators.xml b/app/src/main/res/layout/fragment_collaborators.xml new file mode 100644 index 0000000..6f5a920 --- /dev/null +++ b/app/src/main/res/layout/fragment_collaborators.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_commits.xml b/app/src/main/res/layout/fragment_commits.xml new file mode 100644 index 0000000..8be10b1 --- /dev/null +++ b/app/src/main/res/layout/fragment_commits.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_pull_request_list.xml b/app/src/main/res/layout/fragment_issues_list.xml similarity index 66% rename from app/src/main/res/layout/activity_pull_request_list.xml rename to app/src/main/res/layout/fragment_issues_list.xml index 9c199fd..74f93f1 100644 --- a/app/src/main/res/layout/activity_pull_request_list.xml +++ b/app/src/main/res/layout/fragment_issues_list.xml @@ -1,15 +1,9 @@ - - + xmlns:tools="http://schemas.android.com/tools" + android:animateLayoutChanges="true" + tools:context=".repodetails.issuelist.IssuesListFragment"> - - "Ohh no!\n%s is an invalid language\nPlease query a valid language ;)" TRY AGAIN + PullRequests + Issues + Commits + Collaborators + Branches