Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
add wechat share function and fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
chejdj committed Apr 2, 2019
1 parent 7bfe271 commit 9973850
Show file tree
Hide file tree
Showing 25 changed files with 167 additions and 28 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
### WanAndroid
## WanAndroid
#### 项目介绍
**一款每日推荐优质文章的APP,该项目是鸿洋大佬推荐Andorid开发者的一个开源项目,项目中的API为鸿洋大佬提供([API直通车](https://www.wanandroid.com/blog/show/2)),此项目基于Java+Material Design+MVP+RxJava2+Retrofit等一些主流框架搭建而成**
#### 项目背景
### 项目背景
首先介绍一下自己,自己是一个大学即将毕业的Andorid初级开发者,在找工作的时候,看过一些面经,但是忘记快又理解不深刻,于是想要拿一个项目练练手,加深一下对知识点的理解,以及对于Andorid开发整个流程的梳理,这个项目希望大家一起学习,探讨,尤其是对于Android新手如何写代码的通病以及如何写出高效简洁的代码(希望有大佬指点),欢迎issue,star。
#### 整体模块
### 整体模块
此项目的整体框架如下:
* 首页模块:轮番广告显示,最新文章推送
* 知识体系模块
Expand All @@ -14,7 +14,7 @@
* 文章搜索模块
* WebView文章浏览模块
* 数据库本地缓存模块
#### 第三方开源库
### 第三方开源库
* [Objectbox](https://github.com/objectbox/objectbox-java)(数据库框架)
* [Glide](https://github.com/bumptech/glide)(图片加载框架)
* [Retrofit](https://github.com/square/retrofit)(网络请求框架)
Expand All @@ -28,28 +28,33 @@
* [Bugly](https://bugly.qq.com/v2/)(Bug监控框架)
* [RecyclerView]()(Andorid官方list控件)
* [design]()(Android官方库,包含多种MaterialDesign控件)
#### 参考项目以及文章
### 参考项目以及文章
* [hurshi大神的wanandroid](https://github.com/hurshi/wanandroid)(此项目的UI是参考,模仿hurshi大神的玩Andorid项目,感谢)
* [给初学者的RxJava2.0教程系列](https://www.jianshu.com/p/464fa025229e)
* [Android冷启动解决方法](http://saulmm.github.io/avoding-android-cold-starts)
* [今日头条屏幕适配方案](https://mp.weixin.qq.com/s/sjI-gDx3PaCskxh_vj6vpA)
* [WebView性能、体验分析与优化](https://mp.weixin.qq.com/s?__biz=MjM5NjQ5MTI5OA==&mid=2651746383&idx=2&sn=9b8f8ec2adf7c13934bfb9891eae4d81&chksm=bd12a9028a652014ab8b89ff996cf7b53e8d40bfbcd64725c7c82df72515669fcf5267272ccf&scene=38#wechat_redirect)(这一块此项目后续需要改进)
* [Android MVP架构从入门到精通-真枪实弹](https://www.wanandroid.com/blog/show/2440)
* [你真的会用Retrofit2吗?Retrofit2完全教程](https://www.jianshu.com/p/308f3c54abdd)
#### 版本更新说明
### 版本更新说明

```
v2.0.0 加入微信分享+修改了部分Bug
v1.4.2 更新部分界面,以及无网络及网络差的友好显示,及Bugly上面的Bug
v1.3.0 修改首页Frament之间的切换方式以及FragmentStatePagerAdapter的Bug
v1.2.0 修改Android6.0动态权限申请
v1.1.0 初始版本
#### 项目一览
```

### 项目一览
![启动页](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/start.png?token=AQ4MyR7l6VVBBAtmu58KP5JDaqCvBeeuks5cmY9GwA%3D%3D)![首页](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/home.png?token=AQ4MyRfQ4zg_fKBxyoT20J_lbKqK5yA1ks5cmY9fwA%3D%3D)![知识体系](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/knowledgeArch.png?token=AQ4MyeEP5r7eQBbuzhnjY47bZ4TtVG7cks5cmY97wA%3D%3D)

![详情知识体系文章](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/detail_knowledge.png?token=AQ4MyVOiuSZondN8kyVxxUvM53Sy3av7ks5cmY-SwA%3D%3D)![微信公众号](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/wechat.png?token=AQ4MyczK2p_uOBaMH3fHpijwmpeCAj79ks5cmZLqwA%3D%3D)![项目](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/project.png?token=AQ4MySYP3LhA_S0m-99uQl05v7hJvdLWks5cmY_JwA%3D%3D)

![登录](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/login.png?token=AQ4MyaDqXbyvT1_7QGZ9tnTuylsr25UZks5cmY_rwA%3D%3D)![我的](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/me.png?token=AQ4MyXe7t_GjrtN2f6fH4TblvcbBSHIxks5cmZACwA%3D%3D)![搜索热词](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/search_hot_keys.png?token=AQ4MySHXivZbbxGsRxKDT28I9F15fbeMks5cmZAdwA%3D%3D)

![搜索](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/search.png?token=AQ4MySH6FlcA90BGrtyjntteyjqyn54hks5cmZBtwA%3D%3D)![文章](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/article.png?token=AQ4MyZ4y36FW7ccDsmyNSgHvBz7Ye3QRks5cmZCFwA%3D%3D)
#### 项目资源
### 项目资源
1. [APP下载地址](https://github.com/chejdj/WanAndroid/releases/download/1.2.0/app-release.apk),二维码
![二维码](https://raw.githubusercontent.com/chejdj/WanAndroid/master/image/apk_download.png)
(二维码的APK永远都是最新的,release上的重大更新才发版)
Expand Down
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.chejdj.wanandroid"
minSdkVersion 21
targetSdkVersion 28
versionCode 9
versionName "1.4.3"
versionCode 10
versionName "2.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk{
abiFilters 'armeabi-v7a','arm64-v8a'
Expand Down Expand Up @@ -60,6 +60,8 @@ dependencies {
implementation 'com.hyman:flowlayout-lib:1.1.2'
//notify
implementation 'org.greenrobot:eventbus:3.1.1'
//wx
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+'
//bugly
implementation 'com.tencent.bugly:crashreport:latest.release'
}
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9,"versionName":"1.4.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":10,"versionName":"2.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.chejdj.wanandroid.ui.base.WanAndroidBaseActivty;
import com.chejdj.wanandroid.ui.webviewarticle.contract.WebViewArticleContract;
import com.chejdj.wanandroid.ui.webviewarticle.presenter.WebViewArticlePresenter;
import com.chejdj.wanandroid.util.NetUtils;
import com.chejdj.wanandroid.util.StringUtil;
import com.chejdj.wanandroid.util.wxshare.WxShareDialog;
import com.getbase.floatingactionbutton.FloatingActionButton;

import org.greenrobot.eventbus.EventBus;
Expand All @@ -46,9 +46,6 @@ public class WebViewArticleActivity extends WanAndroidBaseActivty implements Web

@Override
protected int getLayoutId() {
if (NetUtils.getNetWorkState() < 0) {
return R.layout.network_error;
}
return R.layout.activity_webview_article;
}

Expand All @@ -57,7 +54,7 @@ protected void initView() {
Intent intent = getIntent();
article = intent.getParcelableExtra(ARTICLE_NAME);
collectState = intent.getBooleanExtra(COLLECT_STATE, false);
if(collectState){
if (collectState) {
collectButton.setIconDrawable(getDrawable(R.drawable.collected));
}
if (article == null) {
Expand Down Expand Up @@ -107,7 +104,7 @@ public void onPageFinished(WebView view, String url) {

@OnClick(R.id.share)
public void shareArticle() {
Toast.makeText(this, "账号正在审核中,尽情期待!!", Toast.LENGTH_SHORT).show();
WxShareDialog.showWxShareDialog(this, getWindow().getDecorView().findViewById(android.R.id.content), article);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.chejdj.wanandroid.util.wxshare;

import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.chejdj.wanandroid.R;
import com.chejdj.wanandroid.network.bean.article.Article;

public class WxShareDialog {
public static void showWxShareDialog(Context context, View parent, Article article) {
PopupWindow popupWindow = new PopupWindow(LayoutInflater.from(context).inflate(R.layout.wechat_share, null), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

View.OnClickListener listener = (View v) -> {
switch (v.getId()) {
case R.id.share_friends:
WxShareUtil.getInstance().shareToWeChat(context, article.getLink(), article.getTitle(), article.getDesc(), 0);
break;
case R.id.share_timeline:
WxShareUtil.getInstance().shareToWeChat(context, article.getLink(), article.getTitle(), article.getDesc(), 1);
break;
default:
Log.e("WxShareDialg", "no this view" + v.getId());
}
popupWindow.dismiss();
};


popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(context.getDrawable(R.drawable.wx_share_bg));

popupWindow.getContentView().findViewById(R.id.share_friends).setOnClickListener(listener);
popupWindow.getContentView().findViewById(R.id.share_timeline).setOnClickListener(listener);

popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.chejdj.wanandroid.util.wxshare;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.widget.Toast;

import com.chejdj.wanandroid.R;
import com.chejdj.wanandroid.WanAndroidApplication;
import com.chejdj.wanandroid.util.StringUtil;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WxShareUtil {
private static final String APP_ID = "*****"; //填入自己的APPID
private IWXAPI api;

private WxShareUtil() {
api = WXAPIFactory.createWXAPI(WanAndroidApplication.getMyApplication(), APP_ID, true);
api.registerApp(APP_ID);
}

static class Wrapper {
static WxShareUtil INSTANCE = new WxShareUtil();
}

public static WxShareUtil getInstance() {
return Wrapper.INSTANCE;
}

/**
* @param link 网页链接
* @param title 网页title
* @param description 网页描述
* @param type 分享类型,0代表会话,1代表朋友圈
*/
public void shareToWeChat(Context context, String link, String title, String description, int type) {

WXWebpageObject webpageObject = new WXWebpageObject();
webpageObject.webpageUrl = link;
WXMediaMessage msg = new WXMediaMessage(webpageObject);
msg.title = title;
msg.description = description;
msg.setThumbImage(BitmapFactory.decodeResource(WanAndroidApplication.getMyApplication().getResources(), R.drawable.wanandroid));

SendMessageToWX.Req req = new SendMessageToWX.Req();
req.message = msg;
req.scene = type == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
boolean state = api.sendReq(req);
if (!state) {
Toast.makeText(context, StringUtil.getString(context, R.string.wx_share_error), Toast.LENGTH_SHORT).show();
}
}
}
Binary file added app/src/main/res/drawable-xxhdpi/wanandroid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/wc_friends.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/wc_timeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/wx_share_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="@color/white"/>
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
<stroke android:color="@color/gray" android:width="1dp"/>

</shape>
35 changes: 35 additions & 0 deletions app/src/main/res/layout/wechat_share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/share_friends"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/wx_friends"
android:textSize="14sp"
android:textColor="@color/black"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginTop="@dimen/margin_normal"
android:drawableTop="@drawable/wc_friends"
android:layout_marginBottom="@dimen/margin_normal"
/>
<TextView
android:id="@+id/share_timeline"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/wx_timeline"
android:layout_marginBottom="@dimen/margin_normal"
android:textSize="14sp"
android:textColor="@color/black"
android:layout_marginTop="@dimen/margin_normal"
android:gravity="center_horizontal"
android:layout_weight="1"
android:drawableTop="@drawable/wc_timeline"
/>

</LinearLayout>
5 changes: 0 additions & 5 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

This file was deleted.

5 changes: 0 additions & 5 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

This file was deleted.

Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">WanAndroid</string>
<string name="app_name">Wan安卓</string>
<string name="menu_home">首页</string>
<string name="menu_knowledge_hierarchy">体系</string>
<string name="menu_wechat_sub">公众号</string>
Expand Down Expand Up @@ -31,4 +31,7 @@
<string name="please_login">请先登录,再收藏!!</string>
<string name="deny_permissions_warning">拒绝权限,将导致图片加载不出来!!</string>
<string name="reload">重新加载</string>
<string name="wx_friends">朋友</string>
<string name="wx_timeline">朋友圈</string>
<string name="wx_share_error">没有安装微信或网络连接失败</string>
</resources>

0 comments on commit 9973850

Please sign in to comment.