Skip to content

Commit

Permalink
UI elements should be laid out correctly, but none of the logic is in…
Browse files Browse the repository at this point in the history
… place. Started working on the crypt class.
  • Loading branch information
Romulus10 committed Oct 3, 2018
1 parent 7d8d7ba commit 02b1285
Show file tree
Hide file tree
Showing 18 changed files with 549 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ContactFragment : Fragment() {
*/
interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
fun onListFragmentInteraction(item: Contact?)
fun onListFragmentInteraction(item: Contact.Contact)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package io.github.romulus10.blckchnmsg

import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import io.github.romulus10.blckchnmsg.blckchnmsg.data.Key

/**
* A fragment representing a list of Items.
* Activities containing this fragment MUST implement the
* [ListKeysFragment.OnListFragmentInteractionListener] interface.
*/
class ListKeysFragment : Fragment() {

// TODO: Customize parameters
private var columnCount = 1

private var listener: OnListFragmentInteractionListener? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

arguments?.let {
columnCount = it.getInt(ARG_COLUMN_COUNT)
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_listkeys_list, container, false)

// Set the adapter
if (view is RecyclerView) {
with(view) {
layoutManager = when {
columnCount <= 1 -> LinearLayoutManager(context)
else -> GridLayoutManager(context, columnCount)
}
adapter = MyListKeysRecyclerViewAdapter(Key.ITEMS, listener)
}
}
return view
}

override fun onAttach(context: Context) {
super.onAttach(context)
if (context is OnListFragmentInteractionListener) {
listener = context
} else {
throw RuntimeException(context.toString() + " must implement OnListFragmentInteractionListener")
}
}

override fun onDetach() {
super.onDetach()
listener = null
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
*
*
* See the Android Training lesson
* [Communicating with Other Fragments](http://developer.android.com/training/basics/fragments/communicating.html)
* for more information.
*/
interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
fun onListFragmentInteraction(item: Key.Key)
}

companion object {

// TODO: Customize parameter argument names
const val ARG_COLUMN_COUNT = "column-count"

// TODO: Customize parameter initialization
@JvmStatic
fun newInstance(columnCount: Int) =
ListKeysFragment().apply {
arguments = Bundle().apply {
putInt(ARG_COLUMN_COUNT, columnCount)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.widget.TextView
import java.util.ArrayList
import android.Manifest.permission.READ_CONTACTS
import android.content.Intent
import android.util.Log

import kotlinx.android.synthetic.main.activity_login.*

Expand Down Expand Up @@ -107,11 +108,23 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {
// Store values at the time of the login attempt.
val addrStr = addr.text.toString()
val unameStr = uname.text.toString()
val emailAddrStr = email.text.toString()
val emailStr = email.text.toString()
val passwordStr = password.text.toString()

var cancel = false
var focusView: View? = null

if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView?.requestFocus()
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
showProgress(true)
mAuthTask = UserLoginTask(emailStr, passwordStr)
mAuthTask!!.execute(null as Void?)
}
}

private fun isEmailValid(email: String): Boolean {
Expand Down Expand Up @@ -235,6 +248,9 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {
}

override fun onPostExecute(success: Boolean?) {

Log.d("UserLoginActivity", "onPostExecute firing.")

mAuthTask = null
showProgress(false)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.romulus10.blckchnmsg

import android.net.Uri
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.design.widget.NavigationView
Expand All @@ -9,10 +10,35 @@ import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import io.github.romulus10.blckchnmsg.blckchnmsg.data.Contact
import io.github.romulus10.blckchnmsg.blckchnmsg.data.Key
import io.github.romulus10.blckchnmsg.blckchnmsg.data.Message
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*

class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener,
MessageFragment.OnListFragmentInteractionListener,
ContactFragment.OnListFragmentInteractionListener,
ListKeysFragment.OnListFragmentInteractionListener,
NewContact.OnFragmentInteractionListener,
NewMessage.OnFragmentInteractionListener,
KeysFragment.OnFragmentInteractionListener {

override fun onFragmentInteraction(uri: Uri) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onListFragmentInteraction(item: Message.Message) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onListFragmentInteraction(item: Contact.Contact) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onListFragmentInteraction(item: Key.Key) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -93,7 +119,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
Log.d("MainActivity", "Keys")
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
val fragment = KeysFragment()
val fragment = ListKeysFragment()
val b = Bundle()
fragment.arguments = b
fragmentTransaction.replace(R.id.fragment_container, fragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MessageFragment : Fragment() {
*/
interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
fun onListFragmentInteraction(item: Message?)
fun onListFragmentInteraction(item: Message.Message)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import android.widget.TextView

import io.github.romulus10.blckchnmsg.ContactFragment.OnListFragmentInteractionListener
import io.github.romulus10.blckchnmsg.blckchnmsg.data.Contact
import io.github.romulus10.blckchnmsg.dummy.DummyContent.DummyItem

import kotlinx.android.synthetic.main.fragment_contact.view.*

/**
* [RecyclerView.Adapter] that can display a [DummyItem] and makes a call to the
* [RecyclerView.Adapter] that can display a [Contact] and makes a call to the
* specified [OnListFragmentInteractionListener].
* TODO: Replace the implementation with code for your data type.
*/
Expand All @@ -27,7 +26,7 @@ class MyContactRecyclerViewAdapter(

init {
mOnClickListener = View.OnClickListener { v ->
val item = v.tag as Contact
val item = v.tag as Contact.Contact
// Notify the active callbacks interface (the activity, if the fragment is attached to
// one) that an item has been selected.
mListener?.onListFragmentInteraction(item)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.github.romulus10.blckchnmsg

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView


import io.github.romulus10.blckchnmsg.ListKeysFragment.OnListFragmentInteractionListener
import io.github.romulus10.blckchnmsg.blckchnmsg.data.Key

import kotlinx.android.synthetic.main.fragment_listkeys.view.*

/**
* [RecyclerView.Adapter] that can display a [DummyItem] and makes a call to the
* specified [OnListFragmentInteractionListener].
* TODO: Replace the implementation with code for your data type.
*/
class MyListKeysRecyclerViewAdapter(
private val mValues: List<Key.Key>,
private val mListener: OnListFragmentInteractionListener?)
: RecyclerView.Adapter<MyListKeysRecyclerViewAdapter.ViewHolder>() {

private val mOnClickListener: View.OnClickListener

init {
mOnClickListener = View.OnClickListener { v ->
val item = v.tag as Key.Key
// Notify the active callbacks interface (the activity, if the fragment is attached to
// one) that an item has been selected.
mListener?.onListFragmentInteraction(item)
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.fragment_listkeys, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = mValues[position]
holder.mIdView.text = item.id
holder.mContentView.text = item.content

with(holder.mView) {
tag = item
setOnClickListener(mOnClickListener)
}
}

override fun getItemCount(): Int = mValues.size

inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
val mIdView: TextView = mView.item_number
val mContentView: TextView = mView.content

override fun toString(): String {
return super.toString() + " '" + mContentView.text + "'"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MyMessageRecyclerViewAdapter(

init {
mOnClickListener = View.OnClickListener { v ->
val item = v.tag as Message
val item = v.tag as Message.Message
// Notify the active callbacks interface (the activity, if the fragment is attached to
// one) that an item has been selected.
mListener?.onListFragmentInteraction(item)
Expand Down
Loading

0 comments on commit 02b1285

Please sign in to comment.