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

Removed redundant tab #333

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 @@ -3,7 +3,6 @@
import org.odk.share.views.ui.send.fragment.BlankFormsFragment;
import org.odk.share.views.ui.send.fragment.FilledFormsFragment;
import org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment;
import org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment;
import org.odk.share.views.ui.instance.fragment.SentInstancesFragment;
import org.odk.share.views.ui.instance.fragment.StatisticsFragment;
import org.odk.share.injection.config.scopes.PerActivity;
Expand All @@ -26,10 +25,6 @@ public abstract class FragmentBuilder {
@ContributesAndroidInjector
abstract ReceivedInstancesFragment provideReceivedInstancesFragment();

@PerActivity
@ContributesAndroidInjector
abstract ReviewedInstancesFragment provideReviewedInstancesFragment();

@PerActivity
@ContributesAndroidInjector
abstract BlankFormsFragment provideBlankFormsFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import timber.log.Timber;

import static org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment.MODE;
import static org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment.MODE;

@Singleton
public class SenderService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import static org.odk.share.tasks.DownloadJob.RESULT_DIVIDER;
import static org.odk.share.utilities.ApplicationConstants.SEND_BLANK_FORM_MODE;
import static org.odk.share.utilities.ApplicationConstants.SEND_FILL_FORM_MODE;
import static org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment.MODE;
import static org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment.MODE;

public class UploadJob extends Job {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static org.odk.share.utilities.ApplicationConstants.ASK_REVIEW_MODE;
import static org.odk.share.utilities.PermissionUtils.APP_SETTING_REQUEST_CODE;
import static org.odk.share.views.ui.instance.InstancesList.INSTANCE_IDS;
import static org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment.MODE;
import static org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment.MODE;
import static org.odk.share.views.ui.send.fragment.BlankFormsFragment.FORM_IDS;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static android.view.View.VISIBLE;
import static org.odk.share.utilities.ApplicationConstants.ASK_REVIEW_MODE;
import static org.odk.share.views.ui.instance.InstancesList.INSTANCE_IDS;
import static org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment.MODE;
import static org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment.MODE;
import static org.odk.share.views.ui.send.fragment.BlankFormsFragment.FORM_IDS;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.odk.share.R;
import org.odk.share.views.ui.common.ViewPagerAdapter;
import org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment;
import org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment;
import org.odk.share.views.ui.instance.fragment.SentInstancesFragment;
import org.odk.share.views.ui.instance.fragment.StatisticsFragment;
import org.odk.share.views.ui.common.injectable.InjectableActivity;
Expand All @@ -33,7 +32,6 @@ public class InstanceManagerTabs extends InjectableActivity implements TabLayout
{R.string.statistics, R.drawable.ic_stats, new StatisticsFragment()},
{R.string.sent, R.drawable.ic_upload, new SentInstancesFragment()},
{R.string.received, R.drawable.ic_download, new ReceivedInstancesFragment()},
{R.string.reviewed, R.drawable.ic_assignment, new ReviewedInstancesFragment()}
};

@BindView(R.id.toolbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import butterknife.ButterKnife;
import butterknife.OnClick;

import static org.odk.share.views.ui.instance.fragment.ReviewedInstancesFragment.MODE;
import static org.odk.share.views.ui.instance.fragment.ReceivedInstancesFragment.MODE;

public class InstancesList extends InstanceListActivity implements LoaderManager.LoaderCallbacks<Cursor> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.odk.share.R;
Expand Down Expand Up @@ -58,17 +59,15 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.bind(position, listener);
TransferInstance instance = items.get(position);
holder.title.setText(instance.getInstance().getDisplayName());
holder.checkBox.setVisibility(View.GONE);


if (showCheckBox) {
holder.checkBox.setVisibility(View.VISIBLE);
if (selectedInstances.contains(instance.getId())) {
holder.checkBox.setChecked(true);
holder.parent.setBackgroundResource(R.color.colorSelected);
} else {
holder.checkBox.setChecked(false);
holder.parent.setBackgroundResource(R.color.colorTabActive);
}
} else {
holder.checkBox.setVisibility(View.GONE);
}


Date date = new Date(instance.getLastStatusChangeDate());
SimpleDateFormat dateFormat = new SimpleDateFormat(context.getString(R.string.date_at_time),
Expand Down Expand Up @@ -114,6 +113,8 @@ static class ViewHolder extends RecyclerView.ViewHolder {
TextView subtitle;
@BindView(R.id.checkbox)
CheckBox checkBox;
@BindView(R.id.parent)
LinearLayout parent;

ViewHolder(View v) {
super(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.odk.collect.android.dao.InstancesDao;
import org.odk.collect.android.dto.Instance;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.share.R;
import org.odk.share.utilities.ApplicationConstants;
import org.odk.share.utilities.ArrayUtils;
import org.odk.share.utilities.DialogUtils;
import org.odk.share.views.ui.common.InstanceListFragment;
import org.odk.share.views.ui.review.ReviewFormActivity;
import org.odk.share.views.ui.instance.adapter.TransferInstanceAdapter;
Expand All @@ -30,9 +34,12 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static org.odk.share.views.ui.instance.InstancesList.INSTANCE_IDS;
import static org.odk.share.views.ui.main.MainActivity.FORM_DISPLAY_NAME;
import static org.odk.share.views.ui.main.MainActivity.FORM_ID;
import static org.odk.share.views.ui.main.MainActivity.FORM_VERSION;
Expand All @@ -46,13 +53,24 @@
public class ReceivedInstancesFragment extends InstanceListFragment implements OnItemClickListener {

private static final String RECEIVED_INSTANCE_LIST_SORTING_ORDER = "receivedInstanceListSortingOrder";
private static final String REVIEWED_INSTANCE_LIST_SORTING_ORDER = "reviewedInstanceListSortingOrder";
public static final String MODE = "mode";
public static final int MODE_REVIEW = 1;
public static final int MODE_RECEIVE = 2;


@BindView(R.id.recyclerview)
RecyclerView recyclerView;
@BindView(R.id.buttonholder)
LinearLayout buttonLayout;
@BindView(R.id.empty_view)
TextView emptyView;
@BindView(R.id.bToggle)
Button toggleButton;
@BindView(R.id.bAction)
Button sendButton;
@BindView(R.id.bToggleWide)
Button selectReviewedButton;

@Inject
InstancesDao instancesDao;
Expand All @@ -63,6 +81,8 @@ public class ReceivedInstancesFragment extends InstanceListFragment implements O
HashMap<Long, Instance> instanceMap;
TransferInstanceAdapter transferInstanceAdapter;
List<TransferInstance> transferInstanceList;
private int activityMode;
private String sortingOrder;

boolean showCheckBox = false;

Expand All @@ -76,11 +96,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
View view = inflater.inflate(R.layout.fragment_instances, container, false);
ButterKnife.bind(this, view);

activityMode = MODE_RECEIVE;
sortingOrder = RECEIVED_INSTANCE_LIST_SORTING_ORDER;

instanceMap = new HashMap<>();
transferInstanceList = new ArrayList<>();
selectedInstances = new LinkedHashSet<>();

buttonLayout.setVisibility(View.GONE);
selectReviewedButton.setVisibility(View.VISIBLE);

LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setOrientation(RecyclerView.VERTICAL);
Expand All @@ -91,14 +115,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

@Override
public void onResume() {
getInstanceFromDB();
getReceivedInstanceFromDB(activityMode);
setEmptyViewVisibility(getString(R.string.no_forms_received,
getActivity().getIntent().getStringExtra(FORM_DISPLAY_NAME)));
transferInstanceAdapter.notifyDataSetChanged();
super.onResume();
}

private void getInstanceFromDB() {

private void getReceivedInstanceFromDB(int mode) {
transferInstanceList.clear();
selectedInstances.clear();
String formVersion = getActivity().getIntent().getStringExtra(FORM_VERSION);
Expand Down Expand Up @@ -128,14 +153,25 @@ private void getInstanceFromDB() {

Cursor cursor = instancesDao.getInstancesCursor(null, selection, selectionArgs, getSortingOrder());
instanceMap = instancesDao.getMapFromCursor(cursor);
Cursor transferCursor = transferDao.getReceiveInstancesCursor();
Cursor transferCursor;
if (mode == MODE_RECEIVE) {
transferCursor = transferDao.getReceiveInstancesCursor();
} else if (mode == MODE_REVIEW) {
transferCursor = transferDao.getReviewedInstancesCursor();
} else {
transferCursor = transferDao.getReceiveInstancesCursor();
}
List<TransferInstance> transferInstances = transferDao.getInstancesFromCursor(transferCursor);
for (TransferInstance instance : transferInstances) {
if (instanceMap.containsKey(instance.getInstanceId())) {
instance.setInstance(instanceMap.get(instance.getInstanceId()));
transferInstanceList.add(instance);
}
}
if (transferInstanceList.isEmpty()){
buttonLayout.setVisibility(View.GONE);
selectReviewedButton.setVisibility(View.GONE);
}
}

private void setupAdapter() {
Expand All @@ -157,22 +193,101 @@ private void setEmptyViewVisibility(String text) {

@Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(getContext(), ReviewFormActivity.class);
intent.putExtra(INSTANCE_ID, transferInstanceList.get(position).getInstanceId());
intent.putExtra(TRANSFER_ID, transferInstanceList.get(position).getId());
startActivity(intent);

if (activityMode == MODE_RECEIVE) {
Intent intent = new Intent(getContext(), ReviewFormActivity.class);
intent.putExtra(INSTANCE_ID, transferInstanceList.get(position).getInstanceId());
intent.putExtra(TRANSFER_ID, transferInstanceList.get(position).getId());
startActivity(intent);
} else if (activityMode == MODE_REVIEW) {

TransferInstance transferInstance = transferInstanceList.get(position);
Long id = transferInstance.getId();

if (selectedInstances.contains(id)) {
selectedInstances.remove(id);

view.setBackgroundResource(R.color.colorTabActive);
} else {
selectedInstances.add(id);
view.setBackgroundResource(R.color.colorSelected);
}
toggleButtonLabel();
}
}

@Override
protected void updateAdapter() {
getInstanceFromDB();
getReceivedInstanceFromDB(activityMode);
setEmptyViewVisibility(getString(R.string.no_forms_received,
getActivity().getIntent().getStringExtra(FORM_DISPLAY_NAME)));
transferInstanceAdapter.notifyDataSetChanged();
}

@Override
protected String getSortingOrderKey() {
return RECEIVED_INSTANCE_LIST_SORTING_ORDER;
return sortingOrder;
}

private void toggleButtonLabel() {
toggleButton.setText(selectedInstances.size() == transferInstanceAdapter.getItemCount() ?
getString(R.string.clear_all) : getString(R.string.select_all));
sendButton.setEnabled(selectedInstances.size() > 0);
}


@OnClick(R.id.bToggleWide)
public void changeMode() {
activityMode = MODE_REVIEW;
sortingOrder = REVIEWED_INSTANCE_LIST_SORTING_ORDER;


selectReviewedButton.setVisibility(View.GONE);
buttonLayout.setVisibility(View.VISIBLE);
toggleButton.setText(getString(R.string.select_all));
sendButton.setText(getString(R.string.send_forms));


getReceivedInstanceFromDB(activityMode);
setEmptyViewVisibility(getString(R.string.no_forms_received,
getActivity().getIntent().getStringExtra(FORM_DISPLAY_NAME)));
transferInstanceAdapter.notifyDataSetChanged();

}

@OnClick(R.id.bToggle)
public void toggle() {
boolean newState = transferInstanceAdapter.getItemCount() > selectedInstances.size();

if (newState) {
for (TransferInstance instance : transferInstanceList) {
selectedInstances.add(instance.getId());
}
} else {
selectedInstances.clear();
}

transferInstanceAdapter.notifyDataSetChanged();
toggleButtonLabel();
}

@OnClick(R.id.bAction)
public void sendForms() {
List<Long> instanceIds = new ArrayList<>();
for (TransferInstance transferInstance : transferInstanceList) {
if (selectedInstances.contains(transferInstance.getId())) {
instanceIds.add(transferInstance.getInstanceId());
}
}

Intent intent = new Intent();
Long[] arr = instanceIds.toArray(new Long[instanceIds.size()]);
long[] a = ArrayUtils.toPrimitive(arr);
intent.putExtra(INSTANCE_IDS, a);
intent.putExtra(MODE, ApplicationConstants.SEND_REVIEW_MODE);

if (getContext() != null) {
DialogUtils.switchToDefaultSendingMethod(getContext(), intent);
}
}
}
Loading