diff --git a/app/src/main/java/com/cmx/wanhui/activity/LoginActivity.kt b/app/src/main/java/com/cmx/wanhui/activity/LoginActivity.kt index 056eba2..e7662d8 100644 --- a/app/src/main/java/com/cmx/wanhui/activity/LoginActivity.kt +++ b/app/src/main/java/com/cmx/wanhui/activity/LoginActivity.kt @@ -5,16 +5,19 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.text.TextUtils +import android.util.Log import android.view.View -import android.widget.Toast import androidx.core.app.ActivityCompat import com.cmx.wanhui.R +import com.cmx.wanhui.constant.Events import com.cmx.wanhui.model.LoginBean import com.cmx.wanhui.model.LoginRes import com.cmx.wanhui.retrofit.RetrofitAPIManager import com.cmx.wanhui.utils.MyUtils.setAndroidNativeLightStatusBar import com.cmx.wanhui.utils.MyUtils.setFullscreen import com.cmx.wanhui.utils.SpUtils.putString +import com.cmx.wanhui.view.ConfirmDialog +import com.lsxiao.apollo.core.Apollo import es.dmoral.toasty.Toasty import kotlinx.android.synthetic.main.activity_login.btn_login import kotlinx.android.synthetic.main.activity_login.edt_password @@ -24,9 +27,8 @@ import retrofit2.Callback import retrofit2.Response class LoginActivity : BaseActivity() { - private val REQUIRED_PERMISSION_LIST = arrayOf( - Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA - ) + + private val REQUIRED_PERMISSION_LIST = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA) private val REQUEST_PERMISSION_CODE = 99 private var allPermission = true @@ -42,7 +44,6 @@ class LoginActivity : BaseActivity() { Toasty.info(this, "请输入用户名").show() return@OnClickListener } - if (TextUtils.isEmpty(edt_password.text.toString().trim { it <= ' ' })) { Toasty.info(this@LoginActivity, "请输入密码").show() return@OnClickListener @@ -51,7 +52,7 @@ class LoginActivity : BaseActivity() { }) } - + /** * 权限检查 */ @@ -94,18 +95,31 @@ class LoginActivity : BaseActivity() { startActivity(intent) finish() } else { - Toasty.error(this@LoginActivity, response.body()!!.message!!).show() + if (null != response.body() && null != response.body()!!.message) { + Toasty.error(this@LoginActivity, response.body()!!.message!!).show() + } else { + Toasty.error(this@LoginActivity, "登录失败").show() + } } } override fun onFailure(call: Call, t: Throwable) { disDialog() Toasty.info(this@LoginActivity, "登录失败").show() - val intent = Intent(this@LoginActivity, MainActivity::class.java) - startActivity(intent) - finish() } }) } + + override fun onBackPressed() { + ConfirmDialog(this, object : ConfirmDialog.IBack { + override fun confirmBack() { + finish() + } + + override fun cancelBack() { + } + }).show() + } + } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/wanhui/activity/MainActivity.kt b/app/src/main/java/com/cmx/wanhui/activity/MainActivity.kt index b42c87b..224de2e 100644 --- a/app/src/main/java/com/cmx/wanhui/activity/MainActivity.kt +++ b/app/src/main/java/com/cmx/wanhui/activity/MainActivity.kt @@ -3,14 +3,16 @@ package com.cmx.wanhui.activity import android.content.Intent import android.os.Build import android.os.Bundle +import android.util.Log import android.view.View -import android.widget.Toast import androidx.annotation.RequiresApi import androidx.navigation.NavController import androidx.navigation.Navigation import androidx.navigation.ui.NavigationUI import com.cmx.wanhui.R import com.cmx.wanhui.constant.Events +import com.cmx.wanhui.view.ConfirmDialog +import com.cmx.wanhui.view.ConfirmDialog.* import com.google.zxing.integration.android.IntentIntegrator import com.lsxiao.apollo.core.Apollo import com.lsxiao.apollo.core.annotations.Receive @@ -25,8 +27,10 @@ class MainActivity : BaseActivity() { setContentView(R.layout.activity_main) navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main) NavigationUI.setupWithNavController(nav_view, navController!!) + nav_view.itemIconTintList = null } + /** * 显示tabbar */ @@ -35,6 +39,7 @@ class MainActivity : BaseActivity() { nav_view.visibility = View.VISIBLE } + /** * 隐藏tabbar */ @@ -83,6 +88,7 @@ class MainActivity : BaseActivity() { } } + /** * 退出登录 */ @@ -94,6 +100,7 @@ class MainActivity : BaseActivity() { startActivity(intent) } + /** * 二维码扫描 */ @@ -106,6 +113,7 @@ class MainActivity : BaseActivity() { integrator.initiateScan() } + // 处理扫描结果 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data) @@ -114,10 +122,27 @@ class MainActivity : BaseActivity() { } else { // 扫描成功,处理结果 val scannedData = result.contents Apollo.emit(Events.JS_OPEN_SCANQR_BACK, scannedData) - Toast.makeText(this, "扫描结果: $scannedData", Toast.LENGTH_LONG).show() } } else { super.onActivityResult(requestCode, resultCode, data) } } + + + override fun onBackPressed() { + Apollo.emit(Events.JS_OPEN_WEB_BACK) + } + + @Receive(Events.JS_OPEN_WEB_BACK_EXIT) + fun exitApp() { + ConfirmDialog(this, object : IBack { + override fun confirmBack() { + finish() + } + + override fun cancelBack() { + } + }).show() + } + } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/wanhui/activity/MyApplication.kt b/app/src/main/java/com/cmx/wanhui/activity/MyApplication.kt index 27ac2e5..4dff779 100644 --- a/app/src/main/java/com/cmx/wanhui/activity/MyApplication.kt +++ b/app/src/main/java/com/cmx/wanhui/activity/MyApplication.kt @@ -19,6 +19,7 @@ class MyApplication : Application() { companion object { private var mInstance: Context? = null private var mToken: String? = null + @JvmStatic fun getmInstance(): Context? { return mInstance diff --git a/app/src/main/java/com/cmx/wanhui/constant/Events.kt b/app/src/main/java/com/cmx/wanhui/constant/Events.kt index 0804cb1..fd7bdd3 100644 --- a/app/src/main/java/com/cmx/wanhui/constant/Events.kt +++ b/app/src/main/java/com/cmx/wanhui/constant/Events.kt @@ -6,8 +6,17 @@ package com.cmx.wanhui.constant */ interface Events { companion object { - const val WEB_SERVER_URL = "http://8.222.137.126:80" - const val SERVER_URL = "http://192.168.110.174:8000" + + //const val SERVER_URL = "http://192.168.110.174:8000" + //const val WBE_URL = "http://192.168.110.253:5173" + + const val SERVER_URL = "http://120.46.182.114:7777" + const val WBE_URL = "http://120.46.182.114:7788" + + + const val WEB_HOME_URL = WBE_URL + const val WEB_MODE_URL = "$WBE_URL/function" + const val WEB_MY_URL = "$WBE_URL/my" /** * tabbar显示 @@ -49,7 +58,14 @@ interface Events { */ const val JS_OPEN_SCANQR_BACK = "js_open_scan_qr_back" - + /** + * 原生返回_发送给web返回 + */ + const val JS_OPEN_WEB_BACK = "js_open_web_back" + /** + * web无法在返回——退出APP + */ + const val JS_OPEN_WEB_BACK_EXIT = "js_open_web_back_exit" } } diff --git a/app/src/main/java/com/cmx/wanhui/model/QRBean.kt b/app/src/main/java/com/cmx/wanhui/model/QRBean.kt new file mode 100644 index 0000000..5d96f82 --- /dev/null +++ b/app/src/main/java/com/cmx/wanhui/model/QRBean.kt @@ -0,0 +1,5 @@ +package com.cmx.wanhui.model + +class QRBean { + var msg: String? = null +} \ No newline at end of file diff --git a/app/src/main/java/com/cmx/wanhui/ui/BaseFragment.kt b/app/src/main/java/com/cmx/wanhui/ui/BaseFragment.kt index b83df88..0268cc6 100644 --- a/app/src/main/java/com/cmx/wanhui/ui/BaseFragment.kt +++ b/app/src/main/java/com/cmx/wanhui/ui/BaseFragment.kt @@ -42,7 +42,7 @@ open class BaseFragment : Fragment() { fun setWebView(webView: WebView) { val webSettings = webView!!.settings webSettings.javaScriptEnabled = true - webSettings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK + webSettings.cacheMode = WebSettings.LOAD_NO_CACHE webSettings.domStorageEnabled = true webSettings.allowFileAccess = true //文件访问 webSettings.allowFileAccessFromFileURLs = true diff --git a/app/src/main/java/com/cmx/wanhui/ui/HomeFragment.java b/app/src/main/java/com/cmx/wanhui/ui/HomeFragment.java index 53b6e51..5938d1f 100644 --- a/app/src/main/java/com/cmx/wanhui/ui/HomeFragment.java +++ b/app/src/main/java/com/cmx/wanhui/ui/HomeFragment.java @@ -29,10 +29,13 @@ import androidx.lifecycle.ViewModelProvider; import com.cmx.wanhui.activity.LoginActivity; import com.cmx.wanhui.constant.Events; import com.cmx.wanhui.databinding.FragmentHomeBinding; +import com.cmx.wanhui.model.QRBean; import com.cmx.wanhui.utils.AndroidtoJs; import com.cmx.wanhui.utils.L; import com.cmx.wanhui.utils.MyUtils; import com.cmx.wanhui.view.BaseLoadingDialog; +import com.cmx.wanhui.view.ConfirmDialog; +import com.google.gson.Gson; import com.lsxiao.apollo.core.Apollo; import com.lsxiao.apollo.core.annotations.Receive; import com.lsxiao.apollo.core.contract.ApolloBinder; @@ -57,18 +60,11 @@ public class HomeFragment extends BaseFragment { View root = binding.getRoot(); mWebView = binding.wvHome; setWebView(mWebView); - mWebView.loadUrl("https://www.baidu.com/"); + mWebView.loadUrl(Events.WEB_HOME_URL); mWebView.setWebChromeClient(new PQChromeClient()); - binding.tvTe.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Apollo.emit(Events.JS_OPEN_SCANQR); - } - }); return root; } - @Override public void onDestroyView() { super.onDestroyView(); @@ -187,17 +183,35 @@ public class HomeFragment extends BaseFragment { } } + /** * 二维码扫描返回 */ @Receive(Events.JS_OPEN_SCANQR_BACK) public void onQRBack(String msg) { - String jsString = "javascript:onQRBack(" + msg + ")"; - L.e("JS二维码扫描返回>>>>", jsString); + QRBean mQRBean = new QRBean(); + mQRBean.setMsg(msg); + String ms = new Gson().toJson(mQRBean); + String jsString = "javascript:window.onQRBack(" + ms + ")"; + L.e("JS二维码扫描返回>>>>", ms + "<<>>" + jsString); mWebView.evaluateJavascript(jsString, new ValueCallback() { @Override public void onReceiveValue(String s) { } }); } + + + /** + * web返回 + */ + @Receive(Events.JS_OPEN_WEB_BACK) + public void webBack() { + if (mWebView.canGoBack()) { + mWebView.goBack(); + } else { + Apollo.emit(Events.JS_OPEN_WEB_BACK_EXIT); + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/wanhui/ui/ModeFragment.java b/app/src/main/java/com/cmx/wanhui/ui/ModeFragment.java index 71f0da7..295ec3f 100644 --- a/app/src/main/java/com/cmx/wanhui/ui/ModeFragment.java +++ b/app/src/main/java/com/cmx/wanhui/ui/ModeFragment.java @@ -26,10 +26,12 @@ import androidx.fragment.app.Fragment; import com.cmx.wanhui.constant.Events; import com.cmx.wanhui.databinding.FragmentDashboardBinding; +import com.cmx.wanhui.model.QRBean; import com.cmx.wanhui.utils.AndroidtoJs; import com.cmx.wanhui.utils.L; import com.cmx.wanhui.utils.MyUtils; import com.cmx.wanhui.view.BaseLoadingDialog; +import com.google.gson.Gson; import com.lsxiao.apollo.core.Apollo; import com.lsxiao.apollo.core.annotations.Receive; import com.lsxiao.apollo.core.contract.ApolloBinder; @@ -47,12 +49,13 @@ public class ModeFragment extends BaseFragment { private long size = 0; private static final int INPUT_FILE_REQUEST_CODE = 1; + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentDashboardBinding.inflate(inflater, container, false); View root = binding.getRoot(); mWebView = binding.wvLoan; setWebView(mWebView); - mWebView.loadUrl("https://www.baidu.com/"); + mWebView.loadUrl(Events.WEB_MODE_URL); mWebView.setWebChromeClient(new PQChromeClient()); return root; } @@ -176,12 +179,27 @@ public class ModeFragment extends BaseFragment { */ @Receive(Events.JS_OPEN_SCANQR_BACK) public void onQRBack(String msg) { - String jsString = "javascript:onQRBack(" + msg + ")"; - L.e("JS二维码扫描返回>>>>", jsString); + QRBean mQRBean = new QRBean(); + mQRBean.setMsg(msg); + String ms = new Gson().toJson(mQRBean); + String jsString = "javascript:window.onQRBack(" + ms + ")"; + L.e("JS二维码扫描返回>>>>", ms + "<<>>" + jsString); mWebView.evaluateJavascript(jsString, new ValueCallback() { @Override public void onReceiveValue(String s) { } }); } + + /** + * web返回 + */ + @Receive(Events.JS_OPEN_WEB_BACK) + public void webBack() { + if (mWebView.canGoBack()) { + mWebView.goBack(); + } else { + Apollo.emit(Events.JS_OPEN_WEB_BACK_EXIT); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/wanhui/ui/PersonalFragment.kt b/app/src/main/java/com/cmx/wanhui/ui/PersonalFragment.kt index 22e1977..e2d4e84 100644 --- a/app/src/main/java/com/cmx/wanhui/ui/PersonalFragment.kt +++ b/app/src/main/java/com/cmx/wanhui/ui/PersonalFragment.kt @@ -1,20 +1,22 @@ package com.cmx.wanhui.ui import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.webkit.ValueCallback import com.cmx.wanhui.R import com.cmx.wanhui.constant.Events -import com.cmx.wanhui.utils.L +import com.cmx.wanhui.model.QRBean +import com.cmx.wanhui.utils.L.Companion.e +import com.google.gson.Gson import com.lsxiao.apollo.core.Apollo import com.lsxiao.apollo.core.annotations.Receive -import kotlinx.android.synthetic.main.fragment_home.tv_te import kotlinx.android.synthetic.main.fragment_notifications.wv_mine class PersonalFragment : BaseFragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_notifications, container, false) } @@ -22,7 +24,7 @@ class PersonalFragment : BaseFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setWebView(wv_mine!!) - wv_mine!!.loadUrl("https://www.baidu.com/")//SERVER_URL + wv_mine!!.loadUrl(Events.WEB_MY_URL) //wv_mine!!.webChromeClient = PQChromeClient() } @@ -32,8 +34,23 @@ class PersonalFragment : BaseFragment() { */ @Receive(Events.JS_OPEN_SCANQR_BACK) fun onQRBack(msg: String) { - val jsString = "javascript:onQRBack($msg)" - L.e("JS二维码扫描返回>>>>", jsString) - wv_mine!!.evaluateJavascript(jsString) { } + val mQRBean = QRBean() + mQRBean.msg = msg + val ms = Gson().toJson(mQRBean) + val jsString = "javascript:window.onQRBack($ms)" + e("JS二维码扫描返回>>>>", "$ms<<>>$jsString") + wv_mine!!.evaluateJavascript(jsString, ValueCallback { }) + } + + /** + * web返回 + */ + @Receive(Events.JS_OPEN_WEB_BACK) + fun webBack() { + if (wv_mine!!.canGoBack()) { + wv_mine!!.goBack() + } else { + Apollo.emit(Events.JS_OPEN_WEB_BACK_EXIT) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/wanhui/view/ConfirmDialog.java b/app/src/main/java/com/cmx/wanhui/view/ConfirmDialog.java new file mode 100644 index 0000000..1645c0d --- /dev/null +++ b/app/src/main/java/com/cmx/wanhui/view/ConfirmDialog.java @@ -0,0 +1,59 @@ +package com.cmx.wanhui.view; + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import com.cmx.wanhui.R; + + +/** + * 确认弹窗 + */ +public class ConfirmDialog extends Dialog { + + private TextView mConfirm; + private TextView mCancel; + private IBack mIBack; + + + public ConfirmDialog(Context context, IBack mIBack) { + super(context, R.style.CustomDialog); + this.mIBack = mIBack; + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.dialog_confirm_all); + setCancelable(false); + setCanceledOnTouchOutside(false); + mConfirm = findViewById(R.id.con_con); + mCancel = findViewById(R.id.con_cancel); + mConfirm.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mIBack.confirmBack(); + dismiss(); + + } + }); + mCancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mIBack.cancelBack(); + dismiss(); + } + }); + } + + public interface IBack { + void confirmBack(); + + void cancelBack(); + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml deleted file mode 100644 index 46fc8de..0000000 --- a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml deleted file mode 100644 index f8bb0b5..0000000 --- a/app/src/main/res/drawable/ic_home_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml deleted file mode 100644 index 78b75c3..0000000 --- a/app/src/main/res/drawable/ic_notifications_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/sel_home.xml b/app/src/main/res/drawable/sel_home.xml new file mode 100644 index 0000000..2a37728 --- /dev/null +++ b/app/src/main/res/drawable/sel_home.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/sel_mode.xml b/app/src/main/res/drawable/sel_mode.xml new file mode 100644 index 0000000..1653fc8 --- /dev/null +++ b/app/src/main/res/drawable/sel_mode.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/sel_my.xml b/app/src/main/res/drawable/sel_my.xml new file mode 100644 index 0000000..7f15f97 --- /dev/null +++ b/app/src/main/res/drawable/sel_my.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/sel_tab_col.xml b/app/src/main/res/drawable/sel_tab_col.xml new file mode 100644 index 0000000..e47f7a7 --- /dev/null +++ b/app/src/main/res/drawable/sel_tab_col.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_eh_line.xml b/app/src/main/res/drawable/shape_eh_line.xml new file mode 100644 index 0000000..a49ae9f --- /dev/null +++ b/app/src/main/res/drawable/shape_eh_line.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 6b3b9b9..7f9b9f8 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -33,10 +33,11 @@ android:hint="请输入用户名" android:paddingStart="10dip" android:singleLine="true" - android:text="15102353035" + android:text="wanhui" android:textColorHint="#919191" android:textSize="16sp" /> - + + - + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index ca32b55..443f8ff 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -4,14 +4,6 @@ android:layout_height="match_parent" android:orientation="vertical"> - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/icon_home_off.png b/app/src/main/res/mipmap-hdpi/icon_home_off.png new file mode 100644 index 0000000..178673d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_home_off.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_home_on.png b/app/src/main/res/mipmap-hdpi/icon_home_on.png new file mode 100644 index 0000000..cc624ff Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_home_on.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_mode_off.png b/app/src/main/res/mipmap-hdpi/icon_mode_off.png new file mode 100644 index 0000000..9baaf0c Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_mode_off.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_mode_on.png b/app/src/main/res/mipmap-hdpi/icon_mode_on.png new file mode 100644 index 0000000..321c246 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_mode_on.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_my_off.png b/app/src/main/res/mipmap-hdpi/icon_my_off.png new file mode 100644 index 0000000..428d64e Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_my_off.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_my_on.png b/app/src/main/res/mipmap-hdpi/icon_my_on.png new file mode 100644 index 0000000..08e237b Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_my_on.png differ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8eca043..fdb6579 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,8 +1,8 @@ 万汇 - Home - Loan - Mine + 首页 + 功能 + 我的 Login Email Password