From b716ff0c308d52021038d4c0a3957330694e1311 Mon Sep 17 00:00:00 2001 From: 13372038054 <550906320@qq.com> Date: Sun, 17 Sep 2017 11:17:33 +0800 Subject: [PATCH] develop releases, released v1.1.0 --- app/build.gradle | 5 ++-- .../openhub/http/Downloader.java | 29 ++++++++++++++++++- .../openhub/mvp/model/EventPayload.java | 13 +++++++++ .../mvp/presenter/ActivityPresenter.java | 1 + .../mvp/presenter/ReleasesPresenter.java | 2 +- .../ui/activity/ReleaseInfoActivity.java | 4 ++- .../openhub/ui/adapter/ActivitiesAdapter.java | 4 +-- .../openhub/ui/adapter/ReleasesAdapter.java | 2 ++ .../openhub/ui/fragment/ActivityFragment.java | 7 +++++ .../main/res/layout/layout_item_release.xml | 3 +- app/src/main/res/values-zh-rCN/strings.xml | 3 +- app/src/main/res/values/strings.xml | 1 + gradle.properties | 3 +- 13 files changed, 67 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8fbdd71a..4f950b1f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,8 +83,9 @@ dependencies { //Android6.0以上权限获取工具 //PermissionsDispatcher provides a simple annotation-based API to handle runtime permissions in Android Marshmallow. // androidApt: 'com.neenbedankt.gradle.plugins:android-apt:1.8', - compile "com.github.hotchemi:permissionsdispatcher:${PERMISSIONS_DISPATCHER_VERSION}" - annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:${PERMISSIONS_DISPATCHER_VERSION}" +// compile "com.github.hotchemi:permissionsdispatcher:${PERMISSIONS_DISPATCHER_VERSION}" +// annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:${PERMISSIONS_DISPATCHER_VERSION}" + compile "com.yanzhenjie:permission:${AND_PERMISSION_VERSION}" compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}" annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}" diff --git a/app/src/main/java/com/thirtydegreesray/openhub/http/Downloader.java b/app/src/main/java/com/thirtydegreesray/openhub/http/Downloader.java index 75e23403..f2402b10 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/http/Downloader.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/http/Downloader.java @@ -8,9 +8,16 @@ import android.database.Cursor; import android.net.Uri; import android.os.Environment; +import android.support.annotation.NonNull; +import android.widget.Toast; import com.thirtydegreesray.openhub.R; import com.thirtydegreesray.openhub.util.StringUtils; +import com.yanzhenjie.permission.AndPermission; +import com.yanzhenjie.permission.Permission; +import com.yanzhenjie.permission.PermissionListener; + +import java.util.List; import es.dmoral.toasty.Toasty; @@ -24,6 +31,7 @@ public class Downloader { private Context mContext; private long downloadId; + private String url; private String fileName; public static Downloader create(Context context){ @@ -35,13 +43,32 @@ private Downloader(Context context){ } public void start(String url, String fileName) { - //FIXME write permission if(StringUtils.isBlank(url) || StringUtils.isBlank(fileName)){ Toasty.error(mContext, mContext.getString(R.string.download_empty_tip)).show(); return; } + this.url = url; this.fileName = fileName; + AndPermission.with(mContext) + .permission(Permission.STORAGE) + .callback(new PermissionListener() { + @Override + public void onSucceed(int requestCode, @NonNull List grantPermissions) { + start(); + } + + @Override + public void onFailed(int requestCode, @NonNull List deniedPermissions) { + Toasty.error(mContext, mContext.getString(R.string.permission_storage_denied), + Toast.LENGTH_LONG).show(); + } + }) + .start(); + } + + private void start() { + DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); //移动网络情况下是否允许漫游 request.setAllowedOverRoaming(false); diff --git a/app/src/main/java/com/thirtydegreesray/openhub/mvp/model/EventPayload.java b/app/src/main/java/com/thirtydegreesray/openhub/mvp/model/EventPayload.java index 05adea5a..4ec77e3b 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/mvp/model/EventPayload.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/mvp/model/EventPayload.java @@ -47,6 +47,9 @@ public class EventPayload implements Parcelable { private String description; @SerializedName("pusher_type") private String pusherType; + //ReleaseEvent + private Release release; + //ForkEvent,PublicEvent None @@ -146,6 +149,14 @@ public void setPusherType(String pusherType) { this.pusherType = pusherType; } + public Release getRelease() { + return release; + } + + public void setRelease(Release release) { + this.release = release; + } + @Override public int describeContents() { return 0; @@ -165,6 +176,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.masterBranch); dest.writeString(this.description); dest.writeString(this.pusherType); + dest.writeParcelable(this.release, flags); } public EventPayload() { @@ -183,6 +195,7 @@ protected EventPayload(Parcel in) { this.masterBranch = in.readString(); this.description = in.readString(); this.pusherType = in.readString(); + this.release = in.readParcelable(Release.class.getClassLoader()); } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { diff --git a/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ActivityPresenter.java b/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ActivityPresenter.java index 06902e30..ed4a0e11 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ActivityPresenter.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ActivityPresenter.java @@ -126,5 +126,6 @@ private void correctEvent(ArrayList events){ } } } + } diff --git a/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ReleasesPresenter.java b/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ReleasesPresenter.java index 84ac30a3..46727819 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ReleasesPresenter.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/mvp/presenter/ReleasesPresenter.java @@ -71,7 +71,7 @@ public void onSuccess(HttpResponse> response) { public Observable>> createObservable(boolean forceNetWork) { return getRepoService().getReleases(forceNetWork, owner, repo, page); } - }, httpObserver); + }, httpObserver, readCacheFirst); } diff --git a/app/src/main/java/com/thirtydegreesray/openhub/ui/activity/ReleaseInfoActivity.java b/app/src/main/java/com/thirtydegreesray/openhub/ui/activity/ReleaseInfoActivity.java index 29c41b02..6716ebdc 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/ui/activity/ReleaseInfoActivity.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/ui/activity/ReleaseInfoActivity.java @@ -51,7 +51,9 @@ public static void show(Activity activity, String repoName, Release release){ @Override public void showReleaseInfo(Release release) { - webView.setMdSource(release.getBodyHtml(), null); + webView.setMdSource(StringUtils.isBlank(release.getBodyHtml()) ? + release.getBody() : release.getBodyHtml(), null); + GlideApp.with(getActivity()) .load(release.getAuthor().getAvatarUrl()) .placeholder(R.mipmap.logo) diff --git a/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ActivitiesAdapter.java b/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ActivitiesAdapter.java index ab4e924f..310d8e6b 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ActivitiesAdapter.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ActivitiesAdapter.java @@ -97,8 +97,8 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) { action = "Push to " + ref + " at " + model.getRepo().getFullName(); } else if (Event.EventType.ReleaseEvent.equals(model.getType())) { - //TODO show release name - action = model.getPayload().getAction() + " release at " + + action = model.getPayload().getAction() + " release " + + model.getPayload().getRelease().getTagName() + " at " + model.getRepo().getFullName(); } else if (Event.EventType.PullRequestEvent.equals(model.getType())) { action = model.getPayload().getAction() + " pull request " + model.getRepo().getFullName(); diff --git a/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ReleasesAdapter.java b/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ReleasesAdapter.java index 4bcec674..d5417336 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ReleasesAdapter.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/ui/adapter/ReleasesAdapter.java @@ -46,8 +46,10 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) { holder.time.setText(StringUtils.getNewsTimeStr(context, model.getCreatedAt())); if(!StringUtils.isBlank(model.getBodyHtml())){ holder.body.setText(Html.fromHtml(model.getBodyHtml())); + holder.body.setVisibility(View.VISIBLE); } else { holder.body.setText(""); + holder.body.setVisibility(View.GONE); } } diff --git a/app/src/main/java/com/thirtydegreesray/openhub/ui/fragment/ActivityFragment.java b/app/src/main/java/com/thirtydegreesray/openhub/ui/fragment/ActivityFragment.java index 63251cc4..dbe89e5b 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/ui/fragment/ActivityFragment.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/ui/fragment/ActivityFragment.java @@ -26,6 +26,7 @@ import com.thirtydegreesray.openhub.mvp.contract.IActivityContract; import com.thirtydegreesray.openhub.mvp.model.Event; import com.thirtydegreesray.openhub.mvp.presenter.ActivityPresenter; +import com.thirtydegreesray.openhub.ui.activity.ReleaseInfoActivity; import com.thirtydegreesray.openhub.ui.activity.RepositoryActivity; import com.thirtydegreesray.openhub.ui.adapter.ActivitiesAdapter; import com.thirtydegreesray.openhub.ui.fragment.base.ListFragment; @@ -96,6 +97,12 @@ public void onItemClick(int position) { String actorId = event.getActor().getLogin(); RepositoryActivity.show(getContext(), actorId, event.getRepo().getName()); break; + case ReleaseEvent: + String repoName = event.getRepo().getFullName(); + repoName = repoName.substring(repoName.lastIndexOf("/") + 1); + ReleaseInfoActivity.show(getActivity(), repoName, + event.getPayload().getRelease()); + break; default: RepositoryActivity.show(getContext(), owner, event.getRepo().getName()); break; diff --git a/app/src/main/res/layout/layout_item_release.xml b/app/src/main/res/layout/layout_item_release.xml index 7c6d8a15..61c8b752 100644 --- a/app/src/main/res/layout/layout_item_release.xml +++ b/app/src/main/res/layout/layout_item_release.xml @@ -65,7 +65,8 @@ android:textColor="?android:textColorPrimary" android:maxLines="6" android:paddingStart="@dimen/spacing_micro" - android:paddingEnd="@dimen/spacing_micro"/> + android:paddingEnd="@dimen/spacing_micro" + android:ellipsize="end"/> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a6676d89..5b8b5c31 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -116,7 +116,7 @@ 已取消关注 关注 已关注 - 查看 + 关注者 添加到我的版本库 添加到我的版本库? 已添加到我的版本库 @@ -147,5 +147,6 @@ 发布此版本 关闭 + 权限被拒绝,请允许访问存储权限。 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 41c04731..a33f0ffc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -217,5 +217,6 @@ Url or file name is empty! Download start Download cancel + Permission denied, please allow storage permission. diff --git a/gradle.properties b/gradle.properties index ab1c480f..7136c83d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -42,7 +42,8 @@ FILE_DOWNLOADER_VERSION=0.3.1 RXJAVA_VERSION=1.1.0 RETROFIT_VERSION=2.1.0 DAGGER_VERSION=2.11 -PERMISSIONS_DISPATCHER_VERSION=2.1.3 +#PERMISSIONS_DISPATCHER_VERSION=2.1.3 +AND_PERMISSION_VERSION=1.1.0 RETROLAMBDA_VERSION=2.3.0 OKHTTP_VERSION=3.6.0 FASTJSON_VERSION=1.1.46.android