diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 62df7c4..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/bird2fish/travelbook/MainActivity.kt b/app/src/main/java/com/bird2fish/travelbook/MainActivity.kt index 9906ae4..6fabc93 100644 --- a/app/src/main/java/com/bird2fish/travelbook/MainActivity.kt +++ b/app/src/main/java/com/bird2fish/travelbook/MainActivity.kt @@ -1,20 +1,14 @@ package com.bird2fish.travelbook -import android.Manifest import android.content.ComponentName -import android.content.Context import android.content.Intent import android.content.ServiceConnection -import android.content.pm.PackageManager import android.os.Bundle import android.os.IBinder import android.view.Menu -import android.view.MenuItem import android.view.View -import android.view.Window import android.widget.ImageView import android.widget.TextView -import androidx.activity.result.contract.ActivityResultContracts import com.google.android.material.navigation.NavigationView import androidx.navigation.findNavController import androidx.navigation.ui.AppBarConfiguration @@ -23,16 +17,11 @@ import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupWithNavController import androidx.drawerlayout.widget.DrawerLayout import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContextCompat import androidx.core.view.GravityCompat -import androidx.core.view.get -import androidx.fragment.app.FragmentActivity -import com.bird2fish.travelbook.R import com.bird2fish.travelbook.core.HttpService import com.bird2fish.travelbook.core.UiHelper import com.bird2fish.travelbook.databinding.ActivityMainBinding import com.bird2fish.travelbook.helper.LogHelper -import com.bird2fish.travelbook.helper.PreferencesHelper import com.bird2fish.travelbook.ui.data.model.CurrentUser class MainActivity : AppCompatActivity() { @@ -50,6 +39,7 @@ class MainActivity : AppCompatActivity() { } public fun openDrawer(){ + binding.drawerLayout.openDrawer(GravityCompat.START); } @@ -94,7 +84,7 @@ class MainActivity : AppCompatActivity() { //R.id.nav_newgroup, R.id.nav_home, R.id.nav_playground, R.id.nav_favourite, R.id.nav_map, R.id.nav_track, - R.id.nav_contract, R.id.nav_setting + R.id.nav_me, R.id.nav_contract, R.id.settingFragment ), drawerLayout ) setupActionBarWithNavController(navController, appBarConfiguration) @@ -118,6 +108,31 @@ class MainActivity : AppCompatActivity() { // window.statusBarColor = resources.getColor(R.color.toolbar_gray) // } + + drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener { + override fun onDrawerSlide(drawerView: View, slideOffset: Float) { + // 当侧边栏滑动时调用 + } + + override fun onDrawerOpened(drawerView: View) { + // 当侧边栏打开时调用 + // 这里可以处理在侧边栏打开时需要执行的逻辑 + val user = CurrentUser.getUser() + if (user != null){ + setUserInfo() + } + } + + override fun onDrawerClosed(drawerView: View) { + // 当侧边栏关闭时调用 + // 这里可以处理在侧边栏关闭时需要执行的逻辑 + } + + override fun onDrawerStateChanged(newState: Int) { + // 当侧边栏状态发生变化时调用 + } + }) + } private fun setUserInfo(){ @@ -126,7 +141,7 @@ class MainActivity : AppCompatActivity() { var navigationView = this.findViewById(R.id.nav_view); // 侧边栏的头部栏的信息设置 var headerLayout = navigationView.getHeaderView(0); - var userNameview = headerLayout.findViewById(R.id.textNick); + var userNameview = headerLayout.findViewById(R.id.tvName); var userInfoview = headerLayout.findViewById(R.id.textInfo); var userIcon = headerLayout.findViewById(R.id.imageViewIcon) diff --git a/app/src/main/java/com/bird2fish/travelbook/ServerSettingView.kt b/app/src/main/java/com/bird2fish/travelbook/ServerSettingView.kt new file mode 100644 index 0000000..d8b8497 --- /dev/null +++ b/app/src/main/java/com/bird2fish/travelbook/ServerSettingView.kt @@ -0,0 +1,95 @@ +package com.bird2fish.travelbook + +import android.content.Context +import android.content.res.Resources +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.view.Gravity +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.Button +import android.widget.PopupWindow +import android.widget.ScrollView +import android.widget.TextView +import com.bird2fish.travelbook.helper.PreferencesHelper + +class ServerSettingView(context: Context) { + + private var popupWindow: PopupWindow + + init { + // 填充布局 R.layout.pop_location + val popupView = LayoutInflater.from(context).inflate(R.layout.setting_server, null) + + // 创建 PopupWindow 实例 + popupWindow = PopupWindow( + popupView, + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT, + true + ) + + // 设置 PopupWindow 的背景 + popupWindow.setBackgroundDrawable(ColorDrawable(Color.WHITE)) + + // 设置 PopupWindow 的位置(在底部) + popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 0) + + // 设置 PopupWindow 进入和退出的动画效果(可选) + popupWindow.animationStyle = R.style.PopupWindowAnimation + + // 设置点击外部不关闭PopupWindow + popupWindow.isOutsideTouchable = false + // 设置背景为null,防止点击外部传递到下面的View + popupWindow.setBackgroundDrawable(null) + + // 添加监听器,处理关闭事件 + popupWindow.setOnDismissListener { + // 在这里添加处理 PopupWindow 关闭时的逻辑 + } + + // 如果需要处理点击事件等,可以在这里找到对应的 View 并设置相应的监听器 + val schemaEdit = popupView.findViewById(R.id.tv_shema) + val schema = PreferencesHelper.getHostSchema() + schemaEdit.setText(schema) + + + val hostEdit = popupView.findViewById(R.id.tv_ip) + val host = PreferencesHelper.getHostName() + hostEdit.setText(host) + + val saveBtn = popupView.findViewById