-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CoreAppCompatActivity with delegate API (#407)
- Loading branch information
Showing
10 changed files
with
270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2017. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
buildscript { | ||
dependencies { | ||
classpath deps.build.gradlePlugins.android | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion deps.build.compileSdkVersion | ||
buildToolsVersion deps.build.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion deps.build.minSdkVersion | ||
targetSdkVersion deps.build.targetSdkVersion | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility deps.build.javaVersion | ||
targetCompatibility deps.build.javaVersion | ||
} | ||
|
||
testOptions { | ||
unitTests { | ||
includeAndroidResources = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation deps.apt.javaxInject | ||
implementation deps.androidx.annotations | ||
implementation deps.androidx.appcompat | ||
testImplementation deps.external.roboelectricBase | ||
testImplementation deps.androidx.appcompat | ||
} | ||
|
||
apply from: rootProject.file('gradle/gradle-mvn-push.gradle') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Copyright (C) 2017. Uber Technologies | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
POM_NAME=RIBs (Android Core) | ||
POM_ARTIFACT_ID=rib-android-core | ||
POM_PACKAGING=android |
2 changes: 2 additions & 0 deletions
2
android/libraries/rib-android-core/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.uber.rib.android.core"/> |
58 changes: 58 additions & 0 deletions
58
android/libraries/rib-android-core/src/main/java/com/uber/rib/core/ActivityDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2017. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.core; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import androidx.annotation.IntRange; | ||
import androidx.annotation.Nullable; | ||
|
||
/** | ||
* This class represents a delegate which you can use to extend CoreAppCompatActivity's | ||
* functionality. This allows RibActivity and any other type of Activity that you need to support to | ||
* share CoreAppCompatActivity as a common parent. | ||
*/ | ||
public interface ActivityDelegate { | ||
/** @see {@link Activity#onCreate(Bundle) } */ | ||
default void onCreate(@Nullable Bundle savedInstanceState) {} | ||
|
||
/** @see {@link Activity#onStart() } */ | ||
default void onStart() {} | ||
|
||
/** @see {@link Activity#onResume() } */ | ||
default void onResume() {} | ||
|
||
/** @see {@link Activity#onPause() } */ | ||
default void onPause() {} | ||
|
||
/** @see {@link Activity#onStop() } */ | ||
default void onStop() {} | ||
|
||
/** @see {@link Activity#onDestroy() } */ | ||
default void onDestroy() {} | ||
|
||
/** @see {@link Activity#onActivityResult(Activity, int, int, Intent) } */ | ||
default void onActivityResult( | ||
Activity activity, int requestCode, int resultCode, @Nullable Intent data) {} | ||
|
||
/** @see {@link Activity#onRequestPermissionsResult(Activity, int, String[], int[]) } */ | ||
default void onRequestPermissionsResult( | ||
Activity activity, | ||
@IntRange(from = 0, to = 255) int requestCode, | ||
String[] permissions, | ||
int[] grantResults) {} | ||
} |
106 changes: 106 additions & 0 deletions
106
...oid/libraries/rib-android-core/src/main/java/com/uber/rib/core/CoreAppCompatActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (C) 2017. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.core; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import androidx.annotation.CallSuper; | ||
import androidx.annotation.IntRange; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
/** Core Support v7 AppCompat Activity. */ | ||
public abstract class CoreAppCompatActivity extends AppCompatActivity { | ||
|
||
@Nullable private ActivityDelegate activityDelegate; | ||
|
||
@CallSuper | ||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
if (getApplicationContext() instanceof HasActivityDelegate) { | ||
activityDelegate = ((HasActivityDelegate) getApplicationContext()).activityDelegate(); | ||
} | ||
super.onCreate(savedInstanceState); | ||
if (activityDelegate != null) { | ||
activityDelegate.onCreate(savedInstanceState); | ||
} | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
if (activityDelegate != null) { | ||
activityDelegate.onStart(); | ||
} | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
if (activityDelegate != null) { | ||
activityDelegate.onResume(); | ||
} | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void onPause() { | ||
if (activityDelegate != null) { | ||
activityDelegate.onPause(); | ||
} | ||
super.onPause(); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void onStop() { | ||
if (activityDelegate != null) { | ||
activityDelegate.onStop(); | ||
} | ||
super.onStop(); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void onDestroy() { | ||
if (activityDelegate != null) { | ||
activityDelegate.onDestroy(); | ||
activityDelegate = null; | ||
} | ||
super.onDestroy(); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
public void onRequestPermissionsResult( | ||
@IntRange(from = 0, to = 255) int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (activityDelegate != null) { | ||
activityDelegate.onRequestPermissionsResult(this, requestCode, permissions, grantResults); | ||
} | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (activityDelegate != null) { | ||
activityDelegate.onActivityResult(this, requestCode, resultCode, data); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
android/libraries/rib-android-core/src/main/java/com/uber/rib/core/HasActivityDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2017. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.core; | ||
|
||
/** Interface to indicate an object has a CoreAppCompatActivity.Delegate. */ | ||
public interface HasActivityDelegate { | ||
|
||
/** | ||
* Get the delegate. | ||
* | ||
* @return The delegate. | ||
*/ | ||
ActivityDelegate activityDelegate(); | ||
} |
1 change: 1 addition & 0 deletions
1
android/libraries/rib-android-core/src/test/resources/robolectric.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
constants=com.uber.rib.android.test.BuildConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters