Merge branch 'tutors-list-activity' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-02 17:00:23 +00:00 committed by Gogs
commit bf694594e4
38 changed files with 2263 additions and 888 deletions

View File

@ -56,5 +56,6 @@ dependencies {
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.annimon:stream:1.2.1'
}

View File

@ -37,12 +37,10 @@
android:label="@string/title_activity_login"
android:launchMode="singleTask"
android:noHistory="true" />
<activity
android:name=".activity.SettingsActivity"
android:label="@string/title_activity_settings" />
<activity
android:name=".activity.SharingActivity"
android:label="@string/title_activity_sharing" />
<service
android:name=".service.BackgroundLocalizationService"
@ -51,7 +49,6 @@
android:enabled="true"
/>
<!--<activity android:name=".activity.MapActivity" />-->
</application>
</manifest>

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
@ -15,46 +16,36 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.ActiveFragment;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import java.util.ArrayList;
public abstract class BaseActivity
extends AppCompatActivity
implements BottomNavigationView.OnNavigationItemSelectedListener {
protected static final int REQUEST_PERMISSIONS = 100;
public DrawerLayout drawerLayout;
protected BottomNavigationView navigationView;
protected NavigationView drawerNavigationView;
protected DrawerLayout sideDrawer;
protected Toolbar toolbar;
public DrawerLayout drawerLayout;
private ActionBarDrawerToggle actionBarDrawerToggle;
// 4 search
private ListView listView;
private ArrayList<String> stringArrayList;
private SharingFragment sharingFragment;
protected static final int REQUEST_PERMISSIONS = 100;
boolean boolean_permission;
protected boolean isTutor;
boolean boolean_permission;
private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment;
private Fragment userListFragment;
private ActiveFragment activeFragment = ActiveFragment.NONE;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -66,22 +57,22 @@ public abstract class BaseActivity
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
String itemName = (String)item.getTitle();
String itemName = (String) item.getTitle();
Intent launchIntent;
if(itemName.equals("Whitelist")){
if (itemName.equals("Whitelist")) {
/* launchIntent = new Intent(getApplicationContext(), WhitelistActivity.class);
startActivity(launchIntent);*/
}else if (itemName.equals("Blacklist")){
} else if (itemName.equals("Blacklist")) {
/* launchIntent = new Intent(getApplicationContext(), BlacklistActivity.class);
startActivity(launchIntent);*/
}else if (itemName.equals("Profile")){
} else if (itemName.equals("Profile")) {
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class);
startActivity(launchIntent);*/
}else if (itemName.equals("Settings")){
} else if (itemName.equals("Settings")) {
launchIntent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(launchIntent);
}else if (itemName.equals("Log out")){
} else if (itemName.equals("Log out")) {
PrefUtils.cleanUserLocalStorage(getApplicationContext());
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
@ -101,6 +92,8 @@ public abstract class BaseActivity
navigationView = findViewById(R.id.navigation);
navigationView.setOnNavigationItemSelectedListener(this);
sharingFragment = new SharingFragment();
userListFragment = new UsersListFragment();
isTutor = PrefUtils.getIsTutor(getApplicationContext());
if (!isTutor) {
@ -112,7 +105,7 @@ public abstract class BaseActivity
@Override
public void setContentView(int layoutResID) {
DrawerLayout fullView = (DrawerLayout) getLayoutInflater().inflate(R.layout.base_activity, null);
FrameLayout activityContainer = (FrameLayout) fullView.findViewById(R.id.activity_content);
FrameLayout activityContainer = fullView.findViewById(R.id.activity_content);
getLayoutInflater().inflate(layoutResID, activityContainer, true);
super.setContentView(fullView);
@ -120,14 +113,13 @@ public abstract class BaseActivity
}
private void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
private void setUpNav() {
drawerLayout = (DrawerLayout) findViewById(R.id.activity_container);
drawerLayout = findViewById(R.id.activity_container);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
@ -147,16 +139,13 @@ public abstract class BaseActivity
setUpNav();
actionBarDrawerToggle.syncState();
Log.e("erororr", "guewa!" + isTutor);
// if (isTutor && getContentViewId() == R.layout.activity_map) {
if (isTutor) {
Log.e("erororr", "taaaaaak!");
if (isTutor) {
fn_permission();
}
}
private void fn_permission() {
private void fn_permission() {
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
if ((ActivityCompat.shouldShowRequestPermissionRationale(BaseActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
@ -191,32 +180,40 @@ public abstract class BaseActivity
}
@Override
public boolean onCreateOptionsMenu( Menu menu) {
getMenuInflater().inflate( R.menu.menu_main, menu);
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem myActionMenuItem = menu.findItem( R.id.action_search);
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) myActionMenuItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
public boolean onQueryTextSubmit(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
executeUserListSearch(input);
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
//adapter.filter("");
//listView.clearTextFilter();
} else {
//adapter.filter(newText);
public boolean onQueryTextChange(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
executeUserListSearch(input);
}
return true;
}
});
return true;
}
private void executeUserListSearch(String input) {
((UsersListFragment) userListFragment).searchUser(input);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
@ -249,46 +246,53 @@ public abstract class BaseActivity
@Override
public void onPause() {
super.onPause();
overridePendingTransition(0,0);
}
private void setFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.activity_content, fragment);
fragmentTransaction.commit();
overridePendingTransition(0, 0);
}
private void removeFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.remove(fragment);
fragmentTransaction.hide(fragment);
fragmentTransaction.commit();
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
navigationView.postDelayed(() -> {
int itemId = item.getItemId();
if (itemId == R.id.nav_map) {
removeFragment(sharingFragment);
// startActivity(new Intent(this, MapActivity.class));
removeFragment(userListFragment);
} else if (itemId == R.id.nav_profile) {
// startActivity(new Intent(this, ProfileActivity.class));
setFragment(sharingFragment);
} else if (itemId == R.id.nav_notif) {
//startActivity(new Intent(this, NotificationsActivity.class));
setFragment(sharingFragment);
loadUserSettingsFragment();
} else if (itemId == R.id.nav_user_list) {
loadUserListFragment();
}
//finish();
}, 300);
return true;
}
private void loadUserSettingsFragment() {
activeFragment = ActiveFragment.SHARED_PREFERENCES;
sharingFragment = SharingFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.activity_content, sharingFragment);
ft.commit();
}
private void loadUserListFragment() {
activeFragment = ActiveFragment.USER_LIST;
userListFragment = UsersListFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.activity_content, userListFragment);
ft.commit();
}
private void updateNavigationBarState() {
int actionId = getNavigationMenuItemId();
selectBottomNavigationBarItem(actionId);

View File

@ -10,6 +10,7 @@ import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.EditorInfo;
@ -143,6 +144,7 @@ public class LoginActivity extends AppCompatActivity {
private void showProgress(final boolean show) {
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
mLoginFormView.animate().setDuration(shortAnimTime).alpha(
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
@ -160,6 +162,7 @@ public class LoginActivity extends AppCompatActivity {
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
}
});
}
@ -168,11 +171,11 @@ public class LoginActivity extends AppCompatActivity {
//Fake validate
LdapUser user = new LdapUser(email, password, "admin", (isTutor) ? "Tutor" : "Student", "string", "string", email);
// ValidateUser user = new ValidateUser(email, password);
// LDAP logging
// disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(user)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -180,6 +183,7 @@ public class LoginActivity extends AppCompatActivity {
}
private void getUserProfile(String userId) {
disposable.add(userService.getUserByID(userId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -198,7 +202,6 @@ public class LoginActivity extends AppCompatActivity {
JWT jwt = new JWT(token);
Claim role = jwt.getClaim("nameid");
Log.e("LOGIN", "SUCCESS " + token);
PrefUtils.storeIsLoggedIn(getApplicationContext(), true);
PrefUtils.storeApiKey(getApplicationContext(), token);
@ -231,5 +234,6 @@ public class LoginActivity extends AppCompatActivity {
PrefUtils.storeUserLastName(getApplicationContext(), user.getLastName());
PrefUtils.storeUserName(getApplicationContext(), user.getUserName());
}
}

View File

@ -1,122 +0,0 @@
package com.uam.wmi.findmytutor.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MenuItem;
import com.uam.wmi.findmytutor.R;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static android.content.ContentValues.TAG;
public class SharingActivity extends AppCompatPreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();
}
public static class MainPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.pref_sharing);
Preference manualStatus = findPreference("key_manual_status");
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) findPreference("key_status_value");
updateListPreference(lp, newValue, "manual_statuses");
return true;
});
/* Preference manualLocation = findPreference("key_sharing_enabled");
manualLocation.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) findPreference("key_sharing_enabled");
updateListPreference(lp, newValue, "sharing_enabled");
return true;
});*/
Preference sharingLocation = findPreference("key_sharing_enabled");
sharingLocation.setOnPreferenceChangeListener((preference, o) -> {
Log.e("change", "1");
return false;
});
}
protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){
CharSequence [] entries = lp.getEntries();
Set <String> defaultEntries = new HashSet(Arrays.asList(entries));
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
Set <String> manualStatusSet = sharedPref.getStringSet(storageKey,defaultEntries);
manualStatusSet.add((String) newValue);
String [] manualStatusArr = manualStatusSet.toArray(new String[0]);
Arrays.sort(manualStatusArr);
setListPreferenceData(lp.getKey(),manualStatusArr);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putStringSet(storageKey,manualStatusSet);
editor.commit();
}
protected ListPreference setListPreferenceData(String lp_name, String [] entries) {
ListPreference lp = (ListPreference) findPreference(lp_name);
lp.setEntries(entries);
CharSequence[] entryValues = new CharSequence [entries.length];
for (int i = 0; i < entries.length; i++){
entryValues[i] = Integer.toString(i+1);
}
lp.setDefaultValue("1");
lp.setEntryValues(entryValues);
return lp;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
/**
* Email client intent to send support mail
* Appends the necessary device information to email body
* useful when providing support
*/
/* public static void sendFeedback(Context context) {
String body = null;
try {
body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
body = "\n\n-----------------------------\nPlease don't remove this information\n Device OS: Android \n Device OS version: " +
Build.VERSION.RELEASE + "\n App Version: " + body + "\n Device Brand: " + Build.BRAND +
"\n Device Model: " + Build.MODEL + "\n Device Manufacturer: " + Build.MANUFACTURER;
} catch (PackageManager.NameNotFoundException e) {
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"team@findmytutor.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Query from android app");
intent.putExtra(Intent.EXTRA_TEXT, body);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_email_client)));
}*/
}

