Skip to content

Commit 5f0b0c2

Browse files
author
Jon Amireh
committed
Introduce isStandalone() to PluginModule
1 parent 4d80138 commit 5f0b0c2

File tree

14 files changed

+90
-13
lines changed

14 files changed

+90
-13
lines changed

hyperion-attr/src/main/java/com/willowtreeapps/hyperion/attr/AttributeInspectorModule.java

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ protected void onDestroy() {
4949
menu.removeOnMenuStateChangedListener(this);
5050
}
5151

52+
@Override
53+
public boolean isStandalone() {
54+
return false;
55+
}
56+
5257
@Override
5358
public void onClick(View v) {
5459
final View currentOverlay = overlay.getOverlayView();

hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/CoreComponent.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ interface CoreComponent {
4040

4141
Set<PluginModule> getPluginModules();
4242

43+
PluginFilter getPluginFilter();
44+
4345
@Component.Builder
4446
interface Builder {
4547

@@ -48,9 +50,6 @@ interface Builder {
4850
@BindsInstance
4951
Builder activity(Activity activity);
5052

51-
@BindsInstance
52-
Builder pluginSource(PluginSource pluginSource);
53-
5453
@BindsInstance
5554
Builder activityResults(ActivityResults activityResults);
5655

@@ -60,6 +59,9 @@ interface Builder {
6059
@BindsInstance
6160
Builder container(ViewGroup container);
6261

62+
@BindsInstance
63+
Builder pluginFilter(PluginFilter pluginFilter);
64+
6365
CoreComponent build();
6466
}
6567

hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/HyperionPluginView.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class HyperionPluginView extends FrameLayout {
3333
@Inject
3434
Set<PluginModule> modules;
3535

36+
@Inject
37+
PluginFilter filter;
38+
3639
public HyperionPluginView(@NonNull Context context) {
3740
this(context, null);
3841
}
@@ -66,9 +69,11 @@ public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets)
6669
}
6770
});
6871

72+
Set<PluginModule> filteredModules = filter.filter(modules);
73+
6974
final Comparator<PluginModule> comparator = new AlphabeticalComparator(getContext());
7075
final Set<PluginModule> sortedModules = new TreeSet<>(comparator);
71-
sortedModules.addAll(modules);
76+
sortedModules.addAll(filteredModules);
7277

7378
final Context inflaterContext = new PluginExtensionContextWrapper(getContext(), pluginExtension);
7479
final LayoutInflater inflater = LayoutInflater.from(inflaterContext);
@@ -88,7 +93,7 @@ static final class Factory implements PluginViewFactory {
8893
this.container = container;
8994
}
9095

91-
private CoreComponent getCoreComponent(Activity activity) {
96+
private CoreComponent getCoreComponent(Activity activity, boolean standalone) {
9297
final ViewGroup windowContentView = activity.getWindow().findViewById(android.R.id.content);
9398
final HyperionMenuController controller = new HyperionMenuController(windowContentView);
9499

@@ -102,13 +107,18 @@ private CoreComponent getCoreComponent(Activity activity) {
102107
.commit();
103108
}
104109

110+
PluginFilter filter = new IdentityPluginFilter();
111+
if(standalone) {
112+
filter = new StandalonePluginFilter();
113+
}
114+
105115
CoreComponent component = DaggerCoreComponent.builder()
106116
.appComponent(AppComponent.Holder.getInstance(activity))
107117
.activity(activity)
108-
.pluginSource(container.getPluginSource())
109118
.menuController(controller)
110119
.container(windowContentView)
111120
.activityResults(activityResults)
121+
.pluginFilter(filter)
112122
.build();
113123

114124
container.putComponent(activity, component);
@@ -117,11 +127,11 @@ private CoreComponent getCoreComponent(Activity activity) {
117127

118128
@Override
119129
public View create(Activity activity) {
120-
return createInternal(activity, false);
130+
return createInternal(activity, false, true);
121131
}
122132

123-
HyperionPluginView createInternal(Activity activity, Boolean bindToMenuController) {
124-
CoreComponent component = getCoreComponent(activity);
133+
HyperionPluginView createInternal(Activity activity, boolean bindToMenuController, boolean standalone) {
134+
CoreComponent component = getCoreComponent(activity, standalone);
125135
HyperionPluginView pluginView = new HyperionPluginView(new ComponentContextThemeWrapper(activity, component));
126136
if(bindToMenuController) {
127137
component.getMenuController().setPluginView(pluginView);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.willowtreeapps.hyperion.core.internal;
2+
3+
import com.willowtreeapps.hyperion.plugin.v1.PluginModule;
4+
5+
import java.util.Set;
6+
7+
class IdentityPluginFilter implements PluginFilter {
8+
@Override
9+
public Set<PluginModule> filter(Set<PluginModule> plugins) {
10+
return plugins;
11+
}
12+
}

hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/InstallationLifecycleDelegate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class InstallationLifecycleDelegate extends LifecycleDelegate {
1818

1919
@Override
2020
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
21-
factory.createInternal(activity, true);
21+
factory.createInternal(activity, true, false);
2222
}
2323

2424
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.willowtreeapps.hyperion.core.internal;
2+
3+
import com.willowtreeapps.hyperion.plugin.v1.PluginModule;
4+
5+
import java.util.Set;
6+
7+
interface PluginFilter {
8+
Set<PluginModule> filter(Set<PluginModule> plugins);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.willowtreeapps.hyperion.core.internal;
2+
3+
import com.willowtreeapps.hyperion.plugin.v1.PluginModule;
4+
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
8+
class StandalonePluginFilter implements PluginFilter {
9+
@Override
10+
public Set<PluginModule> filter(Set<PluginModule> plugins) {
11+
HashSet<PluginModule> result = new HashSet<>();
12+
for(PluginModule plugin : plugins) {
13+
if(plugin.isStandalone()) {
14+
result.add(plugin);
15+
}
16+
}
17+
return result;
18+
}
19+
}
20+

hyperion-geiger-counter/src/main/java/com/willowtreeapps/hyperion/geigercounter/GeigerCounterModule.java

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ protected void onDestroy() {
122122
detector.removeObserver(this);
123123
}
124124

125+
@Override
126+
public boolean isStandalone() {
127+
return false;
128+
}
129+
125130
// OnClickListener
126131

127132
@Override

hyperion-measurement/src/main/java/com/willowtreeapps/hyperion/measurement/MeasurementInspectorModule.java

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ protected void onDestroy() {
4040
overlay.removeOnOverlayViewChangedListener(this);
4141
}
4242

43+
@Override
44+
public boolean isStandalone() {
45+
return false;
46+
}
47+
4348
@Override
4449
public void onClick(View v) {
4550
View currentOverlay = overlay.getOverlayView();

hyperion-plugin/src/main/java/com/willowtreeapps/hyperion/plugin/v1/PluginModule.java

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ protected void onDestroy() {
4848

4949
}
5050

51+
public boolean isStandalone() {
52+
return true;
53+
}
54+
5155
@NonNull
5256
public final PluginExtension getExtension() {
5357
return this.extension;

hyperion-recorder/src/main/java/com/willowtreeapps/hyperion/recorder/RecorderPluginModule.java

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ protected void onDestroy() {
5858
RecordingManager.removeOnRecordingChangedListener(this);
5959
}
6060

61+
@Override
62+
public boolean isStandalone() {
63+
return false;
64+
}
65+
6166
@Override
6267
public void onClick(View v) {
6368
if (RecordingManager.isRecording()) {

hyperion-sample/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<activity android:name=".ScreenRecorderActivity" />
2626
<activity android:name=".FileExplorerActivity" />
2727
<activity android:name=".GeigerCounterActivity" />
28-
<activity android:name=".FactoryActivity" />
28+
<activity android:name=".StandaloneActivity" />
2929

3030
</application>
3131

hyperion-sample/src/main/java/com/willowtreeapps/hyperion/sample/GestureFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void onClick(View v) {
3535
openCustomMenuButton.setOnClickListener(new View.OnClickListener() {
3636
@Override
3737
public void onClick(View v) {
38-
startActivity(new Intent(v.getContext(), FactoryActivity.class));
38+
startActivity(new Intent(v.getContext(), StandaloneActivity.class));
3939
}
4040
});
4141
}

hyperion-sample/src/main/java/com/willowtreeapps/hyperion/sample/FactoryActivity.java renamed to hyperion-sample/src/main/java/com/willowtreeapps/hyperion/sample/StandaloneActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.willowtreeapps.hyperion.plugin.v1.HyperionIgnore;
1313

1414
@HyperionIgnore
15-
public class FactoryActivity extends AppCompatActivity {
15+
public class StandaloneActivity extends AppCompatActivity {
1616
private final PluginViewFactory factory = Hyperion.getPluginViewFactory();
1717

1818
@Override

0 commit comments

Comments
 (0)