This repository has been archived by the owner on Oct 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Implement 'Manage Devices' & improve nav.
Manage Devices & Preferences are now destinations in 'nav_home'
- Loading branch information
1 parent
b4f066e
commit e119d73
Showing
16 changed files
with
402 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
app/src/main/java/org/monora/uprotocol/client/android/activity/ManageDevicesActivity.kt
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
app/src/main/java/org/monora/uprotocol/client/android/activity/PreferencesActivity.kt
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
app/src/main/java/org/monora/uprotocol/client/android/fragment/ManageDevicesFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
app/src/main/java/org/monora/uprotocol/client/android/viewholder/ClientViewHolder.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.