Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #209 from fieldsight/176-project-select-deselect
Browse files Browse the repository at this point in the history
[#176]-project-select-deselection done
  • Loading branch information
konishon authored Jun 6, 2019
2 parents e44278d + 8ea188b commit 0803381
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bcss.collect.naxa.common.FieldSightUserSession;
import org.bcss.collect.naxa.common.InternetUtils;
import org.bcss.collect.naxa.login.model.Project;
import org.bcss.collect.naxa.network.NetworkUtils;
import org.bcss.collect.naxa.notificationslist.NotificationListActivity;
import org.bcss.collect.naxa.project.ProjectListActivity;
import org.bcss.collect.naxa.project.data.ProjectRepository;
Expand Down Expand Up @@ -155,15 +156,19 @@ public void onChanged() {
@Override
protected void onResume() {
super.onResume();
if(tv_sync_project.getVisibility() == View.VISIBLE) {
if(!adapter.anyProjectSelectedForSync()) {
tv_sync_project.setVisibility(View.GONE);
}
}

@OnClick(R.id.cv_resync)
void resyncProject() {
getDataFromServer();
manageNodata(true);
if(NetworkUtils.isNetworkConnected()) {
getDataFromServer();
manageNodata(true);
} else {
Toast.makeText(getApplicationContext(), getString(R.string.no_internet_body), Toast.LENGTH_SHORT).show();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public void notifyProjectisSynced(List<ProjectNameTuple> projecttuple) {
notifyDataSetChanged();
}

public boolean anyProjectSelectedForSync() {
boolean found = false;
for(Project project: this.projectList) {
if(project.isChecked()) {
found = true;
break;
}
}
return found;
}
@Override
public void onBindViewHolder(@NonNull ProjectViewHolder projectViewHolder, int i) {
projectViewHolder.bindView(projectList.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void bindView(Project project) {
sub_text.setText(String.format("A project by %s", project.getOrganizationName()));
tv_synced_date.setText(project.getStatusMessage());
chkbx_sync.setChecked(project.isChecked());
// chkbx_sync.setVisibility(project.isChecked() && !project.isSynced() ? View.VISIBLE : View.GONE);
chkbx_sync.setVisibility(!project.isSynced() ? View.VISIBLE : View.GONE);
imageView.setImageResource(project.isSynced() ? R.drawable.ic_action_check : android.R.drawable.stat_sys_download_done);
Timber.i("project image = %s", project.getUrl());
Glide.with(itemView.getContext()).load(project.getUrl()).apply(RequestOptions.circleCropTransform()).into(iv_thumbnail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.bcss.collect.android.R;
import org.bcss.collect.android.application.Collect;
Expand All @@ -26,6 +27,7 @@
import org.bcss.collect.naxa.common.InternetUtils;
import org.bcss.collect.naxa.common.SharedPreferenceUtils;
import org.bcss.collect.naxa.login.model.Project;
import org.bcss.collect.naxa.network.NetworkUtils;
import org.bcss.collect.naxa.site.db.SiteLocalSource;
import org.bcss.collect.naxa.sync.ContentDownloadAdapter;
import org.bcss.collect.naxa.sync.DownloadViewModel;
Expand Down Expand Up @@ -103,15 +105,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
recyclerView.setAdapter(adapterv3);

findViewById(R.id.download_button).setOnClickListener(v -> {
ToastUtils.showShortToast("Download starts");
Intent syncIntent = new Intent(getApplicationContext(), SyncServiceV3.class);
syncIntent.putParcelableArrayListExtra("projects", projectList);
syncIntent.putExtra("selection", syncableMap);
startService(syncIntent);

Collect.selectedProjectList = projectList;
Collect.syncableMap = syncableMap;
enableDisableAdapter(true);
if (NetworkUtils.isNetworkConnected()) {
ToastUtils.showShortToast("Download starts");
Intent syncIntent = new Intent(getApplicationContext(), SyncServiceV3.class);
syncIntent.putParcelableArrayListExtra("projects", projectList);
syncIntent.putExtra("selection", syncableMap);
startService(syncIntent);

Collect.selectedProjectList = projectList;
Collect.syncableMap = syncableMap;
enableDisableAdapter(true);
} else {
Toast.makeText(this, getString(R.string.no_internet_body), Toast.LENGTH_SHORT).show();
}
});

syncObserver = syncStats -> {
Expand Down Expand Up @@ -167,12 +173,11 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.sync_menu,menu);
getMenuInflater().inflate(R.menu.sync_menu, menu);
return super.onCreateOptionsMenu(menu);
}



@Override
public void onRequestInterrupt(int pos, Project project) {
DialogFactory.createActionDialog(this, getString(R.string.app_name), "Are you sure you want to remove " + project.getName() + "from download queue ?")
Expand Down

0 comments on commit 0803381

Please sign in to comment.