View File

@ -1,5 +1,6 @@
package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -21,6 +22,7 @@ import java.util.Set;
//}
public class SharingFragment extends PreferenceFragment {
@SuppressLint("ResourceType")
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -46,6 +48,13 @@ public class SharingFragment extends PreferenceFragment {
});
}
public static SharingFragment newInstance() {
return new SharingFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);

View File

@ -0,0 +1,261 @@
package com.uam.wmi.findmytutor.activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.annimon.stream.Stream;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.adapters.TutorsListAdapter;
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.TutorTabApi;
import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
public class UsersListFragment extends Fragment {
private static final String TAG = UsersListFragment.class.getSimpleName();
@BindView(R.id.coordinator_layout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@BindView(R.id.txt_empty_notes_view)
TextView noNotesView;
private UserService userService;
private TutorTabApi tutorTabService;
private CompositeDisposable disposable = new CompositeDisposable();
private TutorsListAdapter mAdapter;
private List<User> tutorsList = new ArrayList<>();
private List<User> tutorsFiltered = new ArrayList<>();
public UsersListFragment() {
}
public static UsersListFragment newInstance() {
return new UsersListFragment();
}
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mAdapter = new TutorsListAdapter(getActivity().getApplicationContext(), tutorsFiltered);
View view = inflater.inflate(R.layout.users_list, container, false);
view.setBackgroundColor(getResources().getColor(android.R.color.white));
return view;
}
public void onViewCreated(View view, Bundle savedInstanceState) {
ButterKnife.bind(this, view);
userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class);
tutorTabService = ApiClient.getClient(getActivity().getApplicationContext())
.create(TutorTabApi.class);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new MyDividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL, 16));
recyclerView.setAdapter(mAdapter);
fetchAllTutors();
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity().getApplicationContext(),
recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, final int position) {
showNoteDialog(tutorsFiltered.get(position));
}
@Override
public void onLongClick(View view, int position) {
}
}));
}
public void searchUser(String textToSearch) {
tutorsFiltered.clear();
tutorsFiltered.addAll(Stream.of(tutorsList).filter(t ->
t.toSearchAbleString().toLowerCase().contains(textToSearch.toLowerCase())).toList());
mAdapter.notifyDataSetChanged();
}
private void showNoteDialog(final User user) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity());
alertDialogBuilderUserInput.setView(view);
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
// User cancelled the dialog
});
TextView userName = view.findViewById(R.id.userName);
ListView userDutyHours = view.findViewById(R.id.userDutyHours);
TextView userNote = view.findViewById(R.id.userNote);
TextView userRoom = view.findViewById(R.id.userRoom);
TextView userEmail = view.findViewById(R.id.userEmail);
TextView department = view.findViewById(R.id.userDepartment);
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
disposable.add(
tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
@Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
.map(DutyHourViewModel::getSummary).toList();
userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom()));
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment()));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_list_item_activated_1, dutyHoursList);
userDutyHours.setAdapter(arrayAdapter);
alertDialog.show();
}
@Override
public void onError(Throwable e) {
showError(e);
}
}));
}
private void fetchAllTutors() {
disposable.add(
userService.apiUsersGet()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(tutors -> {
List<User> tutorsList = new ArrayList<>(tutors);
List<User> onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList();
List<User> activeNotOnlineTutors = Stream.of(tutorsList)
.filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList();
List<User> notActiveTutors = Stream.of(tutorsList)
.filterNot(User::isIsActive).toList();
Collections.sort(onlineTutors, this::sortByUserName);
Collections.sort(activeNotOnlineTutors, this::sortByUserName);
Collections.sort(notActiveTutors, this::sortByUserName);
List<User> sortedUserList = new ArrayList<>(onlineTutors);
sortedUserList.addAll(activeNotOnlineTutors);
sortedUserList.addAll(notActiveTutors);
return sortedUserList;
})
.subscribeWith(new DisposableSingleObserver<List<User>>() {
@Override
public void onSuccess(List<User> users) {
tutorsList.clear();
tutorsList.addAll(users);
tutorsFiltered.addAll(users);
mAdapter.notifyDataSetChanged();
toggleEmptyNotes();
}
@Override
public void onError(Throwable e) {
showError(e);
}
}));
}
private int sortByUserName(User t1, User t2) {
return t1.getFirstName().compareTo(t2.getFirstName());
}
private void showError(Throwable e) {
String message = e.toString();
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
}
Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG)
.show();
}
private void toggleEmptyNotes() {
if (tutorsList.size() > 0) {
noNotesView.setVisibility(View.GONE);
} else {
noNotesView.setVisibility(View.VISIBLE);
}
}
@Override
public void onDestroy() {
super.onDestroy();
disposable.dispose();
}
@Override
public void onResume() {
super.onResume();
fetchAllTutors();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onStop() {
super.onStop();
}
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}

