use asynclayoutinflater instead of new thread
This commit is contained in:
parent
37ced479ac
commit
68531a5a95
|
@ -32,6 +32,7 @@ dependencies {
|
|||
implementation 'commons-io:commons-io:2.11.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.5.1'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.tungsten.fcllibrary.component.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.asynclayoutinflater.view.AsyncLayoutInflater;
|
||||
|
||||
import com.tungsten.fclcore.task.Task;
|
||||
import com.tungsten.fcllibrary.component.FCLActivity;
|
||||
|
@ -30,8 +30,11 @@ public abstract class FCLBaseUI implements FCLUILifecycleCallbacks {
|
|||
return activity;
|
||||
}
|
||||
|
||||
public Task<?> setContentView(@LayoutRes int id) {
|
||||
return Task.runAsync(() -> contentView = LayoutInflater.from(getContext()).inflate(id, null));
|
||||
public void setContentView(@LayoutRes int id, OnInflateFinishedListener listener) {
|
||||
new AsyncLayoutInflater(context).inflate(id, null, (view, resid, parent) -> {
|
||||
contentView = view;
|
||||
listener.onFinish();
|
||||
});
|
||||
}
|
||||
|
||||
public View getContentView() {
|
||||
|
@ -76,4 +79,8 @@ public abstract class FCLBaseUI implements FCLUILifecycleCallbacks {
|
|||
public void onDestroy() {
|
||||
|
||||
}
|
||||
|
||||
public interface OnInflateFinishedListener {
|
||||
void onFinish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,7 @@ import android.view.ViewGroup;
|
|||
|
||||
import androidx.annotation.LayoutRes;
|
||||
|
||||
import com.tungsten.fclcore.task.Schedulers;
|
||||
import com.tungsten.fclcore.task.Task;
|
||||
import com.tungsten.fclcore.util.function.ExceptionalRunnable;
|
||||
import com.tungsten.fcllibrary.R;
|
||||
import com.tungsten.fcllibrary.anim.DisplayAnimUtils;
|
||||
import com.tungsten.fcllibrary.component.view.FCLUILayout;
|
||||
|
@ -22,11 +20,12 @@ public abstract class FCLCommonUI extends FCLBaseUI {
|
|||
public FCLCommonUI(Context context, FCLUILayout parent, @LayoutRes int id) {
|
||||
super(context);
|
||||
this.parent = parent;
|
||||
setContentView(id).thenRunAsync(Schedulers.androidUIThread(), (ExceptionalRunnable<Exception>) this::onCreate).thenRunAsync(Schedulers.androidUIThread(), (ExceptionalRunnable<Exception>) () -> {
|
||||
setContentView(id, () -> {
|
||||
onCreate();
|
||||
if (callback != null) {
|
||||
callback.onLoad();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue