diff --git a/app/src/main/java/com/cmx/hydrology/activity/LoginActivity.kt b/app/src/main/java/com/cmx/hydrology/activity/LoginActivity.kt index 491e689..4b364ef 100644 --- a/app/src/main/java/com/cmx/hydrology/activity/LoginActivity.kt +++ b/app/src/main/java/com/cmx/hydrology/activity/LoginActivity.kt @@ -1,92 +1,110 @@ -package com.cmx.hydrology.activity; +package com.cmx.hydrology.activity -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; +import android.Manifest +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Build +import android.os.Bundle +import android.text.TextUtils +import android.view.View +import androidx.annotation.RequiresApi +import androidx.core.app.ActivityCompat +import com.cmx.hydrology.databinding.ActivityLoginBinding +import com.cmx.hydrology.model.LoginBean +import com.cmx.hydrology.model.LoginRes +import com.cmx.hydrology.retrofit.RetrofitAPIManager +import com.cmx.hydrology.utils.MyUtils +import com.cmx.hydrology.utils.SpUtils +import es.dmoral.toasty.Toasty +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response -import androidx.annotation.RequiresApi; +class LoginActivity : BaseActivity() { + private var binding: ActivityLoginBinding? = null + private val REQUIRED_PERMISSION_LIST = arrayOf( + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION + ) + private val REQUEST_PERMISSION_CODE = 99 + private var allPermission = true -import com.cmx.hydrology.databinding.ActivityLoginBinding; -import com.cmx.hydrology.model.LoginBean; -import com.cmx.hydrology.model.LoginRes; -import com.cmx.hydrology.retrofit.RetrofitAPIManager; -import com.cmx.hydrology.utils.MyUtils; -import com.cmx.hydrology.utils.SpUtils; - -import es.dmoral.toasty.Toasty; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; - -public class LoginActivity extends BaseActivity { - - private ActivityLoginBinding binding; @RequiresApi(api = Build.VERSION_CODES.M) - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - binding = ActivityLoginBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); - MyUtils.setFullscreen(this, true, true); - binding.btnLogin.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(LoginActivity.this, MainActivity.class); - startActivity(intent); - finish(); - // if (TextUtils.isEmpty(binding.edtUsername.getText().toString().trim())) { - // Toasty.info(LoginActivity.this, "请输入用户名").show(); - // return; - // } - // if (TextUtils.isEmpty(binding.edtPassword.getText().toString().trim())) { - // Toasty.info(LoginActivity.this, "请输入密码").show(); - // return; - // } - // toLogin(); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(binding!!.root) + MyUtils.setFullscreen(this, true, true) + checkAllPermission() + binding!!.btnLogin.setOnClickListener(View.OnClickListener { + if (TextUtils.isEmpty(binding!!.edtUsername.text.toString().trim { it <= ' ' })) { + Toasty.info(this@LoginActivity, "请输入用户名").show() + return@OnClickListener } - }); + if (TextUtils.isEmpty(binding!!.edtPassword.text.toString().trim { it <= ' ' })) { + Toasty.info(this@LoginActivity, "请输入密码").show() + return@OnClickListener + } + toLogin() + }) } - /** * 登录 */ - private void toLogin() { - showDialog(); - LoginBean LoginBean = new LoginBean(); - LoginBean.setUsername(binding.edtUsername.getText().toString().trim()); - LoginBean.setPassword(binding.edtPassword.getText().toString().trim()); - Call call = RetrofitAPIManager.provideClientApi().login(LoginBean); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - disDialog(); - if (response.isSuccessful() && response.body().getCode() == 0) { - SpUtils.putString(LoginActivity.this, "token", response.body().getAccess_token()); - SpUtils.putString(LoginActivity.this, "admin", response.body().getIs_admin()); - Intent intent = new Intent(LoginActivity.this, MainActivity.class); - startActivity(intent); - finish(); + private fun toLogin() { + showDialog() + val LoginBean = LoginBean() + LoginBean.username = binding!!.edtUsername.text.toString().trim { it <= ' ' } + LoginBean.password = binding!!.edtPassword.text.toString().trim { it <= ' ' } + val call = RetrofitAPIManager.provideClientApi().login(LoginBean) + call.enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + disDialog() + if (response.isSuccessful && response.body()!!.code == 0) { + SpUtils.putString(this@LoginActivity, "token", response.body()!!.access_token) + val intent = Intent(this@LoginActivity, MainActivity::class.java) + startActivity(intent) + finish() } else { - Toasty.error(LoginActivity.this, response.body().getMessage()).show(); + Toasty.error(this@LoginActivity, response.body()!!.message).show() } } - @Override - public void onFailure(Call call, Throwable t) { - disDialog(); - Toasty.info(LoginActivity.this, "登录失败").show(); + override fun onFailure(call: Call, t: Throwable) { + disDialog() + Toasty.info(this@LoginActivity, "登录失败").show() } - }); + }) } - @Override - public void onDestroy() { - super.onDestroy(); - binding = null; + public override fun onDestroy() { + super.onDestroy() + binding = null + } + + /** + * 权限检查 + */ + private fun checkAllPermission() { + ActivityCompat.requestPermissions(this, REQUIRED_PERMISSION_LIST, REQUEST_PERMISSION_CODE) + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + if (requestCode == REQUEST_PERMISSION_CODE) { + for (i in grantResults.indices.reversed()) { + if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { + allPermission = false + } + } + if (!allPermission) { + Toasty.info(this, "权限已拒绝,请手动开启!").show() + finish() + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/activity/MainActivity.java b/app/src/main/java/com/cmx/hydrology/activity/MainActivity.java deleted file mode 100644 index b0e1190..0000000 --- a/app/src/main/java/com/cmx/hydrology/activity/MainActivity.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.cmx.hydrology.activity; - -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import androidx.annotation.RequiresApi; -import androidx.navigation.NavController; -import androidx.navigation.Navigation; -import androidx.navigation.ui.NavigationUI; - -import com.cmx.hydrology.R; -import com.cmx.hydrology.constant.Events; -import com.cmx.hydrology.databinding.ActivityMainBinding; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.lsxiao.apollo.core.Apollo; -import com.lsxiao.apollo.core.annotations.Receive; - -public class MainActivity extends BaseActivity { - - private ActivityMainBinding binding; - private BottomNavigationView navView; - private NavController navController; - - - @RequiresApi(api = Build.VERSION_CODES.M) - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - binding = ActivityMainBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); - navView = findViewById(R.id.nav_view); - navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main); - NavigationUI.setupWithNavController(binding.navView, navController); - } - - - /** - * 显示tabbar - */ - @Receive(Events.JS_OPEN_TABBAR_SHOW) - public void showTab() { - binding.navView.setVisibility(View.VISIBLE); - } - - /** - * 隐藏tabbar - */ - @Receive(Events.JS_OPEN_TABBAR_HIDE) - public void hideTab() { - binding.navView.setVisibility(View.GONE); - } - - - /** - * 打开新的web - */ - @Receive(Events.JS_OPEN_OPEN_WEB) - public void openWeb(String url) { - Intent intent = new Intent(this, WebActivity.class); - intent.putExtra("url", url); - startActivity(intent); - } - - - /** - * 选择tab - */ - @Receive(Events.JS_OPEN_TAB) - public void ckTab(String mode) { - Apollo.emit(Events.JS_OPEN_CLOSE_WEB); - switch (mode) { - case "1": - Menu menu = navView.getMenu(); - MenuItem menuItem = menu.getItem(0); // 将index替换为您想要点击的项目的索引 - menuItem.setChecked(true); - navController.navigate(R.id.navigation_home); - break; - case "2": - Menu menu2 = navView.getMenu(); - MenuItem menuItem2 = menu2.getItem(1); // 将index替换为您想要点击的项目的索引 - menuItem2.setChecked(true); - navController.navigate(R.id.navigation_msg); - break; - case "3": - Menu menu3 = navView.getMenu(); - MenuItem menuItem3 = menu3.getItem(2); // 将index替换为您想要点击的项目的索引 - menuItem3.setChecked(true); - navController.navigate(R.id.navigation_map); - break; - case "4": - Menu menu4 = navView.getMenu(); - MenuItem menuItem4 = menu4.getItem(3); // 将index替换为您想要点击的项目的索引 - menuItem4.setChecked(true); - navController.navigate(R.id.navigation_my); - break; - } - } - - - /** - * 退出登录 - */ - @Receive(Events.JS_OPEN_LOGOUT) - public void exit() { - Apollo.emit(Events.JS_OPEN_CLOSE_WEB); - finish(); - Intent intent = new Intent(this, LoginActivity.class); - startActivity(intent); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/activity/MainActivity.kt b/app/src/main/java/com/cmx/hydrology/activity/MainActivity.kt new file mode 100644 index 0000000..1dac205 --- /dev/null +++ b/app/src/main/java/com/cmx/hydrology/activity/MainActivity.kt @@ -0,0 +1,105 @@ +package com.cmx.hydrology.activity + +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.view.View +import androidx.annotation.RequiresApi +import androidx.navigation.NavController +import androidx.navigation.Navigation +import androidx.navigation.ui.NavigationUI +import com.cmx.hydrology.R +import com.cmx.hydrology.constant.Events +import com.cmx.hydrology.databinding.ActivityMainBinding +import com.google.android.material.bottomnavigation.BottomNavigationView +import com.lsxiao.apollo.core.Apollo +import com.lsxiao.apollo.core.annotations.Receive +import kotlinx.android.synthetic.main.activity_main.nav_view + +class MainActivity : BaseActivity() { + + private var navController: NavController? = null + + @RequiresApi(api = Build.VERSION_CODES.M) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + 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 + */ + @Receive(Events.JS_OPEN_TABBAR_SHOW) + fun showTab() { + nav_view.visibility = View.VISIBLE + } + + /** + * 隐藏tabbar + */ + @Receive(Events.JS_OPEN_TABBAR_HIDE) + fun hideTab() { + nav_view.visibility = View.GONE + } + + /** + * 打开新的web + */ + @Receive(Events.JS_OPEN_OPEN_WEB) + fun openWeb(url: String?) { + val intent = Intent(this, WebActivity::class.java) + intent.putExtra("url", url) + startActivity(intent) + } + + /** + * 选择tab + */ + @Receive(Events.JS_OPEN_TAB) + fun ckTab(mode: String?) { + Apollo.emit(Events.JS_OPEN_CLOSE_WEB) + when (mode) { + "1" -> { + val menu = nav_view!!.menu + val menuItem = menu.getItem(0) // 将index替换为您想要点击的项目的索引 + menuItem.isChecked = true + navController!!.navigate(R.id.navigation_home) + } + + "2" -> { + val menu2 = nav_view!!.menu + val menuItem2 = menu2.getItem(1) // 将index替换为您想要点击的项目的索引 + menuItem2.isChecked = true + navController!!.navigate(R.id.navigation_msg) + } + + "3" -> { + val menu3 = nav_view!!.menu + val menuItem3 = menu3.getItem(2) // 将index替换为您想要点击的项目的索引 + menuItem3.isChecked = true + navController!!.navigate(R.id.navigation_map) + } + + "4" -> { + val menu4 = nav_view!!.menu + val menuItem4 = menu4.getItem(3) // 将index替换为您想要点击的项目的索引 + menuItem4.isChecked = true + navController!!.navigate(R.id.navigation_my) + } + } + } + + /** + * 退出登录 + */ + @Receive(Events.JS_OPEN_LOGOUT) + fun exit() { + Apollo.emit(Events.JS_OPEN_CLOSE_WEB) + finish() + val intent = Intent(this, LoginActivity::class.java) + startActivity(intent) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/constant/Events.kt b/app/src/main/java/com/cmx/hydrology/constant/Events.kt index c14c8f5..568046c 100644 --- a/app/src/main/java/com/cmx/hydrology/constant/Events.kt +++ b/app/src/main/java/com/cmx/hydrology/constant/Events.kt @@ -6,8 +6,13 @@ package com.cmx.hydrology.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 WEB_SERVER_URL = "https://cmx.bskies.cc:8000" + const val SERVER_URL = "http://106.54.217.74:6622" + const val WEB_HOME_URL = "$WEB_SERVER_URL/cmx-hydrology-h5/#/home" + const val WEB_MSG_URL = WEB_SERVER_URL + "" + const val WEB_MAP_URL = "$WEB_SERVER_URL/cmx-hydrology-h5/#/map" + const val WEB_MY_URL = WEB_SERVER_URL + "" + /** * tabbar显示 diff --git a/app/src/main/java/com/cmx/hydrology/model/LoginRes.java b/app/src/main/java/com/cmx/hydrology/model/LoginRes.java index b83f261..5aeef36 100644 --- a/app/src/main/java/com/cmx/hydrology/model/LoginRes.java +++ b/app/src/main/java/com/cmx/hydrology/model/LoginRes.java @@ -8,14 +8,12 @@ public class LoginRes { * code : 0 * message : 登录成功 * access_token : 1914936f8c87fddd11836ebebb65317bb7f57506 - * is_admin : 1 */ private int code; private String message; private String access_token; - private String is_admin; public int getCode() { return code; @@ -41,11 +39,4 @@ public class LoginRes { this.access_token = access_token; } - public String getIs_admin() { - return is_admin; - } - - public void setIs_admin(String is_admin) { - this.is_admin = is_admin; - } } diff --git a/app/src/main/java/com/cmx/hydrology/ui/BaseFragment.kt b/app/src/main/java/com/cmx/hydrology/ui/BaseFragment.kt new file mode 100644 index 0000000..9145204 --- /dev/null +++ b/app/src/main/java/com/cmx/hydrology/ui/BaseFragment.kt @@ -0,0 +1,92 @@ +package com.cmx.hydrology.ui + +import android.graphics.Bitmap +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.webkit.WebResourceError +import android.webkit.WebResourceRequest +import android.webkit.WebSettings +import android.webkit.WebView +import android.webkit.WebViewClient +import androidx.fragment.app.Fragment +import com.cmx.hydrology.utils.AndroidtoJs +import com.cmx.hydrology.utils.MyUtils +import com.cmx.hydrology.view.BaseLoadingDialog +import com.lsxiao.apollo.core.Apollo +import com.lsxiao.apollo.core.contract.ApolloBinder + + +open class BaseFragment : Fragment() { + + var mBaseLoadingDialog: BaseLoadingDialog? = null + var mApolloBinder: ApolloBinder? = null + + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(null, container, false) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mBaseLoadingDialog = BaseLoadingDialog(activity) + MyUtils.setFullscreen(requireActivity(), false, false) + MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true) + mApolloBinder = Apollo.bind(this) + } + + /** + * 相关属性设置 + */ + fun setWebView(webView: WebView) { + val webSettings = webView!!.settings + webSettings.javaScriptEnabled = true + webSettings.cacheMode = WebSettings.LOAD_NO_CACHE + webSettings.domStorageEnabled = true + webSettings.allowFileAccess = true //文件访问 + webSettings.allowFileAccessFromFileURLs = true + webView!!.addJavascriptInterface(AndroidtoJs(), "AndroidtoJs") + webView!!.webViewClient = object : WebViewClient() { + override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { + super.onPageStarted(view, url, favicon) + showDialog() + } + + override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { + view.loadUrl(url) + return true + } + + override fun onPageFinished(view: WebView, url: String) { + disDialog() + } + + override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) { + disDialog() + } + } + } + + + override fun onDestroyView() { + super.onDestroyView() + if (mApolloBinder != null) { + mApolloBinder!!.unbind() + } + } + + fun showDialog() { + mBaseLoadingDialog = BaseLoadingDialog(activity) + if (!mBaseLoadingDialog!!.isShowing) { + mBaseLoadingDialog!!.show() + } + } + + fun disDialog() { + if (mBaseLoadingDialog!!.isShowing) { + mBaseLoadingDialog!!.dismiss() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/ui/HomeFragment.java b/app/src/main/java/com/cmx/hydrology/ui/HomeFragment.java index e4a1332..72098fb 100644 --- a/app/src/main/java/com/cmx/hydrology/ui/HomeFragment.java +++ b/app/src/main/java/com/cmx/hydrology/ui/HomeFragment.java @@ -1,6 +1,9 @@ package com.cmx.hydrology.ui; +import static com.cmx.hydrology.constant.Events.WEB_HOME_URL; +import static com.cmx.hydrology.constant.Events.WEB_SERVER_URL; + import android.app.Activity; import android.content.ClipData; import android.content.Intent; @@ -35,12 +38,10 @@ import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; -public class HomeFragment extends Fragment { +public class HomeFragment extends BaseFragment { private FragmentHomeBinding binding; - private BaseLoadingDialog mBaseLoadingDialog; private WebView mWebView; - private ApolloBinder mApolloBinder; private ValueCallback mUploadMessage; private String mCameraPhotoPath = null; private long size = 0; @@ -49,66 +50,19 @@ public class HomeFragment extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentHomeBinding.inflate(inflater, container, false); - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); View root = binding.getRoot(); - MyUtils.setFullscreen(requireActivity(), false, false); - MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true); mWebView = binding.wvHome; - mApolloBinder = Apollo.bind(this); - WebSettings webSettings = mWebView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - webSettings.setDomStorageEnabled(true); - webSettings.setAllowFileAccess(true);//文件访问 - webSettings.setAllowFileAccessFromFileURLs(true); - mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs"); - mWebView.loadUrl("https://cmx.bskies.cc:8000/cmx-hydrology-h5/#/home"); - showDialog(); + setWebView(mWebView); + mWebView.loadUrl(WEB_HOME_URL); mWebView.setWebChromeClient(new PQChromeClient()); - mWebView.setWebViewClient(new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - //使用WebView加载显示url - view.loadUrl(url); - //返回true - return true; - } - - @Override - public void onPageFinished(WebView view, String url) { - disDialog(); - } - - @Override - public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { - disDialog(); - } - } - - ); return root; } + @Override public void onDestroyView() { super.onDestroyView(); binding = null; - if (mApolloBinder != null) { - mApolloBinder.unbind(); - } - } - - public void showDialog() { - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); - if (!mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.show(); - } - } - - public void disDialog() { - if (mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.dismiss(); - } } diff --git a/app/src/main/java/com/cmx/hydrology/ui/MapFragment.java b/app/src/main/java/com/cmx/hydrology/ui/MapFragment.java index b1d7858..65fef74 100644 --- a/app/src/main/java/com/cmx/hydrology/ui/MapFragment.java +++ b/app/src/main/java/com/cmx/hydrology/ui/MapFragment.java @@ -1,6 +1,9 @@ package com.cmx.hydrology.ui; +import static com.cmx.hydrology.constant.Events.WEB_MAP_URL; +import static com.cmx.hydrology.constant.Events.WEB_SERVER_URL; + import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -21,49 +24,17 @@ import com.cmx.hydrology.view.BaseLoadingDialog; import com.lsxiao.apollo.core.Apollo; import com.lsxiao.apollo.core.contract.ApolloBinder; -public class MapFragment extends Fragment { +public class MapFragment extends BaseFragment { private FragmentMapBinding binding; - private BaseLoadingDialog mBaseLoadingDialog; private WebView mWebView; - private ApolloBinder mApolloBinder; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentMapBinding.inflate(inflater, container, false); - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); View root = binding.getRoot(); - mApolloBinder = Apollo.bind(this); - MyUtils.setFullscreen(requireActivity(), false, false); - MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true); mWebView = binding.wvMine; - WebSettings webSettings = mWebView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - webSettings.setDomStorageEnabled(true); - mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs"); - // mWebView.loadUrl(SERVER_URL + "/nigeria/?lang=English#/my"); - // showDialog(); - mWebView.setWebViewClient(new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - //使用WebView加载显示url - view.loadUrl(url); - //返回true - return true; - } - - @Override - public void onPageFinished(WebView view, String url) { - disDialog(); - } - - @Override - public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { - disDialog(); - } - } - - ); + setWebView(mWebView); + mWebView.loadUrl(WEB_MAP_URL); return root; } @@ -72,22 +43,6 @@ public class MapFragment extends Fragment { public void onDestroyView() { super.onDestroyView(); binding = null; - if (mApolloBinder != null) { - mApolloBinder.unbind(); - } } - public void showDialog() { - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); - if (!mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.show(); - } - } - - - public void disDialog() { - if (mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.dismiss(); - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/ui/MsgFragment.java b/app/src/main/java/com/cmx/hydrology/ui/MsgFragment.java index f1778cb..dac6dbb 100644 --- a/app/src/main/java/com/cmx/hydrology/ui/MsgFragment.java +++ b/app/src/main/java/com/cmx/hydrology/ui/MsgFragment.java @@ -1,6 +1,8 @@ package com.cmx.hydrology.ui; +import static com.cmx.hydrology.constant.Events.SERVER_URL; + import android.app.Activity; import android.content.ClipData; import android.content.Intent; @@ -35,57 +37,18 @@ import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; -public class MsgFragment extends Fragment { +public class MsgFragment extends BaseFragment { private FragmentMsgBinding binding; - private BaseLoadingDialog mBaseLoadingDialog; private WebView mWebView; - private ApolloBinder mApolloBinder; - private ValueCallback mUploadMessage; - private String mCameraPhotoPath = null; - private long size = 0; - private static final int INPUT_FILE_REQUEST_CODE = 1; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentMsgBinding.inflate(inflater, container, false); - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); View root = binding.getRoot(); - MyUtils.setFullscreen(requireActivity(), false, false); - MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true); mWebView = binding.wvLoan; - mApolloBinder = Apollo.bind(this); - WebSettings webSettings = mWebView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - webSettings.setDomStorageEnabled(true); - webSettings.setAllowFileAccess(true);//文件访问 - webSettings.setAllowFileAccessFromFileURLs(true); - mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs"); + setWebView(mWebView); // mWebView.loadUrl(SERVER_URL + "/nigeria/?lang=English#/loans"); - // showDialog(); - mWebView.setWebChromeClient(new PQChromeClient()); - mWebView.setWebViewClient(new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - //使用WebView加载显示url - view.loadUrl(url); - //返回true - return true; - } - - @Override - public void onPageFinished(WebView view, String url) { - disDialog(); - } - - @Override - public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { - disDialog(); - } - } - - ); return root; } @@ -94,139 +57,7 @@ public class MsgFragment extends Fragment { public void onDestroyView() { super.onDestroyView(); binding = null; - if (mApolloBinder != null) { - mApolloBinder.unbind(); - } } - public void showDialog() { - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); - if (!mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.show(); - } - } - - - public void disDialog() { - if (mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.dismiss(); - } - } - - - public class PQChromeClient extends WebChromeClient { - // For Android 5.0+ - public boolean onShowFileChooser(WebView view, ValueCallback filePath, WebChromeClient.FileChooserParams fileChooserParams) { - // Double check that we don't have any existing callbacks - if (mUploadMessage != null) { - mUploadMessage.onReceiveValue(null); - } - mUploadMessage = filePath; - Log.e("FileCooserParams => ", filePath.toString()); - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { - // Create the File where the photo should go - File photoFile = null; - try { - photoFile = createImageFile(); - takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); - } catch (IOException ex) { - // Error occurred while creating the File - Log.e("test", "Unable to create Image File", ex); - } - - // Continue only if the File was successfully created - if (photoFile != null) { - mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); - } else { - takePictureIntent = null; - } - } - - Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); - contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); - contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - contentSelectionIntent.setType("image/*"); - - Intent[] intentArray; - if (takePictureIntent != null) { - intentArray = new Intent[]{takePictureIntent}; - } else { - intentArray = new Intent[2]; - } - Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); - chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); - chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); - startActivityForResult(Intent.createChooser(chooserIntent, "Select images"), 1); - - return true; - } - } - - - private File createImageFile() throws IOException { - // Create an image file name - String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); - String imageFileName = "JPEG_" + timeStamp + "_"; - File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); - File imageFile = File.createTempFile(imageFileName, /* prefix */ - ".jpg", /* suffix */ - storageDir /* directory */); - return imageFile; - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode != INPUT_FILE_REQUEST_CODE || mUploadMessage == null) { - super.onActivityResult(requestCode, resultCode, data); - return; - } - try { - String file_path = mCameraPhotoPath.replace("file:", ""); - File file = new File(file_path); - size = file.length(); - - } catch (Exception e) { - Log.e("Error!", "Error while opening image file" + e.getLocalizedMessage()); - } - - if (data != null || mCameraPhotoPath != null) { - Integer count = 1; - ClipData images = null; - try { - images = data.getClipData(); - } catch (Exception e) { - Log.e("Error!", e.getLocalizedMessage()); - } - - if (images == null && data != null && data.getDataString() != null) { - count = data.getDataString().length(); - } else if (images != null) { - count = images.getItemCount(); - } - Uri[] results = new Uri[count]; - // Check that the response is a good one - if (resultCode == Activity.RESULT_OK) { - if (size != 0) { - // If there is not data, then we may have taken a photo - if (mCameraPhotoPath != null) { - results = new Uri[]{Uri.parse(mCameraPhotoPath)}; - } - } else if (data.getClipData() == null) { - results = new Uri[]{Uri.parse(data.getDataString())}; - } else { - - for (int i = 0; i < images.getItemCount(); i++) { - results[i] = images.getItemAt(i).getUri(); - } - } - } - mUploadMessage.onReceiveValue(results); - mUploadMessage = null; - } - } - } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/ui/MyFragment.java b/app/src/main/java/com/cmx/hydrology/ui/MyFragment.java index 47d1890..ec480f6 100644 --- a/app/src/main/java/com/cmx/hydrology/ui/MyFragment.java +++ b/app/src/main/java/com/cmx/hydrology/ui/MyFragment.java @@ -21,49 +21,17 @@ import com.cmx.hydrology.view.BaseLoadingDialog; import com.lsxiao.apollo.core.Apollo; import com.lsxiao.apollo.core.contract.ApolloBinder; -public class MyFragment extends Fragment { +public class MyFragment extends BaseFragment { private FragmentMyBinding binding; - private BaseLoadingDialog mBaseLoadingDialog; private WebView mWebView; - private ApolloBinder mApolloBinder; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentMyBinding.inflate(inflater, container, false); - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); View root = binding.getRoot(); - mApolloBinder = Apollo.bind(this); - MyUtils.setFullscreen(requireActivity(), false, false); - MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true); mWebView = binding.wvMine; - WebSettings webSettings = mWebView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - webSettings.setDomStorageEnabled(true); - mWebView.addJavascriptInterface(new AndroidtoJs(), "AndroidtoJs"); + setWebView(mWebView); // mWebView.loadUrl(SERVER_URL + "/nigeria/?lang=English#/my"); - // showDialog(); - mWebView.setWebViewClient(new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - //使用WebView加载显示url - view.loadUrl(url); - //返回true - return true; - } - - @Override - public void onPageFinished(WebView view, String url) { - disDialog(); - } - - @Override - public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { - disDialog(); - } - } - - ); return root; } @@ -72,22 +40,6 @@ public class MyFragment extends Fragment { public void onDestroyView() { super.onDestroyView(); binding = null; - if (mApolloBinder != null) { - mApolloBinder.unbind(); - } } - public void showDialog() { - mBaseLoadingDialog = new BaseLoadingDialog(getActivity()); - if (!mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.show(); - } - } - - - public void disDialog() { - if (mBaseLoadingDialog.isShowing()) { - mBaseLoadingDialog.dismiss(); - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/cmx/hydrology/utils/AndroidtoJs.java b/app/src/main/java/com/cmx/hydrology/utils/AndroidtoJs.java index 1b824d6..cd2bb5e 100644 --- a/app/src/main/java/com/cmx/hydrology/utils/AndroidtoJs.java +++ b/app/src/main/java/com/cmx/hydrology/utils/AndroidtoJs.java @@ -20,17 +20,6 @@ public class AndroidtoJs { return SpUtils.getString(MyApplication.getmInstance(), "token"); } - /** - * 用户角色类型 - * - * @return - */ - @JavascriptInterface - public String getUser() { - L.e("JS--", "getUser()"); - return SpUtils.getString(MyApplication.getmInstance(), "admin"); - } - @JavascriptInterface public String getAppVersion() { 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_map.xml b/app/src/main/res/drawable/sel_map.xml new file mode 100644 index 0000000..3906f15 --- /dev/null +++ b/app/src/main/res/drawable/sel_map.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/sel_msg.xml b/app/src/main/res/drawable/sel_msg.xml new file mode 100644 index 0000000..723cedb --- /dev/null +++ b/app/src/main/res/drawable/sel_msg.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..93fc5f4 --- /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/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 0ad315b..604087a 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -59,6 +59,7 @@ android:hint="请输入用户名" android:paddingStart="10dip" android:singleLine="true" + android:text="superuser" android:textColorHint="#919191" android:textSize="16sp" /> @@ -76,6 +77,7 @@ android:inputType="textPassword" android:paddingStart="10dip" android:singleLine="true" + android:text="Cmx170904" android:textColorHint="#919191" android:textSize="16sp" /> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3b8a463..a24d126 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="32dp"> - + \ 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..1f506dc 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..7028b52 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_logo.png b/app/src/main/res/mipmap-hdpi/icon_logo.png index fc65e44..fa4439f 100644 Binary files a/app/src/main/res/mipmap-hdpi/icon_logo.png and b/app/src/main/res/mipmap-hdpi/icon_logo.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_map_off.png b/app/src/main/res/mipmap-hdpi/icon_map_off.png new file mode 100644 index 0000000..dd13f50 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_map_off.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_map_on.png b/app/src/main/res/mipmap-hdpi/icon_map_on.png new file mode 100644 index 0000000..66f2a09 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_map_on.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_msg_off.png b/app/src/main/res/mipmap-hdpi/icon_msg_off.png new file mode 100644 index 0000000..122f144 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_msg_off.png differ diff --git a/app/src/main/res/mipmap-hdpi/icon_msg_on.png b/app/src/main/res/mipmap-hdpi/icon_msg_on.png new file mode 100644 index 0000000..53489de Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_msg_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..1dc7c50 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..4328cbc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/icon_my_on.png differ