Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	app/src/main/java/razerdp/demo/DemoActivity.java
#	app/src/main/java/razerdp/demo/popup/update/PopupUpdate.java
#	build.gradle
  • Loading branch information
razerdp committed May 28, 2021
2 parents 883549f + e9fb7f0 commit 8a7471e
Show file tree
Hide file tree
Showing 60 changed files with 931 additions and 427 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
- Release版本:一般在Snapshot版本反复验证修复后发布到Release,如果您对稳定性要求较高,请使用Release版本。
- Snapshot:一般新功能、issue修复都会发布到Snapshot版本,Snapshot版本发布比较频繁,但通常会拥有新的功能,如果您喜欢试验新功能同时对稳定性要求不高,请使用Snapshot版本。
- **Release和Snapshot两个版本互相切换可能会导致Build失败,这时候您Clean一下Project即可**
- 从16年[**第一次**](https://github.com/razerdp/BasePopup/commit/c92b7088270d5757269d9b79213627a4a0392d31)提交到现在,本人技术也一直在进步,BasePopup也会一直迭代更新,所以,请谨慎选择版本哦~一不小心就颠覆了之前的实现。
- **3.0版本是破坏性升级,请您务必阅读升级提示**[关于BasePopup 3.0的破坏性更新说明](./Update_3.0.md)

<br>

Expand All @@ -117,6 +117,8 @@ allprojects {

**由于JCenter已经停止服务,自2.3版本开始,本库将迁移到Maven,新的依赖groupId为 【io.github.razerdp】**

**3.0版本是破坏性升级,请您务必阅读升级提示**[关于BasePopup 3.0的破坏性更新说明](./Update_3.0.md)

- **Release:** `implementation 'io.github.razerdp:BasePopup:{$latestVersion}'`
- e.g. `implementation 'io.github.razerdp:BasePopup:2.3.0'`
- **Snapshot:** `implementation 'io.github.razerdp:BasePopup:{$latestVersion_for_snapshot}-SNAPSHOT'`
Expand All @@ -133,13 +135,24 @@ BasePopup配备完善的文档,建议您优先查阅文档。
<br>



### 更新日志 [(历史更新)](https://www.yuque.com/razerdp/basepopup/uyrsxx)

**正在开发日志(Snapshot版本)请查看dev分支:** [**branch-dev**](https://github.com/razerdp/BasePopup/tree/dev#%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97-%E5%8E%86%E5%8F%B2%E6%9B%B4%E6%96%B0)

* **【Release】2.3.0** (2021/04/30)
* 迁移到maven central
* **【Snapshot】2.3.2-SNAPSHOT** (2021/05/13)
* 修复屏幕旋转后Popup大小没更新的问题
* 修复update(float,float)失效的问题
* **【Snapshot】3.0.0-SNAPSHOT** (2021/05/14)
* 升级提示:[关于BasePopup 3.0的破坏性更新说明](./Update_3.0.md)
* 删除**BaseLazyPopupWindow**:往后不需要区分懒加载和正常的BasePopupWindow,统一依赖BasePopupWindow
* 删除方法`onCreateConstructor`:该方法实际上是给BaseLazyPopupWindow使用的,现在没有了BaseLazyPopupWindow,自然不需要该方法
* 【重要】删除方法`onCreateContentView`:该方法的删除将会影响所有的BasePopupWindow子类,您需要手动去改动
* 该方法将会被`setContentView(@LayoutRes int layoutResID)``setContentView(final View view)`所代替,您需要修改其使用。
* 当然,如果使用`setContentView(final View view)`,我们依然建议您用setContentView(createPopupById(layoutResID)),以便我们解析到正确的xml配置。
* **【Snapshot】3.1.0-SNAPSHOT** (2021/05/27)
* 增加api:`hideKeyboardOnShow(boolean)`,是否在BasePopup显示时收起键盘,默认收起
* demo增加 issue 369测试用例
* fixed [#369](https://github.com/razerdp/BasePopup/issues/369)
* 蒙层现在只有点击的时候才会执行dismiss(之前是只判断action_up是否在蒙层内)
* `onOutSideTouch`增加isMaskPressed标记


<br>
Expand Down
88 changes: 88 additions & 0 deletions Update_3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
**中文** | [**English**](./Update_3.0_EN.md)

---

## 关于BasePopup 3.0的破坏性更新说明

### 改动说明

* 删除**BaseLazyPopupWindow**:往后不需要区分懒加载和正常的BasePopupWindow,统一依赖BasePopupWindow
* 删除方法`onCreateConstructor`:该方法实际上是给BaseLazyPopupWindow使用的,现在没有了BaseLazyPopupWindow,自然不需要该方法
* 【重要】删除方法`onCreateContentView`:该方法的删除将会影响所有的BasePopupWindow子类,您需要手动去改动
* 该方法将会被`setContentView(@LayoutRes int layoutResID)``setContentView(final View view)`所代替,您需要修改其使用。
* 当然,如果使用`setContentView(final View view)`,我们依然建议您用setContentView(createPopupById(layoutResID)),以便我们解析到正确的xml配置。

### 为什么要这么改

事实上想改这个很久了,而且也不止一位开发者向我提过这个issue,如[#368](https://github.com/razerdp/BasePopup/issues/368)

初始化ContentView其实就应该跟Dialog或者Activity一样,把权限交给使用者而非框架强行设定。

之所以会出现`onCreateContentView`这样的强制实现的方法,是因为第一版的BasePopup就是这么设计的,而第一版的设计时间是16年,那时候我大四,设计这个框架的目的就是为了求职。

那时候我也想不到BasePopup会被我一直维护且迭代更新,也没想到会有那么多开发者使用。

但也正因为是那么多人使用,因此我一直不太敢去动他,毕竟这是一个破坏性更新,要改的很多很多(虽然改动很小,但可能依赖BasePopup的类很多)。

但是,随着越来越多人的提出这个问题,我认为这种修改是躲不过的。

因此这次改动我将直接发布3.0版本,与2.x版本区分开来。


### 修改的好处

优点有很多,先来说说以前的缺点:

#### BaseLazyPopupWindow

在以前的版本中,我提供了一个BaseLazyPopupWindow来解决构造器传参,onViewCreated中无法获取的问题。

咋一眼似乎还行,实际上仍有弊端,最主要体现在两个:

1. inflate的时机在showPopupWindow(),这会导致复杂的布局在第一次show的时候会卡顿(卡顿原因:inflate)
2. 由于懒加载,其加载时机在show的时候,因此我们无法在构造器中findViewById,其次对于 new popup().setText().showPopupWindow()这样的在setText中直接访问控件的方法是不可行的,只会得到NPE报错(在show之前都没有inflate呢,访问控件只能是空的)。

这两个问题也许很多人没遇到过,但一旦遇到了就会觉得巨麻烦,框架为啥这么设计。

#### 构造器传参及onViewCreated取参的问题

在以前的版本中,onViewCreated是在父类的构造器中调用的,此时子类的参数都还没赋值进行初始化,因此执行onViewCreated时我们无法得到参数。

哪怕后来提供了BaseLazyPopupWindow,也会有上述几个问题。


### 修改后的使用

修改后的使用上跟以前其实没啥区别,优点是`setContentView`的时机完全由您控制,不必担心上面所说的问题。

e.g.

```java
public class DemoPopup extends BasePopupWindow {
@BindView(R.id.tv_desc)
public TextView mTvDesc;

int a;

public DemoPopup(Context context,int a) {
super(context);
// 此时赋值构造器传入的值
this.a = a;
setContentView(R.layout.popup_demo);
}


@Override
public void onViewCreated(View contentView) {
ButterKnifeUtil.bind(this, contentView);
// 此时能正确访问到a
mTvDesc.setText(String.valueOf(a));
}

// 如果使用 new DemoPopup().setText(),不需要担心mTvDesc为空
public DemoPopup setText(CharSequence text) {
mTvDesc.setText(text);
return this;
}
}
```
89 changes: 89 additions & 0 deletions Update_3.0_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[**Chinese**](./Update_3.0.md) | **English**

---

## Notes on the disruptive update to BasePopup 3.0

### Description of alterations

* Delete **BaseLazyPopupWindow**: there is no need to distinguish between lazy loading and normal BasePopupWindow in the future, it inherits BasePopupWindow uniformly
* Remove the method `onCreateConstructor`: this method is actually for the BaseLazyPopupWindow and is not needed now that there is no more BaseLazyPopupWindow
* [Important] Delete method `onCreateContentView`: The deletion of this method will affect all BasePopupWindow subclasses and you will need to change it manually.
* This method will be replaced by `setContentView(@LayoutRes int layoutResID)` or `setContentView(final View view)` and you will need to modify its use.
* Of course, if you use `setContentView(final View view)`, we still recommend that you use setContentView(createPopupById(layoutResID)) so that we parse to the correct xml configuration.

### Why

I've actually wanted to change this for a long time, and I've had more than one developer mention it to me, e.g. [#368](https://github.com/razerdp/BasePopup/issues/368).

Initialising a ContentView should be like a Dialog or Activity, with permissions given to the user rather than forced by the framework.

The reason for the `onCreateContentView` forced method is that this is how the first version of BasePopup was designed, and the first version was designed back in '16, when I was a senior in college and designed the framework for job hunting purposes.

At that time I didn't expect that BasePopup would be maintained and iterated upon, nor did I expect that it would be used by so many developers.

But because so many people were using it, I didn't dare to touch it, because it was a disruptive update and there was a lot to change (although the changes were small, there were probably a lot of classes that depended on BasePopup).

However, with more and more people asking this question, I think this change is inevitable.

So for this change I will release version 3.0 straight away, to distinguish it from version 2.x.

Translated with www.DeepL.com/Translator (free version)


### Benefits

There are many advantages, starting with the previous disadvantages.

#### BaseLazyPopupWindow

In previous versions, I provided a BaseLazyPopupWindow to solve the problem of constructors passing parameters that were not available in onViewCreated.

At first glance it seems to work, but in reality there are still drawbacks, most notably in two areas.
1. The timing of the inflate is in `showPopupWindow()`, which can cause complex layouts to lag on the first show (reason for lag: inflate)
2. Because of lazy loading, its loading time is at show time, so we can't findViewById in the constructor, and secondly for `new popup().setText().showPopupWindow()` which accesses the control directly in setText is not feasible, it just gets an NPE error (there is no inflate before show There is no inflate before the show, so the access control will be empty).

These two problems may not be encountered by many people, but when they are, they can be a huge pain in the ass to understand why the framework is designed the way it is.

#### Problems with constructor passing and onViewCreated taking parameters

In previous versions, onViewCreated was called in the constructor of the parent class, where none of the subclass parameters had been assigned for initialisation, so we could not get the parameters when onViewCreated was executed.

Even with the later provision of BaseLazyPopupWindow, there were several problems with this.


### How

The advantage is that the timing of the `setContentView` is entirely under your control and you don't have to worry about the problems described above.

e.g.

```java
public class DemoPopup extends BasePopupWindow {
@BindView(R.id.tv_desc)
public TextView mTvDesc;

int a;

public DemoPopup(Context context,int a) {
super(context);
// The value passed in by the assignment constructor at this point
this.a = a;
setContentView(R.layout.popup_demo);
}


@Override
public void onViewCreated(View contentView) {
ButterKnifeUtil.bind(this, contentView);
// At this point it is possible to correctly access the a
mTvDesc.setText(String.valueOf(a));
}

// If you use new DemoPopup().setText(), you don't need to worry about mTvDesc being empty
public DemoPopup setText(CharSequence text) {
mTvDesc.setText(text);
return this;
}
}
```
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
android:theme="@style/DialogTheme" />
<activity android:name="razerdp.demo.ui.issuestest.Issue358TestActivity" />
<activity android:name="razerdp.demo.ui.updatetest.UpdateTestActivity" />
<activity
android:name="razerdp.demo.ui.ScreenRotateActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name="razerdp.demo.ui.issuestest.Issue369TestActivity"
android:windowSoftInputMode="adjustResize|stateHidden" />

<service android:name="razerdp.demo.services.DemoService" />
<service android:name="razerdp.demo.services.DelayDemoService" />
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/razerdp/demo/DemoActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
package razerdp.demo;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.PictureDrawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.pgyersdk.update.DownloadFileListener;
import com.pgyersdk.update.PgyUpdateManager;
import com.pgyersdk.update.UpdateManagerListener;
import com.pgyersdk.update.javabean.AppBean;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -18,6 +31,8 @@
import razerdp.demo.base.baseactivity.BaseActivity;
import razerdp.demo.base.baseadapter.BaseSimpleRecyclerViewHolder;
import razerdp.demo.base.baseadapter.SimpleRecyclerViewAdapter;
import razerdp.demo.base.imageloader.GlideApp;
import razerdp.demo.base.imageloader.SvgSoftwareLayerSetter;
import razerdp.demo.model.DemoMainItem;
import razerdp.demo.ui.ActivityLauncher;
import razerdp.demo.ui.ApiListActivity;
Expand Down Expand Up @@ -58,6 +73,7 @@ protected void onInitView(View decorView) {
View header = ViewUtil.inflate(this, R.layout.item_main_demo_header, rvContent, false);
header.setOnClickListener(v -> onHeaderClick());
rvContent.addHeaderView(header);
rvContent.addHeaderView(genVersionHeader());
mAdapter = new SimpleRecyclerViewAdapter<>(this, generateItem());
mAdapter.setHolder(InnerViewHolder.class);
mAdapter.setOnItemClickListener((v, position, data) -> ActivityLauncher.start(self(),
Expand All @@ -68,6 +84,29 @@ protected void onInitView(View decorView) {
showWjPopup();
}

private View genVersionHeader() {
View header = ViewUtil.inflate(this, R.layout.item_main_demo_version, rvContent, false);
ImageView release = header.findViewById(R.id.iv_release);
GlideApp.with(release)
.as(PictureDrawable.class)
.placeholder(new ColorDrawable(UIHelper.getColor(R.color.color_loading)))
.error(R.drawable.ic_error_gray)
.transition(DrawableTransitionOptions.withCrossFade())
.listener(new SvgSoftwareLayerSetter())
.load("https://img.shields.io/maven-central/v/io.github.razerdp/BasePopup")
.into(release);
ImageView snapshot = header.findViewById(R.id.iv_snapshot);
GlideApp.with(snapshot)
.as(PictureDrawable.class)
.placeholder(new ColorDrawable(UIHelper.getColor(R.color.color_loading)))
.error(R.drawable.ic_error_gray)
.transition(DrawableTransitionOptions.withCrossFade())
.listener(new SvgSoftwareLayerSetter())
.load("https://img.shields.io/nexus/s/io.github.razerdp/BasePopup?server=https%3A%2F%2Fs01.oss.sonatype.org%2F")
.into(snapshot);
return header;
}

private List<DemoMainItem> generateItem() {
List<DemoMainItem> result = new ArrayList<>();
result.add(new DemoMainItem(GuideActivity.class, "简介", GuideActivity.DESC, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,7 @@ public void showLoadingDialog(boolean cancelable) {
}
mLoadingDialog.setCancelable(cancelable);
if (mLoadingDialog != null && !mLoadingDialog.isShowing()) {
if (ToolUtil.isMainThread()) {
mLoadingDialog.show();
} else {
runOnUiThread(() -> mLoadingDialog.show());
}
runOnUiThread(() -> mLoadingDialog.show());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package razerdp.demo.model.common;

import android.view.View;

import razerdp.demo.model.DemoCommonUsageInfo;
import razerdp.demo.ui.ActivityLauncher;
import razerdp.demo.ui.ScreenRotateActivity;
import razerdp.demo.utils.UIHelper;

/**
* Created by 大灯泡 on 2020/05/17
* <p>
* Description:屏幕旋转
*/
public class ScreenRotateActivityInfo extends DemoCommonUsageInfo {

public ScreenRotateActivityInfo() {
title = "屏幕旋转";
}

@Override
public void toShow(View v) {
ActivityLauncher.start(v.getContext(), ScreenRotateActivity.class);
}

@Override
public void toOption(View v) {
UIHelper.toast("这里啥都没有哦");
}
}
7 changes: 3 additions & 4 deletions app/src/main/java/razerdp/demo/popup/DemoPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ public class DemoPopup extends BasePopupWindow {

public DemoPopup(Context context) {
super(context);
setContentView(R.layout.popup_demo);
}

public DemoPopup(Fragment fragment) {
super(fragment);
setContentView(R.layout.popup_demo);
}

public DemoPopup(Dialog dialog) {
super(dialog);
setContentView(R.layout.popup_demo);
}

@Override
Expand All @@ -54,10 +57,6 @@ protected Animation onCreateDismissAnimation() {
.toDismiss();
}

@Override
public View onCreateContentView() {
return createPopupById(R.layout.popup_demo);
}

public DemoPopup setText(CharSequence text) {
mTvDesc.setText(text);
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/razerdp/demo/popup/PopupAnimate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
public class PopupAnimate extends BasePopupWindow {
public PopupAnimate(Context context) {
super(context);
setContentView(R.layout.popup_animate);
}

@Override
public View onCreateContentView() {
return createPopupById(R.layout.popup_animate);
}
}
Loading

0 comments on commit 8a7471e

Please sign in to comment.