Skip to content

Commit

Permalink
solve bug 0000392
Browse files Browse the repository at this point in the history
  • Loading branch information
domjos1994 committed Oct 29, 2019
1 parent 8aec8af commit 89d0ab8
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package de.domjos.unitrackermobile.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.LinkedList;
import java.util.List;

import de.domjos.unitrackerlibrary.model.objects.DescriptionObject;

public class SuggestionAdapter extends ArrayAdapter<DescriptionObject> {
private Context context;
private List<DescriptionObject> values;

public SuggestionAdapter(@NonNull Context context, List<DescriptionObject> values) {
super(context, android.R.layout.simple_list_item_1);
this.context = context;
this.values = values;
}

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View view = convertView;
try {
if(convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
}
DescriptionObject descriptionObject = this.getItem(position);
if(descriptionObject != null) {
TextView name = view.findViewById(android.R.id.text1);
name.setText(descriptionObject.getDescription());
}
} catch (Exception e) {
e.printStackTrace();
}
return view;
}

@Override
public Filter getFilter() {
return nameFilter;
}


private Filter nameFilter = new Filter() {
@Override
public CharSequence convertResultToString(Object resultValue) {
return ((DescriptionObject) resultValue).getTitle();
}

@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<DescriptionObject> descriptionObjects = new LinkedList<>();
for(int i = 0; i<=SuggestionAdapter.this.values.size()-1; i++) {
DescriptionObject descriptionObject = SuggestionAdapter.this.values.get(i);
if(descriptionObject!=null) {
if(constraint != null && descriptionObject.getTitle()!=null) {
if(descriptionObject.getTitle().contains(constraint)) {
descriptionObjects.add(descriptionObject);
}
}
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = descriptionObjects;
filterResults.count = descriptionObjects.size();
return filterResults;
}

@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
List<DescriptionObject> filterList = (LinkedList) results.values;
if (results != null && results.count > 0) {
clear();
for (DescriptionObject descriptionObject : filterList) {
add(descriptionObject);
notifyDataSetChanged();
}
}
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.domjos.unitrackermobile.custom;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.widget.MultiAutoCompleteTextView;

public class SpecialTokenizer implements MultiAutoCompleteTextView.Tokenizer {
@Override
public int findTokenStart(CharSequence charSequence, int i) {
while(i > 0) {
if(charSequence.charAt(i - 1)=='#' || charSequence.charAt(i - 1)=='@') {
return i-1;
}
i--;
}
return 0;
}

@Override
public int findTokenEnd(CharSequence charSequence, int i) {
while(i > 0) {
if(charSequence.charAt(i - 1)==' ') {
return i;
}
i--;
}
return 0;
}

@Override
public CharSequence terminateToken(CharSequence charSequence) {
int i = charSequence.length();

while (i > 0 && charSequence.charAt(i - 1) == '#' || charSequence.charAt(i - 1) == '@') {
i--;
}

if (i > 0 && charSequence.charAt(i - 1) == ' ') {
return charSequence;
} else {
if (charSequence instanceof Spanned) {
SpannableString sp = new SpannableString(charSequence + "\n");
TextUtils.copySpansFrom((Spanned) charSequence, 0, charSequence.length(), Object.class, sp, 0);
return sp;
} else {
return charSequence + " ";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,39 @@

package de.domjos.unitrackermobile.fragments;

import android.accounts.Account;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.MultiAutoCompleteTextView;
import android.widget.TableRow;

import androidx.annotation.NonNull;

import java.util.LinkedList;
import java.util.List;

import de.domjos.unitrackerlibrary.interfaces.IBugService;
import de.domjos.unitrackerlibrary.model.issues.Issue;
import de.domjos.unitrackerlibrary.model.issues.User;
import de.domjos.unitrackerlibrary.model.objects.DescriptionObject;
import de.domjos.unitrackerlibrary.services.engine.Authentication;
import de.domjos.unitrackerlibrary.tasks.IssueTask;
import de.domjos.unitrackerlibrary.tasks.UserTask;
import de.domjos.unitrackermobile.R;
import de.domjos.unitrackermobile.activities.MainActivity;
import de.domjos.unitrackermobile.adapter.SuggestionAdapter;
import de.domjos.unitrackermobile.custom.SpecialTokenizer;
import de.domjos.unitrackermobile.helper.Helper;
import de.domjos.unitrackermobile.helper.Validator;

/**
* A placeholder fragment containing a simple view.
*/
public final class IssueDescriptionsFragment extends AbstractFragment {
private EditText txtIssueDescriptionsDescription, txtIssueDescriptionsSteps, txtIssueDescriptionsAdditional;
private MultiAutoCompleteTextView txtIssueDescriptionsDescription, txtIssueDescriptionsSteps, txtIssueDescriptionsAdditional;
private TableRow rowIssueDescriptionsSteps, rowIssueDescriptionsAdditional;

private View root;
Expand All @@ -61,13 +73,61 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
this.txtIssueDescriptionsSteps = this.root.findViewById(R.id.txtIssueDescriptionsSteps);
this.txtIssueDescriptionsAdditional = this.root.findViewById(R.id.txtIssueDescriptionsAdditional);

if(this.getContext()!=null) {
List<User> users = new LinkedList<>();
List<Issue> issues = new LinkedList<>();
try {
IBugService bugService = Helper.getCurrentBugService(this.getActivity());
Object pid = MainActivity.GLOBALS.getSettings(this.getActivity()).getCurrentProjectId();
boolean show = MainActivity.GLOBALS.getSettings(this.getActivity()).showNotifications();

UserTask userTask = new UserTask(this.getActivity(), bugService, pid, false, show, R.drawable.ic_person_black_24dp);
users = userTask.execute(0).get();

IssueTask issueTask = new IssueTask(this.getActivity(), bugService, pid, false, false, show, R.drawable.ic_bug_report_black_24dp);
issues = issueTask.execute(0).get();
} catch (Exception ignored) {}

SuggestionAdapter descriptionAdapter = fillAdapter(users, issues, this.getActivity());
this.txtIssueDescriptionsDescription.setAdapter(descriptionAdapter);
this.txtIssueDescriptionsDescription.setTokenizer(new SpecialTokenizer());
descriptionAdapter.notifyDataSetChanged();

SuggestionAdapter stepsAdapter = fillAdapter(users, issues, this.getActivity());
this.txtIssueDescriptionsDescription.setAdapter(stepsAdapter);
this.txtIssueDescriptionsDescription.setTokenizer(new SpecialTokenizer());
stepsAdapter.notifyDataSetChanged();

SuggestionAdapter additionalAdapter = fillAdapter(users, issues, this.getActivity());
this.txtIssueDescriptionsDescription.setAdapter(additionalAdapter);
this.txtIssueDescriptionsDescription.setTokenizer(new SpecialTokenizer());
additionalAdapter.notifyDataSetChanged();
}

this.updateUITrackerSpecific();
this.initData();
this.manageControls(this.editMode);
this.initValidator();
return this.root;
}

static SuggestionAdapter fillAdapter(List<User> users, List<Issue> issues, Activity activity) {
List<DescriptionObject> descriptionObjects = new LinkedList<>();
for(User user : users) {
DescriptionObject descriptionObject = new DescriptionObject();
descriptionObject.setTitle("@" + user.getTitle());
descriptionObject.setDescription(user.getRealName());
descriptionObjects.add(descriptionObject);
}
for(Issue issue : issues) {
DescriptionObject descriptionObject = new DescriptionObject();
descriptionObject.setTitle("#" + issue.getId());
descriptionObject.setDescription(issue.getTitle());
descriptionObjects.add(descriptionObject);
}
return new SuggestionAdapter(activity, descriptionObjects);
}

@Override
public void setObject(DescriptionObject descriptionObject) {
this.issue = (Issue) descriptionObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.MultiAutoCompleteTextView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.LinkedList;
import java.util.List;

import de.domjos.unitrackerlibrary.interfaces.IBugService;
import de.domjos.unitrackerlibrary.model.ListObject;
import de.domjos.unitrackerlibrary.model.issues.Issue;
import de.domjos.unitrackerlibrary.model.issues.Note;
import de.domjos.unitrackerlibrary.model.issues.User;
import de.domjos.unitrackerlibrary.model.objects.DescriptionObject;
import de.domjos.unitrackerlibrary.services.engine.Authentication;
import de.domjos.unitrackerlibrary.tasks.IssueTask;
import de.domjos.unitrackerlibrary.tasks.UserTask;
import de.domjos.unitrackermobile.R;
import de.domjos.unitrackermobile.activities.MainActivity;
import de.domjos.unitrackermobile.adapter.SuggestionAdapter;
import de.domjos.unitrackermobile.custom.SpecialTokenizer;
import de.domjos.unitrackermobile.custom.swiperefreshlist.SwipeRefreshDeleteList;
import de.domjos.unitrackermobile.helper.ArrayHelper;
import de.domjos.unitrackermobile.helper.DateConverter;
Expand All @@ -49,7 +58,7 @@
public final class IssueNotesFragment extends AbstractFragment {
private SwipeRefreshDeleteList lvIssueNotes;
private ImageButton cmdIssueNotesAdd, cmdIssueNotesEdit, cmdIssueNotesDelete, cmdIssueNotesCancel, cmdIssueNotesSave;
private EditText txtIssueNotesText;
private MultiAutoCompleteTextView txtIssueNotesText;
private TextView txtIssueNotesSubmitDate, txtIssueNotesLastUpdated;
private Spinner spIssueNotesView;
private IBugService bugService;
Expand Down Expand Up @@ -83,6 +92,26 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
this.txtIssueNotesLastUpdated = this.root.findViewById(R.id.txtIssueNotesLastUpdated);
this.spIssueNotesView = this.root.findViewById(R.id.spIssueNotesView);

if(this.getContext()!=null) {
List<User> users = new LinkedList<>();
List<Issue> issues = new LinkedList<>();
try {
IBugService bugService = Helper.getCurrentBugService(this.getActivity());
Object pid = MainActivity.GLOBALS.getSettings(this.getActivity()).getCurrentProjectId();
boolean show = MainActivity.GLOBALS.getSettings(this.getActivity()).showNotifications();

UserTask userTask = new UserTask(this.getActivity(), bugService, pid, false, show, R.drawable.ic_person_black_24dp);
users = userTask.execute(0).get();

IssueTask issueTask = new IssueTask(this.getActivity(), bugService, pid, false, false, show, R.drawable.ic_bug_report_black_24dp);
issues = issueTask.execute(0).get();
} catch (Exception ignored) {}

SuggestionAdapter descriptionAdapter = IssueDescriptionsFragment.fillAdapter(users, issues, this.getActivity());
this.txtIssueNotesText.setAdapter(descriptionAdapter);
this.txtIssueNotesText.setTokenizer(new SpecialTokenizer());
descriptionAdapter.notifyDataSetChanged();
}

this.lvIssueNotes.click(new SwipeRefreshDeleteList.ClickListener() {
@Override
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/issue_fragment_descriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<TableRow>

<EditText
<MultiAutoCompleteTextView
android:id="@+id/txtIssueDescriptionsDescription"
android:hint="@string/general_description"
android:inputType="textMultiLine"
Expand All @@ -39,7 +39,7 @@

<TableRow android:id="@+id/rowDescriptionsSteps">

<EditText
<MultiAutoCompleteTextView
android:id="@+id/txtIssueDescriptionsSteps"
android:hint="@string/issues_descriptions_steps"
android:inputType="textMultiLine"
Expand All @@ -50,7 +50,7 @@

<TableRow android:id="@+id/rowDescriptionsAdditional">

<EditText
<MultiAutoCompleteTextView
android:id="@+id/txtIssueDescriptionsAdditional"
android:hint="@string/issues_descriptions_additional"
android:inputType="textMultiLine"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/issue_fragment_notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

<TableRow>

<EditText
<MultiAutoCompleteTextView
android:id="@+id/txtIssueNotesContent"
android:hint="@string/general_description"
android:inputType="textMultiLine"
Expand Down

0 comments on commit 89d0ab8

Please sign in to comment.