Skip to content

Commit

Permalink
feat(*):优化WebView、自动播放、返回键;使用时按TODO切换碎片
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMate-520 committed Aug 20, 2022
1 parent eba5ad6 commit 8bc7ff6
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 17 deletions.
14 changes: 4 additions & 10 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation files('libs\\tbs_sdk_thirdapp_v4.3.0.316_44216_sharewithdownloadwithfile_withoutGame_obfs_20220728_101601.jar')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down Expand Up @@ -160,4 +161,5 @@ dependencies {
implementation 'androidx.work:work-runtime:2.5.0'

implementation 'com.contrarywind:Android-PickerView:4.1.9'

}
Binary file not shown.
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
android:theme="@style/Theme.Potato"
tools:targetApi="31">
<activity
android:name=".tetsActivity"
android:name=".module.mine.activity.WebViewTestActivity"
android:exported="false" />

<activity
android:name=".module.videolist.activity.RankActivity"
android:exported="false" />
Expand All @@ -51,6 +52,14 @@
<action android:name="com.aweme.opensdk.action.stay.in.dy.im" />
</intent-filter>
</receiver>

<!-- 该Service仅在TBS内核首次Dex加载时触发并执行dex2oat任务,任务完成后自动结束。-->
<service
android:name="com.tencent.smtt.export.external.DexClassLoaderProviderService"
android:label="dexopt"
android:process=":dexopt" >
</service>

</application>

</manifest>
21 changes: 21 additions & 0 deletions app/src/main/java/com/qxy/potato/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.qxy.potato.util.MyUtil;
import com.tamsiree.rxkit.RxTool;
import com.tencent.mmkv.MMKV;
import com.tencent.smtt.sdk.QbSdk;

import org.greenrobot.eventbus.EventBus;

/**
Expand Down Expand Up @@ -69,6 +71,25 @@ public void onCreate() {
LogUtil.setIsLog(true);
//注册Activity生命周期
registerActivityLifecycleCallbacks(ActivityUtil.getActivityLifecycleCallbacks());

QbSdk.initX5Environment(getContext(), new QbSdk.PreInitCallback() {
@Override
public void onCoreInitFinished() {
// 内核初始化完成,可能为系统内核,也可能为系统内核
}

/**
* 预初始化结束
* 由于X5内核体积较大,需要依赖网络动态下发,所以当内核不存在的时候,默认会回调false,此时将会使用系统内核代替
* @param isX5 是否使用X5内核
*/
@Override
public void onViewInitFinished(boolean isX5) {
LogUtil.i("是否使用腾讯内核:"+isX5);

}
});

}

public static Context getContext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.qxy.potato.module.mine.activity;

import android.app.Fragment;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;
import android.webkit.WebViewFragment;

import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
Expand All @@ -16,35 +17,38 @@
import com.bytedance.sdk.open.aweme.common.model.BaseResp;
import com.bytedance.sdk.open.douyin.DouYinOpenApiFactory;
import com.bytedance.sdk.open.douyin.api.DouYinOpenApi;
import com.qxy.potato.R;
import com.qxy.potato.base.BaseActivity;
import com.qxy.potato.base.BaseEvent;
import com.qxy.potato.bean.PictureGirl;
import com.qxy.potato.annotation.BindEventBus;
import com.qxy.potato.bean.VideoVersion;
import com.qxy.potato.common.EventCode;
import com.qxy.potato.common.GlobalConstant;
import com.qxy.potato.databinding.ActivityMainBinding;
import com.qxy.potato.module.mine.fragment.TestFragment;
import com.qxy.potato.module.mine.fragment.VideoDisplayragment;
import com.qxy.potato.module.mine.presenter.MinePresenter;
import com.qxy.potato.module.mine.view.IMineView;
import com.qxy.potato.module.mine.workmanager.ClientCancelWork;
import com.qxy.potato.module.videolist.activity.RankActivity;
import com.qxy.potato.util.ActivityUtil;
import com.qxy.potato.util.EventBusUtil;
import com.qxy.potato.util.LogUtil;
import com.qxy.potato.util.ToastUtil;
import com.tencent.mmkv.MMKV;
import com.tencent.smtt.sdk.WebView;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

@BindEventBus
public class MineActivity extends BaseActivity<MinePresenter, ActivityMainBinding> implements IMineView, IApiEventHandler {
DouYinOpenApi douYinOpenApi;
MMKV kv = MMKV.defaultMMKV();

private long mBackPressed;//用来记录按下时间,连点两次返回键才返回
private static final int BACK_PRESSED_INTERVAL = 1500;//时间间隔

/**
* 初始化presenter,也是与Activity的绑定
*
Expand All @@ -71,7 +75,18 @@ protected void initView() {
getBinding().btnRegister.setOnClickListener(v -> ActivityUtil.startActivity(LoginActivity.class));

//跳转到榜单
getBinding().imgRank.setOnClickListener(v->ActivityUtil.startActivity(RankActivity.class));
// getBinding().imgRank.setOnClickListener(v->ActivityUtil.startActivity(RankActivity.class));

//跳转到Webview测试用
// getBinding().imgRank.setOnClickListener(v->ActivityUtil.startActivity(WebViewTestActivity.class));


//TODO: 个人界面碎片按下面样例添加;跳转到视频碎片需传入url。
// //个人界面碎片
// getFragmentManager().beginTransaction().add(R.id.fragment_webview, new TestFragment()).commit();
// //打开视频详情页(添加tag)
// getFragmentManager().beginTransaction().add(R.id.fragment_webview, VideoDisplayragment.newInstance(url),"WebView").addToBackStack(null).commit();


presenter.getClientVersionDemo();

Expand All @@ -85,6 +100,7 @@ protected void initData() {
douYinOpenApi = DouYinOpenApiFactory.create(this);
douYinOpenApi.handleIntent(getIntent(), this);
initClient();
mBackPressed =System.currentTimeMillis();
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down Expand Up @@ -164,4 +180,38 @@ private void initClient() {
kv.encode(GlobalConstant.IS_CLIENT,false);
presenter.getClientToken();
}


/**
* 配置Webview的返回键,碎片切换要加到返回栈中
*/
@Override public void onBackPressed() {
Fragment fragment = getFragmentManager().findFragmentByTag("WebView");
if(fragment!=null){//说明现在是webview播放页面
VideoDisplayragment videoDisplayragment = (VideoDisplayragment) fragment;
WebView webView = videoDisplayragment.getmWebViewWebView();
//不空且是焦点
if (webView != null && webView.isFocused()) {

if (webView.canGoBack()) {//WebView的向前
webView.goBack();
} else {
if(mBackPressed + BACK_PRESSED_INTERVAL > System.currentTimeMillis()){//连续两次才返回到个人碎片(1.5s内)
super.onBackPressed();
return;
}else{//提示
ToastUtil.showToast("再点一次返回键返回个人界面");
mBackPressed = System.currentTimeMillis();

}
}
}
} else {//正常系统返回键
super.onBackPressed();
}


}


}
Loading

0 comments on commit 8bc7ff6

Please sign in to comment.