Skip to content

Commit

Permalink
Rewrite to use fragments for better view control
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Oct 21, 2024
1 parent 8c55ac1 commit 50bf533
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 247 deletions.
4 changes: 2 additions & 2 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.7.0" apply false
id("com.android.library") version "8.7.0" apply false
id("com.android.application") version "8.7.1" apply false
id("com.android.library") version "8.7.1" apply false
}

tasks.wrapper {
Expand Down
1 change: 1 addition & 0 deletions android/fuse/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.webkit:webkit:1.12.1")
implementation("androidx.fragment:fragment:1.8.4")
implementation("org.bouncycastle:bcprov-jdk18on:1.77")
implementation("org.bouncycastle:bcpkix-jdk18on:1.77")

Expand Down
306 changes: 153 additions & 153 deletions android/fuse/src/main/java/com/breautek/fuse/FuseActivity.java
Original file line number Diff line number Diff line change
@@ -1,153 +1,153 @@

/*
Copyright 2023 Breautek
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.breautek.fuse;

import android.os.Bundle;

import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.view.View;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;

import android.view.Window;

import com.breautek.fuse.plugins.IFusePluginRegistrar;

/**
* Convenience class that can be extended which provides
* a FuseContext with all the glue bits already done.
*
* If fine control is required, it is possible to create the FuseContext
* itself, you'll need to pass through the following lifecycle methods:
* - onCreate(Bundle)
* - onStart
* - onResume
* - onPause
* - onSaveInstanceState(Bundle)
* - onLowMemory
* - onRequestPermissionsResult
* - onStop
* - onDestroy
*/
public class FuseActivity extends AppCompatActivity {

private FuseContext $fuseContext;

public FuseActivity() {
super();
$init();
}

@ContentView
public FuseActivity(@LayoutRes int contentLayoutId) {
super(contentLayoutId);
$init();
}

private void $init() {
$fuseContext = new FuseContext(this, this::_onContextReady);
$fuseContext.$pluginMapLock.writeLock().lock();
_registerFusePlugins(plugin -> $fuseContext.$registerPlugin(plugin));
$fuseContext.$pluginMapLock.writeLock().unlock();
}

protected void _onContextReady() {}

/**
* Can be overwritten by subclasses to register plugins
*
* @param registrar
*/
protected void _registerFusePlugins(IFusePluginRegistrar registrar) {}

public FuseContext getFuseContext() {
return $fuseContext;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Window window = getWindow();
WindowCompat.setDecorFitsSystemWindows(window, false);
$fuseContext.onCreate(savedInstanceState);
View contentView = $fuseContext.getLayout();
setContentView(contentView);

WindowInsetsControllerCompat controller = WindowCompat.getInsetsController(window, contentView);
controller.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_DEFAULT);
}

@Override
protected void onStart() {
super.onStart();
$fuseContext.onStart();
}

@Override
protected void onStop() {
super.onStop();
$fuseContext.onStop();
}

@Override
public void onLowMemory() {
super.onLowMemory();
$fuseContext.onLowMemory();
}

@Override
protected void onPause() {
super.onPause();
$fuseContext.onPause();
}

@Override
protected void onResume() {
super.onResume();
$fuseContext.onResume();
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
$fuseContext.onSaveInstanceState(outState);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
$fuseContext.onRequestPermissionResult(requestCode, permissions, grantResults);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
$fuseContext.onActivityResult(requestCode, resultCode, data);
}

@Override
protected void onDestroy() {
super.onDestroy();
$fuseContext.onDestroy();
}
}
//
///*
//Copyright 2023 Breautek
//
//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.breautek.fuse;
//
//import android.os.Bundle;
//
//import androidx.annotation.ContentView;
//import androidx.annotation.LayoutRes;
//import androidx.annotation.NonNull;
//import androidx.appcompat.app.AppCompatActivity;
//import android.content.Intent;
//import android.view.View;
//import androidx.core.view.WindowCompat;
//import androidx.core.view.WindowInsetsControllerCompat;
//
//import android.view.Window;
//
//import com.breautek.fuse.plugins.IFusePluginRegistrar;
//
///**
// * Convenience class that can be extended which provides
// * a FuseContext with all the glue bits already done.
// *
// * If fine control is required, it is possible to create the FuseContext
// * itself, you'll need to pass through the following lifecycle methods:
// * - onCreate(Bundle)
// * - onStart
// * - onResume
// * - onPause
// * - onSaveInstanceState(Bundle)
// * - onLowMemory
// * - onRequestPermissionsResult
// * - onStop
// * - onDestroy
// */
//public class FuseActivity extends AppCompatActivity {
//
// private FuseContext $fuseContext;
//
// public FuseActivity() {
// super();
// $init();
// }
//
// @ContentView
// public FuseActivity(@LayoutRes int contentLayoutId) {
// super(contentLayoutId);
// $init();
// }
//
// private void $init() {
// $fuseContext = new FuseContext(this, this::_onContextReady);
// $fuseContext.$pluginMapLock.writeLock().lock();
// _registerFusePlugins(plugin -> $fuseContext.$registerPlugin(plugin));
// $fuseContext.$pluginMapLock.writeLock().unlock();
// }
//
// protected void _onContextReady() {}
//
// /**
// * Can be overwritten by subclasses to register plugins
// *
// * @param registrar
// */
// protected void _registerFusePlugins(IFusePluginRegistrar registrar) {}
//
// public FuseContext getFuseContext() {
// return $fuseContext;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
//
// Window window = getWindow();
// WindowCompat.setDecorFitsSystemWindows(window, false);
// $fuseContext.onCreate(savedInstanceState);
// View contentView = $fuseContext.getLayout();
// setContentView(contentView);
//
// WindowInsetsControllerCompat controller = WindowCompat.getInsetsController(window, contentView);
// controller.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_DEFAULT);
// }
//
// @Override
// protected void onStart() {
// super.onStart();
// $fuseContext.onStart();
// }
//
// @Override
// protected void onStop() {
// super.onStop();
// $fuseContext.onStop();
// }
//
// @Override
// public void onLowMemory() {
// super.onLowMemory();
// $fuseContext.onLowMemory();
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// $fuseContext.onPause();
// }
//
// @Override
// protected void onResume() {
// super.onResume();
// $fuseContext.onResume();
// }
//
// @Override
// protected void onSaveInstanceState(@NonNull Bundle outState) {
// super.onSaveInstanceState(outState);
// $fuseContext.onSaveInstanceState(outState);
// }
//
// @Override
// public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// $fuseContext.onRequestPermissionResult(requestCode, permissions, grantResults);
// }
//
// @Override
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
// $fuseContext.onActivityResult(requestCode, resultCode, data);
// }
//
// @Override
// protected void onDestroy() {
// super.onDestroy();
// $fuseContext.onDestroy();
// }
//}
Loading

0 comments on commit 50bf533

Please sign in to comment.