Add expiration settings screen
parent
e6d854a4ea
commit
63f372b45c
@ -0,0 +1,96 @@
|
||||
package org.thoughtcrime.securesms.conversation.expiration
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.util.SparseArray
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import network.loki.messenger.R
|
||||
import network.loki.messenger.databinding.ActivityExpirationSettingsBinding
|
||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.preferences.RadioOption
|
||||
import org.thoughtcrime.securesms.preferences.RadioOptionAdapter
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
|
||||
|
||||
private lateinit var binding : ActivityExpirationSettingsBinding
|
||||
|
||||
private val expirationType: ExpirationType? by lazy {
|
||||
ExpirationType.valueOf(intent.getIntExtra(EXTRA_EXPIRATION_TYPE, -1))
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
val scrollParcelArray = SparseArray<Parcelable>()
|
||||
binding.scrollView.saveHierarchyState(scrollParcelArray)
|
||||
outState.putSparseParcelableArray(SCROLL_PARCEL, scrollParcelArray)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
|
||||
super.onCreate(savedInstanceState, ready)
|
||||
binding = ActivityExpirationSettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setUpToolbar()
|
||||
|
||||
savedInstanceState?.let { bundle ->
|
||||
val scrollStateParcel = bundle.getSparseParcelableArray<Parcelable>(SCROLL_PARCEL)
|
||||
if (scrollStateParcel != null) {
|
||||
binding.scrollView.restoreHierarchyState(scrollStateParcel)
|
||||
}
|
||||
}
|
||||
|
||||
val options = if (expirationType == ExpirationType.DELETE_AFTER_SEND) {
|
||||
val values = resources.getIntArray(R.array.send_expiration_time_values).map(Int::toString)
|
||||
val names = resources.getStringArray(R.array.send_expiration_time_names)
|
||||
values.zip(names) { value, name -> RadioOption(value, name)}
|
||||
} else {
|
||||
listOf(
|
||||
RadioOption("off", getString(R.string.expiration_off)),
|
||||
RadioOption("read", getString(R.string.expiration_type_disappear_after_read)),
|
||||
RadioOption("send", getString(R.string.expiration_type_disappear_after_send))
|
||||
)
|
||||
}
|
||||
val optionAdapter = RadioOptionAdapter {
|
||||
|
||||
}
|
||||
binding.textViewDeleteType.isVisible = expirationType == null
|
||||
binding.textViewTimer.isVisible = expirationType == null
|
||||
binding.layoutTimer.isVisible = expirationType == null
|
||||
binding.recyclerView.apply {
|
||||
adapter = optionAdapter
|
||||
addItemDecoration(ContextCompat.getDrawable(this@ExpirationSettingsActivity, R.drawable.conversation_menu_divider)!!.let {
|
||||
DividerItemDecoration(this@ExpirationSettingsActivity, RecyclerView.VERTICAL).apply {
|
||||
setDrawable(it)
|
||||
}
|
||||
})
|
||||
setHasFixedSize(true)
|
||||
}
|
||||
optionAdapter.submitList(options)
|
||||
|
||||
}
|
||||
|
||||
private fun setUpToolbar() {
|
||||
setSupportActionBar(binding.toolbar)
|
||||
val actionBar = supportActionBar ?: return
|
||||
actionBar.title = getString(R.string.activity_expiration_settings_title)
|
||||
actionBar.subtitle = if (expirationType == ExpirationType.DELETE_AFTER_SEND) {
|
||||
getString(R.string.activity_expiration_settings_subtitle_sent)
|
||||
} else {
|
||||
getString(R.string.activity_expiration_settings_subtitle)
|
||||
}
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.setHomeButtonEnabled(true)
|
||||
}
|
||||
companion object {
|
||||
private const val SCROLL_PARCEL = "scroll_parcel"
|
||||
const val EXTRA_EXPIRATION_TYPE = "expiration_type"
|
||||
const val EXTRA_READ_ONLY = "read_only"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?colorPrimary"
|
||||
app:contentInsetStart="0dp"
|
||||
app:subtitle="@string/activity_expiration_settings_subtitle"
|
||||
app:subtitleTextAppearance="@style/TextAppearance.Session.ToolbarSubtitle"
|
||||
app:title="@string/activity_expiration_settings_title" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_delete_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="@dimen/large_spacing"
|
||||
android:paddingVertical="@dimen/small_spacing"
|
||||
android:text="@string/activity_expiration_settings_delete_type"
|
||||
android:textColor="?android:textColorTertiary"
|
||||
android:textSize="@dimen/medium_font_size" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/theme_option_classic_dark"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/preference_top"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="@dimen/large_spacing"
|
||||
android:paddingVertical="@dimen/medium_spacing">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:itemCount="6"
|
||||
tools:listitem="@layout/item_selectable" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_timer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="@dimen/large_spacing"
|
||||
android:paddingVertical="@dimen/small_spacing"
|
||||
android:text="@string/activity_expiration_settings_timer"
|
||||
android:textColor="?android:textColorTertiary"
|
||||
android:textSize="@dimen/medium_font_size" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_timer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/massive_spacing"
|
||||
android:background="@drawable/preference_single"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/medium_spacing">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingHorizontal="@dimen/large_spacing"
|
||||
android:paddingVertical="@dimen/small_spacing"
|
||||
android:text="@string/activity_appearance_follow_system_explanation"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/medium_font_size"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/system_settings_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="@dimen/large_spacing" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_set"
|
||||
style="@style/Widget.Session.Button.Common.ProminentOutline"
|
||||
android:layout_width="196dp"
|
||||
android:layout_height="@dimen/medium_button_height"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/medium_spacing"
|
||||
android:layout_marginBottom="@dimen/massive_spacing"
|
||||
android:text="@string/expiration_settings_set_button_title" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
Loading…
Reference in New Issue