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

Rework the app bar #6320

Merged
merged 28 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eee2f89
Reworked the main menu layout
grzesiek2010 Aug 8, 2024
5832fb8
Removed shadow from the app bar layout
grzesiek2010 Aug 9, 2024
e7b5143
Reworked the blank form list
grzesiek2010 Aug 9, 2024
c4ca523
Reworked the list of drafts
grzesiek2010 Aug 12, 2024
a27cf30
Reworked the list of settings
grzesiek2010 Aug 12, 2024
f93d530
Reworked the about screen
grzesiek2010 Aug 12, 2024
14878c1
Reworked the list of errors
grzesiek2010 Aug 12, 2024
bf28d23
Reworked the list of entities
grzesiek2010 Aug 12, 2024
ffb0366
Reworked the list of forms to download
grzesiek2010 Aug 12, 2024
8424452
Reworked the list of forms to upload
grzesiek2010 Aug 12, 2024
80ed9ba
Reworked the hierarych view
grzesiek2010 Aug 12, 2024
01e7b1e
Reworked the list of forms to delete
grzesiek2010 Aug 12, 2024
aed24bf
Reworked the offline map layers importer
grzesiek2010 Aug 13, 2024
6b12107
Reworked the form entry
grzesiek2010 Aug 13, 2024
a1c261f
Reworked the user identity screen
grzesiek2010 Aug 13, 2024
dcaa543
Reworked the reason for changes screen
grzesiek2010 Aug 13, 2024
095d23f
Reworked the select minimal dialog layout
grzesiek2010 Aug 13, 2024
fee5719
Reworked the manual project creator screen
grzesiek2010 Aug 13, 2024
1430336
Reworked the qr code project creator screen
grzesiek2010 Aug 13, 2024
671bcc7
Fixed imports
grzesiek2010 Aug 13, 2024
d07a960
Use the same app bar layout across the app
grzesiek2010 Aug 13, 2024
928d316
Reworked the webview layout
grzesiek2010 Aug 13, 2024
875456a
Removed unused resources
grzesiek2010 Aug 13, 2024
20786e8
Fixed using ObviousProgressBar
grzesiek2010 Aug 14, 2024
ba46fe6
Simplified ObviousProgressBar#hide()
grzesiek2010 Aug 14, 2024
26cbd4b
Converted ObviousProgressBar to kotlin
grzesiek2010 Aug 14, 2024
b0385ff
Added missing content description used in tests
grzesiek2010 Aug 14, 2024
e2f0fa6
Removed unused id
grzesiek2010 Aug 14, 2024
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
@@ -0,0 +1,47 @@
package org.odk.collect.androidshared.ui

import android.content.Context
import android.os.Handler
import android.util.AttributeSet
import android.widget.ProgressBar

/**
* A progress bar that shows for a minimum amount fo time so it's obvious to the user that
* something has happened.
*/
class ObviousProgressBar(context: Context, attrs: AttributeSet?) : ProgressBar(context, attrs) {
private val handler = Handler()
private var shownAt: Long? = null

fun show() {
handler.removeCallbacksAndMessages(null)
shownAt = System.currentTimeMillis()
super.setVisibility(VISIBLE)
}

fun hide() {
if (shownAt != null) {
val timeShown = System.currentTimeMillis() - shownAt!!

if (timeShown < MINIMUM_SHOW_TIME) {
val delay = MINIMUM_SHOW_TIME - timeShown

handler.removeCallbacksAndMessages(null)
handler.postDelayed({ this.makeGone() }, delay)
} else {
makeGone()
}
} else {
makeGone()
}
}

private fun makeGone() {
super.setVisibility(GONE)
shownAt = null
}

companion object {
private const val MINIMUM_SHOW_TIME = 750
}
}
10 changes: 9 additions & 1 deletion androidshared/src/main/res/layout/app_bar_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@
android:layout_height="?attr/actionBarSize"
tools:title="Title" />

<include layout="@layout/app_bar_shadow"/>
<org.odk.collect.androidshared.ui.ObviousProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appBarLayout"
android:layout_marginTop="-7dp"
android:indeterminate="true"
android:visibility="gone" />
</com.google.android.material.appbar.AppBarLayout>
35 changes: 0 additions & 35 deletions androidshared/src/main/res/layout/app_bar_shadow.xml

This file was deleted.

18 changes: 0 additions & 18 deletions androidshared/src/main/res/values/toolbars.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AboutActivity : LocalizedActivity(), AboutItemClickListener {
}

