mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
list commits to open
This commit is contained in:
parent
25fda5771e
commit
385dc36dd3
@ -1,6 +1,8 @@
|
||||
package com.fastaccess.github.di.modules
|
||||
|
||||
import com.fastaccess.fasthub.commit.dialog.CommitListBottomSheetDialog
|
||||
import com.fastaccess.fasthub.dagger.scopes.PerFragment
|
||||
import com.fastaccess.github.base.dialog.IconDialogFragment
|
||||
import com.fastaccess.github.editor.dialog.CreateLinkDialogFragment
|
||||
import com.fastaccess.github.ui.modules.issuesprs.edit.labels.create.CreateLabelFragment
|
||||
import com.fastaccess.github.ui.modules.issuesprs.edit.milestone.CreateMilestoneDialogFragment
|
||||
@ -9,7 +11,6 @@ import com.fastaccess.github.ui.modules.multipurpose.MultiPurposeBottomSheetDial
|
||||
import com.fastaccess.github.ui.modules.quickmsg.QuickMessageBottomSheetDialog
|
||||
import com.fastaccess.github.ui.modules.search.filter.FilterSearchBottomSheet
|
||||
import com.fastaccess.github.ui.modules.trending.filter.FilterTrendingBottomSheet
|
||||
import com.fastaccess.github.base.dialog.IconDialogFragment
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
|
||||
@ -28,4 +29,5 @@ abstract class DialogFragmentBindingModule {
|
||||
@PerFragment @ContributesAndroidInjector abstract fun provideFilterTrendingBottomSheet(): FilterTrendingBottomSheet
|
||||
@PerFragment @ContributesAndroidInjector abstract fun provideCreateLinkDialogFragment(): CreateLinkDialogFragment
|
||||
@PerFragment @ContributesAndroidInjector abstract fun provideQuickMessageBottomSheetDialog(): QuickMessageBottomSheetDialog
|
||||
@PerFragment @ContributesAndroidInjector abstract fun provideCommitListBottomSheetDialog(): CommitListBottomSheetDialog
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.fastaccess.data.model.MainScreenModel
|
||||
import com.fastaccess.data.model.MainScreenModelRowType
|
||||
import com.fastaccess.data.persistence.models.FeedModel
|
||||
import com.fastaccess.domain.response.enums.EventsType
|
||||
import com.fastaccess.fasthub.commit.dialog.CommitListBottomSheetDialog
|
||||
import com.fastaccess.github.base.utils.FEEDS_LINK
|
||||
import com.fastaccess.github.base.utils.FILTER_ISSUE_LINK
|
||||
import com.fastaccess.github.base.utils.FILTER_PR_LINK
|
||||
@ -39,7 +40,17 @@ fun FeedModel.onClick(fragment: Fragment) {
|
||||
EventsType.PullRequestEvent -> fragment.route("${payload?.pullRequest?.htmlUrl}")
|
||||
EventsType.PullRequestReviewCommentEvent -> fragment.route("${payload?.pullRequest?.htmlUrl}")
|
||||
EventsType.PullRequestReviewEvent -> fragment.route("${payload?.pullRequest?.htmlUrl}")
|
||||
EventsType.PushEvent -> fragment.route("${payload?.commits?.getOrNull(0)?.url}")
|
||||
EventsType.PushEvent -> {
|
||||
payload?.commits?.let { list ->
|
||||
if (list.size > 1) {
|
||||
val m = payload?.commits?.associateBy({ it.sha?.take(7) ?: "" }, { it.url })
|
||||
CommitListBottomSheetDialog.show(fragment.childFragmentManager, m as HashMap<String, String>)
|
||||
} else {
|
||||
fragment.route(list[0].url)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else -> fragment.route(actor?.url) // TODO(handle click)
|
||||
}
|
||||
}
|
||||
@ -4,22 +4,24 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.fastaccess.data.model.FragmentType
|
||||
import com.fastaccess.fasthub.commit.dialog.CommitListCallback
|
||||
import com.fastaccess.github.R
|
||||
import com.fastaccess.github.base.BaseFragment
|
||||
import com.fastaccess.github.base.adapter.CurrentState
|
||||
import com.fastaccess.github.base.extensions.isConnected
|
||||
import com.fastaccess.github.base.viewmodel.ViewModelProviders
|
||||
import com.fastaccess.github.extensions.isTrue
|
||||
import com.fastaccess.github.extensions.observeNotNull
|
||||
import com.fastaccess.github.extensions.route
|
||||
import com.fastaccess.github.platform.extension.onClick
|
||||
import com.fastaccess.github.base.viewmodel.ViewModelProviders
|
||||
import com.fastaccess.github.ui.adapter.ProfileFeedsAdapter
|
||||
import com.fastaccess.github.base.adapter.CurrentState
|
||||
import com.fastaccess.github.ui.modules.feed.fragment.viewmodel.FeedsViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Created by Kosh on 20.10.18.
|
||||
*/
|
||||
class FeedsFragment : BaseFragment() {
|
||||
class FeedsFragment : BaseFragment(), CommitListCallback {
|
||||
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(FeedsViewModel::class.java) }
|
||||
@ -50,6 +52,10 @@ class FeedsFragment : BaseFragment() {
|
||||
listenToChanges()
|
||||
}
|
||||
|
||||
override fun onCommitClicked(url: String) {
|
||||
route(url)
|
||||
}
|
||||
|
||||
private fun listenToChanges() {
|
||||
viewModel.progress.observeNotNull(this) {
|
||||
adapter.currentState = if (it) CurrentState.LOADING else CurrentState.DONE
|
||||
|
||||
@ -8,9 +8,11 @@ import com.fastaccess.data.model.MainScreenModel
|
||||
import com.fastaccess.data.model.parcelable.EditIssuePrBundleModel
|
||||
import com.fastaccess.data.persistence.models.LoginModel
|
||||
import com.fastaccess.data.storage.FastHubSharedPreference
|
||||
import com.fastaccess.fasthub.commit.dialog.CommitListCallback
|
||||
import com.fastaccess.github.R
|
||||
import com.fastaccess.github.base.BaseFragment
|
||||
import com.fastaccess.github.base.BaseViewModel
|
||||
import com.fastaccess.github.base.dialog.IconDialogFragment
|
||||
import com.fastaccess.github.base.extensions.isConnected
|
||||
import com.fastaccess.github.base.extensions.otpCode
|
||||
import com.fastaccess.github.base.extensions.setBottomSheetCallback
|
||||
@ -19,14 +21,13 @@ import com.fastaccess.github.base.utils.LOGIN_DEEP_LINK
|
||||
import com.fastaccess.github.base.utils.NOTIFICATION_LINK
|
||||
import com.fastaccess.github.base.utils.SEARCH_LINK
|
||||
import com.fastaccess.github.base.utils.TRENDING_LINK
|
||||
import com.fastaccess.github.base.viewmodel.ViewModelProviders
|
||||
import com.fastaccess.github.extensions.*
|
||||
import com.fastaccess.github.platform.extension.onClick
|
||||
import com.fastaccess.github.base.viewmodel.ViewModelProviders
|
||||
import com.fastaccess.github.ui.adapter.MainScreenAdapter
|
||||
import com.fastaccess.github.ui.modules.issuesprs.edit.EditIssuePrActivity
|
||||
import com.fastaccess.github.ui.modules.main.fragment.viewmodel.MainFragmentViewModel
|
||||
import com.fastaccess.github.ui.modules.multipurpose.MultiPurposeBottomSheetDialog
|
||||
import com.fastaccess.github.base.dialog.IconDialogFragment
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import kotlinx.android.synthetic.main.bottm_bar_menu_layout.*
|
||||
import kotlinx.android.synthetic.main.main_fragment_layout.*
|
||||
@ -35,7 +36,7 @@ import javax.inject.Inject
|
||||
/**
|
||||
* Created by Kosh on 12.06.18.
|
||||
*/
|
||||
class MainFragment : BaseFragment(), IconDialogFragment.IconDialogClickListener {
|
||||
class MainFragment : BaseFragment(), IconDialogFragment.IconDialogClickListener, CommitListCallback {
|
||||
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
@Inject lateinit var preference: FastHubSharedPreference
|
||||
@ -91,6 +92,10 @@ class MainFragment : BaseFragment(), IconDialogFragment.IconDialogClickListener
|
||||
positive.isTrue { viewModel.logout() }
|
||||
}
|
||||
|
||||
override fun onCommitClicked(url: String) {
|
||||
route(url)
|
||||
}
|
||||
|
||||
private fun initClicks() {
|
||||
bottomBar.setNavigationOnClickListener { addDisposal(viewModel.login.subscribe({ route(it?.htmlUrl) }, ::print)) }
|
||||
bottomBar.setOnMenuItemClickListener { item ->
|
||||
|
||||
@ -4,24 +4,25 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.fastaccess.data.model.FragmentType
|
||||
import com.fastaccess.fasthub.commit.dialog.CommitListCallback
|
||||
import com.fastaccess.github.R
|
||||
import com.fastaccess.github.base.adapter.CurrentState
|
||||
import com.fastaccess.github.base.extensions.addDivider
|
||||
import com.fastaccess.github.base.extensions.isConnected
|
||||
import com.fastaccess.github.base.utils.EXTRA
|
||||
import com.fastaccess.github.base.viewmodel.ViewModelProviders
|
||||
import com.fastaccess.github.extensions.isTrue
|
||||
import com.fastaccess.github.extensions.observeNotNull
|
||||
import com.fastaccess.github.extensions.route
|
||||
import com.fastaccess.github.platform.extension.onClick
|
||||
import com.fastaccess.github.base.viewmodel.ViewModelProviders
|
||||
import com.fastaccess.github.ui.adapter.ProfileFeedsAdapter
|
||||
import com.fastaccess.github.base.adapter.CurrentState
|
||||
import com.fastaccess.github.ui.modules.profile.feeds.viewmodel.ProfileFeedsViewModel
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Created by Kosh on 20.10.18.
|
||||
*/
|
||||
class ProfileFeedFragment : com.fastaccess.github.base.BaseFragment() {
|
||||
class ProfileFeedFragment : com.fastaccess.github.base.BaseFragment(), CommitListCallback {
|
||||
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(ProfileFeedsViewModel::class.java) }
|
||||
@ -53,6 +54,10 @@ class ProfileFeedFragment : com.fastaccess.github.base.BaseFragment() {
|
||||
listenToChanges()
|
||||
}
|
||||
|
||||
override fun onCommitClicked(url: String) {
|
||||
route(url)
|
||||
}
|
||||
|
||||
private fun listenToChanges() {
|
||||
viewModel.progress.observeNotNull(this) {
|
||||
adapter.currentState = if (it) CurrentState.LOADING else CurrentState.DONE
|
||||
|
||||
@ -13,7 +13,11 @@ import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.fastaccess.github.base.extensions.setBottomSheetCallback
|
||||
import com.fastaccess.github.base.widget.ParentSwipeRefreshLayout
|
||||
import com.fastaccess.github.base.widget.recyclerview.BaseRecyclerView
|
||||
import com.fastaccess.github.base.widget.recyclerview.RecyclerViewFastScroller
|
||||
import com.fastaccess.github.extensions.observeNotNull
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
@ -35,7 +39,7 @@ abstract class BaseBottomSheetDialogFragment : BottomSheetDialogFragment(), HasA
|
||||
@Inject lateinit var childFragmentInjector: DispatchingAndroidInjector<Any>
|
||||
|
||||
private var disposal = CompositeDisposable()
|
||||
private var activityCallback: com.fastaccess.github.base.ActivityCallback? = null
|
||||
private var activityCallback: ActivityCallback? = null
|
||||
private var bottomSheetBehavior: BottomSheetBehavior<View>? = null
|
||||
|
||||
@LayoutRes abstract fun layoutRes(): Int
|
||||
@ -48,8 +52,8 @@ abstract class BaseBottomSheetDialogFragment : BottomSheetDialogFragment(), HasA
|
||||
AndroidSupportInjection.inject(this)
|
||||
super.onAttach(context)
|
||||
activityCallback = when {
|
||||
parentFragment is com.fastaccess.github.base.ActivityCallback -> parentFragment as com.fastaccess.github.base.ActivityCallback
|
||||
context is com.fastaccess.github.base.ActivityCallback -> context
|
||||
parentFragment is ActivityCallback -> parentFragment as ActivityCallback
|
||||
context is ActivityCallback -> context
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@ -149,4 +153,8 @@ abstract class BaseBottomSheetDialogFragment : BottomSheetDialogFragment(), HasA
|
||||
protected val emptyLayout by lazy { view?.findViewById<View>(R.id.emptyLayout) ?: throw IllegalAccessError("error") }
|
||||
protected val toolbarTitle by lazy { view?.findViewById<TextView>(R.id.toolbarTitle) ?: throw IllegalAccessError("error") }
|
||||
protected val tabs by lazy { view?.findViewById<TabLayout>(R.id.tabs) ?: throw IllegalAccessError("error") }
|
||||
protected val pager by lazy { view?.findViewById<ViewPager>(R.id.pager) ?: throw IllegalAccessError("error") }
|
||||
protected val recyclerView by lazy { view?.findViewById<BaseRecyclerView>(R.id.recyclerView) ?: throw IllegalAccessError("error") }
|
||||
protected val fastScroller by lazy { view?.findViewById<RecyclerViewFastScroller>(R.id.fastScroller) ?: throw IllegalAccessError("error") }
|
||||
protected val swipeRefresh by lazy { view?.findViewById<ParentSwipeRefreshLayout>(R.id.swipeRefresh) ?: throw IllegalAccessError("error") }
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.fastaccess.github.base.adapter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import com.fastaccess.github.base.R
|
||||
import kotlinx.android.synthetic.main.simple_text_row_item.view.*
|
||||
|
||||
class SimpleListAdapter<T>(
|
||||
private val onClick: (T) -> Unit
|
||||
) : ListAdapter<T, SimpleViewHolder<T>>(object : DiffUtil.ItemCallback<T>() {
|
||||
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean = oldItem.hashCode() == newItem.hashCode()
|
||||
|
||||
@SuppressLint("DiffUtilEquals")
|
||||
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean = oldItem == newItem
|
||||
}) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder<T> = SimpleViewHolder<T>(parent).apply {
|
||||
itemView.setOnClickListener {
|
||||
getItem(adapterPosition)?.let(onClick)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SimpleViewHolder<T>, position: Int) = holder.bind(getItem(position))
|
||||
}
|
||||
|
||||
class SimpleViewHolder<T>(parent: ViewGroup) : BaseViewHolder<T>(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.simple_text_row_item, parent, false)
|
||||
) {
|
||||
override fun bind(item: T) {
|
||||
itemView.textView.text = item.toString()
|
||||
}
|
||||
|
||||
}
|
||||
12
base/src/main/res/layout/simple_text_row_item.xml
Normal file
12
base/src/main/res/layout/simple_text_row_item.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.appcompat.widget.AppCompatTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:ellipsize="middle"
|
||||
android:maxLines="2"
|
||||
android:padding="@dimen/spacing_xs_large"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
|
||||
tools:text="this is a text" />
|
||||
@ -0,0 +1,66 @@
|
||||
package com.fastaccess.fasthub.commit.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.fastaccess.fasthub.commit.R
|
||||
import com.fastaccess.github.base.BaseBottomSheetDialogFragment
|
||||
import com.fastaccess.github.base.BaseViewModel
|
||||
import com.fastaccess.github.base.adapter.SimpleListAdapter
|
||||
import com.fastaccess.github.base.utils.EXTRA
|
||||
import com.fastaccess.github.extensions.show
|
||||
|
||||
class CommitListBottomSheetDialog : BaseBottomSheetDialogFragment() {
|
||||
|
||||
private var commitListCallback: CommitListCallback? = null
|
||||
private val map by lazy { arguments?.getSerializable(EXTRA) as? HashMap<String, String> }
|
||||
private val adapter by lazy {
|
||||
SimpleListAdapter<String> {
|
||||
commitListCallback?.onCommitClicked(map?.get(it) ?: "")
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
commitListCallback = when {
|
||||
parentFragment is CommitListCallback -> parentFragment as CommitListCallback
|
||||
context is CommitListCallback -> context
|
||||
else -> throw IllegalAccessError("your parent fragment or activity must implement CommitListCallback")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetach() {
|
||||
commitListCallback = null
|
||||
super.onDetach()
|
||||
}
|
||||
|
||||
override fun viewModel(): BaseViewModel? = null
|
||||
|
||||
override fun layoutRes(): Int = R.layout.rounded_toolbar_fragment_list_layout
|
||||
|
||||
override fun onFragmentCreatedWithUser(view: View, savedInstanceState: Bundle?) {
|
||||
setupToolbar(R.string.commits)
|
||||
swipeRefresh.isEnabled = false
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.setEmptyView(swipeRefresh, emptyLayout)
|
||||
fastScroller.attachRecyclerView(recyclerView)
|
||||
map?.let { adapter.submitList(it.keys.toList()) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun show(
|
||||
fragmentManager: FragmentManager,
|
||||
map: HashMap<String, String>
|
||||
) = CommitListBottomSheetDialog().apply {
|
||||
arguments = bundleOf().apply { putSerializable(EXTRA, map) }
|
||||
show(fragmentManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface CommitListCallback {
|
||||
fun onCommitClicked(url: String)
|
||||
}
|
||||
@ -42,7 +42,7 @@ class CommitFilesFragment : BaseFragment() {
|
||||
swipeRefresh.setOnRefreshListener {
|
||||
if (isConnected()) {
|
||||
recyclerView.resetScrollState()
|
||||
viewModel.loadFiles(sha, login, repo)
|
||||
viewModel.loadFiles(login, repo, sha)
|
||||
} else {
|
||||
swipeRefresh.isRefreshing = false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user