Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share white
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
location share white
Commits
f6cb9add
Commit
f6cb9add
authored
Oct 31, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
de944271
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
173 additions
and
32 deletions
+173
-32
ViewerBean.kt
.../main/java/com/base/locationsharewhite/bean/ViewerBean.kt
+3
-1
BaseActivity.kt
...n/java/com/base/locationsharewhite/helper/BaseActivity.kt
+1
-1
LocationLoginUtils.kt
...om/base/locationsharewhite/location/LocationLoginUtils.kt
+4
-4
LocationShareActivity.kt
.../base/locationsharewhite/ui/main/LocationShareActivity.kt
+44
-0
ViewerAdapter.kt
...java/com/base/locationsharewhite/ui/main/ViewerAdapter.kt
+2
-2
RenameActivity.kt
...java/com/base/locationsharewhite/ui/set/RenameActivity.kt
+80
-22
SettingActivity.kt
...ava/com/base/locationsharewhite/ui/set/SettingActivity.kt
+1
-1
DialogView.kt
...n/java/com/base/locationsharewhite/ui/views/DialogView.kt
+2
-1
SpStringUtils.kt
...n/java/com/base/locationsharewhite/utils/SpStringUtils.kt
+34
-0
activity_rename.xml
app/src/main/res/layout/activity_rename.xml
+1
-0
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/com/base/locationsharewhite/bean/ViewerBean.kt
View file @
f6cb9add
...
...
@@ -8,4 +8,6 @@ data class ViewerBean(
val
nickName
:
String
,
var
status
:
Int
,
//0不可以看 1可以看
val
device
:
String
,
)
)
{
var
localNickName
:
String
?
=
null
}
app/src/main/java/com/base/locationsharewhite/helper/BaseActivity.kt
View file @
f6cb9add
...
...
@@ -19,7 +19,7 @@ abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
lateinit
var
launcher
:
ActivityLauncher
var
isRunning
:
Boolean
=
false
//需要用时在onResume()最后一行
复制
var
isRunning
:
Boolean
=
false
//需要用时在onResume()最后一行
赋值
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
app/src/main/java/com/base/locationsharewhite/location/LocationLoginUtils.kt
View file @
f6cb9add
...
...
@@ -20,13 +20,13 @@ object LocationLoginUtils {
field
=
value
AppPreferences
.
getInstance
().
put
(
"invitationCodeSp"
,
value
,
true
)
}
var
n
ickNameSp
=
""
var
myN
ickNameSp
=
""
get
()
{
return
AppPreferences
.
getInstance
().
getString
(
"
n
ickNameSp"
,
field
)
return
AppPreferences
.
getInstance
().
getString
(
"
myN
ickNameSp"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"
n
ickNameSp"
,
value
,
true
)
AppPreferences
.
getInstance
().
put
(
"
myN
ickNameSp"
,
value
,
true
)
}
private
val
TAG
=
"LocationLoginUtils"
...
...
@@ -86,7 +86,7 @@ object LocationLoginUtils {
invitationCodeSp
=
invitationCode
val
nickName
=
data
.
getString
(
"nickName"
)
n
ickNameSp
=
nickName
myN
ickNameSp
=
nickName
LogEx
.
logDebug
(
TAG
,
"invitationCode=$invitationCode nickName=$nickName"
)
}
...
...
app/src/main/java/com/base/locationsharewhite/ui/main/LocationShareActivity.kt
View file @
f6cb9add
package
com.base.locationsharewhite.ui.main
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.graphics.Color
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.lifecycleScope
import
com.base.locationsharewhite.R
import
com.base.locationsharewhite.bean.ViewerBean
import
com.base.locationsharewhite.databinding.ActivityLocationShareBinding
import
com.base.locationsharewhite.helper.BaseActivity
import
com.base.locationsharewhite.location.LocationShareListUtils
...
...
@@ -14,10 +17,16 @@ import com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_MYSEL
import
com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_SHARED
import
com.base.locationsharewhite.location.LocationShareUtils.SHARE_STATE_SUCCESS
import
com.base.locationsharewhite.location.LocationStatusUtils
import
com.base.locationsharewhite.ui.set.RenameActivity
import
com.base.locationsharewhite.ui.views.DialogView.showViewerMoreDialog
import
com.base.locationsharewhite.utils.BarUtils
import
com.base.locationsharewhite.utils.LogEx
import
com.base.locationsharewhite.utils.SpStringUtils
import
com.base.locationsharewhite.utils.SpStringUtils.VIEWER_NICKNAME_KEY
import
com.base.locationsharewhite.utils.SpStringUtils._DEVICE_NICKNAME_
import
com.base.locationsharewhite.utils.ToastUtils.toast
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
/**
* 添加谁可以看我
...
...
@@ -66,6 +75,12 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
toast
(
it
.
toString
())
}
}
},
renameAction
=
{
startActivity
(
Intent
(
this
,
RenameActivity
::
class
.
java
).
apply
{
putExtra
(
"doWhat"
,
RenameActivity
.
RENAME_FRIEND_NICK_NAME
)
putExtra
(
"device"
,
viewerBean
.
device
)
putExtra
(
"nickName"
,
viewerBean
.
localNickName
?:
viewerBean
.
nickName
)
})
})
}
binding
.
rv
.
adapter
=
adapter
...
...
@@ -121,11 +136,40 @@ class LocationShareActivity : BaseActivity<ActivityLocationShareBinding>() {
private
fun
initShareData
()
{
LocationShareListUtils
.
getShareList
(
viewerListCallBack
=
{
val
nickList
=
SpStringUtils
.
getSpStringList
(
VIEWER_NICKNAME_KEY
)
it
.
forEach
{
viewer
->
changeLocalNickName
(
viewer
,
nickList
)
}
runOnUiThread
{
adapter
.
submitList
(
it
)
}
})
}
override
fun
onResume
()
{
super
.
onResume
()
refreshNickName
()
}
@SuppressLint
(
"NotifyDataSetChanged"
)
private
fun
refreshNickName
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
nickList
=
SpStringUtils
.
getSpStringList
(
VIEWER_NICKNAME_KEY
)
adapter
.
items
.
map
{
viewer
->
changeLocalNickName
(
viewer
,
nickList
)
}
launch
(
Dispatchers
.
Main
)
{
adapter
.
notifyDataSetChanged
()
}
}
private
fun
changeLocalNickName
(
viewer
:
ViewerBean
,
nickList
:
List
<
String
>)
{
val
deviceNicknameSp
=
nickList
.
find
{
it
.
contains
(
viewer
.
device
)
}
deviceNicknameSp
?.
let
{
sp
->
runCatching
{
val
localNickName
=
sp
.
split
(
_DEVICE_NICKNAME_
)[
1
]
viewer
.
localNickName
=
localNickName
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ui/main/ViewerAdapter.kt
View file @
f6cb9add
...
...
@@ -3,7 +3,6 @@ package com.base.locationsharewhite.ui.main
import
android.content.Context
import
android.view.View
import
android.view.ViewGroup
import
android.widget.CompoundButton
import
androidx.recyclerview.widget.RecyclerView.ViewHolder
import
com.base.locationsharewhite.R
import
com.base.locationsharewhite.bean.ViewerBean
...
...
@@ -23,7 +22,8 @@ class ViewerAdapter(
item
?:
return
val
binding
=
ItemViewerBinding
.
bind
(
holder
.
itemView
)
runCatching
{
binding
.
tvNameLetters
.
text
=
item
.
nickName
.
substring
(
0
,
1
)
}
binding
.
tvNameCode
.
text
=
item
.
nickName
binding
.
tvNameCode
.
text
=
item
.
localNickName
?:
item
.
nickName
binding
.
tvTime
.
text
=
"time"
binding
.
tvSwitch
.
isChecked
=
item
.
status
==
1
binding
.
tvSwitch
.
setOnCheckedChangeListener
{
buttonView
,
isChecked
->
...
...
app/src/main/java/com/base/locationsharewhite/ui/set/RenameActivity.kt
View file @
f6cb9add
package
com.base.locationsharewhite.ui.set
import
android.content.Intent
import
android.graphics.Color
import
android.view.View
import
androidx.core.view.updatePadding
import
com.base.locationsharewhite.BuildConfig
import
com.base.locationsharewhite.R
import
com.base.locationsharewhite.databinding.ActivityRenameBinding
import
com.base.locationsharewhite.helper.BaseActivity
import
com.base.locationsharewhite.helper.MyApplication
import
com.base.locationsharewhite.location.LocationLoginUtils
import
com.base.locationsharewhite.location.LocationNameUtils
import
com.base.locationsharewhite.utils.AppPreferences
import
com.base.locationsharewhite.utils.BarUtils
import
com.base.locationsharewhite.utils.ClipboardUtils.copyText
import
com.base.locationsharewhite.utils.SpStringUtils
import
com.base.locationsharewhite.utils.SpStringUtils.VIEWER_NICKNAME_KEY
import
com.base.locationsharewhite.utils.SpStringUtils._DEVICE_NICKNAME_
import
com.base.locationsharewhite.utils.ToastUtils.toast
class
RenameActivity
:
BaseActivity
<
ActivityRenameBinding
>()
{
...
...
@@ -23,38 +23,96 @@ class RenameActivity : BaseActivity<ActivityRenameBinding>() {
ActivityRenameBinding
.
inflate
(
layoutInflater
)
}
private
var
doWhat
=
RENAME_USER_NAME
private
var
device
:
String
=
""
private
var
nickName
:
String
=
""
companion
object
{
const
val
RENAME_USER_NAME
=
"rename_user_name"
const
val
RENAME_FRIEND_NICK_NAME
=
"rename_friend_nick_name"
}
override
fun
onNewIntent
(
intent
:
Intent
?)
{
super
.
onNewIntent
(
intent
)
doWhat
=
intent
?.
extras
?.
getString
(
"doWhat"
,
RENAME_USER_NAME
)
?:
RENAME_USER_NAME
device
=
intent
?.
extras
?.
getString
(
"device"
,
""
)
?:
""
nickName
=
intent
?.
extras
?.
getString
(
"nickName"
,
""
)
?:
""
}
override
fun
initView
()
{
BarUtils
.
setStatusBarLightMode
(
this
,
true
)
BarUtils
.
setStatusBarColor
(
this
,
Color
.
TRANSPARENT
)
binding
.
root
.
updatePadding
(
top
=
BarUtils
.
getStatusBarHeight
())
doWhat
=
intent
.
extras
?.
getString
(
"doWhat"
,
RENAME_USER_NAME
)
?:
RENAME_USER_NAME
device
=
intent
?.
extras
?.
getString
(
"device"
,
""
)
?:
""
nickName
=
intent
?.
extras
?.
getString
(
"nickName"
,
""
)
?:
""
binding
.
editName
.
setText
(
LocationLoginUtils
.
nickNameSp
)
if
(
BuildConfig
.
DEBUG
)
{
binding
.
tvDevice
.
visibility
=
View
.
VISIBLE
binding
.
tvDevice
.
text
=
AppPreferences
.
getInstance
().
getString
(
"uuid"
,
""
)
binding
.
tvDevice
.
setOnClickListener
{
copyText
(
"device"
,
binding
.
tvDevice
.
text
.
toString
())
}
if
(
doWhat
==
RENAME_USER_NAME
)
{
binding
.
editName
.
setText
(
LocationLoginUtils
.
myNickNameSp
)
}
else
{
binding
.
editName
.
setText
(
nickName
)
binding
.
tvEnterTip
.
text
=
getString
(
R
.
string
.
enter_friend_nickname
)
}
// if (BuildConfig.DEBUG) {
// binding.tvDevice.visibility = View.VISIBLE
// binding.tvDevice.text = AppPreferences.getInstance().getString("uuid", "")
// binding.tvDevice.setOnClickListener {
// copyText("device", binding.tvDevice.text.toString())
// }
// }
}
override
fun
initListener
()
{
super
.
initListener
()
binding
.
tvRename
.
setOnClickListener
{
val
newName
=
binding
.
editName
.
text
.
toString
()
if
(
newName
.
isEmpty
())
{
toast
(
getString
(
R
.
string
.
name_is_empty
))
return
@setOnClickListener
when
(
doWhat
)
{
RENAME_USER_NAME
->
{
renameUser
()
}
RENAME_FRIEND_NICK_NAME
->
{
renameFriendNickName
()
}
}
LocationNameUtils
.
renameNickName
(
newName
)
{
flag
->
runCatching
{
if
(
flag
)
{
toast
(
"Rename success"
)
}
else
{
toast
(
"Rename failed"
)
}
}
}
private
fun
renameFriendNickName
()
{
val
newName
=
binding
.
editName
.
text
.
toString
()
if
(
newName
.
isEmpty
())
{
toast
(
getString
(
R
.
string
.
name_is_empty
))
return
}
val
nickList
=
SpStringUtils
.
getSpStringList
(
VIEWER_NICKNAME_KEY
)
val
olderSp
=
nickList
.
find
{
it
.
contains
(
device
)
}
olderSp
?.
let
{
SpStringUtils
.
deleteSpString
(
VIEWER_NICKNAME_KEY
,
it
)
}
val
sp
=
device
+
_DEVICE_NICKNAME_
+
newName
SpStringUtils
.
addSpString
(
VIEWER_NICKNAME_KEY
,
sp
)
toast
(
"Rename success"
)
finish
()
}
private
fun
renameUser
()
{
val
newName
=
binding
.
editName
.
text
.
toString
()
if
(
newName
.
isEmpty
())
{
toast
(
getString
(
R
.
string
.
name_is_empty
))
return
}
LocationNameUtils
.
renameNickName
(
newName
)
{
flag
->
runOnUiThread
{
if
(
flag
)
{
toast
(
"Rename success"
)
}
else
{
toast
(
"Rename failed"
)
}
finish
()
}
}
}
...
...
app/src/main/java/com/base/locationsharewhite/ui/set/SettingActivity.kt
View file @
f6cb9add
...
...
@@ -26,7 +26,7 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() {
BarUtils
.
setStatusBarColor
(
this
,
Color
.
WHITE
)
binding
.
root
.
updatePadding
(
top
=
BarUtils
.
getStatusBarHeight
())
binding
.
tvHelloName
.
text
=
getString
(
R
.
string
.
hello
)
+
",\n"
+
LocationLoginUtils
.
n
ickNameSp
binding
.
tvHelloName
.
text
=
getString
(
R
.
string
.
hello
)
+
",\n"
+
LocationLoginUtils
.
myN
ickNameSp
}
override
fun
initListener
()
{
...
...
app/src/main/java/com/base/locationsharewhite/ui/views/DialogView.kt
View file @
f6cb9add
...
...
@@ -122,7 +122,8 @@ object DialogView {
dialog
.
window
?.
attributes
=
params
binding
.
tvRename
.
setOnClickListener
{
dialog
.
dismiss
()
renameAction
?.
invoke
()
}
binding
.
tvDelete
.
setOnClickListener
{
dialog
.
dismiss
()
...
...
app/src/main/java/com/base/locationsharewhite/utils/SpStringUtils.kt
0 → 100644
View file @
f6cb9add
package
com.base.locationsharewhite.utils
object
SpStringUtils
{
private
val
TAG
=
"SpStringUtils"
const
val
VIEWER_NICKNAME_KEY
=
"viewer_nickname_key"
const
val
_DEVICE_NICKNAME_
=
"_device_nickname_"
fun
getSpStringList
(
key
:
String
):
List
<
String
>
{
val
sp
=
AppPreferences
.
getInstance
().
getString
(
key
,
""
)
return
if
(
sp
.
equals
(
""
))
{
listOf
()
}
else
{
sp
.
split
(
"|||"
)
}
}
fun
addSpString
(
key
:
String
,
value
:
String
)
{
LogEx
.
logDebug
(
TAG
,
"key=$key value=$value"
)
val
list
=
getSpStringList
(
key
).
toMutableList
()
list
.
add
(
value
)
val
string
=
list
.
joinToString
(
separator
=
"|||"
)
AppPreferences
.
getInstance
().
put
(
key
,
string
)
}
fun
deleteSpString
(
key
:
String
,
value
:
String
)
{
val
list
=
getSpStringList
(
key
).
toMutableList
()
list
.
remove
(
value
)
val
string
=
list
.
joinToString
(
separator
=
"|||"
)
AppPreferences
.
getInstance
().
put
(
key
,
string
)
}
}
\ No newline at end of file
app/src/main/res/layout/activity_rename.xml
View file @
f6cb9add
...
...
@@ -38,6 +38,7 @@
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/tv_enter_tip"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginHorizontal=
"16dp"
...
...
app/src/main/res/values/strings.xml
View file @
f6cb9add
...
...
@@ -59,4 +59,5 @@
<string
name=
"my_code"
>
My Code
</string>
<string
name=
"share"
>
Share
</string>
<string
name=
"preparing_advertisement"
>
<![CDATA[Preparing advertisement…]]>
</string>
<string
name=
"enter_friend_nickname"
>
Enter friend nickname
</string>
</resources>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment