Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some inspection results #5

Merged
merged 10 commits into from
Sep 15, 2017
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ In your `build.gradle`:

```groovy
dependencies {
compile 'me.drakeet.floo:floo:1.0.2'
compile 'me.drakeet.floo:floo:1.0.4'
}
```

If you are using `com.android.tools.build:gradle:3.+`, use this instead:

```groovy
dependencies {
implementation 'me.drakeet.floo:floo:1.0.2'
implementation 'me.drakeet.floo:floo:1.0.4'
}
```

Expand Down
9 changes: 9 additions & 0 deletions findbugs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Or>
<Class name="~.*\.R\$.*"/>
<Class name="~.*\.Manifest\$.*"/>
</Or>
</Match>
</FindBugsFilter>
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 4
versionName "1.0.2"
versionCode 6
versionName "1.0.4"
}

buildTypes {
Expand Down
4 changes: 2 additions & 2 deletions library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
POM_NAME=floo
POM_ARTIFACT_ID=floo
POM_PACKAGING=aar
VERSION_NAME=1.0.2
VERSION_CODE=4
VERSION_NAME=1.0.4
VERSION_CODE=6
GROUP=me.drakeet.floo
POM_DESCRIPTION=A router supporting AOP, stack control, cross-page message, and dynamic routing.
POM_URL=http://github.com/drakeet/Floo
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/me/drakeet/floo/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class Configuration {

private @NonNull TargetMap targetMap;
private @NonNull final TargetMap targetMap;
private @NonNull final List<TargetNotFoundHandler> targetNotFoundHandlers;
private @NonNull final List<Interceptor> requestInterceptors;
private @NonNull final List<Interceptor> targetInterceptors;
Expand Down Expand Up @@ -126,7 +126,6 @@ Target getTarget(@NonNull String url) {
@RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void initStackObserverIfNeed(@NonNull Activity activity) {
if (!stackObserverInitialized) {

activity.getApplication().registerActivityLifecycleCallbacks(
new ActivityOnResumeCallback() {

Expand All @@ -135,6 +134,7 @@ public void onActivityResumed(@NonNull Activity activity) {
StackManager.onActivityResumed(activity);
}
});
stackObserverInitialized = true;
}
}
}
20 changes: 10 additions & 10 deletions library/src/main/java/me/drakeet/floo/Floo.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public final class Floo implements Navigation {

private static final Configuration CONFIGURATION = new Configuration();

private @NonNull Context context;
private @NonNull Bundle bundle;
private @NonNull Map<String, String> queryParams;
private @NonNull final Context context;
private @NonNull final Bundle bundle;
private @NonNull final Map<String, String> queries;
private @NonNull Uri sourceUri;

private @Nullable Uri targetUri;
Expand All @@ -64,7 +64,7 @@ private Floo(@NonNull Context context, @NonNull String url) {
this.context = context;
this.bundle = new Bundle();
this.sourceUri = Uri.parse(url);
this.queryParams = new HashMap<>();
this.queries = new HashMap<>();
}


Expand Down Expand Up @@ -173,7 +173,7 @@ public Navigation putExtras(@NonNull Bundle bundle) {
*/
@NonNull @Override @CheckResult
public Navigation appendQueryParameter(@NonNull String key, @NonNull String value) {
queryParams.put(key, value);
queries.put(key, value);
return this;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ public void ifIntentNonNullSendTo(@NonNull IntentReceiver receiver) {
*/
@Nullable @Override @CheckResult
public Intent getIntent() {
sourceUri = appendSourceUri(sourceUri, queryParams);
sourceUri = appendSourceUri(sourceUri, queries);
Chain chain = interceptRequest(sourceUri);
sourceUri = chain.request();
if (chain.isProceed()) {
Expand Down Expand Up @@ -334,8 +334,8 @@ private void dispatchTargetNotFoundEvent(@NonNull Uri sourceUri, @NonNull Bundle
@NonNull
private Uri appendSourceUri(@NonNull final Uri base, @NonNull final Map<String, String> queryParams) {
final Uri.Builder sourceBuilder = base.buildUpon();
for (String paramKey : queryParams.keySet()) {
sourceBuilder.appendQueryParameter(paramKey, queryParams.get(paramKey));
for (Map.Entry<String, String> query : queryParams.entrySet()) {
sourceBuilder.appendQueryParameter(query.getKey(), query.getValue());
}
return sourceBuilder.build();
}
Expand All @@ -362,8 +362,8 @@ private String mergeEncodedQuery(@NonNull Uri sourceUri, @NonNull Uri sessionUri
map.putAll(encodedQueryParameters(sourceUri));
map.putAll(encodedQueryParameters(sessionUri));
StringBuilder builder = new StringBuilder();
for (String key : map.keySet()) {
builder.append(key).append("=").append(map.get(key)).append("&");
for (Map.Entry<String, String> query : map.entrySet()) {
builder.append(query.getKey()).append("=").append(query.getValue()).append("&");
}
String result = builder.toString();
if (result.endsWith("&")) {
Expand Down
3 changes: 1 addition & 2 deletions library/src/main/java/me/drakeet/floo/StackCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

package me.drakeet.floo;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
* @author drakeet
*/
public interface StackCallback {

@NonNull String indexKeyForStackTarget();
@Nullable String indexKeyForStackTarget();

void onReceivedResult(@Nullable Object result);
}
10 changes: 8 additions & 2 deletions library/src/main/java/me/drakeet/floo/StackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Objects;

/**
* @author drakeet
Expand Down Expand Up @@ -109,8 +110,8 @@ private static boolean hasTarget() {
}


private static boolean match(@NonNull String matcherKey) {
return matcherKey.equals(StackManager.targetIndexKey);
private static boolean match(@Nullable String matcherKey) {
return equals(matcherKey, StackManager.targetIndexKey);
}


Expand All @@ -133,4 +134,9 @@ private static boolean match(@NonNull String matcherKey) {
private static StackCallback stackCallback(@NonNull Activity activity) {
return (StackCallback) activity;
}


private static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
}
}
8 changes: 4 additions & 4 deletions library/src/main/java/me/drakeet/floo/TargetMapParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public Map<String, Target> fromJson(@Nullable String json) throws JSONException
/**
* Convert a target map to JSON string.
*
* @param map The target map.
* @param targetMap The target map.
* @return A JSON string of the map.
*/
@NonNull
public String toJson(@NonNull Map<String, Target> map) {
public String toJson(@NonNull Map<String, Target> targetMap) {
final Map<String, JSONObject> flatMap = new HashMap<>();
for (String key : map.keySet()) {
for (Map.Entry<String, Target> entry : targetMap.entrySet()) {
try {
flatMap.put(key, toJsonObject(map.get(key)));
flatMap.put(entry.getKey(), toJsonObject(entry.getValue()));
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -38,8 +37,11 @@ public class ContainerActivity extends AppCompatActivity implements StackCallbac
private TextView textView;


@NonNull @Override
@Nullable @Override
public String indexKeyForStackTarget() {
if (getIntent().getData() == null) {
return null;
}
String pageURLOfThis = getIntent().getData().getQueryParameter("url");
Uri pageUri = Uri.parse(pageURLOfThis);

Expand Down
6 changes: 3 additions & 3 deletions sample/src/main/java/me/drakeet/floo/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
TextView text = (TextView) findViewById(R.id.text);
Map<String, Target> targetMap = Floo.getTargetMap();
for (String url : targetMap.keySet()) {
text.append(url);
for (Map.Entry<String, Target> entry : targetMap.entrySet()) {
text.append(entry.getKey());
text.append("\t\t <-> \t\t");
text.append(targetMap.get(url).toTargetUrl());
text.append(entry.getValue().toTargetUrl());
text.append("\n");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
text.append("\n\n\nExtras: \n\n");

Bundle bundle = intent.getExtras();
assert bundle != null;
for (String key : bundle.keySet()) {
text.append(key + "\n" + bundle.get(key) + "\n\n");
}
Expand All @@ -47,6 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
setTitle(Uri.parse(sourceUrl).getPath());
}

// noinspection ConstantConditions
String subUrl = intent.getData().getQueryParameter("url");
if (subUrl != null) {
text.append("\n\nSUB-URL: ");
Expand Down
9 changes: 7 additions & 2 deletions sample/src/main/java/me/drakeet/floo/sample/WebActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package me.drakeet.floo.sample;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
Expand All @@ -28,19 +29,23 @@

public class WebActivity extends AppCompatActivity {

public static final String URL = "url";
private static final String URL = "url";
private TextView loading;


@Override
@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
WebView webView = (WebView) findViewById(R.id.web_view);
String url = getIntent().getStringExtra(URL);
if (url == null) {
if (url == null && getIntent().getData() != null) {
url = getIntent().getData().getQueryParameter(URL);
}
if (url == null) {
finish();
}
webView.setWebViewClient(new InnerWebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
Expand Down
25 changes: 0 additions & 25 deletions sample/src/main/res/drawable/divider.xml

This file was deleted.

4 changes: 3 additions & 1 deletion sample/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
-->

<menu
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/github"
android:title="GitHub"
app:showAsAction="always"/>
app:showAsAction="always"
tools:ignore="HardcodedText"/>

</menu>
2 changes: 0 additions & 2 deletions sample/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@
-->

<resources>
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
4 changes: 3 additions & 1 deletion sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
~ limitations under the License.
-->

<resources>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyEllipsis">
<string name="app_name">Floo</string>
<string name="loading">Loading...</string>
</resources>