From baee5a949af62cbc5bddcf3c263b2d153eaa1416 Mon Sep 17 00:00:00 2001 From: Paul-Louis NECH Date: Sat, 16 Nov 2019 14:06:58 +0100 Subject: [PATCH] chore: TODO --- .idea/dictionaries/pln.xml | 7 +++++++ TODO.md | 9 +++++++++ app/src/main/java/fr/plnech/dunbar/BuddyDetailActivity.kt | 72 ------------------------------------------------------------------------ app/src/main/java/fr/plnech/dunbar/BuddyDetailFragment.kt | 62 -------------------------------------------------------------- app/src/main/java/fr/plnech/dunbar/BuddyListActivity.kt | 121 ------------------------------------------------------------------------------------------------------------------------- app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/fr/plnech/dunbar/data/Friends.kt | 10 ---------- app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt | 112 ---------------------------------------------------------------------------------------------------------------- app/src/main/res/layout/activity_buddy_detail.xml | 54 ------------------------------------------------------ app/src/main/res/layout/activity_buddy_list.xml | 42 ------------------------------------------ app/src/main/res/layout/activity_contacts.xml | 33 +++++++++++++++++++++++++++++++++ app/src/main/res/layout/activity_friend_detail.xml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/activity_friends.xml | 33 --------------------------------- app/src/main/res/layout/activity_friends_list.xml | 42 ++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/buddy_detail.xml | 10 ---------- app/src/main/res/layout/buddy_list.xml | 13 ------------- app/src/main/res/layout/buddy_list_content.xml | 20 -------------------- app/src/main/res/layout/friend_detail.xml | 10 ++++++++++ app/src/main/res/layout/friend_list.xml | 35 +++++++++++++++++++++++++++++++++++ app/src/main/res/layout/friend_list_content.xml | 20 ++++++++++++++++++++ 23 files changed, 577 insertions(+), 549 deletions(-) create mode 100644 .idea/dictionaries/pln.xml delete mode 100644 app/src/main/java/fr/plnech/dunbar/BuddyDetailActivity.kt delete mode 100644 app/src/main/java/fr/plnech/dunbar/BuddyDetailFragment.kt delete mode 100644 app/src/main/java/fr/plnech/dunbar/BuddyListActivity.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt delete mode 100644 app/src/main/java/fr/plnech/dunbar/data/Friends.kt create mode 100644 app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt delete mode 100644 app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt delete mode 100644 app/src/main/res/layout/activity_buddy_detail.xml delete mode 100644 app/src/main/res/layout/activity_buddy_list.xml create mode 100644 app/src/main/res/layout/activity_contacts.xml create mode 100644 app/src/main/res/layout/activity_friend_detail.xml delete mode 100644 app/src/main/res/layout/activity_friends.xml create mode 100644 app/src/main/res/layout/activity_friends_list.xml delete mode 100644 app/src/main/res/layout/buddy_detail.xml delete mode 100644 app/src/main/res/layout/buddy_list.xml delete mode 100644 app/src/main/res/layout/buddy_list_content.xml create mode 100644 app/src/main/res/layout/friend_detail.xml create mode 100644 app/src/main/res/layout/friend_list.xml create mode 100644 app/src/main/res/layout/friend_list_content.xml diff --git a/.idea/dictionaries/pln.xml b/.idea/dictionaries/pln.xml new file mode 100644 index 0000000..601fdd4 --- /dev/null +++ b/.idea/dictionaries/pln.xml @@ -0,0 +1,7 @@ + + + + smsto + + + \ No newline at end of file diff --git a/TODO.md b/TODO.md index ea0833e..6ba94e1 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,12 @@ +# Nov 17 +- Refactor into BuddyListActivity + Details +- Whitelist, add friends, eventually from contacts + - Reusing current landing as "select contact"? Unless better picker +- Notifs +- Fastlane + +- Deploy v0.1! + # Feats - List friends diff --git a/app/src/main/java/fr/plnech/dunbar/BuddyDetailActivity.kt b/app/src/main/java/fr/plnech/dunbar/BuddyDetailActivity.kt deleted file mode 100644 index f2b9603..0000000 --- a/app/src/main/java/fr/plnech/dunbar/BuddyDetailActivity.kt +++ /dev/null @@ -1,72 +0,0 @@ -package fr.plnech.dunbar - -import android.content.Intent -import android.os.Bundle -import com.google.android.material.snackbar.Snackbar -import androidx.appcompat.app.AppCompatActivity -import android.view.MenuItem -import kotlinx.android.synthetic.main.activity_buddy_detail.* - -/** - * An activity representing a single Buddy detail screen. This - * activity is only used on narrow width devices. On tablet-size devices, - * item details are presented side-by-side with a list of items - * in a [BuddyListActivity]. - */ -class BuddyDetailActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_buddy_detail) - setSupportActionBar(detail_toolbar) - - fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() - } - - // Show the Up button in the action bar. - supportActionBar?.setDisplayHomeAsUpEnabled(true) - - // savedInstanceState is non-null when there is fragment state - // saved from previous configurations of this activity - // (e.g. when rotating the screen from portrait to landscape). - // In this case, the fragment will automatically be re-added - // to its container so we don't need to manually add it. - // For more information, see the Fragments API guide at: - // - // http://developer.android.com/guide/components/fragments.html - // - if (savedInstanceState == null) { - // Create the detail fragment and add it to the activity - // using a fragment transaction. - val fragment = BuddyDetailFragment().apply { - arguments = Bundle().apply { - putString( - BuddyDetailFragment.ARG_ITEM_ID, - intent.getStringExtra(BuddyDetailFragment.ARG_ITEM_ID) - ) - } - } - - supportFragmentManager.beginTransaction() - .add(R.id.buddy_detail_container, fragment) - .commit() - } - } - - override fun onOptionsItemSelected(item: MenuItem) = - when (item.itemId) { - android.R.id.home -> { - // This ID represents the Home or Up button. In the case of this - // activity, the Up button is shown. For - // more details, see the Navigation pattern on Android Design: - // - // http://developer.android.com/design/patterns/navigation.html#up-vs-back - - navigateUpTo(Intent(this, BuddyListActivity::class.java)) - true - } - else -> super.onOptionsItemSelected(item) - } -} diff --git a/app/src/main/java/fr/plnech/dunbar/BuddyDetailFragment.kt b/app/src/main/java/fr/plnech/dunbar/BuddyDetailFragment.kt deleted file mode 100644 index d7144c4..0000000 --- a/app/src/main/java/fr/plnech/dunbar/BuddyDetailFragment.kt +++ /dev/null @@ -1,62 +0,0 @@ -package fr.plnech.dunbar - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import fr.plnech.dunbar.dummy.DummyContent -import fr.plnech.dunbar.model.Friend -import kotlinx.android.synthetic.main.activity_buddy_detail.* -import kotlinx.android.synthetic.main.buddy_detail.view.* - -/** - * A fragment representing a single Buddy detail screen. - * This fragment is either contained in a [BuddyListActivity] - * in two-pane mode (on tablets) or a [BuddyDetailActivity] - * on handsets. - */ -class BuddyDetailFragment : Fragment() { - - /** - * The dummy content this fragment is presenting. - */ - private var item: Friend? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - arguments?.let { - if (it.containsKey(ARG_ITEM_ID)) { - // Load the dummy content specified by the fragment - // arguments. In a real-world scenario, use a Loader - // to load content from a content provider. - item = DummyContent.ITEM_MAP[it.getInt(ARG_ITEM_ID)] - activity?.toolbar_layout?.title = item?.name - } - } - } - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - val rootView = inflater.inflate(R.layout.buddy_detail, container, false) - - // Show the dummy content as text in a TextView. - item?.let { - rootView.buddy_detail.text = it.mapString() - activity?.title = it.name - } - - return rootView - } - - companion object { - /** - * The fragment argument representing the item ID that this fragment - * represents. - */ - const val ARG_ITEM_ID = "item_id" - } -} diff --git a/app/src/main/java/fr/plnech/dunbar/BuddyListActivity.kt b/app/src/main/java/fr/plnech/dunbar/BuddyListActivity.kt deleted file mode 100644 index 975d13f..0000000 --- a/app/src/main/java/fr/plnech/dunbar/BuddyListActivity.kt +++ /dev/null @@ -1,121 +0,0 @@ -package fr.plnech.dunbar - -import android.content.Intent -import android.os.Bundle -import android.view.LayoutInflater -import android.view.MenuItem -import android.view.View -import android.view.ViewGroup -import android.widget.TextView -import androidx.appcompat.app.AppCompatActivity -import androidx.core.app.NavUtils -import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.snackbar.Snackbar -import fr.plnech.dunbar.dummy.DummyContent -import fr.plnech.dunbar.model.Friend -import kotlinx.android.synthetic.main.activity_buddy_list.* -import kotlinx.android.synthetic.main.buddy_list.* -import kotlinx.android.synthetic.main.buddy_list_content.view.* - -class BuddyListActivity : AppCompatActivity() { - - /** - * Whether or not the activity is in two-pane mode, i.e. running on a tablet - * device. - */ - private var twoPane: Boolean = false - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_buddy_list) - - setSupportActionBar(toolbar) - toolbar.title = title - - fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() - } - // Show the Up button in the action bar. - supportActionBar?.setDisplayHomeAsUpEnabled(true) - - if (buddy_detail_container != null) { - // The detail container view will be present only in the - // large-screen layouts (res/values-w900dp). - // If this view is present, then the - // activity should be in two-pane mode. - twoPane = true - } - - setupRecyclerView(buddy_list) - } - - override fun onOptionsItemSelected(item: MenuItem) = - when (item.itemId) { - android.R.id.home -> { - NavUtils.navigateUpFromSameTask(this) - true - } - else -> super.onOptionsItemSelected(item) - } - - private fun setupRecyclerView(recyclerView: RecyclerView) { - recyclerView.adapter = SimpleItemRecyclerViewAdapter(this, DummyContent.ITEMS, twoPane) - } - - class SimpleItemRecyclerViewAdapter( - private val parentActivity: BuddyListActivity, - private val values: List, - private val twoPane: Boolean - ) : - RecyclerView.Adapter() { - - private val onClickListener: View.OnClickListener - - init { - onClickListener = View.OnClickListener { v -> - val item = v.tag as Friend - if (twoPane) { - val fragment = BuddyDetailFragment().apply { - arguments = Bundle().apply { - putString(BuddyDetailFragment.ARG_ITEM_ID, "friend_${item.id}") - } - } - parentActivity.supportFragmentManager - .beginTransaction() - .replace(R.id.buddy_detail_container, fragment) - .commit() - } else { - val intent = Intent(v.context, BuddyDetailActivity::class.java).apply { - putExtra(BuddyDetailFragment.ARG_ITEM_ID, "friend_${item.id}") - } - v.context.startActivity(intent) - } - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(R.layout.buddy_list_content, parent, false) - return ViewHolder(view) - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val item = values[position] - holder.idView.text = item.name - holder.contentView.text = item.mapString() - - with(holder.itemView) { - tag = item - setOnClickListener(onClickListener) - } - } - - override fun getItemCount() = values.size - - inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { - val idView: TextView = view.id_text - val contentView: TextView = view.content - } - } -} diff --git a/app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt b/app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt new file mode 100644 index 0000000..c30f1cf --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/FriendDetailActivity.kt @@ -0,0 +1,72 @@ +package fr.plnech.dunbar + +import android.content.Intent +import android.os.Bundle +import android.view.MenuItem +import androidx.appcompat.app.AppCompatActivity +import com.google.android.material.snackbar.Snackbar +import kotlinx.android.synthetic.main.activity_buddy_detail.* + +/** + * An activity representing a single Friend detail screen. This + * activity is only used on narrow width devices. On tablet-size devices, + * item details are presented side-by-side with a list of items + * in a [BuddyListActivity]. + */ +class BuddyDetailActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_buddy_detail) + setSupportActionBar(detail_toolbar) + + fab.setOnClickListener { view -> + Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show() + } + + // Show the Up button in the action bar. + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + // savedInstanceState is non-null when there is fragment state + // saved from previous configurations of this activity + // (e.g. when rotating the screen from portrait to landscape). + // In this case, the fragment will automatically be re-added + // to its container so we don't need to manually add it. + // For more information, see the Fragments API guide at: + // + // http://developer.android.com/guide/components/fragments.html + // + if (savedInstanceState == null) { + // Create the detail fragment and add it to the activity + // using a fragment transaction. + val fragment = BuddyDetailFragment().apply { + arguments = Bundle().apply { + putString( + BuddyDetailFragment.ARG_ITEM_ID, + intent.getStringExtra(BuddyDetailFragment.ARG_ITEM_ID) + ) + } + } + + supportFragmentManager.beginTransaction() + .add(R.id.buddy_detail_container, fragment) + .commit() + } + } + + override fun onOptionsItemSelected(item: MenuItem) = + when (item.itemId) { + android.R.id.home -> { + // This ID represents the Home or Up button. In the case of this + // activity, the Up button is shown. For + // more details, see the Navigation pattern on Android Design: + // + // http://developer.android.com/design/patterns/navigation.html#up-vs-back + + navigateUpTo(Intent(this, BuddyListActivity::class.java)) + true + } + else -> super.onOptionsItemSelected(item) + } +} diff --git a/app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt b/app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt new file mode 100644 index 0000000..be535f3 --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/FriendDetailFragment.kt @@ -0,0 +1,62 @@ +package fr.plnech.dunbar + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import fr.plnech.dunbar.dummy.DummyContent +import fr.plnech.dunbar.model.Friend +import kotlinx.android.synthetic.main.activity_buddy_detail.* +import kotlinx.android.synthetic.main.buddy_detail.view.* + +/** + * A fragment representing a single Buddy detail screen. + * This fragment is either contained in a [FriendListActivity] + * in two-pane mode (on tablets) or a [FriendDetailActivity] + * on handsets. + */ +class BuddyDetailFragment : Fragment() { + + /** + * The dummy content this fragment is presenting. + */ + private var item: Friend? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + arguments?.let { + if (it.containsKey(ARG_ITEM_ID)) { + // Load the dummy content specified by the fragment + // arguments. In a real-world scenario, use a Loader + // to load content from a content provider. + item = DummyContent.ITEM_MAP[it.getInt(ARG_ITEM_ID)] + activity?.toolbar_layout?.title = item?.name + } + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val rootView = inflater.inflate(R.layout.buddy_detail, container, false) + + // Show the dummy content as text in a TextView. + item?.let { + rootView.buddy_detail.text = it.mapString() + activity?.title = it.name + } + + return rootView + } + + companion object { + /** + * The fragment argument representing the item ID that this fragment + * represents. + */ + const val ARG_ITEM_ID = "item_id" + } +} diff --git a/app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt b/app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt new file mode 100644 index 0000000..975d13f --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/FriendListActivity.kt @@ -0,0 +1,121 @@ +package fr.plnech.dunbar + +import android.content.Intent +import android.os.Bundle +import android.view.LayoutInflater +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.NavUtils +import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.snackbar.Snackbar +import fr.plnech.dunbar.dummy.DummyContent +import fr.plnech.dunbar.model.Friend +import kotlinx.android.synthetic.main.activity_buddy_list.* +import kotlinx.android.synthetic.main.buddy_list.* +import kotlinx.android.synthetic.main.buddy_list_content.view.* + +class BuddyListActivity : AppCompatActivity() { + + /** + * Whether or not the activity is in two-pane mode, i.e. running on a tablet + * device. + */ + private var twoPane: Boolean = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_buddy_list) + + setSupportActionBar(toolbar) + toolbar.title = title + + fab.setOnClickListener { view -> + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show() + } + // Show the Up button in the action bar. + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + if (buddy_detail_container != null) { + // The detail container view will be present only in the + // large-screen layouts (res/values-w900dp). + // If this view is present, then the + // activity should be in two-pane mode. + twoPane = true + } + + setupRecyclerView(buddy_list) + } + + override fun onOptionsItemSelected(item: MenuItem) = + when (item.itemId) { + android.R.id.home -> { + NavUtils.navigateUpFromSameTask(this) + true + } + else -> super.onOptionsItemSelected(item) + } + + private fun setupRecyclerView(recyclerView: RecyclerView) { + recyclerView.adapter = SimpleItemRecyclerViewAdapter(this, DummyContent.ITEMS, twoPane) + } + + class SimpleItemRecyclerViewAdapter( + private val parentActivity: BuddyListActivity, + private val values: List, + private val twoPane: Boolean + ) : + RecyclerView.Adapter() { + + private val onClickListener: View.OnClickListener + + init { + onClickListener = View.OnClickListener { v -> + val item = v.tag as Friend + if (twoPane) { + val fragment = BuddyDetailFragment().apply { + arguments = Bundle().apply { + putString(BuddyDetailFragment.ARG_ITEM_ID, "friend_${item.id}") + } + } + parentActivity.supportFragmentManager + .beginTransaction() + .replace(R.id.buddy_detail_container, fragment) + .commit() + } else { + val intent = Intent(v.context, BuddyDetailActivity::class.java).apply { + putExtra(BuddyDetailFragment.ARG_ITEM_ID, "friend_${item.id}") + } + v.context.startActivity(intent) + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.buddy_list_content, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = values[position] + holder.idView.text = item.name + holder.contentView.text = item.mapString() + + with(holder.itemView) { + tag = item + setOnClickListener(onClickListener) + } + } + + override fun getItemCount() = values.size + + inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val idView: TextView = view.id_text + val contentView: TextView = view.content + } + } +} diff --git a/app/src/main/java/fr/plnech/dunbar/data/Friends.kt b/app/src/main/java/fr/plnech/dunbar/data/Friends.kt deleted file mode 100644 index 7e90ff0..0000000 --- a/app/src/main/java/fr/plnech/dunbar/data/Friends.kt +++ /dev/null @@ -1,10 +0,0 @@ -package fr.plnech.dunbar.data - -import android.content.ContentUris -import android.content.Context -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.provider.ContactsContract -import fr.plnech.dunbar.model.Friend -import java.io.IOException - diff --git a/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt b/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt new file mode 100644 index 0000000..4717ba7 --- /dev/null +++ b/app/src/main/java/fr/plnech/dunbar/ui/ContactsActivity.kt @@ -0,0 +1,112 @@ +package fr.plnech.dunbar.ui + +import android.content.Intent +import android.os.Bundle +import android.view.Menu +import android.view.MenuItem +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.NotificationManagerCompat +import androidx.recyclerview.widget.LinearLayoutManager +import fr.plnech.dunbar.BuddyListActivity +import fr.plnech.dunbar.R +import fr.plnech.dunbar.data.Messages +import fr.plnech.dunbar.fetchFriends +import fr.plnech.dunbar.model.Friend +import fr.plnech.dunbar.notif.FriendReminder +import fr.plnech.dunbar.plural +import kotlinx.android.synthetic.main.activity_friends.* +import kotlinx.android.synthetic.main.content_friends.* +import java.util.* + + +class FriendsActivity : AppCompatActivity() { + + private lateinit var messages: Messages + private var friends = listOf() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_friends) + setSupportActionBar(toolbar) + +// messages = Messages(applicationContext) + + fab.setOnClickListener { view -> + reloadFriends() + notifyFriend() + } + + reloadFriends() + notifyFriend() + } + + private fun notifyFriend() { + val idNotif = 0 + val notRecentlyTalked = friends.filter { + it.lastDate != null && (Date().time - it.lastDate!!.time) > 1 * 60 * 60 * 1000 + } + println("${notRecentlyTalked.size} good old friends I could talk to.") + val friend = notRecentlyTalked.minBy { it.timesContacted } + + + friend?.let { + with(NotificationManagerCompat.from(this)) { + val notification = + FriendReminder(applicationContext).createNotification( + friend, + this@FriendsActivity + ) + notification?.let { + notify(idNotif, notification) + } + } + } + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.menu_main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + return when (item.itemId) { + R.id.action_settings -> true + R.id.action_buddies -> { + startActivity(Intent(this, BuddyListActivity::class.java)) + true + } + else -> super.onOptionsItemSelected(item) + } + } + + private fun reloadFriends() { + friends = fetchFriends() + displayFriends() +// fetchMessages() + } + + private fun fetchMessages() { + messages.fetchAll() + Toast.makeText( + this, "${messages.sent.size} messages sent, " + + "${messages.inbox.size} messages received.", Toast.LENGTH_SHORT + ).show() + } + + + private fun displayFriends() { + val adapter = FriendsAdapter(friends) + val nbFriends = adapter.itemCount + + friendsList.layoutManager = LinearLayoutManager(this) + friendsList.setHasFixedSize(true) + friendsList.adapter = adapter + welcomeTitle.text = "$nbFriends ${"friend".plural(nbFriends)} on Dunbar" + } + +} diff --git a/app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt b/app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt deleted file mode 100644 index 4717ba7..0000000 --- a/app/src/main/java/fr/plnech/dunbar/ui/FriendsActivity.kt +++ /dev/null @@ -1,112 +0,0 @@ -package fr.plnech.dunbar.ui - -import android.content.Intent -import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import androidx.core.app.NotificationManagerCompat -import androidx.recyclerview.widget.LinearLayoutManager -import fr.plnech.dunbar.BuddyListActivity -import fr.plnech.dunbar.R -import fr.plnech.dunbar.data.Messages -import fr.plnech.dunbar.fetchFriends -import fr.plnech.dunbar.model.Friend -import fr.plnech.dunbar.notif.FriendReminder -import fr.plnech.dunbar.plural -import kotlinx.android.synthetic.main.activity_friends.* -import kotlinx.android.synthetic.main.content_friends.* -import java.util.* - - -class FriendsActivity : AppCompatActivity() { - - private lateinit var messages: Messages - private var friends = listOf() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_friends) - setSupportActionBar(toolbar) - -// messages = Messages(applicationContext) - - fab.setOnClickListener { view -> - reloadFriends() - notifyFriend() - } - - reloadFriends() - notifyFriend() - } - - private fun notifyFriend() { - val idNotif = 0 - val notRecentlyTalked = friends.filter { - it.lastDate != null && (Date().time - it.lastDate!!.time) > 1 * 60 * 60 * 1000 - } - println("${notRecentlyTalked.size} good old friends I could talk to.") - val friend = notRecentlyTalked.minBy { it.timesContacted } - - - friend?.let { - with(NotificationManagerCompat.from(this)) { - val notification = - FriendReminder(applicationContext).createNotification( - friend, - this@FriendsActivity - ) - notification?.let { - notify(idNotif, notification) - } - } - } - } - - override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. - menuInflater.inflate(R.menu.menu_main, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - return when (item.itemId) { - R.id.action_settings -> true - R.id.action_buddies -> { - startActivity(Intent(this, BuddyListActivity::class.java)) - true - } - else -> super.onOptionsItemSelected(item) - } - } - - private fun reloadFriends() { - friends = fetchFriends() - displayFriends() -// fetchMessages() - } - - private fun fetchMessages() { - messages.fetchAll() - Toast.makeText( - this, "${messages.sent.size} messages sent, " + - "${messages.inbox.size} messages received.", Toast.LENGTH_SHORT - ).show() - } - - - private fun displayFriends() { - val adapter = FriendsAdapter(friends) - val nbFriends = adapter.itemCount - - friendsList.layoutManager = LinearLayoutManager(this) - friendsList.setHasFixedSize(true) - friendsList.adapter = adapter - welcomeTitle.text = "$nbFriends ${"friend".plural(nbFriends)} on Dunbar" - } - -} diff --git a/app/src/main/res/layout/activity_buddy_detail.xml b/app/src/main/res/layout/activity_buddy_detail.xml deleted file mode 100644 index 4cdf42d..0000000 --- a/app/src/main/res/layout/activity_buddy_detail.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_buddy_list.xml b/app/src/main/res/layout/activity_buddy_list.xml deleted file mode 100644 index 43cf072..0000000 --- a/app/src/main/res/layout/activity_buddy_list.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_contacts.xml b/app/src/main/res/layout/activity_contacts.xml new file mode 100644 index 0000000..8ac531a --- /dev/null +++ b/app/src/main/res/layout/activity_contacts.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_friend_detail.xml b/app/src/main/res/layout/activity_friend_detail.xml new file mode 100644 index 0000000..b1db4c5 --- /dev/null +++ b/app/src/main/res/layout/activity_friend_detail.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_friends.xml b/app/src/main/res/layout/activity_friends.xml deleted file mode 100644 index a4bf715..0000000 --- a/app/src/main/res/layout/activity_friends.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_friends_list.xml b/app/src/main/res/layout/activity_friends_list.xml new file mode 100644 index 0000000..dad967a --- /dev/null +++ b/app/src/main/res/layout/activity_friends_list.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/buddy_detail.xml b/app/src/main/res/layout/buddy_detail.xml deleted file mode 100644 index ef9a0c2..0000000 --- a/app/src/main/res/layout/buddy_detail.xml +++ /dev/null @@ -1,10 +0,0 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/buddy_list.xml b/app/src/main/res/layout/buddy_list.xml deleted file mode 100644 index 1a28090..0000000 --- a/app/src/main/res/layout/buddy_list.xml +++ /dev/null @@ -1,13 +0,0 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/buddy_list_content.xml b/app/src/main/res/layout/buddy_list_content.xml deleted file mode 100644 index 395ec3e..0000000 --- a/app/src/main/res/layout/buddy_list_content.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/friend_detail.xml b/app/src/main/res/layout/friend_detail.xml new file mode 100644 index 0000000..d4374f4 --- /dev/null +++ b/app/src/main/res/layout/friend_detail.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/friend_list.xml b/app/src/main/res/layout/friend_list.xml new file mode 100644 index 0000000..33c05c0 --- /dev/null +++ b/app/src/main/res/layout/friend_list.xml @@ -0,0 +1,35 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/friend_list_content.xml b/app/src/main/res/layout/friend_list_content.xml new file mode 100644 index 0000000..395ec3e --- /dev/null +++ b/app/src/main/res/layout/friend_list_content.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file -- libgit2 0.27.0