private fun initToolbar() {
val toolbar = findViewById<Toolbar>(R.id.toolbar)
val toolbar = findViewById<Toolbar>(org.odk.collect.androidshared.R.id.toolbar)
title = getString(org.odk.collect.strings.R.string.about_preferences)
setSupportActionBar(toolbar)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
Expand All @@ -39,6 +37,7 @@
import org.odk.collect.android.formlists.sorting.FormListSortingBottomSheetDialog;
import org.odk.collect.android.formlists.sorting.FormListSortingOption;
import org.odk.collect.android.injection.DaggerUtils;
import org.odk.collect.androidshared.ui.ObviousProgressBar;
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;
import org.odk.collect.settings.SettingsProvider;
import org.odk.collect.strings.localization.LocalizedActivity;
Expand All @@ -63,8 +62,7 @@ public abstract class AppListActivity extends LocalizedActivity {
protected List<FormListSortingOption> sortingOptions;
protected Integer selectedSortingOrder;
protected ListView listView;
protected LinearLayout llParent;
protected ProgressBar progressBar;
protected ObviousProgressBar progressBar;

private String filterText;
private String savedFilterText;
Expand Down Expand Up @@ -136,14 +134,13 @@ private void init() {
listView = findViewById(android.R.id.list);
listView.setOnItemClickListener((AdapterView.OnItemClickListener) this);
listView.setEmptyView(findViewById(android.R.id.empty));
progressBar = findViewById(R.id.progressBar);
llParent = findViewById(R.id.llParent);
progressBar = findViewById(org.odk.collect.androidshared.R.id.progressBar);

// Use the nicer-looking drawable with Material Design insets.
listView.setDivider(ContextCompat.getDrawable(this, org.odk.collect.androidshared.R.drawable.list_item_divider));
listView.setDividerHeight(1);

setSupportActionBar(findViewById(R.id.toolbar));
setSupportActionBar(findViewById(org.odk.collect.androidshared.R.id.toolbar));
}

@Override
Expand Down Expand Up @@ -302,10 +299,10 @@ protected void hideProgressBarAndAllow() {
}

private void hideProgressBar() {
progressBar.setVisibility(View.GONE);
progressBar.hide();
}

protected void showProgressBar() {
progressBar.setVisibility(View.VISIBLE);
progressBar.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ private void loadFromIntent(Intent intent) {


private void initToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(org.odk.collect.androidshared.R.id.toolbar);
setSupportActionBar(toolbar);
setTitle(getString(org.odk.collect.strings.R.string.loading_form));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) {

Toolbar toolbar = getToolbar();
toolbar.setTitle(viewModel.getFormName());
toolbar.setNavigationIcon(org.odk.collect.icons.R.drawable.ic_close);
toolbar.setNavigationContentDescription(org.odk.collect.strings.R.string.close);
toolbar.inflateMenu(R.menu.changes_reason_dialog);

EditText reasonField = view.findViewById(R.id.reason);
Expand Down Expand Up @@ -76,7 +78,7 @@ protected void onBackPressed() {

@Override
protected Toolbar getToolbar() {
return getView().findViewById(R.id.toolbar);
return getView().findViewById(org.odk.collect.androidshared.R.id.toolbar);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

getToolbar().setTitle(viewModel.getFormTitle());
Toolbar toolbar = getToolbar();
toolbar.setTitle(viewModel.getFormTitle());
toolbar.setNavigationIcon(org.odk.collect.icons.R.drawable.ic_close);
toolbar.setNavigationContentDescription(org.odk.collect.strings.R.string.close);

EditText identityField = view.findViewById(R.id.identity);
identityField.setText(viewModel.getUser());
Expand Down Expand Up @@ -85,7 +88,7 @@ protected void onBackPressed() {

@Override
protected Toolbar getToolbar() {
return getView().findViewById(R.id.toolbar);
return getView().findViewById(org.odk.collect.androidshared.R.id.toolbar);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void onCreate(Bundle savedInstanceState) {
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

EmptyListView emptyView = findViewById(android.R.id.empty);
Toolbar toolbar = findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(org.odk.collect.androidshared.R.id.toolbar);
setSupportActionBar(toolbar);

formEntryViewModel = new ViewModelProvider(this, viewModelFactory).get(FormEntryViewModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.ProgressBar
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -15,6 +14,7 @@ import org.odk.collect.android.formmanagement.FormFillingIntentFactory
import org.odk.collect.android.injection.DaggerUtils
import org.odk.collect.android.preferences.dialogs.ServerAuthDialogFragment
import org.odk.collect.androidshared.ui.DialogFragmentUtils
import org.odk.collect.androidshared.ui.ObviousProgressBar
import org.odk.collect.androidshared.ui.SnackbarUtils
import org.odk.collect.async.network.NetworkStateProvider
import org.odk.collect.lists.EmptyListView
Expand Down Expand Up @@ -50,7 +50,7 @@ class BlankFormListActivity : LocalizedActivity(), OnFormItemClickListener {
DaggerUtils.getComponent(this).inject(this)
setContentView(R.layout.activity_blank_form_list)
title = getString(org.odk.collect.strings.R.string.enter_data)
setSupportActionBar(findViewById(R.id.toolbar))
setSupportActionBar(findViewById(org.odk.collect.androidshared.R.id.toolbar))

val menuProvider = BlankFormListMenuProvider(this, viewModel, networkStateProvider)
addMenuProvider(menuProvider, this)
Expand Down Expand Up @@ -91,8 +91,11 @@ class BlankFormListActivity : LocalizedActivity(), OnFormItemClickListener {

private fun initObservers() {
viewModel.isLoading.observe(this) { isLoading ->
findViewById<ProgressBar>(R.id.progressBar).visibility =
if (isLoading) View.VISIBLE else View.GONE
if (isLoading) {
findViewById<ObviousProgressBar>(org.odk.collect.androidshared.R.id.progressBar).show()
} else {
findViewById<ObviousProgressBar>(org.odk.collect.androidshared.R.id.progressBar).hide()
}
}

viewModel.syncResult.observe(this) { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected void closeDialogAndSaveAnswers() {
@Nullable
@Override
protected Toolbar getToolbar() {
return getView().findViewById(R.id.toolbar);
return getView().findViewById(org.odk.collect.androidshared.R.id.toolbar);
}

private void initToolbar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
Expand Down Expand Up @@ -64,6 +63,7 @@
import org.odk.collect.android.preferences.screens.ProjectPreferencesActivity;
import org.odk.collect.android.projects.ProjectsDataService;
import org.odk.collect.androidshared.ui.MenuExtKt;
import org.odk.collect.androidshared.ui.ObviousProgressBar;
import org.odk.collect.androidshared.ui.ToastUtils;
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;
import org.odk.collect.async.network.NetworkStateProvider;
Expand Down Expand Up @@ -125,7 +125,7 @@ public class InstanceUploaderListActivity extends LocalizedActivity implements
private InstanceUploaderAdapter listAdapter;
private Integer selectedSortingOrder;
private List<FormListSortingOption> sortingOptions;
private ProgressBar progressBar;
private ObviousProgressBar progressBar;
private String filterText;

private MultiSelectViewModel<Object> multiSelectViewModel;
Expand Down Expand Up @@ -198,13 +198,13 @@ public void setContentView(View view) {
listView = findViewById(android.R.id.list);
listView.setOnItemClickListener((AdapterView.OnItemClickListener) this);
listView.setEmptyView(findViewById(android.R.id.empty));
progressBar = findViewById(R.id.progressBar);
progressBar = findViewById(org.odk.collect.androidshared.R.id.progressBar);

// Use the nicer-looking drawable with Material Design insets.
listView.setDivider(ContextCompat.getDrawable(this, org.odk.collect.androidshared.R.drawable.list_item_divider));
listView.setDividerHeight(1);

setSupportActionBar(findViewById(R.id.toolbar));
setSupportActionBar(findViewById(org.odk.collect.androidshared.R.id.toolbar));

init();
}
Expand Down Expand Up @@ -534,15 +534,15 @@ private void restoreSelectedSortingOrder() {
}

private void showProgressBar() {
progressBar.setVisibility(View.VISIBLE);
progressBar.show();
}

private void hideProgressBarAndAllow() {
hideProgressBar();
}

private void hideProgressBar() {
progressBar.setVisibility(View.GONE);
progressBar.hide();
}

private CharSequence getFilterText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class MainMenuFragment(
}

private fun initToolbar(binding: MainMenuBinding) {
val toolbar = binding.root.findViewById<Toolbar>(org.odk.collect.android.R.id.toolbar)
val toolbar = binding.root.findViewById<Toolbar>(org.odk.collect.androidshared.R.id.toolbar)
(requireActivity() as AppCompatActivity).setSupportActionBar(toolbar)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ class ManualProjectCreatorDialog :
}

override fun getToolbar(): Toolbar {
return binding.toolbar
return binding.toolbarLayout.toolbar
}

private fun setUpToolbar() {
toolbar.setTitle(org.odk.collect.strings.R.string.add_project)
toolbar.navigationIcon = null
}

private fun handleAddingNewProject() {
Expand Down
Loading