mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-24 14:45:46 +00:00
Merge pull request #5 from HabitRPG/hafiz/settings-updates
Settings Project board fixes/updates
This commit is contained in:
commit
8d4ab949e0
9 changed files with 189 additions and 32 deletions
|
|
@ -1,8 +1,10 @@
|
|||
package com.habitrpg.wearos.habitica.ui.activities
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
import androidx.activity.viewModels
|
||||
import androidx.wear.widget.WearableLinearLayoutManager
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
|
@ -13,6 +15,7 @@ import com.habitrpg.wearos.habitica.ui.viewmodels.SettingsViewModel
|
|||
import com.habitrpg.wearos.habitica.util.HabiticaScrollingLayoutCallback
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class SettingsActivity: BaseActivity<ActivitySettingsBinding, SettingsViewModel>() {
|
||||
override val viewModel: SettingsViewModel by viewModels()
|
||||
|
|
@ -73,19 +76,57 @@ class SettingsActivity: BaseActivity<ActivitySettingsBinding, SettingsViewModel>
|
|||
null
|
||||
) {
|
||||
showLogoutConfirmation()
|
||||
},
|
||||
SettingsItem(
|
||||
"spacer",
|
||||
getString(R.string.settings),
|
||||
SettingsItem.Types.SPACER,
|
||||
null
|
||||
) {
|
||||
},
|
||||
SettingsItem(
|
||||
"footer",
|
||||
getString(R.string.version_info, versionName, versionCode),
|
||||
SettingsItem.Types.FOOTER,
|
||||
null
|
||||
){
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLogoutConfirmation() {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.are_you_sure)
|
||||
.setPositiveButton(R.string.logout) { alert, _ ->
|
||||
logout()
|
||||
alert.dismiss()
|
||||
}
|
||||
.setPositiveButton(R.string.action_cancel) { alert, _ ->
|
||||
alert.dismiss()
|
||||
}.show()
|
||||
private val versionName: String by lazy {
|
||||
try {
|
||||
@Suppress("DEPRECATION")
|
||||
packageManager?.getPackageInfo(packageName ?: "", 0)?.versionName ?: ""
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
private val versionCode: Int by lazy {
|
||||
try {
|
||||
@Suppress("DEPRECATION")
|
||||
packageManager?.getPackageInfo(packageName ?: "", 0)?.versionCode ?: 0
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLogoutConfirmation() {
|
||||
val logoutDialog = Dialog(this)
|
||||
val myLayout = layoutInflater.inflate(R.layout.logout_layout, null)
|
||||
val positiveButton: Button = myLayout.findViewById(R.id.logout_button)
|
||||
positiveButton.setOnClickListener {
|
||||
logout()
|
||||
logoutDialog.dismiss()
|
||||
}
|
||||
val negativeButton: Button = myLayout.findViewById(R.id.cancel_button)
|
||||
negativeButton.setOnClickListener {
|
||||
logoutDialog.dismiss()
|
||||
}
|
||||
logoutDialog.setContentView(myLayout)
|
||||
logoutDialog.show()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,16 +3,18 @@ package com.habitrpg.wearos.habitica.ui.adapters
|
|||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RadioButton
|
||||
import android.widget.Switch
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.RowFooterBinding
|
||||
import com.habitrpg.android.habitica.databinding.RowHeaderBinding
|
||||
import com.habitrpg.android.habitica.databinding.RowSettingsBinding
|
||||
import com.habitrpg.android.habitica.databinding.RowSpacerBinding
|
||||
import com.habitrpg.common.habitica.extensions.dpToPx
|
||||
import com.habitrpg.common.habitica.extensions.layoutInflater
|
||||
import com.habitrpg.wearos.habitica.ui.viewHolders.BindableViewHolder
|
||||
import com.habitrpg.wearos.habitica.ui.viewHolders.FooterViewHolder
|
||||
import com.habitrpg.wearos.habitica.ui.viewHolders.HeaderViewHolder
|
||||
import com.habitrpg.wearos.habitica.ui.viewHolders.SpacerViewHolder
|
||||
|
||||
|
|
@ -23,22 +25,28 @@ class SettingsAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
if (viewType == 0) {
|
||||
return HeaderViewHolder(RowHeaderBinding.inflate(parent.context.layoutInflater, parent, false).root)
|
||||
} else if (viewType == 1) {
|
||||
return SpacerViewHolder(RowSpacerBinding.inflate(parent.context.layoutInflater, parent, false).root)
|
||||
} else {
|
||||
return SettingsViewHolder(RowSettingsBinding.inflate(parent.context.layoutInflater, parent, false).root)
|
||||
return when (viewType) {
|
||||
0 -> { HeaderViewHolder(RowHeaderBinding.inflate(parent.context.layoutInflater, parent, false).root) }
|
||||
1 -> { FooterViewHolder(RowFooterBinding.inflate(parent.context.layoutInflater, parent, false).root) }
|
||||
2 -> { SpacerViewHolder(RowSpacerBinding.inflate(parent.context.layoutInflater, parent, false).root) }
|
||||
else -> { SettingsViewHolder(RowSettingsBinding.inflate(parent.context.layoutInflater, parent, false).root) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is SettingsViewHolder) {
|
||||
holder.bind(data[position])
|
||||
} else if (holder is HeaderViewHolder) {
|
||||
holder.bind(data[position].title)
|
||||
} else if (holder is SpacerViewHolder) {
|
||||
holder.bind(16.dpToPx(holder.itemView.context))
|
||||
when (holder) {
|
||||
is SettingsViewHolder -> {
|
||||
holder.bind(data[position])
|
||||
}
|
||||
is HeaderViewHolder -> {
|
||||
holder.bind(data[position].title)
|
||||
}
|
||||
is FooterViewHolder -> {
|
||||
holder.bind(data[position].title)
|
||||
}
|
||||
is SpacerViewHolder -> {
|
||||
holder.bind(16.dpToPx(holder.itemView.context))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,8 +56,9 @@ class SettingsAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
val item = data[position]
|
||||
return when (item.type) {
|
||||
SettingsItem.Types.HEADER -> 0
|
||||
SettingsItem.Types.SPACER -> 1
|
||||
else -> 2
|
||||
SettingsItem.Types.FOOTER -> 1
|
||||
SettingsItem.Types.SPACER -> 2
|
||||
else -> 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,11 +81,12 @@ class SettingsViewHolder(itemView: View) : BindableViewHolder<SettingsItem>(item
|
|||
}
|
||||
|
||||
if (data.type == SettingsItem.Types.TOGGLE) {
|
||||
val radio = RadioButton(itemView.context)
|
||||
radio.isChecked = data.value as? Boolean == true
|
||||
radio.isEnabled = false
|
||||
widget = radio
|
||||
binding.row.addView(radio)
|
||||
val switch = Switch(itemView.context)
|
||||
switch.isChecked = data.value as? Boolean == true
|
||||
switch.isClickable = false
|
||||
switch.showText = false
|
||||
widget = switch
|
||||
binding.row.addView(switch)
|
||||
|
||||
if (data.value as? Boolean == true) {
|
||||
binding.row.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(itemView.context, R.color.watch_purple_100))
|
||||
|
|
@ -105,6 +115,7 @@ data class SettingsItem(
|
|||
DESTRUCTIVE_BUTTON,
|
||||
SPACER,
|
||||
TOGGLE,
|
||||
HEADER
|
||||
HEADER,
|
||||
FOOTER
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.habitrpg.wearos.habitica.ui.viewHolders
|
||||
|
||||
import android.view.View
|
||||
import com.habitrpg.android.habitica.databinding.RowFooterBinding
|
||||
|
||||
class FooterViewHolder(itemView: View): BindableViewHolder<String>(itemView) {
|
||||
private val binding = RowFooterBinding.bind(itemView)
|
||||
|
||||
override fun bind(data: String) {
|
||||
binding.textView.text = data
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
package com.habitrpg.wearos.habitica.ui.viewHolders
|
||||
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.RowHeaderBinding
|
||||
|
||||
class HeaderViewHolder(itemView: View): BindableViewHolder<String>(itemView) {
|
||||
private val binding = RowHeaderBinding.bind(itemView)
|
||||
|
||||
override fun bind(data: String) {
|
||||
if (data == itemView.context.resources.getString(R.string.settings)) {
|
||||
binding.textView.setTextColor(ContextCompat.getColor(itemView.context, R.color.white))
|
||||
}
|
||||
binding.textView.text = data
|
||||
}
|
||||
}
|
||||
9
wearos/src/main/res/drawable/cancel.xml
Normal file
9
wearos/src/main/res/drawable/cancel.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportWidth="16"
|
||||
android:viewportHeight="16">
|
||||
<path
|
||||
android:pathData="M2.3249,15.85L0.2,13.675L5.8499,8L0.2,2.3L2.3249,0.125L7.9999,5.825L13.675,0.125L15.8,2.3L10.15,8L15.8,13.675L13.675,15.85L7.9999,10.15L2.3249,15.85Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
||||
9
wearos/src/main/res/drawable/logout.xml
Normal file
9
wearos/src/main/res/drawable/logout.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="22dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="22"
|
||||
android:viewportHeight="20">
|
||||
<path
|
||||
android:pathData="M3.8,19.8C2.95,19.8 2.225,19.5043 1.625,18.913C1.025,18.321 0.725,17.5917 0.725,16.725V3.275C0.725,2.4083 1.025,1.679 1.625,1.087C2.225,0.4957 2.95,0.2 3.8,0.2H11.025V3.275H3.8V16.725H11.025V19.8H3.8ZM14.975,16.325L12.775,14.125L15.375,11.525H7.6V8.45H15.375L12.775,5.85L14.975,3.675L21.275,10L14.975,16.325Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
||||
42
wearos/src/main/res/layout/logout_layout.xml
Normal file
42
wearos/src/main/res/layout/logout_layout.xml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.habitrpg.wearos.habitica.ui.views.HabiticaScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/log_out_of_habitica"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="@color/white"
|
||||
android:layout_marginBottom="18dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/logout_button"
|
||||
style="@style/ChipButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/spacing_small"
|
||||
android:drawableStart="@drawable/logout"
|
||||
android:text="@string/logout" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel_button"
|
||||
style="@style/ChipButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableStart="@drawable/cancel"
|
||||
android:text="@string/action_cancel" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.habitrpg.wearos.habitica.ui.views.HabiticaScrollView>
|
||||
26
wearos/src/main/res/layout/row_footer.xml
Normal file
26
wearos/src/main/res/layout/row_footer.xml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="45dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_above="@id/text_view"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:fontFamily="sans-serif"
|
||||
android:textColor="@color/watch_purple_200"
|
||||
android:textSize="12sp"
|
||||
tools:text="Footer Text" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -29,5 +29,7 @@
|
|||
<string name="save">Save</string>
|
||||
<string name="sync_data">Sync Data</string>
|
||||
<string name="hide_task_rewards">Hide task rewards</string>
|
||||
<string name="version_info">Version %1$s (%2$d)</string>
|
||||
<string name="log_out_of_habitica">Log out of Habitica?</string>
|
||||
<string name="no_tasks">Create a %s to add to this list</string>
|
||||
</resources>
|
||||
Loading…
Reference in a new issue