mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2026-01-25 14:47:05 +00:00
This commit impl project cards list for repos. WIP for cards
This commit is contained in:
parent
e406010e39
commit
bfc2fc4952
@ -44,6 +44,7 @@ import com.fastaccess.ui.modules.repos.extras.branches.BranchesFragment;
|
||||
import com.fastaccess.ui.modules.repos.issues.issue.RepoClosedIssuesFragment;
|
||||
import com.fastaccess.ui.modules.repos.issues.issue.RepoOpenedIssuesFragment;
|
||||
import com.fastaccess.ui.modules.repos.issues.issue.details.timeline.IssueTimelineFragment;
|
||||
import com.fastaccess.ui.modules.repos.projects.list.RepoProjectFragment;
|
||||
import com.fastaccess.ui.modules.repos.pull_requests.pull_request.RepoPullRequestFragment;
|
||||
import com.fastaccess.ui.modules.repos.pull_requests.pull_request.details.commits.PullRequestCommitsFragment;
|
||||
import com.fastaccess.ui.modules.repos.pull_requests.pull_request.details.files.PullRequestFilesFragment;
|
||||
@ -230,4 +231,15 @@ import lombok.Setter;
|
||||
BranchesFragment.Companion.newInstance(login, repoId, false)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@NonNull public static List<FragmentPagerAdapterModel> buildForRepoProjects(@NonNull Context context, @NonNull String repoId,
|
||||
@NonNull String login) {
|
||||
return Stream.of(new FragmentPagerAdapterModel(context.getString(R.string.open),
|
||||
RepoProjectFragment.Companion.newInstance(login, repoId, IssueState.open)),
|
||||
new FragmentPagerAdapterModel(context.getString(R.string.closed),
|
||||
RepoProjectFragment.Companion.newInstance(login, repoId, IssueState.closed)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
165
app/src/main/java/com/fastaccess/data/dao/ProjectsModel.java
Normal file
165
app/src/main/java/com/fastaccess/data/dao/ProjectsModel.java
Normal file
@ -0,0 +1,165 @@
|
||||
package com.fastaccess.data.dao;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.fastaccess.data.dao.model.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
|
||||
public class ProjectsModel implements Parcelable {
|
||||
private String ownerUrl;
|
||||
private String url;
|
||||
private String htmlUrl;
|
||||
private String columnsUrl;
|
||||
private int id;
|
||||
private String name;
|
||||
private String body;
|
||||
private int number;
|
||||
private String state;
|
||||
private User creator;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
|
||||
public String getOwnerUrl() {
|
||||
return ownerUrl;
|
||||
}
|
||||
|
||||
public void setOwnerUrl(String ownerUrl) {
|
||||
this.ownerUrl = ownerUrl;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getHtmlUrl() {
|
||||
return htmlUrl;
|
||||
}
|
||||
|
||||
public void setHtmlUrl(String htmlUrl) {
|
||||
this.htmlUrl = htmlUrl;
|
||||
}
|
||||
|
||||
public String getColumnsUrl() {
|
||||
return columnsUrl;
|
||||
}
|
||||
|
||||
public void setColumnsUrl(String columnsUrl) {
|
||||
this.columnsUrl = columnsUrl;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public User getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setCreator(User creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
@Override public int describeContents() { return 0; }
|
||||
|
||||
@Override public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(this.ownerUrl);
|
||||
dest.writeString(this.url);
|
||||
dest.writeString(this.htmlUrl);
|
||||
dest.writeString(this.columnsUrl);
|
||||
dest.writeInt(this.id);
|
||||
dest.writeString(this.name);
|
||||
dest.writeString(this.body);
|
||||
dest.writeInt(this.number);
|
||||
dest.writeString(this.state);
|
||||
dest.writeParcelable(this.creator, flags);
|
||||
dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1);
|
||||
dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1);
|
||||
}
|
||||
|
||||
public ProjectsModel() {}
|
||||
|
||||
protected ProjectsModel(Parcel in) {
|
||||
this.ownerUrl = in.readString();
|
||||
this.url = in.readString();
|
||||
this.htmlUrl = in.readString();
|
||||
this.columnsUrl = in.readString();
|
||||
this.id = in.readInt();
|
||||
this.name = in.readString();
|
||||
this.body = in.readString();
|
||||
this.number = in.readInt();
|
||||
this.state = in.readString();
|
||||
this.creator = in.readParcelable(User.class.getClassLoader());
|
||||
long tmpCreatedAt = in.readLong();
|
||||
this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
|
||||
long tmpUpdatedAt = in.readLong();
|
||||
this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<ProjectsModel> CREATOR = new Parcelable.Creator<ProjectsModel>() {
|
||||
@Override public ProjectsModel createFromParcel(Parcel source) {return new ProjectsModel(source);}
|
||||
|
||||
@Override public ProjectsModel[] newArray(int size) {return new ProjectsModel[size];}
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.fastaccess.data.service
|
||||
|
||||
import com.fastaccess.data.dao.Pageable
|
||||
import com.fastaccess.data.dao.ProjectsModel
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
|
||||
interface ProjectsService {
|
||||
|
||||
@GET("repos/{owner}/{repo}/projects")
|
||||
@Headers("Accept: application/vnd.github.inertia-preview+json")
|
||||
fun getRepoProjects(@Path("owner") owner: String, @Path("repo") repo: String,
|
||||
@Query("state") state: String?, @Query("page") page: Int): Observable<Pageable<ProjectsModel>>
|
||||
|
||||
@GET("orgs/{org}/projects")
|
||||
@Headers("Accept: application/vnd.github.inertia-preview+json")
|
||||
fun getOrgsProjects(@Path("org") org: String,
|
||||
@Query("page") page: Int): Observable<Pageable<ProjectsModel>>
|
||||
|
||||
}
|
||||
@ -18,6 +18,7 @@ import com.fastaccess.data.service.GistService;
|
||||
import com.fastaccess.data.service.IssueService;
|
||||
import com.fastaccess.data.service.NotificationService;
|
||||
import com.fastaccess.data.service.OrganizationService;
|
||||
import com.fastaccess.data.service.ProjectsService;
|
||||
import com.fastaccess.data.service.PullRequestService;
|
||||
import com.fastaccess.data.service.ReactionsService;
|
||||
import com.fastaccess.data.service.RepoService;
|
||||
@ -192,6 +193,10 @@ public class RestProvider {
|
||||
return provideRetrofit(enterprise).create(ContentService.class);
|
||||
}
|
||||
|
||||
@NonNull public static ProjectsService getProjectsService(boolean enterprise) {
|
||||
return provideRetrofit(enterprise).create(ProjectsService.class);
|
||||
}
|
||||
|
||||
@Nullable public static GitHubErrorResponse getErrorResponse(@NonNull Throwable throwable) {
|
||||
ResponseBody body = null;
|
||||
if (throwable instanceof HttpException) {
|
||||
|
||||
@ -144,12 +144,13 @@ public class TableHandler extends TagNodeHandler {
|
||||
|
||||
int rowHeight = 0;
|
||||
|
||||
for (Spanned cell : row) {
|
||||
StaticLayout layout = new StaticLayout(cell, textPaint, columnWidth
|
||||
- 2 * PADDING, Alignment.ALIGN_NORMAL, 1f, 0f, true);
|
||||
|
||||
if (layout.getHeight() > rowHeight) {
|
||||
rowHeight = layout.getHeight();
|
||||
if (columnWidth > 0) {
|
||||
for (Spanned cell : row) {
|
||||
StaticLayout layout = new StaticLayout(cell, textPaint, columnWidth
|
||||
- 2 * PADDING, Alignment.ALIGN_NORMAL, 1f, 0f, true);
|
||||
if (layout.getHeight() > rowHeight) {
|
||||
rowHeight = layout.getHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.fastaccess.ui.adapter
|
||||
|
||||
import android.view.ViewGroup
|
||||
import com.fastaccess.data.dao.ProjectsModel
|
||||
import com.fastaccess.ui.adapter.viewholder.ProjectViewHolder
|
||||
import com.fastaccess.ui.widgets.recyclerview.BaseRecyclerAdapter
|
||||
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
class ProjectsAdapter(data: ArrayList<ProjectsModel>) :
|
||||
BaseRecyclerAdapter<ProjectsModel, ProjectViewHolder, BaseViewHolder.OnItemClickListener<ProjectsModel>>(data) {
|
||||
|
||||
override fun viewHolder(parent: ViewGroup, viewType: Int): ProjectViewHolder = ProjectViewHolder.newInstance(parent, this)
|
||||
|
||||
override fun onBindView(holder: ProjectViewHolder?, position: Int) {
|
||||
holder?.bind(data[position])
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.fastaccess.ui.adapter.viewholder
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import butterknife.BindView
|
||||
import com.fastaccess.R
|
||||
import com.fastaccess.data.dao.ProjectsModel
|
||||
import com.fastaccess.helper.ParseDateFormat
|
||||
import com.fastaccess.ui.widgets.FontTextView
|
||||
import com.fastaccess.ui.widgets.recyclerview.BaseRecyclerAdapter
|
||||
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
class ProjectViewHolder(view: View, adapter: BaseRecyclerAdapter<*, *, *>) : BaseViewHolder<ProjectsModel>(view, adapter) {
|
||||
|
||||
@BindView(R.id.description) lateinit var description: FontTextView
|
||||
@BindView(R.id.title) lateinit var title: FontTextView
|
||||
@BindView(R.id.date) lateinit var date: FontTextView
|
||||
|
||||
override fun bind(t: ProjectsModel) {
|
||||
title.text = t.name
|
||||
if (t.body.isNullOrBlank()) {
|
||||
description.visibility = View.GONE
|
||||
} else {
|
||||
description.visibility = View.VISIBLE
|
||||
description.text = t.body
|
||||
}
|
||||
if (t.updatedAt == null) {
|
||||
date.text = ParseDateFormat.getTimeAgo(t.createdAt)
|
||||
} else {
|
||||
date.text = ParseDateFormat.getTimeAgo(t.updatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(parent: ViewGroup, adapter: BaseRecyclerAdapter<*, *, *>): ProjectViewHolder {
|
||||
return ProjectViewHolder(getView(parent, R.layout.feeds_row_no_image_item), adapter)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,12 +24,14 @@ public interface RepoPagerMvp {
|
||||
int CODE = 0;
|
||||
int ISSUES = 1;
|
||||
int PULL_REQUEST = 2;
|
||||
int PROFILE = 3;
|
||||
int PROJECTS = 3;
|
||||
int PROFILE = 4;
|
||||
|
||||
@IntDef({
|
||||
CODE,
|
||||
ISSUES,
|
||||
PULL_REQUEST,
|
||||
PROJECTS,
|
||||
PROFILE
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE) @interface RepoNavigationType {}
|
||||
|
||||
@ -18,6 +18,7 @@ import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import com.fastaccess.ui.modules.repos.code.RepoCodePagerFragment;
|
||||
import com.fastaccess.ui.modules.repos.issues.RepoIssuesPagerFragment;
|
||||
import com.fastaccess.ui.modules.repos.projects.RepoProjectsFragmentPager;
|
||||
import com.fastaccess.ui.modules.repos.pull_requests.RepoPullRequestPagerFragment;
|
||||
|
||||
import static com.fastaccess.helper.ActivityHelper.getVisibleFragment;
|
||||
@ -185,6 +186,8 @@ class RepoPagerPresenter extends BasePresenter<RepoPagerMvp.View> implements Rep
|
||||
AppHelper.getFragmentByTag(fragmentManager, RepoIssuesPagerFragment.TAG);
|
||||
RepoPullRequestPagerFragment pullRequestPagerView = (RepoPullRequestPagerFragment)
|
||||
AppHelper.getFragmentByTag(fragmentManager, RepoPullRequestPagerFragment.TAG);
|
||||
RepoProjectsFragmentPager projectsFragmentPager = (RepoProjectsFragmentPager) AppHelper.getFragmentByTag(fragmentManager,
|
||||
RepoProjectsFragmentPager.Companion.getTAG());
|
||||
if (getRepo() == null) {
|
||||
sendToView(RepoPagerMvp.View::onFinishActivity);
|
||||
return;
|
||||
@ -219,6 +222,13 @@ class RepoPagerPresenter extends BasePresenter<RepoPagerMvp.View> implements Rep
|
||||
onShowHideFragment(fragmentManager, pullRequestPagerView, currentVisible);
|
||||
}
|
||||
break;
|
||||
case RepoPagerMvp.PROJECTS:
|
||||
if (projectsFragmentPager == null) {
|
||||
onAddAndHide(fragmentManager, RepoProjectsFragmentPager.Companion.newInstance(repoId(), login()), currentVisible);
|
||||
} else {
|
||||
onShowHideFragment(fragmentManager, projectsFragmentPager, currentVisible);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
package com.fastaccess.ui.modules.repos.projects
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.TabLayout
|
||||
import android.view.View
|
||||
import butterknife.BindView
|
||||
import com.fastaccess.R
|
||||
import com.fastaccess.data.dao.FragmentPagerAdapterModel
|
||||
import com.fastaccess.helper.BundleConstant
|
||||
import com.fastaccess.helper.Bundler
|
||||
import com.fastaccess.ui.adapter.FragmentsPagerAdapter
|
||||
import com.fastaccess.ui.base.BaseFragment
|
||||
import com.fastaccess.ui.base.mvp.BaseMvp
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter
|
||||
import com.fastaccess.ui.widgets.ViewPagerView
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
class RepoProjectsFragmentPager : BaseFragment<BaseMvp.FAView, BasePresenter<BaseMvp.FAView>>() {
|
||||
|
||||
@BindView(R.id.tabs) lateinit var tabs: TabLayout
|
||||
@BindView(R.id.pager) lateinit var pager: ViewPagerView
|
||||
|
||||
override fun fragmentLayout(): Int = R.layout.centered_tabbed_viewpager
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
pager.adapter = FragmentsPagerAdapter(childFragmentManager, FragmentPagerAdapterModel.buildForRepoProjects(context,
|
||||
arguments.getString(BundleConstant.EXTRA), arguments.getString(BundleConstant.ID)))
|
||||
tabs.setupWithViewPager(pager)
|
||||
}
|
||||
|
||||
override fun providePresenter(): BasePresenter<BaseMvp.FAView> = BasePresenter()
|
||||
|
||||
companion object {
|
||||
val TAG = RepoProjectsFragmentPager::class.java.simpleName
|
||||
fun newInstance(login: String, repoId: String): RepoProjectsFragmentPager {
|
||||
val fragment = RepoProjectsFragmentPager()
|
||||
fragment.arguments = Bundler.start()
|
||||
.put(BundleConstant.ID, repoId)
|
||||
.put(BundleConstant.EXTRA, login)
|
||||
.end()
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
package com.fastaccess.ui.modules.repos.projects.list
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.annotation.StringRes
|
||||
import android.support.v4.widget.SwipeRefreshLayout
|
||||
import android.view.View
|
||||
import butterknife.BindView
|
||||
import com.fastaccess.R
|
||||
import com.fastaccess.data.dao.ProjectsModel
|
||||
import com.fastaccess.data.dao.types.IssueState
|
||||
import com.fastaccess.helper.BundleConstant
|
||||
import com.fastaccess.helper.Bundler
|
||||
import com.fastaccess.provider.rest.loadmore.OnLoadMore
|
||||
import com.fastaccess.ui.adapter.ProjectsAdapter
|
||||
import com.fastaccess.ui.base.BaseFragment
|
||||
import com.fastaccess.ui.widgets.StateLayout
|
||||
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView
|
||||
import com.fastaccess.ui.widgets.recyclerview.scroll.RecyclerViewFastScroller
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
|
||||
class RepoProjectFragment : BaseFragment<RepoProjectMvp.View, RepoProjectPresenter>(), RepoProjectMvp.View {
|
||||
|
||||
@BindView(R.id.recycler) lateinit var recycler: DynamicRecyclerView
|
||||
@BindView(R.id.refresh) lateinit var refresh: SwipeRefreshLayout
|
||||
@BindView(R.id.stateLayout) lateinit var stateLayout: StateLayout
|
||||
@BindView(R.id.fastScroller) lateinit var fastScroller: RecyclerViewFastScroller
|
||||
private var onLoadMore: OnLoadMore<IssueState>? = null
|
||||
private val adapter by lazy { ProjectsAdapter(presenter.getProjects()) }
|
||||
|
||||
|
||||
override fun providePresenter(): RepoProjectPresenter = RepoProjectPresenter()
|
||||
|
||||
override fun onNotifyAdapter(items: List<ProjectsModel>?, page: Int) {
|
||||
hideProgress()
|
||||
if (items == null || items.isEmpty()) {
|
||||
adapter.clear()
|
||||
return
|
||||
}
|
||||
if (page <= 1) {
|
||||
adapter.insertItems(items)
|
||||
} else {
|
||||
adapter.addItems(items)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLoadMore(): OnLoadMore<IssueState> {
|
||||
if (onLoadMore == null) {
|
||||
onLoadMore = OnLoadMore<IssueState>(presenter)
|
||||
}
|
||||
onLoadMore!!.parameter = getState()
|
||||
return onLoadMore!!
|
||||
}
|
||||
|
||||
override fun fragmentLayout(): Int = R.layout.micro_grid_refresh_list
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
stateLayout.setEmptyText(R.string.no_projects)
|
||||
stateLayout.setOnReloadListener({ presenter.onCallApi(1, getState()) })
|
||||
refresh.setOnRefreshListener({ presenter.onCallApi(1, getState()) })
|
||||
recycler.setEmptyView(stateLayout, refresh)
|
||||
getLoadMore().initialize(presenter.currentPage, presenter
|
||||
.previousTotal)
|
||||
adapter.listener = presenter
|
||||
recycler.adapter = adapter
|
||||
recycler.addDivider()
|
||||
recycler.addOnScrollListener(getLoadMore())
|
||||
fastScroller.attachRecyclerView(recycler)
|
||||
if (presenter.getProjects().isEmpty() && !presenter.isApiCalled) {
|
||||
presenter.onFragmentCreate(arguments)
|
||||
presenter.onCallApi(1, getState())
|
||||
}
|
||||
}
|
||||
|
||||
override fun showProgress(@StringRes resId: Int) {
|
||||
refresh.isRefreshing = true
|
||||
stateLayout.showProgress()
|
||||
}
|
||||
|
||||
override fun hideProgress() {
|
||||
refresh.isRefreshing = false
|
||||
stateLayout.hideProgress()
|
||||
}
|
||||
|
||||
override fun showErrorMessage(message: String) {
|
||||
showReload()
|
||||
super.showErrorMessage(message)
|
||||
}
|
||||
|
||||
override fun showMessage(titleRes: Int, msgRes: Int) {
|
||||
showReload()
|
||||
super.showMessage(titleRes, msgRes)
|
||||
}
|
||||
|
||||
override fun onScrollTop(index: Int) {
|
||||
super.onScrollTop(index)
|
||||
if (recycler != null) {
|
||||
recycler.scrollToPosition(0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
recycler.removeOnScrollListener(getLoadMore())
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private fun showReload() {
|
||||
hideProgress()
|
||||
stateLayout.showReload(adapter.itemCount)
|
||||
}
|
||||
|
||||
private fun getState(): IssueState = arguments.getSerializable(BundleConstant.EXTRA_TYPE) as IssueState
|
||||
|
||||
companion object {
|
||||
fun newInstance(login: String, repoId: String, state: IssueState): RepoProjectFragment {
|
||||
val fragment = RepoProjectFragment()
|
||||
fragment.arguments = Bundler.start()
|
||||
.put(BundleConstant.ID, repoId)
|
||||
.put(BundleConstant.EXTRA, login)
|
||||
.put(BundleConstant.EXTRA_TYPE, state)
|
||||
.end()
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.fastaccess.ui.modules.repos.projects.list
|
||||
|
||||
import android.os.Bundle
|
||||
import com.fastaccess.data.dao.ProjectsModel
|
||||
import com.fastaccess.data.dao.types.IssueState
|
||||
import com.fastaccess.provider.rest.loadmore.OnLoadMore
|
||||
import com.fastaccess.ui.base.mvp.BaseMvp
|
||||
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
interface RepoProjectMvp {
|
||||
|
||||
interface View : BaseMvp.FAView {
|
||||
fun onNotifyAdapter(items: List<ProjectsModel>?, page: Int)
|
||||
fun getLoadMore(): OnLoadMore<IssueState>
|
||||
}
|
||||
|
||||
interface Presenter : BaseViewHolder.OnItemClickListener<ProjectsModel>,
|
||||
BaseMvp.PaginationListener<IssueState> {
|
||||
|
||||
fun onFragmentCreate(bundle: Bundle?)
|
||||
|
||||
fun getProjects(): ArrayList<ProjectsModel>
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package com.fastaccess.ui.modules.repos.projects.list
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.fastaccess.data.dao.ProjectsModel
|
||||
import com.fastaccess.data.dao.types.IssueState
|
||||
import com.fastaccess.helper.BundleConstant
|
||||
import com.fastaccess.helper.Logger
|
||||
import com.fastaccess.provider.rest.RestProvider
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by kosh on 09/09/2017.
|
||||
*/
|
||||
class RepoProjectPresenter : BasePresenter<RepoProjectMvp.View>(), RepoProjectMvp.Presenter {
|
||||
|
||||
private val projects = ArrayList<ProjectsModel>()
|
||||
private var page: Int = 0
|
||||
private var previousTotal: Int = 0
|
||||
private var lastPage = Integer.MAX_VALUE
|
||||
@com.evernote.android.state.State var login: String = ""
|
||||
@com.evernote.android.state.State var repoId: String = ""
|
||||
|
||||
override fun onItemClick(position: Int, v: View?, item: ProjectsModel?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onItemLongClick(position: Int, v: View?, item: ProjectsModel?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onFragmentCreate(bundle: Bundle?) {
|
||||
bundle?.let {
|
||||
repoId = it.getString(BundleConstant.ID)
|
||||
login = it.getString(BundleConstant.EXTRA)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getProjects(): ArrayList<ProjectsModel> = projects
|
||||
|
||||
override fun getCurrentPage(): Int = page
|
||||
|
||||
override fun getPreviousTotal(): Int = previousTotal
|
||||
|
||||
override fun setCurrentPage(page: Int) {
|
||||
this.page = page
|
||||
}
|
||||
|
||||
override fun setPreviousTotal(previousTotal: Int) {
|
||||
this.previousTotal = previousTotal
|
||||
}
|
||||
|
||||
override fun onCallApi(page: Int, parameter: IssueState?): Boolean {
|
||||
if (page == 1) {
|
||||
lastPage = Integer.MAX_VALUE
|
||||
sendToView { view -> view.getLoadMore().reset() }
|
||||
}
|
||||
if (page > lastPage || lastPage == 0) {
|
||||
sendToView({ it.hideProgress() })
|
||||
return false
|
||||
}
|
||||
currentPage = page
|
||||
makeRestCall(RestProvider.getProjectsService(isEnterprise)
|
||||
.getRepoProjects(login, repoId, parameter?.name, page), { response ->
|
||||
lastPage = response.last
|
||||
Logger.e(response.items as List<Any>?)
|
||||
sendToView({ it.onNotifyAdapter(response.items, page) })
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
9
app/src/main/res/drawable/ic_project.xml
Normal file
9
app/src/main/res/drawable/ic_project.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM9,17L7,17v-7h2v7zM13,17h-2L11,7h2v10zM17,17h-2v-4h2v4z"/>
|
||||
</vector>
|
||||
@ -24,6 +24,14 @@
|
||||
android:icon="@drawable/ic_pull_requests"
|
||||
android:title="@string/pull_requests"/>
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/projects"
|
||||
android:color="?colorPrimary"
|
||||
android:icon="@drawable/ic_project"
|
||||
android:title="@string/projects"/>
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/profile"
|
||||
android:color="?colorPrimary"
|
||||
|
||||
@ -24,6 +24,14 @@
|
||||
android:icon="@drawable/ic_pull_requests"
|
||||
android:title="@string/pull_requests"/>
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/projects"
|
||||
android:color="?colorPrimary"
|
||||
android:icon="@drawable/ic_project"
|
||||
android:title="@string/projects"/>
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/profile"
|
||||
android:color="?colorPrimary"
|
||||
|
||||
@ -18,10 +18,17 @@
|
||||
android:color="?colorPrimary"
|
||||
android:icon="@drawable/ic_issues"
|
||||
android:title="@string/issues"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/pullRequests"
|
||||
android:color="?colorPrimary"
|
||||
android:icon="@drawable/ic_pull_requests"
|
||||
android:title="@string/pull_requests"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/projects"
|
||||
android:color="?colorPrimary"
|
||||
android:icon="@drawable/ic_project"
|
||||
android:title="@string/projects"/>
|
||||
|
||||
</menu>
|
||||
@ -561,4 +561,6 @@
|
||||
<string name="app_animation_title">In App Animations</string>
|
||||
<string name="app_animation_summary">Disable in App animations everywhere.</string>
|
||||
<string name="can_not_merge_pr">This PR can\'t be merged now.</string>
|
||||
<string name="projects">Projects</string>
|
||||
<string name="no_projects">No Projects</string>
|
||||
</resources>
|
||||
|
||||
@ -20,7 +20,10 @@ import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.firebase.jobdispatcher.FirebaseJobDispatcher.ScheduleResult;
|
||||
|
||||
/**
|
||||
@ -28,7 +31,8 @@ import com.firebase.jobdispatcher.FirebaseJobDispatcher.ScheduleResult;
|
||||
* services installed. This backend does not do any availability checks and any uses should be
|
||||
* guarded with a call to {@code GoogleApiAvailability#isGooglePlayServicesAvailable(android.content.Context)}
|
||||
*
|
||||
* @see <a href="https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability#isGooglePlayServicesAvailable(android.content.Context)">GoogleApiAvailability</a>
|
||||
* @see
|
||||
* <a href="https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability#isGooglePlayServicesAvailable(android.content.Context)">GoogleApiAvailability</a>
|
||||
*/
|
||||
public final class GooglePlayDriver implements Driver {
|
||||
static final String BACKEND_PACKAGE = "com.google.android.gms";
|
||||
@ -62,12 +66,6 @@ public final class GooglePlayDriver implements Driver {
|
||||
* Turns Jobs into Bundles.
|
||||
*/
|
||||
private final GooglePlayJobWriter mWriter;
|
||||
/**
|
||||
* This is hardcoded to true to avoid putting an unnecessary dependency on the Google Play
|
||||
* services library.
|
||||
*/
|
||||
//TODO: this is an unsatisfying solution
|
||||
private final boolean mAvailable = true;
|
||||
|
||||
/**
|
||||
* Instantiates a new GooglePlayDriver.
|
||||
@ -81,9 +79,16 @@ public final class GooglePlayDriver implements Driver {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mAvailable;
|
||||
ApplicationInfo applicationInfo = null;
|
||||
try {
|
||||
applicationInfo = mContext.getPackageManager().getApplicationInfo(BACKEND_PACKAGE, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return applicationInfo != null && applicationInfo.enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Schedules the provided Job.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user