Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
ui: Implement 'Manage Devices' & improve nav.
Browse files Browse the repository at this point in the history
Manage Devices & Preferences are now
destinations in 'nav_home'
  • Loading branch information
velitasali committed Aug 9, 2021
1 parent b4f066e commit e119d73
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 188 deletions.
20 changes: 0 additions & 20 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,6 @@
android:value="org.monora.uprotocol.client.android.activity.HomeActivity" />
</activity>

<activity
android:name="org.monora.uprotocol.client.android.activity.ManageDevicesActivity"
android:label="@string/text_manageDevices"
android:parentActivityName="org.monora.uprotocol.client.android.activity.HomeActivity"
tools:targetApi="jelly_bean">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.monora.uprotocol.client.android.activity.HomeActivity" />
</activity>

<activity
android:name="org.monora.uprotocol.client.android.activity.PreferencesActivity"
android:label="@string/text_preferences"
android:parentActivityName="org.monora.uprotocol.client.android.activity.HomeActivity"
tools:targetApi="jelly_bean">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.monora.uprotocol.client.android.activity.HomeActivity" />
</activity>

<activity
android:name="org.monora.uprotocol.client.android.activity.TextEditorActivity"
android:label="@string/text_textEditor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ class HomeActivity : Activity(), NavigationView.OnNavigationItemSelectedListener
}