View File

@ -0,0 +1,87 @@
package com.uam.wmi.findmytutor.adapters;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.User;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.MyViewHolder> {
private Context context;
private List<User> tutorsList;
public TutorsListAdapter(Context context, List<User> tutors) {
this.context = context;
this.tutorsList = tutors;
}
class MyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.firstName)
TextView firstName;
@BindView(R.id.lastName)
TextView lastName;
@BindView(R.id.isOnline)
TextView isOnline;
MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.tutor_list_row, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Drawable image = null;
User tutor = tutorsList.get(position);
holder.firstName.setText(tutor.getFirstName());
holder.lastName.setText(tutor.getLastName());
if(tutor.isIsOnline()) {
image = context.getResources().getDrawable(R.drawable.online_user);
} else {
image = context.getResources().getDrawable(R.drawable.not_online);
}
if(!tutor.isIsActive()){
image = context.getResources().getDrawable(R.drawable.not_active_user);
}
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
holder.isOnline.setCompoundDrawables(image, null, null, null);
}
@Override
public int getItemCount() {
return tutorsList.size();
}
}

View File

@ -0,0 +1,127 @@
package com.uam.wmi.findmytutor.model;
import java.util.Objects;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
/**
* DutyHourViewModel
*/
public class DutyHourViewModel {
@SerializedName("day")
private String day = null;
@SerializedName("start")
private String start = null;
@SerializedName("end")
private String end = null;
public DutyHourViewModel day(String day) {
this.day = day;
return this;
}
/**
* Get day
* @return day
**/
@ApiModelProperty(value = "")
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public DutyHourViewModel start(String start) {
this.start = start;
return this;
}
/**
* Get start
* @return start
**/
@ApiModelProperty(value = "")
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public DutyHourViewModel end(String end) {
this.end = end;
return this;
}
/**
* Get end
* @return end
**/
@ApiModelProperty(value = "")
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DutyHourViewModel dutyHourViewModel = (DutyHourViewModel) o;
return Objects.equals(this.day, dutyHourViewModel.day) &&
Objects.equals(this.start, dutyHourViewModel.start) &&
Objects.equals(this.end, dutyHourViewModel.end);
}
@Override
public int hashCode() {
return Objects.hash(day, start, end);
}
public String getSummary() {
return this.getDay() + " " + this.getStart() + " " + this.getEnd();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DutyHourViewModel {\n");
sb.append(" day: ").append(toIndentedString(day)).append("\n");
sb.append(" start: ").append(toIndentedString(start)).append("\n");
sb.append(" end: ").append(toIndentedString(end)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -11,7 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
* LdapUser
*/
public class LdapUser extends BaseResponse{
public class LdapUser extends BaseResponse {
@SerializedName("login")
private String login = null;

View File

@ -1,3 +1,4 @@
/*
package com.uam.wmi.findmytutor.model;
@ -14,3 +15,4 @@ public class Model
}
}
*/

View File

@ -1,3 +1,4 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
@ -9,7 +10,7 @@ public class PagedResult {
@SerializedName("results")
@Expose
private List<User> results = null;
private List<ReturnedTutors> results = null;
@SerializedName("currentPage")
@Expose
private Integer currentPage;
@ -29,11 +30,11 @@ public class PagedResult {
@Expose
private Integer lastRowOnPage;
public List<User> getResults() {
public List<ReturnedTutors> getResults() {
return results;
}
public void setResults(List<User> results) {
public void setResults(List<ReturnedTutors> results) {
this.results = results;
}
@ -86,3 +87,15 @@ public class PagedResult {
}
}

View File

@ -0,0 +1,89 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.uam.wmi.findmytutor.model.Results;
public class PagedResultReturnedTutors extends BaseResponse{
@SerializedName("results")
@Expose
private Results results;
@SerializedName("currentPage")
@Expose
private Integer currentPage;
@SerializedName("pageCount")
@Expose
private Integer pageCount;
@SerializedName("pageSize")
@Expose
private Integer pageSize;
@SerializedName("rowCount")
@Expose
private Integer rowCount;
@SerializedName("firstRowOnPage")
@Expose
private Integer firstRowOnPage;
@SerializedName("lastRowOnPage")
@Expose
private Integer lastRowOnPage;
public Results getResults() {
return results;
}
public void setResults(Results results) {
this.results = results;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageCount() {
return pageCount;
}
public void setPageCount(Integer pageCount) {
this.pageCount = pageCount;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getRowCount() {
return rowCount;
}
public void setRowCount(Integer rowCount) {
this.rowCount = rowCount;
}
public Integer getFirstRowOnPage() {
return firstRowOnPage;
}
public void setFirstRowOnPage(Integer firstRowOnPage) {
this.firstRowOnPage = firstRowOnPage;
}
public Integer getLastRowOnPage() {
return lastRowOnPage;
}
public void setLastRowOnPage(Integer lastRowOnPage) {
this.lastRowOnPage = lastRowOnPage;
}
}

View File

@ -1,5 +1,6 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
@ -14,24 +15,31 @@ import io.swagger.annotations.ApiModelProperty;
public class PagedResultUserResponseModel extends BaseResponse {
@SerializedName("results")
@Expose
private List<UserResponseModel> results = null;
@SerializedName("currentPage")
@Expose
private Integer currentPage = null;
@SerializedName("pageCount")
@Expose
private Integer pageCount = null;
@SerializedName("pageSize")
@Expose
private Integer pageSize = null;
@SerializedName("rowCount")
@Expose
private Integer rowCount = null;
@SerializedName("firstRowOnPage")
@Expose
private Integer firstRowOnPage = null;
@SerializedName("lastRowOnPage")
@Expose
private Integer lastRowOnPage = null;
public PagedResultUserResponseModel results(List<UserResponseModel> results) {

View File

@ -0,0 +1,33 @@
package com.uam.wmi.findmytutor.model;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Results extends BaseResponse {
@SerializedName("tutors")
@Expose
private List<Tutor> tutors = null;
@SerializedName("blacklistersTutors")
@Expose
private List<Object> blacklistersTutors = null;
public List<Tutor> getTutors() {
return tutors;
}
public void setTutors(List<Tutor> tutors) {
this.tutors = tutors;
}
public List<Object> getBlacklistersTutors() {
return blacklistersTutors;
}
public void setBlacklistersTutors(List<Object> blacklistersTutors) {
this.blacklistersTutors = blacklistersTutors;
}
}

View File

@ -0,0 +1,108 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ReturnedTutors {
@SerializedName("id")
@Expose
private String id;
@SerializedName("isOnline")
@Expose
private Boolean isOnline;
@SerializedName("title")
@Expose
private String title;
@SerializedName("firstName")
@Expose
private String firstName;
@SerializedName("lastName")
@Expose
private String lastName;
@SerializedName("department")
@Expose
private String department;
@SerializedName("userName")
@Expose
private String userName;
@SerializedName("email")
@Expose
private String email;
@SerializedName("isActive")
@Expose
private Boolean isActive;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Boolean getIsOnline() {
return isOnline;
}
public void setIsOnline(Boolean isOnline) {
this.isOnline = isOnline;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
}

View File

@ -0,0 +1,109 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Tutor {
@SerializedName("id")
@Expose
private String id;
@SerializedName("isOnline")
@Expose
private Boolean isOnline;
@SerializedName("title")
@Expose
private String title;
@SerializedName("firstName")
@Expose
private String firstName;
@SerializedName("lastName")
@Expose
private String lastName;
@SerializedName("department")
@Expose
private String department;
@SerializedName("userName")
@Expose
private String userName;
@SerializedName("email")
@Expose
private String email;
@SerializedName("isActive")
@Expose
private Boolean isActive;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Boolean getIsOnline() {
return isOnline;
}
public void setIsOnline(Boolean isOnline) {
this.isOnline = isOnline;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
}

View File

@ -0,0 +1,202 @@
package com.uam.wmi.findmytutor.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import java.util.UUID;
/**
* TutorTabViewModel
*/
public class TutorTabViewModel {
@SerializedName("tutorTabId")
private UUID tutorTabId = null;
@SerializedName("userId")
private String userId = null;
@SerializedName("room")
private String room = "";
@SerializedName("emailTutorTab")
private String emailTutorTab = "";
@SerializedName("note")
private String note = "";
@SerializedName("dutyHours")
private List<DutyHourViewModel> dutyHours = null;
public TutorTabViewModel tutorTabId(UUID tutorTabId) {
this.tutorTabId = tutorTabId;
return this;
}
/**
* Get tutorTabId
* @return tutorTabId
**/
@ApiModelProperty(value = "")
public UUID getTutorTabId() {
return tutorTabId;
}
public void setTutorTabId(UUID tutorTabId) {
this.tutorTabId = tutorTabId;
}
public TutorTabViewModel userId(String userId) {
this.userId = userId;
return this;
}
/**
* Get userId
* @return userId
**/
@ApiModelProperty(value = "")
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public TutorTabViewModel room(String room) {
this.room = room;
return this;
}
/**
* Get room
* @return room
**/
@ApiModelProperty(value = "")
public String getRoom() {
return room;
}
public void setRoom(String room) {
this.room = room;
}
public TutorTabViewModel emailTutorTab(String emailTutorTab) {
this.emailTutorTab = emailTutorTab;
return this;
}
/**
* Get emailTutorTab
* @return emailTutorTab
**/
@ApiModelProperty(value = "")
public String getEmailTutorTab() {
return emailTutorTab;
}
public void setEmailTutorTab(String emailTutorTab) {
this.emailTutorTab = emailTutorTab;
}
public TutorTabViewModel note(String note) {
this.note = note;
return this;
}
public String getNote() {
if(note == null)
return "";
return note;
}
public void setNote(String note) {
this.note = note;
}
public TutorTabViewModel dutyHours(List<DutyHourViewModel> dutyHours) {
this.dutyHours = dutyHours;
return this;
}
public TutorTabViewModel addDutyHoursItem(DutyHourViewModel dutyHoursItem) {
if (this.dutyHours == null) {
this.dutyHours = new ArrayList<DutyHourViewModel>();
}
this.dutyHours.add(dutyHoursItem);
return this;
}
/**
* Get dutyHours
* @return dutyHours
**/
@ApiModelProperty(value = "")
public List<DutyHourViewModel> getDutyHours() {
return dutyHours;
}
public void setDutyHours(List<DutyHourViewModel> dutyHours) {
this.dutyHours = dutyHours;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TutorTabViewModel tutorTabViewModel = (TutorTabViewModel) o;
return Objects.equals(this.tutorTabId, tutorTabViewModel.tutorTabId) &&
Objects.equals(this.userId, tutorTabViewModel.userId) &&
Objects.equals(this.room, tutorTabViewModel.room) &&
Objects.equals(this.emailTutorTab, tutorTabViewModel.emailTutorTab) &&
Objects.equals(this.note, tutorTabViewModel.note) &&
Objects.equals(this.dutyHours, tutorTabViewModel.dutyHours);
}
@Override
public int hashCode() {
return Objects.hash(tutorTabId, userId, room, emailTutorTab, note, dutyHours);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class TutorTabViewModel {\n");
sb.append(" tutorTabId: ").append(toIndentedString(tutorTabId)).append("\n");
sb.append(" userId: ").append(toIndentedString(userId)).append("\n");
sb.append(" room: ").append(toIndentedString(room)).append("\n");
sb.append(" emailTutorTab: ").append(toIndentedString(emailTutorTab)).append("\n");
sb.append(" note: ").append(toIndentedString(note)).append("\n");
sb.append(" dutyHours: ").append(toIndentedString(dutyHours)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -33,8 +33,8 @@ public class ApiClient {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
return retrofit;
@ -59,6 +59,7 @@ public class ApiClient {
.addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json");
// Adding Authorization token (API Key)
// Requests will be denied without API key
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {

View File

@ -51,4 +51,5 @@ public class RetrofitClientInstance {
}
return retrofit.create(serviceClass);
}
}
}

View File

@ -0,0 +1,58 @@
package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import io.reactivex.Observable;
import io.reactivex.Single;
import retrofit2.http.*;
public interface TutorTabApi {
/**
* Scrap all tutor tabs
* With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source
* @param tutorId (required)
* @return Call&lt;Void&gt;
*/
@POST("api/users/scrapTutorTab/{tutorId}")
Observable<Void> apiUsersScrapTutorTabByTutorIdPost(
@retrofit2.http.Path("tutorId") String tutorId
);
/**
* Scrap all tutor tabs
* With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source
* @return Call&lt;Void&gt;
*/
@POST("api/users/scrapTutorTab")
Observable<Void> apiUsersScrapTutorTabPost();
/**
*
*
* @param tutorId (required)
* @return Call&lt;TutorTabViewModel&gt;
*/
@GET("api/users/tutorTab/{tutorId}")
Single<TutorTabViewModel> apiUsersTutorTabByTutorIdGet(
@retrofit2.http.Path("tutorId") String tutorId
);
/**
*
*
* @param tutorId (required)
* @param tutorTab (optional)
* @return Call&lt;Void&gt;
*/
@Headers({
"Content-Type:application/json"
})
@PUT("api/users/tutorTab/{tutorId}")
Observable<Void> apiUsersTutorTabByTutorIdPut(
@retrofit2.http.Path("tutorId") String tutorId, @retrofit2.http.Body TutorTabViewModel tutorTab
);
}

View File

@ -1,14 +1,17 @@
package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.IsUsingListBool;
import com.uam.wmi.findmytutor.model.PagedResult;
import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors;
import com.uam.wmi.findmytutor.model.ReturnedTutors;
import com.uam.wmi.findmytutor.model.StudentIdModel;
import com.uam.wmi.findmytutor.model.User;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
@ -21,17 +24,20 @@ public interface UserService {
@GET("api/users")
Single <List<User>> getAllUsers();
@GET("api/users")
Single <List<User>> apiUsersGet();
@POST("api/users")
Completable createUser(@Body User user);
@GET("api/users/page/{pageNum}")
Single <PagedResult> getPagedUsers(@Path("pageNum") String pageNum );
Single <PagedResultReturnedTutors> getPagedUsers(@Path("pageNum") String pageNum );
@GET("api/users/tutors/page/{pageNum}")
Single <PagedResult> getPagedTutors(@Path("pageNum") String pageNum);
Single <PagedResultReturnedTutors> getPagedTutors(@Path("pageNum") Integer pageNum );
@GET("api/users/students/page/{pageNum}")
Single<PagedResult> getPagedStudents(@Path("pageNum") String pageNum);
Single<PagedResultReturnedTutors> getPagedStudents(@Path("pageNum") String pageNum);
@GET("api/users/{id}")
Single<User> getUserByID(@Path("id") String userID);

View File

@ -0,0 +1,8 @@
package com.uam.wmi.findmytutor.utils;
public enum ActiveFragment {
USER_LIST,
SHARED_PREFERENCES,
NONE
}

View File

@ -0,0 +1,98 @@
package com.uam.wmi.findmytutor.utils;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
public class MyDividerItemDecoration extends RecyclerView.ItemDecoration {
private static final int[] ATTRS = new int[]{
android.R.attr.listDivider
};
public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
private Drawable mDivider;
private int mOrientation;
private Context context;
private int margin;
public MyDividerItemDecoration(Context context, int orientation, int margin) {
this.context = context;
this.margin = margin;
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();
setOrientation(orientation);
}
public void setOrientation(int orientation) {
if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
throw new IllegalArgumentException("invalid orientation");
}
mOrientation = orientation;
}
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == VERTICAL_LIST) {
drawVertical(c, parent);
} else {
drawHorizontal(c, parent);
}
}
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left + dpToPx(margin), top, right - dpToPx(margin), bottom);
mDivider.draw(c);
}
}
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top + dpToPx(margin), right, bottom - dpToPx(margin));
mDivider.draw(c);
}
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
private int dpToPx(int dp) {
Resources r = context.getResources();
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()));
}
}

View File

@ -0,0 +1,62 @@
package com.uam.wmi.findmytutor.utils;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by ravi on 21/02/18.
*/
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
private ClickListener clicklistener;
private GestureDetector gestureDetector;
public RecyclerTouchListener(Context context, final RecyclerView recycleView, final ClickListener clicklistener) {
this.clicklistener = clicklistener;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
View child = recycleView.findChildViewUnder(e.getX(), e.getY());
if (child != null && clicklistener != null) {
clicklistener.onLongClick(child, recycleView.getChildAdapterPosition(child));
}
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clicklistener != null && gestureDetector.onTouchEvent(e)) {
clicklistener.onClick(child, rv.getChildAdapterPosition(child));
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
public interface ClickListener {
void onClick(View view, int position);
void onLongClick(View view, int position);
}
}

View File

@ -1,10 +1,19 @@
package com.uam.wmi.findmytutor.utils;
import android.app.Activity;
import android.graphics.Color;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.TextView;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.uam.wmi.findmytutor.R;
import org.json.JSONObject;
import okhttp3.ResponseBody;
public class RestApiHelper {
public class RestApiHelper extends Activity {
public RestApiHelper() {
}
@ -17,4 +26,20 @@ public class RestApiHelper {
return e.getMessage();
}
}
public void showError(Throwable e) {
String message = e.toString();
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
}
Snackbar snackbar = Snackbar.make(findViewById(R.id.activity_content), message, Snackbar.LENGTH_LONG);
View sbView = snackbar.getView();
TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.BLUE);
snackbar.show();
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#252525"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#010101" android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#BD120A"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#010101" android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#0ABD48"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#010101" android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#0ABD48"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#010101" android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"/>
</vector>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
<TextView android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="@string/lbl_new_note_title"
android:textColor="@color/note_list_text"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<TextView
android:id="@+id/userDepartment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text"
/>
<TextView
android:id="@+id/userRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text"
/>
<TextView
android:id="@+id/userEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text" />
<TextView
android:id="@+id/userDutyHoursTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/userDutyHoursHeader"
android:textColor="@color/note_list_text"
tools:text="@string/dutyHours" />
<ListView
android:id="@+id/userDutyHours"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text" />
<TextView
android:id="@+id/userNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text" />
</LinearLayout>

View File

@ -1,40 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="90dp"
android:clickable="true"
android:paddingBottom="@dimen/dimen_10"
android:focusable="true"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/dimen_10"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/dimen_10">
android:paddingBottom="@dimen/dimen_10">
<TextView
android:id="@+id/firstName"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_width="271dp"
android:layout_height="22dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:textColor="@color/note_list_text"
android:textSize="@dimen/note_list_text" />
android:textSize="15sp" />
<TextView
android:id="@+id/lastName"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_width="270dp"
android:layout_height="22dp"
android:layout_below="@+id/firstName"
android:layout_centerHorizontal="true"
android:layout_alignEnd="@+id/firstName"
android:layout_marginTop="10dp"
android:layout_marginEnd="0dp"
android:textColor="@color/note_list_text"
android:textSize="@dimen/note_list_text" />
android:textSize="15sp" />
<TextView
android:id="@+id/isOnline"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_below="@+id/lastName"
android:layout_centerHorizontal="true"
android:layout_width="48dp"
android:layout_height="30dp"
android:layout_below="@+id/firstName"
android:layout_marginStart="7dp"
android:layout_marginTop="-10dp"
android:layout_toEndOf="@+id/firstName"
android:textColor="@color/note_list_text"
android:textSize="@dimen/note_list_text" />

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.UsersListFragment">
<include layout="@layout/users_list_main" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.UsersListFragment"
tools:showIn="@layout/users_list_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/txt_empty_notes_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_top_no_notes"
android:fontFamily="sans-serif-light"
android:text="@string/loading"
android:textColor="@color/msg_no_notes"
android:textSize="@dimen/msg_no_notes" />
</RelativeLayout>

View File

@ -11,7 +11,7 @@
android:icon="@drawable/outline_map_white_24dp"
android:title="@string/nav_map" />
<item
android:id="@+id/nav_notif"
android:id="@+id/nav_user_list"
android:icon="@drawable/mapbox_info_icon_default"
android:title="Active" />
</menu>

View File

@ -2,7 +2,7 @@
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#9ef13f</color>
<color name="colorAccent">#dc0004</color>
<color name="msg_no_notes">#999</color>
<color name="hint_enter_note">#89c3c3c3</color>
<color name="timestamp">#858585</color>

View File

@ -201,5 +201,16 @@ functionality.</string>
</plurals>
<string name="title_activity_main2">Main2Activity</string>
<string name="error_invalid_login_name">Invalid login format</string>
<string name="there_is_no_users_in_system">There is no users in system</string>
<string name="cancel">Close</string>
<string name="userRoom">Pokój</string>
<string name="userEmail">Email</string>
<string name="userNote">Notatka</string>
<string name="userDutyHoursHeader">Dyżury</string>
<string name="dutyHours">Dyżury</string>
<string name="error_invalid_login_name">Invalid format login. Use s11111 format</string>
<string name="userDepartment">Zakład</string>
<string name="loading">Loading ...</string>
</resources>