Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2way sync: Better view handling #13494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,79 @@
package com.owncloud.android.ui.activity

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.core.view.MenuProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.nextcloud.client.di.Injectable
import com.owncloud.android.R
import com.owncloud.android.databinding.InternalTwoWaySyncLayoutBinding
import com.owncloud.android.ui.adapter.InternalTwoWaySyncAdapter
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject

class InternalTwoWaySyncActivity : BaseActivity(), Injectable {
class InternalTwoWaySyncActivity : DrawerActivity(), Injectable {
lateinit var binding: InternalTwoWaySyncLayoutBinding

@Inject
lateinit var viewThemeUtils: ViewThemeUtils

override fun onCreate(savedInstanceState: Bundle?) {
Copy link
Collaborator

@alperozturk96 alperozturk96 Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @SuppressLint("NotifyDataSetChanged") since code updates InternalTwoWaySyncAdapter items in onCreate

super.onCreate(savedInstanceState)

binding = InternalTwoWaySyncLayoutBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.list.apply {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit the binding prefix for emptyList.
Instead of apply, use run when there’s no need to return a modified instance at the end of the block. Use apply only when assigning to a variable.

binding.list.run {
            setEmptyView(binding.emptyList.emptyListView)

            binding.emptyList.run {
                emptyListViewHeadline.run {
                    visibility = View.VISIBLE
                    setText(R.string.internal_two_way_sync_list_empty_headline)
                }
                emptyListViewText.run {
                    visibility = View.VISIBLE
                    setText(R.string.internal_two_way_sync_text)
                }
                emptyListIcon.run {
                    visibility = View.VISIBLE
                    setImageDrawable(
                        viewThemeUtils.platform.tintDrawable(
                            context,
                            R.drawable.ic_sync,
                            ColorRole.PRIMARY
                        )
                    )
                }
            }

            adapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), context).apply {
                notifyDataSetChanged()
            }
            layoutManager = LinearLayoutManager(context)
        }

Alternatively you can omit second binding as well.


binding.run {
            list.run {
                setEmptyView(binding.emptyList.emptyListView)

                emptyList.run {
                    emptyListViewHeadline.run {
                        visibility = View.VISIBLE
                        setText(R.string.internal_two_way_sync_list_empty_headline)
                    }
                    emptyListViewText.run {
                        visibility = View.VISIBLE
                        setText(R.string.internal_two_way_sync_text)
                    }
                    emptyListIcon.run {
                        visibility = View.VISIBLE
                        setImageDrawable(
                            viewThemeUtils.platform.tintDrawable(
                                context,
                                R.drawable.ic_sync,
                                ColorRole.PRIMARY
                            )
                        )
                    }
                }

                adapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), context).apply {
                    notifyDataSetChanged()
                }
                layoutManager = LinearLayoutManager(context)
            }
        }

adapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), context)
setEmptyView(binding.emptyList.emptyListView)

binding.emptyList.emptyListViewHeadline.apply {
visibility = View.VISIBLE
setText(R.string.internal_two_way_sync_list_empty_headline)
}
binding.emptyList.emptyListViewText.apply {
visibility = View.VISIBLE
setText(R.string.internal_two_way_sync_text)
}
binding.emptyList.emptyListIcon.apply {
visibility = View.VISIBLE
setImageDrawable(
viewThemeUtils.platform.tintPrimaryDrawable(
context,
R.drawable.ic_sync
)
)
}

adapter = InternalTwoWaySyncAdapter(fileDataStorageManager, user.get(), context).apply {
notifyDataSetChanged()
}
layoutManager = LinearLayoutManager(context)
}

setupToolbar()
updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_synced_folders))
if (supportActionBar != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need null check, you can use this. supportActionBar?.setDisplayHomeAsUpEnabled(true)

supportActionBar!!.setDisplayHomeAsUpEnabled(true)
}

addMenuProvider(
object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
android.R.id.home -> {
onBackPressed()
true
}
else -> false
}
}
}
)
}
}
32 changes: 23 additions & 9 deletions app/src/main/res/layout/internal_two_way_sync_layout.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
~ SPDX-License-Identifier: AGPL-3.0-or-later
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="@layout/toolbar_standard" />

<com.owncloud.android.ui.EmptyRecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />

<include
android:id="@+id/empty_list"
layout="@layout/empty_list" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1236,4 +1236,6 @@
<string name="file_name_validator_error_forbidden_file_extensions">.%s is a forbidden file extension</string>
<string name="file_name_validator_error_ends_with_space_period">Name ends with a space or a period</string>
<string name="sync">Sync</string>
<string name="internal_two_way_sync_list_empty_headline">No two way sync folder yet</string>
<string name="internal_two_way_sync_text">To setup a two way sync folder, please enable it in details of desired folder.</string>
</resources>
Loading