when (pendingMenuItemId) {
R.id.edit_profile -> navController.navigate(NavHomeDirections.actionToProfileEditorFragment())
R.id.manage_devices -> startActivity(Intent(this, ManageDevicesActivity::class.java))
R.id.edit_profile -> navController.navigate(NavHomeDirections.actionGlobalProfileEditorFragment())
R.id.manage_devices -> navController.navigate(NavHomeDirections.actionGlobalNavManageDevices())
R.id.about -> startActivity(Intent(this, AboutActivity::class.java))
R.id.preferences -> startActivity(Intent(this, PreferencesActivity::class.java))
R.id.preferences -> navController.navigate(NavHomeDirections.actionGlobalNavPreferences())
R.id.donate -> try {
startActivity(
Intent(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2021 Veli Tasalı
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.monora.uprotocol.client.android.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import dagger.hilt.android.AndroidEntryPoint
import org.monora.uprotocol.client.android.R
import org.monora.uprotocol.client.android.database.model.UClient
import org.monora.uprotocol.client.android.databinding.LayoutEmptyContentBinding
import org.monora.uprotocol.client.android.databinding.ListManageClientBinding
import org.monora.uprotocol.client.android.itemcallback.UClientItemCallback
import org.monora.uprotocol.client.android.viewmodel.ClientsViewModel
import org.monora.uprotocol.client.android.viewmodel.EmptyContentViewModel
import org.monora.uprotocol.client.android.viewmodel.content.ClientContentViewModel

@AndroidEntryPoint
class ManageDevicesFragment : Fragment(R.layout.layout_manage_devices) {
private val viewModel: ClientsViewModel by viewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val recyclerView = view.findViewById<RecyclerView>(R.id.recyclerView)
val emptyView = LayoutEmptyContentBinding.bind(view.findViewById(R.id.emptyView))
val adapter = Adapter {
findNavController().navigate(
ManageDevicesFragmentDirections.actionManageDevicesFragment2ToClientDetailsFragment3(it)
)
}
val emptyContentViewModel = EmptyContentViewModel()

emptyView.viewModel = emptyContentViewModel
emptyView.emptyText.setText(R.string.text_listEmptyMusic)
emptyView.emptyImage.setImageResource(R.drawable.ic_music_note_white_24dp)
emptyView.executePendingBindings()
adapter.setHasStableIds(true)
recyclerView.adapter = adapter

viewModel.clients.observe(viewLifecycleOwner) {
adapter.submitList(it)
emptyContentViewModel.with(recyclerView, it.isNotEmpty())
}
}

class ClientViewHolder(
val binding: ListManageClientBinding,
val clickListener: (UClient) -> Unit,
) : RecyclerView.ViewHolder(binding.root) {
fun bind(client: UClient) {
binding.viewModel = ClientContentViewModel(client)
binding.clickListener = View.OnClickListener { clickListener(client) }
binding.detailsClickListener = View.OnClickListener { clickListener(client) }
binding.executePendingBindings()
}
}

class Adapter(
private val clickListener: (UClient) -> Unit,
) : ListAdapter<UClient, ClientViewHolder>(UClientItemCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClientViewHolder {
return ClientViewHolder(
ListManageClientBinding.inflate(LayoutInflater.from(parent.context), parent, false),
clickListener
)
}

override fun onBindViewHolder(holder: ClientViewHolder, position: Int) {
holder.bind(getItem(position))
}

override fun getItemId(position: Int): Long {
return getItem(position).uid.hashCode().toLong()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,63 @@
*/
package org.monora.uprotocol.client.android.fragment

import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import org.monora.uprotocol.client.android.R
import org.monora.uprotocol.client.android.activity.IntroductionPrefsFragment

class PreferencesFragment : PreferenceFragmentCompat() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences_main_app)
addPreferencesFromResource(R.xml.preferences_main_notification)
IntroductionPrefsFragment.loadThemeOptionsTo(requireContext(), findPreference("theme"))
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.preferences_options, menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.actions_preference_main_reset_to_defaults -> findNavController().navigate(
PreferencesFragmentDirections.actionPreferencesFragment2ToResetPreferencesFragment()
)
else -> return super.onOptionsItemSelected(item)
}
return true
}
}

class ResetPreferencesFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(requireActivity())
.setTitle(R.string.ques_resetToDefault)
.setMessage(R.string.text_resetPreferencesToDefaultSummary)
.setNegativeButton(R.string.butn_cancel, null)
.setPositiveButton(R.string.butn_proceed) { _: DialogInterface?, _: Int ->
PreferenceManager.getDefaultSharedPreferences(context).edit {
clear()
}
PreferenceManager.setDefaultValues(context, R.xml.preferences_defaults_main, true)

activity?.finish()
}
.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import dagger.hilt.android.AndroidEntryPoint
import org.monora.uprotocol.client.android.R
import org.monora.uprotocol.client.android.database.model.UClient
import org.monora.uprotocol.client.android.databinding.LayoutEmptyContentBinding
import org.monora.uprotocol.client.android.databinding.ListClientBinding
import org.monora.uprotocol.client.android.databinding.ListPickClientBinding
import org.monora.uprotocol.client.android.itemcallback.UClientItemCallback
import org.monora.uprotocol.client.android.viewholder.ClientViewHolder
import org.monora.uprotocol.client.android.viewmodel.ClientsViewModel
import org.monora.uprotocol.client.android.viewmodel.EmptyContentViewModel
import org.monora.uprotocol.client.android.viewmodel.content.ClientContentViewModel
Expand Down Expand Up @@ -70,12 +69,26 @@ class PickClientFragment : Fragment(R.layout.layout_clients) {
}
}

class ClientViewHolder(
val binding: ListPickClientBinding,
val clickListener: (UClient, ClientContentViewModel.ClickType) -> Unit,
) : RecyclerView.ViewHolder(binding.root) {
fun bind(client: UClient) {
binding.viewModel = ClientContentViewModel(client)
binding.clickListener =
View.OnClickListener { clickListener(client, ClientContentViewModel.ClickType.Default) }
binding.detailsClickListener =
View.OnClickListener { clickListener(client, ClientContentViewModel.ClickType.Details) }
binding.executePendingBindings()
}
}

class Adapter(
private val clickListener: (UClient, ClientContentViewModel.ClickType) -> Unit,
) : ListAdapter<UClient, ClientViewHolder>(UClientItemCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClientViewHolder {
return ClientViewHolder(
ListClientBinding.inflate(LayoutInflater.from(parent.context), parent, false),
ListPickClientBinding.inflate(LayoutInflater.from(parent.context), parent, false),
clickListener
)
}
Expand All @@ -88,4 +101,4 @@ class PickClientFragment : Fragment(R.layout.layout_clients) {
return getItem(position).uid.hashCode().toLong()
}
}
}
}

This file was deleted.

Loading

0 comments on commit e119d73

Please sign in to comment.