forked from hush/SilentDragonAndroid-old
N1CK145
5 years ago
9 changed files with 106 additions and 133 deletions
@ -1,43 +0,0 @@ |
|||
package org.myhush.silentdragon |
|||
|
|||
class Addressbook { |
|||
private val data = ArrayList<Contact>() |
|||
|
|||
fun addContact(contact: Contact){ |
|||
data.add(contact) |
|||
} |
|||
|
|||
fun getContactByAddress(address: String): Contact? { |
|||
data.forEach { |
|||
if (it.zaddress == address) |
|||
return it |
|||
} |
|||
return null |
|||
} |
|||
|
|||
fun getContactsByFirstName(firstName: String): ArrayList<Contact> { |
|||
val list = ArrayList<Contact>() |
|||
data.forEach { |
|||
if (it.firstName == firstName) |
|||
list.add(it) |
|||
} |
|||
return list |
|||
} |
|||
|
|||
fun getContactsByLastName(lastName: String): ArrayList<Contact> { |
|||
val list = ArrayList<Contact>() |
|||
data.forEach { |
|||
if (it.lastName == lastName) |
|||
list.add(it) |
|||
} |
|||
return list } |
|||
|
|||
fun getContactsByFullName(firstName: String, lastName: String): ArrayList<Contact> { |
|||
val list = ArrayList<Contact>() |
|||
data.forEach { |
|||
if (it.firstName == firstName && it.lastName == lastName) |
|||
list.add(it) |
|||
} |
|||
return list |
|||
} |
|||
} |
@ -1,7 +0,0 @@ |
|||
package org.myhush.silentdragon |
|||
|
|||
class Contact { |
|||
var firstName = "" |
|||
var lastName = "" |
|||
var zaddress = "" |
|||
} |
@ -1,53 +1,65 @@ |
|||
package org.myhush.silentdragon.chat |
|||
|
|||
import android.content.Context |
|||
import android.support.v7.app.AppCompatActivity |
|||
import android.os.Bundle |
|||
import android.support.v4.app.FragmentTransaction |
|||
import android.util.AttributeSet |
|||
import android.view.View |
|||
import android.view.Window |
|||
import android.widget.TextView |
|||
import kotlinx.android.synthetic.main.fragment_conversation_item_send.* |
|||
import org.myhush.silentdragon.R |
|||
import org.myhush.silentdragon.conversation_item_recive |
|||
import org.myhush.silentdragon.conversation_item_send |
|||
|
|||
class ConversationActivity : AppCompatActivity() { |
|||
var displayName = "" |
|||
var messages = HashMap<Boolean, String>() |
|||
|
|||
override fun onCreate(savedInstanceState: Bundle?) { |
|||
super.onCreate(savedInstanceState) |
|||
setContentView(R.layout.activity_conversation) |
|||
findViewById<TextView>(R.id.textViewContactName2) |
|||
|
|||
displayName = intent.extras.get("displayName").toString() |
|||
|
|||
restoreChat() |
|||
setViews() |
|||
} |
|||
|
|||
private fun setViews() { |
|||
findViewById<TextView>(R.id.textViewContactName2).text = displayName |
|||
} |
|||
|
|||
private fun restoreChat(){ |
|||
addMessage("Lorem Ipsum", true) |
|||
addMessage("Lorem Ipsum", true) |
|||
addMessage("Lorem Ipsum", false) |
|||
addMessage("Lorem Ipsum", true) |
|||
val message1 = Message() |
|||
message1.content = " Hallo! " |
|||
message1.type = ConversationFragmentType.RECIVE |
|||
message1.dateTime = 0 |
|||
|
|||
addMessage(message1) |
|||
|
|||
val message2 = Message() |
|||
message2.content = " Wie geht es dir? " |
|||
message2.type = ConversationFragmentType.SEND |
|||
message2.dateTime = 0 |
|||
|
|||
//addMessage(" Wie gehts?", ConversationFragmentType.RECIVE, 0) |
|||
//addMessage("Follow me on YouTube! <3 ", ConversationFragmentType.RECIVE, 0) |
|||
//addMessage(" .", ConversationFragmentType.SEND, 0) |
|||
//addMessage("f", ConversationFragmentType.SEND, 0) |
|||
} |
|||
|
|||
|
|||
|
|||
fun addMessage(message: String, recived: Boolean){ |
|||
private fun addMessage(message: Message){ |
|||
var memo = message.content |
|||
|
|||
while (memo.startsWith(" ") || memo.endsWith(" ")){ |
|||
memo = memo.removePrefix(" ") |
|||
memo = memo.removeSuffix(" ") |
|||
} |
|||
|
|||
if(!memo.isNullOrEmpty()){ |
|||
val fragTx: FragmentTransaction = supportFragmentManager.beginTransaction() |
|||
val fragment = ConversationItemFragment() |
|||
|
|||
if(recived){ |
|||
val fragment = conversation_item_recive() |
|||
fragment.message.text = message |
|||
fragTx.add(R.id.MessageList, fragment) |
|||
fragment.message = message |
|||
|
|||
}else{ |
|||
val fragment = conversation_item_send() |
|||
fragment.message.text = message |
|||
fragTx.add(R.id.MessageList, fragment) |
|||
} |
|||
fragTx.commit() |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,59 @@ |
|||
package org.myhush.silentdragon.chat |
|||
|
|||
import android.graphics.drawable.Drawable |
|||
import android.os.Bundle |
|||
import android.support.constraint.ConstraintSet |
|||
import android.support.v4.app.Fragment |
|||
import android.view.LayoutInflater |
|||
import android.view.View |
|||
import android.view.ViewGroup |
|||
import android.widget.TextView |
|||
import android.widget.Toast |
|||
import kotlinx.android.synthetic.main.content_tx_details.* |
|||
import org.myhush.silentdragon.R |
|||
|
|||
enum class ConversationFragmentType{ |
|||
SEND, |
|||
RECIVE |
|||
} |
|||
|
|||
class ConversationItemFragment: Fragment() { |
|||
var message: Message = Message() |
|||
|
|||
override fun onCreateView( |
|||
inflater: LayoutInflater, |
|||
container: ViewGroup?, |
|||
savedInstanceState: Bundle? |
|||
): View? { |
|||
val v = inflater.inflate(R.layout.fragment_conversation_item, container, false) |
|||
val msgView = v.findViewById<TextView>(R.id.message) |
|||
Toast.makeText(v.context, "onCreateView", Toast.LENGTH_SHORT) |
|||
|
|||
msgView.text = message.content |
|||
|
|||
when (message.type){ |
|||
ConversationFragmentType.SEND -> { |
|||
var set = ConstraintSet() |
|||
|
|||
set.clone(constraintLayout) |
|||
set.connect(R.id.message, ConstraintSet.RIGHT, parentFragment!!.id, ConstraintSet.RIGHT, 8) |
|||
set.connect(R.id.message, ConstraintSet.TOP, parentFragment!!.id, ConstraintSet.TOP, 8) |
|||
set.applyTo(constraintLayout) |
|||
|
|||
msgView.background = Drawable.createFromPath("drawable/chat_background_send.xml") |
|||
} |
|||
|
|||
ConversationFragmentType.RECIVE -> { |
|||
var set = ConstraintSet() |
|||
|
|||
set.clone(constraintLayout) |
|||
set.connect(R.id.message, ConstraintSet.LEFT, parentFragment!!.id, ConstraintSet.LEFT, 8) |
|||
set.connect(R.id.message, ConstraintSet.TOP, parentFragment!!.id, ConstraintSet.TOP, 8) |
|||
set.applyTo(constraintLayout) |
|||
|
|||
msgView.background = Drawable.createFromPath("drawable/chat_background_recive.xml") |
|||
} |
|||
} |
|||
return super.onCreateView(inflater, container, savedInstanceState) |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
package org.myhush.silentdragon.chat |
|||
|
|||
class Message { |
|||
var content: String = "" |
|||
var dateTime: Long = 0 |
|||
var type: ConversationFragmentType = ConversationFragmentType.SEND |
|||
} |
@ -1,17 +0,0 @@ |
|||
package org.myhush.silentdragon |
|||
|
|||
import android.os.Bundle |
|||
import android.support.v4.app.Fragment |
|||
import android.view.LayoutInflater |
|||
import android.view.View |
|||
import android.view.ViewGroup |
|||
|
|||
class conversation_item_recive : Fragment() { |
|||
|
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, |
|||
savedInstanceState: Bundle?): View? { |
|||
// Inflate the layout for this fragment |
|||
var v: View = inflater.inflate(R.layout.fragment_conversation_item_recive, container, false) |
|||
return v |
|||
} |
|||
} |
@ -1,17 +0,0 @@ |
|||
package org.myhush.silentdragon |
|||
|
|||
import android.os.Bundle |
|||
import android.support.v4.app.Fragment |
|||
import android.view.LayoutInflater |
|||
import android.view.View |
|||
import android.view.ViewGroup |
|||
|
|||
class conversation_item_send : Fragment() { |
|||
|
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, |
|||
savedInstanceState: Bundle?): View? { |
|||
// Inflate the layout for this fragment |
|||
var v: View = inflater.inflate(R.layout.fragment_conversation_item_send, container, false) |
|||
return v |
|||
} |
|||
} |
@ -1,21 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
tools:context=".conversation_item_send" > |
|||
|
|||
<TextView |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="9dp" |
|||
android:layout_marginTop="10dp" |
|||
android:background="@drawable/chat_background_recive" |
|||
android:maxWidth="260sp" |
|||
android:padding="10sp" |
|||
android:text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr" |
|||
android:textColor="@color/message_text" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" /> |
|||
</android.support.constraint.ConstraintLayout> |
Loading…
Reference in new issue