Skip to content

Commit

Permalink
v0.1.2 修改包名,并提供support版本
Browse files Browse the repository at this point in the history
  • Loading branch information
lnysky committed Sep 5, 2019
1 parent b132e1e commit f313fba
Show file tree
Hide file tree
Showing 160 changed files with 2,402 additions and 96 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2019 lnysky

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
74 changes: 45 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
# scorpio
[ ![Download](https://api.bintray.com/packages/danyon/maven/scorpio/images/download.svg) ](https://bintray.com/danyon/maven/scorpio/_latestVersion)[![License](https://img.shields.io/badge/license-Apache%202-lightgrey.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)

一行代码切换状态布局,内置数据为空,错误,加载中三种默认布局
一行代码切换状态布局,内置加载中,数据为空,错误三种状态布局

## 添加gradle依赖
## Gradle 依赖

support

```groovy
implementation 'com.lnysky.scorpio:support:0.1.2'
```

androidx

```groovy
implementation 'com.lnysky.tech:scorpio:0.1.1'
implementation 'com.lnysky.scorpio:x:0.1.2'
```

### 使用
## 使用

#### 内置状态
#### 显示原始状态

```jav
Scorpio.with(this).content().show();
```

#### 显示内置状态

- 加载中
```java
Scorpio.with(this).loading().setTips("加载中...").show();
Scorpio.with(this).loading().setTips("加载中...").show();
```
- 数据为空
```java
Scorpio.with(this).empty().setTips("主页面空空的~~").show();
Scorpio.with(this).empty().setTips("主页面空空的~~").show();
```
- 加载出错
```java
Scorpio.with(this).error()
.setRetryText("重新加载")
.setOnRetryListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Scorpio.loading(MainActivity.this).show();
}
}).show();
Scorpio.with(this).error()
.setRetryText("重新加载")
.setOnRetryListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Scorpio.loading(MainActivity.this).show();
}
}).show();
```
#### 自定义状态
#### 显示自定义状态

```java
public class CustomState extends StateLayout.State<CustomState.ViewHolder> {
Expand Down Expand Up @@ -68,7 +82,9 @@ public class CustomState extends StateLayout.State<CustomState.ViewHolder> {
Scorpio.with(this).get(CustomState.class).show();
```

### fragment中使用
## 问题

- fragment中使用

```java
@Override
Expand All @@ -80,12 +96,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
```
注意:如果StateLayout作为root view,可以不调wrapper,类似在activity中使用方法

### xml中使用
- 布局中使用

- StateLayout包含content view
StateLayout有一个子view

```xml
<com.lnysky.tech.scorpio.StateLayout
<com.lnysky.scorpio.StateLayout
android:id="@+id/state_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -99,28 +115,28 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
android:layout_height="wrap_content"
android:text="@string/text_content_show" />
</LinearLayout>
</com.lnysky.tech.scorpio.StateLayout>
</com.lnysky.scorpio.StateLayout>
```

```java
private StateLayout stateLayout;
private StateLayout stateLayout;

Scorpio.with(stateLayout).loading().setTips("加载中...").show();
Scorpio.with(stateLayout).loading().setTips("加载中...").show();
```

- StateLayout不含content view,则必须调用setContentView方法设置content view,此方法只能调用一次。代码如下:
StateLayout不含子view,则必须调用setContentView方法设置content view,此方法只能调用一次。

```java
stateLayout = findViewById(R.id.state_layout);
View contentView = LayoutInflater.from(this)
.inflate(layoutResID, stateLayout, false);
stateLayout.setContentView(contentView);
stateLayout = findViewById(R.id.state_layout);
View contentView = LayoutInflater.from(this).inflate(layoutResID, stateLayout, false);
stateLayout.setContentView(contentView);
```
**注意**:后面会考虑强制有一个view,去掉setContentView()方法。

## License

```
Copyright (C) 2017 - present, Danyon Liu.
Copyright (C) Copyright 2019 lnysky
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
15 changes: 9 additions & 6 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ ext {
]

android = [
applicationId : "com.lnysky.tech.state.sample",
applicationId : "com.lnysky.scorpio.sample",
compileSdkVersion: 28,
buildToolsVersion: "28.0.3",

minSdkVersion : 14,
minSdkVersion : 15,
targetSdkVersion : 28,

versionCode : 1,
versionName : "0.0.1",
]

bintray = [
version : "0.1.1", // 指定库的版本号
group : "com.lnysky.tech", // 库的group名,确定好之后不能修改
version : "0.1.2", // 指定库的版本号
group : "com.lnysky.scorpio", // 库的group名,确定好之后不能修改

siteUrl : "https://github.com/lnysky/scorpio.git", // 项目开源地址
gitUrl : "https://github.com/lnysky/scorpio.git", // 项目git地址
Expand All @@ -41,7 +41,10 @@ ext {
]

dependencies = [
appCompat : "androidx.appcompat:appcompat:1.0.0",
constraint: "androidx.constraintlayout:constraintlayout:1.1.2"
appCompat : "com.android.support:appcompat-v7:27.1.1",
constraint: "com.android.support.constraint:constraint-layout:1.1.3",

xAppCompat : "androidx.appcompat:appcompat:1.0.0",
xConstraint: "androidx.constraintlayout:constraintlayout:1.1.2"
]
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':scorpio'
include ':support', ':supportSample', ':x', ':xSample'
File renamed without changes.
37 changes: 37 additions & 0 deletions support/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 29


defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

resourcePrefix "scorpio_"
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation rootProject.ext.dependencies.appCompat
}

apply from: 'https://raw.githubusercontent.com/yanzhenjie/bintray/master/maven.gradle'
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.lnysky.scorpio;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.lnysky.scorpio.test", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lnysky.tech.scorpio" />
package="com.lnysky.scorpio" />
23 changes: 23 additions & 0 deletions support/src/main/java/com/lnysky/scorpio/ActivityBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lnysky.scorpio;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;


public final class ActivityBar extends Wrapper {

@NonNull
private final Activity activity;

ActivityBar(@NonNull Activity activity) {
this.activity = activity;
}

@NonNull
protected Bar getRealBar() {
View view = ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
return Utils.viewWrapper(view);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.lnysky.tech.scorpio;
package com.lnysky.scorpio;

public interface Bar {

Expand Down
54 changes: 54 additions & 0 deletions support/src/main/java/com/lnysky/scorpio/Content.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.lnysky.scorpio;

import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import java.lang.reflect.InvocationTargetException;

/**
* Created by lny on 2018/11/28.
*/
public final class Content extends StateLayout.State<StateLayout.ViewHolder> {

private View view;

public Content(View view) {
this.view = view;
}

@NonNull
@Override
public StateLayout.ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent) {
return new StateLayout.ViewHolder(view);
}

static class Factory implements StateLayout.Factory {

private View view;

Factory(View view) {
this.view = view;
}

@SuppressWarnings("ClassNewInstance")
@NonNull
@Override
public <T extends StateLayout.State> T create(@NonNull Class<T> modelClass) {
//noinspection TryWithIdenticalCatches
try {
return modelClass.getConstructor(View.class).newInstance(view);
} catch (InstantiationException e) {
throw new RuntimeException("Cannot create an instance of " + modelClass, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot create an instance of " + modelClass, e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Cannot create an instance of " + modelClass, e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot create an instance of " + modelClass, e);
}
}
}
}
59 changes: 59 additions & 0 deletions support/src/main/java/com/lnysky/scorpio/Empty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.lnysky.scorpio;

import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


/**
* Created by lny on 2018/11/28.
*/
public class Empty extends StateLayout.State<Empty.ViewHolder> {

@DrawableRes
private int img;
private String tips;

@NonNull
@Override
public ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent) {
View view = inflater.inflate(R.layout.scorpio_state_empty, parent, false);
return new ViewHolder(view);
}

@Override
protected void onSwitchState(ViewHolder holder, boolean showing) {
super.onSwitchState(holder, showing);
if (img != 0) {
holder.emptyImage.setImageResource(img);
}
holder.emptyText.setText(tips);
}

public Empty setImg(@DrawableRes int img) {
this.img = img;
return this;
}

public Empty setTips(String tips) {
this.tips = tips;
return this;
}

static class ViewHolder extends StateLayout.ViewHolder {

ImageView emptyImage;
TextView emptyText;

ViewHolder(View view) {
super(view);
emptyImage = view.findViewById(R.id.empty_image);
emptyText = view.findViewById(R.id.empty_text);
}
}

}
Loading

0 comments on commit f313fba

Please sign in to comment.