mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
WIP
This commit is contained in:
parent
b80d70c31f
commit
fb3bd26538
@ -1,5 +1,6 @@
|
|||||||
package org.thoughtcrime.securesms.loki.redesign.activities
|
package org.thoughtcrime.securesms.loki.redesign.activities
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.arch.lifecycle.Observer
|
import android.arch.lifecycle.Observer
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -8,9 +9,11 @@ import android.database.Cursor
|
|||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
|
import android.os.AsyncTask
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.LoaderManager
|
import android.support.v4.app.LoaderManager
|
||||||
import android.support.v4.content.Loader
|
import android.support.v4.content.Loader
|
||||||
|
import android.support.v7.app.AlertDialog
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper
|
import android.support.v7.widget.helper.ItemTouchHelper
|
||||||
@ -26,6 +29,7 @@ import org.thoughtcrime.securesms.loki.redesign.utilities.push
|
|||||||
import org.thoughtcrime.securesms.loki.redesign.views.ConversationView
|
import org.thoughtcrime.securesms.loki.redesign.views.ConversationView
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
import org.thoughtcrime.securesms.notifications.MessageNotifier
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
@ -139,7 +143,29 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
|||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
||||||
// TODO: Implement
|
val builder = AlertDialog.Builder(context)
|
||||||
|
builder.setIconAttribute(R.attr.dialog_alert_icon)
|
||||||
|
builder.setTitle("Delete Selected Conversation?")
|
||||||
|
builder.setMessage("This will permanently delete the selected conversation.")
|
||||||
|
builder.setCancelable(true)
|
||||||
|
builder.setPositiveButton("Delete") { dialog, _ ->
|
||||||
|
val threadID = (viewHolder as HomeAdapter.ViewHolder).view.thread!!.threadId
|
||||||
|
AsyncTask.execute {
|
||||||
|
DatabaseFactory.getThreadDatabase(context).deleteConversation(threadID)
|
||||||
|
MessageNotifier.updateNotification(context)
|
||||||
|
}
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||||
|
val animator = ValueAnimator.ofFloat(viewHolder.itemView.translationX, 0.0f)
|
||||||
|
animator.duration = 150
|
||||||
|
animator.addUpdateListener {
|
||||||
|
update(viewHolder, animator.animatedValue as Float)
|
||||||
|
}
|
||||||
|
animator.start()
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
builder.create().show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dx: Float, dy: Float, actionState: Int, isCurrentlyActive: Boolean) {
|
override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dx: Float, dy: Float, actionState: Int, isCurrentlyActive: Boolean) {
|
||||||
@ -147,7 +173,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
|||||||
super.onChildDraw(c, recyclerView, viewHolder, dx, dy, actionState, isCurrentlyActive)
|
super.onChildDraw(c, recyclerView, viewHolder, dx, dy, actionState, isCurrentlyActive)
|
||||||
} else {
|
} else {
|
||||||
val itemView = viewHolder.itemView
|
val itemView = viewHolder.itemView
|
||||||
val alpha = 1.0f - abs(dx) / viewHolder.itemView.width.toFloat()
|
|
||||||
if (dx < 0) {
|
if (dx < 0) {
|
||||||
val backgroundPaint = Paint()
|
val backgroundPaint = Paint()
|
||||||
backgroundPaint.color = context.resources.getColorWithID(R.color.destructive, context.theme)
|
backgroundPaint.color = context.resources.getColorWithID(R.color.destructive, context.theme)
|
||||||
@ -158,10 +183,15 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
|||||||
val top = itemView.top.toFloat() + (itemView.bottom.toFloat() - itemView.top.toFloat() - icon.height) / 2
|
val top = itemView.top.toFloat() + (itemView.bottom.toFloat() - itemView.top.toFloat() - icon.height) / 2
|
||||||
c.drawBitmap(icon, left, top, iconPaint)
|
c.drawBitmap(icon, left, top, iconPaint)
|
||||||
}
|
}
|
||||||
viewHolder.itemView.alpha = alpha
|
update(viewHolder, dx)
|
||||||
viewHolder.itemView.translationX = dx
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun update(viewHolder: RecyclerView.ViewHolder, dx: Float) {
|
||||||
|
val alpha = 1.0f - abs(dx) / viewHolder.itemView.width.toFloat()
|
||||||
|
viewHolder.itemView.alpha = alpha
|
||||||
|
viewHolder.itemView.translationX = dx
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user